From 77d05865d70bbd6b36b5346c303ee6d86b49adf8 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 13 Dec 2016 10:31:58 +0800 Subject: [PATCH] #60 Fixed reposition page's JS bug when using Boost --- .../moodle-mod_customcert-rearrange-debug.js | 4 ++-- .../moodle-mod_customcert-rearrange-min.js | 2 +- .../moodle-mod_customcert-rearrange.js | 4 ++-- yui/src/rearrange/js/rearrange.js | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-debug.js b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-debug.js index 45da5ad..b3ad478 100644 --- a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-debug.js +++ b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-debug.js @@ -147,12 +147,12 @@ Y.extend(Rearrange, Y.Base, { */ create_events : function() { // Trigger a save event when save button is pushed. - Y.one('.savepositionsbtn input[type=submit]').on('click', function(e) { + Y.one('.savepositionsbtn [type=submit]').on('click', function(e) { this.save_positions(e); }, this); // Trigger a save event when apply button is pushed. - Y.one('.applypositionsbtn input[type=submit]').on('click', function(e) { + Y.one('.applypositionsbtn [type=submit]').on('click', function(e) { this.save_positions(e); e.preventDefault(); }, this); diff --git a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-min.js b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-min.js index 657bb8b..30a83cd 100644 --- a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-min.js +++ b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-min.js @@ -1 +1 @@ -YUI.add("moodle-mod_customcert-rearrange",function(e,t){var n=function(){n.superclass.constructor.apply(this,[arguments])};e.extend(n,e.Base,{templateid:0,page:[],elements:[],pdfx:0,pdfy:0,pdfwidth:0,pdfheight:0,elementxy:0,pdfleftboundary:0,pdfrightboundary:0,pixelsinmm:3.779527559055,initializer:function(t){this.templateid=t[0],this.page=t[1],this.elements=t[2],this.pdfx=e.one("#pdf").getX(),this.pdfy=e.one("#pdf").getY(),this.pdfwidth=parseFloat(e.one("#pdf").getComputedStyle("width"),10),this.pdfheight=parseFloat(e.one("#pdf").getComputedStyle("height"),10),this.pdfleftboundary=this.pdfx,this.page.leftmargin&&(this.pdfleftboundary+=parseInt(this.page.leftmargin*this.pixelsinmm,10)),this.pdfrightboundary=this.pdfx+this.pdfwidth,this.page.rightmargin&&(this.pdfrightboundary-=parseInt(this.page.rightmargin*this.pixelsinmm,10)),this.set_data(),this.set_positions(),this.create_events()},set_data:function(){for(var t in this.elements){var n=this.elements[t];e.one("#element-"+n.id).setData("refpoint",n.refpoint)}},set_positions:function(){for(var t in this.elements){var n=this.elements[t],r=this.pdfx+n.posx*this.pixelsinmm,i=this.pdfy+n.posy*this.pixelsinmm,s=parseFloat(e.one("#element-"+n.id).getComputedStyle("width"),10),o=n.width*this.pixelsinmm;o&&s>o&&(s=o);switch(n.refpoint){case"1":r-=s/2;break;case"2":r=r-s+2}e.one("#element-"+n.id).setX(r),e.one("#element-"+n.id).setY(i)}},create_events:function(){e.one(".savepositionsbtn input[type=submit]").on("click",function(e){this.save_positions(e)},this),e.one(".applypositionsbtn input[type=submit]").on("click",function(e){this.save_positions(e),e.preventDefault()},this);var t=new e.DD.Delegate({container:"#pdf",nodes:".element"});t.on("drag:start",function(){var e=t.get("currentNode");this.elementxy=e.getXY()},this),t.on("drag:end",function(){var e=t.get("currentNode");this.is_out_of_bounds(e)&&e.setXY(this.elementxy)},this)},is_out_of_bounds:function(e){var t=parseFloat(e.getComputedStyle("width"),10),n=parseFloat(e.getComputedStyle("height"),10),r=e.getX(),i=r+t,s=e.getY(),o=s+n;return rthis.pdfrightboundary?!0:sthis.pdfy+this.pdfheight?!0:!1},save_positions:function(t){var n={tid:this.templateid,values:[]};for(var r in this.elements){var i=this.elements[r],s=e.one("#element-"+i.id),o=s.getX()-this.pdfx,u=s.getY()-this.pdfy,a=parseFloat(s.getComputedStyle("width"),10);switch(i.refpoint){case"1":o+=a/2;break;case"2":o+=a}n.values.push({id:i.id,posx:Math.round(parseFloat(o/this.pixelsinmm,10)),posy:Math.round(parseFloat(u/this.pixelsinmm,10))})}n.values=JSON.stringify(n.values),e.io(M.cfg.wwwroot+"/mod/customcert/ajax.php",{method:"POST",data:n,on:{failure:function(e,t){this.ajax_failure(t)},success:function(){var e=t.currentTarget.ancestor("form",!0),n=e.getAttribute("action"),r=e.one("[name=pid]");if(r){var i=r.get("value");window.location=n+"?pid="+i}else{var s=e.one("[name=tid]").get("value");window.location=n+"?tid="+s}}},context:this}),t.preventDefault()},ajax_failure:function(e){var t={name:e.status+" "+e.statusText,message:e.responseText};return new M.core.exception(t)}}),M.mod_customcert=M.mod_customcert||{},M.mod_customcert.rearrange=M.mod_customcert.rearrange||{},M.mod_customcert.rearrange.init=function(e,t,r){new n(e,t,r)}},"@VERSION@",{requires:["dd-delegate","dd-drag"]}); +YUI.add("moodle-mod_customcert-rearrange",function(e,t){var n=function(){n.superclass.constructor.apply(this,[arguments])};e.extend(n,e.Base,{templateid:0,page:[],elements:[],pdfx:0,pdfy:0,pdfwidth:0,pdfheight:0,elementxy:0,pdfleftboundary:0,pdfrightboundary:0,pixelsinmm:3.779527559055,initializer:function(t){this.templateid=t[0],this.page=t[1],this.elements=t[2],this.pdfx=e.one("#pdf").getX(),this.pdfy=e.one("#pdf").getY(),this.pdfwidth=parseFloat(e.one("#pdf").getComputedStyle("width"),10),this.pdfheight=parseFloat(e.one("#pdf").getComputedStyle("height"),10),this.pdfleftboundary=this.pdfx,this.page.leftmargin&&(this.pdfleftboundary+=parseInt(this.page.leftmargin*this.pixelsinmm,10)),this.pdfrightboundary=this.pdfx+this.pdfwidth,this.page.rightmargin&&(this.pdfrightboundary-=parseInt(this.page.rightmargin*this.pixelsinmm,10)),this.set_data(),this.set_positions(),this.create_events()},set_data:function(){for(var t in this.elements){var n=this.elements[t];e.one("#element-"+n.id).setData("refpoint",n.refpoint)}},set_positions:function(){for(var t in this.elements){var n=this.elements[t],r=this.pdfx+n.posx*this.pixelsinmm,i=this.pdfy+n.posy*this.pixelsinmm,s=parseFloat(e.one("#element-"+n.id).getComputedStyle("width"),10),o=n.width*this.pixelsinmm;o&&s>o&&(s=o);switch(n.refpoint){case"1":r-=s/2;break;case"2":r=r-s+2}e.one("#element-"+n.id).setX(r),e.one("#element-"+n.id).setY(i)}},create_events:function(){e.one(".savepositionsbtn [type=submit]").on("click",function(e){this.save_positions(e)},this),e.one(".applypositionsbtn [type=submit]").on("click",function(e){this.save_positions(e),e.preventDefault()},this);var t=new e.DD.Delegate({container:"#pdf",nodes:".element"});t.on("drag:start",function(){var e=t.get("currentNode");this.elementxy=e.getXY()},this),t.on("drag:end",function(){var e=t.get("currentNode");this.is_out_of_bounds(e)&&e.setXY(this.elementxy)},this)},is_out_of_bounds:function(e){var t=parseFloat(e.getComputedStyle("width"),10),n=parseFloat(e.getComputedStyle("height"),10),r=e.getX(),i=r+t,s=e.getY(),o=s+n;return rthis.pdfrightboundary?!0:sthis.pdfy+this.pdfheight?!0:!1},save_positions:function(t){var n={tid:this.templateid,values:[]};for(var r in this.elements){var i=this.elements[r],s=e.one("#element-"+i.id),o=s.getX()-this.pdfx,u=s.getY()-this.pdfy,a=parseFloat(s.getComputedStyle("width"),10);switch(i.refpoint){case"1":o+=a/2;break;case"2":o+=a}n.values.push({id:i.id,posx:Math.round(parseFloat(o/this.pixelsinmm,10)),posy:Math.round(parseFloat(u/this.pixelsinmm,10))})}n.values=JSON.stringify(n.values),e.io(M.cfg.wwwroot+"/mod/customcert/ajax.php",{method:"POST",data:n,on:{failure:function(e,t){this.ajax_failure(t)},success:function(){var e=t.currentTarget.ancestor("form",!0),n=e.getAttribute("action"),r=e.one("[name=pid]");if(r){var i=r.get("value");window.location=n+"?pid="+i}else{var s=e.one("[name=tid]").get("value");window.location=n+"?tid="+s}}},context:this}),t.preventDefault()},ajax_failure:function(e){var t={name:e.status+" "+e.statusText,message:e.responseText};return new M.core.exception(t)}}),M.mod_customcert=M.mod_customcert||{},M.mod_customcert.rearrange=M.mod_customcert.rearrange||{},M.mod_customcert.rearrange.init=function(e,t,r){new n(e,t,r)}},"@VERSION@",{requires:["dd-delegate","dd-drag"]}); diff --git a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange.js b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange.js index 45da5ad..b3ad478 100644 --- a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange.js +++ b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange.js @@ -147,12 +147,12 @@ Y.extend(Rearrange, Y.Base, { */ create_events : function() { // Trigger a save event when save button is pushed. - Y.one('.savepositionsbtn input[type=submit]').on('click', function(e) { + Y.one('.savepositionsbtn [type=submit]').on('click', function(e) { this.save_positions(e); }, this); // Trigger a save event when apply button is pushed. - Y.one('.applypositionsbtn input[type=submit]').on('click', function(e) { + Y.one('.applypositionsbtn [type=submit]').on('click', function(e) { this.save_positions(e); e.preventDefault(); }, this); diff --git a/yui/src/rearrange/js/rearrange.js b/yui/src/rearrange/js/rearrange.js index fe30e98..722cc70 100644 --- a/yui/src/rearrange/js/rearrange.js +++ b/yui/src/rearrange/js/rearrange.js @@ -145,12 +145,12 @@ Y.extend(Rearrange, Y.Base, { */ create_events : function() { // Trigger a save event when save button is pushed. - Y.one('.savepositionsbtn input[type=submit]').on('click', function(e) { + Y.one('.savepositionsbtn [type=submit]').on('click', function(e) { this.save_positions(e); }, this); // Trigger a save event when apply button is pushed. - Y.one('.applypositionsbtn input[type=submit]').on('click', function(e) { + Y.one('.applypositionsbtn [type=submit]').on('click', function(e) { this.save_positions(e); e.preventDefault(); }, this);