#64 Fixed incorrect element position after changing reference point
This commit is contained in:
parent
2c3f6d1419
commit
62f73e3db8
7 changed files with 51 additions and 81 deletions
2
amd/build/rearrange-area.min.js
vendored
2
amd/build/rearrange-area.min.js
vendored
|
@ -1 +1 @@
|
|||
define(["jquery","core/yui","core/fragment","mod_customcert/dialogue","core/notification","core/str","core/templates","core/ajax"],function(a,b,c,d,e,f,g,h){var i=function(b){this._node=a(b),this._setEvents()};return i.prototype.CUSTOMCERT_REF_POINT_TOPLEFT=0,i.prototype.CUSTOMCERT_REF_POINT_TOPCENTER=1,i.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT=2,i.prototype._setEvents=function(){this._node.on("click",".element",this._editElement.bind(this))},i.prototype._editElement=function(a){var g=a.currentTarget.id.substr(8),h=this._node.attr("data-contextid"),i={elementid:g};c.loadFragment("mod_customcert","editelement",h,i).done(function(a,c){f.get_string("editelement","mod_customcert").done(function(e){b.use("moodle-core-formchangechecker",function(){new d(e,"<div id='elementcontent'></div>",this._editElementDialogueConfig.bind(this,g,a,c),(void 0),(!0))}.bind(this))}.bind(this))}.bind(this)).fail(e.exception)},i.prototype._editElementDialogueConfig=function(b,c,d,e){g.replaceNode("#elementcontent",c,d);var f=a(e.getContent());f.on("click","#id_submitbutton",function(c){M.core_formchangechecker.reset_form_dirty_state(),this._saveElement(b).then(function(){this._getElementHTML(b).done(function(c){var d=this._node.find("#element-"+b),f=a("#id_refpoint").val(),g="";f==this.CUSTOMCERT_REF_POINT_TOPLEFT?g="refpoint-left":f==this.CUSTOMCERT_REF_POINT_TOPCENTER?g="refpoint-center":f==this.CUSTOMCERT_REF_POINT_TOPRIGHT&&(g="refpoint-right"),d.empty().append(c),d.removeClass(),d.addClass("element "+g),this._setPosition(b,f),e.close()}.bind(this))}.bind(this)),c.preventDefault()}.bind(this)),f.on("click","#id_cancel",function(a){e.close(),a.preventDefault()}.bind(this))},i.prototype._setPosition=function(c,d){var e=b.one("#element-"+c),f=3.779527559055,g=b.one("#pdf").getX(),h=b.one("#pdf").getY(),i=g+a("#editelementform #id_posx").val()*f,j=h+a("#editelementform #id_posy").val()*f,k=parseFloat(e.getComputedStyle("width")),l=e.width*this.pixelsinmm;switch(l&&k>l&&(k=l),d){case"1":i-=k/2;break;case"2":i=i-k+2}e.setX(i),e.setY(j)},i.prototype._getElementHTML=function(a){var b=this._node.attr("data-templateid"),c=h.call([{methodname:"mod_customcert_get_element_html",args:{templateid:b,elementid:a}}]);return c[0]},i.prototype._saveElement=function(b){var c=this._node.attr("data-templateid"),d=a("#editelementform").serializeArray(),e=h.call([{methodname:"mod_customcert_save_element",args:{templateid:c,elementid:b,values:d}}]);return e[0]},{init:function(a){new i(a)}}});
|
||||
define(["jquery","core/yui","core/fragment","mod_customcert/dialogue","core/notification","core/str","core/templates","core/ajax"],function(a,b,c,d,e,f,g,h){var i=function(b){this._node=a(b),this._setEvents()};return i.prototype.CUSTOMCERT_REF_POINT_TOPLEFT=0,i.prototype.CUSTOMCERT_REF_POINT_TOPCENTER=1,i.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT=2,i.prototype.PIXELSINMM=3.779527559055,i.prototype._setEvents=function(){this._node.on("click",".element",this._editElement.bind(this))},i.prototype._editElement=function(a){var g=a.currentTarget.id.substr(8),h=this._node.attr("data-contextid"),i={elementid:g};c.loadFragment("mod_customcert","editelement",h,i).done(function(a,c){f.get_string("editelement","mod_customcert").done(function(e){b.use("moodle-core-formchangechecker",function(){new d(e,"<div id='elementcontent'></div>",this._editElementDialogueConfig.bind(this,g,a,c),(void 0),(!0))}.bind(this))}.bind(this))}.bind(this)).fail(e.exception)},i.prototype._editElementDialogueConfig=function(b,c,d,e){g.replaceNode("#elementcontent",c,d);var f=a(e.getContent());f.on("click","#id_submitbutton",function(c){M.core_formchangechecker.reset_form_dirty_state(),this._saveElement(b).then(function(){this._getElementHTML(b).done(function(c){var d=this._node.find("#element-"+b),f=parseInt(a("#id_refpoint").val()),g="";f==this.CUSTOMCERT_REF_POINT_TOPLEFT?g="refpoint-left":f==this.CUSTOMCERT_REF_POINT_TOPCENTER?g="refpoint-center":f==this.CUSTOMCERT_REF_POINT_TOPRIGHT&&(g="refpoint-right"),d.empty().append(c),d.removeClass(),d.addClass("element "+g),d.attr("data-refpoint",f);var h=a("#editelementform #id_posx").val(),i=a("#editelementform #id_posy").val();this._setPosition(b,f,h,i),e.close()}.bind(this))}.bind(this)),c.preventDefault()}.bind(this)),f.on("click","#id_cancel",function(a){e.close(),a.preventDefault()}.bind(this))},i.prototype._setPosition=function(a,c,d,e){var f=b.one("#element-"+a),d=b.one("#pdf").getX()+d*this.PIXELSINMM,e=b.one("#pdf").getY()+e*this.PIXELSINMM,g=parseFloat(f.getComputedStyle("width")),h=f.width*this.PIXELSINMM;switch(h&&g>h&&(g=h),c){case this.CUSTOMCERT_REF_POINT_TOPCENTER:d-=g/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:d=d-g+2}f.setX(d),f.setY(e)},i.prototype._getElementHTML=function(a){var b=this._node.attr("data-templateid"),c=h.call([{methodname:"mod_customcert_get_element_html",args:{templateid:b,elementid:a}}]);return c[0]},i.prototype._saveElement=function(b){var c=this._node.attr("data-templateid"),d=a("#editelementform").serializeArray(),e=h.call([{methodname:"mod_customcert_save_element",args:{templateid:c,elementid:b,values:d}}]);return e[0]},{init:function(a){new i(a)}}});
|
|
@ -38,6 +38,7 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/
|
|||
RearrangeArea.prototype.CUSTOMCERT_REF_POINT_TOPLEFT = 0;
|
||||
RearrangeArea.prototype.CUSTOMCERT_REF_POINT_TOPCENTER = 1;
|
||||
RearrangeArea.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT = 2;
|
||||
RearrangeArea.prototype.PIXELSINMM = 3.779527559055;
|
||||
|
||||
RearrangeArea.prototype._setEvents = function() {
|
||||
this._node.on('click', '.element', this._editElement.bind(this));
|
||||
|
@ -79,7 +80,7 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/
|
|||
// Update the DOM to reflect the adjusted value.
|
||||
this._getElementHTML(elementid).done(function(html) {
|
||||
var elementNode = this._node.find('#element-' + elementid);
|
||||
var refpoint = $('#id_refpoint').val();
|
||||
var refpoint = parseInt($('#id_refpoint').val());
|
||||
var refpointClass = '';
|
||||
if (refpoint == this.CUSTOMCERT_REF_POINT_TOPLEFT) {
|
||||
refpointClass = 'refpoint-left';
|
||||
|
@ -92,8 +93,12 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/
|
|||
// Update the ref point.
|
||||
elementNode.removeClass();
|
||||
elementNode.addClass('element ' + refpointClass);
|
||||
// Move the element if we need to.
|
||||
this._setPosition(elementid, refpoint);
|
||||
elementNode.attr('data-refpoint', refpoint);
|
||||
// Move the element.
|
||||
var posx = $('#editelementform #id_posx').val();
|
||||
var posy = $('#editelementform #id_posy').val();
|
||||
this._setPosition(elementid, refpoint, posx, posy);
|
||||
// All done.
|
||||
popup.close();
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
|
@ -106,26 +111,23 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/
|
|||
}.bind(this));
|
||||
};
|
||||
|
||||
RearrangeArea.prototype._setPosition = function(elementid, refpoint) {
|
||||
RearrangeArea.prototype._setPosition = function(elementid, refpoint, posx, posy) {
|
||||
var element = Y.one('#element-' + elementid);
|
||||
|
||||
var pixelsinmm = 3.779527559055;
|
||||
var pdfx = Y.one('#pdf').getX();
|
||||
var pdfy = Y.one('#pdf').getY();
|
||||
var posx = pdfx + $('#editelementform #id_posx').val() * pixelsinmm;
|
||||
var posy = pdfy + $('#editelementform #id_posy').val() * pixelsinmm;
|
||||
var posx = Y.one('#pdf').getX() + posx * this.PIXELSINMM;
|
||||
var posy = Y.one('#pdf').getY() + posy * this.PIXELSINMM;
|
||||
var nodewidth = parseFloat(element.getComputedStyle('width'));
|
||||
var maxwidth = element.width * this.pixelsinmm;
|
||||
var maxwidth = element.width * this.PIXELSINMM;
|
||||
|
||||
if (maxwidth && (nodewidth > maxwidth)) {
|
||||
nodewidth = maxwidth;
|
||||
}
|
||||
|
||||
switch (refpoint) {
|
||||
case '1': // Top-center.
|
||||
case this.CUSTOMCERT_REF_POINT_TOPCENTER:
|
||||
posx -= nodewidth / 2;
|
||||
break;
|
||||
case '2': // Top-right.
|
||||
case this.CUSTOMCERT_REF_POINT_TOPRIGHT:
|
||||
posx = posx - nodewidth + 2;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,8 @@ if ($elements) {
|
|||
default:
|
||||
$class = 'element refpoint-left';
|
||||
}
|
||||
$html .= html_writer::tag('div', $e->render_html(), array('class' => $class, 'id' => 'element-' . $element->id));
|
||||
$html .= html_writer::tag('div', $e->render_html(), array('class' => $class,
|
||||
'data-refpoint' => $element->refpoint, 'id' => 'element-' . $element->id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,8 +82,8 @@ Y.extend(Rearrange, Y.Base, {
|
|||
// Set the PDF dimensions.
|
||||
this.pdfx = Y.one('#pdf').getX();
|
||||
this.pdfy = Y.one('#pdf').getY();
|
||||
this.pdfwidth = parseFloat(Y.one('#pdf').getComputedStyle('width'), 10);
|
||||
this.pdfheight = parseFloat(Y.one('#pdf').getComputedStyle('height'), 10);
|
||||
this.pdfwidth = parseFloat(Y.one('#pdf').getComputedStyle('width'));
|
||||
this.pdfheight = parseFloat(Y.one('#pdf').getComputedStyle('height'));
|
||||
|
||||
// Set the boundaries.
|
||||
this.pdfleftboundary = this.pdfx;
|
||||
|
@ -96,22 +96,10 @@ Y.extend(Rearrange, Y.Base, {
|
|||
this.pdfrightboundary -= parseInt(this.page.rightmargin * this.pixelsinmm, 10);
|
||||
}
|
||||
|
||||
this.set_data();
|
||||
this.set_positions();
|
||||
this.create_events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the additional data for the elements.
|
||||
*/
|
||||
set_data : function() {
|
||||
// Go through the elements and set their reference points.
|
||||
for (var key in this.elements) {
|
||||
var element = this.elements[key];
|
||||
Y.one('#element-' + element.id).setData('refpoint', element.refpoint);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the current position of the elements.
|
||||
*/
|
||||
|
@ -121,7 +109,7 @@ Y.extend(Rearrange, Y.Base, {
|
|||
var element = this.elements[key];
|
||||
var posx = this.pdfx + element.posx * this.pixelsinmm;
|
||||
var posy = this.pdfy + element.posy * this.pixelsinmm;
|
||||
var nodewidth = parseFloat(Y.one('#element-' + element.id).getComputedStyle('width'), 10);
|
||||
var nodewidth = parseFloat(Y.one('#element-' + element.id).getComputedStyle('width'));
|
||||
var maxwidth = element.width * this.pixelsinmm;
|
||||
|
||||
if (maxwidth && (nodewidth > maxwidth)) {
|
||||
|
@ -187,8 +175,8 @@ Y.extend(Rearrange, Y.Base, {
|
|||
*/
|
||||
is_out_of_bounds : function(node) {
|
||||
// Get the width and height of the node.
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'), 10);
|
||||
var nodeheight = parseFloat(node.getComputedStyle('height'), 10);
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'));
|
||||
var nodeheight = parseFloat(node.getComputedStyle('height'));
|
||||
|
||||
// Store the positions of each edge of the node.
|
||||
var left = node.getX();
|
||||
|
@ -226,13 +214,14 @@ Y.extend(Rearrange, Y.Base, {
|
|||
var element = this.elements[key];
|
||||
var node = Y.one('#element-' + element.id);
|
||||
|
||||
// Get the current X and Y positions for this element.
|
||||
// Get the current X and Y positions and refpoint for this element.
|
||||
var posx = node.getX() - this.pdfx;
|
||||
var posy = node.getY() - this.pdfy;
|
||||
var refpoint = node.getData('refpoint');
|
||||
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'), 10);
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'));
|
||||
|
||||
switch (element.refpoint) {
|
||||
switch (refpoint) {
|
||||
case '1': // Top-center
|
||||
posx += nodewidth / 2;
|
||||
break;
|
||||
|
@ -244,8 +233,8 @@ Y.extend(Rearrange, Y.Base, {
|
|||
// Set the parameters to pass to the AJAX request.
|
||||
params.values.push({
|
||||
id: element.id,
|
||||
posx: Math.round(parseFloat(posx / this.pixelsinmm, 10)),
|
||||
posy: Math.round(parseFloat(posy / this.pixelsinmm, 10))
|
||||
posx: Math.round(parseFloat(posx / this.pixelsinmm)),
|
||||
posy: Math.round(parseFloat(posy / this.pixelsinmm))
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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 r<this.pdfleftboundary||i>this.pdfrightboundary?!0:s<this.pdfy||o>this.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")),this.pdfheight=parseFloat(e.one("#pdf").getComputedStyle("height")),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_positions(),this.create_events()},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")),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")),n=parseFloat(e.getComputedStyle("height")),r=e.getX(),i=r+t,s=e.getY(),o=s+n;return r<this.pdfleftboundary||i>this.pdfrightboundary?!0:s<this.pdfy||o>this.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=s.getData("refpoint"),f=parseFloat(s.getComputedStyle("width"));switch(a){case"1":o+=f/2;break;case"2":o+=f}n.values.push({id:i.id,posx:Math.round(parseFloat(o/this.pixelsinmm)),posy:Math.round(parseFloat(u/this.pixelsinmm))})}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"]});
|
||||
|
|
|
@ -82,8 +82,8 @@ Y.extend(Rearrange, Y.Base, {
|
|||
// Set the PDF dimensions.
|
||||
this.pdfx = Y.one('#pdf').getX();
|
||||
this.pdfy = Y.one('#pdf').getY();
|
||||
this.pdfwidth = parseFloat(Y.one('#pdf').getComputedStyle('width'), 10);
|
||||
this.pdfheight = parseFloat(Y.one('#pdf').getComputedStyle('height'), 10);
|
||||
this.pdfwidth = parseFloat(Y.one('#pdf').getComputedStyle('width'));
|
||||
this.pdfheight = parseFloat(Y.one('#pdf').getComputedStyle('height'));
|
||||
|
||||
// Set the boundaries.
|
||||
this.pdfleftboundary = this.pdfx;
|
||||
|
@ -96,22 +96,10 @@ Y.extend(Rearrange, Y.Base, {
|
|||
this.pdfrightboundary -= parseInt(this.page.rightmargin * this.pixelsinmm, 10);
|
||||
}
|
||||
|
||||
this.set_data();
|
||||
this.set_positions();
|
||||
this.create_events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the additional data for the elements.
|
||||
*/
|
||||
set_data : function() {
|
||||
// Go through the elements and set their reference points.
|
||||
for (var key in this.elements) {
|
||||
var element = this.elements[key];
|
||||
Y.one('#element-' + element.id).setData('refpoint', element.refpoint);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the current position of the elements.
|
||||
*/
|
||||
|
@ -121,7 +109,7 @@ Y.extend(Rearrange, Y.Base, {
|
|||
var element = this.elements[key];
|
||||
var posx = this.pdfx + element.posx * this.pixelsinmm;
|
||||
var posy = this.pdfy + element.posy * this.pixelsinmm;
|
||||
var nodewidth = parseFloat(Y.one('#element-' + element.id).getComputedStyle('width'), 10);
|
||||
var nodewidth = parseFloat(Y.one('#element-' + element.id).getComputedStyle('width'));
|
||||
var maxwidth = element.width * this.pixelsinmm;
|
||||
|
||||
if (maxwidth && (nodewidth > maxwidth)) {
|
||||
|
@ -187,8 +175,8 @@ Y.extend(Rearrange, Y.Base, {
|
|||
*/
|
||||
is_out_of_bounds : function(node) {
|
||||
// Get the width and height of the node.
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'), 10);
|
||||
var nodeheight = parseFloat(node.getComputedStyle('height'), 10);
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'));
|
||||
var nodeheight = parseFloat(node.getComputedStyle('height'));
|
||||
|
||||
// Store the positions of each edge of the node.
|
||||
var left = node.getX();
|
||||
|
@ -226,13 +214,14 @@ Y.extend(Rearrange, Y.Base, {
|
|||
var element = this.elements[key];
|
||||
var node = Y.one('#element-' + element.id);
|
||||
|
||||
// Get the current X and Y positions for this element.
|
||||
// Get the current X and Y positions and refpoint for this element.
|
||||
var posx = node.getX() - this.pdfx;
|
||||
var posy = node.getY() - this.pdfy;
|
||||
var refpoint = node.getData('refpoint');
|
||||
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'), 10);
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'));
|
||||
|
||||
switch (element.refpoint) {
|
||||
switch (refpoint) {
|
||||
case '1': // Top-center
|
||||
posx += nodewidth / 2;
|
||||
break;
|
||||
|
@ -244,8 +233,8 @@ Y.extend(Rearrange, Y.Base, {
|
|||
// Set the parameters to pass to the AJAX request.
|
||||
params.values.push({
|
||||
id: element.id,
|
||||
posx: Math.round(parseFloat(posx / this.pixelsinmm, 10)),
|
||||
posy: Math.round(parseFloat(posy / this.pixelsinmm, 10))
|
||||
posx: Math.round(parseFloat(posx / this.pixelsinmm)),
|
||||
posy: Math.round(parseFloat(posy / this.pixelsinmm))
|
||||
});
|
||||
}
|
||||
|
||||
|
|
33
yui/src/rearrange/js/rearrange.js
vendored
33
yui/src/rearrange/js/rearrange.js
vendored
|
@ -80,8 +80,8 @@ Y.extend(Rearrange, Y.Base, {
|
|||
// Set the PDF dimensions.
|
||||
this.pdfx = Y.one('#pdf').getX();
|
||||
this.pdfy = Y.one('#pdf').getY();
|
||||
this.pdfwidth = parseFloat(Y.one('#pdf').getComputedStyle('width'), 10);
|
||||
this.pdfheight = parseFloat(Y.one('#pdf').getComputedStyle('height'), 10);
|
||||
this.pdfwidth = parseFloat(Y.one('#pdf').getComputedStyle('width'));
|
||||
this.pdfheight = parseFloat(Y.one('#pdf').getComputedStyle('height'));
|
||||
|
||||
// Set the boundaries.
|
||||
this.pdfleftboundary = this.pdfx;
|
||||
|
@ -94,22 +94,10 @@ Y.extend(Rearrange, Y.Base, {
|
|||
this.pdfrightboundary -= parseInt(this.page.rightmargin * this.pixelsinmm, 10);
|
||||
}
|
||||
|
||||
this.set_data();
|
||||
this.set_positions();
|
||||
this.create_events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the additional data for the elements.
|
||||
*/
|
||||
set_data : function() {
|
||||
// Go through the elements and set their reference points.
|
||||
for (var key in this.elements) {
|
||||
var element = this.elements[key];
|
||||
Y.one('#element-' + element.id).setData('refpoint', element.refpoint);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the current position of the elements.
|
||||
*/
|
||||
|
@ -119,7 +107,7 @@ Y.extend(Rearrange, Y.Base, {
|
|||
var element = this.elements[key];
|
||||
var posx = this.pdfx + element.posx * this.pixelsinmm;
|
||||
var posy = this.pdfy + element.posy * this.pixelsinmm;
|
||||
var nodewidth = parseFloat(Y.one('#element-' + element.id).getComputedStyle('width'), 10);
|
||||
var nodewidth = parseFloat(Y.one('#element-' + element.id).getComputedStyle('width'));
|
||||
var maxwidth = element.width * this.pixelsinmm;
|
||||
|
||||
if (maxwidth && (nodewidth > maxwidth)) {
|
||||
|
@ -185,8 +173,8 @@ Y.extend(Rearrange, Y.Base, {
|
|||
*/
|
||||
is_out_of_bounds : function(node) {
|
||||
// Get the width and height of the node.
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'), 10);
|
||||
var nodeheight = parseFloat(node.getComputedStyle('height'), 10);
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'));
|
||||
var nodeheight = parseFloat(node.getComputedStyle('height'));
|
||||
|
||||
// Store the positions of each edge of the node.
|
||||
var left = node.getX();
|
||||
|
@ -224,13 +212,14 @@ Y.extend(Rearrange, Y.Base, {
|
|||
var element = this.elements[key];
|
||||
var node = Y.one('#element-' + element.id);
|
||||
|
||||
// Get the current X and Y positions for this element.
|
||||
// Get the current X and Y positions and refpoint for this element.
|
||||
var posx = node.getX() - this.pdfx;
|
||||
var posy = node.getY() - this.pdfy;
|
||||
var refpoint = node.getData('refpoint');
|
||||
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'), 10);
|
||||
var nodewidth = parseFloat(node.getComputedStyle('width'));
|
||||
|
||||
switch (element.refpoint) {
|
||||
switch (refpoint) {
|
||||
case '1': // Top-center
|
||||
posx += nodewidth / 2;
|
||||
break;
|
||||
|
@ -242,8 +231,8 @@ Y.extend(Rearrange, Y.Base, {
|
|||
// Set the parameters to pass to the AJAX request.
|
||||
params.values.push({
|
||||
id: element.id,
|
||||
posx: Math.round(parseFloat(posx / this.pixelsinmm, 10)),
|
||||
posy: Math.round(parseFloat(posy / this.pixelsinmm, 10))
|
||||
posx: Math.round(parseFloat(posx / this.pixelsinmm)),
|
||||
posy: Math.round(parseFloat(posy / this.pixelsinmm))
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue