Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Gallery Build Tag: gallery-2011.03.02-20-58

  • Loading branch information...
commit 7aa3b355d3ec9704796035340e3da89d979e7799 1 parent 29f1542
YUI Builder authored
View
210 build/gallery-dispatcher/gallery-dispatcher-debug.js
@@ -49,6 +49,7 @@ DISPATCHER_PURGE = 'purge',
DISPATCHER_BEFOREEXECUTE = 'beforeExecute',
DISPATCHER_LOAD = 'load',
DISPATCHER_READY = 'ready',
+DISPATCHER_ERROR = 'error',
// Attribute keys
ATTR_URI = 'uri',
@@ -100,7 +101,7 @@ function _parseContent(content, normalize) {
function _propagateIOEvent (ev, cfg, args) {
if (cfg && cfg.on && cfg.on[ev]) {
- cfg.on[ev].apply(cfg.context || Y, args);
+ cfg.on[ev].apply(cfg.context || Y, args);
}
}
@@ -133,40 +134,116 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
_io: null,
initializer: function(config) {
+ var instance = this;
config = config || {};
Y.log('Initializer', 'info', DISPATCHER);
- this._queue = new Y.AsyncQueue();
+ instance._queue = new Y.AsyncQueue();
- this.after(ATTR_CONTENT + "Change",
- function(e) {
- this._dispatch(e.newVal);
- },
- this);
+ instance.after(ATTR_CONTENT + "Change", function(e) {
+ instance._dispatch(e.newVal);
+ });
- this.after(ATTR_URI + "Change",
- function(e) {
- this._fetch(e.newVal);
- },
- this);
+ instance.after(ATTR_URI + "Change", function(e) {
+ instance._fetch(e.newVal);
+ });
// making the trick for content and uri in case the user want to set up thru config
if (config[ATTR_CONTENT]) {
- this._dispatch(this.get(ATTR_CONTENT));
+ instance._dispatch(instance.get(ATTR_CONTENT));
}
if (config[ATTR_URI]) {
- this._fetch(this.get(ATTR_URI));
+ instance._fetch(instance.get(ATTR_URI));
}
},
destructor: function() {
- this.stop();
- this._queue = null;
- this._io = null;
+ var instance = this;
+ instance.stop();
+ instance._queue = null;
+ instance._io = null;
},
-
+
// Protected methods
-
+
+ /**
+ * @method _executeScript
+ * @description Inject an inline script into the page as part of the dispatcher process.
+ * @protected
+ * @param {string} text Script code that should be executed
+ * @param {Node} n A reference to the original SCRIPT tag Node, in case you want to get more specific attributes
+ */
+ _executeScript: function (text, jsNode) {
+ var d = ( jsNode ? jsNode.get('ownerDocument') : null ) || Y.one('doc'),
+ h = d.one('head') || d.get('documentElement'),
+ // creating a new script node to execute the inline javascrip code
+ newScript = Y.Node.create('<' + SC + '></' + SC + '>');
+
+ Y.log('inline script tag: ' + text, 'info', DISPATCHER);
+ if (text) {
+ newScript._node.text = text;
+ }
+ h.appendChild(newScript);
+ // removing script nodes as part of the clean up process
+ newScript.remove();
+ if (jsNode) {
+ jsNode.remove();
+ }
+ },
+
+ /**
+ * @method _getScript
+ * @description Inject an external script into the page as part of the dispatcher process. Due
+ * the async nature of this routine, we need to run the queue after the execution.
+ * @protected
+ * @param {string} src URI of the script that need to be injected
+ * @param {Node} n A reference to the original SCRIPT tag Node, in case you want to get more specific attributes
+ */
+ _getScript: function (src, jsNode) {
+ var instance = this,
+ q = instance._queue;
+ Y.log('external script tag: ' + src, 'info', DISPATCHER);
+ Y.Get.script(src, {
+ autopurge: true, //removes the script node immediately after executing it
+ onFailure: function(o) {
+ Y.log('external script tag fails to load: ' + src, 'error', DISPATCHER);
+ // notifying that an error has occurred
+ instance.fire(DISPATCHER_ERROR, o);
+ },
+ onEnd: function(o) {
+ // continuing the async execution
+ if (q) {
+ q.run();
+ }
+ }
+ });
+ },
+
+ /**
+ * @method _setContent
+ * @description Set a new content into the dispatcher host node.
+ * @protected
+ * @param {string} content HTML code that will replace the current content
+ */
+ _setContent: function (content) {
+ var n = this.get(ATTR_NODE);
+ Y.log('setting new content: ' + content, 'info', DISPATCHER);
+ n.setContent(content);
+ },
+
+ /**
+ * @method _purgeContent
+ * @description Purge all the child node in preparation for a new content to be injected.
+ * @protected
+ */
+ _purgeContent: function() {
+ var n = this.get(ATTR_NODE);
+ Y.log('purging children collection', 'info', DISPATCHER);
+ n.get('children').each(function(c) {
+ c.purge(true);
+ });
+ },
+
/**
* @method _dispatch
* @description Dispatch a content into the code, parsing out the scripts,
@@ -176,13 +253,13 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
* @return null
*/
_dispatch: function(content) {
- var that = this,
- o = _parseContent(content, this.get(ATTR_NORMALIZE)),
- q = this._queue,
- n = this.get(ATTR_NODE);
+ var instance = this,
+ o = _parseContent(content, instance.get(ATTR_NORMALIZE)),
+ q = instance._queue,
+ n = instance.get(ATTR_NODE);
// stopping any previous process, just in case...
- this.stop();
+ instance.stop();
if (!n) {
Y.log('Dispatcher requires a NODE to dispatch the content', 'error', DISPATCHER);
@@ -192,72 +269,41 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
Y.log('dispatching a new content', 'info', DISPATCHER);
// autopurging children collection
- if (this.get(ATTR_AUTOPURGE)) {
+ if (instance.get(ATTR_AUTOPURGE)) {
q.add({
fn: function() {
- Y.log('purging children collection', 'info', DISPATCHER);
- n.get('children').each(function(c) {
- c.purge(true);
- });
- that.fire(DISPATCHER_PURGE, n);
+ instance._purgeContent();
+ instance.fire(DISPATCHER_PURGE, n);
}
});
}
// injecting new content
q.add({
fn: function() {
- Y.log('setting new content: ' + o.content, 'info', DISPATCHER);
- n.setContent(o.content);
- that.fire(DISPATCHER_BEFOREEXECUTE, n);
+ instance._setContent(o.content);
+ instance.fire(DISPATCHER_BEFOREEXECUTE, n);
}
});
// executing JS blocks before the injection
o.js.each(function(jsNode) {
if (jsNode && jsNode.get('src')) {
q.add({
- fn: function() {
- Y.log('external script tag: ' + jsNode.get('src'), 'info', DISPATCHER);
- //q.next();
- Y.Get.script(jsNode.get('src'), {
- onFailure: function(o) {
- Y.log('external script tag fail to load: ' + jsNode.get('src'), 'error', DISPATCHER);
- },
- onEnd: function(o) {
- o.purge();
- //removes the script node immediately after executing it
- q.run();
- }
- });
- },
+ fn: Y.bind(instance._getScript, instance, jsNode.get('src'), jsNode),
autoContinue: false
});
} else {
q.add({
- fn: function() {
- // inject js;
- Y.log('inline script tag: ' + jsNode.get('innerHTML'), 'info', DISPATCHER);
- var d = jsNode.get('ownerDocument'),
- h = d.one('head') || d.get('documentElement'),
- // creating a new script node to execute the inline javascrip code
- newScript = Y.Node.create('<' + SC + '></' + SC + '>');
- if (jsNode._node.text) {
- newScript._node.text = jsNode._node.text;
- }
- h.appendChild(newScript);
- // removing script nodes as part of the clean up process
- newScript.remove();
- jsNode.remove();
- }
+ fn: Y.bind(instance._executeScript, instance, jsNode._node.text, jsNode)
});
}
});
q.add({
fn: function() {
- that.fire(DISPATCHER_READY);
+ instance.fire(DISPATCHER_READY);
}
});
// executing the queue
- this._queue.run();
+ instance._queue.run();
},
/**
@@ -269,10 +315,11 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
*/
_fetch: function(uri) {
- var defIOConfig = this.get("ioConfig") || {},
+ var instance = this,
+ defIOConfig = instance.get("ioConfig") || {},
cfg;
// stopping any previous process, just in case...
- this.stop();
+ instance.stop();
if (!uri) {
return false;
@@ -287,27 +334,28 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
cfg.on = {
start: function() {
- this._set(ATTR_LOADING, true);
+ instance._set(ATTR_LOADING, true);
Y.log('Start Loading', 'info', DISPATCHER);
_propagateIOEvent ('start', defIOConfig, arguments);
},
success: function(tid, o) {
Y.log('Success: ' + o.responseText, 'info', DISPATCHER);
- this.set(ATTR_CONTENT, o.responseText);
+ instance.set(ATTR_CONTENT, o.responseText);
_propagateIOEvent ('success', defIOConfig, arguments);
},
failure: function(tid, o) {
Y.log('Failure: ' + uri, 'warn', DISPATCHER);
_propagateIOEvent ('failure', defIOConfig, arguments);
+ instance.fire(DISPATCHER_ERROR, o);
},
end: function() {
- this._set(ATTR_LOADING, false);
+ instance._set(ATTR_LOADING, false);
Y.log('End Loading', 'info', DISPATCHER);
_propagateIOEvent ('end', defIOConfig, arguments);
}
};
- cfg.context = this;
- return (this._io = Y.io(uri, cfg));
+ cfg.context = instance;
+ return (instance._io = Y.io(uri, cfg));
},
// Public methods
@@ -319,11 +367,12 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
* @return {object} reference for chaining
*/
stop: function() {
- this._queue.stop();
- if (this._io) {
- this._io.abort();
+ var instance = this;
+ instance._queue.stop();
+ if (instance._io) {
+ instance._io.abort();
}
- return this;
+ return instance;
}
}, {
@@ -411,13 +460,14 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
validator: isBoolean,
readOnly: true,
setter: function(v) {
+ var instance = this;
Y.log('setting status to ' + v, 'info', DISPATCHER);
if (v) {
- this.fire(DISPATCHER_FETCH);
- this.get(ATTR_NODE).addClass(CLASS_DISPATCHER_LOADING);
+ instance.fire(DISPATCHER_FETCH);
+ instance.get(ATTR_NODE).addClass(CLASS_DISPATCHER_LOADING);
} else {
- this.fire(DISPATCHER_LOAD);
- this.get(ATTR_NODE).removeClass(CLASS_DISPATCHER_LOADING);
+ instance.fire(DISPATCHER_LOAD);
+ instance.get(ATTR_NODE).removeClass(CLASS_DISPATCHER_LOADING);
}
return v;
}
@@ -438,4 +488,4 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
});
-}, 'gallery-2010.09.15-18-40' ,{requires:['base', 'node-base', 'io-base', 'get', 'async-queue', 'classnamemanager']});
+}, 'gallery-2011.03.02-20-58' ,{requires:['base', 'node-base', 'io-base', 'get', 'async-queue', 'classnamemanager']});
View
2  build/gallery-dispatcher/gallery-dispatcher-min.js
@@ -1 +1 @@
-YUI.add("gallery-dispatcher",function(B){var I=B.ClassNameManager.getClassName,K="dispatcher",T="script",W="fetch",S="purge",D="beforeExecute",V="load",Q="ready",H="uri",E="content",F="autopurge",P="loading",R="node",G="normalize",A=/<\s*body.*?>(.*?)<\/\s*?body[^>\w]*?>/i,U=/<\s*head.*?>(.*?)<\/\s*?head[^>\w]*?>/i,C=I(K,"loading"),J=B.Lang,M=J.isBoolean,N=J.isString;function X(c,L){var Z=B.Node.create("<div></div>"),b=Z.cloneNode(),d={},Y=null,a="";if(L&&(Y=U.exec(c))){Z.setContent(Y[1]).all(T+",style,link").each(function(e){b.append(e);});a=b.get("innerHTML");}Z.setContent(a+((Y=A.exec(c))?Y[1]:c));d.js=Z.all(T).each(function(e){e.get("parentNode").removeChild(e);});d.content=Z.get("innerHTML");return d;}function O(Z,L,Y){if(L&&L.on&&L.on[Z]){L.on[Z].apply(L.context||B,Y);}}B.Dispatcher=B.Base.create(K,B.Base,[],{_queue:null,_io:null,initializer:function(L){L=L||{};this._queue=new B.AsyncQueue();this.after(E+"Change",function(Y){this._dispatch(Y.newVal);},this);this.after(H+"Change",function(Y){this._fetch(Y.newVal);},this);if(L[E]){this._dispatch(this.get(E));}if(L[H]){this._fetch(this.get(H));}},destructor:function(){this.stop();this._queue=null;this._io=null;},_dispatch:function(Y){var L=this,a=X(Y,this.get(G)),Z=this._queue,b=this.get(R);this.stop();if(!b){return;}if(this.get(F)){Z.add({fn:function(){b.get("children").each(function(d){d.purge(true);});L.fire(S,b);}});}Z.add({fn:function(){b.setContent(a.content);L.fire(D,b);}});a.js.each(function(c){if(c&&c.get("src")){Z.add({fn:function(){B.Get.script(c.get("src"),{onFailure:function(d){},onEnd:function(d){d.purge();Z.run();}});},autoContinue:false});}else{Z.add({fn:function(){var g=c.get("ownerDocument"),f=g.one("head")||g.get("documentElement"),e=B.Node.create("<"+T+"></"+T+">");if(c._node.text){e._node.text=c._node.text;}f.appendChild(e);e.remove();c.remove();}});}});Z.add({fn:function(){L.fire(Q);}});this._queue.run();},_fetch:function(Z){var Y=this.get("ioConfig")||{},L;this.stop();if(!Z){return false;}L=B.merge({method:"GET"},Y);L.on={start:function(){this._set(P,true);O("start",Y,arguments);},success:function(a,b){this.set(E,b.responseText);O("success",Y,arguments);},failure:function(a,b){O("failure",Y,arguments);},end:function(){this._set(P,false);O("end",Y,arguments);}};L.context=this;return(this._io=B.io(Z,L));},stop:function(){this._queue.stop();if(this._io){this._io.abort();}return this;}},{EVENT_PREFIX:K,ATTRS:{node:{value:null,setter:function(L){this.stop();return B.one(L);}},autopurge:{value:true,validator:M},normalize:{value:false,validator:M},uri:{value:null,validator:function(L){return(L&&N(L)&&(L!==""));}},content:{value:"",validator:N},loading:{value:false,validator:M,readOnly:true,setter:function(L){if(L){this.fire(W);this.get(R).addClass(C);}else{this.fire(V);this.get(R).removeClass(C);}return L;}},ioConfig:{value:null}}});},"gallery-2010.09.15-18-40",{requires:["base","node-base","io-base","get","async-queue","classnamemanager"]});
+YUI.add("gallery-dispatcher",function(c){var j=c.ClassNameManager.getClassName,l="dispatcher",t="script",w="fetch",s="purge",e="beforeExecute",v="load",q="ready",a="error",i="uri",f="content",g="autopurge",p="loading",r="node",h="normalize",b=/<\s*body.*?>(.*?)<\/\s*?body[^>\w]*?>/i,u=/<\s*head.*?>(.*?)<\/\s*?head[^>\w]*?>/i,d=j(l,"loading"),k=c.Lang,m=k.isBoolean,n=k.isString;function x(D,y){var A=c.Node.create("<div></div>"),C=A.cloneNode(),E={},z=null,B="";if(y&&(z=u.exec(D))){A.setContent(z[1]).all(t+",style,link").each(function(F){C.append(F);});B=C.get("innerHTML");}A.setContent(B+((z=b.exec(D))?z[1]:D));E.js=A.all(t).each(function(F){F.get("parentNode").removeChild(F);});E.content=A.get("innerHTML");return E;}function o(A,y,z){if(y&&y.on&&y.on[A]){y.on[A].apply(y.context||c,z);}}c.Dispatcher=c.Base.create(l,c.Base,[],{_queue:null,_io:null,initializer:function(z){var y=this;z=z||{};y._queue=new c.AsyncQueue();y.after(f+"Change",function(A){y._dispatch(A.newVal);});y.after(i+"Change",function(A){y._fetch(A.newVal);});if(z[f]){y._dispatch(y.get(f));}if(z[i]){y._fetch(y.get(i));}},destructor:function(){var y=this;y.stop();y._queue=null;y._io=null;},_executeScript:function(C,A){var B=(A?A.get("ownerDocument"):null)||c.one("doc"),z=B.one("head")||B.get("documentElement"),y=c.Node.create("<"+t+"></"+t+">");if(C){y._node.text=C;}z.appendChild(y);y.remove();if(A){A.remove();}},_getScript:function(B,z){var y=this,A=y._queue;c.Get.script(B,{autopurge:true,onFailure:function(C){y.fire(a,C);},onEnd:function(C){if(A){A.run();}}});},_setContent:function(y){var z=this.get(r);z.setContent(y);},_purgeContent:function(){var y=this.get(r);y.get("children").each(function(z){z.purge(true);});},_dispatch:function(z){var y=this,B=x(z,y.get(h)),A=y._queue,C=y.get(r);y.stop();if(!C){return;}if(y.get(g)){A.add({fn:function(){y._purgeContent();y.fire(s,C);}});}A.add({fn:function(){y._setContent(B.content);y.fire(e,C);}});B.js.each(function(D){if(D&&D.get("src")){A.add({fn:c.bind(y._getScript,y,D.get("src"),D),autoContinue:false});}else{A.add({fn:c.bind(y._executeScript,y,D._node.text,D)});}});A.add({fn:function(){y.fire(q);}});y._queue.run();},_fetch:function(B){var y=this,A=y.get("ioConfig")||{},z;y.stop();if(!B){return false;}z=c.merge({method:"GET"},A);z.on={start:function(){y._set(p,true);o("start",A,arguments);},success:function(C,D){y.set(f,D.responseText);o("success",A,arguments);},failure:function(C,D){o("failure",A,arguments);y.fire(a,D);},end:function(){y._set(p,false);o("end",A,arguments);}};z.context=y;return(y._io=c.io(B,z));},stop:function(){var y=this;y._queue.stop();if(y._io){y._io.abort();}return y;}},{EVENT_PREFIX:l,ATTRS:{node:{value:null,setter:function(y){this.stop();return c.one(y);}},autopurge:{value:true,validator:m},normalize:{value:false,validator:m},uri:{value:null,validator:function(y){return(y&&n(y)&&(y!==""));}},content:{value:"",validator:n},loading:{value:false,validator:m,readOnly:true,setter:function(z){var y=this;if(z){y.fire(w);y.get(r).addClass(d);}else{y.fire(v);y.get(r).removeClass(d);}return z;}},ioConfig:{value:null}}});},"gallery-2011.03.02-20-58",{requires:["base","node-base","io-base","get","async-queue","classnamemanager"]});
View
200 build/gallery-dispatcher/gallery-dispatcher.js
@@ -49,6 +49,7 @@ DISPATCHER_PURGE = 'purge',
DISPATCHER_BEFOREEXECUTE = 'beforeExecute',
DISPATCHER_LOAD = 'load',
DISPATCHER_READY = 'ready',
+DISPATCHER_ERROR = 'error',
// Attribute keys
ATTR_URI = 'uri',
@@ -98,7 +99,7 @@ function _parseContent(content, normalize) {
function _propagateIOEvent (ev, cfg, args) {
if (cfg && cfg.on && cfg.on[ev]) {
- cfg.on[ev].apply(cfg.context || Y, args);
+ cfg.on[ev].apply(cfg.context || Y, args);
}
}
@@ -131,39 +132,110 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
_io: null,
initializer: function(config) {
+ var instance = this;
config = config || {};
- this._queue = new Y.AsyncQueue();
+ instance._queue = new Y.AsyncQueue();
- this.after(ATTR_CONTENT + "Change",
- function(e) {
- this._dispatch(e.newVal);
- },
- this);
+ instance.after(ATTR_CONTENT + "Change", function(e) {
+ instance._dispatch(e.newVal);
+ });
- this.after(ATTR_URI + "Change",
- function(e) {
- this._fetch(e.newVal);
- },
- this);
+ instance.after(ATTR_URI + "Change", function(e) {
+ instance._fetch(e.newVal);
+ });
// making the trick for content and uri in case the user want to set up thru config
if (config[ATTR_CONTENT]) {
- this._dispatch(this.get(ATTR_CONTENT));
+ instance._dispatch(instance.get(ATTR_CONTENT));
}
if (config[ATTR_URI]) {
- this._fetch(this.get(ATTR_URI));
+ instance._fetch(instance.get(ATTR_URI));
}
},
destructor: function() {
- this.stop();
- this._queue = null;
- this._io = null;
+ var instance = this;
+ instance.stop();
+ instance._queue = null;
+ instance._io = null;
},
-
+
// Protected methods
-
+
+ /**
+ * @method _executeScript
+ * @description Inject an inline script into the page as part of the dispatcher process.
+ * @protected
+ * @param {string} text Script code that should be executed
+ * @param {Node} n A reference to the original SCRIPT tag Node, in case you want to get more specific attributes
+ */
+ _executeScript: function (text, jsNode) {
+ var d = ( jsNode ? jsNode.get('ownerDocument') : null ) || Y.one('doc'),
+ h = d.one('head') || d.get('documentElement'),
+ // creating a new script node to execute the inline javascrip code
+ newScript = Y.Node.create('<' + SC + '></' + SC + '>');
+
+ if (text) {
+ newScript._node.text = text;
+ }
+ h.appendChild(newScript);
+ // removing script nodes as part of the clean up process
+ newScript.remove();
+ if (jsNode) {
+ jsNode.remove();
+ }
+ },
+
+ /**
+ * @method _getScript
+ * @description Inject an external script into the page as part of the dispatcher process. Due
+ * the async nature of this routine, we need to run the queue after the execution.
+ * @protected
+ * @param {string} src URI of the script that need to be injected
+ * @param {Node} n A reference to the original SCRIPT tag Node, in case you want to get more specific attributes
+ */
+ _getScript: function (src, jsNode) {
+ var instance = this,
+ q = instance._queue;
+ Y.Get.script(src, {
+ autopurge: true, //removes the script node immediately after executing it
+ onFailure: function(o) {
+ // notifying that an error has occurred
+ instance.fire(DISPATCHER_ERROR, o);
+ },
+ onEnd: function(o) {
+ // continuing the async execution
+ if (q) {
+ q.run();
+ }
+ }
+ });
+ },
+
+ /**
+ * @method _setContent
+ * @description Set a new content into the dispatcher host node.
+ * @protected
+ * @param {string} content HTML code that will replace the current content
+ */
+ _setContent: function (content) {
+ var n = this.get(ATTR_NODE);
+ n.setContent(content);
+ },
+
+ /**
+ * @method _purgeContent
+ * @description Purge all the child node in preparation for a new content to be injected.
+ * @protected
+ */
+ _purgeContent: function() {
+ var n = this.get(ATTR_NODE);
+ n.get('children').each(function(c) {
+ c.purge(true);
+ });
+ },
+
/**
* @method _dispatch
* @description Dispatch a content into the code, parsing out the scripts,
@@ -173,13 +245,13 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
* @return null
*/
_dispatch: function(content) {
- var that = this,
- o = _parseContent(content, this.get(ATTR_NORMALIZE)),
- q = this._queue,
- n = this.get(ATTR_NODE);
+ var instance = this,
+ o = _parseContent(content, instance.get(ATTR_NORMALIZE)),
+ q = instance._queue,
+ n = instance.get(ATTR_NODE);
// stopping any previous process, just in case...
- this.stop();
+ instance.stop();
if (!n) {
return;
@@ -187,67 +259,41 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
// autopurging children collection
- if (this.get(ATTR_AUTOPURGE)) {
+ if (instance.get(ATTR_AUTOPURGE)) {
q.add({
fn: function() {
- n.get('children').each(function(c) {
- c.purge(true);
- });
- that.fire(DISPATCHER_PURGE, n);
+ instance._purgeContent();
+ instance.fire(DISPATCHER_PURGE, n);
}
});
}
// injecting new content
q.add({
fn: function() {
- n.setContent(o.content);
- that.fire(DISPATCHER_BEFOREEXECUTE, n);
+ instance._setContent(o.content);
+ instance.fire(DISPATCHER_BEFOREEXECUTE, n);
}
});
// executing JS blocks before the injection
o.js.each(function(jsNode) {
if (jsNode && jsNode.get('src')) {
q.add({
- fn: function() {
- //q.next();
- Y.Get.script(jsNode.get('src'), {
- onFailure: function(o) {
- },
- onEnd: function(o) {
- o.purge();
- //removes the script node immediately after executing it
- q.run();
- }
- });
- },
+ fn: Y.bind(instance._getScript, instance, jsNode.get('src'), jsNode),
autoContinue: false
});
} else {
q.add({
- fn: function() {
- // inject js;
- var d = jsNode.get('ownerDocument'),
- h = d.one('head') || d.get('documentElement'),
- // creating a new script node to execute the inline javascrip code
- newScript = Y.Node.create('<' + SC + '></' + SC + '>');
- if (jsNode._node.text) {
- newScript._node.text = jsNode._node.text;
- }
- h.appendChild(newScript);
- // removing script nodes as part of the clean up process
- newScript.remove();
- jsNode.remove();
- }
+ fn: Y.bind(instance._executeScript, instance, jsNode._node.text, jsNode)
});
}
});
q.add({
fn: function() {
- that.fire(DISPATCHER_READY);
+ instance.fire(DISPATCHER_READY);
}
});
// executing the queue
- this._queue.run();
+ instance._queue.run();
},
/**
@@ -259,10 +305,11 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
*/
_fetch: function(uri) {
- var defIOConfig = this.get("ioConfig") || {},
+ var instance = this,
+ defIOConfig = instance.get("ioConfig") || {},
cfg;
// stopping any previous process, just in case...
- this.stop();
+ instance.stop();
if (!uri) {
return false;
@@ -276,23 +323,24 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
cfg.on = {
start: function() {
- this._set(ATTR_LOADING, true);
+ instance._set(ATTR_LOADING, true);
_propagateIOEvent ('start', defIOConfig, arguments);
},
success: function(tid, o) {
- this.set(ATTR_CONTENT, o.responseText);
+ instance.set(ATTR_CONTENT, o.responseText);
_propagateIOEvent ('success', defIOConfig, arguments);
},
failure: function(tid, o) {
_propagateIOEvent ('failure', defIOConfig, arguments);
+ instance.fire(DISPATCHER_ERROR, o);
},
end: function() {
- this._set(ATTR_LOADING, false);
+ instance._set(ATTR_LOADING, false);
_propagateIOEvent ('end', defIOConfig, arguments);
}
};
- cfg.context = this;
- return (this._io = Y.io(uri, cfg));
+ cfg.context = instance;
+ return (instance._io = Y.io(uri, cfg));
},
// Public methods
@@ -304,11 +352,12 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
* @return {object} reference for chaining
*/
stop: function() {
- this._queue.stop();
- if (this._io) {
- this._io.abort();
+ var instance = this;
+ instance._queue.stop();
+ if (instance._io) {
+ instance._io.abort();
}
- return this;
+ return instance;
}
}, {
@@ -396,12 +445,13 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
validator: isBoolean,
readOnly: true,
setter: function(v) {
+ var instance = this;
if (v) {
- this.fire(DISPATCHER_FETCH);
- this.get(ATTR_NODE).addClass(CLASS_DISPATCHER_LOADING);
+ instance.fire(DISPATCHER_FETCH);
+ instance.get(ATTR_NODE).addClass(CLASS_DISPATCHER_LOADING);
} else {
- this.fire(DISPATCHER_LOAD);
- this.get(ATTR_NODE).removeClass(CLASS_DISPATCHER_LOADING);
+ instance.fire(DISPATCHER_LOAD);
+ instance.get(ATTR_NODE).removeClass(CLASS_DISPATCHER_LOADING);
}
return v;
}
@@ -422,4 +472,4 @@ Y.Dispatcher = Y.Base.create(DISPATCHER, Y.Base, [], {
});
-}, 'gallery-2010.09.15-18-40' ,{requires:['base', 'node-base', 'io-base', 'get', 'async-queue', 'classnamemanager']});
+}, 'gallery-2011.03.02-20-58' ,{requires:['base', 'node-base', 'io-base', 'get', 'async-queue', 'classnamemanager']});
View
136 build/gallery-graphics-svg/gallery-graphics-svg-debug.js
@@ -396,6 +396,7 @@ Y.Drawing = Drawing;
_addListeners: function()
{
this.after("initializedChange", this._updateHandler);
+ this.after("transformAdded", this._updateHandler);
this.after("strokeChange", this._updateHandler);
this.after("fillChange", this._updateHandler);
this.after("widthChange", this._updateHandler);
@@ -454,29 +455,16 @@ Y.Drawing = Drawing;
fillAlpha;
if(fill)
{
- if(fill.type === "linear" || fill.type === "radial")
+ if(!fill.color)
{
- this.beginGradientFill(fill);
- //node.appendChild(this._getFill());
- }
- else if(fill.type === "bitmap")
- {
- this.beginBitmapFill(fill);
- //node.appendChild(this._getFill());
+ node.setAttribute("fill", "none");
}
else
{
- if(!fill.color)
- {
- node.setAttribute("fill", "none");
- }
- else
- {
- fillAlpha = fill.alpha;
- fill.alpha = Y.Lang.isNumber(fillAlpha) ? fillAlpha : 1;
- node.setAttribute("fill", fill.color);
- node.setAttribute("fill-opacity", fillAlpha);
- }
+ fillAlpha = fill.alpha;
+ fill.alpha = Y.Lang.isNumber(fillAlpha) ? fillAlpha : 1;
+ node.setAttribute("fill", fill.color);
+ node.setAttribute("fill-opacity", fillAlpha);
}
}
else
@@ -509,10 +497,7 @@ Y.Drawing = Drawing;
*/
_translate: function(x, y)
{
- var node = this.get("node"),
- translate = "translate(" + x + ", " + y + ")",
- transform = node.getAttribute("transform");
- this._updateTransform("translate", /translate\(.*\)/, translate);
+ this._addTransform("translate", arguments);
},
/**
@@ -523,8 +508,7 @@ Y.Drawing = Drawing;
*/
skewX: function(x)
{
- var skewX= "skewX(" + x + ")";
- this._updateTransform("skewX", /skewX\(.*\)/, skewX);
+ this._addTransform("skewX", arguments);
},
/**
@@ -535,8 +519,7 @@ Y.Drawing = Drawing;
*/
skewY: function(y)
{
- var skewY = "skewY(" + y + ")";
- this._updateTransform("skewY", /skewY\(.*\)/, skewY);
+ this._addTransform("skewY", arguments);
},
/**
@@ -545,13 +528,9 @@ Y.Drawing = Drawing;
* @method rotate
* @param
*/
- rotate: function(deg, translate)
+ rotate: function(deg)
{
- var w = this.get("width") * 0.5,
- h = this.get("height") * 0.5;
- translate = translate || w + "," + h;
- var rotate = "rotate(" + deg + "," + translate + ")";
- this._updateTransform("rotate", /rotate\(.*\)/, rotate);
+ this._addTransform("rotate", arguments);
},
/**
@@ -562,8 +541,7 @@ Y.Drawing = Drawing;
*/
scale: function(val)
{
- var scale = "scale(" + val + ")";
- this._updateTransform("scale", /scale\(.*\)/, scale);
+ this._addTransform("scale", arguments);
},
/**
@@ -573,34 +551,69 @@ Y.Drawing = Drawing;
*/
matrix: function(a, b, c, d, e, f)
{
- var matrix = "matrix(" + a + ", " + b + ", " + c + ", " + d + ", " + e + ", " + f + ")";
- this._updateTransform("matrix", /matrix\(.*\)/, matrix);
+ this._addTransform("matrix", arguments);
},
/**
* @private
*/
- _updateTransform: function(type, test, val)
+ _addTransform: function(type, args)
+ {
+ if(!this._transformArgs)
+ {
+ this._transformArgs = {};
+ }
+ this._transformArgs[type] = Array.prototype.slice.call(args, 0);
+ this.fire("transformAdded");
+ },
+
+ /**
+ * @private
+ */
+ _updateTransform: function()
{
var node = this.get("node"),
- transform = node.getAttribute("transform");
- if(transform && transform.length > 0)
+ key,
+ args,
+ val,
+ transform = node.getAttribute("transform"),
+ test;
+ if(this._transformArgs)
{
- if(transform.indexOf(type) > -1)
+ if(this._transformArgs.hasOwnProperty("rotate"))
{
- transform = transform.replace(test, val);
+ args = this._transformArgs.rotate;
+ args[1] = this.get("x") + (this.get("width") * 0.5);
+ args[2] = this.get("y") + (this.get("height") * 0.5);
}
- else
+ }
+ for(key in this._transformArgs)
+ {
+ if(key && this._transformArgs.hasOwnProperty(key))
{
- transform += " " + val;
+ val = key + "(" + this._transformArgs[key].toString() + ")";
+ if(transform && transform.length > 0)
+ {
+ test = new RegExp(key + '(.*)');
+ if(transform.indexOf(key) > -1)
+ {
+ transform = transform.replace(test, val);
+ }
+ else
+ {
+ transform += " " + val;
+ }
+ }
+ else
+ {
+ transform = val;
+ }
}
}
- else
+ if(transform)
{
- transform = val;
+ node.setAttribute("transform", transform);
}
- node.setAttribute("transform", transform);
- this.fire("shapeUpdate");
},
/**
@@ -620,6 +633,7 @@ Y.Drawing = Drawing;
node.style.top = this.get("y") + "px";
this._fillChangeHandler();
this._strokeChangeHandler();
+ this._updateTransform();
},
/**
@@ -982,11 +996,18 @@ Y.Path = Y.Base.create("path", Y.Shape, [Y.Drawing], {
{
path += 'z';
}
- node.setAttribute("d", path);
- this._translate(left + tx, top + ty);
+ if(path)
+ {
+ node.setAttribute("d", path);
+ }
+ //Use transform to handle positioning.
+ this._transformArgs = this._transformArgs || {};
+ this._transformArgs.translate = [left + tx, top + ty];
+
this.set("path", path);
this._fillChangeHandler();
this._strokeChangeHandler();
+ this._updateTransform();
},
/**
@@ -1001,7 +1022,6 @@ Y.Path = Y.Base.create("path", Y.Shape, [Y.Drawing], {
var node = this.get("node");
this._translateX = x;
this._translateY = y;
- this._translate(x, y);
this._translate(this._left + x, this._top + y);
},
@@ -1047,10 +1067,10 @@ Y.Path = Y.Base.create("path", Y.Shape, [Y.Drawing], {
{
wt = stroke.weight;
}
- bounds.left = this._left - wt - tx;
- bounds.top = this._top - wt - ty;
- bounds.right = (this._right - this._left) + wt - tx;
- bounds.bottom = (this._bottom - this._top) + wt - ty;
+ bounds.left = this._left - wt + tx;
+ bounds.top = this._top - wt + ty;
+ bounds.right = (this._right - this._left) + wt + tx;
+ bounds.bottom = (this._bottom - this._top) + wt + ty;
return bounds;
}
}, {
@@ -1126,6 +1146,7 @@ Y.Path = Y.Base.create("path", Y.Shape, [Y.Drawing], {
node.setAttribute("cy", cy);
this._fillChangeHandler();
this._strokeChangeHandler();
+ this._updateTransform();
}
}, {
ATTRS: {
@@ -1238,6 +1259,7 @@ Y.Path = Y.Base.create("path", Y.Shape, [Y.Drawing], {
node.setAttribute("cy", cy);
this._fillChangeHandler();
this._strokeChangeHandler();
+ this._updateTransform();
}
}, {
ATTRS: {
@@ -1569,6 +1591,10 @@ Graphic.prototype = {
shape,
shapes = this._graphicsList,
len = shapes.length;
+ this._left = 0;
+ this._right = 0;
+ this._top = 0;
+ this._bottom = 0;
for(; i < len; ++i)
{
shape = this.getShape(shapes[i].getAttribute("id"));
View
6 build/gallery-graphics-svg/gallery-graphics-svg-min.js
@@ -1,3 +1,3 @@
-YUI.add("gallery-graphics-svg",function(c){function a(){}a.prototype={curveTo:function(i,g,n,m,l,k){var e,j,h,d,f,o;if(this._pathType!=="C"){this._pathType="C";j=["C"];this._pathArray.push(j);}else{j=this._pathArray[Math.max(0,this._pathArray.length-1)];if(!j){j=[];this._pathArray.push(j);}}e=this._pathArray.length-1;this._pathArray[e]=this._pathArray[e].concat([Math.round(i),Math.round(g),Math.round(n),Math.round(m),l,k]);h=Math.max(l,Math.max(i,n));f=Math.max(k,Math.max(g,m));d=Math.min(l,Math.min(i,n));o=Math.min(k,Math.min(g,m));this._trackSize(h,f);this._trackSize(d,o);},quadraticCurveTo:function(i,h,l,k){var e,j,g,d,f,m;if(this._pathType!=="Q"){this._pathType="Q";j=["Q"];this._pathArray.push(j);}else{j=this._pathArray[Math.max(0,this._pathArray.length-1)];if(!j){j=[];this._pathArray.push(j);}}e=this._pathArray.length-1;this._pathArray[e]=this._pathArray[e].concat([Math.round(i),Math.round(h),Math.round(l),Math.round(k)]);g=Math.max(l,i);f=Math.max(k,h);d=Math.min(l,i);m=Math.min(k,h);this._trackSize(g,f);this._trackSize(d,m);},drawRect:function(d,g,e,f){this.moveTo(d,g);this.lineTo(d+e,g);this.lineTo(d+e,g+f);this.lineTo(d,g+f);this.lineTo(d,g);},drawRoundRect:function(d,j,e,g,f,i){this.moveTo(d,j+i);this.lineTo(d,j+g-i);this.quadraticCurveTo(d,j+g,d+f,j+g);this.lineTo(d+e-f,j+g);this.quadraticCurveTo(d+e,j+g,d+e,j+g-i);this.lineTo(d+e,j+i);this.quadraticCurveTo(d+e,j,d+e-f,j);this.lineTo(d+f,j);this.quadraticCurveTo(d,j,d,j+i);},drawWedge:function(f,i,h,g,e,d){this._drawingComplete=false;this.path=this._getWedgePath({x:f,y:i,startAngle:h,arc:g,radius:e,yRadius:d});},_getWedgePath:function(A){var o=A.x,l=A.y,t=A.startAngle,k=A.arc,f=A.radius,g=A.yRadius||f,s,q,j,z,h,p,n,w,v,e,d,u=0,m=f*2,r=" M"+o+", "+l;if(Math.abs(k)>360){k=360;}s=Math.ceil(Math.abs(k)/45);q=k/s;j=-(q/180)*Math.PI;z=(t/180)*Math.PI;if(s>0){p=o+Math.cos(t/180*Math.PI)*f;n=l+Math.sin(t/180*Math.PI)*g;r+=" L"+Math.round(p)+", "+Math.round(n);r+=" Q";for(;u<s;++u){z+=j;h=z-(j/2);w=o+Math.cos(z)*f;v=l+Math.sin(z)*g;e=o+Math.cos(h)*(f/Math.cos(j/2));d=l+Math.sin(h)*(g/Math.cos(j/2));r+=Math.round(e)+" "+Math.round(d)+" "+Math.round(w)+" "+Math.round(v)+" ";}r+=" L"+o+", "+l;}this._trackSize(m,m);return r;},lineTo:function(j,h,f){var e=arguments,g,d,l,k;this._pathArray=this._pathArray||[];if(typeof j==="string"||typeof j==="number"){e=[[j,h]];}d=e.length;this._shapeType="path";if(this._pathType!=="L"){this._pathType="L";k=["L"];this._pathArray.push(k);}else{k=this._pathArray[Math.max(0,this._pathArray.length-1)];if(!k){k=[];this._pathArray.push(k);}}l=this._pathArray.length-1;for(g=0;g<d;++g){this._pathArray[l]=this._pathArray[l].concat([e[g][0],e[g][1]]);this._trackSize.apply(this,e[g]);}},moveTo:function(d,g){var f,e;this._pathArray=this._pathArray||[];if(this._pathType!="M"){this._pathType="M";e=["M"];this._pathArray.push(e);}else{e=this._pathArray[Math.max(0,this._pathArray.length-1)];if(!e){e=[];this._pathArray.push(e);}}f=this._pathArray.length-1;this._pathArray[f]=this._pathArray[f].concat([d,g]);this._trackSize(d,g);},end:function(){this._draw();},setSize:function(d,e){var f;if(this.get("autoSize")){f=this.get("node");if(d>f.getAttribute("width")){f.setAttribute("width",d);}if(e>f.getAttribute("height")){f.setAttribute("height",e);}}},_trackSize:function(d,e){var f=this.get("node");if(d>this._right){this._right=d;}if(d<this._left){this._left=d;}if(e<this._top){this._top=e;}if(e>this._bottom){this._bottom=e;}this._width=this._right-this._left;this._height=this._bottom-this._top;f.style.left=this._left+"px";f.style.top=this._top+"px";this.setSize(this._width,this._height);}};c.Drawing=a;c.Shape=c.Base.create("shape",c.Base,[],{initializer:function(){this.publish("shapeUpdate");this._addListeners();},_getNode:function(){var e=document.createElementNS("http://www.w3.org/2000/svg","svg:"+this._type),d=this.get("pointerEvents")||"none";e.setAttribute("pointer-events",d);e.setAttribute("class","yui3-"+this.name);e.setAttribute("id",this.get("id"));return e;},_addListeners:function(){this.after("initializedChange",this._updateHandler);this.after("strokeChange",this._updateHandler);this.after("fillChange",this._updateHandler);this.after("widthChange",this._updateHandler);this.after("heightChange",this._updateHandler);this.after("xChange",this._updateHandler);this.after("yChange",this._updateHandler);},_strokeChangeHandler:function(l){var g=this.get("node"),m=this.get("stroke"),n,f,j,h,k,d;if(m&&m.weight&&m.weight>0){n=m.alpha;f=m.dashstyle||"none";j=c.Lang.isArray(f)?f.toString():f;m.color=m.color||"#000000";m.weight=m.weight||1;m.alpha=c.Lang.isNumber(n)?n:1;m.linecap=m.linecap||"butt";g.setAttribute("stroke-dasharray",j);g.setAttribute("stroke",m.color);g.setAttribute("stroke-linecap",m.linecap);g.setAttribute("stroke-width",m.weight);g.setAttribute("stroke-opacity",m.alpha);}else{g.setAttribute("stroke","none");}},_fillChangeHandler:function(h){var f=this.get("node"),g=this.get("fill"),d;if(g){if(g.type==="linear"||g.type==="radial"){this.beginGradientFill(g);}else{if(g.type==="bitmap"){this.beginBitmapFill(g);}else{if(!g.color){f.setAttribute("fill","none");}else{d=g.alpha;g.alpha=c.Lang.isNumber(d)?d:1;f.setAttribute("fill",g.color);f.setAttribute("fill-opacity",d);}}}}else{f.setAttribute("fill","none");}},translate:function(d,e){this._translateX=d;this._translateY=e;this._translate.apply(this,arguments);},_translate:function(d,h){var f=this.get("node"),g="translate("+d+", "+h+")",e=f.getAttribute("transform");this._updateTransform("translate",/translate\(.*\)/,g);},skewX:function(d){var e="skewX("+d+")";this._updateTransform("skewX",/skewX\(.*\)/,e);},skewY:function(e){var d="skewY("+e+")";this._updateTransform("skewY",/skewY\(.*\)/,d);},rotate:function(g,i){var d=this.get("width")*0.5,f=this.get("height")*0.5;i=i||d+","+f;var e="rotate("+g+","+i+")";this._updateTransform("rotate",/rotate\(.*\)/,e);},scale:function(e){var d="scale("+e+")";this._updateTransform("scale",/scale\(.*\)/,d);},matrix:function(h,g,m,l,k,j){var i="matrix("+h+", "+g+", "+m+", "+l+", "+k+", "+j+")";
-this._updateTransform("matrix",/matrix\(.*\)/,i);},_updateTransform:function(e,h,g){var f=this.get("node"),d=f.getAttribute("transform");if(d&&d.length>0){if(d.indexOf(e)>-1){d=d.replace(h,g);}else{d+=" "+g;}}else{d=g;}f.setAttribute("transform",d);this.fire("shapeUpdate");},_draw:function(){var d=this.get("node");d.setAttribute("width",this.get("width"));d.setAttribute("height",this.get("height"));d.setAttribute("x",this.get("x"));d.setAttribute("y",this.get("y"));d.style.left=this.get("x")+"px";d.style.top=this.get("y")+"px";this._fillChangeHandler();this._strokeChangeHandler();},_updateHandler:function(d){this._draw();this.fire("shapeUpdate");},_translateX:0,_translateY:0,getBounds:function(){var l=this.get("width"),g=this.get("height"),m=this.get("stroke"),k=this.get("x"),j=this.get("y"),i=0,f=this.get("translateX"),e=this.get("translateY"),d={};if(m&&m.weight){i=m.weight;}d.left=k-i+f;d.top=j-i+e;d.right=k+l+i+f;d.bottom=j+g+i+e;return d;}},{ATTRS:{node:{readOnly:true,valueFn:"_getNode"},id:{valueFn:function(){return c.guid();},setter:function(e){var d=this.get("node");d.setAttribute("id",e);return e;}},x:{value:0},y:{value:0},width:{},height:{},visible:{value:true,setter:function(e){var d=e?"visible":"hidden";this.get("node").style.visibility=d;return e;}},fill:{setter:function(e){var d=this.get("fill")||this._getAttrCfg("fill").defaultValue;return(e)?c.merge(d,e):null;}},stroke:{valueFn:function(){return{weight:1,dashstyle:null,color:"#000",alpha:1};},setter:function(e){var d=this.get("stroke")||this._getAttrCfg("stroke").defaultValue;return(e)?c.merge(d,e):null;}},autoSize:{value:false},pointerEvents:{value:"visiblePainted"},translateX:{getter:function(){return this._translateX;},setter:function(d){this._translateX=d;this._transform(d,this._translateY);return d;}},translateY:{getter:function(){return this._translateY;},setter:function(d){this._translateY=d;this._transform(this._translateX,d);return d;}},graphic:{setter:function(d){this.after("shapeUpdate",c.bind(d.updateCoordSpace,d));return d;}}}});c.Path=c.Base.create("path",c.Shape,[c.Drawing],{_left:0,_right:0,_top:0,_bottom:0,_type:"path",_draw:function(){var e=this._pathArray,l,d,o,f,n,m,q=this.get("path"),h=this.get("node"),k=this.get("translateX"),j=this.get("translateY"),g=this._left,p=this._top;while(e&&e.length>0){l=e.shift();o=l.length;d=l[0];q+=" "+d+(l[1]-g);switch(d){case"L":case"M":for(m=2;m<o;++m){f=(m%2===0)?p:g;f=l[m]-f;q+=", "+f;}break;case"Q":case"C":for(m=2;m<o;++m){f=(m%2===0)?p:g;n=l[m];n-=f;q+=" "+n;}break;}}if(this._fill){q+="z";}h.setAttribute("d",q);this._translate(g+k,p+j);this.set("path",q);this._fillChangeHandler();this._strokeChangeHandler();},translate:function(d,f){var e=this.get("node");this._translateX=d;this._translateY=f;this._translate(d,f);this._translate(this._left+d,this._top+f);},end:function(){this._draw();this.fire("shapeUpdate");},clear:function(){this._left=0;this._right=0;this._top=0;this._bottom=0;this.set("path","");},getBounds:function(){var e=0,g={},h=this.get("stroke"),f=this.get("translateX"),d=this.get("translateY");if(h&&h.weight){e=h.weight;}g.left=this._left-e-f;g.top=this._top-e-d;g.right=(this._right-this._left)+e-f;g.bottom=(this._bottom-this._top)+e-d;return g;}},{ATTRS:{path:{value:""},width:{getter:function(){var d=this._right,e=this._left,f=Math.max(this._right-this._left,0);return f;}},height:{getter:function(){return Math.max(this._bottom-this._top,0);}}}});c.Rect=c.Base.create("rect",c.Shape,[],{_type:"rect"});c.Ellipse=c.Base.create("ellipse",c.Shape,[],{_type:"ellipse",_draw:function(){var d=this.get("node"),m=this.get("width"),g=this.get("height"),l=this.get("x"),j=this.get("y"),k=m*0.5,i=g*0.5,f=l+k,e=j+i;d.setAttribute("rx",k);d.setAttribute("ry",i);d.setAttribute("cx",f);d.setAttribute("cy",e);this._fillChangeHandler();this._strokeChangeHandler();}},{ATTRS:{xRadius:{readOnly:true,getter:function(){var d=this.get("width");if(d){d*=0.5;}return d;}},yRadius:{readOnly:true,getter:function(){var d=this.get("height");if(d){d*=0.5;}return d;}},x:{lazyAdd:false,value:0},y:{lazyAdd:false}}});c.Circle=c.Base.create("circle",c.Shape,[],{_type:"circle",_addListeners:function(){c.Circle.superclass._addListeners.apply(this);this.after("radiusChange",this._updateHandler);},_draw:function(){var g=this.get("node"),f=this.get("x"),i=this.get("y"),e=this.get("radius"),d=f+e,h=i+e;g.setAttribute("r",e);g.setAttribute("cx",d);g.setAttribute("cy",h);this._fillChangeHandler();this._strokeChangeHandler();}},{ATTRS:{width:{readOnly:true,getter:function(){return this.get("radius")*2;}},height:{readOnly:true,getter:function(){return this.get("radius")*2;}},radius:{value:0}}});function b(d){this.initializer.apply(this,arguments);}b.prototype={autoSize:true,initializer:function(e){e=e||{};var d=e.width||0,f=e.height||0;this.id=c.guid();this.node=this._createGraphics();this.node.setAttribute("id",this.id);this.setSize(d,f);if(e.render){this.render(e.render);}},destroy:function(){this._removeChildren(this.node);if(this.node&&this.node.parentNode){this.node.parentNode.removeChild(this.node);}},_removeChildren:function(d){if(d.hasChildNodes()){var e;while(d.firstChild){e=d.firstChild;this._removeChildren(e);d.removeChild(e);}}},toggleVisible:function(d){this._toggleVisible(this.node,d);},_toggleVisible:function(h,j){var g=c.Selector.query(">/*",h),e=j?"visible":"hidden",f=0,d;if(g){d=g.length;for(;f<d;++f){this._toggleVisible(g[f],j);}}h.style.visibility=e;},clear:function(){if(this._graphicsList){while(this._graphicsList.length>0){this.node.removeChild(this._graphicsList.shift());}}},setSize:function(d,e){if(this.autoSize){if(d>this.node.getAttribute("width")){this.node.setAttribute("width",d);}if(e>this.node.getAttribute("height")){this.node.setAttribute("height",e);}}},_trackSize:function(d,e){if(d>this._right){this._right=d;}if(d<this._left){this._left=d;}if(e<this._top){this._top=e;}if(e>this._bottom){this._bottom=e;}this._width=this._right-this._left;this._height=this._bottom-this._top;
-this.node.style.left=this._left+"px";this.node.style.top=this._top+"px";this.setSize(this._width,this._height);},render:function(g){var d=c.one(g),e=parseInt(d.getComputedStyle("width"),10),f=parseInt(d.getComputedStyle("height"),10);d=d||c.config.doc.body;d.appendChild(this.node);this.setSize(e,f);return this;},_createGraphics:function(){var d=this._createGraphicNode("svg");this._styleGroup(d);return d;},_styleGroup:function(d){d.style.position="absolute";d.style.top="0px";d.style.left="0px";d.style.overflow="auto";d.setAttribute("overflow","auto");d.setAttribute("pointer-events","none");},_createGraphicNode:function(f,d){var g=document.createElementNS("http://www.w3.org/2000/svg","svg:"+f),e=d||"none";if(f!=="defs"&&f!=="stop"&&f!=="linearGradient"){g.setAttribute("pointer-events",e);}return g;},addShape:function(d){var e=d.get("node");d.set("graphic",this);this.node.appendChild(e);if(!this._graphicsList){this._graphicsList=[];}if(!this._shapes){this._shapes={};}this._graphicsList.push(e);this._shapes[d.get("id")]=d;this.updateCoordSpace();},getShape:function(d){return this._shapes[d];},updateCoordSpace:function(k){var j,h=0,g,f=this._graphicsList,d=f.length;for(;h<d;++h){g=this.getShape(f[h].getAttribute("id"));j=g.getBounds();this._left=Math.min(this._left,j.left);this._top=Math.min(this._top,j.top);this._right=Math.max(this._right,j.right);this._bottom=Math.max(this._bottom,j.bottom);}this._width=this._right-this._left;this._height=this._bottom-this._top;this.node.setAttribute("width",this._width);this.node.setAttribute("height",this._height);this.node.style.width=this._width+"px";this.node.style.height=this._height+"px";this.node.style.left=this._left+"px";this.node.style.top=this._top+"px";this.node.setAttribute("viewBox",""+this._left+" "+this._top+" "+this._width+" "+this._height+"");},_left:0,_right:0,_top:0,_bottom:0};c.Graphic=b;},"@VERSION@",{requires:["graphics"],skinnable:false});
+YUI.add("gallery-graphics-svg",function(c){function a(){}a.prototype={curveTo:function(i,g,n,m,l,k){var e,j,h,d,f,o;if(this._pathType!=="C"){this._pathType="C";j=["C"];this._pathArray.push(j);}else{j=this._pathArray[Math.max(0,this._pathArray.length-1)];if(!j){j=[];this._pathArray.push(j);}}e=this._pathArray.length-1;this._pathArray[e]=this._pathArray[e].concat([Math.round(i),Math.round(g),Math.round(n),Math.round(m),l,k]);h=Math.max(l,Math.max(i,n));f=Math.max(k,Math.max(g,m));d=Math.min(l,Math.min(i,n));o=Math.min(k,Math.min(g,m));this._trackSize(h,f);this._trackSize(d,o);},quadraticCurveTo:function(i,h,l,k){var e,j,g,d,f,m;if(this._pathType!=="Q"){this._pathType="Q";j=["Q"];this._pathArray.push(j);}else{j=this._pathArray[Math.max(0,this._pathArray.length-1)];if(!j){j=[];this._pathArray.push(j);}}e=this._pathArray.length-1;this._pathArray[e]=this._pathArray[e].concat([Math.round(i),Math.round(h),Math.round(l),Math.round(k)]);g=Math.max(l,i);f=Math.max(k,h);d=Math.min(l,i);m=Math.min(k,h);this._trackSize(g,f);this._trackSize(d,m);},drawRect:function(d,g,e,f){this.moveTo(d,g);this.lineTo(d+e,g);this.lineTo(d+e,g+f);this.lineTo(d,g+f);this.lineTo(d,g);},drawRoundRect:function(d,j,e,g,f,i){this.moveTo(d,j+i);this.lineTo(d,j+g-i);this.quadraticCurveTo(d,j+g,d+f,j+g);this.lineTo(d+e-f,j+g);this.quadraticCurveTo(d+e,j+g,d+e,j+g-i);this.lineTo(d+e,j+i);this.quadraticCurveTo(d+e,j,d+e-f,j);this.lineTo(d+f,j);this.quadraticCurveTo(d,j,d,j+i);},drawWedge:function(f,i,h,g,e,d){this._drawingComplete=false;this.path=this._getWedgePath({x:f,y:i,startAngle:h,arc:g,radius:e,yRadius:d});},_getWedgePath:function(A){var o=A.x,l=A.y,t=A.startAngle,k=A.arc,f=A.radius,g=A.yRadius||f,s,q,j,z,h,p,n,w,v,e,d,u=0,m=f*2,r=" M"+o+", "+l;if(Math.abs(k)>360){k=360;}s=Math.ceil(Math.abs(k)/45);q=k/s;j=-(q/180)*Math.PI;z=(t/180)*Math.PI;if(s>0){p=o+Math.cos(t/180*Math.PI)*f;n=l+Math.sin(t/180*Math.PI)*g;r+=" L"+Math.round(p)+", "+Math.round(n);r+=" Q";for(;u<s;++u){z+=j;h=z-(j/2);w=o+Math.cos(z)*f;v=l+Math.sin(z)*g;e=o+Math.cos(h)*(f/Math.cos(j/2));d=l+Math.sin(h)*(g/Math.cos(j/2));r+=Math.round(e)+" "+Math.round(d)+" "+Math.round(w)+" "+Math.round(v)+" ";}r+=" L"+o+", "+l;}this._trackSize(m,m);return r;},lineTo:function(j,h,f){var e=arguments,g,d,l,k;this._pathArray=this._pathArray||[];if(typeof j==="string"||typeof j==="number"){e=[[j,h]];}d=e.length;this._shapeType="path";if(this._pathType!=="L"){this._pathType="L";k=["L"];this._pathArray.push(k);}else{k=this._pathArray[Math.max(0,this._pathArray.length-1)];if(!k){k=[];this._pathArray.push(k);}}l=this._pathArray.length-1;for(g=0;g<d;++g){this._pathArray[l]=this._pathArray[l].concat([e[g][0],e[g][1]]);this._trackSize.apply(this,e[g]);}},moveTo:function(d,g){var f,e;this._pathArray=this._pathArray||[];if(this._pathType!="M"){this._pathType="M";e=["M"];this._pathArray.push(e);}else{e=this._pathArray[Math.max(0,this._pathArray.length-1)];if(!e){e=[];this._pathArray.push(e);}}f=this._pathArray.length-1;this._pathArray[f]=this._pathArray[f].concat([d,g]);this._trackSize(d,g);},end:function(){this._draw();},setSize:function(d,e){var f;if(this.get("autoSize")){f=this.get("node");if(d>f.getAttribute("width")){f.setAttribute("width",d);}if(e>f.getAttribute("height")){f.setAttribute("height",e);}}},_trackSize:function(d,e){var f=this.get("node");if(d>this._right){this._right=d;}if(d<this._left){this._left=d;}if(e<this._top){this._top=e;}if(e>this._bottom){this._bottom=e;}this._width=this._right-this._left;this._height=this._bottom-this._top;f.style.left=this._left+"px";f.style.top=this._top+"px";this.setSize(this._width,this._height);}};c.Drawing=a;c.Shape=c.Base.create("shape",c.Base,[],{initializer:function(){this.publish("shapeUpdate");this._addListeners();},_getNode:function(){var e=document.createElementNS("http://www.w3.org/2000/svg","svg:"+this._type),d=this.get("pointerEvents")||"none";e.setAttribute("pointer-events",d);e.setAttribute("class","yui3-"+this.name);e.setAttribute("id",this.get("id"));return e;},_addListeners:function(){this.after("initializedChange",this._updateHandler);this.after("transformAdded",this._updateHandler);this.after("strokeChange",this._updateHandler);this.after("fillChange",this._updateHandler);this.after("widthChange",this._updateHandler);this.after("heightChange",this._updateHandler);this.after("xChange",this._updateHandler);this.after("yChange",this._updateHandler);},_strokeChangeHandler:function(l){var g=this.get("node"),m=this.get("stroke"),n,f,j,h,k,d;if(m&&m.weight&&m.weight>0){n=m.alpha;f=m.dashstyle||"none";j=c.Lang.isArray(f)?f.toString():f;m.color=m.color||"#000000";m.weight=m.weight||1;m.alpha=c.Lang.isNumber(n)?n:1;m.linecap=m.linecap||"butt";g.setAttribute("stroke-dasharray",j);g.setAttribute("stroke",m.color);g.setAttribute("stroke-linecap",m.linecap);g.setAttribute("stroke-width",m.weight);g.setAttribute("stroke-opacity",m.alpha);}else{g.setAttribute("stroke","none");}},_fillChangeHandler:function(h){var f=this.get("node"),g=this.get("fill"),d;if(g){if(!g.color){f.setAttribute("fill","none");}else{d=g.alpha;g.alpha=c.Lang.isNumber(d)?d:1;f.setAttribute("fill",g.color);f.setAttribute("fill-opacity",d);}}else{f.setAttribute("fill","none");}},translate:function(d,e){this._translateX=d;this._translateY=e;this._translate.apply(this,arguments);},_translate:function(d,e){this._addTransform("translate",arguments);},skewX:function(d){this._addTransform("skewX",arguments);},skewY:function(d){this._addTransform("skewY",arguments);},rotate:function(d){this._addTransform("rotate",arguments);},scale:function(d){this._addTransform("scale",arguments);},matrix:function(h,g,l,k,j,i){this._addTransform("matrix",arguments);},_addTransform:function(e,d){if(!this._transformArgs){this._transformArgs={};}this._transformArgs[e]=Array.prototype.slice.call(d,0);this.fire("transformAdded");},_updateTransform:function(){var g=this.get("node"),f,e,h,d=g.getAttribute("transform"),i;if(this._transformArgs){if(this._transformArgs.hasOwnProperty("rotate")){e=this._transformArgs.rotate;
+e[1]=this.get("x")+(this.get("width")*0.5);e[2]=this.get("y")+(this.get("height")*0.5);}}for(f in this._transformArgs){if(f&&this._transformArgs.hasOwnProperty(f)){h=f+"("+this._transformArgs[f].toString()+")";if(d&&d.length>0){i=new RegExp(f+"(.*)");if(d.indexOf(f)>-1){d=d.replace(i,h);}else{d+=" "+h;}}else{d=h;}}}if(d){g.setAttribute("transform",d);}},_draw:function(){var d=this.get("node");d.setAttribute("width",this.get("width"));d.setAttribute("height",this.get("height"));d.setAttribute("x",this.get("x"));d.setAttribute("y",this.get("y"));d.style.left=this.get("x")+"px";d.style.top=this.get("y")+"px";this._fillChangeHandler();this._strokeChangeHandler();this._updateTransform();},_updateHandler:function(d){this._draw();this.fire("shapeUpdate");},_translateX:0,_translateY:0,getBounds:function(){var l=this.get("width"),g=this.get("height"),m=this.get("stroke"),k=this.get("x"),j=this.get("y"),i=0,f=this.get("translateX"),e=this.get("translateY"),d={};if(m&&m.weight){i=m.weight;}d.left=k-i+f;d.top=j-i+e;d.right=k+l+i+f;d.bottom=j+g+i+e;return d;}},{ATTRS:{node:{readOnly:true,valueFn:"_getNode"},id:{valueFn:function(){return c.guid();},setter:function(e){var d=this.get("node");d.setAttribute("id",e);return e;}},x:{value:0},y:{value:0},width:{},height:{},visible:{value:true,setter:function(e){var d=e?"visible":"hidden";this.get("node").style.visibility=d;return e;}},fill:{setter:function(e){var d=this.get("fill")||this._getAttrCfg("fill").defaultValue;return(e)?c.merge(d,e):null;}},stroke:{valueFn:function(){return{weight:1,dashstyle:null,color:"#000",alpha:1};},setter:function(e){var d=this.get("stroke")||this._getAttrCfg("stroke").defaultValue;return(e)?c.merge(d,e):null;}},autoSize:{value:false},pointerEvents:{value:"visiblePainted"},translateX:{getter:function(){return this._translateX;},setter:function(d){this._translateX=d;this._transform(d,this._translateY);return d;}},translateY:{getter:function(){return this._translateY;},setter:function(d){this._translateY=d;this._transform(this._translateX,d);return d;}},graphic:{setter:function(d){this.after("shapeUpdate",c.bind(d.updateCoordSpace,d));return d;}}}});c.Path=c.Base.create("path",c.Shape,[c.Drawing],{_left:0,_right:0,_top:0,_bottom:0,_type:"path",_draw:function(){var e=this._pathArray,l,d,o,f,n,m,q=this.get("path"),h=this.get("node"),k=this.get("translateX"),j=this.get("translateY"),g=this._left,p=this._top;while(e&&e.length>0){l=e.shift();o=l.length;d=l[0];q+=" "+d+(l[1]-g);switch(d){case"L":case"M":for(m=2;m<o;++m){f=(m%2===0)?p:g;f=l[m]-f;q+=", "+f;}break;case"Q":case"C":for(m=2;m<o;++m){f=(m%2===0)?p:g;n=l[m];n-=f;q+=" "+n;}break;}}if(this._fill){q+="z";}if(q){h.setAttribute("d",q);}this._transformArgs=this._transformArgs||{};this._transformArgs.translate=[g+k,p+j];this.set("path",q);this._fillChangeHandler();this._strokeChangeHandler();this._updateTransform();},translate:function(d,f){var e=this.get("node");this._translateX=d;this._translateY=f;this._translate(this._left+d,this._top+f);},end:function(){this._draw();this.fire("shapeUpdate");},clear:function(){this._left=0;this._right=0;this._top=0;this._bottom=0;this.set("path","");},getBounds:function(){var e=0,g={},h=this.get("stroke"),f=this.get("translateX"),d=this.get("translateY");if(h&&h.weight){e=h.weight;}g.left=this._left-e+f;g.top=this._top-e+d;g.right=(this._right-this._left)+e+f;g.bottom=(this._bottom-this._top)+e+d;return g;}},{ATTRS:{path:{value:""},width:{getter:function(){var d=this._right,e=this._left,f=Math.max(this._right-this._left,0);return f;}},height:{getter:function(){return Math.max(this._bottom-this._top,0);}}}});c.Rect=c.Base.create("rect",c.Shape,[],{_type:"rect"});c.Ellipse=c.Base.create("ellipse",c.Shape,[],{_type:"ellipse",_draw:function(){var d=this.get("node"),m=this.get("width"),g=this.get("height"),l=this.get("x"),j=this.get("y"),k=m*0.5,i=g*0.5,f=l+k,e=j+i;d.setAttribute("rx",k);d.setAttribute("ry",i);d.setAttribute("cx",f);d.setAttribute("cy",e);this._fillChangeHandler();this._strokeChangeHandler();this._updateTransform();}},{ATTRS:{xRadius:{readOnly:true,getter:function(){var d=this.get("width");if(d){d*=0.5;}return d;}},yRadius:{readOnly:true,getter:function(){var d=this.get("height");if(d){d*=0.5;}return d;}},x:{lazyAdd:false,value:0},y:{lazyAdd:false}}});c.Circle=c.Base.create("circle",c.Shape,[],{_type:"circle",_addListeners:function(){c.Circle.superclass._addListeners.apply(this);this.after("radiusChange",this._updateHandler);},_draw:function(){var g=this.get("node"),f=this.get("x"),i=this.get("y"),e=this.get("radius"),d=f+e,h=i+e;g.setAttribute("r",e);g.setAttribute("cx",d);g.setAttribute("cy",h);this._fillChangeHandler();this._strokeChangeHandler();this._updateTransform();}},{ATTRS:{width:{readOnly:true,getter:function(){return this.get("radius")*2;}},height:{readOnly:true,getter:function(){return this.get("radius")*2;}},radius:{value:0}}});function b(d){this.initializer.apply(this,arguments);}b.prototype={autoSize:true,initializer:function(e){e=e||{};var d=e.width||0,f=e.height||0;this.id=c.guid();this.node=this._createGraphics();this.node.setAttribute("id",this.id);this.setSize(d,f);if(e.render){this.render(e.render);}},destroy:function(){this._removeChildren(this.node);if(this.node&&this.node.parentNode){this.node.parentNode.removeChild(this.node);}},_removeChildren:function(d){if(d.hasChildNodes()){var e;while(d.firstChild){e=d.firstChild;this._removeChildren(e);d.removeChild(e);}}},toggleVisible:function(d){this._toggleVisible(this.node,d);},_toggleVisible:function(h,j){var g=c.Selector.query(">/*",h),e=j?"visible":"hidden",f=0,d;if(g){d=g.length;for(;f<d;++f){this._toggleVisible(g[f],j);}}h.style.visibility=e;},clear:function(){if(this._graphicsList){while(this._graphicsList.length>0){this.node.removeChild(this._graphicsList.shift());}}},setSize:function(d,e){if(this.autoSize){if(d>this.node.getAttribute("width")){this.node.setAttribute("width",d);}if(e>this.node.getAttribute("height")){this.node.setAttribute("height",e);}}},_trackSize:function(d,e){if(d>this._right){this._right=d;
+}if(d<this._left){this._left=d;}if(e<this._top){this._top=e;}if(e>this._bottom){this._bottom=e;}this._width=this._right-this._left;this._height=this._bottom-this._top;this.node.style.left=this._left+"px";this.node.style.top=this._top+"px";this.setSize(this._width,this._height);},render:function(g){var d=c.one(g),e=parseInt(d.getComputedStyle("width"),10),f=parseInt(d.getComputedStyle("height"),10);d=d||c.config.doc.body;d.appendChild(this.node);this.setSize(e,f);return this;},_createGraphics:function(){var d=this._createGraphicNode("svg");this._styleGroup(d);return d;},_styleGroup:function(d){d.style.position="absolute";d.style.top="0px";d.style.left="0px";d.style.overflow="auto";d.setAttribute("overflow","auto");d.setAttribute("pointer-events","none");},_createGraphicNode:function(f,d){var g=document.createElementNS("http://www.w3.org/2000/svg","svg:"+f),e=d||"none";if(f!=="defs"&&f!=="stop"&&f!=="linearGradient"){g.setAttribute("pointer-events",e);}return g;},addShape:function(d){var e=d.get("node");d.set("graphic",this);this.node.appendChild(e);if(!this._graphicsList){this._graphicsList=[];}if(!this._shapes){this._shapes={};}this._graphicsList.push(e);this._shapes[d.get("id")]=d;this.updateCoordSpace();},getShape:function(d){return this._shapes[d];},updateCoordSpace:function(k){var j,h=0,g,f=this._graphicsList,d=f.length;this._left=0;this._right=0;this._top=0;this._bottom=0;for(;h<d;++h){g=this.getShape(f[h].getAttribute("id"));j=g.getBounds();this._left=Math.min(this._left,j.left);this._top=Math.min(this._top,j.top);this._right=Math.max(this._right,j.right);this._bottom=Math.max(this._bottom,j.bottom);}this._width=this._right-this._left;this._height=this._bottom-this._top;this.node.setAttribute("width",this._width);this.node.setAttribute("height",this._height);this.node.style.width=this._width+"px";this.node.style.height=this._height+"px";this.node.style.left=this._left+"px";this.node.style.top=this._top+"px";this.node.setAttribute("viewBox",""+this._left+" "+this._top+" "+this._width+" "+this._height+"");},_left:0,_right:0,_top:0,_bottom:0};c.Graphic=b;},"@VERSION@",{requires:["graphics"],skinnable:false});
View
136 build/gallery-graphics-svg/gallery-graphics-svg.js
@@ -396,6 +396,7 @@ Y.Drawing = Drawing;
_addListeners: function()
{
this.after("initializedChange", this._updateHandler);
+ this.after("transformAdded", this._updateHandler);
this.after("strokeChange", this._updateHandler);
this.after("fillChange", this._updateHandler);
this.after("widthChange", this._updateHandler);
@@ -454,29 +455,16 @@ Y.Drawing = Drawing;
fillAlpha;
if(fill)
{
- if(fill.type === "linear" || fill.type === "radial")
+ if(!fill.color)
{
- this.beginGradientFill(fill);
- //node.appendChild(this._getFill());
- }
- else if(fill.type === "bitmap")
- {
- this.beginBitmapFill(fill);
- //node.appendChild(this._getFill());
+ node.setAttribute("fill", "none");
}
else
{
- if(!fill.color)
- {
- node.setAttribute("fill", "none");
- }
- else
- {
- fillAlpha = fill.alpha;
- fill.alpha = Y.Lang.isNumber(fillAlpha) ? fillAlpha : 1;
- node.setAttribute("fill", fill.color);
- node.setAttribute("fill-opacity", fillAlpha);
- }
+ fillAlpha = fill.alpha;
+ fill.alpha = Y.Lang.isNumber(fillAlpha) ? fillAlpha : 1;
+ node.setAttribute("fill", fill.color);
+ node.setAttribute("fill-opacity", fillAlpha);
}
}
else
@@ -509,10 +497,7 @@ Y.Drawing = Drawing;
*/
_translate: function(x, y)
{
- var node = this.get("node"),
- translate = "translate(" + x + ", " + y + ")",
- transform = node.getAttribute("transform");
- this._updateTransform("translate", /translate\(.*\)/, translate);
+ this._addTransform("translate", arguments);
},
/**
@@ -523,8 +508,7 @@ Y.Drawing = Drawing;
*/
skewX: function(x)
{
- var skewX= "skewX(" + x + ")";
- this._updateTransform("skewX", /skewX\(.*\)/, skewX);
+ this._addTransform("skewX", arguments);
},
/**
@@ -535,8 +519,7 @@ Y.Drawing = Drawing;
*/
skewY: function(y)
{
- var skewY = "skewY(" + y + ")";
- this._updateTransform("skewY", /skewY\(.*\)/, skewY);
+ this._addTransform("skewY", arguments);
},
/**
@@ -545,13 +528,9 @@ Y.Drawing = Drawing;
* @method rotate
* @param
*/
- rotate: function(deg, translate)
+ rotate: function(deg)
{
- var w = this.get("width") * 0.5,
- h = this.get("height") * 0.5;
- translate = translate || w + "," + h;
- var rotate = "rotate(" + deg + "," + translate + ")";
- this._updateTransform("rotate", /rotate\(.*\)/, rotate);
+ this._addTransform("rotate", arguments);
},
/**
@@ -562,8 +541,7 @@ Y.Drawing = Drawing;
*/
scale: function(val)
{
- var scale = "scale(" + val + ")";
- this._updateTransform("scale", /scale\(.*\)/, scale);
+ this._addTransform("scale", arguments);
},
/**
@@ -573,34 +551,69 @@ Y.Drawing = Drawing;
*/
matrix: function(a, b, c, d, e, f)
{
- var matrix = "matrix(" + a + ", " + b + ", " + c + ", " + d + ", " + e + ", " + f + ")";
- this._updateTransform("matrix", /matrix\(.*\)/, matrix);
+ this._addTransform("matrix", arguments);
},
/**
* @private
*/
- _updateTransform: function(type, test, val)
+ _addTransform: function(type, args)
+ {
+ if(!this._transformArgs)
+ {
+ this._transformArgs = {};
+ }
+ this._transformArgs[type] = Array.prototype.slice.call(args, 0);
+ this.fire("transformAdded");
+ },
+
+ /**
+ * @private
+ */
+ _updateTransform: function()
{
var node = this.get("node"),
- transform = node.getAttribute("transform");
- if(transform && transform.length > 0)
+ key,
+ args,
+ val,
+ transform = node.getAttribute("transform"),
+ test;
+ if(this._transformArgs)
{
- if(transform.indexOf(type) > -1)
+ if(this._transformArgs.hasOwnProperty("rotate"))
{
- transform = transform.replace(test, val);
+ args = this._transformArgs.rotate;
+ args[1] = this.get("x") + (this.get("width") * 0.5);
+ args[2] = this.get("y") + (this.get("height") * 0.5);
}
- else
+ }
+ for(key in this._transformArgs)
+ {
+ if(key && this._transformArgs.hasOwnProperty(key))
{
- transform += " " + val;
+ val = key + "(" + this._transformArgs[key].toString() + ")";
+ if(transform && transform.length > 0)
+ {
+ test = new RegExp(key + '(.*)');
+ if(transform.indexOf(key) > -1)
+ {
+ transform = transform.replace(test, val);
+ }
+ else
+ {
+ transform += " " + val;
+ }
+ }
+ else
+ {
+ transform = val;
+ }
}
}
- else
+ if(transform)
{
- transform = val;
+ node.setAttribute("transform", transform);
}
- node.setAttribute("transform", transform);
- this.fire("shapeUpdate");
},
/**
@@ -620,6 +633,7 @@ Y.Drawing = Drawing;
node.style.top = this.get("y") + "px";
this._fillChangeHandler();
this._strokeChangeHandler();
+ this._updateTransform();
},
/**
@@ -982,11 +996,18 @@ Y.Path = Y.Base.create("path", Y.Shape, [Y.Drawing], {
{
path += 'z';
}
- node.setAttribute("d", path);
- this._translate(left + tx, top + ty);
+ if(path)
+ {
+ node.setAttribute("d", path);
+ }
+ //Use transform to handle positioning.
+ this._transformArgs = this._transformArgs || {};
+ this._transformArgs.translate = [left + tx, top + ty];
+
this.set("path", path);
this._fillChangeHandler();
this._strokeChangeHandler();
+ this._updateTransform();
},
/**
@@ -1001,7 +1022,6 @@ Y.Path = Y.Base.create("path", Y.Shape, [Y.Drawing], {
var node = this.get("node");
this._translateX = x;
this._translateY = y;
- this._translate(x, y);
this._translate(this._left + x, this._top + y);
},
@@ -1047,10 +1067,10 @@ Y.Path = Y.Base.create("path", Y.Shape, [Y.Drawing], {
{
wt = stroke.weight;
}
- bounds.left = this._left - wt - tx;
- bounds.top = this._top - wt - ty;
- bounds.right = (this._right - this._left) + wt - tx;
- bounds.bottom = (this._bottom - this._top) + wt - ty;
+ bounds.left = this._left - wt + tx;
+ bounds.top = this._top - wt + ty;
+ bounds.right = (this._right - this._left) + wt + tx;
+ bounds.bottom = (this._bottom - this._top) + wt + ty;
return bounds;
}
}, {
@@ -1126,6 +1146,7 @@ Y.Path = Y.Base.create("path", Y.Shape, [Y.Drawing], {
node.setAttribute("cy", cy);
this._fillChangeHandler();
this._strokeChangeHandler();
+ this._updateTransform();
}
}, {
ATTRS: {
@@ -1238,6 +1259,7 @@ Y.Path = Y.Base.create("path", Y.Shape, [Y.Drawing], {
node.setAttribute("cy", cy);
this._fillChangeHandler();
this._strokeChangeHandler();
+ this._updateTransform();
}
}, {
ATTRS: {
@@ -1569,6 +1591,10 @@ Graphic.prototype = {
shape,
shapes = this._graphicsList,
len = shapes.length;
+ this._left = 0;
+ this._right = 0;
+ this._top = 0;
+ this._bottom = 0;
for(; i < len; ++i)
{
shape = this.getShape(shapes[i].getAttribute("id"));
View
2  build/gallery-graphics/gallery-graphics-debug.js
@@ -7,4 +7,4 @@ YUI.add('gallery-graphics', function(Y) {
*/
-}, 'gallery-2011.02.18-23-10' ,{requires:['dom', 'event-custom', 'base']});
+}, 'gallery-2011.03.02-20-58' ,{requires:['dom', 'event-custom', 'base']});
View
2  build/gallery-graphics/gallery-graphics-min.js
@@ -1 +1 @@
-YUI.add("gallery-graphics",function(a){},"gallery-2011.02.18-23-10",{requires:["dom","event-custom","base"]});
+YUI.add("gallery-graphics",function(a){},"gallery-2011.03.02-20-58",{requires:["dom","event-custom","base"]});
View
2  build/gallery-graphics/gallery-graphics.js
@@ -7,4 +7,4 @@ YUI.add('gallery-graphics', function(Y) {
*/
-}, 'gallery-2011.02.18-23-10' ,{requires:['dom', 'event-custom', 'base']});
+}, 'gallery-2011.03.02-20-58' ,{requires:['dom', 'event-custom', 'base']});
View
14 build/gallery-node-accordion/assets/gallery-node-accordion-core.css
@@ -1,6 +1,6 @@
.yui3-accordion {
- position: relative;
- zoom: 1;
+ position: relative;
+ zoom: 1;
}
.yui3-accordion .yui3-accordion-item {
display: block;
@@ -8,14 +8,14 @@
.yui3-accordion .yui3-accordion-item .yui3-accordion-item-hd {
}
.yui3-accordion .yui3-accordion-item .yui3-accordion-item-bd {
- height: 0;
- _height: 1px;
- *height: 1px;
- overflow: hidden;
+ height: 0;
+ _height: 1px;
+ *height: 1px;
+ overflow: hidden;
zoom: 1;
}
.yui3-accordion .yui3-accordion-item-active .yui3-accordion-item-bd {
- height: auto;
+ height: auto;
}
.yui3-accordion-hidden {
/* absolute position off-screen and box collapsing used to
View
22 build/gallery-node-accordion/assets/skins/sam/gallery-node-accordion-skin.css
@@ -14,30 +14,30 @@
border-bottom: solid 1px #808080;
}
.yui3-skin-sam .yui3-accordion .yui3-accordion-item .yui3-accordion-item-hd {
- line-height: 2; /* ~24px */
+ line-height: 2; /* ~24px */
*line-height: 1.9; /* For IE */
background: url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) repeat-x 0 0;
padding: 0;
padding: 5px;
}
.yui3-skin-sam .yui3-accordion .yui3-accordion-item .yui3-accordion-item-bd {
- font-size: 100%;
- margin: 0;
- padding: 0;
- display: block;
+ font-size: 100%;
+ margin: 0;
+ padding: 0;
+ display: block;
}
.yui3-skin-sam .yui3-accordion .first-of-type {
-
+
}
.yui3-skin-sam .yui3-accordion .yui3-accordion-item-hd a.yui3-accordion-item-trigger {
- width: auto;
- display: block;
+ width: auto;
+ display: block;
color: #000;
text-decoration: none;
cursor: default;
- padding: 0 5px 0 10px;
- background: url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) no-repeat 110% -345px;
+ padding: 0 5px 0 10px;
+ background: url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) no-repeat 110% -345px;
}
.yui3-skin-sam .yui3-accordion .yui3-accordion-item-active .yui3-accordion-item-hd a.yui3-accordion-item-trigger {
- background: url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) no-repeat 110% -395px;
+ background: url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) no-repeat 110% -395px;
}
View
2  build/gallery-node-accordion/assets/skins/sam/gallery-node-accordion.css
@@ -1 +1 @@
-.yui3-accordion{position:relative;zoom:1;}.yui3-accordion .yui3-accordion-item{display:block;}.yui3-accordion .yui3-accordion-item .yui3-accordion-item-bd{height:0;_height:1px;*height:1px;overflow:hidden;zoom:1;}.yui3-accordion .yui3-accordion-item-active .yui3-accordion-item-bd{height:auto;}.yui3-accordion-hidden{border:0;height:0;width:0;padding:0;position:absolute;left:-999999px;overflow:hidden;visibility:hidden;}.yui3-skin-sam .yui3-accordion{font-size:93%;line-height:1.5;*line-height:1.45;border-top:solid 1px #808080;border-left:solid 1px #808080;border-right:solid 1px #808080;background:#fff;padding:0;text-align:left;}.yui3-skin-sam .yui3-accordion .yui3-accordion-item{display:block;border-bottom:solid 1px #808080;}.yui3-skin-sam .yui3-accordion .yui3-accordion-item .yui3-accordion-item-hd{line-height:2;*line-height:1.9;background:url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) repeat-x 0 0;padding:0;padding:5px;}.yui3-skin-sam .yui3-accordion .yui3-accordion-item .yui3-accordion-item-bd{font-size:100%;margin:0;padding:0;display:block;}.yui3-skin-sam .yui3-accordion .yui3-accordion-item-hd a.yui3-accordion-item-trigger{width:auto;display:block;color:#000;text-decoration:none;cursor:default;padding:0 5px 0 10px;background:url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) no-repeat 110% -345px;}.yui3-skin-sam .yui3-accordion .yui3-accordion-item-active .yui3-accordion-item-hd a.yui3-accordion-item-trigger{background:url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) no-repeat 110% -395px;}
+.yui3-accordion{position:relative;zoom:1}.yui3-accordion .yui3-accordion-item{display:block}.yui3-accordion .yui3-accordion-item .yui3-accordion-item-bd{height:0;_height:1px;*height:1px;overflow:hidden;zoom:1}.yui3-accordion .yui3-accordion-item-active .yui3-accordion-item-bd{height:auto}.yui3-accordion-hidden{border:0;height:0;width:0;padding:0;position:absolute;left:-999999px;overflow:hidden;visibility:hidden}.yui3-skin-sam .yui3-accordion{font-size:93%;line-height:1.5;*line-height:1.45;border-top:solid 1px #808080;border-left:solid 1px #808080;border-right:solid 1px #808080;background:#fff;padding:0;text-align:left}.yui3-skin-sam .yui3-accordion .yui3-accordion-item{display:block;border-bottom:solid 1px #808080}.yui3-skin-sam .yui3-accordion .yui3-accordion-item .yui3-accordion-item-hd{line-height:2;*line-height:1.9;background:url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) repeat-x 0 0;padding:0;padding:5px}.yui3-skin-sam .yui3-accordion .yui3-accordion-item .yui3-accordion-item-bd{font-size:100%;margin:0;padding:0;display:block}.yui3-skin-sam .yui3-accordion .yui3-accordion-item-hd a.yui3-accordion-item-trigger{width:auto;display:block;color:#000;text-decoration:none;cursor:default;padding:0 5px 0 10px;background:url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) no-repeat 110% -345px}.yui3-skin-sam .yui3-accordion .yui3-accordion-item-active .yui3-accordion-item-hd a.yui3-accordion-item-trigger{background:url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) no-repeat 110% -395px}
View
1,168 build/gallery-node-accordion/gallery-node-accordion-debug.js
@@ -13,31 +13,31 @@ YUI.add('gallery-node-accordion', function(Y) {
* <code>
* &#60;script type="text/javascript"&#62; <br>
* <br>
-* // Call the "use" method, passing in "gallery-node-accordion". This will <br>
-* // load the script and CSS for the Accordion Node Plugin and all of <br>
-* // the required dependencies. <br>
+* // Call the "use" method, passing in "gallery-node-accordion". This will <br>
+* // load the script and CSS for the Accordion Node Plugin and all of <br>
+* // the required dependencies. <br>
* <br>
-* YUI().use("gallery-node-accordion", function(Y) { <br>
+* YUI().use("gallery-node-accordion", function(Y) { <br>
* <br>
-* // Use the "contentready" event to initialize the accordion when <br>
-* // the element that represente the accordion <br>
-* // (&#60;div id="accordion-1"&#62;) is ready to be scripted. <br>
+* // Use the "contentready" event to initialize the accordion when <br>
+* // the element that represente the accordion <br>
+* // (&#60;div id="accordion-1"&#62;) is ready to be scripted. <br>
* <br>
-* Y.on("contentready", function () { <br>
+* Y.on("contentready", function () { <br>
* <br>
-* // The scope of the callback will be a Node instance <br>
-* // representing the accordion (&#60;div id="accordion-1"&#62;). <br>
-* // Therefore, since "this" represents a Node instance, it <br>
-* // is possible to just call "this.plug" passing in a <br>
-* // reference to the Accordion Node Plugin. <br>
+* // The scope of the callback will be a Node instance <br>
+* // representing the accordion (&#60;div id="accordion-1"&#62;). <br>
+* // Therefore, since "this" represents a Node instance, it <br>
+* // is possible to just call "this.plug" passing in a <br>
+* // reference to the Accordion Node Plugin. <br>
* <br>
-* this.plug(Y.Plugin.NodeAccordion); <br>
+* this.plug(Y.Plugin.NodeAccordion); <br>
* <br>
-* }, "#accordion-1"); <br>
-* <br>
-* }); <br>
-* <br>
-* &#60;/script&#62; <br>
+* }, "#accordion-1"); <br>
+* <br>
+* }); <br>
+* <br>
+* &#60;/script&#62; <br>
* </code>
* </p>
*
@@ -50,86 +50,92 @@ YUI.add('gallery-node-accordion', function(Y) {
* <code>
* &#60;script type="text/javascript"&#62; <br>
* <br>
-* // Call the "use" method, passing in "gallery-node-accordion". This will <br>
-* // load the script and CSS for the Accordion Node Plugin and all of <br>
-* // the required dependencies. <br>
+* // Call the "use" method, passing in "gallery-node-accordion". This will <br>
+* // load the script and CSS for the Accordion Node Plugin and all of <br>
+* // the required dependencies. <br>
* <br>
-* YUI().use("gallery-node-accordion", function(Y) { <br>
+* YUI().use("gallery-node-accordion", function(Y) { <br>
* <br>
-* // Use the "contentready" event to initialize the accordion when <br>
-* // the element that represente the accordion <br>
-* // (&#60;div id="accordion-1"&#62;) is ready to be scripted. <br>
+* // Use the "contentready" event to initialize the accordion when <br>
+* // the element that represente the accordion <br>
+* // (&#60;div id="accordion-1"&#62;) is ready to be scripted. <br>
* <br>
-* Y.on("contentready", function () { <br>
+* Y.on("contentready", function () { <br>
* <br>
-* // The scope of the callback will be a Node instance <br>
-* // representing the accordion (&#60;div id="accordion-1"&#62;). <br>
-* // Therefore, since "this" represents a Node instance, it <br>
-* // is possible to just call "this.plug" passing in a <br>
-* // reference to the Accordion Node Plugin. <br>
+* // The scope of the callback will be a Node instance <br>
+* // representing the accordion (&#60;div id="accordion-1"&#62;). <br>
+* // Therefore, since "this" represents a Node instance, it <br>
+* // is possible to just call "this.plug" passing in a <br>
+* // reference to the Accordion Node Plugin. <br>
* <br>
-* this.plug(Y.Plugin.NodeAccordion, { anim: true, effect: Y.Easing.backIn });
+* this.plug(Y.Plugin.NodeAccordion, { anim: true, effect: Y.Easing.backIn });
* <br><br>
-* }, "#accordion-1"); <br>
-* <br>
-* }); <br>
-* <br>
-* &#60;/script&#62; <br>
+* }, "#accordion-1"); <br>
+* <br>
+* }); <br>
+* <br>
+* &#60;/script&#62; <br>
* </code>
* </p>
*
* @module gallery-node-accordion
*/
-// Util shortcuts
+// Util shortcuts
-var UA = Y.UA,
- getClassName = Y.ClassNameManager.getClassName,
+var getClassName = Y.ClassNameManager.getClassName,
anims = {},
WHEELS = {fast:0.1,slow:0.6,normal:0.4},
- // Frequently used strings
- ACCORDION = "accordion",
- ACCORDIONITEM = "item",
- SCROLL_HEIGHT = "scrollHeight",
- SCROLL_WIDTH = "scrollWidth",
- WIDTH = "width",
- HEIGHT = "height",
- PX = "px",
- PERIOD = ".",
- HOST = "host",
-
- // Attribute keys
- ATTR_ORIENTATION = 'orientation',
- ATTR_FADE = 'fade',
- ATTR_MULTIPLE = 'multiple',
- ATTR_PERSISTENT = 'persistent',
- ATTR_SPEED = 'speed',
- ATTR_ANIM = 'anim',
- ATTR_ITEMS = 'items',
-
- // CSS class names
- CLASS_ACCORDION = getClassName(ACCORDION),
- CLASS_ACCORDION_HIDDEN = getClassName(ACCORDION, 'hidden'),
- CLASS_ACCORDION_ITEM = getClassName(ACCORDION, ACCORDIONITEM),
- CLASS_ACTIVE = getClassName(ACCORDION, ACCORDIONITEM, "active"),
- CLASS_SLIDING = getClassName(ACCORDION, ACCORDIONITEM, "sliding"),
- CLASS_ACCORDION_ITEM_HD = getClassName(ACCORDION, ACCORDIONITEM, "hd"),
- CLASS_ACCORDION_ITEM_BD = getClassName(ACCORDION, ACCORDIONITEM, "bd"),
- CLASS_ACCORDION_ITEM_FT = getClassName(ACCORDION, ACCORDIONITEM, "ft"),
- CLASS_ACCORDION_ITEM_TRIGGER = getClassName(ACCORDION, ACCORDIONITEM, "trigger"),
-
- // CSS selectors
- SELECTOR_ACCORDION_ITEM = PERIOD + CLASS_ACCORDION_ITEM,
- SELECTOR_ACCORDION_ITEM_BD = PERIOD + CLASS_ACCORDION_ITEM_BD,
-
- FC = '>.',
- ITEM_QUERY = FC + CLASS_ACCORDION_ITEM,
- ITEM_TRIGGER_QUERY = ITEM_QUERY + PERIOD + CLASS_ACCORDION_ITEM_TRIGGER + ', ' +
- ITEM_QUERY + FC + CLASS_ACCORDION_ITEM_HD + PERIOD + CLASS_ACCORDION_ITEM_TRIGGER + ', ' +
- ITEM_QUERY + FC + CLASS_ACCORDION_ITEM_HD + FC + CLASS_ACCORDION_ITEM_TRIGGER + ', ' +
- ITEM_QUERY + FC + CLASS_ACCORDION_ITEM_FT + PERIOD + CLASS_ACCORDION_ITEM_TRIGGER + ', ' +
- ITEM_QUERY + FC + CLASS_ACCORDION_ITEM_FT + FC + CLASS_ACCORDION_ITEM_TRIGGER;
+ // Frequently used strings
+ ACCORDION = "accordion",
+ ACCORDIONITEM = "item",
+ SCROLL_HEIGHT = "scrollHeight",
+ SCROLL_WIDTH = "scrollWidth",
+ WIDTH = "width",
+ HEIGHT = "height",
+ PX = "px",
+ HOST = "host",
+
+ // Attribute keys
+ ATTR_ORIENTATION = 'orientation',
+ ATTR_FADE = 'fade',
+ ATTR_MULTIPLE = 'multiple',
+ ATTR_PERSISTENT = 'persistent',
+ ATTR_SPEED = 'speed',
+ ATTR_ANIM = 'anim',
+ ATTR_ITEMS = 'items',
+ ATTR_TRIGGER_SEL = 'triggerSelector',
+ ATTR_ITEM_SEL = 'itemSelector',
+ ATTR_ITEM_BD_SEL = 'itemBodySelector',
+
+ // CSS class names
+ CLASS_ACCORDION = getClassName(ACCORDION),
+ CLASS_ACCORDION_HIDDEN = getClassName(ACCORDION, 'hidden'),
+ CLASS_ACCORDION_ITEM = getClassName(ACCORDION, ACCORDIONITEM),
+ CLASS_ACTIVE = getClassName(ACCORDION, ACCORDIONITEM, "active"),
+ CLASS_SLIDING = getClassName(ACCORDION, ACCORDIONITEM, "sliding"),
+ CLASS_ACCORDION_ITEM_HD = getClassName(ACCORDION, ACCORDIONITEM, "hd"),
+ CLASS_ACCORDION_ITEM_BD = getClassName(ACCORDION, ACCORDIONITEM, "bd"),
+ CLASS_BD_SLIDING = getClassName(ACCORDION, ACCORDIONITEM, "bd", "sliding"),
+ CLASS_ACCORDION_ITEM_FT = getClassName(ACCORDION, ACCORDIONITEM, "ft"),
+ CLASS_ACCORDION_ITEM_TRIGGER = getClassName(ACCORDION, ACCORDIONITEM, "trigger"),
+
+ // CSS selectors
+ PERIOD = ".",
+ FC = '>.',
+ SC = ' .',
+ CS = ', ',
+ DEFAULT_ITEM_SELECTOR = FC + CLASS_ACCORDION_ITEM,
+ DEFAULT_ITEM_BD_SELECTOR = PERIOD + CLASS_ACCORDION_ITEM_BD,
+ DEFAULT_TRIGGER_SELECTOR = DEFAULT_ITEM_SELECTOR + PERIOD + CLASS_ACCORDION_ITEM_TRIGGER + CS +
+ DEFAULT_ITEM_SELECTOR + FC + PERIOD + CLASS_ACCORDION_ITEM_TRIGGER + CS +
+ DEFAULT_ITEM_SELECTOR + FC + CLASS_ACCORDION_ITEM_HD + SC + CLASS_ACCORDION_ITEM_TRIGGER + CS +
+ DEFAULT_ITEM_SELECTOR + FC + CLASS_ACCORDION_ITEM_FT + SC + CLASS_ACCORDION_ITEM_TRIGGER;
+
+function _computeSize (n, s) {
+ return n.get('region')[s];
+}
/**
* The NodeAccordion class is a plugin for a Node instance. The class is used via
@@ -141,453 +147,593 @@ var UA = Y.UA,
Y.namespace('Plugin').NodeAccordion = Y.Base.create("NodeAccordion", Y.Plugin.Base, [], {
- // Prototype Properties for NodeAccordion
+ // Prototype Properties for NodeAccordion
- /**
- * @property _root
- * @description Node instance representing the root node in the accordion.
- * @default null
- * @protected
- * @type Node
- */
- _root: null,
-
- _eventHandler: null,
+ /**
+ * @property _root
+ * @description Node instance representing the root node in the accordion.
+ * @default null
+ * @protected
+ * @type Node
+ */
+ _root: null,
+
+ _eventHandler: null,
initializer: function (config) {
- if ((this._root = this.get(HOST))) {
-
- // close all items and open the actived ones
- this.get(ATTR_ITEMS).each(function(item) {
- if (item.hasClass(CLASS_ACTIVE)) {
- this.expandItem(item);
- } else {
- this.collapseItem(item);
- }
- }, this);
-
- // Wire up all event handlers
- this._eventHandler = this._root.delegate('click', function(e) {
- Y.log ('Accordion Trigger: ' + e);
- this.toggleItem(e.currentTarget); // probably is better to pass the ancestor for the item
- e.target.blur();
- e.halt();
- }, ITEM_TRIGGER_QUERY, this);
-
- // removing this class if exists, in case the accordion is hidden by default.
- this._root.removeClass(CLASS_ACCORDION_HIDDEN);
- }
+ var instance = this;
+ if ((instance._root = instance.get(HOST))) {
+
+ // close all items and open the actived ones
+ instance.get(ATTR_ITEMS).each(function(item) {
+ if (item.hasClass(CLASS_ACTIVE)) {
+ instance.expandItem(item);
+ } else {
+ instance.collapseItem(item);
+ }
+ });
+
+ // Wire up all event handlers
+ instance._eventHandler = instance._root.delegate('click', function(e) {
+ Y.log ('Accordion Trigger: ' + e, "info", "nodeAccordion");
+ instance.toggleItem(e.currentTarget); // probably is better to pass the ancestor for the item
+ e.target.blur();
+ e.halt();
+ }, instance.get(ATTR_TRIGGER_SEL));
+
+ // removing the hidden class if exists, in case the accordion is hidden by default,
+ // and also adding the default accordion class just in case
+ instance._root.replaceClass(CLASS_ACCORDION_HIDDEN, CLASS_ACCORDION);
+ }
+ },
+
+ destructor: function () {
+ var instance = this;
+ if (instance._eventHandler) {
+ instance._eventHandler.detach();
+ }
+ instance._eventHandler = null;
+ },
+
+ // Protected methods
+
+ /**
+ * @method _slidingBegin
+ * @description just adding the corresponding sliding classes.
+ * @protected
+ * @param {Node} item Item Node reference
+ * @param {Node} bd Item Body Node reference
+ * @param {boolean} active whether or not we should also add the active class
+ */
+ _slidingBegin: function(item, bd, active) {
+ item.addClass(CLASS_SLIDING);
+ bd.addClass(CLASS_BD_SLIDING);
+ if (active) {
+ item.addClass(CLASS_ACTIVE);
+ }
},
- destructor: function () {
- if (this._eventHandler) {
- this._eventHandler.detach();
- }
- this._eventHandler = null;
+ /**
+ * @method _slidingEnd
+ * @description just removing the corresponding sliding classes.
+ * @protected
+ * @param {Node} item Item Node reference
+ * @param {Node} bd Item Body Node reference
+ * @param {boolean} active whether or not we should also remove the active class
+ */
+ _slidingEnd: function(item, bd, active) {
+ item.removeClass(CLASS_SLIDING);
+ bd.removeClass(CLASS_BD_SLIDING);
+ if (active) {
+ item.removeClass(CLASS_ACTIVE);
+ }
},
- // Protected methods
-
- /**
- * @method _getItem
- * @description Searching for an item based on a node reference or an index order.
- * @protected
- * @param {Node|Number} node Node reference or Node index.
- * @return {Node} The matching DOM node or null if none found.
- */
- _getItem: function(node) {
- if (Y.Lang.isNumber(node)) {
- node = this.get(ATTR_ITEMS).item(node);
- }
- var fn = function(n) {
- return n.hasClass(CLASS_ACCORDION_ITEM);
- };
- if (node && !node.hasClass(CLASS_ACCORDION_ITEM)) {
- return node.ancestor( fn );
- }
- return node;
- },
-
- /**
- * @method _animate
- * @description Using Y.Anim to expand or collapse an item.
- * @protected
- * @param {String} id Global Unique ID for the animation.
- * @param {Object} conf Configuration object for the animation.
- * @param {Function} fn callback function that should be executed after the end of the anim.
- * @return {Object} Animation handler.
- */
- _animate: function(id, conf, fn) {
- var anim = anims[id];
- Y.log ('Anim Conf: ' + conf);
- // if the animation is underway: we need to stop it...
- if ((anim) && (anim.get ('running'))) {
- anim.stop();
+ /**
+ * @method _getItemBody
+ * @description Searching for the body of an item based on an item node reference or an index order.
+ * @protected
+ * @param {Node|Number} node Item Node reference or Item index.
+ * @return {Node} The matching DOM node or null if none found.
+ */
+ _getItemBody: function(node) {
+ var bd, sel = this.get(ATTR_ITEM_BD_SEL);
+ if (Y.Lang.isNumber(node)) {
+ node = this.get(ATTR_ITEMS).item(node);
+ }
+ // getting the child element with bd class
+ bd = node.one(sel);
+ if (!bd) {
+ node = node.next();
+ // the bd element is not a child element, it might be the next child element
+ bd = ( (node && node.test(sel)) ? node : null );
+ // this is needed to support a more semantic markup, like this one:
+ /*
+ <dl id="myaccordion3" class="yui3-accordion">
+ <dt class="yui3-accordion-item yui3-accordion-item-trigger">option 1</dt>
+ <dd class="yui3-accordion-item-bd" id="bd5">content here...</dd>
+ <dt class="yui3-accordion-item yui3-accordion-item-trigger">option 2</dt>
+ <dd class="yui3-accordion-item-bd" id="bd6">content here...</dd>
+ </dl>
+ */
+ }
+ return bd;
+ },
+
+ /**
+ * @method _getItem
+ * @description Searching for an item based on a node reference or an index order.
+ * @protected
+ * @param {Node|Number} node Node reference or Node index.
+ * @return {Node} The matching DOM node or null if none found.
+ */
+ _getItem: function(node) {
+ if (Y.Lang.isNumber(node)) {
+ node = this.get(ATTR_ITEMS).item(node);
+ }
+ var fn = function(n) {
+ return n.hasClass(CLASS_ACCORDION_ITEM);
+ };
+ if (node && !node.hasClass(CLASS_ACCORDION_ITEM)) {
+ return node.ancestor( fn );
}
- if (Y.Lang.isFunction(this.get(ATTR_ANIM))) {
- conf.easing = this.get(ATTR_ANIM);
- }
- anim = new Y.Anim(conf);
- anim.on('end', fn, this);
- anim.run();
- anims[id] = anim;
- return anim;
- },
-
- /**
- * @method _openItem
- * @description Open an item.
- * @protected
- * @param {Node} item Node instance representing an item.
- */
- _openItem: function (item) {
- var bd,
- id,
- fn,
- fs,
- i,
- list = this.get(ATTR_ITEMS),
- o = this.get (ATTR_ORIENTATION),
- conf = {
- duration: this.get(ATTR_SPEED),
- to: {
- scroll: []
- }
- },
- mirror;
- // if the item is not already opened
- if (item && list.size() && !item.hasClass(CLASS_ACTIVE) && (bd = item.one(SELECTOR_ACCORDION_ITEM_BD)) && (id = Y.stamp(bd))) {
- // closing all the selected items if neccesary
- if (!this.get(ATTR_MULTIPLE)) {
- // close all items and open the actived ones
- mirror = this._root.one(FC+CLASS_ACTIVE);
+ return node;
+ },
+
+ /**
+ * @method _animate
+ * @description Using Y.Anim to expand or collapse an item.
+ * @protected
+ * @param {String} id Global Unique ID for the animation.
+ * @param {Object} conf Configuration object for the animation.
+ * @param {Function} fn callback function that should be executed after the end of the anim.
+ * @return {Object} Animation handler.
+ */
+ _animate: function(id, conf, fn) {
+ var anim = anims[id],
+ instance = this;
+ Y.log ('Anim Conf: ' + conf, "info", "nodeAccordion");
+ // if the animation is underway: we need to stop it...
+ if ((anim) && (anim.get ('running'))) {
+ anim.stop();
+ }
+ if (Y.Lang.isFunction(instance.get(ATTR_ANIM))) {
+ conf.easing = instance.get(ATTR_ANIM);
+ }
+ anim = new Y.Anim(conf);
+ anim.on('end', fn, instance);
+ anim.run();
+ anims[id] = anim;
+ return anim;
+ },
+
+ /**
+ * @method _openItem
+ * @description Open an item.
+ * @protected
+ * @param {Node} item Node instance representing an item.
+ */
+ _openItem: function (item) {
+ var instance = this,
+ bd,
+ id,
+ fn,
+ fs,
+ i,
+ list = instance.get(ATTR_ITEMS),
+ o = instance.get (ATTR_ORIENTATION),
+ conf = {
+ duration: instance.get(ATTR_SPEED),
+ to: {
+ scroll: []
+ }
+ },
+ mirror, mirror_bd;
+ // if the item is not already opened
+ if (item && list.size() && !item.hasClass(CLASS_ACTIVE) && (bd = instance._getItemBody(item)) && (id = Y.stamp(bd))) {
+ // closing all the selected items if neccesary
+ if (!instance.get(ATTR_MULTIPLE)) {
+ // close all items and open the actived ones
+ mirror = instance._root.one(FC+CLASS_ACTIVE);
}
// opening the selected element, based on the orientation, timer and anim attributes...
- conf.to[o] = (o==WIDTH?bd.get(SCROLL_WIDTH):bd.get(SCROLL_HEIGHT));
- conf.node = bd;
- item.addClass(CLASS_SLIDING);
- fn = function() {
- item.removeClass(CLASS_SLIDING);
- item.addClass(CLASS_ACTIVE);
- // broadcasting the corresponding event (close)...
- // $B.fire ('accordionOpenItem', item);
- };
- if (!this.get(ATTR_ANIM)) {
- // animation manually
- // getting the desired dimension from the current item
- fs = bd.get(o);
- // override the desired dimension from the mirror if exists
- if (Y.Lang.isObject(mirror)) {
- fs = mirror.get(o);
- mirror.addClass(CLASS_SLIDING);
- }
- for (i=1;i<=fs;i++){
- if (Y.Lang.isObject(mirror)) {
- mirror.setStyle (o, (fs-i)+PX);
- }
- bd.setStyle (o, i+PX);
- }
- if (Y.Lang.isObject(mirror)) {
- mirror.removeClass(CLASS_SLIDING);
- mirror.removeClass(CLASS_ACTIVE);
- }
- fn();
- } else {
- // scrolling effect
- conf.to.scroll = [0,0];
- // appliying fadeIn
- if (this.get(ATTR_FADE)) {
- conf.to.opacity = 1;
- }
- if (Y.Lang.isObject(mirror)) {
- this._closeItem(mirror);
- }
- this._animate(id, conf, fn);
- }
+ conf.to[o] = (o==WIDTH?bd.get(SCROLL_WIDTH):bd.get(SCROLL_HEIGHT));
+ conf.node = bd;
+ instance._slidingBegin(item, bd, true);
+ fn = function() {
+ instance._slidingEnd(item, bd);
+ // TODO: broadcasting the corresponding event (close)...
+ };
+ if (!instance.get(ATTR_ANIM)) {
+ // animation manually
+ // getting the desired dimension from the current item
+ fs = _computeSize(bd, o);
+ // override the desired dimension from the mirror if exists
+ if (mirror && (mirror_bd = instance._getItemBody(mirror))) {
+ fs = _computeSize(mirror_bd, o);
+ instance._slidingBegin(mirror, mirror_bd);
+ }
+ for (i=1;i<=conf.to[o];i++){
+ if (mirror && mirror_bd) {
+ mirror_bd.setStyle (o, (fs-i)+PX);
+ }
+ bd.setStyle (o, i+PX);
+ }
+ if (mirror && mirror_bd) {
+ instance._slidingEnd(mirror, mirror_bd, true);
+ }
+ fn();
+ } else {
+ // scrolling effect
+ conf.to.scroll = [0,0];
+ // appliying fadeIn
+ if (instance.get(ATTR_FADE)) {
+ conf.to.opacity = 1;
+ }
+ if (Y.Lang.isObject(mirror)) {
+ instance._closeItem(mirror);
+ }
+ instance._animate(id, conf, fn);
+ }
}
- },
-
- /**
- * @method _closeItem
- * @description Closes the specified item.
- * @protected
- * @param {Node} item Node instance representing an item.
- */
- _closeItem: function (item) {
-
- var bd,
- id,
- fn,
- fs,
- i,
- list = this.get(ATTR_ITEMS),
- o = this.get (ATTR_ORIENTATION),
- conf = {
- duration: this.get(ATTR_SPEED),
- to: {
- scroll: []
- }
- };
- if (item && list.size() && (bd = item.one(SELECTOR_ACCORDION_ITEM_BD)) && (id = Y.stamp(bd))) {
+ },
+
+ /**
+ * @method _closeItem
+ * @description Closes the specified item.
+ * @protected
+ * @param {Node} item Node instance representing an item.
+ */
+ _closeItem: function (item) {
+
+ var instance = this,
+ bd,
+ id,
+ fn,
+ fs,
+ i,
+ list = instance.get(ATTR_ITEMS),
+ o = instance.get (ATTR_ORIENTATION),
+ conf = {
+ duration: instance.get(ATTR_SPEED),
+ to: {
+ scroll: []
+ }
+ };
+ if (item && list.size() && (bd = instance._getItemBody(item)) && (id = Y.stamp(bd))) {
// closing the item, based on the orientation, timer and anim attributes...
- conf.to[o] = (((o==HEIGHT) && UA.ie && (UA.ie<7))?1:0); // hack for vertical accordion issue on Safari and Opera
+ conf.to[o] = (o==HEIGHT?instance.get('minHeight'):instance.get('minWidth'));
conf.node = bd;
- item.addClass(CLASS_SLIDING);
- fn = function() {
- item.removeClass(CLASS_SLIDING);
- item.removeClass(CLASS_ACTIVE);
- // broadcasting the corresponding event (close)...
- // $B.fire ('accordionCloseItem', item);
- };
- if (!this.get(ATTR_ANIM)) {
- // animation manually
- fs = bd.get(o);
- for (i=fs;i>=conf.to[o].to;i--){
- bd.setStyle (o, i+PX);
- }
- fn();
- } else {
- // scrolling effect
- conf.to.scroll = (o==WIDTH?[bd.get(SCROLL_WIDTH),0]:[0,bd.get(SCROLL_HEIGHT)]);
- // appliying fadeIn
- if (this.get(ATTR_FADE)) {
- conf.to.opacity = 0;
- }
- this._animate(id, conf, fn);
- }
+ instance._slidingBegin(item, bd);
+ fn = function() {
+ instance._slidingEnd(item, bd, true);
+ // todo: broadcasting the corresponding event (close)...
+ };
+ if (!instance.get(ATTR_ANIM)) {
+ // animation manually
+ fs = _computeSize(bd, o);
+ for (i=fs;i>=conf.to[o];i--){
+ bd.setStyle (o, i+PX);
+ }
+ fn();
+ } else {
+ // scrolling effect
+ conf.to.scroll = (o==WIDTH?[bd.get(SCROLL_WIDTH),0]:[0,bd.get(SCROLL_HEIGHT)]);
+ // appliying fadeIn
+ if (instance.get(ATTR_FADE)) {
+ conf.to.opacity = 0;
+ }
+ instance._animate(id, conf, fn);
+ }
}
- },
-
- // Public methods
-
- // Generic DOM Event handlers
- /**
- * @method expandAllItems
- * @description Expanding all items.
- * @public
- * @return {object} Plugin reference for chaining
- */
- expandAllItems: function () {
- Y.log(("Expanding all items (only if attr multiple=true): " + this._root), "info", "nodeAccordion");
- if (this.get(ATTR_MULTIPLE)) {
- this.get(ATTR_ITEMS).each(function (node) {
- this.expandItem(node);
- }, this);
- }
- return this;
- },
-
- /**
- * @method collapseAllItems
- * @description Collapsing all items.
- * @public
- * @return {object} Plugin reference for chaining
- */
- collapseAllItems: function () {
- Y.log(("Collapsing all items (only if attr multiple=true or attr persistent=false): " + this._root), "info", "nodeAccordion");
- if (this.get(ATTR_MULTIPLE) || !this.get(ATTR_PERSISTENT)) {
- this.get(ATTR_ITEMS).each(function (node) {
- this.collapseItem(node);
- }, this);
- }
- return this;
- },
-
- /**
- * @method expandItem
- * @description Expand a certain item.
- * @public
- * @param {Node} node Node reference
- * @return {object} Plugin reference for chaining
- */
- expandItem: function ( node ) {