$(document).ready(function() { $(".hiding-sheet").click(toggleSheet); }); $(window).on("load", function() { layout(); }); $(window).on("resize", function() { layout(); }); function layout() { layout_pic_and_description(); } function toggleSheet() { $(this).children("*").each(function(index){ $(this).slideToggle(); }); } function layout_pic_and_description() { $("div.pic_and_description > *").css({ position : 'absolute' }); $("div.pic_and_description").each(function(index){ if ($(this).is(':hidden')) { return; } if ($(this).hasClass("second_left")) { $thisDesc = $("> *:nth-child(1)",this); $thisPic = $("> *:nth-child(2)",this); if (!$(this).data('second_top_toggle_thrown')) { $(this).data('second_top_toggle_thrown','true'); $(this).toggleClass("second_top"); } } else { $thisPic = $("> *:nth-child(1)",this); $thisDesc = $("> *:nth-child(2)",this); } if (!$thisPic.data('originalWidth')) { var width; var nextWidth; width = $thisPic.width(); nextWidth = parseInt($thisPic.css("width"), 10); if (nextWidth) width = Math.max(width,nextWidth); $thisPic.data('originalWidth',width); } if (!$thisDesc.data('originalWidth')) { $thisDesc.data('originalWidth',$thisDesc.width()); } $thisDesc.css({ position : 'absolute' }); $thisPic.css({ position : 'absolute' }); var viewWidth; viewWidth = $(this).outerWidth(); viewWidth = Math.min(viewWidth, $(window).width()); var margin = 0; var padding = 15; var marginGap = 0; if ($(this).css('padding')) { padding = parseInt($(this).css('padding')); } if ($(this).css('margin')) { margin = parseInt($(this).css('margin')); } $(this).css({ 'margin': margin, 'padding': padding, 'position' : 'relative' }); // getting the image's actual width // Get on screen image var imageHeight; var imageWidth; var screenImage = $thisPic; var originalImage = new Image(); originalImage.src = screenImage.attr("src"); var realImageWidth = originalImage.width; realImageWidth = $thisPic.data('originalWidth'); if (realImageWidth + margin*2 + padding*2 > viewWidth) { imageWidth = viewWidth - margin*2 - padding*2; } else { imageWidth = realImageWidth; } $thisPic.css({ width : imageWidth, }); imageHeight = $thisPic.height(); imageWidth = $thisPic.width(); var divWidth = 0; var divTop = 0; var divLeft = 0; var imageLeft = 0; var imageTop = 0; if (viewWidth - imageWidth < 300) { // stack pic and description; width is to little for side by side if (margin == 0 && padding == 0) { marginGap = 15; $(this).css({ 'margin-bottom': marginGap }); } divWidth = (viewWidth - margin*2 - padding*2); $thisDesc.css({ width : divWidth, }); if ($(this).hasClass("second_top")) { var divHeight = $thisDesc.outerHeight(true); imageTop = divHeight + padding*2 + margin; divTop = 0; } else { divTop = imageHeight + padding*2 + margin; imageTop = 0; } divLeft = padding; imageLeft = (viewWidth - margin*2 - padding*2 - imageWidth) / 2; $thisDesc.css({ width : divWidth, left : divLeft, top : divTop, }); $thisPic.css({ 'margin-left' : imageLeft, 'margin-top' : imageTop, }); } else { // set pic and description side by side if (margin == 0 && padding == 0) { marginGap = 15; $("div:nth-child(2)",this).css({ 'margin-left': marginGap }); } divWidth = (viewWidth - margin*2 - padding*3 - imageWidth-marginGap); divLeft = (imageWidth + padding*2); $thisPic.css({ 'margin-left' : imageLeft, 'margin-top' : imageTop, }); $thisDesc.css({ width : divWidth, left : divLeft, }); if ($thisDesc.height() < imageHeight) { var descriptionBlockHeight = $thisDesc.height(); divTop = ((imageHeight - descriptionBlockHeight) / 2) + padding; } else { divTop = 0; } $thisDesc.css({ top : divTop }); } var viewHeight = Math.max(imageTop + imageHeight + margin + padding, divTop + $thisDesc.height() + margin + padding)+marginGap; $(this).css({ 'height' : viewHeight, }); }); } function edit_page(site_id, user_name) { html = '
?
'; document.getElementById("editing-tools").innerHTML = html; document.getElementById("gs").classList.add("editing-on-gs"); window.scrollTo(0, document.body.scrollHeight); } function edit_login(site_id) { // html = "
" + '
'; html = "
" + '
'; document.getElementById("editing-tools").innerHTML = html; document.getElementById("gs").classList.add("editing-on-gs"); } function login(site_id) { var user = document.getElementById("emailInput").value; var password = document.getElementById("passwordInput").value; if (!user) { document.getElementById(errorElementId).innerText = 'User name is required.'; return } else if (!password) { document.getElementById(errorElementId).innerText = 'Password is required.'; return } else { let xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", `common_public/phpFunctions/ajaxFunctions.php?f1=edit_page_login&email=${encodeURIComponent(user)}&site_id=${encodeURIComponent(site_id)}&password=${encodeURIComponent(password)}`, true); xmlhttp.responseType = 'text'; xmlhttp.onload = function() { let values = xmlhttp.response.split('~,~'); let entryId = values[0]; if (entryId!='') { start_editing(site_id,entryId); } else { alert("Login Failed"); } } xmlhttp.send(); } } function editing_logout() { let xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", `common_public/phpFunctions/ajaxFunctions.php?f1=editing_logout`, true); xmlhttp.responseType = 'text'; xmlhttp.onload = function() { let values = xmlhttp.response.split('~,~'); html = ''; document.getElementById("editing-tools").innerHTML = html; document.getElementById("gs").classList.remove("editing-on-gs"); es = document.getElementsByClassName("gs-editable"); var i; for (i = 0; i < es.length; i++) { es[i].contentEditable = "false"; es[i].classList.remove("editing-on"); } const was0 = document.getElementsByClassName("was0"); for (i = 0; i < was0.length; i++) { was0[i].style.top = "0px"; } document.getElementById("page").style.marginTop = "0px"; document.getElementById("page").style.paddingBottom = "0px"; drop_stylesheet(); location.reload(); } xmlhttp.send(); } function start_editing(site_id,entryId) { es = document.getElementsByClassName("gs-editable"); var i; for (i = 0; i < es.length; i++) { es[i].contentEditable = "true"; es[i].classList.add("editing-on"); } html = '
'; add_stylesheet(site_id,entryId); toolbar_html = get_toolbar(); html = html + toolbar_html; document.getElementById("editing-tools").innerHTML = html; document.getElementById("gs").classList.add("editing-on-gs"); document.body.appendChild(document.getElementById("editing-tools")); window.scrollTo(0, document.body.scrollHeight); editingEnabled(); clicker(); // fixPageMargins(); } function add_stylesheet(site_id,entryId) { var lnk=document.createElement('link'); lnk.href='common_public/inline-editing.css'; lnk.rel='stylesheet'; lnk.type='text/css'; lnk.id='inlineCSS'; (document.head||document.documentElement).appendChild(lnk); if (site_id=='1001074') { var lnk2=document.createElement('link'); lnk2.href='//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'; lnk2.rel='stylesheet'; lnk2.type='text/css'; lnk2.id='bootstrap3CSS'; (document.head||document.documentElement).appendChild(lnk2); var stylesheet3 = document.getElementById("bootstrap2"); if (stylesheet3) { stylesheet3.disabled = true; stylesheet3.parentNode.removeChild(stylesheet3); } } if (typeof addStyle !== "function") { var scriptTag = document.createElement('script'); scriptTag.src = 'common_public/inline-editing.js'; inlineScript = document.body.appendChild(scriptTag); inlineScript.setAttribute("id","inlineScript"); } } function drop_stylesheet() { var stylesheet = document.getElementById("inlineCSS"); stylesheet.disabled = true; document.querySelector("link[href='common_public/inline-editing.css']").removeAttribute("href"); stylesheet.parentNode.removeChild(stylesheet); var stylesheet2 = document.getElementById("bootstrap3CSS"); if (stylesheet2) { stylesheet2.disabled = true; stylesheet2.parentNode.removeChild(stylesheet2); var lnk2=document.createElement('link'); lnk2.href='_site_layouts//css/bootstrap.css'; lnk2.rel='stylesheet'; lnk2.type='text/css'; lnk2.id='bootstrap2'; (document.head||document.documentElement).appendChild(lnk2); } document.getElementById("inlineScript").remove; } function save_edits(site_id) { es = document.getElementsByClassName("gs-editable"); var i; for (i = 0; i < es.length; i++) { tipe_id = es[i].dataset.tipe; html = es[i].innerHTML; user_id = document.getElementById("saveEdits").dataset.user; save_tipe_page(tipe_id,html,user_id); } alert("Changes Saved"); } function save_tipe_page(tipe_id,html,user_id) { html = html.replace(/#/g,"%23"); html = encodeURIComponent(html); var params = "f1=edit_page_save§ion_name=" + tipe_id + "&html=" + html + "&user_id="+user_id; var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", "common_public/phpFunctions/ajaxFunctions.php", true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.onload = function() { if (xmlhttp.readyState === xmlhttp.DONE) { if (xmlhttp.status === 200) { console.log(xmlhttp.response); console.log(xmlhttp.responseText); } } values = xmlhttp.response.split('~,~'); result = values[0]; }; xmlhttp.send(params); } function get_toolbar() { var toolbar_html = '\
\
\
\ \ \ \ \ \
\
\ \ \ \
\
\
\ \ \
\
\
\
\ \ \ \
\
\
\ \ \
\ \ \
\
\ \
\ \
\ '; /*
\ \
\
\ \
\ \
\
\ \ \
\
\
\ \
\ */ toolbar_html = toolbar_html + '\
\
\ \ \ '; return toolbar_html; } function editingEnabled() { $('#editingEnabled').modal('show'); } function clicker() { $('.editing-on').click(function(){ var sel = window.getSelection(); size = window.getComputedStyle(sel.anchorNode.parentElement, null).getPropertyValue('font-size'); size = parseInt(size,10); document.getElementById("current-fontsize").innerHTML = size; }); } function closeModal() { $('#editingEnabled').modal('hide'); } $(document).ready(function(){ clicker(); });