addStyleSheet(JURI::root(1) . '/modules/mod_hot_joomla_zoomer/elements/zeditor.css'); // Initialize some field attributes. $size = $this->element['size'] ? ' size="'.(int) $this->element['size'].'"' : ''; $maxLength = $this->element['maxlength'] ? ' maxlength="'.(int) $this->element['maxlength'].'"' : ''; $id = $this->element['id'] ? ' id="'.(string) $this->element['id'].'"' : ''; $previewid = $this->element['previewid'] ? ' id="'.(string) $this->element['previewid'].'"' : ''; $readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : ''; $disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : ''; // Initialize JavaScript field attributes. $onchange = $this->element['onchange'] ? ' onchange="'.(string) $this->element['onchange'].'"' : ''; $html = array(); $class = $this->element['class'] ? (string) $this->element['class'] : 'zeditor'; $value = htmlspecialchars(html_entity_decode($this->value, ENT_QUOTES), ENT_QUOTES); ob_start(); //---------------------------------------------- ?> addScriptDeclaration(' var zQuery = jQuery; var zoomerPrevImageSkipMeasure = true; zQuery("#zoomerEditorDialog button").button(); var zoomer_aspectRat = 1; var zoomerPMDragArgs = null; var zoomerPMResArgs = null; function zoomerCalculatePreviewPos(el){ var val = [0,0,1]; var top = zQuery(el).offset().top - zQuery(el).parent().offset().top - 1; var left = zQuery(el).offset().left - zQuery(el).parent().offset().left - 1; var width = zQuery(el).innerWidth(); var height = zQuery(el).innerHeight(); var pwidth = zQuery(el).parent().innerWidth(); var pheight = zQuery(el).parent().innerHeight(); if(!(pwidth - width == 0)) val[0] = Math.round((left / (pwidth - width)) * 100)/100;else val[0] = 1; if(!(pheight - height == 0)) val[1] = Math.round((top / (pheight - height)) * 100)/100;else val[1] = 1; var sc = width/pwidth; if( height/pheight > sc) sc = height/pheight; if(sc != 0)val[2] = Math.round((1/sc) * 100)/100;else val[2] = 1; return val; } function zoomerSetPreviewPos(val_f,val_t) { var refW = true; var pwidth = zQuery("#zoomerPerViewContainer").innerWidth(); var pheight = zQuery("#zoomerPerViewContainer").innerHeight(); var width; var height; var top; var left; if( pheight < pwidth) refW = false; if(val_f){ try{ if(refW){ width = pwidth/val_f[2] - 4; height = width * (1/zoomer_aspectRat) - 4; } else{ height = pheight/val_f[2] - 4; width = height * zoomer_aspectRat - 4 ; } left = (pwidth - width - 3) * val_f[0] + zQuery("#zoomerPerViewContainer").position().left + 1; top = (pheight - height - 4) * val_f[1] + zQuery("#zoomerPerViewContainer").position().top + 1; zQuery("#zoomerVisualMesureFromResizer").css({ width: String(width) + "px", height: String(height) + "px" }); zQuery("#zoomerVisualMesureFrom").css({ left: String(left) + "px", top: String(top) + "px" }); }catch(Exf){ // } } if(val_t){ try{ if(refW){ width = pwidth/val_t[2] - 4; height = width * (1/zoomer_aspectRat) - 4; } else{ height = pheight/val_t[2] - 4; width = height * zoomer_aspectRat - 4; } left = (pwidth - width - 3) * val_t[0] + zQuery("#zoomerPerViewContainer").position().left + 1; top = (pheight - height - 4) * val_t[1] + zQuery("#zoomerPerViewContainer").position().top + 1; zQuery("#zoomerVisualMesureToResizer").css({ width: String(width) + "px", height: String(height) + "px" }); zQuery("#zoomerVisualMesureTo").css({ left: String(left) + "px", top: String(top) + "px" }); }catch(Ext){ // } } } var zdata_loaded = false; function ShowZoomerModal() { zdata_loaded = false; zQuery("#zoomerNoLoadMessage").css({"display":"block"}); zQuery("#zoomerUserEditTable").css({"display":"none"}); zoomer_aspectRat = parseFloat(zQuery("#jform_params_viewWidth").val()) / parseFloat(zQuery("#jform_params_viewHeight").val()); if(!zoomer_aspectRat)zoomer_aspectRat = 1; zQuery("#zoomerVisualMesureFrom > DIV, #zoomerVisualMesureTo > DIV").innerWidth( Math.round(30 * zoomer_aspectRat)).innerHeight(30); zQuery("#zoomerVisualMesureFrom .ui-resizable, #zoomerVisualMesureTo .ui-resizable").resizable( "option", "aspectRatio", zoomer_aspectRat ); zQuery("#zoomerEditorDialog").dialog({ modal: true, closeOnEscape: true, resizable: true, draggable: true, width: 860, resizeStop: function(event, ui){ zQuery("#zoomerEditorListView").innerHeight(ui.size.height - 150); zQuery("#zoomerEditorListView").innerWidth(ui.size.width - 390 ); zQuery("#zoomerEditorToolbar").innerWidth(ui.size.width - 390 ); }, title:"'. JText::sprintf("HOT Joomla Zoomer - Edit Images For Zoomer Module") . '", buttons: [ { text: "OK", width: "100", height: "22", click: function () { var Val = new Array(); zQuery("#zoomerEditorList tr").each(function(ind){ if(ind > 0){ if(zQuery(this).attr("k_src")) Val[ind-1]= { src: zQuery(this).attr("k_src"), item_duration: zQuery(this).attr("k_item_duration"), animation_duration: zQuery(this).attr("k_animation_duration"), animationEasing: zQuery(this).attr("k_animationEasing"), from: zQuery(this).attr("k_from").split(","), to: zQuery(this).attr("k_to").split(","), title: zQuery(this).attr("k_title"), link: zQuery(this).attr("k_link"), width: zQuery(this).attr("k_width"), height:zQuery(this).attr("k_height") }; } }); zQuery("' . $this->id . '").val(JSON.stringify(Val)); zQuery("#zoomerEditorDialog").dialog("close"); } }, { text: "Cancel", click: function () { zQuery("#zoomerEditorDialog").dialog("close"); } }, ], close: function (ev, ui) { zQuery(this).dialog("destroy"); //zQuery(this).remove(); } }); LoadZoomerData(); // zQuery("#zoomerEditorDialog").dialog("open"); return false; } function onSelectZoomerListRow(row){ if(row.hasClass("current")) return false; zoomerPrevImageSkipMeasure = true; zQuery("#zoomerEditorList .current").removeClass("current").removeClass("ui-widget-header"); row.addClass("current").addClass("ui-widget-header"); zQuery("#zoomerNoLoadMessage").css({display:"none"}); zQuery("#zoomerUserEditTable").css({display:"block"}); ShowZoomerCurrent(); return false; } function Zoomer_AddRow(item){ if(!item) item = {}; var zoomer_row = zQuery("" + String(zQuery("#zoomerEditorList tr").length) + "" + (item.src ? item.src : "") + ""); zQuery("#zoomerEditorList").append(zoomer_row); zoomer_row.click(function(){ onSelectZoomerListRow(zoomer_row); }); try{ zoomer_row.attr("k_src",(item.src ? item.src : "")); zoomer_row.attr("k_item_duration",(item.item_duration ? item.item_duration : "8000") ); zoomer_row.attr("k_animation_duration",(item.animation_duration ? item.animation_duration : "4000") ); zoomer_row.attr("k_animationEasing",(item.animationEasing ? item.animationEasing : "linear")); zoomer_row.attr("k_from", (item.from ? (String(item.from[0]) + "," + String(item.from[1]) + "," + String(item.from[2])) : "0,0,1" )); zoomer_row.attr("k_to", (item.to ? (String(item.to[0]) + "," + String(item.to[1]) + "," + String(item.to[2])) : "1,1,1" )); zoomer_row.attr("k_title",(item.title ? item.title : "" )); zoomer_row.attr("k_link",(item.link ? item.link : "")); zoomer_row.attr("k_width",(item.width ? item.width : "0")); zoomer_row.attr("k_height",(item.height ? item.height : "0") ); }catch(e){ // } return zoomer_row; } function LoadZoomerData() { if(zdata_loaded) return; zdata_loaded = true; var sVal = zQuery("#' . $this->id . '").val(); if(!sVal)sVal = "[]"; var zoomerData = eval("(" + sVal + ")"); while(zQuery("#zoomerEditorList").find("TR").length > 1){ zQuery("#zoomerEditorList").find("TR").last().remove(); } if(zoomerData.length > 0){ for(var i = 0 ; i < zoomerData.length ; i++){ Zoomer_AddRow(zoomerData[i]); } if(zQuery("#zoomerEditorList tr")[1]){ setTimeout(function(){ zQuery(zQuery("#zoomerEditorList tr")[1]).click(); },100); } } return false; } var onZoomerUserValueChangeDisabled = false; function ShowZoomerCurrent(){ onZoomerUserValueChangeDisabled = true; var condition = zQuery("#zoomerUserEditTable INPUT,#zoomerUserEditTable SELECT"); if(condition) { condition.each(function(){ if(zQuery("#zoomerEditorList .current")[0]){ var attr = false; try { attr = zQuery(this).val(zQuery("#zoomerEditorList .current").attr(zQuery(this).attr("id"))); } catch(error) { console.error("XXXX"); console.error(error); } if (typeof attr=== "undefined" && attr === false) { console.log("attr1 is undefined"); return; } }else{ zQuery(this).val(null); } }); } zQuery("#zoomerPreviewImage").attr("src", zQuery("#zoomerUserEditTable #k_src").val()); onZoomerUserValueChangeDisabled = false; return false; } function onZoomerUserValueChange(){ // if(onZoomerUserValueChangeDisabled) // return; zQuery("#zoomerUserEditTable INPUT,#zoomerUserEditTable SELECT").each(function(){ if(zQuery("#zoomerEditorList .current")[0]){ if(zQuery(this).attr("id") == "k_src"){ if(zQuery("#zoomerEditorList .current").attr(zQuery(this).attr("id")) != zQuery(this).val()){ zQuery("#zoomerEditorList .current").attr(zQuery(this).attr("id"),zQuery(this).val()); zQuery(zQuery("#zoomerEditorList .current").find("TD")[1]).html(zQuery(this).val()); setzoomerPreviewImage(zQuery(this).val()); } }else{ zQuery("#zoomerEditorList .current").attr(zQuery(this).attr("id"),zQuery(this).val()); } if(zQuery(this).attr("id") == "k_from" || zQuery(this).attr("id") == "k_to"){ zoomerSetPreviewPos(zQuery("#k_from").val().split(","),zQuery("#k_to").val().split(",")); } } }); return false; } function setzoomerPreviewImage(src){ if(!zoomerPrevImageSkipMeasure){ zQuery("#zoomerPreviewImage").removeAttr("width"); zQuery("#zoomerPreviewImage").removeAttr("height"); zQuery("#zoomerPreviewImage").parent().css({overflow:"hidden"}); } zQuery("#zoomerPreviewImage").attr("src",src); return false; } function zoomerImageMeasure(){ if(!zoomerPrevImageSkipMeasure){ var w = zQuery("#zoomerPreviewImage").innerWidth(); var h = zQuery("#zoomerPreviewImage").innerHeight(); zQuery("#k_width").val(w); zQuery("#k_height").val(h); zQuery("#zoomerEditorList .current").attr("k_width",w); zQuery("#zoomerEditorList .current").attr("k_height",h); zQuery("#zoomerPreviewImage").parent().css({overflow:"auto"}); zQuery("#zoomerPreviewImage").attr("width" , "300px"); zQuery("#zoomerPreviewImage").parent().css({width:"300px"}); zQuery("#zoomerPreviewImage").attr("height", String((h/w)*300) + "px"); zoomerPrevImageSkipMeasure = true; } zoomerSetPreviewPos(zQuery("#k_from").val().split(","),zQuery("#k_to").val().split(",")); return false; } function onZoomerDeleteItem(){ if(zQuery("#zoomerEditorList .current")[0]){ var No = parseInt( zQuery("#zoomerEditorList .current td").html()); var Next = zQuery("#zoomerEditorList .current").next(); while(Next[0]){ zQuery(Next.find("TD")[0]).html(No); No++; Next = Next.next(); } zQuery("#zoomerEditorList .current").remove(); }else alert("' . JText::sprintf("First Select Item For Removal!") . '"); return false; } zQuery(document).ready(function(){ zoomer_aspectRat = parseFloat(zQuery("#jform_params_viewWidth").val()) / parseFloat(zQuery("#jform_params_viewHeight").val()); zQuery("#zoomerUserEditTable INPUT,#zoomerUserEditTable SELECT").change(function(){onZoomerUserValueChange();}); zQuery("#zoomerVisualMesureFrom > DIV, #zoomerVisualMesureTo > DIV").innerWidth( Math.round(30 * zoomer_aspectRat)).innerHeight(30); zQuery("#zoomerVisualMesureFrom, #zoomerVisualMesureTo").draggable({ containment: "parent", drag: function(event, ui){ var updEl = null; if(zQuery(this).attr("id") == "zoomerVisualMesureFrom") updEl = zQuery("#k_from"); else updEl = zQuery("#k_to"); var val = zoomerCalculatePreviewPos(this); updEl.val( String(val[0]) + "," + String(val[1]) + "," + String(val[2]) ); zQuery("#zoomerEditorList .current").attr("k_from",zQuery("#k_from").val()); zQuery("#zoomerEditorList .current").attr("k_to",zQuery("#k_to").val()); } }); zQuery("#zoomerVisualMesureFrom > DIV:not(.ui-resizable), #zoomerVisualMesureTo > DIV:not(.ui-resizable)").resizable({ containment: "#zoomerPerViewContainer", aspectRatio: zoomer_aspectRat, resize: function(event, ui) { var updEl = null; if(zQuery(this).parent().attr("id") == "zoomerVisualMesureFrom") updEl = zQuery("#k_from"); else updEl = zQuery("#k_to"); var val = zoomerCalculatePreviewPos(zQuery(this).parent()[0]); updEl.val( String(val[0]) + "," + String(val[1]) + "," + String(val[2]) ); zQuery("#zoomerEditorList .current").attr("k_from",zQuery("#k_from").val()); zQuery("#zoomerEditorList .current").attr("k_to",zQuery("#k_to").val()); } }); zQuery("#zoomer_cmdAdd").click(function(){ Zoomer_AddRow(null); zQuery("#zoomerVisualMesureFrom, #zoomerVisualMesureTo").each(function(){ if(zQuery(this).parent().position().left) { zQuery(this).css({ left: String(zQuery(this).parent().position().left) + "px", top: String(zQuery(this).parent().position().top) + "px" }); } }); zQuery("#zoomerVisualMesureFrom > DIV, #zoomerVisualMesureTo > DIV").innerWidth( Math.round(30 * zoomer_aspectRat)).innerHeight(30); }); zQuery("#zoomer_cmdRemove").click(function(){ onZoomerDeleteItem(); return false; }); zQuery("#zoomer_cmdUP").click(function(){ if(zQuery("#zoomerEditorList .current")[0]){ var curr = zQuery(zQuery("#zoomerEditorList .current")[0]); var No = zQuery(curr.find("TD")[0]).html(); var prev = curr.prev(); if(prev[0]){ if(prev.find("TH").length == 0){ zQuery(curr.find("TD")[0]).html( zQuery(prev.find("TD")[0]).html() ); zQuery(prev.find("TD")[0]).html(No); curr.insertBefore(prev); } } } }); zQuery("#zoomer_cmdDown").click(function(){ if(zQuery("#zoomerEditorList .current")[0]){ var curr = zQuery(zQuery("#zoomerEditorList .current")[0]); var No = zQuery(curr.find("TD")[0]).html(); var next = curr.next(); if(next[0]){ zQuery(curr.find("TD")[0]).html( zQuery(next.find("TD")[0]).html()); zQuery(next.find("TD")[0]).html(No); curr.insertAfter(next); } } }); zQuery("#k_src").click(function(){ zoomerPrevImageSkipMeasure = false; }).mousedown(function(){ zoomerPrevImageSkipMeasure = false; }); zQuery("#cmdShowEditDialog").click(function(e){ e.preventDefault(); console.log("$P -> calling showZoomerModal"); ShowZoomerModal(); }); }); '); ?>