Set the element width in PHP, not JS
This commit is contained in:
parent
e480f5c98f
commit
65aee9c9c0
5 changed files with 6 additions and 15 deletions
|
@ -116,8 +116,11 @@ class element_helper {
|
||||||
$fontstyle .= ': font-style: italic';
|
$fontstyle .= ': font-style: italic';
|
||||||
}
|
}
|
||||||
|
|
||||||
$style = $fontstyle . '; color: ' . $element->colour . '; font-size: ' . $element->size . 'pt';
|
$style = $fontstyle . '; color: ' . $element->colour . '; font-size: ' . $element->size . 'pt;';
|
||||||
return \html_writer::tag('span', $content, array('style' => $style));
|
if ($element->width) {
|
||||||
|
$style .= ' width: ' . $element->width . 'mm';
|
||||||
|
}
|
||||||
|
return \html_writer::div($content, '', array('style' => $style));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -109,7 +109,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
for (var key in this.elements) {
|
for (var key in this.elements) {
|
||||||
var element = this.elements[key];
|
var element = this.elements[key];
|
||||||
Y.one('#element-' + element.id).setData('refpoint', element.refpoint);
|
Y.one('#element-' + element.id).setData('refpoint', element.refpoint);
|
||||||
Y.one('#element-' + element.id).setData('width', element.width);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -128,7 +127,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
if (maxwidth && (nodewidth > maxwidth)) {
|
if (maxwidth && (nodewidth > maxwidth)) {
|
||||||
nodewidth = maxwidth;
|
nodewidth = maxwidth;
|
||||||
}
|
}
|
||||||
Y.one('#element-' + element.id).setStyle('width', nodewidth + 'px');
|
|
||||||
|
|
||||||
switch (element.refpoint) {
|
switch (element.refpoint) {
|
||||||
case '1': // Top-center
|
case '1': // Top-center
|
||||||
|
@ -169,7 +167,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
del.on('drag:start', function() {
|
del.on('drag:start', function() {
|
||||||
var node = del.get('currentNode');
|
var node = del.get('currentNode');
|
||||||
this.elementxy = node.getXY();
|
this.elementxy = node.getXY();
|
||||||
this.elementwidth = node.getComputedStyle('width');
|
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
// When we finish the dragging action check that the node is in bounds,
|
// When we finish the dragging action check that the node is in bounds,
|
||||||
|
@ -178,7 +175,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
var node = del.get('currentNode');
|
var node = del.get('currentNode');
|
||||||
if (this.is_out_of_bounds(node)) {
|
if (this.is_out_of_bounds(node)) {
|
||||||
node.setXY(this.elementxy);
|
node.setXY(this.elementxy);
|
||||||
node.setStyle('width', this.elementwidth);
|
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
|
@ -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),e.one("#element-"+n.id).setData("width",n.width)}},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),e.one("#element-"+n.id).setStyle("width",s+"px");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.elementwidth=e.getComputedStyle("width")},this),t.on("drag:end",function(){var e=t.get("currentNode");this.is_out_of_bounds(e)&&(e.setXY(this.elementxy),e.setStyle("width",this.elementwidth))},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"),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"]});
|
||||||
|
|
|
@ -109,7 +109,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
for (var key in this.elements) {
|
for (var key in this.elements) {
|
||||||
var element = this.elements[key];
|
var element = this.elements[key];
|
||||||
Y.one('#element-' + element.id).setData('refpoint', element.refpoint);
|
Y.one('#element-' + element.id).setData('refpoint', element.refpoint);
|
||||||
Y.one('#element-' + element.id).setData('width', element.width);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -128,7 +127,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
if (maxwidth && (nodewidth > maxwidth)) {
|
if (maxwidth && (nodewidth > maxwidth)) {
|
||||||
nodewidth = maxwidth;
|
nodewidth = maxwidth;
|
||||||
}
|
}
|
||||||
Y.one('#element-' + element.id).setStyle('width', nodewidth + 'px');
|
|
||||||
|
|
||||||
switch (element.refpoint) {
|
switch (element.refpoint) {
|
||||||
case '1': // Top-center
|
case '1': // Top-center
|
||||||
|
@ -169,7 +167,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
del.on('drag:start', function() {
|
del.on('drag:start', function() {
|
||||||
var node = del.get('currentNode');
|
var node = del.get('currentNode');
|
||||||
this.elementxy = node.getXY();
|
this.elementxy = node.getXY();
|
||||||
this.elementwidth = node.getComputedStyle('width');
|
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
// When we finish the dragging action check that the node is in bounds,
|
// When we finish the dragging action check that the node is in bounds,
|
||||||
|
@ -178,7 +175,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
var node = del.get('currentNode');
|
var node = del.get('currentNode');
|
||||||
if (this.is_out_of_bounds(node)) {
|
if (this.is_out_of_bounds(node)) {
|
||||||
node.setXY(this.elementxy);
|
node.setXY(this.elementxy);
|
||||||
node.setStyle('width', this.elementwidth);
|
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
4
yui/src/rearrange/js/rearrange.js
vendored
4
yui/src/rearrange/js/rearrange.js
vendored
|
@ -107,7 +107,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
for (var key in this.elements) {
|
for (var key in this.elements) {
|
||||||
var element = this.elements[key];
|
var element = this.elements[key];
|
||||||
Y.one('#element-' + element.id).setData('refpoint', element.refpoint);
|
Y.one('#element-' + element.id).setData('refpoint', element.refpoint);
|
||||||
Y.one('#element-' + element.id).setData('width', element.width);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -126,7 +125,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
if (maxwidth && (nodewidth > maxwidth)) {
|
if (maxwidth && (nodewidth > maxwidth)) {
|
||||||
nodewidth = maxwidth;
|
nodewidth = maxwidth;
|
||||||
}
|
}
|
||||||
Y.one('#element-' + element.id).setStyle('width', nodewidth + 'px');
|
|
||||||
|
|
||||||
switch (element.refpoint) {
|
switch (element.refpoint) {
|
||||||
case '1': // Top-center
|
case '1': // Top-center
|
||||||
|
@ -167,7 +165,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
del.on('drag:start', function() {
|
del.on('drag:start', function() {
|
||||||
var node = del.get('currentNode');
|
var node = del.get('currentNode');
|
||||||
this.elementxy = node.getXY();
|
this.elementxy = node.getXY();
|
||||||
this.elementwidth = node.getComputedStyle('width');
|
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
// When we finish the dragging action check that the node is in bounds,
|
// When we finish the dragging action check that the node is in bounds,
|
||||||
|
@ -176,7 +173,6 @@ Y.extend(Rearrange, Y.Base, {
|
||||||
var node = del.get('currentNode');
|
var node = del.get('currentNode');
|
||||||
if (this.is_out_of_bounds(node)) {
|
if (this.is_out_of_bounds(node)) {
|
||||||
node.setXY(this.elementxy);
|
node.setXY(this.elementxy);
|
||||||
node.setStyle('width', this.elementwidth);
|
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue