var isLogged = false; var isAdmin = false; var isGlobalIndex = false; var app={}; app.filter = {}; app.maxScrollTimes = 2; app.insertWallADV = true; app.ADVs = ["div-gpt-ad-medium_rectangle-1", "div-gpt-ad-medium_rectangle-2", "div-gpt-ad-box_link-1", "div-gpt-ad-box_link-2"]; function callFacebook() { var req = { "CM": "FACEBOOKAUTH"}; $.getJSON('/applications/gioia/site/access/parts/oauthRequester.jsp', req, function (response) { if (response.ok) location.href = response.url; else alert("Facebook login is not currently available.") }); } function getHome() { self.location.href = '/'; } function openMenu(id, el, e, anim) { if (typeof anim == "undefined") anim = true; var animTime = anim? 300 : 0; function closeMenu(){ document.actualMenu.slideUp(animTime); if(document.actualMenuContainer) document.actualMenuContainer.addClass("closed"); document.actualMenuContainer = null; } if(document.actualMenu){ closeMenu(); document.actualMenu = null; } document.actualMenuContainer = $(el); document.actualMenu = $('#'+id, $(el)); document.actualMenuContainer.removeClass("closed"); $("#"+id).not(document.actualMenu).hide(); if(document.actualMenu.is(":visible")){ closeMenu() }else{ document.actualMenu.slideDown(animTime, function(){ document.actualMenu.css({overflow:"inherit"}) }); } e.stopPropagation(); $(document).one("click",function(e){ if (document.actualMenu && e.target == document.actualMenu.get(0)) return; if(document.actualMenu) closeMenu(); document.actualMenu = null; }) } function showHideSearch(){ $("#formSearch").show(); $(".search").addClass("active"); $("#searchStrip").focus(); $("#searchStrip").on("blur", function(){ if($("#searchStrip").val().length == 0){ $("#formSearch").hide(); $(".search").removeClass("active"); } }); } function dateToRelative(localTime) { var diff = new Date().getTime() - localTime; var ret = ""; var min =60000; var hour =3600000; var day =86400000; var wee =604800000; var mon =2629800000; var yea =31557600000; if (diff < -yea * 2) ret = "tra ## anni".replace("##", (-diff / yea).toFixed(0)); else if (diff < -mon * 9) ret = "tra ## mesi".replace("##", (-diff / mon).toFixed(0)); else if (diff < -wee * 5) ret = "tra ## settimane".replace("##", (-diff / wee).toFixed(0)); else if (diff < -day * 2) ret = "tra ## giorni".replace("##", (-diff / day).toFixed(0)); else if (diff < -hour) ret = "tra ## ore".replace("##", (-diff / hour).toFixed(0)); else if (diff < -min * 35) ret = "tra circa un'ora"; else if (diff < -min * 25) ret = "tra circa mezz'ora"; else if (diff < -min * 10) ret = "tra qualche minuto"; else if (diff < -min * 2) ret = "tra pochi minuti"; else if (diff <= min) ret = "adesso"; else if (diff <= min * 5) ret = "pochi minuti fa"; else if (diff <= min * 15) ret = "alcuni minuti fa"; else if (diff <= min * 35) ret = "circa mezz'ora fa"; else if (diff <= min * 75) ret = "circa un'ora fa"; else if (diff <= hour * 5) ret = "poche ore fa"; else if (diff <= hour * 24) ret = "## ore fa".replace("##", (diff / hour).toFixed(0)); else if (diff <= day * 7) ret = "## giorni fa".replace("##", (diff / day).toFixed(0)); else if (diff <= wee * 5) ret = "## settimane fa".replace("##", (diff / wee).toFixed(0)); else if (diff <= mon * 12) ret = "## mesi fa".replace("##", (diff / mon).toFixed(0)); else ret = "## anni fa".replace("##", (diff / yea).toFixed(0)); return ret; } // transform string values to printable: \n in
function transformToPrintable(data) { for (var prop in data) { var value = data[prop]; if (typeof(value) == "string") data[prop] = (value + "").replace(/\n/g, "
"); } return data; } // see http://www.tinymce.com/tryit/ajax_load_save.php function tinyInitializer(tinyId, callback) { if (isiOsDevice) return; tinyMCE.init({ tmce_ta_id: tinyId, theme: "advanced", mode: "exact", //maxlength_onchange_callback : "alertOnMaxLen", elements: tinyId, valid_elements: "*[*]", relative_urls: true, remove_script_host: true, //document_base_url : baseUrl, cleanup: true, force_br_newlines: true, forced_root_block: false, plugins: " paste", theme_advanced_toolbar_location: "top", theme_advanced_toolbar_align: "left", theme_advanced_buttons1: "bold,italic,underline, separator, pastetext,pasteword, separator,link,unlink", theme_advanced_buttons2: "", theme_advanced_buttons3: "", theme_advanced_buttons4: "", init_instance_callback: callback }); } //returns a jquery object where to write content function createBlackPage(width, height, onCloseCallBack) { if (!width) width = '900px'; if (!height) height = '500px'; $("#__blackpopup__").remove(); var bg = $("
").attr("id", "__blackpopup__"); bg.css({position: 'fixed', top: "0px", paddingTop: "50px", left: 0, width: '100%', height: '100%', backgroundImage: "url('/applications/gioia/images/overlay.png')"}); bg.append("
"); bg.bringToFront(); var ret = bg.find("#bwinPopupd"); ret.css({width: width, height: height, top: 10, "-moz-box-shadow": '1px 1px 6px #333333', overflow: 'auto', "-webkit-box-shadow": '1px 1px 6px #333333', border: '1px solid #777', backgroundColor: "#fff", margin: "auto" }); var bdiv = $("
").css({width: width, position: "relative", height: "0px", textAlign: "right", margin: "auto" }); var img = $(""); bdiv.append(img); img.click(function () { bg.trigger("close"); }); bg.prepend(bdiv); $("body").append(bg); //close call callback bg.bind("close", function () { bg.remove(); if (typeof(onCloseCallBack) == "function") onCloseCallBack(); }); //destroy do not call callback bg.bind("destroy", function () { bg.remove(); }); return ret; } function getBlackPopup() { var ret = $("#__blackpopup__"); if (typeof(top) != "undefined") { ret = top.$("#__blackpopup__"); } return ret; } function closeBlackPopup(divId) { if (!divId) divId = "__blackpopup__"; getBlackPopup(divId).trigger("close"); } function openBlackPopup(url, width, height, onCloseCallBack) { if (!width) width = '1024px'; if (!height) height = '730px'; $("#__blackpopup__").remove(); var bg = $("
").attr("id", "__blackpopup__"); bg.css({position: 'fixed', top: 0, left: 0, width: '100%', height: '100%', backgroundImage: "url('/applications/gioia/images/overlay.png')", textAlign: 'center'}); bg.append(""); bg.bringToFront(); bg.find("#bwinPopup").attr("src", url).css({width: width, height: height, top: 100, "-moz-box-shadow": '1px 1px 6px #333333', "-webkit-box-shadow": '1px 1px 6px #333333', border: '1px solid #777', margin: "auto", "margin-top": '0'}); var bdiv = $("
").css({width: width, position: "relative", height: "5px", textAlign: "right", margin: "auto" }); var img = $(""); bdiv.append(img); img.click(function () { bg.trigger("close"); }); bg.prepend(bdiv); $("body").append(bg); $("body").scrollTo(0).css("overflow", "hidden"); //close call callback bg.bind("close", function () { bg.remove(); $("body").css("overflow", "auto"); if (typeof(onCloseCallBack) == "function") onCloseCallBack(); }); //destroy do not call callback bdiv.bind("destroy", function () { bdiv.remove(); }); } // make autoresize textareas function textAreaAutoResize(domScheda) { //var textArea = $('#notes'); var textArea = domScheda.find('textarea.autosize'); if ($.browser.msie) { textArea.focus(function () { $(this).trigger('change'); }).oneTime(150, "taautosize", function () { $(this).trigger('change'); }); } else { textArea.autoResize({ animateDuration: 300, extraSpace: 40, limit: 400 }).focus(function () { $(this).trigger('change'); }).oneTime(150, "taautosize", function () { $(this).trigger('change'); }); } } $.fn.safety = function (callback, message) { var el = this; if (el.get(0).cancelTimeOut) clearTimeout(el.get(0).cancelTimeOut); function cancel() { el.show(); el.next(".safety").remove(); el.attr("onClick", el.data("click")); } if (typeof callback == "function") { $(".safety").remove(); el.data("click", el.attr("onClick")); el.removeAttr("onClick"); } else { cancel(); return; } var sure = $("").addClass("sure").html(message ? message : "sure?    "); var y = $("").addClass("confirm").html("yes").bind("click", function () { if (typeof callback == "function") { callback(); } }); var n = $("").addClass("cancel").html("no").click(function () { el.safety("cancel"); }); var safety = $("").addClass("safety").css({cursor: "pointer"}); safety.append(sure).append(y).append(" / ").append(n); safety.css({position: "absolute", top: el.position().top, left: el.position().left, marginTop: el.css("margin-top"), minWidth: el.width(), minHeight: el.height(), boxSizing: "border-box", whiteSpace: "nowrap"}); el.after(safety); //el.hide(); el.get(0).cancelTimeOut = setTimeout(cancel, 4000); }; /** * jQuery.fn.sortElements * -------------- * @param Function comparator: * Exactly the same behaviour as [1,2,3].sort(comparator) * * @param Function getSortable * A function that should return the element that is * to be sorted. The comparator will run on the * current collection, but you may want the actual * resulting sort to occur on a parent or another * associated element. * * E.g. $('td').sortElements(comparator, function(){ * return this.parentNode; * }) * * The 's parent () will be sorted instead * of the itself. */ jQuery.fn.sortElements = function () { var sort = [].sort; return function (comparator, getSortable) { getSortable = getSortable || function () { return this; }; var placements = this.map(function () { var sortElement = getSortable.call(this), parentNode = sortElement.parentNode, // Since the element itself will change position, we have // to have some way of storing its original position in // the DOM. The easiest way is to have a 'flag' node: nextSibling = parentNode.insertBefore( document.createTextNode(''), sortElement.nextSibling ); return function () { if (parentNode === this) { throw new Error( "You can't sort elements if any one is a descendant of another." ); } // Insert before flag: parentNode.insertBefore(this, nextSibling); // Remove flag: parentNode.removeChild(nextSibling); }; }); return sort.call(this, comparator).each(function (i) { placements[i].call(getSortable.call(this)); }); }; }; function subscribeUnsubscribeUser(el) { var data = {}; data.CM = 'FOLLOW_USER'; data.userId = el.closest(".jsUser").attr("userId"); var ajaxController = "/applications/gioia/site/API/ajaxController.jsp"; $.ajax({ url: ajaxController, data: data, dataType: 'json', success: function(response) { if (response.ok) { if(el.hasClass("selected")){ el.removeClass("selected"); el.html("+ segui"); }else{ el.addClass("selected"); el.html("segui già"); } } }, error: function(er){ showFeedbackMessage("ERROR", er.statusText); } }); } function reportPost(el){ var sitePost = el.closest(".post"); var postId= sitePost.attr("postId"); var params = {}; params.CM = "REPORT_POST"; params.postId = postId; $.getJSON('/applications/gioia/site/API/ajaxController.jsp', params, function(response){ if(response.ok){ el.html("Grazie per la segnalazione."); el.fadeOut(2500, closeActionWindow); } }); } function banPost(el,callback){} function bindPostEvents(domPost, jsonData) { if (isLogged) { initCare(domPost, jsonData); } else { var care = domPost.find("div.care"); care.attr("title", "Registrati per partecipare alla community di Gioia!"); var message = "Registrati per partecipare alla community di Gioia!" generateMessageDiv(care, message) } var comment = domPost.find(".comment"); if(jsonData.postComments.length) comment.on("click",function () { location.href = jsonData.posturl; }).addClass("active"); initActionWindow(domPost); } function generateMessageDiv (onDiv, msg){ var logtocare = $("
").html(msg) logtocare.css("display", "none"); logtocare.attr("id", "logtocare"); logtocare.addClass("linkEnabled"); onDiv.append(logtocare); onDiv.on("click",function (e) { openMenu('logtocare', this, e, false); }) } function initCare(domPost, jsonData){ if (jsonData.IcareIt) { domPost.find("div.care").click(function () { uncarePost($(this)); }) domPost.find("div.care").addClass("selected") } else { domPost.find("div.care").click(function () { carePost($(this)); }) } } function closeActionWindow(){ $(".inlineButtons").fadeOut(100, function () {$(".inlineButtons").empty()}) } function initActionWindow(domPost, isWall){ function closeWinOnDomClick() { setTimeout(function(){ $(document).one("click.inlineButtons", function (e) { if(!$(e.target).hasClass("confirm")) closeActionWindow(); }); },100) } domPost.find("div.more").click(function (e) { $(document).off("click.inlineButtons"); if($(e.target).parents().is(".inlineButtons")){ closeWinOnDomClick(); return; } var isVis = "" != domPost.find(".inlineButtons").html(); $(".inlineButtons").empty().hide(); if(!isVis){ var url= "/applications/gioia/site/parts/partSharing.jsp?POSTID="+domPost.attr("postid")+"&isPostWall="+(isWall? "yes":"no"); var content = getContent(url); domPost.find(".inlineButtons").html(content).fadeIn(100,closeWinOnDomClick); } }); } function loadNextPage(){ var page = $("#container").attr("pagenumber"); deskLoadOlder(function(){ var container = $("#container"); if(page >= app.maxScrollTimes-1 && container.attr("hasmore")!= "false"){ $("#loadMore").show(); } else{ $("#loadMore").hide(); } }); } function buildWall(emos, container) { var elements = []; var postsLength = emos.length; for (var i = 0; i < postsLength; i++) { var ei = emos[i]; if (typeof ei != "object") continue; var el = buildEI(ei).get(0); elements.push(el); /*Insert Wall Link after the 1st element loaded*/ if (app.insertWallADV && i == 1) { var link = buildWallADV("div-gpt-ad-box_link-1"); if (link) { elements.push(link.get(0)); } } /*Insert Wall AD after the 4th element loaded*/ if (app.insertWallADV && (i == 4)) { var AD = buildWallADV("div-gpt-ad-medium_rectangle-2"); if (AD) { elements.push(AD.get(0)); } } /*Insert Wall Link after the 7th element loaded*/ if (app.insertWallADV && (i == 7)) { var link = buildWallADV("div-gpt-ad-box_link-2"); if (link) { elements.push(link.get(0)); } } } if (container.get(0).masoneryInit) { container.masonry('appended', elements); } if ($(".item", container).length == 0) { $("#div-gpt-ad-box_link-1").remove(); } if ($(".item", container).length < 6) { $("#div-gpt-ad-medium_rectangle-2").remove(); } if ($(".item", container).length < 9) { $("#div-gpt-ad-box_link-2").remove(); } for (var a = 0; a < app.ADVs.length; a++) { var ID = app.ADVs[a]; var wallADV = $("#wallADV_" + ID); wallADV.css({opacity: 0}) } setADVPos(app.ADVs); } function ajaxFillPosts(filter, callback) { if(app.isFilling) return; app.isFilling = true; filter["pageNumber"]=filter.pageNumber ? filter.pageNumber : 0; //reset searchText in order to avoid using it delete filter.searchText; $.getJSON('/applications/gioia/site/API/ajaxController.jsp', filter, function (response) { if(filter.emotion){ var title ="Gioia! live"; $("#maintitle").html(title + ""+ filter.emotion + " *"); } if (response.ok) { var container = $("#container"); container.attr("pageNumber", filter.pageNumber); container.attr("hasMore", response.hasMore); if (filter.clearDesk) { container.empty(); $("#customboxes").hide(500); if(container.get(0).masoneryInit) container.destroyMasonry(); } if(response.emotionInstances.length == 0){ app.isFilling = false; filter.clearDesk=false; } if(response.emotionInstances.length == 0) { container.html("

Nessun post trovato

"); } buildWall(response.emotionInstances, container); container.setMasonry(false); if($("#clean")) $("#clean").remove(); $(".linkEnabled").activateLinks(true); $(".linkEnabled").removeClass("linkEnabled"); if (typeof callback == "function") callback(response); } app.isFilling = false; filter.clearDesk = false; if (filter["pageNumber"] > 0 && typeof googletag != "undefined" && typeof googletag.pubads != "undefined") { if (refreshAllADV) { //Prevent the duplication of the interstitial on refresh if($("#interstitial").length) $("#interstitial").remove(); /*todo: 1.10.2014 added slot to refresh to exclude the Interstitial (Matteo)*/ googletag.pubads().refresh([slot1, slot2, slot3, slot4, slot5, slot6]); // modified by monica var tryad = 20; for (var i = 0; i < tryad; i++) { setTimeout(function () { TAG_LOADER.execute(); }, i * 300); } // TAG_LOADER.execute(); } else { googletag.pubads().refresh([slot3]); } } }); } function buildWallADV(adv_id){ if (!$("#"+adv_id).length) return; var container = $("#container"); if(container.get(0).masoneryInit) container.masonry('remove', $("#wallADV_"+adv_id).get(0)); $("#wallADV_"+adv_id).remove(); var wallADV = $("
").attr({id:"wallADV_"+adv_id}).addClass("item"); wallADV.css({width:300, height:$("#"+adv_id).height() + 8, overflow:"hidden"}); container.append(wallADV); return wallADV; } function setADVPos(adv_IDs){ adv_IDs = typeof adv_IDs.data != "undefined" ? adv_IDs.data : adv_IDs; if(!adv_IDs) return; function manageADV(ID) { if (ID == "div-gpt-ad-medium_rectangle-1"){ var h = $("#" + ID).height() < 5 ? 0 : $("#" + ID).height() + 10; var classname = "zero"; if(h<600) classname = "thin"; if(h<200) classname = "large"; $(".boxNews").addClass(classname); $(".boxAPP").addClass(classname); } var wallADV = $("#wallADV_"+ID); if(wallADV.length) setTimeout(function(){ if($("#" + ID).is(":visible")){ $("#" + ID).css({position: "absolute", top: wallADV.offset().top + 5, left: wallADV.offset().left + 5, opacity: 1 }); var h = $("#" + ID).height() < 20 ? 0 : $("#" + ID).height() + 10; wallADV.css({height: h, opacity:1 }); }else{ wallADV.css({height: 0, opacity:1 }); } $("#container").setMasonry(false); },400); } for (var a = 0; a < adv_IDs.length; a++){ var ID = adv_IDs[a]; manageADV(ID); } } $(window).on("resize.advs", function(){ clearTimeout(app.windowresize); app.windowresize = setTimeout(function(){ setADVPos(app.ADVs); },10); }); function checkForAddLoaded(id, callbackAction, watchDog){ if(typeof watchDog == "undefined"){ watchDog = 0; } watchDog++; if (watchDog >= 10){ var elData= {}; elData.width = $("#" + id).width()>50 ? $("#" + id).width() : 0; elData.height = $("#" + id).height()>50 ? $("#" + id).height() : 0; if(typeof callbackAction == "function") callbackAction(elData); return; } setTimeout(function(){ var elData = {}; if($("#"+id+" iframe").length !=0 && $("#"+id+" iframe").height()>50){ var el = $("#"+id+" iframe").eq(0); elData.width = el.width(); elData.height = el.height(); elData.height = elData.height < 50 ? 0 : parseInt(elData.height); elData.width = elData.width < 50 ? 0 : parseInt(elData.width); callbackAction(elData); }else if ($("#"+id+" div.gioiaLINK div").length != 0){ elData.width = parseFloat($("#"+id+" div.shd-adv-container").width()); elData.height = parseFloat($("#"+id+" div.shd-adv-container").height()); elData.height = elData.height < 50 ? 0 : elData.height; elData.width = elData.width < 50 ? 0 : elData.width; callbackAction(elData); }else if ($("#"+id+" a img").length != 0){ elData.width = parseFloat($("#"+id+" a img").width()); elData.height = parseFloat($("#"+id+" a img").height()); elData.height = elData.height < 50 ? 0 : elData.height; elData.width = elData.width < 50 ? 0 : elData.width; callbackAction(elData); }else checkForAddLoaded(id, callbackAction, watchDog); },600); }; function buildEI(ei) { if( typeof ei != "object") return; var domEmo = $.JST.createFromTemplate(transformToPrintable(ei), "EMO_MODULE"); if(ei.isChain){ domEmo.addClass("isChain") } var user = $.JST.createFromTemplate(transformToPrintable(ei.eiOwner), "USER"); if(ei.eiOwner.redazione){ user.find("a").append("G"); }else if(ei.eiOwner.brand){ user.find("a").append("B") } var postJ = ei.eiPosts[0]; var post = buildPost(postJ); var container = $("#container"); domEmo.append(user); container.append(domEmo); if (post) insertPost( post ,domEmo); return domEmo; } function buildPost(post){ if(!post.postType) return; var domPost = $.JST.createFromTemplate(transformToPrintable(post),"POST_"+post.postType.toUpperCase()); for (var i = 0; i < post.postComments.length; i++) { var c = post.postComments[i]; var commentHTML = buildAndAddComment(post.postIsOwner, c, domPost.find(".comments")); } if(post.hasMore){ domPost.find(".comments").prepend($("
").addClass("moreComments").html("tutti i commenti").on("click",function () { var eiId = domPost.closest(".emoModule").attr("eiId") location.href = post.posturl; })); } if (isLogged) domPost.find(".comments").after($.JST.createFromTemplate(post, "COMMENT_EDITOR")); bindPostEvents(domPost,post); //domPost.append(user); return domPost; } function buildAndAddComment(postIsOwner, comment, ndo){ var commentHTML = $.JST.createFromTemplate(transformToPrintable(comment),"COMMENT"); if(comment.cmtIsOwner || postIsOwner ) commentHTML.find(".deleteComment").show(); if(isLogged){ if(isAdmin){ commentHTML.find(".banComment").show(); commentHTML.find(".banComment").click(function(){$(this).confirm(banComment, "Sei sicuro di voler bannare il post?")}); }else{ commentHTML.find(".reportComment").show(); commentHTML.find(".reportComment").click(function(){$(this).confirm(reportComment, "GIOIA_SURE_TO_REPORT")}); } } var content = commentHTML.find(".linkEnabled"); content.activateLinks(true); content.removeClass("linkEnabled"); ndo.append(commentHTML); } function insertPost(domPost, ndo) { if (!domPost) return; ndo.append(domPost); //domPost.show(); /*Manage the behavior for each type of post -----------------------------------------------------*/ //IMAGE var imageContainer = $(".imageContainer", domPost); if("IMAGE" == domPost.attr("type")){ var imageRatio = imageContainer.data("imageratio") || 1; var w = parseFloat(imageContainer.css("width")); imageContainer.css("height", (imageRatio * w)); } } /*Search methods -----------------------------------------------------*/ function searchByEmo(el){ var title ="Gioia! live"; $("#maintitle").html(title); $("html,body").scrollTop(0); var specificFilter = getFilterOrAll(el, "emozione"); checkPathOrRedirect('/emozione/'+specificFilter); $("#maintitle").html(title + ""+ specificFilter + " *"); changeDocumentTitle(specificFilter); var filter = getFilter(true); filter.emotion=specificFilter; filter.clearDesk=true; deskRefill(); } function searchByUser(userId){ var filter = getFilter(true); checkPathOrRedirect('/utente/'+userid); filter.clearDesk=true; filter.userId=userId; changeDocumentTitle( "Utente - " +userId); deskRefill(); } function changeDocumentTitle(title){ $(document).attr('title', title + ' - Gioia!'); } function searchSpecial(el){ var specificFilter = getFilterOrAll(el, "specialFilter"); var title = ""; if("amici"== specificFilter){ title = "Stai seguendo..."; }else if("brandambassador"== specificFilter){ title = "I brand ambassador di Gioia"; }else if("prodotti"== specificFilter){ title = "I prodotti di Gioia"; }else if("redazione"== specificFilter){ title ="Dalla redazione di Gioia"; } $("#maintitle").html(title) changeDocumentTitle(specificFilter); checkPathOrRedirect('/special/'+specificFilter); var filter = getFilter(true); filter.specialFilter=specificFilter; filter.clearDesk=true; deskRefill(); } function searchByPop(el){ var title ="I post più popolari di Gioia"; $("#maintitle").html(title); //check if we are on homepage or not var specificFilter = getFilterOrAll(el, "popular"); checkPathOrRedirect('/special/popolari'); var filter = getFilter(true); filter.popular = specificFilter; filter.clearDesk=true; deskRefill(); } function searchByTopic(el){ var title ="Parliamo di" + " "+ el.attr("topicName")+""; $("#maintitle").html(title); changeDocumentTitle(el.attr("topicName")); //console.debug(el.attr("topicName"), encodeURIComponent(el.attr("topicName"))); checkPathOrRedirect('/argomento/'+ encodeURIComponent(el.attr("topicName"))); // nella url serve il topic name var specificFilter = getFilterOrAll(el, "topic"); var filter = getFilter(true); filter.clearDesk=true; filter.topicId=specificFilter; deskRefill(); } function isIndex() { var parts = location.pathname; return parts.endsWith('/applications/gioia/write/index.jsp') || parts.endsWith('/applications/gioia/site/index.jsp') || parts == "/" || parts == ""; } function checkPathOrRedirect(redir){ if(!isGlobalIndex){ location.href = redir; }else{ if(window.history.pushState) window.history.pushState('gioia', 'Gioia', redir); else location.href = redir; } } function getFilter(reset){ if(reset) app.filter={} app.filter.CM="GET_POSTS"; return app.filter; } function deskRefill(callback){ var filter=getFilter(); ajaxFillPosts(filter, callback); } function deskLoadOlder(callback){ if ($("#container").attr("hasMore") != "true") return; var container = $("#container"); var filter= getFilter(); //todo get filter filter.pageNumber = parseInt(container.attr("pageNumber"))+1; ajaxFillPosts(filter, callback); } function addPost(){ var editor = createBlackPage(700, 500); editor.load('partPostEditor.jsp'); } function refreshPost(response){ $("#container").prepend(buildEI(response.ei)); } function getFilterOrAll (el, attr){ var spec = el.attr(attr); // var selected= el.hasClass("selected"); // $(".filterBar").find("a").removeClass("selected"); // if(selected){ // spec = ""; // }else{ // el.addClass("selected"); // } return spec; } //----------------------------------------------------------------- COMMENTS ---------------------------------------------------------------------------------- function deleteComment(el){ var params = {}; params.CM = "DELETE_COMMENT"; var cmt = el.closest(".commentLine"); params.cmtId = cmt.attr("cmtId"); $.getJSON('/applications/gioia/site/API/ajaxController.jsp', params, function(response){ if(response.ok){ cmt.fadeOut('slow',function() { cmt.remove(); $("#container").setMasonry(); }); } }); } function reportComment(el){ var params = {}; params.CM = "REPORT_COMMENT"; var cmt = el.closest(".commentLine"); params.cmtId = cmt.attr("cmtId"); $.getJSON('/applications/gioia/site/API/ajaxController.jsp', params, function(response){ if(response.ok){ el.html("Grazie per la segnalazione."); el.fadeOut(2500); } }); } function banComment(el){ var params = {}; params.CM = "BAN_COMMENT"; var cmt = el.closest(".commentLine"); params.cmtId = cmt.attr("cmtId"); $.getJSON('/applications/gioia/site/API/ajaxController.jsp', params, function(response){ if(response.ok){ cmt.fadeOut('slow',function() { cmt.remove(); }); } }); } function saveComment(el){ var text = el.closest(".newComment").find("textarea").val(); if(text){ var params = {}; params.CM = "SAVE_COMMENT"; params.postId= el.closest(".newComment").attr("postId"); params.cmtText= el.closest(".newComment").find("textarea").val() $.getJSON('/applications/gioia/site/API/ajaxController.jsp', params, function(response){ if(response.ok){ var commentHTML = $.JST.createFromTemplate(transformToPrintable(response.comment),"COMMENT"); buildAndAddComment (false, response.comment, el.closest(".post").find(".comments")); el.closest(".newComment").find("textarea").val(""); $("#container").setMasonry(); } }); } } /*Masonry methods -----------------------------------------------------*/ $.fn.setMasonry = function(anim){ anim = typeof anim == "undefined" ? true : anim; var duration = anim ? "1s" : "0"; this.masonry({ columnWidth: 0, itemSelector: '.item', //add animation to masonry ------------------ visibleStyle:{opacity: 1}, //, transform: 'scale(1)' hiddenStyle:{opacity: 0 }, //, transform: 'scale(1)' transitionDuration: duration }); this.get(0).masoneryInit = true; }; $.fn.destroyMasonry = function(){ if(!this.get(0).masoneryInit) return; this.masonry("destroy"); this.get(0).masoneryInit = false; }; /*Crop Image methods -----------------------------------------------------*/ $.fn.cropImage = function(opt){ var defaults = { ratio : 0, minSize: [0,0], maxSize: [0,0], cropWidth: 512, cropHeight: 0, setSelect: [ 0, 0, 512, 512 ], onCrop : function(){}, onStart : function(){} }; $.extend(defaults, opt); var imageToCrop = this.is("img") ? this : this.children("img:first"); var jcrop_api; var cropResult = $("").attr({id:"cropResult", width:0, height:0}).css({background:"#fff"}); imageToCrop.after(cropResult); var cropAction = $("