Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

AUI-152 - Special elements are not properly cloned

git-svn-id: svn://svn.liferay.com/repos/public/alloy/trunk@59971 05bdf26c-840f-0410-9ced-eb539d925f36
  • Loading branch information...
commit 77c942c4be24ed396e7b76ecf4a767834f6d5fce 1 parent 65ecdf3
@natecavanaugh natecavanaugh authored
View
7 ATTRIBUTION.txt
@@ -6,4 +6,9 @@ Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses
Fugue Icons (icon_sprite.png)
Copyright (C) 2009 Yusuke Kamiyamane. All rights reserved.
The icons are licensed under a Creative Commons Attribution 3.0 license.
-<http://creativecommons.org/licenses/by/3.0/>
+<http://creativecommons.org/licenses/by/3.0/>
+----------------------------------
+Portions of the aui-node-base module
+were used from the jQuery Javascript library
+Copyright (c) 2010 John Resig & the jQuery team (http://jquery.com)
+Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
View
130 build/aui-node/aui-node-base-debug.js
@@ -15,7 +15,9 @@ var Lang = A.Lang,
getClassName = A.ClassNameManager.getClassName,
- CLONED_EVENTS = false,
+ STR_EMPTY = '',
+
+ ARRAY_EMPTY_STRINGS = [STR_EMPTY, STR_EMPTY],
HELPER = 'helper',
@@ -27,17 +29,25 @@ var Lang = A.Lang,
NONE = 'none',
PARENT_NODE = 'parentNode',
SCRIPT = 'script',
+
+ SUPPORT_CLONED_EVENTS = false,
+
VALUE = 'value';
- // Event cloning detection support based on pieces from jQuery
+ /*
+ Parts of this file are used from jQuery (http://jquery.com)
+ Dual-licensed under MIT/GPL
+ */
var div = document.createElement('div');
- div.innerHTML = '&nbsp;'; // IE throws an error on fireEvent if the element does not have child nodes
+
+ div.style.display = 'none';
+ div.innerHTML = ' <link/><table></table>&nbsp;';
if (div.attachEvent && div.fireEvent) {
div.attachEvent(
'onclick',
function(){
- CLONED_EVENTS = true;
+ SUPPORT_CLONED_EVENTS = true;
div.detachEvent('onclick', arguments.callee);
}
@@ -46,6 +56,43 @@ var Lang = A.Lang,
div.cloneNode(true).fireEvent('onclick');
}
+ var SUPPORT_SERIALIZE_HTML = !!div.getElementsByTagName('link').length,
+ SUPPORT_OPTIONAL_TBODY = !div.getElementsByTagName('tbody').length,
+ SUPPORT_LEADING_WHITESPACE = div.firstChild.nodeType === 3;
+
+ var REGEX_LEADING_WHITE_SPACE = /^\s+/,
+ REGEX_IE8_ACTION = /=([^=\x27\x22>\s]+\/)>/g,
+ REGEX_XHTML_TAG = /(<([\w:]+)[^>]*?)\/>/g,
+ REGEX_SELF_CLOSING_ELEMENT = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,
+ REGEX_TAGNAME = /<([\w:]+)/,
+ REGEX_TBODY = /<tbody/i,
+ REGEX_HTML = /<|&#?\w+;/,
+
+ FN_CLOSE_TAG = function(all, start, tagName) {
+ return REGEX_SELF_CLOSING_ELEMENT.test(tagName)
+ ? all
+ : start + '></' + tagName + '>';
+ };
+
+ var MAP_WRAPPERS = {
+ _default: [0, STR_EMPTY, STR_EMPTY],
+ area: [1, '<map>', '</map>'],
+ col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
+ legend: [1, '<fieldset>', '</fieldset>'],
+ option: [1, '<select multiple="multiple">', '</select>'],
+ td: [3, '<table><tbody><tr>', '</tr></tbody></table>'],
+ thead: [1, '<table>', '</table>'],
+ tr: [2, '<table><tbody>', '</tbody></table>']
+ };
+
+ MAP_WRAPPERS.optgroup = MAP_WRAPPERS.option;
+ MAP_WRAPPERS.tbody = MAP_WRAPPERS.tfoot = MAP_WRAPPERS.colgroup = MAP_WRAPPERS.caption = MAP_WRAPPERS.thead;
+ MAP_WRAPPERS.th = MAP_WRAPPERS.td;
+
+ if (!SUPPORT_SERIALIZE_HTML) {
+ MAP_WRAPPERS._default = [1, 'div<div>', '</div>'];
+ }
+
/**
* Augment the <a href="Node.html">YUI3 Node</a> with more util methods.
*
@@ -215,13 +262,17 @@ A.mix(A.Node.prototype, {
clone: (function() {
var clone;
- if (CLONED_EVENTS) {
+ if (SUPPORT_CLONED_EVENTS) {
clone = function() {
var el = this.getDOM();
var clone;
if (el.nodeType != 3) {
- clone = A.Node.create(this.outerHTML())
+ var outerHTML = this.outerHTML();
+
+ outerHTML = outerHTML.replace(REGEX_IE8_ACTION, '="$1">').replace(REGEX_LEADING_WHITE_SPACE, '');
+
+ clone = A.one(A.Node._prepareHTML(outerHTML)[0]);
}
else {
clone = A.one(el.cloneNode());
@@ -913,7 +964,7 @@ A.mix(A.Node.prototype, {
var parent = instance.get(PARENT_NODE);
if (parent) {
- if (Lang.isString(newNode)) {
+ if (isString(newNode)) {
newNode = A.Node.create(newNode);
}
@@ -933,6 +984,71 @@ A.mix(A.Node.prototype, {
}
}, true);
+A.Node._prepareHTML = function(element) {
+ var doc = A.config.doc;
+
+ var returnData = [];
+
+ if (isString(element)) {
+ if (!REGEX_HTML.test(element)) {
+ element = doc.createTextNode(element);
+ }
+ else {
+ element = element.replace(REGEX_XHTML_TAG, FN_CLOSE_TAG);
+
+ var tagName = (REGEX_TAGNAME.exec(element) || ARRAY_EMPTY_STRINGS)[1].toLowerCase();
+ var wrap = MAP_WRAPPERS[tagName] || MAP_WRAPPERS._default;
+ var depth = wrap[0];
+ var div = doc.createElement('div');
+
+ div.innerHTML = wrap[1] + element + wrap[2];
+
+ while (depth--) {
+ div = div.lastChild;
+ }
+
+ if (!SUPPORT_OPTIONAL_TBODY) {
+ var hasTBody = REGEX_TBODY.test(element);
+ var tbody = [];
+
+ if (tagName == 'table' && !hasTBody) {
+ if (div.firstChild) {
+ tbody = div.firstChild.childNodes;
+ }
+ }
+ else {
+ if (wrap[1] == '<table>' && !hasTBody) {
+ tbody = div.childNodes;
+ }
+ }
+
+ for (var i = tbody.length - 1; i >= 0; --i) {
+ var node = tbody[i];
+
+ if (node.nodeName.toLowerCase() == 'tbody' && node.childNodes.length) {
+ node.parentNode.removeChild(node);
+ }
+ }
+ }
+
+ if (!SUPPORT_LEADING_WHITESPACE && REGEX_LEADING_WHITE_SPACE.test(element)) {
+ div.insertBefore(doc.createTextNode(REGEX_LEADING_WHITE_SPACE.exec(element)[0]), div.firstChild);
+ }
+
+ element = div.childNodes;
+ }
+ }
+
+ if (element.nodeType) {
+ returnData.push(element);
+ }
+ else {
+ returnData = element;
+ }
+
+ return returnData;
+};
+
/**
* Augment the <a href="NodeList.html">YUI3 NodeList</a> with more util methods.
*
View
4 build/aui-node/aui-node-base-min.js
@@ -1,2 +1,2 @@
-AUI.add("aui-node-base",function(O){var D=O.Lang,K=D.isArray,J=D.isObject,L=D.isString,C=D.isUndefined,R=D.isValue,F=O.ClassNameManager.getClassName,N=false,B="helper",T=F(B,"hidden"),P=F(B,"unselectable"),Q="innerHTML",S="nextSibling",H="none",G="parentNode",I="script",E="value";var M=document.createElement("div");M.innerHTML="&nbsp;";if(M.attachEvent&&M.fireEvent){M.attachEvent("onclick",function(){N=true;M.detachEvent("onclick",arguments.callee);});M.cloneNode(true).fireEvent("onclick");}O.mix(O.Node.prototype,{ancestors:function(U){var A=this;var W=[];var X=A.getDOM();while(X&&X.nodeType!==9){if(X.nodeType===1){W.push(X);}X=X.parentNode;}var V=new O.all(W);if(U){V=V.filter(U);}return V;},ancestorsByClassName:function(W){var A=this;var V=[];var U=new RegExp("\\b"+W+"\\b");var X=A.getDOM();while(X&&X.nodeType!==9){if(X.nodeType===1&&U.test(X.className)){V.push(X);}X=X.parentNode;}return O.all(V);},appendTo:function(U){var A=this;O.one(U).append(A);return A;},attr:function(U,X){var A=this;if(!C(X)){var W=A.getDOM();if(U in W){A.set(U,X);}else{A.setAttribute(U,X);}return A;}else{if(J(U)){for(var V in U){A.attr(V,U[V]);}return A;}return A.get(U)||A.getAttribute(U);}},clone:(function(){var A;if(N){A=function(){var U=this.getDOM();var V;if(U.nodeType!=3){V=O.Node.create(this.outerHTML());}else{V=O.one(U.cloneNode());}return V;};}else{A=function(){return this.cloneNode(true);};}return A;})(),center:function(Y){var A=this;Y=(Y&&O.one(Y))||O.getBody();var W=Y.get("region");var V=A.get("region");var X=W.left+(W.width/2);var U=W.top+(W.height/2);A.setXY([X-(V.width/2),U-(V.height/2)]);},empty:function(){var A=this;A.all(">*").remove().purge();var U=O.Node.getDOMNode(A);while(U.firstChild){U.removeChild(U.firstChild);}return A;},getDOM:function(){var A=this;return O.Node.getDOMNode(A);},guid:function(V){var U=this;var A=U.get("id");if(!A){A=O.stamp(U);U.set("id",A);}return A;},hide:function(U){var A=this;A.addClass(U||A._hideClass||T);return A;},hover:function(V,U){var A=this;var W;var Z=A._defaultHoverOptions;if(J(V,true)){W=V;W=O.mix(W,Z);V=W.over;U=W.out;}else{W=O.mix({over:V,out:U},Z);}A._hoverOptions=W;var Y=new O.DelayedTask(A._hoverOverTaskFn,A);var X=new O.DelayedTask(A._hoverOutTaskFn,A);W.overTask=Y;W.outTask=X;A.on(W.overEventType,A._hoverOverHandler,A);A.on(W.outEventType,A._hoverOutHandler,A);},html:function(){var A=arguments,U=A.length;if(U){this.set(Q,A[0]);}else{return this.get(Q);}return this;},outerHTML:function(){var A=this;var V=A.getDOM();if("outerHTML" in V){return V.outerHTML;}var U=O.Node.create("<div></div>").append(this.clone());try{return U.html();}catch(W){}finally{U=null;}},placeAfter:function(U){var A=this;return A._place(U,A.get(S));},placeBefore:function(U){var A=this;return A._place(U,A);},prependTo:function(U){var A=this;O.one(U).prepend(A);return A;},radioClass:function(U){var A=this;A.siblings().removeClass(U);A.addClass(U);return A;},resetId:function(U){var A=this;A.attr("id",O.guid(U));return A;},selectText:function(Z,V){var A=this;var U=A.getDOM();var X=A.val().length;V=R(V)?V:X;Z=R(Z)?Z:0;try{if(U.setSelectionRange){U.setSelectionRange(Z,V);}else{if(U.createTextRange){var W=U.createTextRange();W.moveStart("character",Z);W.moveEnd("character",V-X);W.select();}else{U.select();}}if(U!=document.activeElement){U.focus();}}catch(Y){}return A;},selectable:function(){var A=this;A.getDOM().unselectable="off";A.detach("selectstart");A.setStyles({"MozUserSelect":"","KhtmlUserSelect":""});A.removeClass(P);return A;},show:function(U){var A=this;A.removeClass(U||A._hideClass||T);return A;},swallowEvent:function(U,V){var A=this;var W=function(X){X.stopPropagation();if(V){X.preventDefault();X.halt();}return false;};if(K(U)){O.Array.each(U,function(X){A.on(X,W);});return this;}else{A.on(U,W);}return A;},text:function(V){var A=this;var U=A.getDOM();if(!C(V)){V=O.DOM._getDoc(U).createTextNode(V);return A.empty().append(V);}return A._getText(U.childNodes);},toggle:function(U){var A=this;var V="hide";var W=U||A._hideClass||T;if(A.hasClass(W)){V="show";}A[V](W);return A;},unselectable:function(){var A=this;A.getDOM().unselectable="on";A.swallowEvent("selectstart",true);A.setStyles({"MozUserSelect":H,"KhtmlUserSelect":H});A.addClass(P);return A;},val:function(U){var A=this;if(C(U)){return A.get(E);}else{return A.set(E,U);}},_getText:function(Y){var A=this;var W=Y.length;var V;var X=[];for(var U=0;U<W;U++){V=Y[U];if(V&&V.nodeType!=8){if(V.nodeType!=1){X.push(V.nodeValue);}if(V.childNodes){X.push(A._getText(V.childNodes));}}}return X.join("");},_hoverOutHandler:function(V){var A=this;var U=A._hoverOptions;U.outTask.delay(U.outDelay,null,null,[V]);},_hoverOverHandler:function(V){var A=this;var U=A._hoverOptions;U.overTask.delay(U.overDelay,null,null,[V]);},_hoverOutTaskFn:function(V){var A=this;var U=A._hoverOptions;U.overTask.cancel();U.out.apply(U.context||V.currentTarget,arguments);},_hoverOverTaskFn:function(V){var A=this;var U=A._hoverOptions;U.outTask.cancel();U.over.apply(U.context||V.currentTarget,arguments);},_place:function(V,U){var A=this;var W=A.get(G);if(W){if(D.isString(V)){V=O.Node.create(V);}W.insertBefore(V,U);}return A;},_defaultHoverOptions:{overEventType:"mouseenter",outEventType:"mouseleave",overDelay:0,outDelay:0,over:D.emptyFn,out:D.emptyFn}},true);O.NodeList.importMethod(O.Node.prototype,["after","appendTo","attr","before","empty","hide","hover","html","outerHTML","prepend","prependTo","purge","selectText","selectable","show","text","toggle","unselectable","val"]);O.mix(O.NodeList.prototype,{all:function(V){var U=this;var Z=[];var W=U._nodes;var Y=W.length;var A;for(var X=0;X<Y;X++){A=O.Selector.query(V,W[X]);if(A&&A.length){Z.push.apply(Z,A);}}Z=O.Array.unique(Z);return O.all(Z);},first:function(){var A=this;return instacne.item(0);},getDOM:function(){var A=this;return O.NodeList.getDOMNodes(this);},last:function(){var A=this;return A.item(A._nodes.length-1);},one:function(U){var A=this;var X=null;var V=A._nodes;var Y=V.length;for(var W=0;W<Y;W++){X=O.Selector.query(U,V[W],true);
-if(X){X=O.one(X);break;}}return X;}});O.mix(O,{getBody:function(){var A=this;if(!A._bodyNode){A._bodyNode=O.one(document.body);}return A._bodyNode;},getDoc:function(){var A=this;if(!A._documentNode){A._documentNode=O.one(document);}return A._documentNode;},getWin:function(){var A=this;if(!A._windowNode){A._windowNode=O.one(window);}return A._windowNode;}});},"@VERSION@",{requires:["aui-base"]});
+AUI.add("aui-node-base",function(V){var F=V.Lang,O=F.isArray,N=F.isObject,Q=F.isString,E=F.isUndefined,c=F.isValue,J=V.ClassNameManager.getClassName,W="",R=[W,W],D="helper",h=J(D,"hidden"),X=J(D,"unselectable"),Z="innerHTML",f="nextSibling",L="none",K="parentNode",M="script",U=false,H="value";var T=document.createElement("div");T.style.display="none";T.innerHTML=" <link/><table></table>&nbsp;";if(T.attachEvent&&T.fireEvent){T.attachEvent("onclick",function(){U=true;T.detachEvent("onclick",arguments.callee);});T.cloneNode(true).fireEvent("onclick");}var P=!!T.getElementsByTagName("link").length,I=!T.getElementsByTagName("tbody").length,C=T.firstChild.nodeType===3;var b=/^\s+/,B=/=([^=\x27\x22>\s]+\/)>/g,a=/(<([\w:]+)[^>]*?)\/>/g,g=/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,S=/<([\w:]+)/,e=/<tbody/i,d=/<|&#?\w+;/,G=function(i,j,A){return g.test(A)?i:j+"></"+A+">";};var Y={_default:[0,W,W],area:[1,"<map>","</map>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],legend:[1,"<fieldset>","</fieldset>"],option:[1,'<select multiple="multiple">',"</select>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"]};Y.optgroup=Y.option;Y.tbody=Y.tfoot=Y.colgroup=Y.caption=Y.thead;Y.th=Y.td;if(!P){Y._default=[1,"div<div>","</div>"];}V.mix(V.Node.prototype,{ancestors:function(i){var A=this;var k=[];var l=A.getDOM();while(l&&l.nodeType!==9){if(l.nodeType===1){k.push(l);}l=l.parentNode;}var j=new V.all(k);if(i){j=j.filter(i);}return j;},ancestorsByClassName:function(k){var A=this;var j=[];var i=new RegExp("\\b"+k+"\\b");var l=A.getDOM();while(l&&l.nodeType!==9){if(l.nodeType===1&&i.test(l.className)){j.push(l);}l=l.parentNode;}return V.all(j);},appendTo:function(i){var A=this;V.one(i).append(A);return A;},attr:function(j,m){var A=this;if(!E(m)){var l=A.getDOM();if(j in l){A.set(j,m);}else{A.setAttribute(j,m);}return A;}else{if(N(j)){for(var k in j){A.attr(k,j[k]);}return A;}return A.get(j)||A.getAttribute(j);}},clone:(function(){var A;if(U){A=function(){var i=this.getDOM();var k;if(i.nodeType!=3){var j=this.outerHTML();j=j.replace(B,'="$1">').replace(b,"");k=V.one(V.Node._prepareHTML(j)[0]);}else{k=V.one(i.cloneNode());}return k;};}else{A=function(){return this.cloneNode(true);};}return A;})(),center:function(m){var A=this;m=(m&&V.one(m))||V.getBody();var k=m.get("region");var j=A.get("region");var l=k.left+(k.width/2);var i=k.top+(k.height/2);A.setXY([l-(j.width/2),i-(j.height/2)]);},empty:function(){var A=this;A.all(">*").remove().purge();var i=V.Node.getDOMNode(A);while(i.firstChild){i.removeChild(i.firstChild);}return A;},getDOM:function(){var A=this;return V.Node.getDOMNode(A);},guid:function(j){var i=this;var A=i.get("id");if(!A){A=V.stamp(i);i.set("id",A);}return A;},hide:function(i){var A=this;A.addClass(i||A._hideClass||h);return A;},hover:function(j,i){var A=this;var k;var n=A._defaultHoverOptions;if(N(j,true)){k=j;k=V.mix(k,n);j=k.over;i=k.out;}else{k=V.mix({over:j,out:i},n);}A._hoverOptions=k;var m=new V.DelayedTask(A._hoverOverTaskFn,A);var l=new V.DelayedTask(A._hoverOutTaskFn,A);k.overTask=m;k.outTask=l;A.on(k.overEventType,A._hoverOverHandler,A);A.on(k.outEventType,A._hoverOutHandler,A);},html:function(){var A=arguments,i=A.length;if(i){this.set(Z,A[0]);}else{return this.get(Z);}return this;},outerHTML:function(){var A=this;var j=A.getDOM();if("outerHTML" in j){return j.outerHTML;}var i=V.Node.create("<div></div>").append(this.clone());try{return i.html();}catch(k){}finally{i=null;}},placeAfter:function(i){var A=this;return A._place(i,A.get(f));},placeBefore:function(i){var A=this;return A._place(i,A);},prependTo:function(i){var A=this;V.one(i).prepend(A);return A;},radioClass:function(i){var A=this;A.siblings().removeClass(i);A.addClass(i);return A;},resetId:function(i){var A=this;A.attr("id",V.guid(i));return A;},selectText:function(n,j){var A=this;var i=A.getDOM();var l=A.val().length;j=c(j)?j:l;n=c(n)?n:0;try{if(i.setSelectionRange){i.setSelectionRange(n,j);}else{if(i.createTextRange){var k=i.createTextRange();k.moveStart("character",n);k.moveEnd("character",j-l);k.select();}else{i.select();}}if(i!=document.activeElement){i.focus();}}catch(m){}return A;},selectable:function(){var A=this;A.getDOM().unselectable="off";A.detach("selectstart");A.setStyles({"MozUserSelect":"","KhtmlUserSelect":""});A.removeClass(X);return A;},show:function(i){var A=this;A.removeClass(i||A._hideClass||h);return A;},swallowEvent:function(i,j){var A=this;var k=function(l){l.stopPropagation();if(j){l.preventDefault();l.halt();}return false;};if(O(i)){V.Array.each(i,function(l){A.on(l,k);});return this;}else{A.on(i,k);}return A;},text:function(j){var A=this;var i=A.getDOM();if(!E(j)){j=V.DOM._getDoc(i).createTextNode(j);return A.empty().append(j);}return A._getText(i.childNodes);},toggle:function(i){var A=this;var j="hide";var k=i||A._hideClass||h;if(A.hasClass(k)){j="show";}A[j](k);return A;},unselectable:function(){var A=this;A.getDOM().unselectable="on";A.swallowEvent("selectstart",true);A.setStyles({"MozUserSelect":L,"KhtmlUserSelect":L});A.addClass(X);return A;},val:function(i){var A=this;if(E(i)){return A.get(H);}else{return A.set(H,i);}},_getText:function(n){var A=this;var l=n.length;var k;var m=[];for(var j=0;j<l;j++){k=n[j];if(k&&k.nodeType!=8){if(k.nodeType!=1){m.push(k.nodeValue);}if(k.childNodes){m.push(A._getText(k.childNodes));}}}return m.join("");},_hoverOutHandler:function(j){var A=this;var i=A._hoverOptions;i.outTask.delay(i.outDelay,null,null,[j]);},_hoverOverHandler:function(j){var A=this;var i=A._hoverOptions;i.overTask.delay(i.overDelay,null,null,[j]);},_hoverOutTaskFn:function(j){var A=this;var i=A._hoverOptions;i.overTask.cancel();i.out.apply(i.context||j.currentTarget,arguments);},_hoverOverTaskFn:function(j){var A=this;var i=A._hoverOptions;i.outTask.cancel();i.over.apply(i.context||j.currentTarget,arguments);},_place:function(j,i){var A=this;var k=A.get(K);if(k){if(Q(j)){j=V.Node.create(j);
+}k.insertBefore(j,i);}return A;},_defaultHoverOptions:{overEventType:"mouseenter",outEventType:"mouseleave",overDelay:0,outDelay:0,over:F.emptyFn,out:F.emptyFn}},true);V.Node._prepareHTML=function(q){var r=V.config.doc;var m=[];if(Q(q)){if(!d.test(q)){q=r.createTextNode(q);}else{q=q.replace(a,G);var k=(S.exec(q)||R)[1].toLowerCase();var j=Y[k]||Y._default;var p=j[0];var A=r.createElement("div");A.innerHTML=j[1]+q+j[2];while(p--){A=A.lastChild;}if(!I){var s=e.test(q);var o=[];if(k=="table"&&!s){if(A.firstChild){o=A.firstChild.childNodes;}}else{if(j[1]=="<table>"&&!s){o=A.childNodes;}}for(var n=o.length-1;n>=0;--n){var l=o[n];if(l.nodeName.toLowerCase()=="tbody"&&l.childNodes.length){l.parentNode.removeChild(l);}}}if(!C&&b.test(q)){A.insertBefore(r.createTextNode(b.exec(q)[0]),A.firstChild);}q=A.childNodes;}}if(q.nodeType){m.push(q);}else{m=q;}return m;};V.NodeList.importMethod(V.Node.prototype,["after","appendTo","attr","before","empty","hide","hover","html","outerHTML","prepend","prependTo","purge","selectText","selectable","show","text","toggle","unselectable","val"]);V.mix(V.NodeList.prototype,{all:function(k){var j=this;var o=[];var l=j._nodes;var n=l.length;var A;for(var m=0;m<n;m++){A=V.Selector.query(k,l[m]);if(A&&A.length){o.push.apply(o,A);}}o=V.Array.unique(o);return V.all(o);},first:function(){var A=this;return instacne.item(0);},getDOM:function(){var A=this;return V.NodeList.getDOMNodes(this);},last:function(){var A=this;return A.item(A._nodes.length-1);},one:function(j){var A=this;var m=null;var k=A._nodes;var n=k.length;for(var l=0;l<n;l++){m=V.Selector.query(j,k[l],true);if(m){m=V.one(m);break;}}return m;}});V.mix(V,{getBody:function(){var A=this;if(!A._bodyNode){A._bodyNode=V.one(document.body);}return A._bodyNode;},getDoc:function(){var A=this;if(!A._documentNode){A._documentNode=V.one(document);}return A._documentNode;},getWin:function(){var A=this;if(!A._windowNode){A._windowNode=V.one(window);}return A._windowNode;}});},"@VERSION@",{requires:["aui-base"]});
View
130 build/aui-node/aui-node-base.js
@@ -15,7 +15,9 @@ var Lang = A.Lang,
getClassName = A.ClassNameManager.getClassName,
- CLONED_EVENTS = false,
+ STR_EMPTY = '',
+
+ ARRAY_EMPTY_STRINGS = [STR_EMPTY, STR_EMPTY],
HELPER = 'helper',
@@ -27,17 +29,25 @@ var Lang = A.Lang,
NONE = 'none',
PARENT_NODE = 'parentNode',
SCRIPT = 'script',
+
+ SUPPORT_CLONED_EVENTS = false,
+
VALUE = 'value';
- // Event cloning detection support based on pieces from jQuery
+ /*
+ Parts of this file are used from jQuery (http://jquery.com)
+ Dual-licensed under MIT/GPL
+ */
var div = document.createElement('div');
- div.innerHTML = '&nbsp;'; // IE throws an error on fireEvent if the element does not have child nodes
+
+ div.style.display = 'none';
+ div.innerHTML = ' <link/><table></table>&nbsp;';
if (div.attachEvent && div.fireEvent) {
div.attachEvent(
'onclick',
function(){
- CLONED_EVENTS = true;
+ SUPPORT_CLONED_EVENTS = true;
div.detachEvent('onclick', arguments.callee);
}
@@ -46,6 +56,43 @@ var Lang = A.Lang,
div.cloneNode(true).fireEvent('onclick');
}
+ var SUPPORT_SERIALIZE_HTML = !!div.getElementsByTagName('link').length,
+ SUPPORT_OPTIONAL_TBODY = !div.getElementsByTagName('tbody').length,
+ SUPPORT_LEADING_WHITESPACE = div.firstChild.nodeType === 3;
+
+ var REGEX_LEADING_WHITE_SPACE = /^\s+/,
+ REGEX_IE8_ACTION = /=([^=\x27\x22>\s]+\/)>/g,
+ REGEX_XHTML_TAG = /(<([\w:]+)[^>]*?)\/>/g,
+ REGEX_SELF_CLOSING_ELEMENT = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,
+ REGEX_TAGNAME = /<([\w:]+)/,
+ REGEX_TBODY = /<tbody/i,
+ REGEX_HTML = /<|&#?\w+;/,
+
+ FN_CLOSE_TAG = function(all, start, tagName) {
+ return REGEX_SELF_CLOSING_ELEMENT.test(tagName)
+ ? all
+ : start + '></' + tagName + '>';
+ };
+
+ var MAP_WRAPPERS = {
+ _default: [0, STR_EMPTY, STR_EMPTY],
+ area: [1, '<map>', '</map>'],
+ col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
+ legend: [1, '<fieldset>', '</fieldset>'],
+ option: [1, '<select multiple="multiple">', '</select>'],
+ td: [3, '<table><tbody><tr>', '</tr></tbody></table>'],
+ thead: [1, '<table>', '</table>'],
+ tr: [2, '<table><tbody>', '</tbody></table>']
+ };
+
+ MAP_WRAPPERS.optgroup = MAP_WRAPPERS.option;
+ MAP_WRAPPERS.tbody = MAP_WRAPPERS.tfoot = MAP_WRAPPERS.colgroup = MAP_WRAPPERS.caption = MAP_WRAPPERS.thead;
+ MAP_WRAPPERS.th = MAP_WRAPPERS.td;
+
+ if (!SUPPORT_SERIALIZE_HTML) {
+ MAP_WRAPPERS._default = [1, 'div<div>', '</div>'];
+ }
+
/**
* Augment the <a href="Node.html">YUI3 Node</a> with more util methods.
*
@@ -215,13 +262,17 @@ A.mix(A.Node.prototype, {
clone: (function() {
var clone;
- if (CLONED_EVENTS) {
+ if (SUPPORT_CLONED_EVENTS) {
clone = function() {
var el = this.getDOM();
var clone;
if (el.nodeType != 3) {
- clone = A.Node.create(this.outerHTML())
+ var outerHTML = this.outerHTML();
+
+ outerHTML = outerHTML.replace(REGEX_IE8_ACTION, '="$1">').replace(REGEX_LEADING_WHITE_SPACE, '');
+
+ clone = A.one(A.Node._prepareHTML(outerHTML)[0]);
}
else {
clone = A.one(el.cloneNode());
@@ -913,7 +964,7 @@ A.mix(A.Node.prototype, {
var parent = instance.get(PARENT_NODE);
if (parent) {
- if (Lang.isString(newNode)) {
+ if (isString(newNode)) {
newNode = A.Node.create(newNode);
}
@@ -933,6 +984,71 @@ A.mix(A.Node.prototype, {
}
}, true);
+A.Node._prepareHTML = function(element) {
+ var doc = A.config.doc;
+
+ var returnData = [];
+
+ if (isString(element)) {
+ if (!REGEX_HTML.test(element)) {
+ element = doc.createTextNode(element);
+ }
+ else {
+ element = element.replace(REGEX_XHTML_TAG, FN_CLOSE_TAG);
+
+ var tagName = (REGEX_TAGNAME.exec(element) || ARRAY_EMPTY_STRINGS)[1].toLowerCase();
+ var wrap = MAP_WRAPPERS[tagName] || MAP_WRAPPERS._default;
+ var depth = wrap[0];
+ var div = doc.createElement('div');
+
+ div.innerHTML = wrap[1] + element + wrap[2];
+
+ while (depth--) {
+ div = div.lastChild;
+ }
+
+ if (!SUPPORT_OPTIONAL_TBODY) {
+ var hasTBody = REGEX_TBODY.test(element);
+ var tbody = [];
+
+ if (tagName == 'table' && !hasTBody) {
+ if (div.firstChild) {
+ tbody = div.firstChild.childNodes;
+ }
+ }
+ else {
+ if (wrap[1] == '<table>' && !hasTBody) {
+ tbody = div.childNodes;
+ }
+ }
+
+ for (var i = tbody.length - 1; i >= 0; --i) {
+ var node = tbody[i];
+
+ if (node.nodeName.toLowerCase() == 'tbody' && node.childNodes.length) {
+ node.parentNode.removeChild(node);
+ }
+ }
+ }
+
+ if (!SUPPORT_LEADING_WHITESPACE && REGEX_LEADING_WHITE_SPACE.test(element)) {
+ div.insertBefore(doc.createTextNode(REGEX_LEADING_WHITE_SPACE.exec(element)[0]), div.firstChild);
+ }
+
+ element = div.childNodes;
+ }
+ }
+
+ if (element.nodeType) {
+ returnData.push(element);
+ }
+ else {
+ returnData = element;
+ }
+
+ return returnData;
+};
+
/**
* Augment the <a href="NodeList.html">YUI3 NodeList</a> with more util methods.
*
View
130 build/aui-node/aui-node-debug.js
@@ -15,7 +15,9 @@ var Lang = A.Lang,
getClassName = A.ClassNameManager.getClassName,
- CLONED_EVENTS = false,
+ STR_EMPTY = '',
+
+ ARRAY_EMPTY_STRINGS = [STR_EMPTY, STR_EMPTY],
HELPER = 'helper',
@@ -27,17 +29,25 @@ var Lang = A.Lang,
NONE = 'none',
PARENT_NODE = 'parentNode',
SCRIPT = 'script',
+
+ SUPPORT_CLONED_EVENTS = false,
+
VALUE = 'value';
- // Event cloning detection support based on pieces from jQuery
+ /*
+ Parts of this file are used from jQuery (http://jquery.com)
+ Dual-licensed under MIT/GPL
+ */
var div = document.createElement('div');
- div.innerHTML = '&nbsp;'; // IE throws an error on fireEvent if the element does not have child nodes
+
+ div.style.display = 'none';
+ div.innerHTML = ' <link/><table></table>&nbsp;';
if (div.attachEvent && div.fireEvent) {
div.attachEvent(
'onclick',
function(){
- CLONED_EVENTS = true;
+ SUPPORT_CLONED_EVENTS = true;
div.detachEvent('onclick', arguments.callee);
}
@@ -46,6 +56,43 @@ var Lang = A.Lang,
div.cloneNode(true).fireEvent('onclick');
}
+ var SUPPORT_SERIALIZE_HTML = !!div.getElementsByTagName('link').length,
+ SUPPORT_OPTIONAL_TBODY = !div.getElementsByTagName('tbody').length,
+ SUPPORT_LEADING_WHITESPACE = div.firstChild.nodeType === 3;
+
+ var REGEX_LEADING_WHITE_SPACE = /^\s+/,
+ REGEX_IE8_ACTION = /=([^=\x27\x22>\s]+\/)>/g,
+ REGEX_XHTML_TAG = /(<([\w:]+)[^>]*?)\/>/g,
+ REGEX_SELF_CLOSING_ELEMENT = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,
+ REGEX_TAGNAME = /<([\w:]+)/,
+ REGEX_TBODY = /<tbody/i,
+ REGEX_HTML = /<|&#?\w+;/,
+
+ FN_CLOSE_TAG = function(all, start, tagName) {
+ return REGEX_SELF_CLOSING_ELEMENT.test(tagName)
+ ? all
+ : start + '></' + tagName + '>';
+ };
+
+ var MAP_WRAPPERS = {
+ _default: [0, STR_EMPTY, STR_EMPTY],
+ area: [1, '<map>', '</map>'],
+ col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
+ legend: [1, '<fieldset>', '</fieldset>'],
+ option: [1, '<select multiple="multiple">', '</select>'],
+ td: [3, '<table><tbody><tr>', '</tr></tbody></table>'],
+ thead: [1, '<table>', '</table>'],
+ tr: [2, '<table><tbody>', '</tbody></table>']
+ };
+
+ MAP_WRAPPERS.optgroup = MAP_WRAPPERS.option;
+ MAP_WRAPPERS.tbody = MAP_WRAPPERS.tfoot = MAP_WRAPPERS.colgroup = MAP_WRAPPERS.caption = MAP_WRAPPERS.thead;
+ MAP_WRAPPERS.th = MAP_WRAPPERS.td;
+
+ if (!SUPPORT_SERIALIZE_HTML) {
+ MAP_WRAPPERS._default = [1, 'div<div>', '</div>'];
+ }
+
/**
* Augment the <a href="Node.html">YUI3 Node</a> with more util methods.
*
@@ -215,13 +262,17 @@ A.mix(A.Node.prototype, {
clone: (function() {
var clone;
- if (CLONED_EVENTS) {
+ if (SUPPORT_CLONED_EVENTS) {
clone = function() {
var el = this.getDOM();
var clone;
if (el.nodeType != 3) {
- clone = A.Node.create(this.outerHTML())
+ var outerHTML = this.outerHTML();
+
+ outerHTML = outerHTML.replace(REGEX_IE8_ACTION, '="$1">').replace(REGEX_LEADING_WHITE_SPACE, '');
+
+ clone = A.one(A.Node._prepareHTML(outerHTML)[0]);
}
else {
clone = A.one(el.cloneNode());
@@ -913,7 +964,7 @@ A.mix(A.Node.prototype, {
var parent = instance.get(PARENT_NODE);
if (parent) {
- if (Lang.isString(newNode)) {
+ if (isString(newNode)) {
newNode = A.Node.create(newNode);
}
@@ -933,6 +984,71 @@ A.mix(A.Node.prototype, {
}
}, true);
+A.Node._prepareHTML = function(element) {
+ var doc = A.config.doc;
+
+ var returnData = [];
+
+ if (isString(element)) {
+ if (!REGEX_HTML.test(element)) {
+ element = doc.createTextNode(element);
+ }
+ else {
+ element = element.replace(REGEX_XHTML_TAG, FN_CLOSE_TAG);
+
+ var tagName = (REGEX_TAGNAME.exec(element) || ARRAY_EMPTY_STRINGS)[1].toLowerCase();
+ var wrap = MAP_WRAPPERS[tagName] || MAP_WRAPPERS._default;
+ var depth = wrap[0];
+ var div = doc.createElement('div');
+
+ div.innerHTML = wrap[1] + element + wrap[2];
+
+ while (depth--) {
+ div = div.lastChild;
+ }
+
+ if (!SUPPORT_OPTIONAL_TBODY) {
+ var hasTBody = REGEX_TBODY.test(element);
+ var tbody = [];
+
+ if (tagName == 'table' && !hasTBody) {
+ if (div.firstChild) {
+ tbody = div.firstChild.childNodes;
+ }
+ }
+ else {
+ if (wrap[1] == '<table>' && !hasTBody) {
+ tbody = div.childNodes;
+ }
+ }
+
+ for (var i = tbody.length - 1; i >= 0; --i) {
+ var node = tbody[i];
+
+ if (node.nodeName.toLowerCase() == 'tbody' && node.childNodes.length) {
+ node.parentNode.removeChild(node);
+ }
+ }
+ }
+
+ if (!SUPPORT_LEADING_WHITESPACE && REGEX_LEADING_WHITE_SPACE.test(element)) {
+ div.insertBefore(doc.createTextNode(REGEX_LEADING_WHITE_SPACE.exec(element)[0]), div.firstChild);
+ }
+
+ element = div.childNodes;
+ }
+ }
+
+ if (element.nodeType) {
+ returnData.push(element);
+ }
+ else {
+ returnData = element;
+ }
+
+ return returnData;
+};
+
/**
* Augment the <a href="NodeList.html">YUI3 NodeList</a> with more util methods.
*
View
8 build/aui-node/aui-node-min.js
@@ -1,5 +1,5 @@
-AUI.add("aui-node-base",function(O){var D=O.Lang,K=D.isArray,J=D.isObject,L=D.isString,C=D.isUndefined,R=D.isValue,F=O.ClassNameManager.getClassName,N=false,B="helper",T=F(B,"hidden"),P=F(B,"unselectable"),Q="innerHTML",S="nextSibling",H="none",G="parentNode",I="script",E="value";var M=document.createElement("div");M.innerHTML="&nbsp;";if(M.attachEvent&&M.fireEvent){M.attachEvent("onclick",function(){N=true;M.detachEvent("onclick",arguments.callee);});M.cloneNode(true).fireEvent("onclick");}O.mix(O.Node.prototype,{ancestors:function(U){var A=this;var W=[];var X=A.getDOM();while(X&&X.nodeType!==9){if(X.nodeType===1){W.push(X);}X=X.parentNode;}var V=new O.all(W);if(U){V=V.filter(U);}return V;},ancestorsByClassName:function(W){var A=this;var V=[];var U=new RegExp("\\b"+W+"\\b");var X=A.getDOM();while(X&&X.nodeType!==9){if(X.nodeType===1&&U.test(X.className)){V.push(X);}X=X.parentNode;}return O.all(V);},appendTo:function(U){var A=this;O.one(U).append(A);return A;},attr:function(U,X){var A=this;if(!C(X)){var W=A.getDOM();if(U in W){A.set(U,X);}else{A.setAttribute(U,X);}return A;}else{if(J(U)){for(var V in U){A.attr(V,U[V]);}return A;}return A.get(U)||A.getAttribute(U);}},clone:(function(){var A;if(N){A=function(){var U=this.getDOM();var V;if(U.nodeType!=3){V=O.Node.create(this.outerHTML());}else{V=O.one(U.cloneNode());}return V;};}else{A=function(){return this.cloneNode(true);};}return A;})(),center:function(Y){var A=this;Y=(Y&&O.one(Y))||O.getBody();var W=Y.get("region");var V=A.get("region");var X=W.left+(W.width/2);var U=W.top+(W.height/2);A.setXY([X-(V.width/2),U-(V.height/2)]);},empty:function(){var A=this;A.all(">*").remove().purge();var U=O.Node.getDOMNode(A);while(U.firstChild){U.removeChild(U.firstChild);}return A;},getDOM:function(){var A=this;return O.Node.getDOMNode(A);},guid:function(V){var U=this;var A=U.get("id");if(!A){A=O.stamp(U);U.set("id",A);}return A;},hide:function(U){var A=this;A.addClass(U||A._hideClass||T);return A;},hover:function(V,U){var A=this;var W;var Z=A._defaultHoverOptions;if(J(V,true)){W=V;W=O.mix(W,Z);V=W.over;U=W.out;}else{W=O.mix({over:V,out:U},Z);}A._hoverOptions=W;var Y=new O.DelayedTask(A._hoverOverTaskFn,A);var X=new O.DelayedTask(A._hoverOutTaskFn,A);W.overTask=Y;W.outTask=X;A.on(W.overEventType,A._hoverOverHandler,A);A.on(W.outEventType,A._hoverOutHandler,A);},html:function(){var A=arguments,U=A.length;if(U){this.set(Q,A[0]);}else{return this.get(Q);}return this;},outerHTML:function(){var A=this;var V=A.getDOM();if("outerHTML" in V){return V.outerHTML;}var U=O.Node.create("<div></div>").append(this.clone());try{return U.html();}catch(W){}finally{U=null;}},placeAfter:function(U){var A=this;return A._place(U,A.get(S));},placeBefore:function(U){var A=this;return A._place(U,A);},prependTo:function(U){var A=this;O.one(U).prepend(A);return A;},radioClass:function(U){var A=this;A.siblings().removeClass(U);A.addClass(U);return A;},resetId:function(U){var A=this;A.attr("id",O.guid(U));return A;},selectText:function(Z,V){var A=this;var U=A.getDOM();var X=A.val().length;V=R(V)?V:X;Z=R(Z)?Z:0;try{if(U.setSelectionRange){U.setSelectionRange(Z,V);}else{if(U.createTextRange){var W=U.createTextRange();W.moveStart("character",Z);W.moveEnd("character",V-X);W.select();}else{U.select();}}if(U!=document.activeElement){U.focus();}}catch(Y){}return A;},selectable:function(){var A=this;A.getDOM().unselectable="off";A.detach("selectstart");A.setStyles({"MozUserSelect":"","KhtmlUserSelect":""});A.removeClass(P);return A;},show:function(U){var A=this;A.removeClass(U||A._hideClass||T);return A;},swallowEvent:function(U,V){var A=this;var W=function(X){X.stopPropagation();if(V){X.preventDefault();X.halt();}return false;};if(K(U)){O.Array.each(U,function(X){A.on(X,W);});return this;}else{A.on(U,W);}return A;},text:function(V){var A=this;var U=A.getDOM();if(!C(V)){V=O.DOM._getDoc(U).createTextNode(V);return A.empty().append(V);}return A._getText(U.childNodes);},toggle:function(U){var A=this;var V="hide";var W=U||A._hideClass||T;if(A.hasClass(W)){V="show";}A[V](W);return A;},unselectable:function(){var A=this;A.getDOM().unselectable="on";A.swallowEvent("selectstart",true);A.setStyles({"MozUserSelect":H,"KhtmlUserSelect":H});A.addClass(P);return A;},val:function(U){var A=this;if(C(U)){return A.get(E);}else{return A.set(E,U);}},_getText:function(Y){var A=this;var W=Y.length;var V;var X=[];for(var U=0;U<W;U++){V=Y[U];if(V&&V.nodeType!=8){if(V.nodeType!=1){X.push(V.nodeValue);}if(V.childNodes){X.push(A._getText(V.childNodes));}}}return X.join("");},_hoverOutHandler:function(V){var A=this;var U=A._hoverOptions;U.outTask.delay(U.outDelay,null,null,[V]);},_hoverOverHandler:function(V){var A=this;var U=A._hoverOptions;U.overTask.delay(U.overDelay,null,null,[V]);},_hoverOutTaskFn:function(V){var A=this;var U=A._hoverOptions;U.overTask.cancel();U.out.apply(U.context||V.currentTarget,arguments);},_hoverOverTaskFn:function(V){var A=this;var U=A._hoverOptions;U.outTask.cancel();U.over.apply(U.context||V.currentTarget,arguments);},_place:function(V,U){var A=this;var W=A.get(G);if(W){if(D.isString(V)){V=O.Node.create(V);}W.insertBefore(V,U);}return A;},_defaultHoverOptions:{overEventType:"mouseenter",outEventType:"mouseleave",overDelay:0,outDelay:0,over:D.emptyFn,out:D.emptyFn}},true);O.NodeList.importMethod(O.Node.prototype,["after","appendTo","attr","before","empty","hide","hover","html","outerHTML","prepend","prependTo","purge","selectText","selectable","show","text","toggle","unselectable","val"]);O.mix(O.NodeList.prototype,{all:function(V){var U=this;var Z=[];var W=U._nodes;var Y=W.length;var A;for(var X=0;X<Y;X++){A=O.Selector.query(V,W[X]);if(A&&A.length){Z.push.apply(Z,A);}}Z=O.Array.unique(Z);return O.all(Z);},first:function(){var A=this;return instacne.item(0);},getDOM:function(){var A=this;return O.NodeList.getDOMNodes(this);},last:function(){var A=this;return A.item(A._nodes.length-1);},one:function(U){var A=this;var X=null;var V=A._nodes;var Y=V.length;for(var W=0;W<Y;W++){X=O.Selector.query(U,V[W],true);
-if(X){X=O.one(X);break;}}return X;}});O.mix(O,{getBody:function(){var A=this;if(!A._bodyNode){A._bodyNode=O.one(document.body);}return A._bodyNode;},getDoc:function(){var A=this;if(!A._documentNode){A._documentNode=O.one(document);}return A._documentNode;},getWin:function(){var A=this;if(!A._windowNode){A._windowNode=O.one(window);}return A._windowNode;}});},"@VERSION@",{requires:["aui-base"]});AUI.add("aui-node-html5",function(B){if(B.UA.ie){var D=B.namespace("HTML5"),C=B.DOM._create;if(!D._fragHTML5Shived){D._fragHTML5Shived=YUI.AUI.html5shiv(document.createDocumentFragment());}B.mix(D,{IECreateFix:function(F,E){var A=D._fragHTML5Shived;A.appendChild(F);F.innerHTML=E;A.removeChild(F);return F;},_doBeforeCreate:function(F,H,E){var G=C.apply(this,arguments);var A=D.IECreateFix(G,F);return new B.Do.Halt(null,A);}});B.Do.before(D._doBeforeCreate,B.DOM,"_create",B.DOM);}},"@VERSION@",{requires:["collection","aui-base"]});AUI.add("aui-node-html5-print",function(A){
+AUI.add("aui-node-base",function(V){var F=V.Lang,O=F.isArray,N=F.isObject,Q=F.isString,E=F.isUndefined,c=F.isValue,J=V.ClassNameManager.getClassName,W="",R=[W,W],D="helper",h=J(D,"hidden"),X=J(D,"unselectable"),Z="innerHTML",f="nextSibling",L="none",K="parentNode",M="script",U=false,H="value";var T=document.createElement("div");T.style.display="none";T.innerHTML=" <link/><table></table>&nbsp;";if(T.attachEvent&&T.fireEvent){T.attachEvent("onclick",function(){U=true;T.detachEvent("onclick",arguments.callee);});T.cloneNode(true).fireEvent("onclick");}var P=!!T.getElementsByTagName("link").length,I=!T.getElementsByTagName("tbody").length,C=T.firstChild.nodeType===3;var b=/^\s+/,B=/=([^=\x27\x22>\s]+\/)>/g,a=/(<([\w:]+)[^>]*?)\/>/g,g=/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,S=/<([\w:]+)/,e=/<tbody/i,d=/<|&#?\w+;/,G=function(i,j,A){return g.test(A)?i:j+"></"+A+">";};var Y={_default:[0,W,W],area:[1,"<map>","</map>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],legend:[1,"<fieldset>","</fieldset>"],option:[1,'<select multiple="multiple">',"</select>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"]};Y.optgroup=Y.option;Y.tbody=Y.tfoot=Y.colgroup=Y.caption=Y.thead;Y.th=Y.td;if(!P){Y._default=[1,"div<div>","</div>"];}V.mix(V.Node.prototype,{ancestors:function(i){var A=this;var k=[];var l=A.getDOM();while(l&&l.nodeType!==9){if(l.nodeType===1){k.push(l);}l=l.parentNode;}var j=new V.all(k);if(i){j=j.filter(i);}return j;},ancestorsByClassName:function(k){var A=this;var j=[];var i=new RegExp("\\b"+k+"\\b");var l=A.getDOM();while(l&&l.nodeType!==9){if(l.nodeType===1&&i.test(l.className)){j.push(l);}l=l.parentNode;}return V.all(j);},appendTo:function(i){var A=this;V.one(i).append(A);return A;},attr:function(j,m){var A=this;if(!E(m)){var l=A.getDOM();if(j in l){A.set(j,m);}else{A.setAttribute(j,m);}return A;}else{if(N(j)){for(var k in j){A.attr(k,j[k]);}return A;}return A.get(j)||A.getAttribute(j);}},clone:(function(){var A;if(U){A=function(){var i=this.getDOM();var k;if(i.nodeType!=3){var j=this.outerHTML();j=j.replace(B,'="$1">').replace(b,"");k=V.one(V.Node._prepareHTML(j)[0]);}else{k=V.one(i.cloneNode());}return k;};}else{A=function(){return this.cloneNode(true);};}return A;})(),center:function(m){var A=this;m=(m&&V.one(m))||V.getBody();var k=m.get("region");var j=A.get("region");var l=k.left+(k.width/2);var i=k.top+(k.height/2);A.setXY([l-(j.width/2),i-(j.height/2)]);},empty:function(){var A=this;A.all(">*").remove().purge();var i=V.Node.getDOMNode(A);while(i.firstChild){i.removeChild(i.firstChild);}return A;},getDOM:function(){var A=this;return V.Node.getDOMNode(A);},guid:function(j){var i=this;var A=i.get("id");if(!A){A=V.stamp(i);i.set("id",A);}return A;},hide:function(i){var A=this;A.addClass(i||A._hideClass||h);return A;},hover:function(j,i){var A=this;var k;var n=A._defaultHoverOptions;if(N(j,true)){k=j;k=V.mix(k,n);j=k.over;i=k.out;}else{k=V.mix({over:j,out:i},n);}A._hoverOptions=k;var m=new V.DelayedTask(A._hoverOverTaskFn,A);var l=new V.DelayedTask(A._hoverOutTaskFn,A);k.overTask=m;k.outTask=l;A.on(k.overEventType,A._hoverOverHandler,A);A.on(k.outEventType,A._hoverOutHandler,A);},html:function(){var A=arguments,i=A.length;if(i){this.set(Z,A[0]);}else{return this.get(Z);}return this;},outerHTML:function(){var A=this;var j=A.getDOM();if("outerHTML" in j){return j.outerHTML;}var i=V.Node.create("<div></div>").append(this.clone());try{return i.html();}catch(k){}finally{i=null;}},placeAfter:function(i){var A=this;return A._place(i,A.get(f));},placeBefore:function(i){var A=this;return A._place(i,A);},prependTo:function(i){var A=this;V.one(i).prepend(A);return A;},radioClass:function(i){var A=this;A.siblings().removeClass(i);A.addClass(i);return A;},resetId:function(i){var A=this;A.attr("id",V.guid(i));return A;},selectText:function(n,j){var A=this;var i=A.getDOM();var l=A.val().length;j=c(j)?j:l;n=c(n)?n:0;try{if(i.setSelectionRange){i.setSelectionRange(n,j);}else{if(i.createTextRange){var k=i.createTextRange();k.moveStart("character",n);k.moveEnd("character",j-l);k.select();}else{i.select();}}if(i!=document.activeElement){i.focus();}}catch(m){}return A;},selectable:function(){var A=this;A.getDOM().unselectable="off";A.detach("selectstart");A.setStyles({"MozUserSelect":"","KhtmlUserSelect":""});A.removeClass(X);return A;},show:function(i){var A=this;A.removeClass(i||A._hideClass||h);return A;},swallowEvent:function(i,j){var A=this;var k=function(l){l.stopPropagation();if(j){l.preventDefault();l.halt();}return false;};if(O(i)){V.Array.each(i,function(l){A.on(l,k);});return this;}else{A.on(i,k);}return A;},text:function(j){var A=this;var i=A.getDOM();if(!E(j)){j=V.DOM._getDoc(i).createTextNode(j);return A.empty().append(j);}return A._getText(i.childNodes);},toggle:function(i){var A=this;var j="hide";var k=i||A._hideClass||h;if(A.hasClass(k)){j="show";}A[j](k);return A;},unselectable:function(){var A=this;A.getDOM().unselectable="on";A.swallowEvent("selectstart",true);A.setStyles({"MozUserSelect":L,"KhtmlUserSelect":L});A.addClass(X);return A;},val:function(i){var A=this;if(E(i)){return A.get(H);}else{return A.set(H,i);}},_getText:function(n){var A=this;var l=n.length;var k;var m=[];for(var j=0;j<l;j++){k=n[j];if(k&&k.nodeType!=8){if(k.nodeType!=1){m.push(k.nodeValue);}if(k.childNodes){m.push(A._getText(k.childNodes));}}}return m.join("");},_hoverOutHandler:function(j){var A=this;var i=A._hoverOptions;i.outTask.delay(i.outDelay,null,null,[j]);},_hoverOverHandler:function(j){var A=this;var i=A._hoverOptions;i.overTask.delay(i.overDelay,null,null,[j]);},_hoverOutTaskFn:function(j){var A=this;var i=A._hoverOptions;i.overTask.cancel();i.out.apply(i.context||j.currentTarget,arguments);},_hoverOverTaskFn:function(j){var A=this;var i=A._hoverOptions;i.outTask.cancel();i.over.apply(i.context||j.currentTarget,arguments);},_place:function(j,i){var A=this;var k=A.get(K);if(k){if(Q(j)){j=V.Node.create(j);
+}k.insertBefore(j,i);}return A;},_defaultHoverOptions:{overEventType:"mouseenter",outEventType:"mouseleave",overDelay:0,outDelay:0,over:F.emptyFn,out:F.emptyFn}},true);V.Node._prepareHTML=function(q){var r=V.config.doc;var m=[];if(Q(q)){if(!d.test(q)){q=r.createTextNode(q);}else{q=q.replace(a,G);var k=(S.exec(q)||R)[1].toLowerCase();var j=Y[k]||Y._default;var p=j[0];var A=r.createElement("div");A.innerHTML=j[1]+q+j[2];while(p--){A=A.lastChild;}if(!I){var s=e.test(q);var o=[];if(k=="table"&&!s){if(A.firstChild){o=A.firstChild.childNodes;}}else{if(j[1]=="<table>"&&!s){o=A.childNodes;}}for(var n=o.length-1;n>=0;--n){var l=o[n];if(l.nodeName.toLowerCase()=="tbody"&&l.childNodes.length){l.parentNode.removeChild(l);}}}if(!C&&b.test(q)){A.insertBefore(r.createTextNode(b.exec(q)[0]),A.firstChild);}q=A.childNodes;}}if(q.nodeType){m.push(q);}else{m=q;}return m;};V.NodeList.importMethod(V.Node.prototype,["after","appendTo","attr","before","empty","hide","hover","html","outerHTML","prepend","prependTo","purge","selectText","selectable","show","text","toggle","unselectable","val"]);V.mix(V.NodeList.prototype,{all:function(k){var j=this;var o=[];var l=j._nodes;var n=l.length;var A;for(var m=0;m<n;m++){A=V.Selector.query(k,l[m]);if(A&&A.length){o.push.apply(o,A);}}o=V.Array.unique(o);return V.all(o);},first:function(){var A=this;return instacne.item(0);},getDOM:function(){var A=this;return V.NodeList.getDOMNodes(this);},last:function(){var A=this;return A.item(A._nodes.length-1);},one:function(j){var A=this;var m=null;var k=A._nodes;var n=k.length;for(var l=0;l<n;l++){m=V.Selector.query(j,k[l],true);if(m){m=V.one(m);break;}}return m;}});V.mix(V,{getBody:function(){var A=this;if(!A._bodyNode){A._bodyNode=V.one(document.body);}return A._bodyNode;},getDoc:function(){var A=this;if(!A._documentNode){A._documentNode=V.one(document);}return A._documentNode;},getWin:function(){var A=this;if(!A._windowNode){A._windowNode=V.one(window);}return A._windowNode;}});},"@VERSION@",{requires:["aui-base"]});AUI.add("aui-node-html5",function(B){if(B.UA.ie){var D=B.namespace("HTML5"),C=B.DOM._create;if(!D._fragHTML5Shived){D._fragHTML5Shived=YUI.AUI.html5shiv(document.createDocumentFragment());}B.mix(D,{IECreateFix:function(F,E){var A=D._fragHTML5Shived;A.appendChild(F);F.innerHTML=E;A.removeChild(F);return F;},_doBeforeCreate:function(F,H,E){var G=C.apply(this,arguments);var A=D.IECreateFix(G,F);return new B.Do.Halt(null,A);}});B.Do.before(D._doBeforeCreate,B.DOM,"_create",B.DOM);}},"@VERSION@",{requires:["collection","aui-base"]});AUI.add("aui-node-html5-print",function(A){
/*@cc_on@if(@_jscript_version<9)
(function (window, document) {
@@ -103,5 +103,5 @@ window.attachEvent('onafterprint', onAfterPrint);
}(A.config.win, A.config.doc));
@end@*/
-},"@VERSION@",{requires:["aui-node-html5"]});AUI.add("aui-node-fx",function(B){var D=B.Lang;B.Node.ATTRS.fx={getter:function(){var A=this;if(!A.fx){A.plug(B.Plugin.NodeFX);}return A.fx;}};var E={fast:0.1,normal:1,slow:1.5};var C=function(A){var G=1;if(D.isNumber(A)){G=A;A=null;}if(D.isString(A)){var F=A.toLowerCase();if(F in E){G=E[F];}A=null;}A=A||{duration:G};return A;};B.mix(B.Node.prototype,{fadeIn:function(G){var A=this;var H=A.get("fx");G=C(G);var F=H.get("to.opacity")||0;if(F==1){F=0;}B.mix(G,{from:{opacity:F},to:{opacity:1},reverse:false});H.setAttrs(G);H.run();},fadeOut:function(F){var A=this;var G=A.get("fx");F=C(F);B.mix(F,{from:{opacity:G.get("to.opacity")||1},to:{opacity:0},reverse:false});G.setAttrs(F);G.run();},fadeTo:function(G,J){var A=this;var F=0;if(D.isNumber(G)||D.isString(G)){F=parseFloat(G);G=null;}G=G||{};J=J||1;if(D.isString(J)){var I=J.toLowerCase();if(I in E){J=E[I];}}B.mix(G,{duration:J,to:{opacity:F},reverse:false});var H=A.get("fx");H.setAttrs(G);H.run();},fadeToggle:function(J){var F=this;J=J||1;if(D.isString(J)){var H=J.toLowerCase();if(H in E){J=E[H];}}var G=F.get("fx");if(false&&!G._fadeToggleSet){G._fadeToggleSet={from:{opacity:0},to:{opacity:1}};G.setAttrs(G._fadeToggleSet);}var I=G.get("from.opacity");var A=G.get("to.opacity");if(D.isUndefined(I)){I=0;}if(D.isUndefined(A)){A=1;}I=Math.round(I);A=Math.round(A);if(I==A){A=(I==1)?0:1;}G.setAttrs({from:{opacity:I},to:{opacity:A},duration:J,reverse:!G.get("reverse")});G.run();},slideDown:function(F){var A=this;var G=A.get("fx");F=C(F);B.mix(F,{from:{height:0},to:{height:function(H){return H.get("scrollHeight");}},reverse:false});G.setAttrs(F);G.on("start",function(H){G.detach("nodefx:start",arguments.callee);A.setStyle("overflow","hidden");});G.run();},slideToggle:function(F){var A=this;var G=A.get("fx");var I=1;if(D.isNumber(F)){I=F;}if(D.isString(F)){var H=F.toLowerCase();if(H in E){I=E[H];}}if(!G._slideToggleSet){G.setAttrs({from:{height:0},to:{height:function(J){return J.get("scrollHeight");}},reverse:false});G._slideToggleSet=true;
-}G.on("start",function(J){G.detach("nodefx:start",arguments.callee);A.setStyle("overflow","hidden");});G.set("duration",I);G.set("reverse",!G.get("reverse"));G.run();},slideUp:function(F){var A=this;var G=A.get("fx");F=C(F);B.mix(F,{from:{height:function(H){return H.get("scrollHeight");}},to:{height:0},reverse:false});G.setAttrs(F);G.on("start",function(H){G.detach("nodefx:start",arguments.callee);A.setStyle("overflow","hidden");});G.run();}});},"@VERSION@",{requires:["aui-base","anim","anim-node-plugin"]});AUI.add("aui-node",function(B){},"@VERSION@",{skinnable:false,use:["aui-node-base","aui-node-html5","aui-node-html5-print","aui-node-fx"]});
+},"@VERSION@",{requires:["aui-node-html5"]});AUI.add("aui-node-fx",function(B){var D=B.Lang;B.Node.ATTRS.fx={getter:function(){var A=this;if(!A.fx){A.plug(B.Plugin.NodeFX);}return A.fx;}};var E={fast:0.1,normal:1,slow:1.5};var C=function(A){var G=1;if(D.isNumber(A)){G=A;A=null;}if(D.isString(A)){var F=A.toLowerCase();if(F in E){G=E[F];}A=null;}A=A||{duration:G};return A;};B.mix(B.Node.prototype,{fadeIn:function(G){var A=this;var H=A.get("fx");
+G=C(G);var F=H.get("to.opacity")||0;if(F==1){F=0;}B.mix(G,{from:{opacity:F},to:{opacity:1},reverse:false});H.setAttrs(G);H.run();},fadeOut:function(F){var A=this;var G=A.get("fx");F=C(F);B.mix(F,{from:{opacity:G.get("to.opacity")||1},to:{opacity:0},reverse:false});G.setAttrs(F);G.run();},fadeTo:function(G,J){var A=this;var F=0;if(D.isNumber(G)||D.isString(G)){F=parseFloat(G);G=null;}G=G||{};J=J||1;if(D.isString(J)){var I=J.toLowerCase();if(I in E){J=E[I];}}B.mix(G,{duration:J,to:{opacity:F},reverse:false});var H=A.get("fx");H.setAttrs(G);H.run();},fadeToggle:function(J){var F=this;J=J||1;if(D.isString(J)){var H=J.toLowerCase();if(H in E){J=E[H];}}var G=F.get("fx");if(false&&!G._fadeToggleSet){G._fadeToggleSet={from:{opacity:0},to:{opacity:1}};G.setAttrs(G._fadeToggleSet);}var I=G.get("from.opacity");var A=G.get("to.opacity");if(D.isUndefined(I)){I=0;}if(D.isUndefined(A)){A=1;}I=Math.round(I);A=Math.round(A);if(I==A){A=(I==1)?0:1;}G.setAttrs({from:{opacity:I},to:{opacity:A},duration:J,reverse:!G.get("reverse")});G.run();},slideDown:function(F){var A=this;var G=A.get("fx");F=C(F);B.mix(F,{from:{height:0},to:{height:function(H){return H.get("scrollHeight");}},reverse:false});G.setAttrs(F);G.on("start",function(H){G.detach("nodefx:start",arguments.callee);A.setStyle("overflow","hidden");});G.run();},slideToggle:function(F){var A=this;var G=A.get("fx");var I=1;if(D.isNumber(F)){I=F;}if(D.isString(F)){var H=F.toLowerCase();if(H in E){I=E[H];}}if(!G._slideToggleSet){G.setAttrs({from:{height:0},to:{height:function(J){return J.get("scrollHeight");}},reverse:false});G._slideToggleSet=true;}G.on("start",function(J){G.detach("nodefx:start",arguments.callee);A.setStyle("overflow","hidden");});G.set("duration",I);G.set("reverse",!G.get("reverse"));G.run();},slideUp:function(F){var A=this;var G=A.get("fx");F=C(F);B.mix(F,{from:{height:function(H){return H.get("scrollHeight");}},to:{height:0},reverse:false});G.setAttrs(F);G.on("start",function(H){G.detach("nodefx:start",arguments.callee);A.setStyle("overflow","hidden");});G.run();}});},"@VERSION@",{requires:["aui-base","anim","anim-node-plugin"]});AUI.add("aui-node",function(B){},"@VERSION@",{skinnable:false,use:["aui-node-base","aui-node-html5","aui-node-html5-print","aui-node-fx"]});
View
130 build/aui-node/aui-node.js
@@ -15,7 +15,9 @@ var Lang = A.Lang,
getClassName = A.ClassNameManager.getClassName,
- CLONED_EVENTS = false,
+ STR_EMPTY = '',
+
+ ARRAY_EMPTY_STRINGS = [STR_EMPTY, STR_EMPTY],
HELPER = 'helper',
@@ -27,17 +29,25 @@ var Lang = A.Lang,
NONE = 'none',
PARENT_NODE = 'parentNode',
SCRIPT = 'script',
+
+ SUPPORT_CLONED_EVENTS = false,
+
VALUE = 'value';
- // Event cloning detection support based on pieces from jQuery
+ /*
+ Parts of this file are used from jQuery (http://jquery.com)
+ Dual-licensed under MIT/GPL
+ */
var div = document.createElement('div');
- div.innerHTML = '&nbsp;'; // IE throws an error on fireEvent if the element does not have child nodes
+
+ div.style.display = 'none';
+ div.innerHTML = ' <link/><table></table>&nbsp;';
if (div.attachEvent && div.fireEvent) {
div.attachEvent(
'onclick',
function(){
- CLONED_EVENTS = true;
+ SUPPORT_CLONED_EVENTS = true;
div.detachEvent('onclick', arguments.callee);
}
@@ -46,6 +56,43 @@ var Lang = A.Lang,
div.cloneNode(true).fireEvent('onclick');
}
+ var SUPPORT_SERIALIZE_HTML = !!div.getElementsByTagName('link').length,
+ SUPPORT_OPTIONAL_TBODY = !div.getElementsByTagName('tbody').length,
+ SUPPORT_LEADING_WHITESPACE = div.firstChild.nodeType === 3;
+
+ var REGEX_LEADING_WHITE_SPACE = /^\s+/,
+ REGEX_IE8_ACTION = /=([^=\x27\x22>\s]+\/)>/g,
+ REGEX_XHTML_TAG = /(<([\w:]+)[^>]*?)\/>/g,
+ REGEX_SELF_CLOSING_ELEMENT = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,
+ REGEX_TAGNAME = /<([\w:]+)/,
+ REGEX_TBODY = /<tbody/i,
+ REGEX_HTML = /<|&#?\w+;/,
+
+ FN_CLOSE_TAG = function(all, start, tagName) {
+ return REGEX_SELF_CLOSING_ELEMENT.test(tagName)
+ ? all
+ : start + '></' + tagName + '>';
+ };
+
+ var MAP_WRAPPERS = {
+ _default: [0, STR_EMPTY, STR_EMPTY],
+ area: [1, '<map>', '</map>'],
+ col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
+ legend: [1, '<fieldset>', '</fieldset>'],
+ option: [1, '<select multiple="multiple">', '</select>'],
+ td: [3, '<table><tbody><tr>', '</tr></tbody></table>'],
+ thead: [1, '<table>', '</table>'],
+ tr: [2, '<table><tbody>', '</tbody></table>']
+ };
+
+ MAP_WRAPPERS.optgroup = MAP_WRAPPERS.option;
+ MAP_WRAPPERS.tbody = MAP_WRAPPERS.tfoot = MAP_WRAPPERS.colgroup = MAP_WRAPPERS.caption = MAP_WRAPPERS.thead;
+ MAP_WRAPPERS.th = MAP_WRAPPERS.td;
+
+ if (!SUPPORT_SERIALIZE_HTML) {
+ MAP_WRAPPERS._default = [1, 'div<div>', '</div>'];
+ }
+
/**
* Augment the <a href="Node.html">YUI3 Node</a> with more util methods.
*
@@ -215,13 +262,17 @@ A.mix(A.Node.prototype, {
clone: (function() {
var clone;
- if (CLONED_EVENTS) {
+ if (SUPPORT_CLONED_EVENTS) {
clone = function() {
var el = this.getDOM();
var clone;
if (el.nodeType != 3) {
- clone = A.Node.create(this.outerHTML())
+ var outerHTML = this.outerHTML();
+
+ outerHTML = outerHTML.replace(REGEX_IE8_ACTION, '="$1">').replace(REGEX_LEADING_WHITE_SPACE, '');
+
+ clone = A.one(A.Node._prepareHTML(outerHTML)[0]);
}
else {
clone = A.one(el.cloneNode());
@@ -913,7 +964,7 @@ A.mix(A.Node.prototype, {
var parent = instance.get(PARENT_NODE);
if (parent) {
- if (Lang.isString(newNode)) {
+ if (isString(newNode)) {
newNode = A.Node.create(newNode);
}
@@ -933,6 +984,71 @@ A.mix(A.Node.prototype, {
}
}, true);
+A.Node._prepareHTML = function(element) {
+ var doc = A.config.doc;
+
+ var returnData = [];
+
+ if (isString(element)) {
+ if (!REGEX_HTML.test(element)) {
+ element = doc.createTextNode(element);
+ }
+ else {
+ element = element.replace(REGEX_XHTML_TAG, FN_CLOSE_TAG);
+
+ var tagName = (REGEX_TAGNAME.exec(element) || ARRAY_EMPTY_STRINGS)[1].toLowerCase();
+ var wrap = MAP_WRAPPERS[tagName] || MAP_WRAPPERS._default;
+ var depth = wrap[0];
+ var div = doc.createElement('div');
+
+ div.innerHTML = wrap[1] + element + wrap[2];
+
+ while (depth--) {
+ div = div.lastChild;
+ }
+
+ if (!SUPPORT_OPTIONAL_TBODY) {
+ var hasTBody = REGEX_TBODY.test(element);
+ var tbody = [];
+
+ if (tagName == 'table' && !hasTBody) {
+ if (div.firstChild) {
+ tbody = div.firstChild.childNodes;
+ }
+ }
+ else {
+ if (wrap[1] == '<table>' && !hasTBody) {
+ tbody = div.childNodes;
+ }
+ }
+
+ for (var i = tbody.length - 1; i >= 0; --i) {
+ var node = tbody[i];
+
+ if (node.nodeName.toLowerCase() == 'tbody' && node.childNodes.length) {
+ node.parentNode.removeChild(node);
+ }
+ }
+ }
+
+ if (!SUPPORT_LEADING_WHITESPACE && REGEX_LEADING_WHITE_SPACE.test(element)) {
+ div.insertBefore(doc.createTextNode(REGEX_LEADING_WHITE_SPACE.exec(element)[0]), div.firstChild);
+ }
+
+ element = div.childNodes;
+ }
+ }
+
+ if (element.nodeType) {
+ returnData.push(element);
+ }
+ else {
+ returnData = element;
+ }
+
+ return returnData;
+};
+
/**
* Augment the <a href="NodeList.html">YUI3 NodeList</a> with more util methods.
*
View
130 src/aui-node/js/aui-node-base.js
@@ -14,7 +14,9 @@ var Lang = A.Lang,
getClassName = A.ClassNameManager.getClassName,
- CLONED_EVENTS = false,
+ STR_EMPTY = '',
+
+ ARRAY_EMPTY_STRINGS = [STR_EMPTY, STR_EMPTY],
HELPER = 'helper',
@@ -26,17 +28,25 @@ var Lang = A.Lang,
NONE = 'none',
PARENT_NODE = 'parentNode',
SCRIPT = 'script',
+
+ SUPPORT_CLONED_EVENTS = false,
+
VALUE = 'value';
- // Event cloning detection support based on pieces from jQuery
+ /*
+ Parts of this file are used from jQuery (http://jquery.com)
+ Dual-licensed under MIT/GPL
+ */
var div = document.createElement('div');
- div.innerHTML = '&nbsp;'; // IE throws an error on fireEvent if the element does not have child nodes
+
+ div.style.display = 'none';
+ div.innerHTML = ' <link/><table></table>&nbsp;';
if (div.attachEvent && div.fireEvent) {
div.attachEvent(
'onclick',
function(){
- CLONED_EVENTS = true;
+ SUPPORT_CLONED_EVENTS = true;
div.detachEvent('onclick', arguments.callee);
}
@@ -45,6 +55,43 @@ var Lang = A.Lang,
div.cloneNode(true).fireEvent('onclick');
}
+ var SUPPORT_SERIALIZE_HTML = !!div.getElementsByTagName('link').length,
+ SUPPORT_OPTIONAL_TBODY = !div.getElementsByTagName('tbody').length,
+ SUPPORT_LEADING_WHITESPACE = div.firstChild.nodeType === 3;
+
+ var REGEX_LEADING_WHITE_SPACE = /^\s+/,
+ REGEX_IE8_ACTION = /=([^=\x27\x22>\s]+\/)>/g,
+ REGEX_XHTML_TAG = /(<([\w:]+)[^>]*?)\/>/g,
+ REGEX_SELF_CLOSING_ELEMENT = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,
+ REGEX_TAGNAME = /<([\w:]+)/,
+ REGEX_TBODY = /<tbody/i,
+ REGEX_HTML = /<|&#?\w+;/,
+
+ FN_CLOSE_TAG = function(all, start, tagName) {
+ return REGEX_SELF_CLOSING_ELEMENT.test(tagName)
+ ? all
+ : start + '></' + tagName + '>';
+ };
+
+ var MAP_WRAPPERS = {
+ _default: [0, STR_EMPTY, STR_EMPTY],
+ area: [1, '<map>', '</map>'],
+ col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
+ legend: [1, '<fieldset>', '</fieldset>'],
+ option: [1, '<select multiple="multiple">', '</select>'],
+ td: [3, '<table><tbody><tr>', '</tr></tbody></table>'],
+ thead: [1, '<table>', '</table>'],
+ tr: [2, '<table><tbody>', '</tbody></table>']
+ };
+
+ MAP_WRAPPERS.optgroup = MAP_WRAPPERS.option;
+ MAP_WRAPPERS.tbody = MAP_WRAPPERS.tfoot = MAP_WRAPPERS.colgroup = MAP_WRAPPERS.caption = MAP_WRAPPERS.thead;
+ MAP_WRAPPERS.th = MAP_WRAPPERS.td;
+
+ if (!SUPPORT_SERIALIZE_HTML) {
+ MAP_WRAPPERS._default = [1, 'div<div>', '</div>'];
+ }
+
/**
* Augment the <a href="Node.html">YUI3 Node</a> with more util methods.
*
@@ -214,13 +261,17 @@ A.mix(A.Node.prototype, {
clone: (function() {
var clone;
- if (CLONED_EVENTS) {
+ if (SUPPORT_CLONED_EVENTS) {
clone = function() {
var el = this.getDOM();
var clone;
if (el.nodeType != 3) {
- clone = A.Node.create(this.outerHTML())
+ var outerHTML = this.outerHTML();
+
+ outerHTML = outerHTML.replace(REGEX_IE8_ACTION, '="$1">').replace(REGEX_LEADING_WHITE_SPACE, '');
+
+ clone = A.one(A.Node._prepareHTML(outerHTML)[0]);
}
else {
clone = A.one(el.cloneNode());
@@ -912,7 +963,7 @@ A.mix(A.Node.prototype, {
var parent = instance.get(PARENT_NODE);
if (parent) {
- if (Lang.isString(newNode)) {
+ if (isString(newNode)) {
newNode = A.Node.create(newNode);
}
@@ -932,6 +983,71 @@ A.mix(A.Node.prototype, {
}
}, true);
+A.Node._prepareHTML = function(element) {
+ var doc = A.config.doc;
+
+ var returnData = [];
+
+ if (isString(element)) {
+ if (!REGEX_HTML.test(element)) {
+ element = doc.createTextNode(element);
+ }
+ else {
+ element = element.replace(REGEX_XHTML_TAG, FN_CLOSE_TAG);
+
+ var tagName = (REGEX_TAGNAME.exec(element) || ARRAY_EMPTY_STRINGS)[1].toLowerCase();
+ var wrap = MAP_WRAPPERS[tagName] || MAP_WRAPPERS._default;
+ var depth = wrap[0];
+ var div = doc.createElement('div');
+
+ div.innerHTML = wrap[1] + element + wrap[2];
+
+ while (depth--) {
+ div = div.lastChild;
+ }
+
+ if (!SUPPORT_OPTIONAL_TBODY) {
+ var hasTBody = REGEX_TBODY.test(element);
+ var tbody = [];
+
+ if (tagName == 'table' && !hasTBody) {
+ if (div.firstChild) {
+ tbody = div.firstChild.childNodes;
+ }
+ }
+ else {
+ if (wrap[1] == '<table>' && !hasTBody) {
+ tbody = div.childNodes;
+ }
+ }
+
+ for (var i = tbody.length - 1; i >= 0; --i) {
+ var node = tbody[i];
+
+ if (node.nodeName.toLowerCase() == 'tbody' && node.childNodes.length) {
+ node.parentNode.removeChild(node);
+ }
+ }
+ }
+
+ if (!SUPPORT_LEADING_WHITESPACE && REGEX_LEADING_WHITE_SPACE.test(element)) {
+ div.insertBefore(doc.createTextNode(REGEX_LEADING_WHITE_SPACE.exec(element)[0]), div.firstChild);
+ }
+
+ element = div.childNodes;
+ }
+ }
+
+ if (element.nodeType) {
+ returnData.push(element);
+ }
+ else {
+ returnData = element;
+ }
+
+ return returnData;
+};
+
/**
* Augment the <a href="NodeList.html">YUI3 NodeList</a> with more util methods.
*
Please sign in to comment.
Something went wrong with that request. Please try again.