Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move Repeat's JS to proper qf.elements.Repeat namespace

git-svn-id: http://svn.php.net/repository/pear/packages/HTML_QuickForm2/trunk@325694 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 9baf1a3f29153c9d25bf767ec6e255fd96c25e1d 1 parent f1ab56a
@sad-spirit sad-spirit authored
View
4 HTML/QuickForm2/Container/Repeat.php
@@ -661,8 +661,8 @@ private function _generateInitScript(
);
list ($rules, $scripts) = $evalBuilder->getFormJavascriptAsStrings();
- return "new qf.Repeat(document.getElementById({$myId}), {$protoId}, {$triggers},\n"
- . $rules . ",\n" . $scripts . "\n);";
+ return "new qf.elements.Repeat(document.getElementById({$myId}), {$protoId}, "
+ . "{$triggers},\n{$rules},\n{$scripts}\n);";
}
/**
View
10 data/js/min/quickform-repeat.js
@@ -7,11 +7,11 @@
Licensed under new BSD license
http://opensource.org/licenses/bsd-license.php
*/
-qf.Repeat=function(a,b,d,e,f){a.repeat=this;this.repeatPrototype=this.form=null;this.container=a;this.itemId=b;this.rulesTpl=e;this.scriptsTpl=f;this.triggers=d;e=this.getElementsByClass("repeatAdd",a);for(b=0;d=e[b];b++)qf.events.addListener(d,"click",qf.Repeat.addHandler);a=this.getElementsByClass("repeatRemove",a);for(b=0;d=a[b];b++)qf.events.addListener(d,"click",qf.Repeat.removeHandler)};
-qf.Repeat.addHandler=function(a){for(var a=qf.events.fixEvent(a),b=a.target;b&&!qf.classes.has(b,"repeat");)b=b.parentNode;b&&b.repeat&&b.repeat.onBeforeAdd()&&b.repeat.add();a.preventDefault()};qf.Repeat.removeHandler=function(a){for(var a=qf.events.fixEvent(a),b=a.target,d;b&&!qf.classes.has(b,"repeat");)qf.classes.has(b,"repeatItem")&&(d=b),b=b.parentNode;b&&d&&b.repeat&&b.repeat.onBeforeRemove(d)&&b.repeat.remove(d);a.preventDefault()};
-qf.Repeat.prototype={getElementsByClass:function(){return document.getElementsByClassName?function(a,b){return b.getElementsByClassName(a)}:function(a,b){for(var d=b.getElementsByTagName("*"),e=[],f=0,c;c=d[f];f++)qf.classes.has(c,a)&&e.push(c);return e}}(),findIndexByItem:function(a){var b=RegExp("^"+this.itemId.replace(":idx:","([a-zA-Z0-9_]+?)")+"$"),d;if(a.id&&(d=b.exec(a.id)))return d[1];for(var a=a.getElementsByTagName("*"),e=0,f;f=a[e];e++)if(f.id&&(d=b.exec(f.id)))return d[1];return null},
+qf.elements.Repeat=function(a,b,d,e,f){a.repeat=this;this.repeatPrototype=this.form=null;this.container=a;this.itemId=b;this.rulesTpl=e;this.scriptsTpl=f;this.triggers=d;e=this.getElementsByClass("repeatAdd",a);for(b=0;d=e[b];b++)qf.events.addListener(d,"click",qf.elements.Repeat.addHandler);a=this.getElementsByClass("repeatRemove",a);for(b=0;d=a[b];b++)qf.events.addListener(d,"click",qf.elements.Repeat.removeHandler)};
+qf.elements.Repeat.addHandler=function(a){for(var a=qf.events.fixEvent(a),b=a.target;b&&!qf.classes.has(b,"repeat");)b=b.parentNode;b&&b.repeat&&b.repeat.onBeforeAdd()&&b.repeat.add();a.preventDefault()};qf.elements.Repeat.removeHandler=function(a){for(var a=qf.events.fixEvent(a),b=a.target,d;b&&!qf.classes.has(b,"repeat");)qf.classes.has(b,"repeatItem")&&(d=b),b=b.parentNode;b&&d&&b.repeat&&b.repeat.onBeforeRemove(d)&&b.repeat.remove(d);a.preventDefault()};
+qf.elements.Repeat.prototype={getElementsByClass:function(){return document.getElementsByClassName?function(a,b){return b.getElementsByClassName(a)}:function(a,b){for(var d=b.getElementsByTagName("*"),e=[],f=0,c;c=d[f];f++)qf.classes.has(c,a)&&e.push(c);return e}}(),findIndexByItem:function(a){var b=RegExp("^"+this.itemId.replace(":idx:","([a-zA-Z0-9_]+?)")+"$"),d;if(a.id&&(d=b.exec(a.id)))return d[1];for(var a=a.getElementsByTagName("*"),e=0,f;f=a[e];e++)if(f.id&&(d=b.exec(f.id)))return d[1];return null},
findItemByIndex:function(a){a=this.itemId.replace(":idx:",a);if((a=document.getElementById(a))&&!qf.classes.has(a,"repeatItem")){do a=a.parentNode;while(a&&!qf.classes.has(a,"repeatItem"))}return a},findForm:function(){for(var a=this.container;a&&"form"!==a.nodeName.toLowerCase();)a=a.parentNode;return a},generateIndex:function(){var a;do a="add"+Math.round(1E4*Math.random());while(document.getElementById(this.itemId.replace(":idx:",a)));return a},add:function(){this.repeatPrototype||(this.repeatPrototype=
this.getElementsByClass("repeatPrototype",this.container)[0]);var a=this.getElementsByClass("repeatItem",this.container),b=a[a.length-1],d=this.repeatPrototype.cloneNode(!0),e=this.generateIndex();qf.classes.remove(d,"repeatPrototype");d.id&&(d.id=d.id.replace(":idx:",e));for(var f=d.getElementsByTagName("*"),a=0,c;c=f[a];a++){c.id&&(c.id=c.id.replace(":idx:",e));c.name&&(c.name=c.name.replace(":idx:",e));if(c.type&&("checkbox"==c.type||"radio"==c.type))c.value=c.value.replace(":idx:",e);c.htmlFor&&
-(c.htmlFor=c.htmlFor.replace(":idx:",e));"script"==c.nodeName.toLowerCase()&&eval(c.innerHTML.replace(/:idx:/g,e));qf.classes.has(c,"repeatAdd")&&qf.events.addListener(c,"click",qf.Repeat.addHandler);qf.classes.has(c,"repeatRemove")&&qf.events.addListener(c,"click",qf.Repeat.removeHandler)}b.parentNode.insertBefore(d,b.nextSibling);this.scriptsTpl&&eval(this.scriptsTpl.replace(/:idx:/g,e));if(this.rulesTpl&&(this.form||(this.form=this.findForm()),this.form.validator)){b=eval(this.rulesTpl.replace(/:idx:/g,
+(c.htmlFor=c.htmlFor.replace(":idx:",e));"script"==c.nodeName.toLowerCase()&&eval(c.innerHTML.replace(/:idx:/g,e));qf.classes.has(c,"repeatAdd")&&qf.events.addListener(c,"click",qf.elements.Repeat.addHandler);qf.classes.has(c,"repeatRemove")&&qf.events.addListener(c,"click",qf.elements.Repeat.removeHandler)}b.parentNode.insertBefore(d,b.nextSibling);this.scriptsTpl&&eval(this.scriptsTpl.replace(/:idx:/g,e));if(this.rulesTpl&&(this.form||(this.form=this.findForm()),this.form.validator)){b=eval(this.rulesTpl.replace(/:idx:/g,
e));for(a=0;d=b[a];a++)this.form.validator.rules.push(d)}this.onChange()},remove:function(a){var b;if("string"==typeof a&&(b=a,!(a=this.findItemByIndex(b))))return;if(this.rulesTpl&&(this.form||(this.form=this.findForm()),this.form.validator)){var d=new qf.Map,e=this.form.validator.rules,f,c;b||(b=this.findIndexByItem(a));for(c=0;f=this.triggers[c];c++)d.set(f.replace(":idx:",b),!0);for(c=e.length-1;b=e[c];c--)d.hasKey(b.owner)&&e.splice(c,1)}a.parentNode.removeChild(a);this.onChange()},onBeforeAdd:function(){return!0},
-onBeforeRemove:function(){return!0},onChange:function(){}};
+onBeforeRemove:function(){return!0},onChange:function(){}};qf.Repeat=qf.elements.Repeat;
View
23 data/js/quickform-repeat.js
@@ -20,7 +20,7 @@
* @param {String} scriptsTpl
* @constructor
*/
-qf.Repeat = function(container, itemId, triggers, rulesTpl, scriptsTpl)
+qf.elements.Repeat = function(container, itemId, triggers, rulesTpl, scriptsTpl)
{
container.repeat = this;
@@ -69,12 +69,12 @@ qf.Repeat = function(container, itemId, triggers, rulesTpl, scriptsTpl)
// find all elements with class repeatAdd inside container...
var adders = this.getElementsByClass('repeatAdd', container);
for (var i = 0, element; element = adders[i]; i++) {
- qf.events.addListener(element, 'click', qf.Repeat.addHandler);
+ qf.events.addListener(element, 'click', qf.elements.Repeat.addHandler);
}
// find all elements with class repeatRemove inside container...
var removers = this.getElementsByClass('repeatRemove', container);
for (i = 0; element = removers[i]; i++) {
- qf.events.addListener(element, 'click', qf.Repeat.removeHandler);
+ qf.events.addListener(element, 'click', qf.elements.Repeat.removeHandler);
}
};
@@ -83,7 +83,7 @@ qf.Repeat = function(container, itemId, triggers, rulesTpl, scriptsTpl)
*
* @param {Event} event
*/
-qf.Repeat.addHandler = function(event)
+qf.elements.Repeat.addHandler = function(event)
{
event = qf.events.fixEvent(event);
@@ -102,7 +102,7 @@ qf.Repeat.addHandler = function(event)
*
* @param {Event} event
*/
-qf.Repeat.removeHandler = function(event)
+qf.elements.Repeat.removeHandler = function(event)
{
event = qf.events.fixEvent(event);
@@ -120,7 +120,7 @@ qf.Repeat.removeHandler = function(event)
event.preventDefault();
};
-qf.Repeat.prototype = {
+qf.elements.Repeat.prototype = {
/**
* Finds elements by CSS class name
*
@@ -259,10 +259,10 @@ qf.Repeat.prototype = {
eval(element.innerHTML.replace(/:idx:/g, index));
}
if (qf.classes.has(element, 'repeatAdd')) {
- qf.events.addListener(element, 'click', qf.Repeat.addHandler);
+ qf.events.addListener(element, 'click', qf.elements.Repeat.addHandler);
}
if (qf.classes.has(element, 'repeatRemove')) {
- qf.events.addListener(element, 'click', qf.Repeat.removeHandler);
+ qf.events.addListener(element, 'click', qf.elements.Repeat.removeHandler);
}
}
@@ -355,3 +355,10 @@ qf.Repeat.prototype = {
{
}
};
+
+/**
+ * Alias for qf.elements.Repeat, in case someone managed to rely on that name
+ * @deprecated will be removed in the next release
+ * @type {Function}
+ */
+qf.Repeat = qf.elements.Repeat;
View
23 js/src/repeat.js
@@ -20,7 +20,7 @@
* @param {String} scriptsTpl
* @constructor
*/
-qf.Repeat = function(container, itemId, triggers, rulesTpl, scriptsTpl)
+qf.elements.Repeat = function(container, itemId, triggers, rulesTpl, scriptsTpl)
{
container.repeat = this;
@@ -69,12 +69,12 @@ qf.Repeat = function(container, itemId, triggers, rulesTpl, scriptsTpl)
// find all elements with class repeatAdd inside container...
var adders = this.getElementsByClass('repeatAdd', container);
for (var i = 0, element; element = adders[i]; i++) {
- qf.events.addListener(element, 'click', qf.Repeat.addHandler);
+ qf.events.addListener(element, 'click', qf.elements.Repeat.addHandler);
}
// find all elements with class repeatRemove inside container...
var removers = this.getElementsByClass('repeatRemove', container);
for (i = 0; element = removers[i]; i++) {
- qf.events.addListener(element, 'click', qf.Repeat.removeHandler);
+ qf.events.addListener(element, 'click', qf.elements.Repeat.removeHandler);
}
};
@@ -83,7 +83,7 @@ qf.Repeat = function(container, itemId, triggers, rulesTpl, scriptsTpl)
*
* @param {Event} event
*/
-qf.Repeat.addHandler = function(event)
+qf.elements.Repeat.addHandler = function(event)
{
event = qf.events.fixEvent(event);
@@ -102,7 +102,7 @@ qf.Repeat.addHandler = function(event)
*
* @param {Event} event
*/
-qf.Repeat.removeHandler = function(event)
+qf.elements.Repeat.removeHandler = function(event)
{
event = qf.events.fixEvent(event);
@@ -120,7 +120,7 @@ qf.Repeat.removeHandler = function(event)
event.preventDefault();
};
-qf.Repeat.prototype = {
+qf.elements.Repeat.prototype = {
/**
* Finds elements by CSS class name
*
@@ -259,10 +259,10 @@ qf.Repeat.prototype = {
eval(element.innerHTML.replace(/:idx:/g, index));
}
if (qf.classes.has(element, 'repeatAdd')) {
- qf.events.addListener(element, 'click', qf.Repeat.addHandler);
+ qf.events.addListener(element, 'click', qf.elements.Repeat.addHandler);
}
if (qf.classes.has(element, 'repeatRemove')) {
- qf.events.addListener(element, 'click', qf.Repeat.removeHandler);
+ qf.events.addListener(element, 'click', qf.elements.Repeat.removeHandler);
}
}
@@ -355,3 +355,10 @@ qf.Repeat.prototype = {
{
}
};
+
+/**
+ * Alias for qf.elements.Repeat, in case someone managed to rely on that name
+ * @deprecated will be removed in the next release
+ * @type {Function}
+ */
+qf.Repeat = qf.elements.Repeat;
Please sign in to comment.
Something went wrong with that request. Please try again.