diff --git a/build/gallery-accordion/gallery-accordion-debug.js b/build/gallery-accordion/gallery-accordion-debug.js
index 330f1c21bb..07542fc17c 100644
--- a/build/gallery-accordion/gallery-accordion-debug.js
+++ b/build/gallery-accordion/gallery-accordion-debug.js
@@ -1,7 +1,7 @@
YUI.add('gallery-accordion', function(Y) {
/**
- * Provides the Accordion class
+ * Provides Accordion widget
*
* @module gallery-accordion
*/
@@ -1712,7 +1712,7 @@ Y.Accordion = Accordion;
}());
/**
- * Provides the Accordion class
+ * Provides AccordionItem class
*
* @module gallery-accordion
*/
@@ -1785,7 +1785,12 @@ var Lang = Y.Lang,
HREF = "href",
HREF_VALUE = "#",
YUICONFIG = "yuiConfig",
- HEADER_CONTENT = "headerContent";
+ HEADER_CONTENT = "headerContent",
+
+ REGEX_TRUE = /^(?:true|yes|1)$/,
+ REGEX_AUTO = /^auto\s*/,
+ REGEX_STRETCH = /^stretch\s*/,
+ REGEX_FIXED = /^fixed-\d+/;
/**
* Static property provides a string to identify the class.
@@ -1906,7 +1911,7 @@ AccordionItem.ATTRS = {
},
/**
- * @description Get/Set the expanded status of the item
+ * @description Get/Set expanded status of the item
*
* @attribute expanded
* @default false
@@ -1952,7 +1957,7 @@ AccordionItem.ATTRS = {
},
/**
- * @description Get/Set the expanded status of the item
+ * @description Get/Set always visible status of the item
*
* @attribute alwaysVisible
* @default false
@@ -2032,7 +2037,7 @@ AccordionItem.HTML_PARSER = {
},
label: function( contentBox ){
- var node, labelSelector, yuiConfig;
+ var node, labelSelector, yuiConfig, label;
yuiConfig = this._getConfigDOMAttribute( contentBox );
@@ -2040,6 +2045,12 @@ AccordionItem.HTML_PARSER = {
return yuiConfig.label;
}
+ label = contentBox.getAttribute( "data-label" );
+
+ if( label ){
+ return label;
+ }
+
labelSelector = HEADER_SELECTOR_SUB + C_LABEL;
node = contentBox.query( labelSelector );
@@ -2092,47 +2103,70 @@ AccordionItem.HTML_PARSER = {
},
expanded: function( contentBox ){
- var yuiConfig = this._getConfigDOMAttribute( contentBox );
+ var yuiConfig, expanded;
+
+ yuiConfig = this._getConfigDOMAttribute( contentBox );
- if( yuiConfig && Lang.isValue( yuiConfig.expanded ) ){
+ if( yuiConfig && Lang.isBoolean( yuiConfig.expanded ) ){
return yuiConfig.expanded;
}
+ expanded = contentBox.getAttribute( "data-expanded" );
+
+ if( expanded ) {
+ return REGEX_TRUE.test( expanded );
+ }
+
return contentBox.hasClass( C_EXPANDED );
},
alwaysVisible: function( contentBox ){
- var value, yuiConfig;
+ var yuiConfig, alwaysVisible;
yuiConfig = this._getConfigDOMAttribute( contentBox );
- if( yuiConfig && Lang.isValue( yuiConfig.alwaysVisible ) ){
- value = yuiConfig.alwaysVisible;
+ if( yuiConfig && Lang.isBoolean( yuiConfig.alwaysVisible ) ){
+ alwaysVisible = yuiConfig.alwaysVisible;
} else {
- value = contentBox.hasClass( C_ALWAYSVISIBLE );
+ alwaysVisible = contentBox.getAttribute( "data-alwaysvisible" );
+
+ if( alwaysVisible ) {
+ alwaysVisible = REGEX_TRUE.test( alwaysVisible );
+ } else {
+ alwaysVisible = contentBox.hasClass( C_ALWAYSVISIBLE );
+ }
}
- if( Lang.isBoolean(value) && value ){
+ if( alwaysVisible ){
this.set( "expanded", true, {
internalCall: true
} );
}
- return value;
+ return alwaysVisible;
},
closable: function( contentBox ){
- var yuiConfig = this._getConfigDOMAttribute( contentBox );
+ var yuiConfig, closable;
+
+ yuiConfig = this._getConfigDOMAttribute( contentBox );
- if( yuiConfig && Lang.isValue( yuiConfig.closable ) ){
+ if( yuiConfig && Lang.isBoolean( yuiConfig.closable ) ){
return yuiConfig.closable;
}
+ closable = contentBox.getAttribute( "data-closable" );
+
+ if( closable ) {
+ return REGEX_TRUE.test( closable );
+ }
+
return contentBox.hasClass( C_CLOSABLE );
},
contentHeight: function( contentBox ){
- var contentHeightClass, classValue, height = 0, i, length, index, chr, yuiConfig;
+ var contentHeightClass, classValue, height = 0, index, yuiConfig,
+ contentHeight;
yuiConfig = this._getConfigDOMAttribute( contentBox );
@@ -2140,6 +2174,26 @@ AccordionItem.HTML_PARSER = {
return yuiConfig.contentHeight;
}
+ contentHeight = contentBox.getAttribute( "data-contentheight" );
+
+ if( REGEX_AUTO.test( contentHeight ) ){
+ return {
+ method: AUTO
+ };
+ } else if( REGEX_STRETCH.test( contentHeight ) ){
+ return {
+ method: STRETCH
+ };
+ } else if( REGEX_FIXED.test( contentHeight ) ){
+ height = this._extractFixedMethodValue( contentHeight );
+
+ return {
+ method: FIXED,
+ height: height
+ };
+ }
+
+
classValue = contentBox.get( CLASS_NAME );
contentHeightClass = C_CONTENTHEIGHT + '-';
@@ -2147,31 +2201,21 @@ AccordionItem.HTML_PARSER = {
index = classValue.indexOf( contentHeightClass, 0);
if( index >= 0 ){
- length = classValue.length;
index += contentHeightClass.length;
classValue = classValue.substring( index );
- if( classValue.match( /^auto\s*/g ) ){
+ if( REGEX_AUTO.test( classValue ) ){
return {
method: AUTO
};
- } else if( classValue.match( /^stretch\s*/g ) ){
+ } else if( REGEX_STRETCH.test( classValue ) ){
return {
method: STRETCH
};
- } else if( classValue.match( /^fixed-\d+/g ) ){
- for( i = 6, length = classValue.length; i < length; i++ ){ // 6 = "fixed-".length
- chr = classValue.charAt(i);
- chr = parseInt( chr, 10 );
-
- if( Lang.isNumber( chr ) ){
- height = (height * 10) + chr;
- } else {
- break;
- }
- }
-
+ } else if( REGEX_FIXED.test( classValue ) ){
+ height = this._extractFixedMethodValue( classValue );
+
return {
method: FIXED,
height: height
@@ -2363,7 +2407,7 @@ Y.extend( AccordionItem, Y.Widget, {
if( this.get( RENDERED ) ){
label = this.get( NODE_LABEL );
- label.set( INNER_HTML, ["", params.newVal, "" ].join('') );
+ label.set( INNER_HTML, params.newVal );
}
},
@@ -2578,9 +2622,9 @@ Y.extend( AccordionItem, Y.Widget, {
* This function will be replaced with more clever solution when YUI 3.1 becomes available
*
* @method _getConfigDOMAttribute
- * @private
* @param {Node} contentBox Widget's contentBox
* @return {Object} The parsed yuiConfig value
+ * @private
*/
_getConfigDOMAttribute: function( contentBox ) {
if( !this._parsedCfg ){
@@ -2592,6 +2636,33 @@ Y.extend( AccordionItem, Y.Widget, {
}
return this._parsedCfg;
+ },
+
+
+ /**
+ * Parses and returns the value of contentHeight property, if set method "fixed".
+ * The value must be in this format: fixed-X, where X is integer
+ *
+ * @method _extractFixedMethodValue
+ * @param {String} value The value to be parsed
+ * @return {Number} The parsed value or null
+ * @protected
+ */
+ _extractFixedMethodValue: function( value ){
+ var i, length, chr, height = null;
+
+ for( i = 6, length = value.length; i < length; i++ ){ // 6 = "fixed-".length
+ chr = value.charAt(i);
+ chr = parseInt( chr, 10 );
+
+ if( Lang.isNumber( chr ) ){
+ height = (height * 10) + chr;
+ } else {
+ break;
+ }
+ }
+
+ return height;
}
});
@@ -2607,4 +2678,4 @@ Y.AccordionItem = AccordionItem;
-}, 'gallery-2009.10.27' ,{requires:['event', 'anim-easing', 'dd-constrain', 'dd-proxy', 'dd-drop', 'widget', 'widget-stdmod', 'json-parse']});
+}, 'gallery-2009.11.09-19' ,{requires:['event', 'anim-easing', 'dd-constrain', 'dd-proxy', 'dd-drop', 'widget', 'widget-stdmod', 'json-parse']});
diff --git a/build/gallery-accordion/gallery-accordion-min.js b/build/gallery-accordion/gallery-accordion-min.js
index 11c7799103..fc6b052faa 100644
--- a/build/gallery-accordion/gallery-accordion-min.js
+++ b/build/gallery-accordion/gallery-accordion-min.js
@@ -1,4 +1,4 @@
YUI.add("gallery-accordion",function(A){(function(){function M(v){M.superclass.constructor.apply(this,arguments);}var u=A.Lang,V=A.Node,Z=A.Anim,H=A.Easing,N="accordion",X=A.WidgetStdMod,s=document.compatMode=="BackCompat",T=s&&A.UA.ie>0,U=T?1:0,I=A.ClassNameManager.getClassName,W="yui-accordion-item",f=I(N,"proxyel","visible"),h=I(N,"graggroup"),b="beforeItemAdd",e="itemAdded",D="beforeItemRemove",i="itemRemoved",C="beforeItemResized",p="itemResized",d="beforeItemExpand",g="beforeItemCollapse",J="itemExpanded",m="itemCollapsed",j="beforeItemReorder",R="beforeEndItemReorder",S="itemReordered",k="default",O="animation",P="alwaysVisible",E="expanded",c="collapseOthersOnExpand",Y="items",t="contentHeight",B="iconClose",F="iconAlwaysVisible",G="stretch",r="px",a="contentBox",n="boundingBox",l="rendered",o="bodyContent",Q="children",K="parentNode",q="node",L="data";M.NAME=N;M.ATTRS={itemChosen:{value:"click",validator:u.isString},items:{value:[],readOnly:true,validator:u.isArray},resizeEvent:{value:k,validator:function(v){return(u.isString(v)||u.isObject(v));}},useAnimation:{value:true,validator:u.isBoolean},animation:{value:{duration:1,easing:H.easeOutStrong},validator:function(v){return u.isObject(v)&&u.isNumber(v.duration)&&u.isFunction(v.easing);}},reorderItems:{value:true,validator:u.isBoolean},collapseOthersOnExpand:{value:true,validator:u.isBoolean}};A.extend(M,A.Widget,{initializer:function(v){this._initEvents();this.after("render",A.bind(this._afterRender,this));this._forCollapsing={};this._forExpanding={};this._animations={};},destructor:function(){var v,y,w,x;v=this.get(Y);x=v.length;for(w=x-1;w>=0;w--){y=v[w];v.splice(w,1);this._removeItemHandles(y);y.destroy();}},_initEvents:function(){this.publish(b);this.publish(e);this.publish(D);this.publish(i);this.publish(C);this.publish(p);this.publish(d);this.publish(g);this.publish(J);this.publish(m);this.publish(j);this.publish(R);this.publish(S);},_itemsHandles:{},_removeItemHandles:function(x){var w,v;w=this._itemsHandles[x];for(v in w){if(w.hasOwnProperty(v)){v=w[v];v.detach();}}delete this._itemsHandles[x];},_getNodeOffsetHeight:function(x){var v,w;if(x instanceof V){if(x.hasMethod("getBoundingClientRect")){w=x.invoke("getBoundingClientRect");if(w){v=w.bottom-w.top;return v;}}else{v=x.get("offsetHeight");return A.Lang.isValue(v)?v:0;}}else{if(x){v=x.offsetHeight;return A.Lang.isValue(v)?v:0;}}return 0;},_setItemProperties:function(x,z,w){var v,y;v=x.get(P);y=x.get(E);if(z!=y){x.set(E,z,{internalCall:true});}if(w!==v){x.set(P,w,{internalCall:true});}},_setItemUI:function(w,x,v){w.markAsExpanded(x);w.markAsAlwaysVisible(v);},_afterRender:function(w){var v;v=this.get("resizeEvent");this._setUpResizing(v);this.after("resizeEventChange",A.bind(this._afterResizeEventChange,this));},_afterResizeEventChange:function(v){this._setUpResizing(v.newValue);},_onItemChosen:function(AA,AB,v){var z,x,y,w;z={};w=this.get(c);x=AA.get(P);y=AA.get(E);if(v){this.removeItem(AA);return;}else{if(AB){if(y){x=!x;y=x?true:y;this._setItemProperties(AA,y,x);this._setItemUI(AA,y,x);return;}else{this._forExpanding[AA]={"item":AA,alwaysVisible:true};if(w){z[AA]={"item":AA};this._storeItemsForCollapsing(z);}}}else{if(y){this._forCollapsing[AA]={"item":AA};}else{this._forExpanding[AA]={"item":AA,"alwaysVisible":x};if(w){z[AA]={"item":AA};this._storeItemsForCollapsing(z);}}}}this._processItems();},_adjustStretchItems:function(){var v=this.get(Y),w;w=this._getHeightPerStretchItem();A.Array.each(v,function(AB,AA,z){var x,AD,AC,AE,y;AE=AB.get(t);y=AB.get(E);if(AE.method===G&&y){AC=this._animations[AB];if(AC){AC.stop();}x=AB.getStdModNode(X.BODY);AD=this._getNodeOffsetHeight(x);if(w
+ * The beforeunload event is not standard, yet it is useful enough that
+ * most browsers support it to some degree. But they are not consistent
+ * about how it operates. This module supplants any existing DOM0
+ * onbeforelistener because DOM2 style listeners won't work across
+ * the A grade at this time.
+ *
+ * You can attempt to prevent the user from leaving the page by calling
+ * preventDefault on the event object. The user will be presented with
+ * a dialog to see whether or not they want to allow this. You can provide
+ * a message to preventDefault, and this will override the default message
+ * in the dialog if it is provided.
+ *
+ * The beforeunload event is not standard, yet it is useful enough that
+ * most browsers support it to some degree. But they are not consistent
+ * about how it operates. This module supplants any existing DOM0
+ * onbeforelistener because DOM2 style listeners won't work across
+ * the A grade at this time.
+ *
+ * You can attempt to prevent the user from leaving the page by calling
+ * preventDefault on the event object. The user will be presented with
+ * a dialog to see whether or not they want to allow this. You can provide
+ * a message to preventDefault, and this will override the default message
+ * in the dialog if it is provided.
+ * Provides subscribable drag events from Node or NodeLists. Subscribing
+ * to any of the events causes the node to be plugged with Y.Plugin.Drag. The
+ * config object passed can be used to set Drag instance attributes or add
+ * additional Plugins to the Drag instance such as Y.Plugin.DDProxy.' + this.get('header') + '
'),
+ node = Y.Node.create(''),
+ n = this.get('node');
+
+ if (type != 'random') {
+ if (type == 'user') {
+ header = Y.Node.create('
' + data.userinfo.fullname + '\'s Gallery Items
');
+ }
+ Y.each(data.modules, function(v) {
+ node.append('"+this.get("header")+"
"),D=A.Node.create(""),G=this.get("node");if(B!="random"){if(B=="user"){H=A.Node.create('
'+E.userinfo.fullname+"'s Gallery Items
");}A.each(E.modules,function(I){D.append('' + this.get('header') + '
'),
+ node = Y.Node.create(''),
+ n = this.get('node');
+
+ if (type != 'random') {
+ if (type == 'user') {
+ header = Y.Node.create('
' + data.userinfo.fullname + '\'s Gallery Items
');
+ }
+ Y.each(data.modules, function(v) {
+ node.append('
+ * Y.on('beforeunload', function(e) {
+ * &nbws;&nbws;e.returnValue = "Please don't go.";
+ * });
+ *
+ *
+ * @event beforeunload
+ * @for YUI
+ * @param type {string} 'beforeunload'
+ * @param fn {function} the callback function to execute.
+ * @param context optional argument that specifies what 'this' refers to.
+ * @param args* 0..n additional arguments to pass on to the callback function.
+ * These arguments will be added after the event object.
+ */
+Y.Env.evt.plugins.beforeunload = {
+ on: function(type, fn) {
+ var a = Y.Array(arguments, 0, true);
+ a[0] = INTERNAL_EVENT_NAME;
+ return Y.on.apply(Y, a);
+ }
+};
+
+
+}, 'gallery-2009.11.02-20' ,{requires:['event-base']});
diff --git a/build/gallery-beforeunload/gallery-beforeunload-min.js b/build/gallery-beforeunload/gallery-beforeunload-min.js
new file mode 100644
index 0000000000..7cac896151
--- /dev/null
+++ b/build/gallery-beforeunload/gallery-beforeunload-min.js
@@ -0,0 +1 @@
+YUI.add("gallery-beforeunload",function(C){var B="gallery-dom0beforeunload",A=window.onbeforeunload;window.onbeforeunload=function(E){var G=E||window.event;if(A){A(G);}var D=new C.DOMEventFacade(G),F;C.fire(B,D);F=D.returnValue;G.returnValue=F;return F;};C.Env.evt.plugins.beforeunload={on:function(F,E){var D=C.Array(arguments,0,true);D[0]=B;return C.on.apply(C,D);}};},"gallery-2009.11.02-20",{requires:["event-base"]});
\ No newline at end of file
diff --git a/build/gallery-beforeunload/gallery-beforeunload.js b/build/gallery-beforeunload/gallery-beforeunload.js
new file mode 100644
index 0000000000..1a71e7d851
--- /dev/null
+++ b/build/gallery-beforeunload/gallery-beforeunload.js
@@ -0,0 +1,63 @@
+YUI.add('gallery-beforeunload', function(Y) {
+
+/**
+ * DOM0 beforeunload event listener support.
+ * @module gallery-beforeunload
+ */
+
+var INTERNAL_EVENT_NAME = 'gallery-dom0beforeunload',
+ supplantedHandler = window.onbeforeunload;
+
+window.onbeforeunload = function(ev) {
+ var e = ev || window.event;
+ if (supplantedHandler) {
+ supplantedHandler(e);
+ }
+ var facade = new Y.DOMEventFacade(e), retVal;
+ Y.fire(INTERNAL_EVENT_NAME, facade);
+ retVal = facade.returnValue;
+ e.returnValue = retVal;
+ return retVal;
+};
+
+/**
+ *
+ * Y.on('beforeunload', function(e) {
+ * &nbws;&nbws;e.returnValue = "Please don't go.";
+ * });
+ *
+ *
+ * @event beforeunload
+ * @for YUI
+ * @param type {string} 'beforeunload'
+ * @param fn {function} the callback function to execute.
+ * @param context optional argument that specifies what 'this' refers to.
+ * @param args* 0..n additional arguments to pass on to the callback function.
+ * These arguments will be added after the event object.
+ */
+Y.Env.evt.plugins.beforeunload = {
+ on: function(type, fn) {
+ var a = Y.Array(arguments, 0, true);
+ a[0] = INTERNAL_EVENT_NAME;
+ return Y.on.apply(Y, a);
+ }
+};
+
+
+}, 'gallery-2009.11.02-20' ,{requires:['event-base']});
diff --git a/build/gallery-bitly/gallery-bitly-debug.js b/build/gallery-bitly/gallery-bitly-debug.js
new file mode 100644
index 0000000000..8c5f4a4543
--- /dev/null
+++ b/build/gallery-bitly/gallery-bitly-debug.js
@@ -0,0 +1,108 @@
+YUI.add('gallery-bitly', function(Y) {
+
+
+
+ var B = function(config) {
+ B.superclass.constructor.call(this, config);
+ };
+
+ B.NAME = 'bitly';
+
+ B.ATTRS = {
+ username: {
+ value: ''
+ },
+ key: {
+ value: ''
+ }
+ };
+
+ Y.extend(B, Y.Base, {
+ api: 'http:/'+'/api.bit.ly/',
+ initializer: function() {
+ if (!this.get('key') || !this.get('username')) {
+ Y.error('You must give a username and an API key. If you do not have an apiKey, sign up for a bitly account and go to your Account page to get your apiKey. (http:/'+'/bit.ly/)');
+ }
+ },
+ destructor: function() {
+ },
+ _buildURL: function(path, param) {
+ return this.api + path + '?version=2.0.1&login=' + this.get('username') + '&apiKey=' + this.get('key') + '&' + param;
+ },
+ _handleAPI: function(name, url, cb) {
+ Y.log('handleAPI: ' + name + ' : ' + url, 'info');
+
+ var stamp = Y.guid().replace(/-/g,'_');
+
+ YUI[stamp] = Y.bind(function(e) {
+ if (e.results) {
+ if (name == 'stats') {
+ this.fire(name, e.results);
+ if (cb) {
+ cb = Y.bind(cb, this);
+ cb(e.results);
+ }
+ } else {
+ Y.each(e.results, function(v) {
+ this.fire(name, v);
+ if (cb) {
+ cb = Y.bind(cb, this);
+ cb(v);
+ }
+ }, this);
+ }
+ }
+ delete YUI[stamp];
+ }, this);
+
+ Y.Get.script(url + '&callback=YUI.' + stamp);
+ },
+ shorten: function(url, cb) {
+ var api = this._buildURL('shorten', 'longUrl=' + encodeURIComponent(url));
+ this._handleAPI('shorten', api, cb);
+ },
+ expand: function(p, cb) {
+ var path = ((p.url) ? 'shortUrl=' + encodeURIComponent(p.url) : 'hash=' + p.hash),
+ api = this._buildURL('expand', path);
+
+ this._handleAPI('expand', api, cb);
+
+ },
+ expandByURL: function(v, cb) {
+ return this.expand({ url: v }, cb);
+ },
+ expandByHash: function(v, cb) {
+ return this.expand({ hash: v }, cb);
+ },
+ info: function(p, cb) {
+ var path = ((p.url) ? 'shortUrl=' + encodeURIComponent(p.url) : 'hash=' + p.hash),
+ api = this._buildURL('info', path);
+
+ this._handleAPI('info', api, cb);
+
+ },
+ infoByURL: function(v, cb) {
+ return this.info({ url: v }, cb);
+ },
+ infoByHash: function(v, cb) {
+ return this.info({ hash: v }, cb);
+ },
+ stats: function(p, cb) {
+ var path = ((p.url) ? 'shortUrl=' + encodeURIComponent(p.url) : 'hash=' + p.hash),
+ api = this._buildURL('stats', path);
+
+ this._handleAPI('stats', api, cb);
+
+ },
+ statsByURL: function(v, cb) {
+ return this.stats({ url: v }, cb);
+ },
+ statsByHash: function(v, cb) {
+ return this.stats({ hash: v }, cb);
+ }
+ });
+
+ Y.bitly = B;
+
+
+}, 'gallery-2009.11.09-19' ,{requires:['base','get']});
diff --git a/build/gallery-bitly/gallery-bitly-min.js b/build/gallery-bitly/gallery-bitly-min.js
new file mode 100644
index 0000000000..765d647a02
--- /dev/null
+++ b/build/gallery-bitly/gallery-bitly-min.js
@@ -0,0 +1 @@
+YUI.add("gallery-bitly",function(A){var C=function(B){C.superclass.constructor.call(this,B);};C.NAME="bitly";C.ATTRS={username:{value:""},key:{value:""}};A.extend(C,A.Base,{api:"http:/"+"/api.bit.ly/",initializer:function(){if(!this.get("key")||!this.get("username")){A.error("You must give a username and an API key. If you do not have an apiKey, sign up for a bitly account and go to your Account page to get your apiKey. (http:/"+"/bit.ly/)");}},destructor:function(){},_buildURL:function(B,D){return this.api+B+"?version=2.0.1&login="+this.get("username")+"&apiKey="+this.get("key")+"&"+D;},_handleAPI:function(E,D,B){var F=A.guid().replace(/-/g,"_");YUI[F]=A.bind(function(G){if(G.results){if(E=="stats"){this.fire(E,G.results);if(B){B=A.bind(B,this);B(G.results);}}else{A.each(G.results,function(H){this.fire(E,H);if(B){B=A.bind(B,this);B(H);}},this);}}delete YUI[F];},this);A.Get.script(D+"&callback=YUI."+F);},shorten:function(D,B){var E=this._buildURL("shorten","longUrl="+encodeURIComponent(D));this._handleAPI("shorten",E,B);},expand:function(F,B){var E=((F.url)?"shortUrl="+encodeURIComponent(F.url):"hash="+F.hash),D=this._buildURL("expand",E);this._handleAPI("expand",D,B);},expandByURL:function(D,B){return this.expand({url:D},B);},expandByHash:function(D,B){return this.expand({hash:D},B);},info:function(F,B){var E=((F.url)?"shortUrl="+encodeURIComponent(F.url):"hash="+F.hash),D=this._buildURL("info",E);this._handleAPI("info",D,B);},infoByURL:function(D,B){return this.info({url:D},B);},infoByHash:function(D,B){return this.info({hash:D},B);},stats:function(F,B){var E=((F.url)?"shortUrl="+encodeURIComponent(F.url):"hash="+F.hash),D=this._buildURL("stats",E);this._handleAPI("stats",D,B);},statsByURL:function(D,B){return this.stats({url:D},B);},statsByHash:function(D,B){return this.stats({hash:D},B);}});A.bitly=C;},"gallery-2009.11.09-19",{requires:["base","get"]});
\ No newline at end of file
diff --git a/build/gallery-bitly/gallery-bitly.js b/build/gallery-bitly/gallery-bitly.js
new file mode 100644
index 0000000000..4210902d13
--- /dev/null
+++ b/build/gallery-bitly/gallery-bitly.js
@@ -0,0 +1,107 @@
+YUI.add('gallery-bitly', function(Y) {
+
+
+
+ var B = function(config) {
+ B.superclass.constructor.call(this, config);
+ };
+
+ B.NAME = 'bitly';
+
+ B.ATTRS = {
+ username: {
+ value: ''
+ },
+ key: {
+ value: ''
+ }
+ };
+
+ Y.extend(B, Y.Base, {
+ api: 'http:/'+'/api.bit.ly/',
+ initializer: function() {
+ if (!this.get('key') || !this.get('username')) {
+ Y.error('You must give a username and an API key. If you do not have an apiKey, sign up for a bitly account and go to your Account page to get your apiKey. (http:/'+'/bit.ly/)');
+ }
+ },
+ destructor: function() {
+ },
+ _buildURL: function(path, param) {
+ return this.api + path + '?version=2.0.1&login=' + this.get('username') + '&apiKey=' + this.get('key') + '&' + param;
+ },
+ _handleAPI: function(name, url, cb) {
+
+ var stamp = Y.guid().replace(/-/g,'_');
+
+ YUI[stamp] = Y.bind(function(e) {
+ if (e.results) {
+ if (name == 'stats') {
+ this.fire(name, e.results);
+ if (cb) {
+ cb = Y.bind(cb, this);
+ cb(e.results);
+ }
+ } else {
+ Y.each(e.results, function(v) {
+ this.fire(name, v);
+ if (cb) {
+ cb = Y.bind(cb, this);
+ cb(v);
+ }
+ }, this);
+ }
+ }
+ delete YUI[stamp];
+ }, this);
+
+ Y.Get.script(url + '&callback=YUI.' + stamp);
+ },
+ shorten: function(url, cb) {
+ var api = this._buildURL('shorten', 'longUrl=' + encodeURIComponent(url));
+ this._handleAPI('shorten', api, cb);
+ },
+ expand: function(p, cb) {
+ var path = ((p.url) ? 'shortUrl=' + encodeURIComponent(p.url) : 'hash=' + p.hash),
+ api = this._buildURL('expand', path);
+
+ this._handleAPI('expand', api, cb);
+
+ },
+ expandByURL: function(v, cb) {
+ return this.expand({ url: v }, cb);
+ },
+ expandByHash: function(v, cb) {
+ return this.expand({ hash: v }, cb);
+ },
+ info: function(p, cb) {
+ var path = ((p.url) ? 'shortUrl=' + encodeURIComponent(p.url) : 'hash=' + p.hash),
+ api = this._buildURL('info', path);
+
+ this._handleAPI('info', api, cb);
+
+ },
+ infoByURL: function(v, cb) {
+ return this.info({ url: v }, cb);
+ },
+ infoByHash: function(v, cb) {
+ return this.info({ hash: v }, cb);
+ },
+ stats: function(p, cb) {
+ var path = ((p.url) ? 'shortUrl=' + encodeURIComponent(p.url) : 'hash=' + p.hash),
+ api = this._buildURL('stats', path);
+
+ this._handleAPI('stats', api, cb);
+
+ },
+ statsByURL: function(v, cb) {
+ return this.stats({ url: v }, cb);
+ },
+ statsByHash: function(v, cb) {
+ return this.stats({ hash: v }, cb);
+ }
+ });
+
+ Y.bitly = B;
+
+
+}, 'gallery-2009.11.09-19' ,{requires:['base','get']});
diff --git a/build/gallery-chromahash/gallery-chromahash-debug.js b/build/gallery-chromahash/gallery-chromahash-debug.js
new file mode 100644
index 0000000000..fbc2561d25
--- /dev/null
+++ b/build/gallery-chromahash/gallery-chromahash-debug.js
@@ -0,0 +1,104 @@
+YUI.add('gallery-chromahash', function(Y) {
+
+/*
+ * Chroma-Hash : A sexy, non-reversable live visualization of password field input
+ * Idea based on jQuery module by Mattt Thompson (http://github.com/mattt/Chroma-Hash/)
+ */
+
+var LBL_TMPL = '',
+ _C = function(conf) {
+ _C.superclass.constructor.apply(this, arguments);
+ this._animations = [];
+ };
+_C.NAME = "ChromaHash";
+_C.ATTRS =
+ {
+ bars: {
+ value: 3,
+ validator: function(b) {
+ if (b < 1 || b > 4) {
+ return false;
+ }
+ }
+ },
+ salt: {
+ value: "7be82b35cb0199120eea35a4507c9acf"
+ },
+ minimum: {
+ value: 6
+ },
+ node: {
+ setter: function(node) {
+ var n = Y.get(node);
+ if (!n && !n.test('input[type=password]')) {
+ Y.fail('ChromaHash: Invalid node provided: ' + node);
+ }
+ return n;
+ }
+ }
+ };
+Y.extend(_C, Y.Widget, {
+ renderUI: function() {
+ var colors = ["primary", "secondary", "tertiary", "quaternary"].slice(0, this.get('bars')),
+ c = this.get('contentBox'), n = this.get('node'), i, lbl, width = n.get('clientWidth'),
+ height = n.get('clientHeight'), position = n.getXY();
+ // Preferably, I'd be able to set the position on the boudningBox, but for now, this will function.
+ for (i = 0 ; i < colors.length ; i += 1) {
+ lbl = Y.Node.create(LBL_TMPL.replace(/\{id\}/g, n.get('id')).replace(/\{color\}/g, colors[i]));
+ lbl.setStyles({
+ position: 'absolute',
+ height: height + "px",
+ width: "8px",
+ margin: "5px",
+ marginLeft: "0px",
+ backgroundColor: this.get('node').getStyle('backgroundColor')
+ });
+ c.insert(lbl);
+ lbl.setXY([position[0] + width - 2 + (-8 * (i + 1)), position[1] + 3]);
+ this._animations.push(new Y.Anim({node: lbl, duration: 0.5}));
+ }
+ },
+ bindUI: function() {
+ this._keyHandler = this.get('node').on('keyup', this._handleKey, this);
+ },
+ hide: function() {
+ this.get('boundingBox').setStyle('display','none');
+ },
+ clear: function() {
+ this.hide();
+ this.get('boundingBox').set('innerHTML','');
+ },
+ destroy: function() {
+ this._keyHandler.detach();
+ this._clear();
+ },
+ _handleKey: function(e) {
+ var n = this.get('node'), value = n.get('value'), i,
+ col = [], bars = this.get('bars'), md5, g;
+ if(value === "" ) {
+ for( i = 0 ; i < bars ; i += 1) { col.push('fff'); }
+ } else {
+ md5 = Y.Crypto.MD5('' + value + ':' + this.get('salt'));
+ col = md5.match(/([\dABCDEF]{6})/ig);
+ if (value.length < this.get('minimum')) {
+ for (i = 0; i < bars ; i += 1) {
+ g = (parseInt(col[i], 0x10) % 0xF).toString(0x10);
+ col[i] = g + g + g;
+ }
+ }
+ }
+
+ Y.Array.each(this._animations,
+ function(a, index) {
+ var c = a.get('node');
+ a.stop();
+ a.set('from', {backgroundColor: c.getStyle('backgroundColor')});
+ a.set('to', {backgroundColor: '#' + col[index] });
+ a.run();
+ });
+ }
+});
+Y.ChromaHash = _C;
+
+
+}, 'gallery-2009.11.09-19' ,{requires:['widget', 'stylesheet', 'collection', 'anim-color', 'gallery-crypto-md5']});
diff --git a/build/gallery-chromahash/gallery-chromahash-min.js b/build/gallery-chromahash/gallery-chromahash-min.js
new file mode 100644
index 0000000000..499fe55621
--- /dev/null
+++ b/build/gallery-chromahash/gallery-chromahash-min.js
@@ -0,0 +1 @@
+YUI.add("gallery-chromahash",function(C){var B='',A=function(D){A.superclass.constructor.apply(this,arguments);this._animations=[];};A.NAME="ChromaHash";A.ATTRS={bars:{value:3,validator:function(D){if(D<1||D>4){return false;}}},salt:{value:"7be82b35cb0199120eea35a4507c9acf"},minimum:{value:6},node:{setter:function(D){var E=C.get(D);if(!E&&!E.test("input[type=password]")){C.fail("ChromaHash: Invalid node provided: "+D);}return E;}}};C.extend(A,C.Widget,{renderUI:function(){var F=["primary","secondary","tertiary","quaternary"].slice(0,this.get("bars")),K=this.get("contentBox"),J=this.get("node"),G,I,H=J.get("clientWidth"),E=J.get("clientHeight"),D=J.getXY();for(G=0;G
node.on('drag:start', fn, { proxy: true, data: 123 });
+ *
+ * This adds Y.Plugin.DDProxy to the Drag instance and also set's the Drag instance's data attribute.
+ * + *Passing any value will result in the Plugin being added, but if you pass + * an object literal as the value, it will be sent to the Plugin's + * constructor.
+ * + *node.on('drag:end', fn, {
+ * constrained: { constrain2node: '#container' }
+ * });
+ *
+ * This adds Y.Plugin.DDConstrained to the Drag instance using the specified + * configuration.
+ * + *A custom detach handle is returned, whose detach method unplugs the + * Y.Plugin.Drag from the node(s).
+ * + *Supported events are:
+ *Additionally, the default callback context is overridden to the
+ * subscribing Node unless otherwise specified during the subscription.
+ * So "this" in the callback will refer to the node. On the
+ * event object passed to subscribers, e.currentTarget
is also the
+ * Node regardless of context override. The Drag instance is available from
+ * the Node as node.dd
.
Provides subscribable drag events from Node or NodeLists. Subscribing + * to any of the events causes the node to be plugged with Y.Plugin.Drag. The + * config object passed can be used to set Drag instance attributes or add + * additional Plugins to the Drag instance such as Y.Plugin.DDProxy.
+ * + * Config properties are formatted and tested for a corresponding Y.Plugin.* as + * 'somePlugin' => Y.Plugin.DDSomePlugin if the property name doesn't already + * start with "DD". So { proxy: true } and { DDProxy: true } are functionally + * equivalent. Both add Y.Plugin.DDProxy to the Drag instance. + * + *node.on('drag:start', fn, { proxy: true, data: 123 });
+ *
+ * This adds Y.Plugin.DDProxy to the Drag instance and also set's the Drag instance's data attribute.
+ * + *Passing any value will result in the Plugin being added, but if you pass + * an object literal as the value, it will be sent to the Plugin's + * constructor.
+ * + *node.on('drag:end', fn, {
+ * constrained: { constrain2node: '#container' }
+ * });
+ *
+ * This adds Y.Plugin.DDConstrained to the Drag instance using the specified + * configuration.
+ * + *A custom detach handle is returned, whose detach method unplugs the + * Y.Plugin.Drag from the node(s).
+ * + *Supported events are:
+ *Additionally, the default callback context is overridden to the
+ * subscribing Node unless otherwise specified during the subscription.
+ * So "this" in the callback will refer to the node. On the
+ * event object passed to subscribers, e.currentTarget
is also the
+ * Node regardless of context override. The Drag instance is available from
+ * the Node as node.dd
.
decodeURIComponent()
that also converts +
+ * chars into spaces.
+ *
+ * @method decode
+ * @param {String} string string to decode
+ * @return {String} decoded string
+ * @private
+ */
+function decode(string) {
+ return decodeURIComponent(string.replace(/\+/g, ' '));
+}
+
+/**
+ * Gets the current URL hash.
+ *
+ * @method getHash
+ * @return {String}
+ * @private
+ */
+var getHash;
+
+if (Y.UA.gecko) {
+ // We branch at runtime for Gecko since window.location.hash in Gecko
+ // returns a decoded string, and we want all encoding untouched.
+ getHash = function () {
+ var matches = /#.*$/.exec(loc.href);
+ return matches && matches[0] ? matches[0] : '';
+ };
+} else {
+ getHash = function () {
+ return loc.hash;
+ };
+}
+
+/**
+ * Sets the browser's location hash to the specified string.
+ *
+ * @method setHash
+ * @param {String} hash
+ * @private
+ */
+function setHash(hash) {
+ loc.hash = hash;
+}
+
+// -- Private Event Handlers -----------------------------------------------
+
+/**
+ * Handles changes to the location hash and fires the history-lite:change
+ * event if necessary.
+ *
+ * @method handleHashChange
+ * @param {String} newHash new hash value
+ * @private
+ */
+function handleHashChange(newHash) {
+ var lastParsed = HistoryLite.parseQuery(lastHash),
+ newParsed = HistoryLite.parseQuery(newHash),
+ changedParams = {},
+ removedParams = {},
+ isChanged;
+
+ // Figure out what changed.
+ Y.each(newParsed, function (value, name) {
+ if (value !== lastParsed[name]) {
+ changedParams[name] = value;
+ isChanged = true;
+ }
+ });
+
+ // Figure out what was removed.
+ Y.each(lastParsed, function (value, name) {
+ if (!newParsed.hasOwnProperty(name)) {
+ removedParams[name] = value;
+ isChanged = true;
+ }
+ });
+
+ if (isChanged) {
+ HistoryLite.fire(EV_HISTORY_CHANGE, {
+ changed: changedParams,
+ newVal : newHash,
+ prevVal: lastHash,
+ removed: removedParams
+ });
+ }
+}
+
+/**
+ * Default handler for the history-lite:change event. Stores the new hash
+ * for later comparison and event triggering.
+ *
+ * @method defaultChangeHandler
+ * @param {EventFacade} e
+ * @private
+ */
+function defaultChangeHandler(e) {
+ lastHash = e.newVal;
+}
+
+Y.HistoryLite = HistoryLite = {
+ // -- Public Methods ---------------------------------------------------
+
+ /**
+ * Adds a history entry with changes to the specified parameters. Any
+ * parameters with a null
or undefined
value
+ * will be removed from the new history entry.
+ *
+ * @method add
+ * @param {String|Object} params query string, hash string, or object
+ * containing name/value parameter pairs
+ * @param {Boolean} silent if true, a history change event will
+ * not be fired for this change
+ */
+ add: function (params, silent) {
+ var newHash = createHash(Y.merge(HistoryLite.parseQuery(getHash()),
+ Y.Lang.isString(params) ? HistoryLite.parseQuery(params) : params));
+
+ if (silent) {
+ defaultChangeHandler({newVal: newHash});
+ }
+
+ setHash(newHash);
+ },
+
+ /**
+ * Gets the current value of the specified history parameter, or an
+ * object of name/value pairs for all current values if no parameter
+ * name is specified.
+ *
+ * @method get
+ * @param {String} name (optional) parameter name
+ * @return {Object|mixed}
+ */
+ get: function (name) {
+ var params = HistoryLite.parseQuery(getHash());
+ return name ? params[name] : params;
+ },
+
+ /**
+ * Parses a query string or hash string into an object of name/value
+ * parameter pairs.
+ *
+ * @method parseQuery
+ * @param {String} query query string or hash string
+ * @return {Object}
+ */
+ parseQuery: function (query) {
+ var matches = query.match(/([^\?#&]+)=([^&]+)/g) || [],
+ params = {},
+ i, len, param;
+
+ for (i = 0, len = matches.length; i < len; ++i) {
+ param = matches[i].split('=');
+ params[decode(param[0])] = decode(param[1]);
+ }
+
+ return params;
+ }
+};
+
+// Make HistoryLite an event target and publish the change event.
+Y.augment(HistoryLite, Y.EventTarget, true, null, {emitFacade: true});
+
+HistoryLite.publish(EV_HISTORY_CHANGE, {
+ broadcast: 2,
+ defaultFn: defaultChangeHandler
+});
+
+// Start watching for hash changes.
+lastHash = getHash();
+
+if (supportsHashChange) {
+ Y.Node.DOM_EVENTS.hashchange = true;
+
+ Y.on('hashchange', function () {
+ handleHashChange(getHash());
+ }, w);
+} else {
+ pollInterval = pollInterval || Y.later(50, HistoryLite, function () {
+ var hash = getHash();
+
+ if (hash !== lastHash) {
+ handleHashChange(hash);
+ }
+ }, null, true);
+}
+
+
+}, 'gallery-2009.11.09-19' ,{requires:['event-custom']});
diff --git a/build/gallery-history-lite/gallery-history-lite-min.js b/build/gallery-history-lite/gallery-history-lite-min.js
new file mode 100644
index 0000000000..ba8f7ffdfa
--- /dev/null
+++ b/build/gallery-history-lite/gallery-history-lite-min.js
@@ -0,0 +1 @@
+YUI.add("gallery-history-lite",function(E){var N=E.config.win,I=E.config.doc.documentMode,L=encodeURIComponent,K=N.location,F=N.onhashchange!==undefined&&(I===undefined||I>7),G,D,C,O="history-lite:change";function B(R){var Q=[];E.each(R,function(T,S){if(E.Lang.isValue(T)){Q.push(L(S)+"="+L(T));}});return Q.join("&");}function A(Q){return decodeURIComponent(Q.replace(/\+/g," "));}var H;if(E.UA.gecko){H=function(){var Q=/#.*$/.exec(K.href);return Q&&Q[0]?Q[0]:"";};}else{H=function(){return K.hash;};}function P(Q){K.hash=Q;}function M(U){var V=C.parseQuery(G),R=C.parseQuery(U),T={},S={},Q;E.each(R,function(X,W){if(X!==V[W]){T[W]=X;Q=true;}});E.each(V,function(X,W){if(!R.hasOwnProperty(W)){S[W]=X;Q=true;}});if(Q){C.fire(O,{changed:T,newVal:U,prevVal:G,removed:S});}}function J(Q){G=Q.newVal;}E.HistoryLite=C={add:function(S,Q){var R=B(E.merge(C.parseQuery(H()),E.Lang.isString(S)?C.parseQuery(S):S));if(Q){J({newVal:R});}P(R);},get:function(Q){var R=C.parseQuery(H());return Q?R[Q]:R;},parseQuery:function(T){var S=T.match(/([^\?#&]+)=([^&]+)/g)||[],V={},R,Q,U;for(R=0,Q=S.length;R7), + + lastHash, + pollInterval, + HistoryLite, + + /** + * Fired when the history state changes. + * + * @event history-lite:change + * @param {EventFacade} Event facade with the following additional + * properties: + *+ *
+ */ + EV_HISTORY_CHANGE = 'history-lite:change'; + +// -- Private Methods ------------------------------------------------------ + +/** + * Creates a hash string from the specified object of name/value parameter + * pairs. + * + * @method createHash + * @param {Object} params name/value parameter pairs + * @return {String} hash string + * @private + */ +function createHash(params) { + var hash = []; + + Y.each(params, function (value, name) { + if (Y.Lang.isValue(value)) { + hash.push(encode(name) + '=' + encode(value)); + } + }); + + return hash.join('&'); +} + +/** + * Wrapper around- changed
+ *- + * name:value pairs of history parameters that have been added or + * changed + *
+ *- removed
+ *- + * name:value pairs of history parameters that have been removed + * (values are the old values) + *
+ *decodeURIComponent()
that also converts + + * chars into spaces. + * + * @method decode + * @param {String} string string to decode + * @return {String} decoded string + * @private + */ +function decode(string) { + return decodeURIComponent(string.replace(/\+/g, ' ')); +} + +/** + * Gets the current URL hash. + * + * @method getHash + * @return {String} + * @private + */ +var getHash; + +if (Y.UA.gecko) { + // We branch at runtime for Gecko since window.location.hash in Gecko + // returns a decoded string, and we want all encoding untouched. + getHash = function () { + var matches = /#.*$/.exec(loc.href); + return matches && matches[0] ? matches[0] : ''; + }; +} else { + getHash = function () { + return loc.hash; + }; +} + +/** + * Sets the browser's location hash to the specified string. + * + * @method setHash + * @param {String} hash + * @private + */ +function setHash(hash) { + loc.hash = hash; +} + +// -- Private Event Handlers ----------------------------------------------- + +/** + * Handles changes to the location hash and fires the history-lite:change + * event if necessary. + * + * @method handleHashChange + * @param {String} newHash new hash value + * @private + */ +function handleHashChange(newHash) { + var lastParsed = HistoryLite.parseQuery(lastHash), + newParsed = HistoryLite.parseQuery(newHash), + changedParams = {}, + removedParams = {}, + isChanged; + + // Figure out what changed. + Y.each(newParsed, function (value, name) { + if (value !== lastParsed[name]) { + changedParams[name] = value; + isChanged = true; + } + }); + + // Figure out what was removed. + Y.each(lastParsed, function (value, name) { + if (!newParsed.hasOwnProperty(name)) { + removedParams[name] = value; + isChanged = true; + } + }); + + if (isChanged) { + HistoryLite.fire(EV_HISTORY_CHANGE, { + changed: changedParams, + newVal : newHash, + prevVal: lastHash, + removed: removedParams + }); + } +} + +/** + * Default handler for the history-lite:change event. Stores the new hash + * for later comparison and event triggering. + * + * @method defaultChangeHandler + * @param {EventFacade} e + * @private + */ +function defaultChangeHandler(e) { + lastHash = e.newVal; +} + +Y.HistoryLite = HistoryLite = { + // -- Public Methods --------------------------------------------------- + + /** + * Adds a history entry with changes to the specified parameters. Any + * parameters with anull
orundefined
value + * will be removed from the new history entry. + * + * @method add + * @param {String|Object} params query string, hash string, or object + * containing name/value parameter pairs + * @param {Boolean} silent if true, a history change event will + * not be fired for this change + */ + add: function (params, silent) { + var newHash = createHash(Y.merge(HistoryLite.parseQuery(getHash()), + Y.Lang.isString(params) ? HistoryLite.parseQuery(params) : params)); + + if (silent) { + defaultChangeHandler({newVal: newHash}); + } + + setHash(newHash); + }, + + /** + * Gets the current value of the specified history parameter, or an + * object of name/value pairs for all current values if no parameter + * name is specified. + * + * @method get + * @param {String} name (optional) parameter name + * @return {Object|mixed} + */ + get: function (name) { + var params = HistoryLite.parseQuery(getHash()); + return name ? params[name] : params; + }, + + /** + * Parses a query string or hash string into an object of name/value + * parameter pairs. + * + * @method parseQuery + * @param {String} query query string or hash string + * @return {Object} + */ + parseQuery: function (query) { + var matches = query.match(/([^\?#&]+)=([^&]+)/g) || [], + params = {}, + i, len, param; + + for (i = 0, len = matches.length; i < len; ++i) { + param = matches[i].split('='); + params[decode(param[0])] = decode(param[1]); + } + + return params; + } +}; + +// Make HistoryLite an event target and publish the change event. +Y.augment(HistoryLite, Y.EventTarget, true, null, {emitFacade: true}); + +HistoryLite.publish(EV_HISTORY_CHANGE, { + broadcast: 2, + defaultFn: defaultChangeHandler +}); + +// Start watching for hash changes. +lastHash = getHash(); + +if (supportsHashChange) { + Y.Node.DOM_EVENTS.hashchange = true; + + Y.on('hashchange', function () { + handleHashChange(getHash()); + }, w); +} else { + pollInterval = pollInterval || Y.later(50, HistoryLite, function () { + var hash = getHash(); + + if (hash !== lastHash) { + handleHashChange(hash); + } + }, null, true); +} + + +}, 'gallery-2009.11.09-19' ,{requires:['event-custom']}); diff --git a/build/gallery-io-poller/gallery-io-poller-debug.js b/build/gallery-io-poller/gallery-io-poller-debug.js new file mode 100644 index 0000000000..1587014d9e --- /dev/null +++ b/build/gallery-io-poller/gallery-io-poller-debug.js @@ -0,0 +1,397 @@ +YUI.add('gallery-io-poller', function(Y) { + + /** + * IO Poller - A utility to smartly poll (via XHR requests) a resource on the server. + * http://925html.com/code/smart-polling/ + * + * Oddnut Software + * Copyright (c) 2009 Eric Ferraiuolo - http://eric.ferraiuolo.name + * YUI BSD License - http://developer.yahoo.com/yui/license.html + */ + + /** + * Extends Y.io to add support for xhr-polling. + * + * @module poller + * @requires io-base, base + */ + + var Poller, + POLLER = 'poller', + + INTERVAL = 'interval', + URI = 'uri', + IO_CONFIG = 'ioConfig', + POLLING = 'polling', + + IF_NONE_MATCH = 'If-None-Match', + If_MODIFIED_SINCE = 'If-Modified-Since', + + E_MODIFIED = 'io:modified', + + isString = Y.Lang.isString, + isNumber = Y.Lang.isNumber, + isObject = Y.Lang.isObject; + + /** + * Create a polling task to continually check the server at the specified interval for updates of a resource at a URI. + * The poller will use conditional GET requests and notify the client via Callbacks and Events when the resource has changed. + * + * @class Poller + * @extends Base + * @param {Object} config Configuration Object + * @constructor + */ + Poller = function (config) { + + Poller.superclass.constructor.apply( this, arguments ); + }; + + Y.mix( Poller, { + + /** + * The identity of the component. + * + * @property Poller.NAME + * @type String + * @static + */ + NAME : POLLER, + + /** + * Static property used to define the default attribute configuration of + * the component. + * + * @property Poller.ATTRS + * @type Object + * @static + */ + ATTRS : { + + /** + * The time in milliseconds for which the component should send a request to the server. + * + * @attribute interval + * @type Number + */ + interval : { + validator : isNumber + }, + + /** + * The URI of the resource which to xhr-poll. + * + * @attribute uri + * @type String + * @writeOnce + */ + uri : { + validator : isString, + writeOnce : true + }, + + /** + * The configuration Y.io config. + * + * @attribute ioConfig + * @type Object + * @writeOnce + */ + ioConfig : { + validator : isObject, + writeOnce : true + }, + + /** + * A read-only attribute the client can check to see if the component is actively polling the server. + * + * @attribute polling + * @type Boolean + * @default false + * @readOnly + * @final + */ + polling : { + value : false, + readOnly : true + } + + } + + }); + + Y.extend( Poller, Y.Base, { + + /** + * Timer object to schedule next request to server. + * + * @property _timer + * @type Y.later + * @protected + */ + _timer : null, + + /** + * Time of the last request was sent. + * + * @property _txTime + * @type Number + * @protected + */ + _txTime : null, + + /** + * active IO transaction Object + * + * @property _activeTx + * @type Object + * @protected + */ + _activeTx : null, + + /** + * Last-Modified date of the resource that the server returned, used to determine if the resource has changed. + * + * @property _modifiedDate + * @type String + * @protected + */ + _modifiedDate : null, + + /** + * Etag of the resource returned by the server, used to determine if the resource has changed. + * + * @property _etag + * @type String + * @protected + */ + _etag : null, + + /** + * Construction of the component. + * + * @method initializer + * @param {Object} config Configuration Object + * @protected + */ + initializer : function (config) { + + /** + * Signals that the resource the component is pulling the server for has been modified. + * This is the interesting event for the client to subscribe to. + * The subscriber could, for example, update the UI in response to this event, poller:modified. + * + * @event io:modified + * @param {Number} txId Y.io Transaction ID + * @param {Object} r Y.io Response Object + * @param {MIXED} args Arguments passed to response handler + */ + + this._timer = null; + this._txTime = null; + this._activeTx = null; + this._modifiedDate = null; + this._etag = null; + }, + + /** + * Destruction of the component. Stops polling and cleans up. + * + * @method destructor + * @protected + */ + destructor : function () { + + this.stop(); + this._modifiedDate = null; + this._etag = null; + }, + + /** + * Starts the polling task. + * A request will be sent to the server right at the time of calling this method; + * and continued by sending subsequent requests at the set interval. + * To stop or pause polling call the stop method. + * + * @method start + */ + start : function () { + + if ( ! this.get(POLLING)) { + this._sendRequest(); + this._set(POLLING, true); + } + }, + + /** + * Stops the polling task. + * Start can be called to resume polling. + * + * @method stop + */ + stop : function () { + + if (this._activeTx) { + this._activeTx.abort(); + this._activeTx = null; + } + + if (this._timer) { + this._timer.cancel(); + this._timer = null; + } + + this._txTime = null; + + this._set(POLLING, false); + }, + + /** + * Sends the XHR request to the server at the given URI (resource). + * Method used internally to make the XHR requests. + * + * @method sendRequest + * @protected + */ + _sendRequest : function () { + + var ioConfig = this.get(IO_CONFIG), + headers = {}, + config; + + if (this._etag) { + headers[IF_NONE_MATCH] = this._etag; + } + if (this._modifiedDate) { + headers[If_MODIFIED_SINCE] = this._modifiedDate; + } + + config = Y.merge(ioConfig, { + + headers : Y.merge(ioConfig.headers, headers), + context : this, + on : Y.merge(ioConfig.on, { + + start : this._defStartHandler, + complete : this._defCompleteHandler, + success : this._defSuccessHandler, + modified : this._defModifiedHandler + + }) + + }); + + this._activeTx = Y.io(this.get(URI), config); + }, + + /** + * Sets the txTime and calls the config's on.start handler. + * + * @method _defStartHandler + * @param {Number} txId Y.io Transaction ID + * @param {MIXED} args Arguments passed to handlers + * @protected + */ + _defStartHandler : function (txId, args) { + + var config = this.get(IO_CONFIG); + + this._txTime = new Date().getTime(); + + if (config && config.on && config.on.start) { + config.on.start.apply(config.context || Y, arguments); + } + }, + + /** + * Schedules the next transaction and calls the config's on.complete handler. + * + * @method _defCompleteHandler + * @param {Number} txId Y.io Transaction ID + * @param {Object} r Y.io Response Object + * @param {MIXED} args Arguments passed to handlers + * @protected + */ + _defCompleteHandler : function (txId, r, args) { + + var config = this.get(IO_CONFIG), + deltaT = this._txTime ? (new Date()).getTime() - this._txTime : 0; + + this._timer = Y.later(Math.max(this.get(INTERVAL) - deltaT, 0), this, this._sendRequest); + + if (config && config.on && config.on.complete) { + config.on.complete.apply(config.context || Y, arguments); + } + }, + + /** + * Chains to the modified callback and calls the config's on.success handler. + * + * @method _defSuccessHandler + * @param {Number} txId Y.io Transaction ID + * @param {Object} r Y.io Response Object + * @param {MIXED} args Arguments passed to handlers + * @protected + */ + _defSuccessHandler : function (txId, r, args) { + + var config = this.get(IO_CONFIG); + + if (config && config.on && config.on.success) { + config.on.success.apply(config.context || Y, arguments); + } + + this._defModifiedHandler.apply(this, arguments); + }, + + /** + * Caches Etag and Last-Modified sent back from the server and calls the config's on.modified handler. + * + * @method _defModifiedHandler + * @param {Number} txId Y.io Transaction ID + * @param {Object} r Y.io Response Object + * @param {MIXED} args Arguments passed to handlers + * @protected + */ + _defModifiedHandler : function (txId, r, args) { + + var config = this.get(IO_CONFIG); + + this._etag = r.getResponseHeader('Etag'); + this._modifiedDate = r.getResponseHeader('Last-Modified'); + + Y.fire(E_MODIFIED, txId, r); + + if (config && config.on && config.on.modified) { + config.on.modified.apply(config.context || Y, arguments); + } + } + + }); + + /** + * Method for scheduling a XHR-polling task. Returns an instance of Poller + * + * @method Y.io.poll + * @param {Number} interval The time in milliseconds for which the component should send a request to the server. + * @param {Object} uri qualified path to transaction resource. + * @param {Object} config configuration object for the transaction(s); just like Y.io's config object, but with an on:modified callback/event. + * @return {Poller} an instance of Poller which has start/stop methods and a configurable interval + * @public + * @static + */ + Y.mix(Y.io, { + + poll: function (interval, uri, config) { + return new Poller({ + interval : interval, + uri : uri, + ioConfig : config + }); + } + + }, true); + + + +}, 'gallery-2009.11.19-20' ,{requires:['io-base', 'base-base']}); diff --git a/build/gallery-io-poller/gallery-io-poller-min.js b/build/gallery-io-poller/gallery-io-poller-min.js new file mode 100644 index 0000000000..f1ee9bb6e9 --- /dev/null +++ b/build/gallery-io-poller/gallery-io-poller-min.js @@ -0,0 +1 @@ +YUI.add("gallery-io-poller",function(B){var C,I="poller",D="interval",H="uri",J="ioConfig",K="polling",E="If-None-Match",G="If-Modified-Since",F="io:modified",A=B.Lang.isString,M=B.Lang.isNumber,L=B.Lang.isObject;C=function(N){C.superclass.constructor.apply(this,arguments);};B.mix(C,{NAME:I,ATTRS:{interval:{validator:M},uri:{validator:A,writeOnce:true},ioConfig:{validator:L,writeOnce:true},polling:{value:false,readOnly:true}}});B.extend(C,B.Base,{_timer:null,_txTime:null,_activeTx:null,_modifiedDate:null,_etag:null,initializer:function(N){this._timer=null;this._txTime=null;this._activeTx=null;this._modifiedDate=null;this._etag=null;},destructor:function(){this.stop();this._modifiedDate=null;this._etag=null;},start:function(){if(!this.get(K)){this._sendRequest();this._set(K,true);}},stop:function(){if(this._activeTx){this._activeTx.abort();this._activeTx=null;}if(this._timer){this._timer.cancel();this._timer=null;}this._txTime=null;this._set(K,false);},_sendRequest:function(){var N=this.get(J),P={},O;if(this._etag){P[E]=this._etag;}if(this._modifiedDate){P[G]=this._modifiedDate;}O=B.merge(N,{headers:B.merge(N.headers,P),context:this,on:B.merge(N.on,{start:this._defStartHandler,complete:this._defCompleteHandler,success:this._defSuccessHandler,modified:this._defModifiedHandler})});this._activeTx=B.io(this.get(H),O);},_defStartHandler:function(P,O){var N=this.get(J);this._txTime=new Date().getTime();if(N&&N.on&&N.on.start){N.on.start.apply(N.context||B,arguments);}},_defCompleteHandler:function(R,Q,O){var N=this.get(J),P=this._txTime?(new Date()).getTime()-this._txTime:0;this._timer=B.later(Math.max(this.get(D)-P,0),this,this._sendRequest);if(N&&N.on&&N.on.complete){N.on.complete.apply(N.context||B,arguments);}},_defSuccessHandler:function(Q,P,O){var N=this.get(J);if(N&&N.on&&N.on.success){N.on.success.apply(N.context||B,arguments);}this._defModifiedHandler.apply(this,arguments);},_defModifiedHandler:function(Q,P,O){var N=this.get(J);this._etag=P.getResponseHeader("Etag");this._modifiedDate=P.getResponseHeader("Last-Modified");B.fire(F,Q,P);if(N&&N.on&&N.on.modified){N.on.modified.apply(N.context||B,arguments);}}});B.mix(B.io,{poll:function(N,P,O){return new C({interval:N,uri:P,ioConfig:O});}},true);},"gallery-2009.11.19-20",{requires:["io-base","base-base"]}); \ No newline at end of file diff --git a/build/gallery-io-poller/gallery-io-poller.js b/build/gallery-io-poller/gallery-io-poller.js new file mode 100644 index 0000000000..1587014d9e --- /dev/null +++ b/build/gallery-io-poller/gallery-io-poller.js @@ -0,0 +1,397 @@ +YUI.add('gallery-io-poller', function(Y) { + + /** + * IO Poller - A utility to smartly poll (via XHR requests) a resource on the server. + * http://925html.com/code/smart-polling/ + * + * Oddnut Software + * Copyright (c) 2009 Eric Ferraiuolo - http://eric.ferraiuolo.name + * YUI BSD License - http://developer.yahoo.com/yui/license.html + */ + + /** + * Extends Y.io to add support for xhr-polling. + * + * @module poller + * @requires io-base, base + */ + + var Poller, + POLLER = 'poller', + + INTERVAL = 'interval', + URI = 'uri', + IO_CONFIG = 'ioConfig', + POLLING = 'polling', + + IF_NONE_MATCH = 'If-None-Match', + If_MODIFIED_SINCE = 'If-Modified-Since', + + E_MODIFIED = 'io:modified', + + isString = Y.Lang.isString, + isNumber = Y.Lang.isNumber, + isObject = Y.Lang.isObject; + + /** + * Create a polling task to continually check the server at the specified interval for updates of a resource at a URI. + * The poller will use conditional GET requests and notify the client via Callbacks and Events when the resource has changed. + * + * @class Poller + * @extends Base + * @param {Object} config Configuration Object + * @constructor + */ + Poller = function (config) { + + Poller.superclass.constructor.apply( this, arguments ); + }; + + Y.mix( Poller, { + + /** + * The identity of the component. + * + * @property Poller.NAME + * @type String + * @static + */ + NAME : POLLER, + + /** + * Static property used to define the default attribute configuration of + * the component. + * + * @property Poller.ATTRS + * @type Object + * @static + */ + ATTRS : { + + /** + * The time in milliseconds for which the component should send a request to the server. + * + * @attribute interval + * @type Number + */ + interval : { + validator : isNumber + }, + + /** + * The URI of the resource which to xhr-poll. + * + * @attribute uri + * @type String + * @writeOnce + */ + uri : { + validator : isString, + writeOnce : true + }, + + /** + * The configuration Y.io config. + * + * @attribute ioConfig + * @type Object + * @writeOnce + */ + ioConfig : { + validator : isObject, + writeOnce : true + }, + + /** + * A read-only attribute the client can check to see if the component is actively polling the server. + * + * @attribute polling + * @type Boolean + * @default false + * @readOnly + * @final + */ + polling : { + value : false, + readOnly : true + } + + } + + }); + + Y.extend( Poller, Y.Base, { + + /** + * Timer object to schedule next request to server. + * + * @property _timer + * @type Y.later + * @protected + */ + _timer : null, + + /** + * Time of the last request was sent. + * + * @property _txTime + * @type Number + * @protected + */ + _txTime : null, + + /** + * active IO transaction Object + * + * @property _activeTx + * @type Object + * @protected + */ + _activeTx : null, + + /** + * Last-Modified date of the resource that the server returned, used to determine if the resource has changed. + * + * @property _modifiedDate + * @type String + * @protected + */ + _modifiedDate : null, + + /** + * Etag of the resource returned by the server, used to determine if the resource has changed. + * + * @property _etag + * @type String + * @protected + */ + _etag : null, + + /** + * Construction of the component. + * + * @method initializer + * @param {Object} config Configuration Object + * @protected + */ + initializer : function (config) { + + /** + * Signals that the resource the component is pulling the server for has been modified. + * This is the interesting event for the client to subscribe to. + * The subscriber could, for example, update the UI in response to this event, poller:modified. + * + * @event io:modified + * @param {Number} txId Y.io Transaction ID + * @param {Object} r Y.io Response Object + * @param {MIXED} args Arguments passed to response handler + */ + + this._timer = null; + this._txTime = null; + this._activeTx = null; + this._modifiedDate = null; + this._etag = null; + }, + + /** + * Destruction of the component. Stops polling and cleans up. + * + * @method destructor + * @protected + */ + destructor : function () { + + this.stop(); + this._modifiedDate = null; + this._etag = null; + }, + + /** + * Starts the polling task. + * A request will be sent to the server right at the time of calling this method; + * and continued by sending subsequent requests at the set interval. + * To stop or pause polling call the stop method. + * + * @method start + */ + start : function () { + + if ( ! this.get(POLLING)) { + this._sendRequest(); + this._set(POLLING, true); + } + }, + + /** + * Stops the polling task. + * Start can be called to resume polling. + * + * @method stop + */ + stop : function () { + + if (this._activeTx) { + this._activeTx.abort(); + this._activeTx = null; + } + + if (this._timer) { + this._timer.cancel(); + this._timer = null; + } + + this._txTime = null; + + this._set(POLLING, false); + }, + + /** + * Sends the XHR request to the server at the given URI (resource). + * Method used internally to make the XHR requests. + * + * @method sendRequest + * @protected + */ + _sendRequest : function () { + + var ioConfig = this.get(IO_CONFIG), + headers = {}, + config; + + if (this._etag) { + headers[IF_NONE_MATCH] = this._etag; + } + if (this._modifiedDate) { + headers[If_MODIFIED_SINCE] = this._modifiedDate; + } + + config = Y.merge(ioConfig, { + + headers : Y.merge(ioConfig.headers, headers), + context : this, + on : Y.merge(ioConfig.on, { + + start : this._defStartHandler, + complete : this._defCompleteHandler, + success : this._defSuccessHandler, + modified : this._defModifiedHandler + + }) + + }); + + this._activeTx = Y.io(this.get(URI), config); + }, + + /** + * Sets the txTime and calls the config's on.start handler. + * + * @method _defStartHandler + * @param {Number} txId Y.io Transaction ID + * @param {MIXED} args Arguments passed to handlers + * @protected + */ + _defStartHandler : function (txId, args) { + + var config = this.get(IO_CONFIG); + + this._txTime = new Date().getTime(); + + if (config && config.on && config.on.start) { + config.on.start.apply(config.context || Y, arguments); + } + }, + + /** + * Schedules the next transaction and calls the config's on.complete handler. + * + * @method _defCompleteHandler + * @param {Number} txId Y.io Transaction ID + * @param {Object} r Y.io Response Object + * @param {MIXED} args Arguments passed to handlers + * @protected + */ + _defCompleteHandler : function (txId, r, args) { + + var config = this.get(IO_CONFIG), + deltaT = this._txTime ? (new Date()).getTime() - this._txTime : 0; + + this._timer = Y.later(Math.max(this.get(INTERVAL) - deltaT, 0), this, this._sendRequest); + + if (config && config.on && config.on.complete) { + config.on.complete.apply(config.context || Y, arguments); + } + }, + + /** + * Chains to the modified callback and calls the config's on.success handler. + * + * @method _defSuccessHandler + * @param {Number} txId Y.io Transaction ID + * @param {Object} r Y.io Response Object + * @param {MIXED} args Arguments passed to handlers + * @protected + */ + _defSuccessHandler : function (txId, r, args) { + + var config = this.get(IO_CONFIG); + + if (config && config.on && config.on.success) { + config.on.success.apply(config.context || Y, arguments); + } + + this._defModifiedHandler.apply(this, arguments); + }, + + /** + * Caches Etag and Last-Modified sent back from the server and calls the config's on.modified handler. + * + * @method _defModifiedHandler + * @param {Number} txId Y.io Transaction ID + * @param {Object} r Y.io Response Object + * @param {MIXED} args Arguments passed to handlers + * @protected + */ + _defModifiedHandler : function (txId, r, args) { + + var config = this.get(IO_CONFIG); + + this._etag = r.getResponseHeader('Etag'); + this._modifiedDate = r.getResponseHeader('Last-Modified'); + + Y.fire(E_MODIFIED, txId, r); + + if (config && config.on && config.on.modified) { + config.on.modified.apply(config.context || Y, arguments); + } + } + + }); + + /** + * Method for scheduling a XHR-polling task. Returns an instance of Poller + * + * @method Y.io.poll + * @param {Number} interval The time in milliseconds for which the component should send a request to the server. + * @param {Object} uri qualified path to transaction resource. + * @param {Object} config configuration object for the transaction(s); just like Y.io's config object, but with an on:modified callback/event. + * @return {Poller} an instance of Poller which has start/stop methods and a configurable interval + * @public + * @static + */ + Y.mix(Y.io, { + + poll: function (interval, uri, config) { + return new Poller({ + interval : interval, + uri : uri, + ioConfig : config + }); + } + + }, true); + + + +}, 'gallery-2009.11.19-20' ,{requires:['io-base', 'base-base']}); diff --git a/build/gallery-node-accordion/assets/gallery-node-accordion-core.css b/build/gallery-node-accordion/assets/gallery-node-accordion-core.css new file mode 100644 index 0000000000..564af43e02 --- /dev/null +++ b/build/gallery-node-accordion/assets/gallery-node-accordion-core.css @@ -0,0 +1,32 @@ +.yui-accordion { + position: relative; + zoom: 1; +} +.yui-accordion .yui-accordion-item { + display: block; +} +.yui-accordion .yui-accordion-item .yui-accordion-item-hd { +} +.yui-accordion .yui-accordion-item .yui-accordion-item-bd { + height: 0; + _height: 1px; + *height: 1px; + overflow: hidden; + zoom: 1; +} +.yui-accordion .yui-accordion-item-active .yui-accordion-item-bd { + height: auto; +} +.yui-accordion-hidden { + /* absolute position off-screen and box collapsing used to + avoid display:none, which causes issues for some content (firefox + restarts flash movies) */ + border:0; + height:0; + width:0; + padding:0; + position:absolute; + left:-999999px; + overflow:hidden; + visibility:hidden; +} \ No newline at end of file diff --git a/build/gallery-node-accordion/assets/skins/sam/gallery-node-accordion-skin.css b/build/gallery-node-accordion/assets/skins/sam/gallery-node-accordion-skin.css new file mode 100644 index 0000000000..76c93dde69 --- /dev/null +++ b/build/gallery-node-accordion/assets/skins/sam/gallery-node-accordion-skin.css @@ -0,0 +1,43 @@ +.yui-skin-sam .yui-accordion { + font-size: 93%; /* 12px */ + line-height: 1.5; /* 18px */ + *line-height: 1.45; /* For IE */ + border-top: solid 1px #808080; + border-left: solid 1px #808080; + border-right: solid 1px #808080; + background: #fff; + padding: 0; + text-align: left; +} +.yui-skin-sam .yui-accordion .yui-accordion-item { + display: block; + border-bottom: solid 1px #808080; +} +.yui-skin-sam .yui-accordion .yui-accordion-item .yui-accordion-item-hd { + 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; +} +.yui-skin-sam .yui-accordion .yui-accordion-item .yui-accordion-item-bd { + font-size: 100%; + margin: 0; + padding: 0; + display: block; +} +.yui-skin-sam .yui-accordion .first-of-type { + +} +.yui-skin-sam .yui-accordion .yui-accordion-item-hd a.yui-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; +} +.yui-skin-sam .yui-accordion .yui-accordion-item-active .yui-accordion-item-hd a.yui-accordion-item-trigger { + background: url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) no-repeat 110% -395px; +} \ No newline at end of file diff --git a/build/gallery-node-accordion/assets/skins/sam/gallery-node-accordion.css b/build/gallery-node-accordion/assets/skins/sam/gallery-node-accordion.css new file mode 100644 index 0000000000..d16bf3f72b --- /dev/null +++ b/build/gallery-node-accordion/assets/skins/sam/gallery-node-accordion.css @@ -0,0 +1 @@ +.yui-accordion{position:relative;zoom:1;}.yui-accordion .yui-accordion-item{display:block;}.yui-accordion .yui-accordion-item .yui-accordion-item-bd{height:0;_height:1px;*height:1px;overflow:hidden;zoom:1;}.yui-accordion .yui-accordion-item-active .yui-accordion-item-bd{height:auto;}.yui-accordion-hidden{border:0;height:0;width:0;padding:0;position:absolute;left:-999999px;overflow:hidden;visibility:hidden;}.yui-skin-sam .yui-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;}.yui-skin-sam .yui-accordion .yui-accordion-item{display:block;border-bottom:solid 1px #808080;}.yui-skin-sam .yui-accordion .yui-accordion-item .yui-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;}.yui-skin-sam .yui-accordion .yui-accordion-item .yui-accordion-item-bd{font-size:100%;margin:0;padding:0;display:block;}.yui-skin-sam .yui-accordion .yui-accordion-item-hd a.yui-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;}.yui-skin-sam .yui-accordion .yui-accordion-item-active .yui-accordion-item-hd a.yui-accordion-item-trigger{background:url(http://yui.yahooapis.com/3.0.0/build/assets/skins/sam/sprite.png) no-repeat 110% -395px;} diff --git a/build/gallery-node-accordion/gallery-node-accordion-debug.js b/build/gallery-node-accordion/gallery-node-accordion-debug.js new file mode 100644 index 0000000000..28fedb7c36 --- /dev/null +++ b/build/gallery-node-accordion/gallery-node-accordion-debug.js @@ -0,0 +1,597 @@ +YUI.add('gallery-node-accordion', function(Y) { + +/** +*The Accordion Node Plugin makes it easy to transform existing +* markup into an accordion element with expandable and collapsable elements, +* elements are easy to customize, and only require a small set of dependencies.
+* +* +*To use the Accordion Node Plugin, simply pass a reference to the plugin to a +* Node instance's
+* +*plug
method.+*
+* +*+* <script type="text/javascript">
+*
+*
+* // Call the "use" method, passing in "gallery-node-accordion". This will
+* // load the script and CSS for the Accordion Node Plugin and all of
+* // the required dependencies.
+*
+* YUI().use("gallery-node-accordion", function(Y) {
+*
+* // Use the "contentready" event to initialize the accordion when
+* // the element that represente the accordion
+* // (<div id="accordion-1">) is ready to be scripted.
+*
+* Y.on("contentready", function () {
+*
+* // The scope of the callback will be a Node instance
+* // representing the accordion (<div id="accordion-1">).
+* // Therefore, since "this" represents a Node instance, it
+* // is possible to just call "this.plug" passing in a
+* // reference to the Accordion Node Plugin.
+*
+* this.plug(Y.Plugin.NodeAccordion);
+*
+* }, "#accordion-1");
+*
+* });
+*
+* </script>
+*The Accordion Node Plugin has several configuration properties that can be +* set via an object literal that is passed as a second argument to a Node +* instance's
+* +*plug
method. +*+*
+* +* @module gallery-node-accordion +*/ + + +// Util shortcuts + +var UA = Y.UA, + 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, + // few more just in case... + //SELECTOR_ACCORDION = PERIOD + CLASS_ACCORDION, + //SELECTOR_ACCORDION_ITEM_TRIGGER = PERIOD + CLASS_ACCORDION_ITEM_TRIGGER, + + FC = '>.', + ITEM_QUERY = FC + CLASS_ACCORDION_ITEM, + ITEM_TRIGGER_QUERY = FC + CLASS_ACCORDION_ITEM + PERIOD + CLASS_ACCORDION_ITEM_TRIGGER + ',' + + FC + CLASS_ACCORDION_ITEM + FC + CLASS_ACCORDION_ITEM_HD + FC + CLASS_ACCORDION_ITEM_TRIGGER + ',' + + FC + CLASS_ACCORDION_ITEM + FC + CLASS_ACCORDION_ITEM_FT + FC + CLASS_ACCORDION_ITEM_TRIGGER, + // few more just in case... + //ITEM_HD_QUERY = FC+CLASS_ACCORDION_ITEM+FC+CLASS_ACCORDION_ITEM_HD, + //ITEM_BD_QUERY = FC+CLASS_ACCORDION_ITEM+FC+CLASS_ACCORDION_ITEM_BD, + //ITEM_FT_QUERY = FC+CLASS_ACCORDION_ITEM+FC+CLASS_ACCORDION_ITEM_FT, + + // Utility functions + /** + * The NodeAccordion class is a plugin for a Node instance. The class is used via + * the+* <script type="text/javascript">
+*
+*
+* // Call the "use" method, passing in "gallery-node-accordion". This will
+* // load the script and CSS for the Accordion Node Plugin and all of
+* // the required dependencies.
+*
+* YUI().use("gallery-node-accordion", function(Y) {
+*
+* // Use the "contentready" event to initialize the accordion when
+* // the element that represente the accordion
+* // (<div id="accordion-1">) is ready to be scripted.
+*
+* Y.on("contentready", function () {
+*
+* // The scope of the callback will be a Node instance
+* // representing the accordion (<div id="accordion-1">).
+* // Therefore, since "this" represents a Node instance, it
+* // is possible to just call "this.plug" passing in a
+* // reference to the Accordion Node Plugin.
+*
+* this.plug(Y.Plugin.NodeAccordion, { anim: true, effect: Y.Easing.backIn }); +*
+* }, "#accordion-1");
+*
+* });
+*
+* </script>
+*plug
method of Node and + * should not be instantiated directly. + * @namespace plugin + * @class NodeAccordion + */ + NodeAccordion = function () { + + NodeAccordion.superclass.constructor.apply(this, arguments); + + }; + +NodeAccordion.NAME = "NodeAccordion"; +NodeAccordion.NS = ACCORDION; + +NodeAccordion.ATTRS = { + /** + * Nodes representing the list of active items. + * + * @attribute activeItems + * @type Y.NodeList + */ + activeItems: { + readOnly: true, + getter: function (value) { + return this._root.all(FC+CLASS_ACTIVE); + } + }, + /** + * Nodes representing the list of items. + * + * @attribute items + * @type Y.NodeList + */ + items: { + readOnly: true, + getter: function (value) { + return this._root.all(ITEM_QUERY); + } + }, + + /** + * orientation defines if the accordion will use width or height to expand and collapse items. + * + * @attribute orientation + * @writeOnce + * @default height + * @type string + */ + orientation: { + value: HEIGHT, + writeOnce: true + }, + /** + * Boolean indicating that animation should include opacity to fade in/out the content of the item. + * + * @attribute fade + * @default false + * @type boolean + */ + fade: { + value: false + }, + /** + * Boolean indicating that Y.Anim should be used to expand and collapse items. + * It also supports a function with an specific effect. + *+ *
+ * + * @attribute anim + * @default false + * @type {boolean|function} + */ + anim: { + value: false, + validator : function (v) { + return !Y.Lang.isUndefined(Y.Anim); + } + }, + /** + * Boolean indicating that more than one item can be opened at the same time. + * + * @attribute multiple + * @default true + * @type boolean + */ + multiple: { + value: true + }, + /** + * Boolean indicating that one of the items should be open at any given time. + * + * @attribute persistent + * @default false + * @type boolean + */ + persistent: { + value: false + }, + /** + * Numeric value indicating the speed in mili-seconds for the animation process. + * Also support three predefined strings in lowercase: + *+ * <script type="text/javascript">
+ *
+ *
+ * // Call the "use" method, passing in "anim" and "gallery-node-accordion".
+ *
+ * YUI().use("anim", "gallery-node-accordion", function(Y) {
+ *
+ * Y.one("#myaccordion").plug(Y.Plugin.NodeAccordion, {
+ * anim: Y.Easing.backIn
+ * });
+ *
+ * </script>
+ *+ *
+ * + * @attribute speed + * @readOnly + * @default 0.4 + * @type numeric + */ + speed: { + value: 0.4, + validator : function (v) { + return (Y.Lang.isNumber(v) || (Y.Lang.isString(v) && wheels.hasOwnProperty(v))); + }, + setter : function (v) { + return (wheels.hasOwnProperty(v)?wheels[v]:v); + } + } + +}; + + +Y.extend(NodeAccordion, Y.Plugin.Base, { + + // Protected properties + + /** + * @property _root + * @description Node instance representing the root node in the accordion. + * @default null + * @protected + * @type Node + */ + _root: null, + + // Public methods + + initializer: function (config) { + var _root = this.get(HOST), + aHandlers = []; + if (_root) { + + this._root = _root; + + // 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 + aHandlers.push(_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)); + aHandlers = this._eventHandlers; + + _root.removeClass(CLASS_ACCORDION_HIDDEN); + } + }, + + destructor: function () { + var aHandlers = this._eventHandlers; + if (aHandlers) { + Y.Array.each(aHandlers, function (handle) { + handle.detach(); + }); + this._eventHandlers = null; + } + }, + + // 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(); + } + 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); + } + // 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); + } + } + }, + + /** + * @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))) { + // 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.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); + } + } + + }, + + // 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 ) { + var item = this._getItem(node); + if (item) { + Y.log(("Expanding an item: " + item), "info", "nodeAccordion"); + this._openItem (item); + } + return this; + }, + + /** + * @method collapseItem + * @description Collapse a certain item. + * @public + * @param {Node} node Node reference + * @return {object} Plugin reference for chaining + */ + collapseItem: function ( node ) { + var item = this._getItem(node); + if (item && item.hasClass(CLASS_ACTIVE) && (this.get(ATTR_MULTIPLE) || !this.get(ATTR_PERSISTENT))) { + Y.log(("Collapse an item: " + item), "info", "nodeAccordion"); + this._closeItem(item); + } + return this; + }, + + /** + * @method toggleItem + * @description toggle a certain item. + * @public + * @param {object} node Node reference + * @return {object} Plugin reference for chaining + */ + toggleItem: function ( node ) { + var item = this._getItem(node); + Y.log ('Looking for accordion item: ' + SELECTOR_ACCORDION_ITEM); + if (item) { + // if the item is already opened, and is multiple and not persistent + Y.log(("Toggling an item: " + item), "info", "nodeAccordion"); + ((item.hasClass(CLASS_ACTIVE) && (this.get(ATTR_MULTIPLE) || !this.get(ATTR_PERSISTENT)))?this._closeItem (item):this._openItem (item)); + } + return this; + } + +}); + +Y.namespace('Plugin'); + +Y.Plugin.NodeAccordion = NodeAccordion; + + +}, 'gallery-2009.10.27-23' ,{requires:['node-base', 'node-style', 'plugin', 'node-event-delegate', 'classnamemanager'], optional:['anim']}); diff --git a/build/gallery-node-accordion/gallery-node-accordion-min.js b/build/gallery-node-accordion/gallery-node-accordion-min.js new file mode 100644 index 0000000000..b6c8b159ff --- /dev/null +++ b/build/gallery-node-accordion/gallery-node-accordion-min.js @@ -0,0 +1 @@ +YUI.add("gallery-node-accordion",function(B){var S=B.UA,f=B.ClassNameManager.getClassName,X={},I={fast:0.1,slow:0.6,normal:0.4},J="accordion",E="item",a="scrollHeight",e="scrollWidth",F="width",V="height",i="px",G=".",O="host",j="orientation",D="fade",W="multiple",L="persistent",k="speed",c="anim",T="items",g=f(J),Z=f(J,"hidden"),H=f(J,E),M=f(J,E,"active"),A=f(J,E,"sliding"),d=f(J,E,"hd"),b=f(J,E,"bd"),K=f(J,E,"ft"),P=f(J,E,"trigger"),h=G+H,C=G+b,Q=">.",U=Q+H,R=Q+H+G+P+","+Q+H+Q+d+Q+P+","+Q+H+Q+K+Q+P,N=function(){N.superclass.constructor.apply(this,arguments);};N.NAME="NodeAccordion";N.NS=J;N.ATTRS={activeItems:{readOnly:true,getter:function(Y){return this._root.all(Q+M);}},items:{readOnly:true,getter:function(Y){return this._root.all(U);}},orientation:{value:V,writeOnce:true},fade:{value:false},anim:{value:false,validator:function(Y){return !B.Lang.isUndefined(B.Anim);}},multiple:{value:true},persistent:{value:false},speed:{value:0.4,validator:function(Y){return(B.Lang.isNumber(Y)||(B.Lang.isString(Y)&&I.hasOwnProperty(Y)));},setter:function(Y){return(I.hasOwnProperty(Y)?I[Y]:Y);}}};B.extend(N,B.Plugin.Base,{_root:null,initializer:function(l){var m=this.get(O),Y=[];if(m){this._root=m;this.get(T).each(function(n){if(n.hasClass(M)){this.expandItem(n);}else{this.collapseItem(n);}},this);Y.push(m.delegate("click",function(n){this.toggleItem(n.currentTarget);n.target.blur();n.halt();},R,this));Y=this._eventHandlers;m.removeClass(Z);}},destructor:function(){var Y=this._eventHandlers;if(Y){B.Array.each(Y,function(l){l.detach();});this._eventHandlers=null;}},_getItem:function(l){if(B.Lang.isNumber(l)){l=this.get(T).item(l);}var Y=function(m){return m.hasClass(H);};if(l&&!l.hasClass(H)){return l.ancestor(Y);}return l;},_animate:function(n,Y,l){var m=X[n];if((m)&&(m.get("running"))){m.stop();}if(B.Lang.isFunction(this.get(c))){Y.easing=this.get(c);}m=new B.Anim(Y);m.on("end",l,this);m.run();X[n]=m;return m;},_openItem:function(u){var p,Y,s,n,m,r=this.get(T),l=this.get(j),q={duration:this.get(k),to:{scroll:[]}},t;if(u&&r.size()&&!u.hasClass(M)&&(p=u.one(C))&&(Y=B.stamp(p))){if(!this.get(W)){t=this._root.one(Q+M);}q.to[l]=(l==F?p.get(e):p.get(a));q.node=p;u.addClass(A);s=function(){u.removeClass(A);u.addClass(M);};if(!this.get(c)){n=p.get(l);if(B.Lang.isObject(t)){n=t.get(l);t.addClass(A);}for(m=1;m<=n;m++){if(B.Lang.isObject(t)){t.setStyle(l,(n-m)+i);}p.setStyle(l,m+i);}if(B.Lang.isObject(t)){t.removeClass(A);t.removeClass(M);}s();}else{q.to.scroll=[0,0];if(this.get(D)){q.to.opacity=1;}if(B.Lang.isObject(t)){this._closeItem(t);}this._animate(Y,q,s);}}},_closeItem:function(t){var p,Y,s,n,m,r=this.get(T),l=this.get(j),q={duration:this.get(k),to:{scroll:[]}};if(t&&r.size()&&(p=t.one(C))&&(Y=B.stamp(p))){q.to[l]=(((l==V)&&S.ie&&(S.ie<7))?1:0);q.node=p;t.addClass(A);s=function(){t.removeClass(A);t.removeClass(M);};if(!this.get(c)){n=p.get(l);for(m=n;m>=q.to[l].to;m--){p.setStyle(l,m+i);}s();}else{q.to.scroll=(l==F?[p.get(e),0]:[0,p.get(a)]);if(this.get(D)){q.to.opacity=0;}this._animate(Y,q,s);}}},expandAllItems:function(){if(this.get(W)){this.get(T).each(function(Y){this.expandItem(Y);},this);}return this;},collapseAllItems:function(){if(this.get(W)||!this.get(L)){this.get(T).each(function(Y){this.collapseItem(Y);},this);}return this;},expandItem:function(l){var Y=this._getItem(l);if(Y){this._openItem(Y);}return this;},collapseItem:function(l){var Y=this._getItem(l);if(Y&&Y.hasClass(M)&&(this.get(W)||!this.get(L))){this._closeItem(Y);}return this;},toggleItem:function(l){var Y=this._getItem(l);if(Y){((Y.hasClass(M)&&(this.get(W)||!this.get(L)))?this._closeItem(Y):this._openItem(Y));}return this;}});B.namespace("Plugin");B.Plugin.NodeAccordion=N;},"gallery-2009.11.02-19",{requires:["node-base","node-style","plugin","node-event-delegate","classnamemanager"],optional:["anim"]}); \ No newline at end of file diff --git a/build/gallery-node-accordion/gallery-node-accordion.js b/build/gallery-node-accordion/gallery-node-accordion.js new file mode 100644 index 0000000000..7fe011ee11 --- /dev/null +++ b/build/gallery-node-accordion/gallery-node-accordion.js @@ -0,0 +1,589 @@ +YUI.add('gallery-node-accordion', function(Y) { + +/** +*- fast = 0.1
+ *- normal = 0.4
+ *- slow = 0.6
+ *The Accordion Node Plugin makes it easy to transform existing +* markup into an accordion element with expandable and collapsable elements, +* elements are easy to customize, and only require a small set of dependencies.
+* +* +*To use the Accordion Node Plugin, simply pass a reference to the plugin to a +* Node instance's
+* +*plug
method.+*
+* +*+* <script type="text/javascript">
+*
+*
+* // Call the "use" method, passing in "gallery-node-accordion". This will
+* // load the script and CSS for the Accordion Node Plugin and all of
+* // the required dependencies.
+*
+* YUI().use("gallery-node-accordion", function(Y) {
+*
+* // Use the "contentready" event to initialize the accordion when
+* // the element that represente the accordion
+* // (<div id="accordion-1">) is ready to be scripted.
+*
+* Y.on("contentready", function () {
+*
+* // The scope of the callback will be a Node instance
+* // representing the accordion (<div id="accordion-1">).
+* // Therefore, since "this" represents a Node instance, it
+* // is possible to just call "this.plug" passing in a
+* // reference to the Accordion Node Plugin.
+*
+* this.plug(Y.Plugin.NodeAccordion);
+*
+* }, "#accordion-1");
+*
+* });
+*
+* </script>
+*The Accordion Node Plugin has several configuration properties that can be +* set via an object literal that is passed as a second argument to a Node +* instance's
+* +*plug
method. +*+*
+* +* @module gallery-node-accordion +*/ + + +// Util shortcuts + +var UA = Y.UA, + 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, + // few more just in case... + //SELECTOR_ACCORDION = PERIOD + CLASS_ACCORDION, + //SELECTOR_ACCORDION_ITEM_TRIGGER = PERIOD + CLASS_ACCORDION_ITEM_TRIGGER, + + FC = '>.', + ITEM_QUERY = FC + CLASS_ACCORDION_ITEM, + ITEM_TRIGGER_QUERY = FC + CLASS_ACCORDION_ITEM + PERIOD + CLASS_ACCORDION_ITEM_TRIGGER + ',' + + FC + CLASS_ACCORDION_ITEM + FC + CLASS_ACCORDION_ITEM_HD + FC + CLASS_ACCORDION_ITEM_TRIGGER + ',' + + FC + CLASS_ACCORDION_ITEM + FC + CLASS_ACCORDION_ITEM_FT + FC + CLASS_ACCORDION_ITEM_TRIGGER, + // few more just in case... + //ITEM_HD_QUERY = FC+CLASS_ACCORDION_ITEM+FC+CLASS_ACCORDION_ITEM_HD, + //ITEM_BD_QUERY = FC+CLASS_ACCORDION_ITEM+FC+CLASS_ACCORDION_ITEM_BD, + //ITEM_FT_QUERY = FC+CLASS_ACCORDION_ITEM+FC+CLASS_ACCORDION_ITEM_FT, + + // Utility functions + /** + * The NodeAccordion class is a plugin for a Node instance. The class is used via + * the+* <script type="text/javascript">
+*
+*
+* // Call the "use" method, passing in "gallery-node-accordion". This will
+* // load the script and CSS for the Accordion Node Plugin and all of
+* // the required dependencies.
+*
+* YUI().use("gallery-node-accordion", function(Y) {
+*
+* // Use the "contentready" event to initialize the accordion when
+* // the element that represente the accordion
+* // (<div id="accordion-1">) is ready to be scripted.
+*
+* Y.on("contentready", function () {
+*
+* // The scope of the callback will be a Node instance
+* // representing the accordion (<div id="accordion-1">).
+* // Therefore, since "this" represents a Node instance, it
+* // is possible to just call "this.plug" passing in a
+* // reference to the Accordion Node Plugin.
+*
+* this.plug(Y.Plugin.NodeAccordion, { anim: true, effect: Y.Easing.backIn }); +*
+* }, "#accordion-1");
+*
+* });
+*
+* </script>
+*plug
method of Node and + * should not be instantiated directly. + * @namespace plugin + * @class NodeAccordion + */ + NodeAccordion = function () { + + NodeAccordion.superclass.constructor.apply(this, arguments); + + }; + +NodeAccordion.NAME = "NodeAccordion"; +NodeAccordion.NS = ACCORDION; + +NodeAccordion.ATTRS = { + /** + * Nodes representing the list of active items. + * + * @attribute activeItems + * @type Y.NodeList + */ + activeItems: { + readOnly: true, + getter: function (value) { + return this._root.all(FC+CLASS_ACTIVE); + } + }, + /** + * Nodes representing the list of items. + * + * @attribute items + * @type Y.NodeList + */ + items: { + readOnly: true, + getter: function (value) { + return this._root.all(ITEM_QUERY); + } + }, + + /** + * orientation defines if the accordion will use width or height to expand and collapse items. + * + * @attribute orientation + * @writeOnce + * @default height + * @type string + */ + orientation: { + value: HEIGHT, + writeOnce: true + }, + /** + * Boolean indicating that animation should include opacity to fade in/out the content of the item. + * + * @attribute fade + * @default false + * @type boolean + */ + fade: { + value: false + }, + /** + * Boolean indicating that Y.Anim should be used to expand and collapse items. + * It also supports a function with an specific effect. + *+ *
+ * + * @attribute anim + * @default false + * @type {boolean|function} + */ + anim: { + value: false, + validator : function (v) { + return !Y.Lang.isUndefined(Y.Anim); + } + }, + /** + * Boolean indicating that more than one item can be opened at the same time. + * + * @attribute multiple + * @default true + * @type boolean + */ + multiple: { + value: true + }, + /** + * Boolean indicating that one of the items should be open at any given time. + * + * @attribute persistent + * @default false + * @type boolean + */ + persistent: { + value: false + }, + /** + * Numeric value indicating the speed in mili-seconds for the animation process. + * Also support three predefined strings in lowercase: + *+ * <script type="text/javascript">
+ *
+ *
+ * // Call the "use" method, passing in "anim" and "gallery-node-accordion".
+ *
+ * YUI().use("anim", "gallery-node-accordion", function(Y) {
+ *
+ * Y.one("#myaccordion").plug(Y.Plugin.NodeAccordion, {
+ * anim: Y.Easing.backIn
+ * });
+ *
+ * </script>
+ *+ *
+ * + * @attribute speed + * @readOnly + * @default 0.4 + * @type numeric + */ + speed: { + value: 0.4, + validator : function (v) { + return (Y.Lang.isNumber(v) || (Y.Lang.isString(v) && wheels.hasOwnProperty(v))); + }, + setter : function (v) { + return (wheels.hasOwnProperty(v)?wheels[v]:v); + } + } + +}; + + +Y.extend(NodeAccordion, Y.Plugin.Base, { + + // Protected properties + + /** + * @property _root + * @description Node instance representing the root node in the accordion. + * @default null + * @protected + * @type Node + */ + _root: null, + + // Public methods + + initializer: function (config) { + var _root = this.get(HOST), + aHandlers = []; + if (_root) { + + this._root = _root; + + // 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 + aHandlers.push(_root.delegate('click', function(e) { + this.toggleItem(e.currentTarget); // probably is better to pass the ancestor for the item + e.target.blur(); + e.halt(); + }, ITEM_TRIGGER_QUERY, this)); + aHandlers = this._eventHandlers; + + _root.removeClass(CLASS_ACCORDION_HIDDEN); + } + }, + + destructor: function () { + var aHandlers = this._eventHandlers; + if (aHandlers) { + Y.Array.each(aHandlers, function (handle) { + handle.detach(); + }); + this._eventHandlers = null; + } + }, + + // 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]; + // if the animation is underway: we need to stop it... + if ((anim) && (anim.get ('running'))) { + anim.stop(); + } + 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); + } + // 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); + } + } + }, + + /** + * @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))) { + // 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.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); + } + } + + }, + + // Generic DOM Event handlers + /** + * @method expandAllItems + * @description Expanding all items. + * @public + * @return {object} Plugin reference for chaining + */ + expandAllItems: function () { + 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 () { + 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 ) { + var item = this._getItem(node); + if (item) { + this._openItem (item); + } + return this; + }, + + /** + * @method collapseItem + * @description Collapse a certain item. + * @public + * @param {Node} node Node reference + * @return {object} Plugin reference for chaining + */ + collapseItem: function ( node ) { + var item = this._getItem(node); + if (item && item.hasClass(CLASS_ACTIVE) && (this.get(ATTR_MULTIPLE) || !this.get(ATTR_PERSISTENT))) { + this._closeItem(item); + } + return this; + }, + + /** + * @method toggleItem + * @description toggle a certain item. + * @public + * @param {object} node Node reference + * @return {object} Plugin reference for chaining + */ + toggleItem: function ( node ) { + var item = this._getItem(node); + if (item) { + // if the item is already opened, and is multiple and not persistent + ((item.hasClass(CLASS_ACTIVE) && (this.get(ATTR_MULTIPLE) || !this.get(ATTR_PERSISTENT)))?this._closeItem (item):this._openItem (item)); + } + return this; + } + +}); + +Y.namespace('Plugin'); + +Y.Plugin.NodeAccordion = NodeAccordion; + + +}, 'gallery-2009.10.27-23' ,{requires:['node-base', 'node-style', 'plugin', 'node-event-delegate', 'classnamemanager'], optional:['anim']}); diff --git a/build/gallery-overlay-modal/gallery-overlay-modal-debug.js b/build/gallery-overlay-modal/gallery-overlay-modal-debug.js new file mode 100644 index 0000000000..ea1791f4fc --- /dev/null +++ b/build/gallery-overlay-modal/gallery-overlay-modal-debug.js @@ -0,0 +1,150 @@ +YUI.add('gallery-overlay-modal', function(Y) { + + /** + * Overlay Modal Plugin + * + * Oddnut Software + * Copyright (c) 2009 Eric Ferraiuolo - http://eric.ferraiuolo.name + * YUI BSD License - http://developer.yahoo.com/yui/license.html + */ + + var OverlayModal, + OVERLAY_MODAL = 'overlayModal', + + OVERLAY = 'overlay', + MODAL = 'modal', + MASK = 'mask', + + HOST = 'host', + BOUNDING_BOX = 'boundingBox', + + CHANGE = 'Change', + + getCN = Y.ClassNameManager.getClassName, + isBoolean = Y.Lang.isBoolean; + + // *** Constructor *** // + + OverlayModal = function (config) { + + OverlayModal.superclass.constructor.apply(this, arguments); + }; + + // *** Static *** // + + Y.mix(OverlayModal, { + + NAME : OVERLAY_MODAL, + + NS : MODAL, + + ATTRS : { + + mask : { + value : true, + validator : isBoolean + } + + }, + + CLASSES : { + + modal : getCN(OVERLAY, MODAL), + mask : getCN(OVERLAY, MASK) + + } + + }); + + // *** Prototype *** // + + Y.extend(OverlayModal, Y.Plugin.Base, { + + // *** Instance Members *** // + + _maskNode : null, + + // *** Lifecycle Methods *** // + + initializer : function (config) { + + this.doAfter('renderUI', this.renderUI); + this.doAfter('bindUI', this.bindUI); + this.doAfter('syncUI', this.syncUI); + + if (this.get(HOST).get('rendered')) { + this.renderUI(); + this.bindUI(); + this.syncUI(); + } + }, + + destructor : function () { + + if (this._maskNode) { + this._maskNode.remove(true); + } + + this.get(HOST).get(BOUNDING_BOX).removeClass(OverlayModal.CLASSES.modal); + }, + + renderUI : function () { + + this._maskNode = Y.Node.create(''); + this._maskNode.addClass(OverlayModal.CLASSES.mask); + this._maskNode.setStyles({ + position : 'fixed', + width : '100%', + height : '100%', + top : '0', + left : '0', + zIndex : '-1' + }); + + this.get(HOST).get(BOUNDING_BOX).addClass(OverlayModal.CLASSES.modal); + }, + + bindUI : function () { + + this.after(MASK+CHANGE, this._afterMaskChange); + }, + + syncUI : function () { + + this._uiSetMask(this.get(MASK)); + }, + + // *** Public Methods *** // + + mask : function () { + + this.set(MASK, true); + }, + + unmask : function () { + + this.set(MASK, false); + }, + + // *** Private Methods *** // + + _uiSetMask : function (mask) { + + if (mask) { + this.get(HOST).get(BOUNDING_BOX).append(this._maskNode); + } else { + this._maskNode.remove(); + } + }, + + _afterMaskChange : function (e) { + + this._uiSetMask(e.newVal); + } + + }); + + Y.namespace('Plugin').OverlayModal = OverlayModal; + + +}, 'gallery-2009.11.09-19' ,{requires:['overlay','plugin']}); diff --git a/build/gallery-overlay-modal/gallery-overlay-modal-min.js b/build/gallery-overlay-modal/gallery-overlay-modal-min.js new file mode 100644 index 0000000000..795437ac14 --- /dev/null +++ b/build/gallery-overlay-modal/gallery-overlay-modal-min.js @@ -0,0 +1 @@ +YUI.add("gallery-overlay-modal",function(B){var K,A="overlayModal",H="overlay",F="modal",J="mask",I="host",G="boundingBox",E="Change",D=B.ClassNameManager.getClassName,C=B.Lang.isBoolean;K=function(L){K.superclass.constructor.apply(this,arguments);};B.mix(K,{NAME:A,NS:F,ATTRS:{mask:{value:true,validator:C}},CLASSES:{modal:D(H,F),mask:D(H,J)}});B.extend(K,B.Plugin.Base,{_maskNode:null,initializer:function(L){this.doAfter("renderUI",this.renderUI);this.doAfter("bindUI",this.bindUI);this.doAfter("syncUI",this.syncUI);if(this.get(I).get("rendered")){this.renderUI();this.bindUI();this.syncUI();}},destructor:function(){if(this._maskNode){this._maskNode.remove(true);}this.get(I).get(G).removeClass(K.CLASSES.modal);},renderUI:function(){this._maskNode=B.Node.create("");this._maskNode.addClass(K.CLASSES.mask);this._maskNode.setStyles({position:"fixed",width:"100%",height:"100%",top:"0",left:"0",zIndex:"-1"});this.get(I).get(G).addClass(K.CLASSES.modal);},bindUI:function(){this.after(J+E,this._afterMaskChange);},syncUI:function(){this._uiSetMask(this.get(J));},mask:function(){this.set(J,true);},unmask:function(){this.set(J,false);},_uiSetMask:function(L){if(L){this.get(I).get(G).append(this._maskNode);}else{this._maskNode.remove();}},_afterMaskChange:function(L){this._uiSetMask(L.newVal);}});B.namespace("Plugin").OverlayModal=K;},"gallery-2009.11.09-19",{requires:["overlay","plugin"]}); \ No newline at end of file diff --git a/build/gallery-overlay-modal/gallery-overlay-modal.js b/build/gallery-overlay-modal/gallery-overlay-modal.js new file mode 100644 index 0000000000..ea1791f4fc --- /dev/null +++ b/build/gallery-overlay-modal/gallery-overlay-modal.js @@ -0,0 +1,150 @@ +YUI.add('gallery-overlay-modal', function(Y) { + + /** + * Overlay Modal Plugin + * + * Oddnut Software + * Copyright (c) 2009 Eric Ferraiuolo - http://eric.ferraiuolo.name + * YUI BSD License - http://developer.yahoo.com/yui/license.html + */ + + var OverlayModal, + OVERLAY_MODAL = 'overlayModal', + + OVERLAY = 'overlay', + MODAL = 'modal', + MASK = 'mask', + + HOST = 'host', + BOUNDING_BOX = 'boundingBox', + + CHANGE = 'Change', + + getCN = Y.ClassNameManager.getClassName, + isBoolean = Y.Lang.isBoolean; + + // *** Constructor *** // + + OverlayModal = function (config) { + + OverlayModal.superclass.constructor.apply(this, arguments); + }; + + // *** Static *** // + + Y.mix(OverlayModal, { + + NAME : OVERLAY_MODAL, + + NS : MODAL, + + ATTRS : { + + mask : { + value : true, + validator : isBoolean + } + + }, + + CLASSES : { + + modal : getCN(OVERLAY, MODAL), + mask : getCN(OVERLAY, MASK) + + } + + }); + + // *** Prototype *** // + + Y.extend(OverlayModal, Y.Plugin.Base, { + + // *** Instance Members *** // + + _maskNode : null, + + // *** Lifecycle Methods *** // + + initializer : function (config) { + + this.doAfter('renderUI', this.renderUI); + this.doAfter('bindUI', this.bindUI); + this.doAfter('syncUI', this.syncUI); + + if (this.get(HOST).get('rendered')) { + this.renderUI(); + this.bindUI(); + this.syncUI(); + } + }, + + destructor : function () { + + if (this._maskNode) { + this._maskNode.remove(true); + } + + this.get(HOST).get(BOUNDING_BOX).removeClass(OverlayModal.CLASSES.modal); + }, + + renderUI : function () { + + this._maskNode = Y.Node.create(''); + this._maskNode.addClass(OverlayModal.CLASSES.mask); + this._maskNode.setStyles({ + position : 'fixed', + width : '100%', + height : '100%', + top : '0', + left : '0', + zIndex : '-1' + }); + + this.get(HOST).get(BOUNDING_BOX).addClass(OverlayModal.CLASSES.modal); + }, + + bindUI : function () { + + this.after(MASK+CHANGE, this._afterMaskChange); + }, + + syncUI : function () { + + this._uiSetMask(this.get(MASK)); + }, + + // *** Public Methods *** // + + mask : function () { + + this.set(MASK, true); + }, + + unmask : function () { + + this.set(MASK, false); + }, + + // *** Private Methods *** // + + _uiSetMask : function (mask) { + + if (mask) { + this.get(HOST).get(BOUNDING_BOX).append(this._maskNode); + } else { + this._maskNode.remove(); + } + }, + + _afterMaskChange : function (e) { + + this._uiSetMask(e.newVal); + } + + }); + + Y.namespace('Plugin').OverlayModal = OverlayModal; + + +}, 'gallery-2009.11.09-19' ,{requires:['overlay','plugin']}); diff --git a/build/gallery-port/gallery-port-debug.js b/build/gallery-port/gallery-port-debug.js new file mode 100644 index 0000000000..8bb4623d2b --- /dev/null +++ b/build/gallery-port/gallery-port-debug.js @@ -0,0 +1,169 @@ +YUI.add('gallery-port', function(Y) { + + var YAHOO = { + lang: Y.Lang, + extend: Y.extend, + util: { + Dom: Y.DOM, + Event: { + on: Y.Event.nativeAdd, + getTarget: function(ev) { + return ev.target; + }, + stopEvent: function(ev) { + ev.halt(); + }, + stopPropagation: function(ev) { + ev.stopPropagation(); + }, + preventDefault: function(ev) { + ev.preventDefault(); + } + }, + Element: Y.Base + }, + getAttributes: function() { + } + }, + Port, PortBase; + // HACK + // So the build system doesn't remove this line.. + YAHOO['log'] = Y['log']; + + YAHOO.util.Dom.get = function(id) { + if (Y.Lang.isString(id)) { + id = '#' + id; + } + return Y.get(id); + }; + YAHOO.util.Dom.getChildren = function(el) { + return Y.Selector.query('> *', el); + }; + + Port = function(args) { + return YAHOO; + }; + + Y.Port = Port; + + PortBase = function(attrs) { + this._lazyAddAttrs = false; + this._portAttrs = attrs; + PortBase.superclass.constructor.apply(this, arguments); + }; + + PortBase.NAME = 'PortBase'; + + PortBase.ATTRS = { + node: { + setter: function(node) { + var n = Y.get(node); + return n.item(0); + } + }, + element: { + getter: function() { + return this.get('node'); + }, + setter: function(n) { + this.set('node', n); + return this.get('node'); + } + } + }; + + Y.extend(PortBase, Y.Base, { + DOM_EVENTS: { + 'click': true, + 'dblclick': true, + 'keydown': true, + 'keypress': true, + 'keyup': true, + 'mousedown': true, + 'mousemove': true, + 'mouseout': true, + 'mouseover': true, + 'mouseup': true, + 'focus': true, + 'blur': true, + 'submit': true, + 'change': true + }, + initializer: function() { + this.initAttributes(this._portAttrs); + }, + initAttributes: function() { + }, + setAttributeConfig: function(name, config) { + if (config.method) { + config.setter = config.method; + delete config.method; + } + this.addAttr(name, config); + }, + addListener: function(name, fn, ctxt, args) { + if (ctxt) { + if (args) { + fn = Y.rbind(fn, args, ctxt); + } else { + fn = Y.bind(fn, ctxt); + } + } + if (this.DOM_EVENTS[name]) { + this.get('node').on(name, fn); + } else { + this.on(name, fn); + } + //console.log('addListener: ', arguments); + }, + getElementsByClassName: function(className, tagName) { + var sel = tagName + ' .' + className; + //console.log('getElementsByClassName', this.constructor.NAME, arguments, sel); + return this.get('node').query(sel) || []; + }, + getElementsByTagName: function(tagName) { + var n = this.get('node'); + return ((n) ? n.query(tagName) : []); + }, + addClass: function(className) { + var n = this.get('node'); + if (!n) { return false; } + return n.addClass(className); + }, + removeClass: function(className) { + var n = this.get('node'); + if (!n) { return false; } + return n.removeClass(className); + }, + hasClass: function(className) { + var n = this.get('node'); + if (!n) { return false; } + return n.hasClass(className); + }, + appendTo: function(el) { + Y.get(el).appendChild(this.get('node')); + }, + fireEvent: function(type, args) { + if (args.target) { + delete args.target; + } + if (args.ev) { + args.ev = new Y.DOMEventFacade(args.ev); + } + var ret = false, e; + this.publish(type, { + defaultFn: function() { + ret = true; + } + }); + e = this.fire(type, args); + Y.log('fireEvent: ' + type); + return ret; + } + }); + + Y.PortBase = PortBase; + + + +}, 'gallery-2009.11.02-20' ,{requires:['base','node']}); diff --git a/build/gallery-port/gallery-port-min.js b/build/gallery-port/gallery-port-min.js new file mode 100644 index 0000000000..d0e903d36d --- /dev/null +++ b/build/gallery-port/gallery-port-min.js @@ -0,0 +1 @@ +YUI.add("gallery-port",function(C){var B={lang:C.Lang,extend:C.extend,util:{Dom:C.DOM,Event:{on:C.Event.nativeAdd,getTarget:function(E){return E.target;},stopEvent:function(E){E.halt();},stopPropagation:function(E){E.stopPropagation();},preventDefault:function(E){E.preventDefault();}},Element:C.Base},getAttributes:function(){}},D,A;B["log"]=C["log"];B.util.Dom.get=function(E){if(C.Lang.isString(E)){E="#"+E;}return C.get(E);};B.util.Dom.getChildren=function(E){return C.Selector.query("> *",E);};D=function(E){return B;};C.Port=D;A=function(E){this._lazyAddAttrs=false;this._portAttrs=E;A.superclass.constructor.apply(this,arguments);};A.NAME="PortBase";A.ATTRS={node:{setter:function(E){var F=C.get(E);return F.item(0);}},element:{getter:function(){return this.get("node");},setter:function(E){this.set("node",E);return this.get("node");}}};C.extend(A,C.Base,{DOM_EVENTS:{"click":true,"dblclick":true,"keydown":true,"keypress":true,"keyup":true,"mousedown":true,"mousemove":true,"mouseout":true,"mouseover":true,"mouseup":true,"focus":true,"blur":true,"submit":true,"change":true},initializer:function(){this.initAttributes(this._portAttrs);},initAttributes:function(){},setAttributeConfig:function(F,E){if(E.method){E.setter=E.method;delete E.method;}this.addAttr(F,E);},addListener:function(G,H,E,F){if(E){if(F){H=C.rbind(H,F,E);}else{H=C.bind(H,E);}}if(this.DOM_EVENTS[G]){this.get("node").on(G,H);}else{this.on(G,H);}},getElementsByClassName:function(F,E){var G=E+" ."+F;return this.get("node").query(G)||[];},getElementsByTagName:function(E){var F=this.get("node");return((F)?F.query(E):[]);},addClass:function(E){var F=this.get("node");if(!F){return false;}return F.addClass(E);},removeClass:function(E){var F=this.get("node");if(!F){return false;}return F.removeClass(E);},hasClass:function(E){var F=this.get("node");if(!F){return false;}return F.hasClass(E);},appendTo:function(E){C.get(E).appendChild(this.get("node"));},fireEvent:function(G,F){if(F.target){delete F.target;}if(F.ev){F.ev=new C.DOMEventFacade(F.ev);}var E=false,H;this.publish(G,{defaultFn:function(){E=true;}});H=this.fire(G,F);return E;}});C.PortBase=A;},"gallery-2009.11.02-20",{requires:["base","node"]}); \ No newline at end of file diff --git a/build/gallery-port/gallery-port.js b/build/gallery-port/gallery-port.js new file mode 100644 index 0000000000..a8b6095737 --- /dev/null +++ b/build/gallery-port/gallery-port.js @@ -0,0 +1,168 @@ +YUI.add('gallery-port', function(Y) { + + var YAHOO = { + lang: Y.Lang, + extend: Y.extend, + util: { + Dom: Y.DOM, + Event: { + on: Y.Event.nativeAdd, + getTarget: function(ev) { + return ev.target; + }, + stopEvent: function(ev) { + ev.halt(); + }, + stopPropagation: function(ev) { + ev.stopPropagation(); + }, + preventDefault: function(ev) { + ev.preventDefault(); + } + }, + Element: Y.Base + }, + getAttributes: function() { + } + }, + Port, PortBase; + // HACK + // So the build system doesn't remove this line.. + YAHOO['log'] = Y['log']; + + YAHOO.util.Dom.get = function(id) { + if (Y.Lang.isString(id)) { + id = '#' + id; + } + return Y.get(id); + }; + YAHOO.util.Dom.getChildren = function(el) { + return Y.Selector.query('> *', el); + }; + + Port = function(args) { + return YAHOO; + }; + + Y.Port = Port; + + PortBase = function(attrs) { + this._lazyAddAttrs = false; + this._portAttrs = attrs; + PortBase.superclass.constructor.apply(this, arguments); + }; + + PortBase.NAME = 'PortBase'; + + PortBase.ATTRS = { + node: { + setter: function(node) { + var n = Y.get(node); + return n.item(0); + } + }, + element: { + getter: function() { + return this.get('node'); + }, + setter: function(n) { + this.set('node', n); + return this.get('node'); + } + } + }; + + Y.extend(PortBase, Y.Base, { + DOM_EVENTS: { + 'click': true, + 'dblclick': true, + 'keydown': true, + 'keypress': true, + 'keyup': true, + 'mousedown': true, + 'mousemove': true, + 'mouseout': true, + 'mouseover': true, + 'mouseup': true, + 'focus': true, + 'blur': true, + 'submit': true, + 'change': true + }, + initializer: function() { + this.initAttributes(this._portAttrs); + }, + initAttributes: function() { + }, + setAttributeConfig: function(name, config) { + if (config.method) { + config.setter = config.method; + delete config.method; + } + this.addAttr(name, config); + }, + addListener: function(name, fn, ctxt, args) { + if (ctxt) { + if (args) { + fn = Y.rbind(fn, args, ctxt); + } else { + fn = Y.bind(fn, ctxt); + } + } + if (this.DOM_EVENTS[name]) { + this.get('node').on(name, fn); + } else { + this.on(name, fn); + } + //console.log('addListener: ', arguments); + }, + getElementsByClassName: function(className, tagName) { + var sel = tagName + ' .' + className; + //console.log('getElementsByClassName', this.constructor.NAME, arguments, sel); + return this.get('node').query(sel) || []; + }, + getElementsByTagName: function(tagName) { + var n = this.get('node'); + return ((n) ? n.query(tagName) : []); + }, + addClass: function(className) { + var n = this.get('node'); + if (!n) { return false; } + return n.addClass(className); + }, + removeClass: function(className) { + var n = this.get('node'); + if (!n) { return false; } + return n.removeClass(className); + }, + hasClass: function(className) { + var n = this.get('node'); + if (!n) { return false; } + return n.hasClass(className); + }, + appendTo: function(el) { + Y.get(el).appendChild(this.get('node')); + }, + fireEvent: function(type, args) { + if (args.target) { + delete args.target; + } + if (args.ev) { + args.ev = new Y.DOMEventFacade(args.ev); + } + var ret = false, e; + this.publish(type, { + defaultFn: function() { + ret = true; + } + }); + e = this.fire(type, args); + return ret; + } + }); + + Y.PortBase = PortBase; + + + +}, 'gallery-2009.11.02-20' ,{requires:['base','node']}); diff --git a/build/gallery-simple-editor/gallery-simple-editor-debug.js b/build/gallery-simple-editor/gallery-simple-editor-debug.js new file mode 100644 index 0000000000..315e22a460 --- /dev/null +++ b/build/gallery-simple-editor/gallery-simple-editor-debug.js @@ -0,0 +1,7045 @@ +YUI.add('gallery-simple-editor', function(Y) { + + + /** + * @description- fast = 0.1
+ *- normal = 0.4
+ *- slow = 0.6
+ *Creates a basic custom Toolbar Button. Primarily used with the Rich Text Editor's Toolbar
Provides a toolbar button based on the button and menu widgets, <select> elements are used in place of menu's.
+ * @class ToolbarButton + * @namespace YAHOO.widget + * @requires yahoo, dom, element, event + * @extends YAHOO.util.Element + * + * + * @constructor + * @param {String/HTMLElement} el The element to turn into a button. + * @param {Object} attrs Object liternal containing configuration parameters. + */ + + var ToolbarButton = function() { + Y.log('ToolbarButton Initalizing', 'info', 'ToolbarButton'); + ToolbarButton.superclass.constructor.apply(this, arguments); + }; + + ToolbarButton.NAME = 'ToolbarButton'; + + ToolbarButton.ATTRS = { + node: { + setter: function(node) { + var n = Y.get(node); + if (!n) { + Y.error('Invalid Node Given: ' + node); + } else { + n = n.item(0); + } + return n; + } + }, + id: { + }, + /** + * @attribute value + * @description The value of the button + * @type String + */ + value: { + }, + /** + * @attribute menu + * @description The menu attribute, see YAHOO.widget.Button + * @type Object + */ + menu: { + value: false + }, + /** + * @attribute type + * @description The type of button to create: push, menu, color, select, spin + * @type String + */ + type: { + value: 'push', + writeOnce: true + }, + /** + * @attribute disabled + * @description Set the button into a disabled state + * @type String + */ + disabled: { + value: false, + setter: function(disabled) { + if (disabled) { + this.get('node').addClass('yui-button-disabled'); + this.get('node').addClass('yui-' + this.get('type') + '-button-disabled'); + } else { + this.get('node').removeClass('yui-button-disabled'); + this.get('node').removeClass('yui-' + this.get('type') + '-button-disabled'); + } + //console.log(this.get('node'), ': ', disabled); + if (this.get('type') == 'select') { + this.get('node').set('disabled', disabled); + } + } + }, + /** + * @attribute label + * @description The text label for the button + * @type String + */ + label: { + value: 'LABEL', + setter: function(label) { + if (this.get('type') == 'push') { + this.get('node').query('a').set('innerHTML', label); + } + } + }, + /** + * @attribute title + * @description The title of the button + * @type String + */ + title: { + value: 'TITLE', + setter: function(title) { + this.get('node').set('title', title); + } + }, + + /** + * @config container + * @description The container that the button is rendered to, handled by Toolbar + * @type String + */ + container: { + value: null, + writeOnce: true, + setter: function(node) { + var n = Y.get(node); + if (!n) { + Y.error('Invalid Node Given: ' + node); + } else { + n = n.item(0); + } + return n; + } + } + }; + + Y.extend(ToolbarButton, Y.Base, { + /** + * @property buttonType + * @private + * @description Tells if the Button is a Rich Button or a Simple Button + */ + buttonType: 'normal', + /** + * @method _handleMouseOver + * @private + * @description Adds classes to the button elements on mouseover (hover) + */ + _handleMouseOver: function() { + if (!this.get('disabled')) { + this.get('node').addClass('yui-button-hover'); + this.get('node').addClass('yui-' + this.get('type') + '-button-hover'); + } + }, + /** + * @method _handleMouseOut + * @private + * @description Removes classes from the button elements on mouseout (hover) + */ + _handleMouseOut: function() { + this.get('node').removeClass('yui-button-hover'); + this.get('node').removeClass('yui-' + this.get('type') + '-button-hover'); + }, + /** + * @method checkValue + * @param {String} value The value of the option that we want to mark as selected + * @description Select an option by value + */ + checkValue: function(value) { + if (this.get('type') == 'select') { + var opt = this.get('node').get('options'); + opt.each(function(n, k) { + if (n.get('value') == value) { + this.get('node').set('selectedIndex', k); + } + }, this); + } + }, + /** + * @method initializer + * @description The ToolbarButton class's initialization method + */ + initializer: function() { + var id, i, el, menu, opt, html; + switch (this.get('type')) { + case 'select': + case 'menu': + el = Y.Node.create(''); + menu = this.get('menu'); + + for (i = 0; i < menu.length; i++) { + opt = Y.Node.create(''); + el.appendChild(opt); + if (menu[i].checked) { + opt.set('selected', true); + } + } + el.on('change', Y.bind(this._handleSelect, this)); + id = Y.stamp(el); + el.set('id', id); + this.set('node', el); + break; + default: + html = ' '; + this.set('node', Y.Node.create(html)); + this.get('node').on('mouseover', Y.bind(this._handleMouseOver, this)); + this.get('node').on('mouseout', Y.bind(this._handleMouseOut, this)); + break; + } + id = Y.stamp(this.get('node')); + this.set('id', id); + this.get('node').set('id', id); + this.set('title', this.get('title')); + this.set('label', this.get('label')); + this.set('disabled', this.get('disabled')); + this.get('container').appendChild(this.get('node')); + + this.get('node').on('click', Y.bind(function(e) { + e.halt(); + }, this)); + }, + /** + * @private + * @method _handleSelect + * @description The event fired when a change event gets fired on a select element + * @param {Event} ev The change event. + */ + _handleSelect: function(e) { + this.fire('change', {type: 'change', value: e.target.get('value'), target: this.get('node') }); + }, + /** + * @method getMenu + * @description A stub function to mimic YAHOO.widget.Button's getMenu method + */ + getMenu: function() { + return this.get('menu'); + }, + destructor: function() { + }, + /** + * @method toString + * @description Returns a string representing the toolbar. + * @return {String} + */ + toString: function() { + return 'Toolbar.Button (' + this.get('node').get('id') + ')'; + } + + }); + + Y.namespace('Toolbar'); + Y.Toolbar.Button = ToolbarButton; + + /* + var Lang = Y.Lang, + Dom = Y.DOM, + Event = { + on: Y.Event.nativeAdd, + getTarget: function(ev) { + return ev.target; + }, + stopEvent: function(ev) { + ev.halt(); + } + }, + YAHOO = { + log: console.log, + lang: Lang, + util: { + Dom: Dom, + Event: Event + } + }; + */ + + var getButton = function(id) { + var button = id; + if (Y.Lang.isString(id)) { + button = this.getButtonById(id); + } + if (Y.Lang.isNumber(id)) { + button = this.getButtonByIndex(id); + } + if (id instanceof Y.Toolbar.Button) { + button = id; + } else { + button = this.getButtonByValue(id); + } + return button; + }; + + /** + * Provides a rich toolbar widget based on the button and menu widgets + * @constructor + * @class Toolbar + * @extends YAHOO.util.Element + * @param {String/HTMLElement} el The element to turn into a toolbar. + * @param {Object} attrs Object liternal containing configuration parameters. + */ + var Toolbar = function() { + + this._configuredButtons = []; + + Toolbar.superclass.constructor.apply(this, arguments); + + }; + + Toolbar.NAME = 'Toolbar'; + + Toolbar.ATTRS = { + node: { + setter: function(node) { + var n = Y.get(node); + if (!n) { + Y.error('Invalid Node Given: ' + node); + } else { + n = n.item(0); + } + return n; + } + }, + /** + * @attribute buttonType + * @description The buttonType to use (advanced or basic) + * @type String + */ + buttonType: { + value: 'basic', + writeOnce: true, + validator: function(type) { + switch (type) { + case 'advanced': + case 'basic': + return type; + } + return 'basic'; + }, + setter: function(type) { + this.buttonType = Y.Toolbar.Button; + } + }, + /** + * @attribute buttons + * @description Object specifying the buttons to include in the toolbar + * Example: + *+ * @type Array + */ + + buttons: { + value: [] + }, + /** + * @config cont + * @description The container for the toolbar. + * @type HTMLElement + */ + cont: { + value: null + }, + id: { + value: null + }, + /** + * @attribute grouplabels + * @description Boolean indicating if the toolbar should show the group label's text string. + * @default true + * @type Boolean + */ + grouplabels: { + value: true, + setter: function(grouplabels) { + if (grouplabels) { + this.get('cont').removeClass(this.CLASS_PREFIX + '-nogrouplabels'); + } else { + this.get('cont').addClass(this.CLASS_PREFIX + '-nogrouplabels'); + } + } + }, + + /** + * @attribute titlebar + * @description Boolean indicating if the toolbar should have a titlebar. If + * passed a string, it will use that as the titlebar text + * @default false + * @type Boolean or String + */ + titlebar: { + value: false + }, + + /** + * @attribute collapse + * @description Boolean indicating if the the titlebar should have a collapse button. + * The collapse button will not remove the toolbar, it will minimize it to the titlebar + * @default false + * @type Boolean + */ + collapse: { + value: false + } + + }; + + Y.extend(Toolbar, Y.Base, { + fireEvent: function(type, args) { + if (args.target) { + delete args.target; + } + this.fire(type, args); + }, + _handleCollapse: function() { + var collapse = this.get('collapse'); + + if (this._titlebar) { + var collapseEl = null; + var el = this._titlebar.query('span.collapse'); + if (collapse) { + if (el) { + //There is already a collapse button + return true; + } + collapseEl = Y.Node.create('X'); + this._titlebar.appendChild(collapseEl); + collapseEl.on('click', Y.bind(function() { + if (this.get('cont').get('parentNode').hasClass('yui-toolbar-container-collapsed')) { + this.collapse(false); //Expand Toolbar + } else { + this.collapse(); //Collapse Toolbar + } + }, this)); + } else { + collapseEl = this._titlebar.query('span.collapse'); + if (collapseEl) { + if (this.get('cont').get('parentNode').hasClass('yui-toolbar-container-collapsed')) { + //We are closed, reopen the titlebar.. + this.collapse(false); //Expand Toolbar + } + collapseEl.get('parentNode').removeChild(collapseEl); + } + } + } + }, + _renderTitle: function() { + var titlebar = this.get('titlebar'); + if (titlebar) { + if (this._titlebar && this._titlebar.get('parentNode')) { + this._titlebar.get('parentNode').removeChild(this._titlebar); + } + this._titlebar = Y.Node.create(''); + this._titlebar.on('focus', Y.bind(this._handleFocus, this)); + + if (Y.Lang.isString(titlebar)) { + var h2 = Y.Node.create('
+ * { + * { id: 'b3', type: 'button', label: 'Underline', value: 'underline' }, + * { type: 'separator' }, + * { id: 'b4', type: 'menu', label: 'Align', value: 'align', + * menu: [ + * { text: "Left", value: 'alignleft' }, + * { text: "Center", value: 'aligncenter' }, + * { text: "Right", value: 'alignright' } + * ] + * } + * } + *' + titlebar + '
'); + this._titlebar.appendChild(h2); + h2.get('firstChild').on('click', function(ev) { + ev.halt(); + }); + /* + Event.on([h2, h2.firstChild], 'focus', function() { + this._handleFocus(); + }, this, true); + */ + } + if (this.get('node').get('firstChild')) { + this.get('node').insertBefore(this._titlebar, this.get('node').get('firstChild')); + } else { + this.get('node').appendChild(this._titlebar); + } + if (this.get('collapse')) { + this.set('collapse', true); + } + } else if (this._titlebar) { + if (this._titlebar && this._titlebar.get('parentNode')) { + this._titlebar.get('parentNode').removeChild(this._titlebar); + } + } + }, + /** + * @protected + * @property _configuredButtons + * @type Array + */ + _configuredButtons: null, + /** + * @method _addMenuClasses + * @private + * @description This method is called from Menu's renderEvent to add a few more classes to the menu items + * @param {String} ev The event that fired. + * @param {Array} na Array of event information. + * @param {Object} o Button config object. + */ + _addMenuClasses: function(ev, na, o) { + Dom.addClass(this.element, 'yui-toolbar-' + o.get('value') + '-menu'); + if (Dom.hasClass(o._button.parentNode.parentNode, 'yui-toolbar-select')) { + Dom.addClass(this.element, 'yui-toolbar-select-menu'); + } + var items = this.getItems(); + for (var i = 0; i < items.length; i++) { + Dom.addClass(items[i].element, 'yui-toolbar-' + o.get('value') + '-' + ((items[i].value) ? items[i].value.replace(/ /g, '-').toLowerCase() : items[i]._oText.nodeValue.replace(/ /g, '-').toLowerCase())); + Dom.addClass(items[i].element, 'yui-toolbar-' + o.get('value') + '-' + ((items[i].value) ? items[i].value.replace(/ /g, '-') : items[i]._oText.nodeValue.replace(/ /g, '-'))); + } + }, + /** + * @property buttonType + * @description The default button to use + * @type Object + */ + buttonType: Y.Toolbar.Button, + /** + * @property dd + * @description The DragDrop instance associated with the Toolbar + * @type Object + */ + dd: null, + /** + * @property _colorData + * @description Object reference containing colors hex and text values. + * @type Object + */ + _colorData: { +/* {{{ _colorData */ + '#111111': 'Obsidian', + '#2D2D2D': 'Dark Gray', + '#434343': 'Shale', + '#5B5B5B': 'Flint', + '#737373': 'Gray', + '#8B8B8B': 'Concrete', + '#A2A2A2': 'Gray', + '#B9B9B9': 'Titanium', + '#000000': 'Black', + '#D0D0D0': 'Light Gray', + '#E6E6E6': 'Silver', + '#FFFFFF': 'White', + '#BFBF00': 'Pumpkin', + '#FFFF00': 'Yellow', + '#FFFF40': 'Banana', + '#FFFF80': 'Pale Yellow', + '#FFFFBF': 'Butter', + '#525330': 'Raw Siena', + '#898A49': 'Mildew', + '#AEA945': 'Olive', + '#7F7F00': 'Paprika', + '#C3BE71': 'Earth', + '#E0DCAA': 'Khaki', + '#FCFAE1': 'Cream', + '#60BF00': 'Cactus', + '#80FF00': 'Chartreuse', + '#A0FF40': 'Green', + '#C0FF80': 'Pale Lime', + '#DFFFBF': 'Light Mint', + '#3B5738': 'Green', + '#668F5A': 'Lime Gray', + '#7F9757': 'Yellow', + '#407F00': 'Clover', + '#8A9B55': 'Pistachio', + '#B7C296': 'Light Jade', + '#E6EBD5': 'Breakwater', + '#00BF00': 'Spring Frost', + '#00FF80': 'Pastel Green', + '#40FFA0': 'Light Emerald', + '#80FFC0': 'Sea Foam', + '#BFFFDF': 'Sea Mist', + '#033D21': 'Dark Forrest', + '#438059': 'Moss', + '#7FA37C': 'Medium Green', + '#007F40': 'Pine', + '#8DAE94': 'Yellow Gray Green', + '#ACC6B5': 'Aqua Lung', + '#DDEBE2': 'Sea Vapor', + '#00BFBF': 'Fog', + '#00FFFF': 'Cyan', + '#40FFFF': 'Turquoise Blue', + '#80FFFF': 'Light Aqua', + '#BFFFFF': 'Pale Cyan', + '#033D3D': 'Dark Teal', + '#347D7E': 'Gray Turquoise', + '#609A9F': 'Green Blue', + '#007F7F': 'Seaweed', + '#96BDC4': 'Green Gray', + '#B5D1D7': 'Soapstone', + '#E2F1F4': 'Light Turquoise', + '#0060BF': 'Summer Sky', + '#0080FF': 'Sky Blue', + '#40A0FF': 'Electric Blue', + '#80C0FF': 'Light Azure', + '#BFDFFF': 'Ice Blue', + '#1B2C48': 'Navy', + '#385376': 'Biscay', + '#57708F': 'Dusty Blue', + '#00407F': 'Sea Blue', + '#7792AC': 'Sky Blue Gray', + '#A8BED1': 'Morning Sky', + '#DEEBF6': 'Vapor', + '#0000BF': 'Deep Blue', + '#0000FF': 'Blue', + '#4040FF': 'Cerulean Blue', + '#8080FF': 'Evening Blue', + '#BFBFFF': 'Light Blue', + '#212143': 'Deep Indigo', + '#373E68': 'Sea Blue', + '#444F75': 'Night Blue', + '#00007F': 'Indigo Blue', + '#585E82': 'Dockside', + '#8687A4': 'Blue Gray', + '#D2D1E1': 'Light Blue Gray', + '#6000BF': 'Neon Violet', + '#8000FF': 'Blue Violet', + '#A040FF': 'Violet Purple', + '#C080FF': 'Violet Dusk', + '#DFBFFF': 'Pale Lavender', + '#302449': 'Cool Shale', + '#54466F': 'Dark Indigo', + '#655A7F': 'Dark Violet', + '#40007F': 'Violet', + '#726284': 'Smoky Violet', + '#9E8FA9': 'Slate Gray', + '#DCD1DF': 'Violet White', + '#BF00BF': 'Royal Violet', + '#FF00FF': 'Fuchsia', + '#FF40FF': 'Magenta', + '#FF80FF': 'Orchid', + '#FFBFFF': 'Pale Magenta', + '#4A234A': 'Dark Purple', + '#794A72': 'Medium Purple', + '#936386': 'Cool Granite', + '#7F007F': 'Purple', + '#9D7292': 'Purple Moon', + '#C0A0B6': 'Pale Purple', + '#ECDAE5': 'Pink Cloud', + '#BF005F': 'Hot Pink', + '#FF007F': 'Deep Pink', + '#FF409F': 'Grape', + '#FF80BF': 'Electric Pink', + '#FFBFDF': 'Pink', + '#451528': 'Purple Red', + '#823857': 'Purple Dino', + '#A94A76': 'Purple Gray', + '#7F003F': 'Rose', + '#BC6F95': 'Antique Mauve', + '#D8A5BB': 'Cool Marble', + '#F7DDE9': 'Pink Granite', + '#C00000': 'Apple', + '#FF0000': 'Fire Truck', + '#FF4040': 'Pale Red', + '#FF8080': 'Salmon', + '#FFC0C0': 'Warm Pink', + '#441415': 'Sepia', + '#82393C': 'Rust', + '#AA4D4E': 'Brick', + '#800000': 'Brick Red', + '#BC6E6E': 'Mauve', + '#D8A3A4': 'Shrimp Pink', + '#F8DDDD': 'Shell Pink', + '#BF5F00': 'Dark Orange', + '#FF7F00': 'Orange', + '#FF9F40': 'Grapefruit', + '#FFBF80': 'Canteloupe', + '#FFDFBF': 'Wax', + '#482C1B': 'Dark Brick', + '#855A40': 'Dirt', + '#B27C51': 'Tan', + '#7F3F00': 'Nutmeg', + '#C49B71': 'Mustard', + '#E1C4A8': 'Pale Tan', + '#FDEEE0': 'Marble' +/* }}} */ + }, + /** + * @property _colorPicker + * @description The HTML Element containing the colorPicker + * @type HTMLElement + */ + _colorPicker: null, + /** + * @property STR_COLLAPSE + * @description String for Toolbar Collapse Button + * @type String + */ + STR_COLLAPSE: 'Collapse Toolbar', + /** + * @property STR_EXPAND + * @description String for Toolbar Collapse Button - Expand + * @type String + */ + STR_EXPAND: 'Expand Toolbar', + /** + * @property STR_SPIN_LABEL + * @description String for spinbutton dynamic label. Note the {VALUE} will be replaced with YAHOO.lang.substitute + * @type String + */ + STR_SPIN_LABEL: 'Spin Button with value {VALUE}. Use Control Shift Up Arrow and Control Shift Down arrow keys to increase or decrease the value.', + /** + * @property STR_SPIN_UP + * @description String for spinbutton up + * @type String + */ + STR_SPIN_UP: 'Click to increase the value of this input', + /** + * @property STR_SPIN_DOWN + * @description String for spinbutton down + * @type String + */ + STR_SPIN_DOWN: 'Click to decrease the value of this input', + /** + * @property _titlebar + * @description Object reference to the titlebar + * @type HTMLElement + */ + _titlebar: null, + /** + * @property browser + * @description Standard browser detection + * @type Object + */ + browser: Y.UA, + /** + * @protected + * @property _buttonList + * @description Internal property list of current buttons in the toolbar + * @type Array + */ + _buttonList: null, + /** + * @protected + * @property _buttonGroupList + * @description Internal property list of current button groups in the toolbar + * @type Array + */ + _buttonGroupList: null, + /** + * @protected + * @property _sep + * @description Internal reference to the separator HTML Element for cloning + * @type HTMLElement + */ + _sep: null, + /** + * @protected + * @property _sepCount + * @description Internal refernce for counting separators, so we can give them a useful class name for styling + * @type Number + */ + _sepCount: null, + /** + * @protected + * @property draghandle + * @type HTMLElement + */ + _dragHandle: null, + /** + * @protected + * @property _toolbarConfigs + * @type Object + */ + _toolbarConfigs: { + renderer: true + }, + /** + * @protected + * @property CLASS_CONTAINER + * @description Default CSS class to apply to the toolbar container element + * @type String + */ + CLASS_CONTAINER: 'yui-toolbar-container', + /** + * @protected + * @property CLASS_DRAGHANDLE + * @description Default CSS class to apply to the toolbar's drag handle element + * @type String + */ + CLASS_DRAGHANDLE: 'yui-toolbar-draghandle', + /** + * @protected + * @property CLASS_SEPARATOR + * @description Default CSS class to apply to all separators in the toolbar + * @type String + */ + CLASS_SEPARATOR: 'yui-toolbar-separator', + /** + * @protected + * @property CLASS_DISABLED + * @description Default CSS class to apply when the toolbar is disabled + * @type String + */ + CLASS_DISABLED: 'yui-toolbar-disabled', + /** + * @protected + * @property CLASS_PREFIX + * @description Default prefix for dynamically created class names + * @type String + */ + CLASS_PREFIX: 'yui-toolbar', + /** + * @method init + * @description The Toolbar class's initialization method + */ + initializer: function() { + var fs = Y.Node.create(''); + this.set('id', this.get('node').get('id')); + this.get('node').appendChild(fs); + this.set('cont', fs.query('div.yui-toolbar-subcont')); + this.get('node').set('tabIndex', '-1'); + this.get('node').addClass(this.CLASS_CONTAINER); + + this._renderTitle(); + this._handleCollapse(); + this.on('titlebarChange', Y.bind(this._renderTitle, this)); + this.on('collapseChange', Y.bind(this._handleCollapse, this)); + + + this.processButtons(); + }, + processButtons: function() { + var button, buttons, len, b, data = this.get('buttons'); + Y.each(data, function(i, k) { + if (i.type == 'separator') { + this.addSeparator(); + } else if (i.group !== undefined) { + buttons = this.addButtonGroup(i); + if (buttons) { + len = buttons.length; + for(b = 0; b < len; b++) { + if (buttons[b]) { + this._configuredButtons[this._configuredButtons.length] = buttons[b].id; + } + } + } + this.set('buttons', data); + } else { + button = this.addButton(i); + if (button) { + this._configuredButtons[this._configuredButtons.length] = button.id; + } + } + }, this); + }, + /** + * @method initAttributes + * @description Initializes all of the configuration attributes used to create + * the toolbar. + * @param {Object} attr Object literal specifying a set of + * configuration attributes used to create the toolbar. + */ + initAttributes: function(attr) { + YAHOO.widget.Toolbar.superclass.initAttributes.call(this, attr); + + + /** + * @attribute disabled + * @description Boolean indicating if the toolbar should be disabled. It will also disable the draggable attribute if it is on. + * @default false + * @type Boolean + */ + this.setAttributeConfig('disabled', { + value: false, + method: function(disabled) { + if (this.get('disabled') === disabled) { + return false; + } + if (disabled) { + this.addClass(this.CLASS_DISABLED); + this.set('draggable', false); + this.disableAllButtons(); + } else { + this.removeClass(this.CLASS_DISABLED); + if (this._configs.draggable._initialConfig.value) { + //Draggable by default, set it back + this.set('draggable', true); + } + this.resetAllButtons(); + } + } + }); + + + /** + * @attribute draggable + * @description Boolean indicating if the toolbar should be draggable. + * @default false + * @type Boolean + */ + + this.setAttributeConfig('draggable', { + value: (attr.draggable || false), + method: function(draggable) { + if (draggable && !this.get('titlebar')) { + YAHOO.log('Dragging enabled', 'info', 'Toolbar'); + if (!this._dragHandle) { + this._dragHandle = document.createElement('SPAN'); + this._dragHandle.innerHTML = '|'; + this._dragHandle.setAttribute('title', 'Click to drag the toolbar'); + this._dragHandle.id = this.get('id') + '_draghandle'; + Dom.addClass(this._dragHandle, this.CLASS_DRAGHANDLE); + if (this.get('cont').hasChildNodes()) { + this.get('cont').insertBefore(this._dragHandle, this.get('cont').firstChild); + } else { + this.get('cont').appendChild(this._dragHandle); + } + this.dd = new YAHOO.util.DD(this.get('id')); + this.dd.setHandleElId(this._dragHandle.id); + + } + } else { + YAHOO.log('Dragging disabled', 'info', 'Toolbar'); + if (this._dragHandle) { + this._dragHandle.parentNode.removeChild(this._dragHandle); + this._dragHandle = null; + this.dd = null; + } + } + if (this._titlebar) { + if (draggable) { + this.dd = new YAHOO.util.DD(this.get('id')); + this.dd.setHandleElId(this._titlebar); + Dom.addClass(this._titlebar, 'draggable'); + } else { + Dom.removeClass(this._titlebar, 'draggable'); + if (this.dd) { + this.dd.unreg(); + this.dd = null; + } + } + } + }, + validator: function(value) { + var ret = true; + if (!YAHOO.util.DD) { + ret = false; + } + return ret; + } + }); + + }, + /** + * @method addButtonGroup + * @description Add a new button group to the toolbar. (uses addButton) + * @param {Object} oGroup Object literal reference to the Groups Config (contains an array of button configs as well as the group label) + */ + addButtonGroup: function(oGroup) { + + if (!this.get('node').hasClass(this.CLASS_PREFIX + '-grouped')) { + this.get('node').addClass(this.CLASS_PREFIX + '-grouped'); + } + var div = Y.Node.create(''); + if (oGroup.label) { + var label = Y.Node.create('' + oGroup.label + '
'); + div.appendChild(label); + } + if (!this.get('grouplabels')) { + this.get('cont').addClass(this.CLASS_PREFIX, '-nogrouplabels'); + } + + this.get('cont').appendChild(div); + + //For accessibility, let's put all of the group buttons in an Unordered List + var ul = Y.Node.create(''); + div.appendChild(ul); + + if (!this._buttonGroupList) { + this._buttonGroupList = {}; + } + + this._buttonGroupList[oGroup.group] = ul; + + + //An array of the button ids added to this group + //This is used for destruction later... + var addedButtons = [], + button; + + Y.each(oGroup.buttons, function(i) { + var li = Y.Node.create('
'); + ul.appendChild(li); + if ((i.type !== undefined) && i.type == 'separator') { + this.addSeparator(li); + } else { + i.container = li; + button = this.addButton(i); + if (button) { + addedButtons[addedButtons.length] = button.id; + } + } + }, this); + + return addedButtons; + }, + /** + * @method addButtonToGroup + * @description Add a new button to a toolbar group. Buttons supported: + * push, split, menu, select, color, spin + * @param {Object} oButton Object literal reference to the Button's Config + * @param {String} group The Group identifier passed into the initial config + * @param {HTMLElement} after Optional HTML element to insert this button after in the DOM. + */ + addButtonToGroup: function(oButton, group, after) { + var groupCont = this._buttonGroupList[group], + li = document.createElement('li'); + + li.className = this.CLASS_PREFIX + '-groupitem'; + oButton.container = li; + this.addButton(oButton, after); + groupCont.appendChild(li); + }, + /** + * @method addButton + * @description Add a new button to the toolbar. Buttons supported: + * push, split, menu, select, color, spin + * @param {Object} oButton Object literal reference to the Button's Config + * @param {HTMLElement} after Optional HTML element to insert this button after in the DOM. + */ + addButton: function(oButton, after) { + if (!this._buttonList) { + this._buttonList = []; + } + if (!oButton.container) { + oButton.container = this.get('cont'); + } + /* + if ((oButton.type == 'menu') || (oButton.type == 'split') || (oButton.type == 'select')) { + if (Y.Lang.isArray(oButton.menu)) { + for (var i in oButton.menu) { + if (Lang.hasOwnProperty(oButton.menu, i)) { + var funcObject = { + fn: function(ev, x, oMenu) { + if (!oButton.menucmd) { + oButton.menucmd = oButton.value; + } + oButton.value = ((oMenu.value) ? oMenu.value : oMenu._oText.nodeValue); + }, + scope: this + }; + oButton.menu[i].onclick = funcObject; + } + } + } + } + */ + var _oButton = {}, skip = false; + Y.each(oButton, function(v, k) { + if (!this._toolbarConfigs[k]) { + _oButton[k] = v; + } + }, this); + if (oButton.type == 'select') { + _oButton.type = 'menu'; + } + if (oButton.type == 'spin') { + _oButton.type = 'push'; + } + if (_oButton.type == 'color') { + if (Y.Overlay) { + _oButton = this._makeColorButton(_oButton); + } else { + skip = true; + } + } + if (_oButton.menu) { + if ((Y.Overlay) && (oButton.menu instanceof Y.Overlay)) { + oButton.menu.on('visibleChange', function() { + this._button = _oButton; + }); + } else { + /* + for (var m = 0; m < _oButton.menu.length; m++) { + if (!_oButton.menu[m].value) { + _oButton.menu[m].value = _oButton.menu[m].text; + } + } + if (this.browser.webkit) { + _oButton.focusmenu = false; + } + */ + } + } + if (skip) { + oButton = false; + } else { + //Add to .get('buttons') manually + //this._configs.buttons.value[this._configs.buttons.value.length] = oButton; + var tmp = new this.buttonType(_oButton); + tmp.get('node').set('tabIndex', '-1'); + tmp.get('node').set('role', 'button'); + if (!_oButton.id || !oButton.id) { + oButton.id = tmp.get('id'); + _oButton.id = tmp.get('id'); + } + //tmp._selected = true; + + if (this.get('disabled')) { + //Toolbar is disabled, disable the new button too! + tmp.set('disabled', true); + } + /* + if (after) { + var el = tmp.get('element'); + var nextSib = null; + if (after.get) { + nextSib = after.get('element').nextSibling; + } else if (after.nextSibling) { + nextSib = after.nextSibling; + } + if (nextSib) { + nextSib.parentNode.insertBefore(el, nextSib); + } + } + */ + tmp.get('node').addClass(this.CLASS_PREFIX + '-' + tmp.get('value')); + + var icon = Y.Node.create(''); + tmp.get('node').insertBefore(icon, tmp.get('node').get('firstChild')); + /* + if (tmp._button.tagName.toLowerCase() == 'button') { + tmp.get('element').setAttribute('unselectable', 'on'); + //Replace the Button HTML Element with an a href if it exists + var a = document.createElement('a'); + a.innerHTML = tmp._button.innerHTML; + a.href = '#'; + a.tabIndex = '-1'; + Event.on(a, 'click', function(ev) { + Event.stopEvent(ev); + }); + tmp._button.parentNode.replaceChild(a, tmp._button); + tmp._button = a; + } + */ + /* + if (oButton.type == 'select') { + if (tmp._button.tagName.toLowerCase() == 'select') { + icon.parentNode.removeChild(icon); + var iel = tmp._button, + parEl = tmp.get('element'); + parEl.parentNode.replaceChild(iel, parEl); + //The 'element' value is currently the orphaned element + //In order for "destroy" to execute we need to get('element') to reference the correct node. + //I'm not sure if there is a direct approach to setting this value. + tmp._configs.element.value = iel; + } else { + //Don't put a class on it if it's a real select element + tmp.addClass(this.CLASS_PREFIX + '-select'); + } + } + */ + if (oButton.type == 'spin') { + if (!Y.Lang.isArray(oButton.range)) { + oButton.range = [ 10, 100 ]; + } + this._makeSpinButton(tmp, oButton); + } + tmp.get('node').set('title', tmp.get('label')); + if (oButton.type != 'spin') { + if ((Y.Overlay) && (_oButton.menu instanceof Y.Overlay)) { + var showPicker = function(ev) { + var exec = true; + if (ev.keyCode && (ev.keyCode == 9)) { + exec = false; + } + if (exec) { + if (this._colorPicker) { + this._colorPicker._button = oButton.value; + } + tmp.getMenu().set('visible', !tmp.getMenu().get('visible')); + } + ev.halt(); + }; + tmp.get('node').on('mousedown', Y.bind(showPicker, this)); + tmp.get('node').on('keydown', Y.bind(showPicker, this)); + + } else if ((oButton.type != 'menu') && (oButton.type != 'select')) { + tmp.get('node').on('keypress', Y.bind(this._buttonClick, this)); + tmp.get('node').on('mousedown', Y.bind(function(ev) { + ev.halt(); + this._buttonClick(ev, oButton); + }, this)); + tmp.get('node').on('click', function(ev) { + ev.halt(); + }); + } else { + + //Stop the mousedown event so we can trap the selection in the editor! + tmp.on('mousedown', function(ev) { + ev.halt(); + }); + tmp.on('click', function(ev) { + ev.halt(); + }); + tmp.on('change', function(ev) { + if (!oButton.menucmd) { + oButton.menucmd = oButton.value; + } + oButton.value = ev.value; + this._buttonClick(ev, oButton); + }, this, true); + } + /* + var self = this; + //Hijack the mousedown event in the menu and make it fire a button click.. + + tmp.on('appendTo', function() { + var tmp = this; + if (tmp.getMenu() && tmp.getMenu().mouseDownEvent) { + tmp.getMenu().mouseDownEvent.subscribe(function(ev, args) { + YAHOO.log('mouseDownEvent', 'warn', 'Toolbar'); + var oMenu = args[1]; + YAHOO.util.Event.stopEvent(args[0]); + tmp._onMenuClick(args[0], tmp); + if (!oButton.menucmd) { + oButton.menucmd = oButton.value; + } + oButton.value = ((oMenu.value) ? oMenu.value : oMenu._oText.nodeValue); + self._buttonClick.call(self, args[1], oButton); + tmp._hideMenu(); + return false; + }); + tmp.getMenu().clickEvent.subscribe(function(ev, args) { + YAHOO.log('clickEvent', 'warn', 'Toolbar'); + YAHOO.util.Event.stopEvent(args[0]); + }); + tmp.getMenu().mouseUpEvent.subscribe(function(ev, args) { + YAHOO.log('mouseUpEvent', 'warn', 'Toolbar'); + YAHOO.util.Event.stopEvent(args[0]); + }); + } + }); + */ + } else { + //Stop the mousedown event so we can trap the selection in the editor! + tmp.on('mousedown', function(ev) { + ev.halt(); + }); + tmp.on('click', function(ev) { + ev.halt(); + }); + } + if (this.browser.ie) { + /* + //Add a couple of new events for IE + tmp.DOM_EVENTS.focusin = true; + tmp.DOM_EVENTS.focusout = true; + + //Stop them so we don't loose focus in the Editor + tmp.on('focusin', function(ev) { + YAHOO.util.Event.stopEvent(ev); + }, oButton, this); + + tmp.on('focusout', function(ev) { + YAHOO.util.Event.stopEvent(ev); + }, oButton, this); + tmp.on('click', function(ev) { + YAHOO.util.Event.stopEvent(ev); + }, oButton, this); + */ + } + if (this.browser.webkit) { + //This will keep the document from gaining focus and the editor from loosing it.. + //Forcefully remove the focus calls in button! + //tmp.hasFocus = function() { + // return true; + //}; + } + this._buttonList[this._buttonList.length] = tmp; + /* + if ((oButton.type == 'menu') || (oButton.type == 'split') || (oButton.type == 'select')) { + if (Lang.isArray(oButton.menu)) { + YAHOO.log('Button type is (' + oButton.type + '), doing extra renderer work.', 'info', 'Toolbar'); + var menu = tmp.getMenu(); + if (menu && menu.renderEvent) { + menu.renderEvent.subscribe(this._addMenuClasses, tmp); + if (oButton.renderer) { + menu.renderEvent.subscribe(oButton.renderer, tmp); + } + } + } + } + */ + } + return oButton; + }, + /** + * @method addSeparator + * @description Add a new button separator to the toolbar. + * @param {HTMLElement} cont Optional HTML element to insert this button into. + * @param {HTMLElement} after Optional HTML element to insert this button after in the DOM. + */ + addSeparator: function(cont, after) { + var sepCont = ((cont) ? cont : this.get('cont')); + if (this._sepCount === null) { + this._sepCount = 0; + } + if (!this._sep) { + Y.log('Separator does not yet exist, creating'); + this._sep = Y.Node.create('|'); + } + Y.log('Separator does exist, cloning'); + var _sep = this._sep.cloneNode(true); + this._sepCount++; + + _sep.addClass(this.CLASS_SEPARATOR + '-' + this._sepCount); + if (after) { + var nextSib = null; + if (after.get) { + nextSib = after.get('element').nextSibling; + } else if (after.nextSibling) { + nextSib = after.nextSibling; + } else { + nextSib = after; + } + if (nextSib) { + if (nextSib == after) { + nextSib.parentNode.appendChild(_sep); + } else { + nextSib.parentNode.insertBefore(_sep, nextSib); + } + } + } else { + sepCont.appendChild(_sep); + } + return _sep; + }, + /** + * @method _createColorPicker + * @private + * @description Creates the core DOM reference to the color picker menu item. + * @param {String} id the id of the toolbar to prefix this DOM container with. + */ + _createColorPicker: function(id) { + var c = Y.get('#' + id + '_colors'); + if (c) { + c.get('parentNode').removeChild(c); + } + var picker = Y.Node.create(''); + Y.get('body').appendChild(picker); + + this._colorPicker = picker; + + var html = ''; + Y.each(this._colorData, function(v, k) { + html += '' + k.replace('#', '') + ''; + }, this); + html += 'X'; + picker.set('innerHTML', html); + + picker.on('mouseover', Y.bind(function(ev) { + var picker = this._colorPicker; + var em = picker.query('em'); + var strong = picker.query('strong'); + var tar = ev.target; + if (tar.get('tagName').toLowerCase() == 'a') { + em.setStyle('backgroundColor', tar.getStyle('backgroundColor')); + strong.set('innerHTML', this._colorData['#' + tar.get('innerHTML')] + '
' + tar.get('innerHTML')); + } + }, this)); + picker.on('focus', function(ev) { + ev.halt(); + }); + picker.on('click', function(ev) { + ev.halt(); + }); + picker.on('mousedown', Y.bind(function(ev) { + ev.halt(); + var tar = ev.target, data; + if (tar.get('tagName').toLowerCase() == 'a') { + data = tar.get('innerHTML'); + var retVal = this.fire('colorPickerClicked', { type: 'colorPickerClicked', button: this._colorPicker._button, color: data, colorName: this._colorData['#' + data] } ); + var info = { + color: data, + colorName: this._colorData['#' + data], + value: this._colorPicker._button + }; + + this.fire('buttonClick', { type: 'buttonClick', button: info }); + this.getButtonByValue(this._colorPicker._button).getMenu().hide(); + this._colorPicker.setStyle('display', 'none'); + } + }, this)); + }, + /** + * @method _resetColorPicker + * @private + * @description Clears the currently selected color or mouseover color in the color picker. + */ + _resetColorPicker: function() { + var em = this._colorPicker.query('em'); + var strong = this._colorPicker.query('strong'); + em.setStyle('backgroundColor', 'transparent'); + strong.set('innerHTML', ''); + }, + /** + * @method _makeColorButton + * @private + * @description Called to turn a "color" button into a menu button with an Overlay for the menu. + * @param {Object} _oButton YAHOO.widget.ToolbarButton reference + */ + _makeColorButton: function(_oButton) { + if (!this._colorPicker) { + this._createColorPicker(this.get('id')); + } + _oButton.type = 'color'; + _oButton.menu = new Y.Overlay({ + contentBox: '#' + this.get('id') + '_' + _oButton.value + '_menu', + bodyContent: 'FOO', + visible: false, + zIndex: 999 + }); + _oButton.menu.render(this.get('cont')); + _oButton.menu.set('visible', false); + + _oButton.menu.get('contentBox').addClass('yui-button-menu'); + _oButton.menu.get('contentBox').addClass('yui-color-button-menu'); + + _oButton.menu.after('visibleChange', Y.bind(function() { + _oButton.menu.set('align', { + node: this.getButtonById(_oButton.id).get('node'), + points: ['tl', 'bl'] + }); + //Move the DOM reference of the color picker to the Overlay that we are about to show. + this._resetColorPicker(); + var _p = this._colorPicker; + if (_p.get('parentNode')) { + _p.get('parentNode').removeChild(_p); + } + _oButton.menu.get('contentBox').query('.yui-widget-bd').set('innerHTML', ''); + _oButton.menu.get('contentBox').query('.yui-widget-bd').appendChild(_p); + this._colorPicker.setStyle('display', 'block'); + }, this)); + + return _oButton; + }, + /** + * @private + * @method _makeSpinButton + * @description Create a button similar to an OS Spin button.. It has an up/down arrow combo to scroll through a range of int values. + * @param {Object} _button YAHOO.widget.ToolbarButton reference + * @param {Object} oButton Object literal containing the buttons initial config + */ + _makeSpinButton: function(_button, oButton) { + _button.get('node').addClass(this.CLASS_PREFIX + '-spinbutton'); + var self = this, + _par = _button.get('node'), //parentNode of Button Element for appending child + range = oButton.range, + _b1 = Y.Node.create('' + this.STR_SPIN_UP + ''), + _b2 = Y.Node.create('' + this.STR_SPIN_DOWN + ''); + + //Append them to the container + _par.appendChild(_b1); + _par.appendChild(_b2); + + + var label = Y.Lang.substitute(this.STR_SPIN_LABEL, { VALUE: _button.get('label') }); + _button.set('title', label); + + + var cleanVal = function(value) { + value = ((value < range[0]) ? range[0] : value); + value = ((value > range[1]) ? range[1] : value); + return value; + }; + + var br = this.browser; + var tbar = false; + var strLabel = this.STR_SPIN_LABEL; + if (this._titlebar && this._titlebar.get('firstChild')) { + tbar = this._titlebar.get('firstChild'); + } + + var _intUp = function(ev) { + ev.halt(); + if (!_button.get('disabled') && (ev.keyCode != 9)) { + var value = parseInt(_button.get('label'), 10); + value++; + value = cleanVal(value); + _button.set('label', ''+value); + var label = Y.Lang.substitute(strLabel, { VALUE: _button.get('label') }); + _button.set('title', label); + self._buttonClick(ev, oButton); + } + }; + + var _intDown = function(ev) { + ev.halt(); + if (!_button.get('disabled') && (ev.keyCode != 9)) { + var value = parseInt(_button.get('label'), 10); + value--; + value = cleanVal(value); + + _button.set('label', ''+value); + var label = Y.Lang.substitute(strLabel, { VALUE: _button.get('label') }); + _button.set('title', label); + self._buttonClick(ev, oButton); + } + }; + + var _intKeyUp = function(ev) { + if (ev.keyCode == 38) { + _intUp(ev); + } else if (ev.keyCode == 40) { + _intDown(ev); + } else if (ev.keyCode == 107 && ev.shiftKey) { //Plus Key + _intUp(ev); + } else if (ev.keyCode == 109 && ev.shiftKey) { //Minus Key + _intDown(ev); + } + }; + + //Handle arrow keys.. + _button.on('keydown', Y.bind(_intKeyUp, this)); + + //Listen for the click on the up button and act on it + //Listen for the click on the down button and act on it + _b1.on('mousedown',function(ev) { ev.halt(); }); + _b2.on('mousedown',function(ev) { ev.halt(); }); + _b1.on('click', Y.bind(_intUp, this)); + _b2.on('click', Y.bind(_intDown, this)); + }, + /** + * @protected + * @method _buttonClick + * @description Click handler for all buttons in the toolbar. + * @param {String} ev The event that was passed in. + * @param {Object} info Object literal of information about the button that was clicked. + */ + _buttonClick: function(ev, info) { + var doEvent = true; + + if (ev && ev.type == 'keypress') { + if (ev.keyCode == 9) { + doEvent = false; + } else if ((ev.keyCode === 13) || (ev.keyCode === 0) || (ev.keyCode === 32)) { + } else { + doEvent = false; + } + } + + if (doEvent) { + var fireNextEvent = true, + retValue = false; + + info.isSelected = this.isSelected(info.id); + + if (info.value) { + Y.log('fireEvent::' + info.value + 'Click'); + retValue = this.fire(info.value + 'Click', { type: info.value + 'Click', target: this.get('element'), button: info }); + if (retValue === false) { + fireNextEvent = false; + } + } + + if (info.menucmd && fireNextEvent) { + Y.log('fireEvent::' + info.menucmd + 'Click'); + retValue = this.fire(info.menucmd + 'Click', { type: info.menucmd + 'Click', target: this.get('element'), button: info }); + if (retValue === false) { + fireNextEvent = false; + } + } + if (fireNextEvent) { + Y.log('fireEvent::buttonClick'); + this.fire('buttonClick', { type: 'buttonClick', target: this.get('element'), button: info }); + } + + if (info.type == 'select') { + var button = this.getButtonById(info.id); + if (button.buttonType == 'rich') { + var txt = info.value; + for (var i = 0; i < info.menu.length; i++) { + if (info.menu[i].value == info.value) { + txt = info.menu[i].text; + break; + } + } + button.set('label', ' '); + var _items = button.getMenu().getItems(); + for (var m = 0; m < _items.length; m++) { + if (_items[m].value.toLowerCase() == info.value.toLowerCase()) { + _items[m].cfg.setProperty('checked', true); + } else { + _items[m].cfg.setProperty('checked', false); + } + } + } + } + if (ev) { + ev.halt(); + } + } + }, + /** + * @private + * @property _keyNav + * @description Flag to determine if the arrow nav listeners have been attached + * @type Boolean + */ + _keyNav: null, + /** + * @private + * @property _navCounter + * @description Internal counter for walking the buttons in the toolbar with the arrow keys + * @type Number + */ + _navCounter: null, + /** + * @private + * @method _navigateButtons + * @description Handles the navigation/focus of toolbar buttons with the Arrow Keys + * @param {Event} ev The Key Event + */ + _navigateButtons: function(ev) { + switch (ev.keyCode) { + case 37: + case 39: + if (ev.keyCode == 37) { + this._navCounter--; + } else { + this._navCounter++; + } + if (this._navCounter > (this._buttonList.length - 1)) { + this._navCounter = 0; + } + if (this._navCounter < 0) { + this._navCounter = (this._buttonList.length - 1); + } + if (this._buttonList[this._navCounter]) { + var el = this._buttonList[this._navCounter].get('node'); + if (this.browser.ie) { + el = this._buttonList[this._navCounter].get('node').query('a'); + } + if (this._buttonList[this._navCounter].get('disabled')) { + this._navigateButtons(ev); + } else { + el.focus(); + } + } + break; + } + }, + /** + * @private + * @method _handleFocus + * @description Sets up the listeners for the arrow key navigation + */ + _handleFocus: function() { + if (!this._keyNav) { + var ev = 'keypress'; + if (this.browser.ie) { + ev = 'keydown'; + } + this.get('node').on(ev, Y.bind(this._navigateButtons, this)); + this._keyNav = true; + this._navCounter = -1; + } + }, + /** + * @method getButtonById + * @description Gets a button instance from the toolbar by is Dom id. + * @param {String} id The Dom id to query for. + * @return {YAHOO.widget.ToolbarButton} + */ + getButtonById: function(id) { + var len = this._buttonList.length; + for (var i = 0; i < len; i++) { + if (this._buttonList[i] && this._buttonList[i].get('id') == id) { + return this._buttonList[i]; + } + } + return false; + }, + /** + * @method getButtonByValue + * @description Gets a button instance or a menuitem instance from the toolbar by it's value. + * @param {String} value The button value to query for. + * @return {YAHOO.widget.ToolbarButton or YAHOO.widget.MenuItem} + */ + getButtonByValue: function(value) { + var _buttons = this.get('buttons'); + if (!_buttons) { + return false; + } + var len = _buttons.length; + for (var i = 0; i < len; i++) { + if (_buttons[i].group !== undefined) { + for (var m = 0; m < _buttons[i].buttons.length; m++) { + if ((_buttons[i].buttons[m].value == value) || (_buttons[i].buttons[m].menucmd == value)) { + return this.getButtonById(_buttons[i].buttons[m].id); + } + if (_buttons[i].buttons[m].menu) { //Menu Button, loop through the values + for (var s = 0; s < _buttons[i].buttons[m].menu.length; s++) { + if (_buttons[i].buttons[m].menu[s].value == value) { + return this.getButtonById(_buttons[i].buttons[m].id); + } + } + } + } + } else { + if ((_buttons[i].value == value) || (_buttons[i].menucmd == value)) { + return this.getButtonById(_buttons[i].id); + } + if (_buttons[i].menu) { //Menu Button, loop through the values + for (var j = 0; j < _buttons[i].menu.length; j++) { + if (_buttons[i].menu[j].value == value) { + return this.getButtonById(_buttons[i].id); + } + } + } + } + } + return false; + }, + /** + * @method getButtonByIndex + * @description Gets a button instance from the toolbar by is index in _buttonList. + * @param {Number} index The index of the button in _buttonList. + * @return {YAHOO.widget.ToolbarButton} + */ + getButtonByIndex: function(index) { + if (this._buttonList[index]) { + return this._buttonList[index]; + } else { + return false; + } + }, + /** + * @method getButtons + * @description Returns an array of buttons in the current toolbar + * @return {Array} + */ + getButtons: function() { + return this._buttonList; + }, + /** + * @method disableButton + * @description Disables a button in the toolbar. + * @param {String/Number} id Disable a button by it's id, index or value. + * @return {Boolean} + */ + disableButton: function(id) { + var button = getButton.call(this, id); + if (button) { + button.set('disabled', true); + } else { + return false; + } + }, + /** + * @method enableButton + * @description Enables a button in the toolbar. + * @param {String/Number} id Enable a button by it's id, index or value. + * @return {Boolean} + */ + enableButton: function(id) { + if (this.get('disabled')) { + return false; + } + var button = getButton.call(this, id); + if (button) { + if (button.get('disabled')) { + button.set('disabled', false); + } + } else { + return false; + } + }, + /** + * @method isSelected + * @description Tells if a button is selected or not. + * @param {String/Number} id A button by it's id, index or value. + * @return {Boolean} + */ + isSelected: function(id) { + var button = getButton.call(this, id); + if (button) { + return button._selected; + } + return false; + }, + /** + * @method selectButton + * @description Selects a button in the toolbar. + * @param {String/Number} id Select a button by it's id, index or value. + * @param {String} value If this is a Menu Button, check this item in the menu + * @return {Boolean} + */ + selectButton: function(id, value) { + var button = getButton.call(this, id); + if (button && (button.get('type') == 'push')) { + button.get('node').addClass('yui-button-selected'); + button.get('node').addClass('yui-button-' + button.get('value') + '-selected'); + button._selected = true; + if (value) { + if (button.buttonType == 'rich') { + var _items = button.getMenu().getItems(); + for (var m = 0; m < _items.length; m++) { + if (_items[m].value == value) { + _items[m].cfg.setProperty('checked', true); + button.set('label', ' '); + } else { + _items[m].cfg.setProperty('checked', false); + } + } + } + } + } else { + return false; + } + }, + /** + * @method deselectButton + * @description Deselects a button in the toolbar. + * @param {String/Number} id Deselect a button by it's id, index or value. + * @return {Boolean} + */ + deselectButton: function(id) { + var button = getButton.call(this, id); + if (button) { + button.get('node').removeClass('yui-button-selected'); + button.get('node').removeClass('yui-button-' + button.get('value') + '-selected'); + button.get('node').removeClass('yui-button-hover'); + button._selected = false; + } else { + return false; + } + }, + /** + * @method deselectAllButtons + * @description Deselects all buttons in the toolbar. + * @return {Boolean} + */ + deselectAllButtons: function() { + var len = this._buttonList.length; + for (var i = 0; i < len; i++) { + this.deselectButton(this._buttonList[i]); + } + }, + /** + * @method disableAllButtons + * @description Disables all buttons in the toolbar. + * @return {Boolean} + */ + disableAllButtons: function() { + if (this.get('disabled')) { + return false; + } + var len = this._buttonList.length; + for (var i = 0; i < len; i++) { + this.disableButton(this._buttonList[i]); + } + }, + /** + * @method enableAllButtons + * @description Enables all buttons in the toolbar. + * @return {Boolean} + */ + enableAllButtons: function() { + if (this.get('disabled')) { + return false; + } + var len = this._buttonList.length; + for (var i = 0; i < len; i++) { + this.enableButton(this._buttonList[i]); + } + }, + /** + * @method resetAllButtons + * @description Resets all buttons to their initial state. + * @param {Object} _ex Except these buttons + * @return {Boolean} + */ + resetAllButtons: function(_ex) { + if (!Y.Lang.isObject(_ex)) { + _ex = {}; + } + if (this.get('disabled') || !this._buttonList) { + return false; + } + var len = this._buttonList.length; + for (var i = 0; i < len; i++) { + var _button = this._buttonList[i]; + if (_button) { + //var disabled = _button._configs.disabled._initialConfig.value; + var disabled = false; + if (_ex[_button.get('id')]) { + this.enableButton(_button); + this.selectButton(_button); + } else { + if (disabled) { + this.disableButton(_button); + } else { + this.enableButton(_button); + } + this.deselectButton(_button); + } + } + } + }, + /** + * @method destroyButton + * @description Destroy a button in the toolbar. + * @param {String/Number} id Destroy a button by it's id or index. + * @return {Boolean} + */ + destroyButton: function(id) { + var button = getButton.call(this, id); + if (button) { + var thisID = button.get('id'), + new_list = [], i = 0, + len = this._buttonList.length; + + button.destroy(); + + for (i = 0; i < len; i++) { + if (this._buttonList[i].get('id') != thisID) { + new_list[new_list.length]= this._buttonList[i]; + } + } + + this._buttonList = new_list; + } else { + return false; + } + }, + /** + * @method destroy + * @description Destroys the toolbar, all of it's elements and objects. + * @return {Boolean} + */ + destructor: function() { + var len = this._configuredButtons.length, j, i, b; + for(b = 0; b < len; b++) { + this.destroyButton(this._configuredButtons[b]); + } + + this._configuredButtons = null; + + this.get('element').innerHTML = ''; + this.get('element').className = ''; + //Brutal Object Destroy + for (i in this) { + if (Lang.hasOwnProperty(this, i)) { + this[i] = null; + } + } + return true; + }, + /** + * @method collapse + * @description Programatically collapse the toolbar. + * @param {Boolean} collapse True to collapse, false to expand. + */ + collapse: function(collapse) { + var el = this._titlebar.query('span.collapse'); + if (collapse === false) { + this.get('cont').get('parentNode').removeClass('yui-toolbar-container-collapsed'); + if (el) { + el.removeClass('collapsed'); + el.set('title', this.STR_COLLAPSE); + } + this.fire('toolbarExpanded', { type: 'toolbarExpanded' }); + } else { + if (el) { + el.addClass('collapsed'); + el.set('title', this.STR_EXPAND); + } + this.get('cont').get('parentNode').addClass('yui-toolbar-container-collapsed'); + this.fire('toolbarCollapsed', { type: 'toolbarCollapsed' }); + } + }, + /** + * @method toString + * @description Returns a string representing the toolbar. + * @return {String} + */ + toString: function() { + return 'Toolbar'; + } + }); + + Y.namespace('Y.Toolbar'); + Y.Toolbar.Bar = Toolbar; + + var YAHOO = Y.Port(), + Lang = YAHOO.lang, + Dom = YAHOO.util.Dom, + Event = YAHOO.util.Event; + + var SimpleEditor = function(o) { + Y.log('SimpleEditor Initalizing'); + + var node = Y.get(o.node), + id = node.get('id'); + if (!id) { + id = Y.stamp(node); + node.set('id', id); + } + + var element_cont = Y.Node.create(''); + //Hack + Y.get('body').appendChild(element_cont); + o.element_cont = element_cont; + o.editor_wrapper = element_cont.query('div.wrapper'); + o.toolbar_cont = element_cont.query('div.toolbar_cont'); + //Hack + Y.get('body').removeChild(element_cont); + + if (!o.html) { + o.html = '{TITLE} {CONTENT}'; + } + if (!o.css) { + o.css = this._defaultCSS; + } + //console.log(o); + + + SimpleEditor.superclass.constructor.apply(this, arguments); + }; + + SimpleEditor.NAME = 'simpleeditor'; + + SimpleEditor.ATTRS = { + node: { + setter: function(node) { + var n = Y.get(node); + if (!n) { + Y.error('Invalid Node Given: ' + node); + } else { + n = n.item(0); + } + return n; + } + }, + /** + * @config container + * @description Used when dynamically creating the Editor from Javascript with no default textarea. + * We will create one and place it in this container. If no container is passed we will append to document.body. + * @default false + * @type HTMLElement + */ + 'container': { + writeOnce: true, + value: false + }, + /** + * @private + * @config iframe + * @description Internal config for holding the iframe element. + * @default null + * @type HTMLElement + */ + 'iframe': { + value: null + }, + /** + * @private + * @depreciated - No longer used, should use this.get('element') + * @config textarea + * @description Internal config for holding the textarea element (replaced with element). + * @default null + * @type HTMLElement + */ + 'textarea': { + value: null, + writeOnce: true + }, + /** + * @config element_cont + * @description Internal config for the editors container + * @default false + * @type HTMLElement + */ + 'element_cont': { + value: null + }, + /** + * @private + * @config editor_wrapper + * @description The outter wrapper for the entire editor. + * @default null + * @type HTMLElement + */ + 'editor_wrapper': { + value: null + }, + /** + * @config toolbar_cont + * @description Internal config for the toolbars container + * @default false + * @type Boolean + */ + 'toolbar_cont': { + value: null, + writeOnce: true + }, + /** + * @attribute toolbar + * @description The default toolbar config. + * @type Object + */ + 'toolbar': { + value: null + }, + /** + * @attribute height + * @description The height of the editor iframe container, not including the toolbar.. + * @default Best guessed size of the textarea, for best results use CSS to style the height of the textarea or pass it in as an argument + * @type String + */ + 'height': { + value: null, + setter: function(height) { + if (this._rendered) { + this.get('iframe').get('parentNode').setStyle('height', height); + } + } + }, + /** + * @attribute width + * @description The width of the editor container. + * @default Best guessed size of the textarea, for best results use CSS to style the width of the textarea or pass it in as an argument + * @type String + */ + 'width': { + value: null, + setter: function(width) { + if (this._rendered) { + //We have been rendered, change the width + this.get('element_cont').setStyle('width', width); + } + } + }, + /** + * @attribute blankimage + * @description The URL for the image placeholder to put in when inserting an image. + * @default The yahooapis.com address for the current release + 'assets/blankimage.png' + * @type String + */ + 'blankimage': { + value: null + }, + /** + * @attribute css + * @description The Base CSS used to format the content of the editor + * @default + * @type String + */ + 'css': { + value: null, + writeOnce: true + }, + /** + * @attribute html + * @description The default HTML to be written to the iframe document before the contents are loaded (Note that the DOCTYPE attr will be added at render item) + * @default This HTML requires a few things if you are to override: +
html { + height: 95%; + } + body { + height: 100%; + padding: 7px; background-color: #fff; font:13px/1.22 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small; + } + a { + color: blue; + text-decoration: underline; + cursor: pointer; + } + .warning-localfile { + border-bottom: 1px dashed red !important; + } + .yui-busy { + cursor: wait !important; + } + img.selected { //Safari image selection + border: 2px dotted #808080; + } + img { + cursor: pointer !important; + border: none; + } +
{TITLE}, {CSS}, {HIDDEN_CSS}, {EXTRA_CSS}
and{CONTENT}
need to be there, they are passed to YAHOO.lang.substitute to be replace with other strings.+
+
onload="document.body._rteLoaded = true;"
: the onload statement must be there or the editor will not finish loading.+
+ * @type String + */ + 'html': { + value: null, + writeOnce: true + }, + /** + * @attribute extracss + * @description Extra user defined css to load after the default SimpleEditor CSS + * @default '' + * @type String + */ + 'extracss': { + value: '', + writeOnce: true + }, + /** + * @config setDesignMode + * @description Should the Editor set designMode on the document. Default: true. + * @default true + * @type Boolean + */ + setDesignMode: { + value: true + }, + /** + * @config nodeChangeDelay + * @description Do we wrap the nodeChange method in a timeout for performance. Default: true. + * @default true + * @type Boolean + */ + nodeChangeDelay: { + value: true + }, + /** + * @attribute dompath + * @description Toggle the display of the current Dom path below the editor + * @default false + * @type Boolean + */ + dompath: { + value: false + }, + /** + * @attribute markup + * @description Should we try to adjust the markup for the following types: semantic, css, default or xhtml + * @default "semantic" + * @type String + */ + markup: { + value: 'semantic', + validator: function(markup) { + switch (markup.toLowerCase()) { + case 'semantic': + case 'css': + case 'default': + case 'xhtml': + return true; + } + return false; + } + }, + /** + * @config maxUndo + * @description The max number of undo levels to store. + * @default 30 + * @type Number + */ + maxUndo: { + writeOnce: true, + value: 30 + }, + + /** + * @config ptags + * @description If true, the editor uses <P> tags instead of <br> tags. (Use Shift + Enter to get a <br>) + * @default false + * @type Boolean + */ + ptags: { + writeOnce: true, + value: false + }, + /** + * @config plainText + * @description Process the inital textarea data as if it was plain text. Accounting for spaces, tabs and line feeds. + * @default false + * @type Boolean + */ + plainText: { + writeOnce: true, + value: false + }, + /** + * @private + * @config disabled_iframe + * @description Internal config for holding the iframe element used when disabling the Editor. + * @default null + * @type HTMLElement + */ + disabled_iframe: { + value: null + }, + /** + * @config nodeChangeThreshold + * @description The number of seconds that need to be in between nodeChange processing + * @default 3 + * @type Number + */ + nodeChangeThreshold: { + value: 3, + validator: Y.Lang.isNumber + }, + /** + * @config allowNoEdit + * @description Should the editor check for non-edit fields. It should be noted that this technique is not perfect. If the user does the right things, they will still be able to make changes. + * Such as highlighting an element below and above the content and hitting a toolbar button or a shortcut key. + * @default false + * @type Boolean + */ + allowNoEdit: { + value: false, + validator: Y.Lang.isBoolean + }, + /** + * @config limitCommands + * @description Should the Editor limit the allowed execCommands to the ones available in the toolbar. If true, then execCommand and keyboard shortcuts will fail if they are not defined in the toolbar. + * @default false + * @type Boolean + */ + limitCommands: { + value: false, + validator: Y.Lang.isBoolean + }, + /** + * @attribute removeLineBreaks + * @description Should we remove linebreaks and extra spaces on cleanup + * @default false + * @type Boolean + */ + removeLineBreaks: { + value: false, + validator: Y.Lang.isBoolean + }, + /** + * @config filterWord + * @description Attempt to filter out MS Word HTML from the Editor's output. + * @type Boolean + */ + filterWord: { + value: false, + validator: Y.Lang.isBoolean + }, + /** + * @config insert + * @description If true, selection is not required for: fontname, fontsize, forecolor, backcolor. + * @default false + * @type Boolean + */ + insert: { + value: false + }, + /** + * @config saveEl + * @description When save HTML is called, this element will be updated as well as the source of data. + * @default element + * @type HTMLElement + */ + saveEl: { + value: null, + setter: function(node) { + var n = Y.get(node); + if (!n) { + return false; + } else { + n = n.item(0); + } + return n; + } + }, + /** + * @attribute disabled + * @description This will toggle the editor's disabled state. When the editor is disabled, designMode is turned off and a mask is placed over the iframe so no interaction can take place. + All Toolbar buttons are also disabled so they cannot be used. + * @default false + * @type Boolean + */ + disabled: { + value: false, + setter: function(disabled) { + if (this._rendered) { + this._disableEditor(disabled); + } + } + }, + /** + * @attribute focusAtStart + * @description Should we focus the window when the content is ready? + * @default false + * @type Boolean + */ + focusAtStart: { + value: false, + writeOnce: true + }, + /** + * @attribute handleSubmit + * @description Config handles if the editor will attach itself to the textareas parent form's submit handler. + If it is set to true, the editor will attempt to attach a submit listener to the textareas parent form. + Then it will trigger the editors save handler and place the new content back into the text area before the form is submitted. + * @default false + * @type Boolean + */ + handleSubmit: { + value: false + } + }; + + Y.extend(SimpleEditor, Y.PortBase, { + _handleSubmit: function() { + var exec = this.get('handleSubmit'); + if (this.get('node').get('form')) { + if (!this._formButtons) { + this._formButtons = []; + } + if (exec) { + this.get('node').get('form').on('submit', Y.bind(this._handleFormSubmit, this)); + + var i = this.get('node').get('form').query('input'); + if (i) { + i.each(function(v, k) { + var type = v.get('type'); + if (type && (type.toLowerCase() == 'submit')) { + v.on('click', Y.bind(this._handleFormButtonClick, this)); + this._formButtons.push(v); + } + }, this); + } + } else { + //Event.removeListener(this.get('element').form, 'submit', this._handleFormSubmit); + //if (this._formButtons) { + // Event.removeListener(this._formButtons, 'click', this._handleFormButtonClick); + //} + } + } + }, + _handleInsert: function() { + if (this.get('insert')) { + var buttons = { + fontname: true, + fontsize: true, + forecolor: true, + backcolor: true + }; + var tmp = this._defaultToolbar.buttons; + for (var i = 0; i < tmp.length; i++) { + if (tmp[i].buttons) { + for (var a = 0; a < tmp[i].buttons.length; a++) { + if (tmp[i].buttons[a].value) { + if (buttons[tmp[i].buttons[a].value]) { + delete tmp[i].buttons[a].disabled; + } + } + } + } + } + } + }, + _handleDOMPath: function() { + var dompath = this.get('dompath'); + if (dompath && !this.dompath) { + this.dompath = Y.Node.create(''); + this.get('element_cont').get('firstChild').appendChild(this.dompath); + if (this.get('iframe')) { + this._writeDomPath(); + } + } else if (!dompath && this.dompath) { + this.dompath.get('parentNode').removeChild(this.dompath); + this.dompath = null; + } + }, + /** + * @private + * @property _lastCommand + * @description A cache of the last execCommand (used for Undo/Redo so they don't mark an undo level) + * @type String + */ + _lastCommand: null, + _undoNodeChange: function() {}, + _storeUndo: function() {}, + /** + * @private + * @method _checkKey + * @description Checks a keyMap entry against a key event + * @param {Object} k The _keyMap object + * @param {Event} e The Mouse Event + * @return {Boolean} + */ + _checkKey: function(k, e) { + var ret = false; + if ((e.keyCode === k.key)) { + if (k.mods && (k.mods.length > 0)) { + var val = 0; + for (var i = 0; i < k.mods.length; i++) { + if (this.browser.mac) { + if (k.mods[i] == 'ctrl') { + k.mods[i] = 'meta'; + } + } + if (e[k.mods[i] + 'Key'] === true) { + val++; + } + } + if (val === k.mods.length) { + ret = true; + } + } else { + ret = true; + } + } + //YAHOO.log('Shortcut Key Check: (' + k.key + ') return: ' + ret, 'info', 'SimpleEditor'); + return ret; + }, + /** + * @private + * @property _keyMap + * @description Named key maps for various actions in the Editor. Example:+ <html> + <head> + <title>{TITLE}</title> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <style> + {CSS} + </style> + <style> + {HIDDEN_CSS} + </style> + <style> + {EXTRA_CSS} + </style> + </head> + <body onload="document.body._rteLoaded = true;"> + {CONTENT} + </body> + </html> ++CLOSE_WINDOW: { key: 87, mods: ['shift', 'ctrl'] }
. + * This entry shows that when key 87 (W) is found with the modifiers of shift and control, the window will close. You can customize this object to tweak keyboard shortcuts. + * @type {Object/Mixed} + */ + _keyMap: { + SELECT_ALL: { + key: 65, //A key + mods: ['ctrl'] + }, + CLOSE_WINDOW: { + key: 87, //W key + mods: ['shift', 'ctrl'] + }, + FOCUS_TOOLBAR: { + key: 27, + mods: ['shift'] + }, + FOCUS_AFTER: { + key: 27 + }, + FONT_SIZE_UP: { + key: 38, + mods: ['shift', 'ctrl'] + }, + FONT_SIZE_DOWN: { + key: 40, + mods: ['shift', 'ctrl'] + }, + CREATE_LINK: { + key: 76, + mods: ['shift', 'ctrl'] + }, + BOLD: { + key: 66, + mods: ['shift', 'ctrl'] + }, + ITALIC: { + key: 73, + mods: ['shift', 'ctrl'] + }, + UNDERLINE: { + key: 85, + mods: ['shift', 'ctrl'] + }, + UNDO: { + key: 90, + mods: ['ctrl'] + }, + REDO: { + key: 90, + mods: ['shift', 'ctrl'] + }, + JUSTIFY_LEFT: { + key: 219, + mods: ['shift', 'ctrl'] + }, + JUSTIFY_CENTER: { + key: 220, + mods: ['shift', 'ctrl'] + }, + JUSTIFY_RIGHT: { + key: 221, + mods: ['shift', 'ctrl'] + } + }, + /** + * @private + * @method _cleanClassName + * @description Makes a useable classname from dynamic data, by dropping it to lowercase and replacing spaces with -'s. + * @param {String} str The classname to clean up + * @return {String} + */ + _cleanClassName: function(str) { + return str.replace(/ /g, '-').toLowerCase(); + }, + /** + * @property _textarea + * @description Flag to determine if we are using a textarea or an HTML Node. + * @type Boolean + */ + _textarea: null, + /** + * @property _docType + * @description The DOCTYPE to use in the editable container. + * @type String + */ + _docType: '', + /** + * @property editorDirty + * @description This flag will be set when certain things in the Editor happen. It is to be used by the developer to check to see if content has changed. + * @type Boolean + */ + editorDirty: null, + /** + * @property _defaultCSS + * @description The default CSS used in the config for 'css'. This way you can add to the config like this: { css: YAHOO.widget.SimpleEditor.prototype._defaultCSS + 'ADD MYY CSS HERE' } + * @type String + */ + _defaultCSS: 'html { height: 95%; } body { padding: 7px; background-color: #fff; font: 13px/1.22 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small; } a, a:visited, a:hover { color: blue !important; text-decoration: underline !important; cursor: text !important; } .warning-localfile { border-bottom: 1px dashed red !important; } .yui-busy { cursor: wait !important; } img.selected { border: 2px dotted #808080; } img { cursor: pointer !important; border: none; } body.ptags.webkit div.yui-wk-p { margin: 11px 0; } body.ptags.webkit div.yui-wk-div { margin: 0; }', + /** + * @property _defaultToolbar + * @private + * @description Default toolbar config. + * @type Object + */ + _defaultToolbar: null, + /** + * @property _lastButton + * @private + * @description The last button pressed, so we don't disable it. + * @type Object + */ + _lastButton: null, + /** + * @property _baseHREF + * @private + * @description The base location of the editable page (this page) so that relative paths for image work. + * @type String + */ + _baseHREF: function() { + var href = document.location.href; + if (href.indexOf('?') !== -1) { //Remove the query string + href = href.substring(0, href.indexOf('?')); + } + href = href.substring(0, href.lastIndexOf('/')) + '/'; + return href; + }(), + /** + * @property _lastImage + * @private + * @description Safari reference for the last image selected (for styling as selected). + * @type HTMLElement + */ + _lastImage: null, + /** + * @property _blankImageLoaded + * @private + * @description Don't load the blank image more than once.. + * @type Boolean + */ + _blankImageLoaded: null, + /** + * @property _fixNodesTimer + * @private + * @description Holder for the fixNodes timer + * @type Date + */ + _fixNodesTimer: null, + /** + * @property _nodeChangeTimer + * @private + * @description Holds a reference to the nodeChange setTimeout call + * @type Number + */ + _nodeChangeTimer: null, + /** + * @property _nodeChangeDelayTimer + * @private + * @description Holds a reference to the nodeChangeDelay setTimeout call + * @type Number + */ + _nodeChangeDelayTimer: null, + /** + * @property _lastNodeChangeEvent + * @private + * @description Flag to determine the last event that fired a node change + * @type Event + */ + _lastNodeChangeEvent: null, + /** + * @property _lastNodeChange + * @private + * @description Flag to determine when the last node change was fired + * @type Date + */ + _lastNodeChange: 0, + /** + * @property _rendered + * @private + * @description Flag to determine if editor has been rendered or not + * @type Boolean + */ + _rendered: null, + /** + * @property DOMReady + * @private + * @description Flag to determine if DOM is ready or not + * @type Boolean + */ + DOMReady: null, + /** + * @property _selection + * @private + * @description Holder for caching iframe selections + * @type Object + */ + _selection: null, + /** + * @property _mask + * @private + * @description DOM Element holder for the editor Mask when disabled + * @type Object + */ + _mask: null, + /** + * @property _showingHiddenElements + * @private + * @description Status of the hidden elements button + * @type Boolean + */ + _showingHiddenElements: null, + /** + * @property currentWindow + * @description A reference to the currently open EditorWindow + * @type Object + */ + currentWindow: null, + /** + * @property currentEvent + * @description A reference to the current editor event + * @type Event + */ + currentEvent: null, + /** + * @property operaEvent + * @private + * @description setTimeout holder for Opera and Image DoubleClick event.. + * @type Object + */ + operaEvent: null, + /** + * @property currentFont + * @description A reference to the last font selected from the Toolbar + * @type HTMLElement + */ + currentFont: null, + /** + * @property currentElement + * @description A reference to the current working element in the editor + * @type Array + */ + currentElement: null, + /** + * @property dompath + * @description A reference to the dompath container for writing the current working dom path to. + * @type HTMLElement + */ + dompath: null, + /** + * @property beforeElement + * @description A reference to the H2 placed before the editor for Accessibilty. + * @type HTMLElement + */ + beforeElement: null, + /** + * @property afterElement + * @description A reference to the H2 placed after the editor for Accessibilty. + * @type HTMLElement + */ + afterElement: null, + /** + * @property invalidHTML + * @description Contains a list of HTML elements that are invalid inside the editor. They will be removed when they are found. If you set the value of a key to "{ keepContents: true }", then the element will be replaced with a yui-non span to be filtered out when cleanHTML is called. The only tag that is ignored here is the span tag as it will force the Editor into a loop and freeze the browser. However.. all of these tags will be removed in the cleanHTML routine. + * @type Object + */ + invalidHTML: { + form: true, + input: true, + button: true, + select: true, + link: true, + html: true, + body: true, + iframe: true, + script: true, + style: true, + textarea: true + }, + /** + * @property toolbar + * @description Local property containing the YAHOO.widget.Toolbar instance + * @type YAHOO.widget.Toolbar + */ + toolbar: null, + /** + * @private + * @property _contentTimer + * @description setTimeout holder for documentReady check + */ + _contentTimer: null, + /** + * @private + * @property _contentTimerMax + * @description The number of times the loaded content should be checked before giving up. Default: 500 + */ + _contentTimerMax: 500, + /** + * @private + * @property _contentTimerCounter + * @description Counter to check the number of times the body is polled for before giving up + * @type Number + */ + _contentTimerCounter: 0, + /** + * @private + * @property _disabled + * @description The Toolbar items that should be disabled if there is no selection present in the editor. + * @type Array + */ + _disabled: [ 'createlink', 'fontname', 'fontsize', 'forecolor', 'backcolor' ], + /** + * @private + * @property _alwaysDisabled + * @description The Toolbar items that should ALWAYS be disabled event if there is a selection present in the editor. + * @type Object + */ + _alwaysDisabled: { undo: true, redo: true }, + /** + * @private + * @property _alwaysEnabled + * @description The Toolbar items that should ALWAYS be enabled event if there isn't a selection present in the editor. + * @type Object + */ + _alwaysEnabled: { }, + /** + * @private + * @property _semantic + * @description The Toolbar commands that we should attempt to make tags out of instead of using styles. + * @type Object + */ + _semantic: { 'bold': true, 'italic' : true, 'underline' : true }, + /** + * @private + * @property _tag2cmd + * @description A tag map of HTML tags to convert to the different types of commands so we can select the proper toolbar button. + * @type Object + */ + _tag2cmd: { + 'b': 'bold', + 'strong': 'bold', + 'i': 'italic', + 'em': 'italic', + 'u': 'underline', + 'sup': 'superscript', + 'sub': 'subscript', + 'img': 'insertimage', + 'a' : 'createlink', + 'ul' : 'insertunorderedlist', + 'ol' : 'insertorderedlist' + }, + + /** + * @private _createIframe + * @description Creates the DOM and YUI Element for the iFrame editor area. + * @param {String} id The string ID to prefix the iframe with + * @return {Object} iFrame object + */ + _createIframe: function() { + var ifrmDom = document.createElement('iframe'); + ifrmDom.id = this.get('node').get('id') + '_editor'; + var config = { + border: '0', + frameBorder: '0', + marginWidth: '0', + marginHeight: '0', + leftMargin: '0', + topMargin: '0', + allowTransparency: 'true', + width: '100%' + }; + if (this.get('autoHeight')) { + config.scrolling = 'no'; + } + Y.each(config, function(v, k) { + ifrmDom.setAttribute(k, v); + }); + var isrc = 'javascript:;'; + if (this.browser.ie) { + //isrc = 'about:blank'; + //TODO - Check this, I have changed it before.. + isrc = 'javascript:false;'; + } + ifrmDom.setAttribute('src', isrc); + //var ifrm = new YAHOO.util.Element(ifrmDom); + var ifrm = Y.get(ifrmDom); + ifrm.setStyle('visibility', 'hidden'); + return ifrm; + }, + /** + * @private _isElement + * @description Checks to see if an Element reference is a valid one and has a certain tag type + * @param {HTMLElement} el The element to check + * @param {String} tag The tag that the element needs to be + * @return {Boolean} + */ + _isElement: function(el, tag) { + if (el && el.tagName && (el.tagName.toLowerCase() == tag)) { + return true; + } + if (el && el.getAttribute && (el.getAttribute('tag') == tag)) { + return true; + } + return false; + }, + /** + * @private _hasParent + * @description Checks to see if an Element reference or one of it's parents is a valid one and has a certain tag type + * @param {HTMLElement} el The element to check + * @param {String} tag The tag that the element needs to be + * @return HTMLElement + */ + _hasParent: function(el, tag) { + if (!el || !el.parentNode) { + return false; + } + + while (el.parentNode) { + if (this._isElement(el, tag)) { + return el; + } + if (el.parentNode) { + el = el.parentNode; + } else { + return false; + } + } + return false; + }, + /** + * @private + * @method _getDoc + * @description Get the Document of the IFRAME + * @return {Object} + */ + _getDoc: function() { + var value = false; + try { + var f = document.getElementById(this.get('iframe').get('id')); + if (f && f.contentWindow.document) { + value = f.contentWindow.document; + return value; + } + } catch (e) { + return false; + } + }, + /** + * @private + * @method _getWindow + * @description Get the Window of the IFRAME + * @return {Object} + */ + _getWindow: function() { + var f = document.getElementById(this.get('iframe').get('id')); + return f.contentWindow; + }, + /** + * @method focus + * @description Attempt to set the focus of the iframes window. + */ + focus: function() { + this._getWindow().focus(); + }, + /** + * @private + * @depreciated - This should not be used, moved to this.focus(); + * @method _focusWindow + * @description Attempt to set the focus of the iframes window. + */ + _focusWindow: function() { + YAHOO.log('_focusWindow: depreciated in favor of this.focus()', 'warn', 'Editor'); + this.focus(); + }, + /** + * @private + * @method _hasSelection + * @description Determines if there is a selection in the editor document. + * @return {Boolean} + */ + _hasSelection: function() { + var sel = this._getSelection(); + var range = this._getRange(); + var hasSel = false; + + if (!sel || !range) { + return hasSel; + } + + //Internet Explorer + if (this.browser.ie || this.browser.opera) { + if (range.text) { + hasSel = true; + } + if (range.html) { + hasSel = true; + } + } else { + if (this.browser.webkit) { + if (sel+'' !== '') { + hasSel = true; + } + } else { + if (sel && (sel.toString() !== '') && (sel !== undefined)) { + hasSel = true; + } + } + } + return hasSel; + }, + /** + * @private + * @method _getSelection + * @description Handles the different selection objects across the A-Grade list. + * @return {Object} Selection Object + */ + _getSelection: function() { + var _sel = null; + if (this._getDoc() && this._getWindow()) { + if (this._getDoc().selection) { + _sel = this._getDoc().selection; + } else { + _sel = this._getWindow().getSelection(); + } + //Handle Safari's lack of Selection Object + if (this.browser.webkit) { + if (_sel.baseNode) { + this._selection = {}; + this._selection.baseNode = _sel.baseNode; + this._selection.baseOffset = _sel.baseOffset; + this._selection.extentNode = _sel.extentNode; + this._selection.extentOffset = _sel.extentOffset; + } else if (this._selection !== null) { + _sel = this._getWindow().getSelection(); + _sel.setBaseAndExtent( + this._selection.baseNode, + this._selection.baseOffset, + this._selection.extentNode, + this._selection.extentOffset); + this._selection = null; + } + } + } + return _sel; + }, + /** + * @private + * @method _selectNode + * @description Places the highlight around a given node + * @param {HTMLElement} node The node to select + */ + _selectNode: function(node, collapse) { + if (!node) { + return false; + } + var sel = this._getSelection(), + range = null; + + if (this.browser.ie) { + try { //IE freaks out here sometimes.. + range = this._getDoc().body.createTextRange(); + range.moveToElementText(node); + range.select(); + } catch (e) { + YAHOO.log('IE failed to select element: ' + node.tagName, 'warn', 'SimpleEditor'); + } + } else if (this.browser.webkit) { + if (collapse) { + sel.setBaseAndExtent(node, 1, node, node.innerText.length); + } else { + sel.setBaseAndExtent(node, 0, node, node.innerText.length); + } + } else if (this.browser.opera) { + sel = this._getWindow().getSelection(); + range = this._getDoc().createRange(); + range.selectNode(node); + sel.removeAllRanges(); + sel.addRange(range); + } else { + range = this._getDoc().createRange(); + range.selectNodeContents(node); + sel.removeAllRanges(); + sel.addRange(range); + } + //TODO - Check Performance + this.nodeChange(); + }, + /** + * @private + * @method _getRange + * @description Handles the different range objects across the A-Grade list. + * @return {Object} Range Object + */ + _getRange: function() { + var sel = this._getSelection(); + + if (sel === null) { + return null; + } + + if (this.browser.webkit && !sel.getRangeAt) { + var _range = this._getDoc().createRange(); + try { + _range.setStart(sel.anchorNode, sel.anchorOffset); + _range.setEnd(sel.focusNode, sel.focusOffset); + } catch (e) { + _range = this._getWindow().getSelection()+''; + } + return _range; + } + + if (this.browser.ie || this.browser.opera) { + try { + return sel.createRange(); + } catch (e2) { + return null; + } + } + + if (sel.rangeCount > 0) { + return sel.getRangeAt(0); + } + return null; + }, + /** + * @private + * @method _setDesignMode + * @description Sets the designMode property of the iFrame document's body. + * @param {String} state This should be either on or off + */ + _setDesignMode: function(state) { + if (this.get('setDesignMode')) { + try { + this._getDoc().designMode = ((state.toLowerCase() == 'off') ? 'off' : 'on'); + } catch(e) { } + } + }, + /** + * @private + * @method _toggleDesignMode + * @description Toggles the designMode property of the iFrame document on and off. + * @return {String} The state that it was set to. + */ + _toggleDesignMode: function() { + YAHOO.log('It is not recommended to use this method and it will be depreciated.', 'warn', 'SimpleEditor'); + var _dMode = this._getDoc().designMode, + _state = ((_dMode.toLowerCase() == 'on') ? 'off' : 'on'); + this._setDesignMode(_state); + return _state; + }, + /** + * @private + * @property _focused + * @description Holder for trapping focus/blur state and prevent double events + * @type Boolean + */ + _focused: null, + /** + * @private + * @method _handleFocus + * @description Handles the focus of the iframe. Note, this is window focus event, not an Editor focus event. + * @param {Event} e The DOM Event + */ + _handleFocus: function(e) { + if (!this._focused) { + YAHOO.log('Editor Window Focused', 'info', 'SimpleEditor'); + this._focused = true; + this.fireEvent('editorWindowFocus', { type: 'editorWindowFocus', target: this }); + } + }, + /** + * @private + * @method _handleBlur + * @description Handles the blur of the iframe. Note, this is window blur event, not an Editor blur event. + * @param {Event} e The DOM Event + */ + _handleBlur: function(e) { + if (this._focused) { + YAHOO.log('Editor Window Blurred', 'info', 'SimpleEditor'); + this._focused = false; + this.fireEvent('editorWindowBlur', { type: 'editorWindowBlur', target: this }); + } + }, + /** + * @private + * @method _initEditorEvents + * @description This method sets up the listeners on the Editors document. + */ + _initEditorEvents: function() { + //Setup Listeners on iFrame + var doc = this._getDoc(), + win = this._getWindow(); + + Y.Event.nativeAdd(doc, 'mouseup', Y.bind(this._handleMouseUp, this)); + Y.Event.nativeAdd(doc, 'mousedown', Y.bind(this._handleMouseDown, this)); + Y.Event.nativeAdd(doc, 'click', Y.bind(this._handleClick, this)); + Y.Event.nativeAdd(doc, 'dblclick', Y.bind(this._handleDoubleClick, this)); + Y.Event.nativeAdd(doc, 'keypress', Y.bind(this._handleKeyPress, this)); + Y.Event.nativeAdd(doc, 'keyup', Y.bind(this._handleKeyUp, this)); + Y.Event.nativeAdd(doc, 'keydown', Y.bind(this._handleKeyDown, this)); + + //Focus and blur.. + Y.Event.nativeAdd(win, 'focus', Y.bind(this._handleFocus, this)); + Y.Event.nativeAdd(win, 'blur', Y.bind(this._handleBlur, this)); + }, + /** + * @private + * @method _removeEditorEvents + * @description This method removes the listeners on the Editors document (for disabling). + */ + _removeEditorEvents: function() { + //Remove Listeners on iFrame + var doc = this._getDoc(), + win = this._getWindow(); + + Y.Event.nativeRremove(doc, 'mouseup', Y.bind(this._handleMouseUp, this)); + Y.Event.nativeRremove(doc, 'mousedown', Y.bind(this._handleMouseDown, this)); + Y.Event.nativeRremove(doc, 'click', Y.bind(this._handleClick, this)); + Y.Event.nativeRremove(doc, 'dblclick', Y.bind(this._handleDoubleClick, this)); + Y.Event.nativeRremove(doc, 'keypress', Y.bind(this._handleKeyPress, this)); + Y.Event.nativeRremove(doc, 'keyup', Y.bind(this._handleKeyUp, this)); + Y.Event.nativeRremove(doc, 'keydown', Y.bind(this._handleKeyDown, this)); + + //Focus and blur.. + Y.Event.nativeRremove(win, 'focus', Y.bind(this._handleFocus, this)); + Y.Event.nativeRremove(win, 'blur', Y.bind(this._handleBlur, this)); + }, + _fixWebkitDivs: function() { + if (this.browser.webkit) { + var divs = this._getDoc().body.getElementsByTagName('div'); + Dom.addClass(divs, 'yui-wk-div'); + } + }, + /** + * @private + * @method _initEditor + * @param {Boolean} raw Don't add events. + * @description This method is fired from _checkLoaded when the document is ready. It turns on designMode and set's up the listeners. + */ + _initEditor: function(raw) { + if (this._editorInit) { + return; + } + this._editorInit = true; + if (this.browser.ie) { + this._getDoc().body.style.margin = '0'; + } + if (!this.get('disabled')) { + this._setDesignMode('on'); + this._contentTimerCounter = 0; + } + if (!this._getDoc().body) { + YAHOO.log('Body is null, check again', 'error', 'SimpleEditor'); + this._contentTimerCounter = 0; + this._editorInit = false; + this._checkLoaded(); + return false; + } + + YAHOO.log('editorLoaded', 'info', 'SimpleEditor'); + if (!raw) { + this.toolbar.on('buttonClick', Y.bind(this._handleToolbarClick, this)); + } + if (!this.get('disabled')) { + this._initEditorEvents(); + this.toolbar.set('disabled', false); + } + + if (raw) { + this.fire('editorContentReloaded', { type: 'editorreloaded'}); + } else { + this.fire('editorContentLoaded', { type: 'editorLoaded' }); + } + this._fixWebkitDivs(); + if (this.get('dompath')) { + YAHOO.log('Delayed DomPath write', 'info', 'SimpleEditor'); + Y.later(150, this, this._writeDomPath); + } + var br = []; + Y.each(this.browser, function(v, k) { + if (v) { + br.push(k); + } + }, this); + if (this.get('ptags')) { + br.push('ptags'); + } + Y.DOM.addClass(this._getDoc().body, br.join(' ')); + this.nodeChange(true); + }, + /** + * @private + * @method _checkLoaded + * @param {Boolean} raw Don't add events. + * @description Called from a setTimeout loop to check if the iframes body.onload event has fired, then it will init the editor. + */ + _checkLoaded: function(raw) { + this._editorInit = false; + this._contentTimerCounter++; + if (this._contentTimer) { + clearTimeout(this._contentTimer); + } + if (this._contentTimerCounter > this._contentTimerMax) { + YAHOO.log('ERROR: Body Did Not load', 'error', 'SimpleEditor'); + return false; + } + var init = false; + try { + if (this._getDoc() && this._getDoc().body) { + if (this.browser.ie) { + if (this._getDoc().body.readyState == 'complete') { + init = true; + } + } else { + if (this._getDoc().body._rteLoaded === true) { + init = true; + } + } + } + } catch (e) { + init = false; + YAHOO.log('checking body (e)' + e, 'error', 'SimpleEditor'); + } + + if (init === true) { + //The onload event has fired, clean up after ourselves and fire the _initEditor method + YAHOO.log('Firing _initEditor', 'info', 'SimpleEditor'); + this._initEditor(raw); + } else { + var self = this; + this._contentTimer = setTimeout(function() { + self._checkLoaded.call(self, raw); + }, 20); + } + }, + /** + * @private + * @method _setInitialContent + * @param {Boolean} raw Don't add events. + * @description This method will open the iframes content document and write the textareas value into it, then start the body.onload checking. + */ + _setInitialContent: function(raw) { + YAHOO.log('Populating editor body with contents of the text area', 'info', 'SimpleEditor'); + + var value = ((this._textarea) ? this.get('node').get('value') : this.get('node').get('innerHTML')), + doc = null; + + if (value === '') { + value = '
'; + } + + var html = Y.Lang.substitute(this.get('html'), { + TITLE: this.STR_TITLE, + CONTENT: this._cleanIncomingHTML(value), + CSS: this.get('css'), + HIDDEN_CSS: ((this.get('hiddencss')) ? this.get('hiddencss') : '/* No Hidden CSS */'), + EXTRA_CSS: ((this.get('extracss')) ? this.get('extracss') : '/* No Extra CSS */') + }), + check = true; + + html = html.replace(/RIGHT_BRACKET/gi, '{'); + html = html.replace(/LEFT_BRACKET/gi, '}'); + + if (document.compatMode != 'BackCompat') { + YAHOO.log('Adding Doctype to editable area', 'info', 'SimpleEditor'); + html = this._docType + "\n" + html; + } else { + YAHOO.log('DocType skipped because we are in BackCompat Mode.', 'warn', 'SimpleEditor'); + } + + if (this.browser.ie || this.browser.webkit || this.browser.opera || (navigator.userAgent.indexOf('Firefox/1.5') != -1)) { + //Firefox 1.5 doesn't like setting designMode on an document created with a data url + try { + //Adobe AIR Code + if (this.browser.air) { + doc = this._getDoc().implementation.createHTMLDocument(); + var origDoc = this._getDoc(); + origDoc.open(); + origDoc.close(); + doc.open(); + doc.write(html); + doc.close(); + var node = origDoc.importNode(doc.getElementsByTagName("html")[0], true); + origDoc.replaceChild(node, origDoc.getElementsByTagName("html")[0]); + origDoc.body._rteLoaded = true; + } else { + doc = this._getDoc(); + doc.open(); + doc.write(html); + doc.close(); + } + } catch (e) { + YAHOO.log('Setting doc failed.. (_setInitialContent)', 'error', 'SimpleEditor'); + //Safari will only be here if we are hidden + check = false; + } + } else { + //This keeps Firefox 2 from writing the iframe to history preserving the back buttons functionality + this.get('iframe').set('src', 'data:text/html;charset=utf-8,' + encodeURIComponent(html)); + } + this.get('iframe').setStyle('visibility', ''); + if (check) { + this._checkLoaded(raw); + } + }, + /** + * @private + * @method _setMarkupType + * @param {String} action The action to take. Possible values are: css, default or semantic + * @description This method will turn on/off the useCSS execCommand. + */ + _setMarkupType: function(action) { + switch (this.get('markup')) { + case 'css': + this._setEditorStyle(true); + break; + case 'default': + this._setEditorStyle(false); + break; + case 'semantic': + case 'xhtml': + if (this._semantic[action]) { + this._setEditorStyle(false); + } else { + this._setEditorStyle(true); + } + break; + } + }, + /** + * Set the editor to use CSS instead of HTML + * @param {Booleen} stat True/False + */ + _setEditorStyle: function(stat) { + try { + this._getDoc().execCommand('useCSS', false, !stat); + } catch (ex) { + } + }, + /** + * @private + * @method _getSelectedElement + * @description This method will attempt to locate the element that was last interacted with, either via selection, location or event. + * @return {HTMLElement} The currently selected element. + */ + _getSelectedElement: function() { + var doc = this._getDoc(), + range = null, + sel = null, + elm = null, + check = true; + + if (this.browser.ie) { + this.currentEvent = this._getWindow().event; //Event utility assumes window.event, so we need to reset it to this._getWindow().event; + range = this._getRange(); + if (range) { + elm = range.item ? range.item(0) : range.parentElement(); + if (this._hasSelection()) { + //TODO + //WTF.. Why can't I get an element reference here?!??! + } + if (elm === doc.body) { + elm = null; + } + } + if ((this.currentEvent !== null) && (this.currentEvent.keyCode === 0)) { + elm = Event.getTarget(this.currentEvent); + } + } else { + sel = this._getSelection(); + range = this._getRange(); + + if (!sel || !range) { + return null; + } + //TODO + if (!this._hasSelection() && this.browser.webkit3) { + //check = false; + } + if (this.browser.gecko) { + //Added in 2.6.0 + if (range.startContainer) { + if (range.startContainer.nodeType === 3) { + elm = range.startContainer.parentNode; + } else if (range.startContainer.nodeType === 1) { + elm = range.startContainer; + } + //Added in 2.7.0 + if (this.currentEvent) { + var tar = Event.getTarget(this.currentEvent); + if (!this._isElement(tar, 'html')) { + if (elm !== tar) { + elm = tar; + } + } + } + } + } + + if (check) { + if (sel.anchorNode && (sel.anchorNode.nodeType == 3)) { + if (sel.anchorNode.parentNode) { //next check parentNode + elm = sel.anchorNode.parentNode; + } + if (sel.anchorNode.nextSibling != sel.focusNode.nextSibling) { + elm = sel.anchorNode.nextSibling; + } + } + if (this._isElement(elm, 'br')) { + elm = null; + } + if (!elm) { + elm = range.commonAncestorContainer; + if (!range.collapsed) { + if (range.startContainer == range.endContainer) { + if (range.startOffset - range.endOffset < 2) { + if (range.startContainer.hasChildNodes()) { + elm = range.startContainer.childNodes[range.startOffset]; + } + } + } + } + } + } + } + + if (this.currentEvent !== null) { + try { + switch (this.currentEvent.type) { + case 'click': + case 'mousedown': + case 'mouseup': + if (this.browser.webkit) { + elm = Event.getTarget(this.currentEvent); + } + break; + default: + //Do nothing + break; + } + } catch (e) { + YAHOO.log('Firefox 1.5 errors here: ' + e, 'error', 'SimpleEditor'); + } + } else if ((this.currentElement && this.currentElement[0]) && (!this.browser.ie)) { + //TODO is this still needed? + //elm = this.currentElement[0]; + } + + + if (this.browser.opera || this.browser.webkit) { + if (this.currentEvent && !elm) { + elm = Event.getTarget(this.currentEvent); + } + } + if (!elm || !elm.tagName) { + elm = doc.body; + } + if (this._isElement(elm, 'html')) { + //Safari sometimes gives us the HTML node back.. + elm = doc.body; + } + if (this._isElement(elm, 'body')) { + //make sure that body means this body not the parent.. + elm = doc.body; + } + if (elm && !elm.parentNode) { //Not in document + elm = doc.body; + } + if (elm === undefined) { + elm = null; + } + return elm; + }, + /** + * @private + * @method _getSelectedNode + * @description Calls _getSelectedElement and passes it through Y.get to get a Node reference. + * @return {Y.Node} The currently selected element. + */ + _getSelectedNode: function() { + return Y.get(this._getSelectedElement()); + }, + /** + * @private + * @method _getDomPath + * @description This method will attempt to build the DOM path from the currently selected element. + * @param HTMLElement el The element to start with, if not provided _getSelectedElement is used + * @return {Array} An array of node references that will create the DOM Path. + */ + _getDomPath: function(el) { + if (!el) { + el = this._getSelectedElement(); + } + var domPath = []; + while (el !== null) { + if (el.ownerDocument != this._getDoc()) { + el = null; + break; + } + //Check to see if we get el.nodeName and nodeType + if (el.nodeName && el.nodeType && (el.nodeType == 1)) { + domPath[domPath.length] = el; + } + + if (this._isElement(el, 'body')) { + break; + } + + el = el.parentNode; + } + if (domPath.length === 0) { + if (this._getDoc() && this._getDoc().body) { + domPath[0] = this._getDoc().body; + } + } + return domPath.reverse(); + }, + /** + * @private + * @method _writeDomPath + * @description Write the current DOM path out to the dompath container below the editor. + */ + _writeDomPath: function() { + var path = this._getDomPath(), + pathArr = [], + classPath = '', + pathStr = ''; + + for (var i = 0; i < path.length; i++) { + var tag = path[i].tagName.toLowerCase(); + if ((tag == 'ol') && (path[i].type)) { + tag += ':' + path[i].type; + } + if (Dom.hasClass(path[i], 'yui-tag')) { + tag = path[i].getAttribute('tag'); + } + if ((this.get('markup') == 'semantic') || (this.get('markup') == 'xhtml')) { + switch (tag) { + case 'b': tag = 'strong'; break; + case 'i': tag = 'em'; break; + } + } + if (!Dom.hasClass(path[i], 'yui-non')) { + if (Dom.hasClass(path[i], 'yui-tag')) { + pathStr = tag; + } else { + classPath = ((path[i].className !== '') ? '.' + path[i].className.replace(/ /g, '.') : ''); + if ((classPath.indexOf('yui') != -1) || (classPath.toLowerCase().indexOf('apple-style-span') != -1)) { + classPath = ''; + } + pathStr = tag + ((path[i].id) ? '#' + path[i].id : '') + classPath; + } + switch (tag) { + case 'body': + pathStr = 'body'; + break; + case 'a': + if (path[i].getAttribute('href', 2)) { + pathStr += ':' + path[i].getAttribute('href', 2).replace('mailto:', '').replace('http:/'+'/', '').replace('https:/'+'/', ''); //May need to add others here ftp + } + break; + case 'img': + var h = path[i].height; + var w = path[i].width; + if (path[i].style.height) { + h = parseInt(path[i].style.height, 10); + } + if (path[i].style.width) { + w = parseInt(path[i].style.width, 10); + } + pathStr += '(' + w + 'x' + h + ')'; + break; + } + + if (pathStr.length > 10) { + pathStr = '' + pathStr.substring(0, 10) + '...' + ''; + } else { + pathStr = '' + pathStr + ''; + } + pathArr[pathArr.length] = pathStr; + } + } + var str = pathArr.join(' ' + this.SEP_DOMPATH + ' '); + //Prevent flickering + if (this.dompath.get('innerHTML') != str) { + this.dompath.set('innerHTML', str); + } + }, + /** + * @private + * @method _fixNodes + * @description Fix href and imgs as well as remove invalid HTML. + */ + _fixNodes: function() { + try { + var doc = this._getDoc(), + els = []; + + Y.each(this.invalidHTML, function(v, k) { + if (k.toLowerCase() != 'span') { + var tags = doc.body.getElementsByTagName(k); + if (tags.length) { + for (var i = 0; i < tags.length; i++) { + els.push(tags[i]); + } + } + } + }); + for (var h = 0; h < els.length; h++) { + if (els[h].parentNode) { + if (Lang.isObject(this.invalidHTML[els[h].tagName.toLowerCase()]) && this.invalidHTML[els[h].tagName.toLowerCase()].keepContents) { + this._swapEl(els[h], 'span', function(el) { + el.className = 'yui-non'; + }); + } else { + els[h].parentNode.removeChild(els[h]); + } + } + } + var imgs = this._getDoc().getElementsByTagName('img'); + Dom.addClass(imgs, 'yui-img'); + } catch(e) {} + }, + /** + * @private + * @method _isNonEditable + * @param Event ev The Dom event being checked + * @description Method is called at the beginning of all event handlers to check if this element or a parent element has the class yui-noedit (this.CLASS_NOEDIT) applied. + * If it does, then this method will stop the event and return true. The event handlers will then return false and stop the nodeChange from occuring. This method will also + * disable and enable the Editor's toolbar based on the noedit state. + * @return Boolean + */ + _isNonEditable: function(ev) { + if (this.get('allowNoEdit')) { + var el = Event.getTarget(ev); + if (this._isElement(el, 'html')) { + el = null; + } + var path = this._getDomPath(el); + for (var i = (path.length - 1); i > -1; i--) { + if (Dom.hasClass(path[i], this.CLASS_NOEDIT)) { + //if (this.toolbar.get('disabled') === false) { + // this.toolbar.set('disabled', true); + //} + try { + this._getDoc().execCommand('enableObjectResizing', false, 'false'); + } catch (e) {} + this.nodeChange(); + Event.stopEvent(ev); + YAHOO.log('CLASS_NOEDIT found in DOM Path, stopping event', 'info', 'SimpleEditor'); + return true; + } + } + //if (this.toolbar.get('disabled') === true) { + //Should only happen once.. + //this.toolbar.set('disabled', false); + try { + this._getDoc().execCommand('enableObjectResizing', false, 'true'); + } catch (e2) {} + //} + } + return false; + }, + /** + * @private + * @method _setCurrentEvent + * @param {Event} ev The event to cache + * @description Sets the current event property + */ + _setCurrentEvent: function(ev) { + this.currentEvent = ev; + }, + /** + * @private + * @method _handleClick + * @param {Event} ev The event we are working on. + * @description Handles all click events inside the iFrame document. + */ + _handleClick: function(ev) { + var ret = this.fireEvent('beforeEditorClick', { type: 'beforeEditorClick', target: this, ev: ev }); + if (ret === false) { + return false; + } + if (this._isNonEditable(ev)) { + return false; + } + this._setCurrentEvent(ev); + if (this.currentWindow) { + this.closeWindow(); + } + if (this.currentWindow) { + this.closeWindow(); + } + if (this.browser.webkit) { + var tar =Event.getTarget(ev); + if (this._isElement(tar, 'a') || this._isElement(tar.parentNode, 'a')) { + Event.stopEvent(ev); + this.nodeChange(); + } + } else { + this.nodeChange(); + } + this.fireEvent('editorClick', { type: 'editorClick', target: this, ev: ev }); + }, + /** + * @private + * @method _handleMouseUp + * @param {Event} ev The event we are working on. + * @description Handles all mouseup events inside the iFrame document. + */ + _handleMouseUp: function(ev) { + var ret = this.fireEvent('beforeEditorMouseUp', { type: 'beforeEditorMouseUp', target: this, ev: ev }); + if (ret === false) { + return false; + } + if (this._isNonEditable(ev)) { + return false; + } + //Don't set current event for mouseup. + //It get's fired after a menu is closed and gives up a bogus event to work with + //this._setCurrentEvent(ev); + var self = this; + if (this.browser.opera) { + /* + * @knownissue Opera appears to stop the MouseDown, Click and DoubleClick events on an image inside of a document with designMode on.. + * @browser Opera + * @description This work around traps the MouseUp event and sets a timer to check if another MouseUp event fires in so many seconds. If another event is fired, they we internally fire the DoubleClick event. + */ + var sel = Event.getTarget(ev); + if (this._isElement(sel, 'img')) { + this.nodeChange(); + if (this.operaEvent) { + clearTimeout(this.operaEvent); + this.operaEvent = null; + this._handleDoubleClick(ev); + } else { + this.operaEvent = window.setTimeout(function() { + self.operaEvent = false; + }, 700); + } + } + } + //This will stop Safari from selecting the entire document if you select all the text in the editor + if (this.browser.webkit || this.browser.opera) { + if (this.browser.webkit) { + Event.stopEvent(ev); + } + } + this.nodeChange(); + this.fireEvent('editorMouseUp', { type: 'editorMouseUp', target: this, ev: ev }); + }, + /** + * @private + * @method _handleMouseDown + * @param {Event} ev The event we are working on. + * @description Handles all mousedown events inside the iFrame document. + */ + _handleMouseDown: function(ev) { + var ret = this.fireEvent('beforeEditorMouseDown', { type: 'beforeEditorMouseDown', target: this, ev: ev }); + if (ret === false) { + return false; + } + if (this._isNonEditable(ev)) { + return false; + } + this._setCurrentEvent(ev); + var sel = Event.getTarget(ev); + if (this.browser.webkit && this._hasSelection()) { + var _sel = this._getSelection(); + if (!this.browser.webkit3) { + _sel.collapse(true); + } else { + _sel.collapseToStart(); + } + } + if (this.browser.webkit && this._lastImage) { + Dom.removeClass(this._lastImage, 'selected'); + this._lastImage = null; + } + if (this._isElement(sel, 'img') || this._isElement(sel, 'a')) { + if (this.browser.webkit) { + Event.stopEvent(ev); + if (this._isElement(sel, 'img')) { + Dom.addClass(sel, 'selected'); + this._lastImage = sel; + } + } + if (this.currentWindow) { + this.closeWindow(); + } + this.nodeChange(); + } + this.fireEvent('editorMouseDown', { type: 'editorMouseDown', target: this, ev: ev }); + }, + /** + * @private + * @method _handleDoubleClick + * @param {Event} ev The event we are working on. + * @description Handles all doubleclick events inside the iFrame document. + */ + _handleDoubleClick: function(ev) { + var ret = this.fireEvent('beforeEditorDoubleClick', { type: 'beforeEditorDoubleClick', target: this, ev: ev }); + if (ret === false) { + return false; + } + if (this._isNonEditable(ev)) { + return false; + } + this._setCurrentEvent(ev); + var sel = Event.getTarget(ev); + if (this._isElement(sel, 'img')) { + this.currentElement[0] = sel; + this.toolbar.fireEvent('insertimageClick', { type: 'insertimageClick', target: this.toolbar }); + this.fireEvent('afterExecCommand', { type: 'afterExecCommand', target: this }); + } else if (this._hasParent(sel, 'a')) { //Handle elements inside an a + this.currentElement[0] = this._hasParent(sel, 'a'); + this.toolbar.fireEvent('createlinkClick', { type: 'createlinkClick', target: this.toolbar }); + this.fireEvent('afterExecCommand', { type: 'afterExecCommand', target: this }); + } + this.nodeChange(); + this.fireEvent('editorDoubleClick', { type: 'editorDoubleClick', target: this, ev: ev }); + }, + /** + * @private + * @method _handleKeyUp + * @param {Event} ev The event we are working on. + * @description Handles all keyup events inside the iFrame document. + */ + _handleKeyUp: function(ev) { + var ret = this.fireEvent('beforeEditorKeyUp', { type: 'beforeEditorKeyUp', target: this, ev: ev }); + if (ret === false) { + return false; + } + if (this._isNonEditable(ev)) { + return false; + } + this._setCurrentEvent(ev); + switch (ev.keyCode) { + case this._keyMap.SELECT_ALL.key: + if (this._checkKey(this._keyMap.SELECT_ALL, ev)) { + this.nodeChange(); + } + break; + case 32: //Space Bar + case 35: //End + case 36: //Home + case 37: //Left Arrow + case 38: //Up Arrow + case 39: //Right Arrow + case 40: //Down Arrow + case 46: //Forward Delete + case 8: //Delete + case this._keyMap.CLOSE_WINDOW.key: //W key if window is open + if ((ev.keyCode == this._keyMap.CLOSE_WINDOW.key) && this.currentWindow) { + if (this._checkKey(this._keyMap.CLOSE_WINDOW, ev)) { + this.closeWindow(); + } + } else { + if (!this.browser.ie) { + if (this._nodeChangeTimer) { + clearTimeout(this._nodeChangeTimer); + } + var self = this; + this._nodeChangeTimer = setTimeout(function() { + self._nodeChangeTimer = null; + self.nodeChange.call(self); + }, 100); + } else { + this.nodeChange(); + } + this.editorDirty = true; + } + break; + } + this.fireEvent('editorKeyUp', { type: 'editorKeyUp', target: this, ev: ev }); + this._storeUndo(); + }, + /** + * @private + * @method _handleKeyPress + * @param {Event} ev The event we are working on. + * @description Handles all keypress events inside the iFrame document. + */ + _handleKeyPress: function(ev) { + var ret = this.fireEvent('beforeEditorKeyPress', { type: 'beforeEditorKeyPress', target: this, ev: ev }); + if (ret === false) { + return false; + } + + if (this.get('allowNoEdit')) { + //if (ev && ev.keyCode && ((ev.keyCode == 46) || ev.keyCode == 63272)) { + if (ev && ev.keyCode && (ev.keyCode == 63272)) { + //Forward delete key + YAHOO.log('allowNoEdit is set, forward delete key has been disabled', 'warn', 'SimpleEditor'); + Event.stopEvent(ev); + } + } + if (this._isNonEditable(ev)) { + return false; + } + this._setCurrentEvent(ev); + if (this.browser.opera) { + if (ev.keyCode === 13) { + var tar = this._getSelectedElement(); + if (!this._isElement(tar, 'li')) { + this.execCommand('inserthtml', '
'); + Event.stopEvent(ev); + } + } + } + if (this.browser.webkit) { + if (!this.browser.webkit3) { + if (ev.keyCode && (ev.keyCode == 122) && (ev.metaKey)) { + //This is CMD + z (for undo) + if (this._hasParent(this._getSelectedElement(), 'li')) { + YAHOO.log('We are in an LI and we found CMD + z, stopping the event', 'warn', 'SimpleEditor'); + Event.stopEvent(ev); + } + } + } + this._listFix(ev); + } + this._fixListDupIds(); + this.fireEvent('editorKeyPress', { type: 'editorKeyPress', target: this, ev: ev }); + }, + /** + * @private + * @method _handleKeyDown + * @param {Event} ev The event we are working on. + * @description Handles all keydown events inside the iFrame document. + */ + _handleKeyDown: function(ev) { + var ret = this.fireEvent('beforeEditorKeyDown', { type: 'beforeEditorKeyDown', target: this, ev: ev }); + if (ret === false) { + return false; + } + var tar = null, _range = null; + if (this._isNonEditable(ev)) { + return false; + } + this._setCurrentEvent(ev); + if (this.currentWindow) { + this.closeWindow(); + } + if (this.currentWindow) { + this.closeWindow(); + } + var doExec = false, + action = null, + value = null, + exec = false; + + //YAHOO.log('keyCode: ' + ev.keyCode, 'info', 'SimpleEditor'); + + switch (ev.keyCode) { + case this._keyMap.FOCUS_TOOLBAR.key: + if (this._checkKey(this._keyMap.FOCUS_TOOLBAR, ev)) { + var h = this.toolbar.getElementsByTagName('h2')[0]; + if (h && h.firstChild) { + h.firstChild.focus(); + } + } else if (this._checkKey(this._keyMap.FOCUS_AFTER, ev)) { + //Focus After Element - Esc + this.afterElement.focus(); + } + Event.stopEvent(ev); + doExec = false; + break; + //case 76: //L + case this._keyMap.CREATE_LINK.key: //L + if (this._hasSelection()) { + if (this._checkKey(this._keyMap.CREATE_LINK, ev)) { + var makeLink = true; + if (this.get('limitCommands')) { + if (!this.toolbar.getButtonByValue('createlink')) { + YAHOO.log('Toolbar Button for (createlink) was not found, skipping exec.', 'info', 'SimpleEditor'); + makeLink = false; + } + } + if (makeLink) { + this.execCommand('createlink', ''); + this.toolbar.fireEvent('createlinkClick', { type: 'createlinkClick', target: this.toolbar }); + this.fireEvent('afterExecCommand', { type: 'afterExecCommand', target: this }); + doExec = false; + } + } + } + break; + //case 90: //Z + case this._keyMap.UNDO.key: + case this._keyMap.REDO.key: + if (this._checkKey(this._keyMap.REDO, ev)) { + action = 'redo'; + doExec = true; + } else if (this._checkKey(this._keyMap.UNDO, ev)) { + action = 'undo'; + doExec = true; + } + break; + //case 66: //B + case this._keyMap.BOLD.key: + if (this._checkKey(this._keyMap.BOLD, ev)) { + action = 'bold'; + doExec = true; + } + break; + case this._keyMap.FONT_SIZE_UP.key: + case this._keyMap.FONT_SIZE_DOWN.key: + var uk = false, dk = false; + if (this._checkKey(this._keyMap.FONT_SIZE_UP, ev)) { + uk = true; + } + if (this._checkKey(this._keyMap.FONT_SIZE_DOWN, ev)) { + dk = true; + } + if (uk || dk) { + var fs_button = this.toolbar.getButtonByValue('fontsize'), + label = parseInt(fs_button.get('label'), 10), + newValue = (label + 1); + + if (dk) { + newValue = (label - 1); + } + + action = 'fontsize'; + value = newValue + 'px'; + doExec = true; + } + break; + //case 73: //I + case this._keyMap.ITALIC.key: + if (this._checkKey(this._keyMap.ITALIC, ev)) { + action = 'italic'; + doExec = true; + } + break; + //case 85: //U + case this._keyMap.UNDERLINE.key: + if (this._checkKey(this._keyMap.UNDERLINE, ev)) { + action = 'underline'; + doExec = true; + } + break; + case 9: + if (this.browser.ie) { + //Insert a tab in Internet Explorer + _range = this._getRange(); + tar = this._getSelectedElement(); + if (!this._isElement(tar, 'li')) { + if (_range) { + _range.pasteHTML(' '); + _range.collapse(false); + _range.select(); + } + Event.stopEvent(ev); + } + } + //Firefox 3 code + if (this.browser.gecko > 1.8) { + tar = this._getSelectedElement(); + if (this._isElement(tar, 'li')) { + if (ev.shiftKey) { + this._getDoc().execCommand('outdent', null, ''); + } else { + this._getDoc().execCommand('indent', null, ''); + } + + } else if (!this._hasSelection()) { + this.execCommand('inserthtml', ' '); + } + Event.stopEvent(ev); + } + break; + case 13: + var p = null, i = 0; + if (this.get('ptags') && !ev.shiftKey) { + if (this.browser.gecko) { + tar = this._getSelectedElement(); + if (!this._hasParent(tar, 'li')) { + if (this._hasParent(tar, 'p')) { + p = this._getDoc().createElement('p'); + p.innerHTML = ' '; + Dom.insertAfter(p, tar); + this._selectNode(p.firstChild); + } else if (this._isElement(tar, 'body')) { + this.execCommand('insertparagraph', null); + var ps = this._getDoc().body.getElementsByTagName('p'); + for (i = 0; i < ps.length; i++) { + if (ps[i].getAttribute('_moz_dirty') !== null) { + p = this._getDoc().createElement('p'); + p.innerHTML = ' '; + Dom.insertAfter(p, ps[i]); + this._selectNode(p.firstChild); + ps[i].removeAttribute('_moz_dirty'); + } + } + } else { + YAHOO.log('Something went wrong with paragraphs, please file a bug!!', 'error', 'SimpleEditor'); + doExec = true; + action = 'insertparagraph'; + } + Event.stopEvent(ev); + } + } + if (this.browser.webkit) { + tar = this._getSelectedElement(); + if (!this._hasParent(tar, 'li')) { + this.execCommand('insertparagraph', null); + var divs = this._getDoc().body.getElementsByTagName('div'); + for (i = 0; i < divs.length; i++) { + if (!Dom.hasClass(divs[i], 'yui-wk-div')) { + Dom.addClass(divs[i], 'yui-wk-p'); + } + } + Event.stopEvent(ev); + } + } + } else { + if (this.browser.webkit) { + tar = this._getSelectedElement(); + if (!this._hasParent(tar, 'li')) { + if (this.browser.webkit4) { + this.execCommand('insertlinebreak'); + } else { + this.execCommand('inserthtml', ''); + var holder = this._getDoc().getElementById('yui-br'), + br = this._getDoc().createElement('br'), + caret = this._getDoc().createElement('span'); + + holder.parentNode.replaceChild(br, holder); + caret.className = 'yui-non'; + caret.innerHTML = ' '; + Dom.insertAfter(caret, br); + this._selectNode(caret); + } + Event.stopEvent(ev); + } + } + if (this.browser.ie) { + YAHOO.log('Stopping P tags', 'info', 'SimpleEditor'); + //Insert a
instead of a in Internet Explorer + _range = this._getRange(); + tar = this._getSelectedElement(); + if (!this._isElement(tar, 'li')) { + if (_range) { + _range.pasteHTML('
'); + _range.collapse(false); + _range.select(); + } + Event.stopEvent(ev); + } + } + } + break; + } + if (this.browser.ie) { + this._listFix(ev); + } + if (doExec && action) { + this.execCommand(action, value); + Event.stopEvent(ev); + this.nodeChange(); + } + this.fireEvent('editorKeyDown', { type: 'editorKeyDown', target: this, ev: ev }); + }, + /** + * @private + * @property _fixListRunning + * @type Boolean + * @description Keeps more than one _fixListDupIds from running at the same time. + */ + _fixListRunning: null, + /** + * @private + * @method _fixListDupIds + * @description Some browsers will duplicate the id of an LI when created in designMode. + * This method will fix the duplicate id issue. However it will only preserve the first element + * in the document list with the unique id. + */ + _fixListDupIds: function() { + if (this._fixListRunning) { + return false; + } + if (this._getDoc()) { + this._fixListRunning = true; + var lis = this._getDoc().body.getElementsByTagName('li'), + i = 0, ids = {}; + for (i = 0; i < lis.length; i++) { + if (lis[i].id) { + if (ids[lis[i].id]) { + lis[i].id = ''; + } + ids[lis[i].id] = true; + } + } + this._fixListRunning = false; + } + }, + /** + * @private + * @method _listFix + * @param {Event} ev The event we are working on. + * @description Handles the Enter key, Tab Key and Shift + Tab keys for List Items. + */ + _listFix: function(ev) { + //YAHOO.log('Lists Fix (' + ev.keyCode + ')', 'info', 'SimpleEditor'); + var testLi = null, par = null, preContent = false, range = null; + //Enter Key + if (this.browser.webkit) { + if (ev.keyCode && (ev.keyCode == 13)) { + if (this._hasParent(this._getSelectedElement(), 'li')) { + var tar = this._hasParent(this._getSelectedElement(), 'li'); + if (tar.previousSibling) { + if (tar.firstChild && (tar.firstChild.length == 1)) { + this._selectNode(tar); + } + } + } + } + } + //Shift + Tab Key + if (ev.keyCode && ((!this.browser.webkit3 && (ev.keyCode == 25)) || ((this.browser.webkit3 || !this.browser.webkit) && ((ev.keyCode == 9) && ev.shiftKey)))) { + testLi = this._getSelectedElement(); + if (this._hasParent(testLi, 'li')) { + testLi = this._hasParent(testLi, 'li'); + YAHOO.log('We have a SHIFT tab in an LI, reverse it..', 'info', 'SimpleEditor'); + if (this._hasParent(testLi, 'ul') || this._hasParent(testLi, 'ol')) { + YAHOO.log('We have a double parent, move up a level', 'info', 'SimpleEditor'); + par = this._hasParent(testLi, 'ul'); + if (!par) { + par = this._hasParent(testLi, 'ol'); + } + //YAHOO.log(par.previousSibling + ' :: ' + par.previousSibling.innerHTML); + if (this._isElement(par.previousSibling, 'li')) { + par.removeChild(testLi); + par.parentNode.insertBefore(testLi, par.nextSibling); + if (this.browser.ie) { + range = this._getDoc().body.createTextRange(); + range.moveToElementText(testLi); + range.collapse(false); + range.select(); + } + if (this.browser.webkit) { + this._selectNode(testLi.firstChild); + } + Event.stopEvent(ev); + } + } + } + } + //Tab Key + if (ev.keyCode && ((ev.keyCode == 9) && (!ev.shiftKey))) { + YAHOO.log('List Fix - Tab', 'info', 'SimpleEditor'); + var preLi = this._getSelectedElement(); + if (this._hasParent(preLi, 'li')) { + preContent = this._hasParent(preLi, 'li').innerHTML; + } + //YAHOO.log('preLI: ' + preLi.tagName + ' :: ' + preLi.innerHTML); + if (this.browser.webkit) { + this._getDoc().execCommand('inserttext', false, '\t'); + } + testLi = this._getSelectedElement(); + if (this._hasParent(testLi, 'li')) { + YAHOO.log('We have a tab in an LI', 'info', 'SimpleEditor'); + par = this._hasParent(testLi, 'li'); + YAHOO.log('parLI: ' + par.tagName + ' :: ' + par.innerHTML); + var newUl = this._getDoc().createElement(par.parentNode.tagName.toLowerCase()); + if (this.browser.webkit) { + var span = Dom.getElementsByClassName('Apple-tab-span', 'span', par); + //Remove the span element that Safari puts in + if (span[0]) { + par.removeChild(span[0]); + par.innerHTML = Lang.trim(par.innerHTML); + //Put the HTML from the LI into this new LI + if (preContent) { + par.innerHTML = '' + preContent + ' '; + } else { + par.innerHTML = ' '; + } + } + } else { + if (preContent) { + par.innerHTML = preContent + ' '; + } else { + par.innerHTML = ' '; + } + } + + par.parentNode.replaceChild(newUl, par); + newUl.appendChild(par); + if (this.browser.webkit) { + this._getSelection().setBaseAndExtent(par.firstChild, 1, par.firstChild, par.firstChild.innerText.length); + if (!this.browser.webkit3) { + par.parentNode.parentNode.style.display = 'list-item'; + setTimeout(function() { + par.parentNode.parentNode.style.display = 'block'; + }, 1); + } + } else if (this.browser.ie) { + range = this._getDoc().body.createTextRange(); + range.moveToElementText(par); + range.collapse(false); + range.select(); + } else { + this._selectNode(par); + } + Event.stopEvent(ev); + } + if (this.browser.webkit) { + Event.stopEvent(ev); + } + this.nodeChange(); + } + }, + /** + * @method nodeChange + * @param {Boolean} force Optional paramenter to skip the threshold counter + * @description Handles setting up the toolbar buttons, getting the Dom path, fixing nodes. + */ + nodeChange: function(force) { + var NCself = this; + this._storeUndo(); + if (this.get('nodeChangeDelay')) { + this._nodeChangeDelayTimer = window.setTimeout(function() { + NCself._nodeChangeDelayTimer = null; + NCself._nodeChange.apply(NCself, arguments); + }, 0); + } else { + this._nodeChange(); + } + }, + /** + * @private + * @method _nodeChange + * @param {Boolean} force Optional paramenter to skip the threshold counter + * @description Fired from nodeChange in a setTimeout. + */ + _nodeChange: function(force) { + var threshold = parseInt(this.get('nodeChangeThreshold'), 10), + thisNodeChange = Math.round(new Date().getTime() / 1000), + self = this; + + if (force === true) { + this._lastNodeChange = 0; + } + + if ((this._lastNodeChange + threshold) < thisNodeChange) { + if (this._fixNodesTimer === null) { + this._fixNodesTimer = window.setTimeout(function() { + self._fixNodes.call(self); + self._fixNodesTimer = null; + }, 0); + } + } + this._lastNodeChange = thisNodeChange; + if (this.currentEvent) { + try { + this._lastNodeChangeEvent = this.currentEvent.type; + } catch (e) {} + } + + var beforeNodeChange = this.fire('beforeNodeChange', { type: 'beforeNodeChange' }); + if (beforeNodeChange === false) { + return false; + } + if (this.get('dompath')) { + Y.later(0, this, this._writeDomPath); + } + //Check to see if we are disabled before continuing + if (!this.get('disabled')) { + if (this.STOP_NODE_CHANGE) { + //Reset this var for next action + this.STOP_NODE_CHANGE = false; + return false; + } else { + var sel = this._getSelection(), + range = this._getRange(), + el = this._getSelectedElement(), + fn_button = this.toolbar.getButtonByValue('fontname'), + fs_button = this.toolbar.getButtonByValue('fontsize'), + undo_button = this.toolbar.getButtonByValue('undo'), + redo_button = this.toolbar.getButtonByValue('redo'); + + //Handle updating the toolbar with active buttons + var _ex = {}; + if (this._lastButton) { + _ex[this._lastButton.id] = true; + //this._lastButton = null; + } + if (!this._isElement(el, 'body')) { + if (fn_button) { + _ex[fn_button.get('id')] = true; + } + if (fs_button) { + _ex[fs_button.get('id')] = true; + } + } + if (redo_button) { + delete _ex[redo_button.get('id')]; + } + this.toolbar.resetAllButtons(_ex); + + //Handle disabled buttons + for (var d = 0; d < this._disabled.length; d++) { + var _button = this.toolbar.getButtonByValue(this._disabled[d]); + if (_button && _button.get) { + if (this._lastButton && (_button.get('id') === this._lastButton.id)) { + //Skip + } else { + if (!this._hasSelection() && !this.get('insert')) { + switch (this._disabled[d]) { + case 'fontname': + case 'fontsize': + break; + default: + //No Selection - disable + this.toolbar.disableButton(_button); + } + } else { + if (!this._alwaysDisabled[this._disabled[d]]) { + this.toolbar.enableButton(_button); + } + } + if (!this._alwaysEnabled[this._disabled[d]]) { + this.toolbar.deselectButton(_button); + } + } + } + } + var path = this._getDomPath(); + var tag = null, cmd = null; + for (var i = 0; i < path.length; i++) { + tag = path[i].tagName.toLowerCase(); + if (path[i].getAttribute('tag')) { + tag = path[i].getAttribute('tag').toLowerCase(); + } + cmd = this._tag2cmd[tag]; + if (cmd === undefined) { + cmd = []; + } + if (!Lang.isArray(cmd)) { + cmd = [cmd]; + } + + //Bold and Italic styles + if (path[i].style.fontWeight.toLowerCase() == 'bold') { + cmd[cmd.length] = 'bold'; + } + if (path[i].style.fontStyle.toLowerCase() == 'italic') { + cmd[cmd.length] = 'italic'; + } + if (path[i].style.textDecoration.toLowerCase() == 'underline') { + cmd[cmd.length] = 'underline'; + } + if (path[i].style.textDecoration.toLowerCase() == 'line-through') { + cmd[cmd.length] = 'strikethrough'; + } + if (cmd.length > 0) { + for (var j = 0; j < cmd.length; j++) { + this.toolbar.selectButton(cmd[j]); + this.toolbar.enableButton(cmd[j]); + } + } + //Handle Alignment + switch (path[i].style.textAlign.toLowerCase()) { + case 'left': + case 'right': + case 'center': + case 'justify': + var alignType = path[i].style.textAlign.toLowerCase(); + if (path[i].style.textAlign.toLowerCase() == 'justify') { + alignType = 'full'; + } + this.toolbar.selectButton('justify' + alignType); + this.toolbar.enableButton('justify' + alignType); + break; + } + } + //After for loop + + //Reset Font Family and Size to the inital configs + if (fn_button) { + var family = fn_button._conf.data.initValue.label; + fn_button.set('label', ' '); + this._updateMenuChecked('fontname', family); + } + + if (fs_button) { + fs_button.set('label', fs_button._conf.data.initValue.label); + } + + var hd_button = this.toolbar.getButtonByValue('heading'); + if (hd_button) { + hd_button.set('label', hd_button._conf.data.initValue.label); + this._updateMenuChecked('heading', 'none'); + } + var img_button = this.toolbar.getButtonByValue('insertimage'); + if (img_button && this.currentWindow && (this.currentWindow.name == 'insertimage')) { + this.toolbar.disableButton(img_button); + } + if (this._lastButton && this._lastButton.isSelected) { + this.toolbar.deselectButton(this._lastButton.id); + } + this._undoNodeChange(); + } + } + + this.fire('afterNodeChange', { type: 'afterNodeChange' }); + }, + /** + * @private + * @method _updateMenuChecked + * @param {Object} button The command identifier of the button you want to check + * @param {String} value The value of the menu item you want to check + * @param {YAHOO.widget.Toolbar} The Toolbar instance the button belongs to (defaults to this.toolbar) + * @description Gets the menu from a button instance, if the menu is not rendered it will render it. It will then search the menu for the specified value, unchecking all other items and checking the specified on. + */ + _updateMenuChecked: function(button, value, tbar) { + if (!tbar) { + tbar = this.toolbar; + } + var _button = tbar.getButtonByValue(button); + _button.checkValue(value); + }, + /** + * @private + * @method _handleToolbarClick + * @param {Event} ev The event that triggered the button click + * @description This is an event handler attached to the Toolbar's buttonClick event. It will fire execCommand with the command identifier from the Toolbar Button. + */ + _handleToolbarClick: function(ev) { + var value = ''; + var str = ''; + var cmd = ev.button.value; + if (ev.button.menucmd) { + value = cmd; + cmd = ev.button.menucmd; + } + this._lastButton = ev.button; + if (this.STOP_EXEC_COMMAND) { + YAHOO.log('execCommand skipped because we found the STOP_EXEC_COMMAND flag set to true', 'warn', 'SimpleEditor'); + YAHOO.log('NOEXEC::execCommand::(' + cmd + '), (' + value + ')', 'warn', 'SimpleEditor'); + this.STOP_EXEC_COMMAND = false; + return false; + } else { + this.execCommand(cmd, value); + if (!this.browser.webkit) { + var Fself = this; + setTimeout(function() { + Fself.focus.call(Fself); + }, 5); + } + } + Event.stopEvent(ev); + }, + /** + * @private + * @method _setupAfterElement + * @description Creates the accessibility h2 header and places it after the iframe in the Dom for navigation. + */ + _setupAfterElement: function() { + if (!this.beforeElement) { + this.beforeElement = Y.Node.create(''); + this.beforeElement.set('innerHTML', this.STR_BEFORE_EDITOR); + this.get('element_cont').query('.first-child').insertBefore(this.beforeElement, this.toolbar.get('node').get('nextSibling')); + } + if (!this.afterElement) { + this.afterElement = Y.Node.create('' + this.STR_LEAVE_EDITOR + '
'); + this.get('element_cont').get('firstChild').appendChild(this.afterElement); + } + }, + /** + * @private + * @method _disableEditor + * @param {Boolean} disabled Pass true to disable, false to enable + * @description Creates a mask to place over the Editor. + */ + _disableEditor: function(disabled) { + var iframe, par, html, height; + if (!this.get('disabled_iframe') && disabled) { + iframe = this._createIframe(); + iframe.set('id', 'disabled_' + this.get('iframe').get('id')); + iframe.setStyle('height', '100%'); + iframe.setStyle('display', 'none'); + iframe.setStyle('visibility', 'visible'); + this.set('disabled_iframe', iframe); + par = this.get('iframe').get('parentNode'); + par.appendChild(iframe); + } + if (!iframe) { + iframe = this.get('disabled_iframe'); + } + if (disabled) { + this._orgIframe = this.get('iframe'); + + if (this.toolbar) { + this.toolbar.set('disabled', true); + } + + html = this.getEditorHTML(); + height = this.get('iframe').get('offsetHeight'); + iframe.setStyle('visibility', ''); + iframe.setStyle('position', ''); + iframe.setStyle('top', ''); + iframe.setStyle('left', ''); + this._orgIframe.setStyle('visibility', 'hidden'); + this._orgIframe.setStyle('position', 'absolute'); + this._orgIframe.setStyle('top', '-99999px'); + this._orgIframe.setStyle('left', '-99999px'); + this.set('iframe', iframe); + this._setInitialContent(true); + + if (!this._mask) { + this._mask = Y.Node.create(''); + if (this.browser.ie) { + this._mask.setStyle('height', height + 'px'); + } + this.get('iframe').get('parentNode').appendChild(this._mask); + } + this.on('editorContentReloaded', function() { + this._getDoc().body._rteLoaded = false; + this.setEditorHTML(html); + iframe.setStyle('display', 'block'); + }); + } else { + if (this._mask) { + this._mask.get('parentNode').removeChild(this._mask); + this._mask = null; + if (this.toolbar) { + this.toolbar.set('disabled', false); + } + iframe.setStyle('visibility', 'hidden'); + iframe.setStyle('position', 'absolute'); + iframe.setStyle('top', '-99999px'); + iframe.setStyle('left', '-99999px'); + this._orgIframe.setStyle('visibility', ''); + this._orgIframe.setStyle('position', ''); + this._orgIframe.setStyle('top', ''); + this._orgIframe.setStyle('left', ''); + this.set('iframe', this._orgIframe); + + this.focus(); + Y.later(100, this, this.nodeChange); + } + } + }, + /** + * @property SEP_DOMPATH + * @description The value to place in between the Dom path items + * @type String + */ + SEP_DOMPATH: '<', + /** + * @property STR_LEAVE_EDITOR + * @description The accessibility string for the element after the iFrame + * @type String + */ + STR_LEAVE_EDITOR: 'You have left the Rich Text Editor.', + /** + * @property STR_BEFORE_EDITOR + * @description The accessibility string for the element before the iFrame + * @type String + */ + STR_BEFORE_EDITOR: 'This text field can contain stylized text and graphics. To cycle through all formatting options, use the keyboard shortcut Shift + Escape to place focus on the toolbar and navigate between options with your arrow keys. To exit this text editor use the Escape key and continue tabbing.Common formatting keyboard shortcuts:
', + /** + * @property STR_TITLE + * @description The Title of the HTML document that is created in the iFrame + * @type String + */ + STR_TITLE: 'Rich Text Area.', + /** + * @property STR_IMAGE_HERE + * @description The text to place in the URL textbox when using the blankimage. + * @type String + */ + STR_IMAGE_HERE: 'Image URL Here', + /** + * @property STR_IMAGE_URL + * @description The label string for Image URL + * @type String + */ + STR_IMAGE_URL: 'Image URL', + /** + * @property STR_LINK_URL + * @description The label string for the Link URL. + * @type String + */ + STR_LINK_URL: 'Link URL', + /** + * @protected + * @property STOP_EXEC_COMMAND + * @description Set to true when you want the default execCommand function to not process anything + * @type Boolean + */ + STOP_EXEC_COMMAND: false, + /** + * @protected + * @property STOP_NODE_CHANGE + * @description Set to true when you want the default nodeChange function to not process anything + * @type Boolean + */ + STOP_NODE_CHANGE: false, + /** + * @protected + * @property CLASS_NOEDIT + * @description CSS class applied to elements that are not editable. + * @type String + */ + CLASS_NOEDIT: 'yui-noedit', + /** + * @protected + * @property CLASS_CONTAINER + * @description Default CSS class to apply to the editors container element + * @type String + */ + CLASS_CONTAINER: 'yui-editor-container', + /** + * @protected + * @property CLASS_EDITABLE + * @description Default CSS class to apply to the editors iframe element + * @type String + */ + CLASS_EDITABLE: 'yui-editor-editable', + /** + * @protected + * @property CLASS_EDITABLE_CONT + * @description Default CSS class to apply to the editors iframe's parent element + * @type String + */ + CLASS_EDITABLE_CONT: 'yui-editor-editable-container', + /** + * @protected + * @property CLASS_PREFIX + * @description Default prefix for dynamically created class names + * @type String + */ + CLASS_PREFIX: 'yui-editor', + /** + * @property browser + * @description Standard browser detection + * @type Object + */ + browser: function() { + var br = Y.UA; + //Check for webkit3 + if (br.webkit >= 420) { + br.webkit3 = br.webkit; + } else { + br.webkit3 = 0; + } + if (br.webkit >= 530) { + br.webkit4 = br.webkit; + } else { + br.webkit4 = 0; + } + br.mac = false; + //Check for Mac + if (navigator.userAgent.indexOf('Macintosh') !== -1) { + br.mac = true; + } + + return br; + }(), + /** + * @method init + * @description The Editor class' initialization method + */ + initializer: function() { + Y.log('SimpleEditor initializer'); + + if (!this._defaultToolbar) { + this._defaultToolbar = { + collapse: true, + titlebar: 'Text Editing Tools', + draggable: false, + buttons: [ + { group: 'fontstyle', label: 'Font Name and Size', + buttons: [ + { type: 'select', label: 'Arial', value: 'fontname', disabled: true, + menu: [ + { text: 'Arial', checked: true }, + { text: 'Arial Black' }, + { text: 'Comic Sans MS' }, + { text: 'Courier New' }, + { text: 'Lucida Console' }, + { text: 'Tahoma' }, + { text: 'Times New Roman' }, + { text: 'Trebuchet MS' }, + { text: 'Verdana' } + ] + }, + { type: 'spin', label: '13', value: 'fontsize', range: [ 9, 75 ], disabled: true } + ] + }, + { type: 'separator' }, + { group: 'textstyle', label: 'Font Style', + buttons: [ + { type: 'push', label: 'Bold CTRL + SHIFT + B', value: 'bold' }, + { type: 'push', label: 'Italic CTRL + SHIFT + I', value: 'italic' }, + { type: 'push', label: 'Underline CTRL + SHIFT + U', value: 'underline' }, + { type: 'push', label: 'Strike Through', value: 'strikethrough' }, + { type: 'separator' }, + { type: 'color', label: 'Font Color', value: 'forecolor', disabled: true }, + { type: 'color', label: 'Background Color', value: 'backcolor', disabled: true } + + ] + }, + { type: 'separator' }, + { group: 'indentlist', label: 'Lists', + buttons: [ + { type: 'push', label: 'Create an Unordered List', value: 'insertunorderedlist' }, + { type: 'push', label: 'Create an Ordered List', value: 'insertorderedlist' } + ] + }, + { type: 'separator' }, + { group: 'insertitem', label: 'Insert Item', + buttons: [ + { type: 'push', label: 'HTML Link CTRL + SHIFT + L', value: 'createlink', disabled: true }, + { type: 'push', label: 'Insert Image', value: 'insertimage' } + ] + } + ] + }; + } + + Y.Editor.Info._instances[this.get('node').get('id')] = this; + + this.currentElement = []; + + this._handleDOMPath(); + this.on('dompathChange', Y.bind(this._handleDOMPath, this)); + this.set('blankimage', this._getBlankImage()); + this._handleInsert(); + this.set('saveEl', this.get('node')); + this._handleSubmit(); + this.on('handleSubmitChange', Y.bind(this._handleSubmit, this)); + if (this.get('focusAtStart')) { + this.on('editorContentLoaded', function() { + Y.later(400, this, function() { + this.focus(); + this.editorDirty = false; + }); + }); + } + }, + /** + * @private + * @method _getBlankImage + * @description Retrieves the full url of the image to use as the blank image. + * @return {String} The URL to the blank image + */ + _getBlankImage: function() { + var img = ''; + if (!this._blankImageLoaded) { + if (Y.Editor.Info.blankImage) { + this.set('blankimage', Y.Editor.Info.blankImage); + this._blankImageLoaded = true; + } else { + var div = document.createElement('div'); + div.style.position = 'absolute'; + div.style.top = '-9999px'; + div.style.left = '-9999px'; + div.className = this.CLASS_PREFIX + '-blankimage'; + document.body.appendChild(div); + img = Dom.getStyle(div, 'backgroundImage'); + img = img.replace('url(', '').replace(')', '').replace(/"/g, ''); + //Adobe AIR Code + img = img.replace('app:/', ''); + this.set('blankimage', img); + this._blankImageLoaded = true; + div.parentNode.removeChild(div); + Y.Editor.Info.blankImage = img; + } + } else { + img = this.get('blankimage'); + } + return img; + }, + /** + * @private + * @method _handleAutoHeight + * @description Handles resizing the editor's height based on the content + */ + _handleAutoHeight: function() { + var doc = this._getDoc(), + body = doc.body, + docEl = doc.documentElement; + + var height = parseInt(Dom.getStyle(this.get('editor_wrapper'), 'height'), 10); + var newHeight = body.scrollHeight; + if (this.browser.webkit) { + newHeight = docEl.scrollHeight; + } + if (newHeight < parseInt(this.get('height'), 10)) { + newHeight = parseInt(this.get('height'), 10); + } + if ((height != newHeight) && (newHeight >= parseInt(this.get('height'), 10))) { + var anim = this.get('animate'); + this.set('animate', false); + this.set('height', newHeight + 'px'); + this.set('animate', anim); + if (this.browser.ie) { + //Internet Explorer needs this + this.get('iframe').setStyle('height', '99%'); + this.get('iframe').setStyle('zoom', '1'); + var self = this; + window.setTimeout(function() { + self.get('iframe').setStyle('height', '100%'); + }, 1); + } + } + }, + /** + * @private + * @property _formButtons + * @description Array of buttons that are in the Editor's parent form (for handleSubmit) + * @type Array + */ + _formButtons: null, + /** + * @private + * @property _formButtonClicked + * @description The form button that was clicked to submit the form. + * @type HTMLElement + */ + _formButtonClicked: null, + /** + * @private + * @method _handleFormButtonClick + * @description The click listener assigned to each submit button in the Editor's parent form. + * @param {Event} ev The click event + */ + _handleFormButtonClick: function(ev) { + var tar = Event.getTarget(ev); + this._formButtonClicked = tar; + }, + /** + * @private + * @method _handleFormSubmit + * @description Handles the form submission. + * @param {Object} ev The Form Submit Event + */ + _handleFormSubmit: function(ev) { + this.saveHTML(); + + var form = this.get('node').get('form'), + tar = this._formButtonClicked || false; + + form.detach('submit', Y.bind(this._handleFormSubmit, this)); + //console.log(form); + /* + if (this.browser.ie) { + if (tar && !tar.disabled) { + tar.click(); + } + } else { // Gecko, Opera, and Safari + if (tar && !tar.disabled) { + tar.click(); + } + var oEvent = document.createEvent("HTMLEvents"); + oEvent.initEvent("submit", true, true); + form.dispatchEvent(oEvent); + if (YAHOO.env.ua.webkit) { + if (YAHOO.lang.isFunction(form.submit)) { + form.submit(); + } + } + } + */ + //2.6.0 + //Removed this, not need since removing Safari 2.x + //Event.stopEvent(ev); + }, + /** + * @private + * @method _handleFontSize + * @description Handles the font size button in the toolbar. + * @param {Object} o Object returned from Toolbar's buttonClick Event + */ + _handleFontSize: function(o) { + var button = this.toolbar.getButtonById(o.button.id); + var value = button.get('label') + 'px'; + this.execCommand('fontsize', value); + return false; + }, + /** + * @private + * @description Handles the colorpicker buttons in the toolbar. + * @param {Object} o Object returned from Toolbar's buttonClick Event + */ + _handleColorPicker: function(o) { + var cmd = o.button; + var value = '#' + o.color; + if ((cmd == 'forecolor') || (cmd == 'backcolor')) { + this.execCommand(cmd, value); + } + }, + /** + * @private + * @method _handleAlign + * @description Handles the alignment buttons in the toolbar. + * @param {Object} o Object returned from Toolbar's buttonClick Event + */ + _handleAlign: function(o) { + var cmd = null; + for (var i = 0; i < o.button.menu.length; i++) { + if (o.button.menu[i].value == o.button.value) { + cmd = o.button.menu[i].value; + } + } + var value = this._getSelection(); + + this.execCommand(cmd, value); + return false; + }, + /** + * @private + * @method _handleAfterNodeChange + * @description Fires after a nodeChange happens to setup the things that where reset on the node change (button state). + */ + _handleAfterNodeChange: function() { + var path = this._getDomPath(), + elm = null, + family = null, + fontsize = null, + validFont = false, + fn_button = this.toolbar.getButtonByValue('fontname'), + fs_button = this.toolbar.getButtonByValue('fontsize'), + hd_button = this.toolbar.getButtonByValue('heading'); + + for (var i = 0; i < path.length; i++) { + elm = path[i]; + + var tag = elm.tagName.toLowerCase(); + + + if (elm.getAttribute('tag')) { + tag = elm.getAttribute('tag'); + } + + family = elm.getAttribute('face'); + if (Dom.getStyle(elm, 'fontFamily')) { + family = Dom.getStyle(elm, 'fontFamily'); + //Adobe AIR Code + family = family.replace(/'/g, ''); + } + + if (tag.substring(0, 1) == 'h') { + if (hd_button) { + /* + for (var h = 0; h < hd_button._conf.data.initValue.menu.length; h++) { + if (hd_button._conf.data.initValue.menu.value[h].value.toLowerCase() == tag) { + hd_button.set('label', hd_button._configs.menu.value[h].text); + } + } + this._updateMenuChecked('heading', tag); + */ + } + } + } + + if (fn_button) { + /* + for (var b = 0; b < fn_button._conf.data.initValue.menu.value.length; b++) { + if (family && fn_button._configs.menu.value[b].text.toLowerCase() == family.toLowerCase()) { + validFont = true; + family = fn_button._configs.menu.value[b].text; //Put the proper menu name in the button + } + } + */ + if (!validFont) { + family = fn_button._conf.data.initValue.label; + } + var familyLabel = ' '; + if (fn_button.get('label') != familyLabel) { + fn_button.set('label', familyLabel); + this._updateMenuChecked('fontname', family); + } + } + + if (fs_button) { + fontsize = parseInt(Dom.getStyle(elm, 'fontSize'), 10); + if ((fontsize === null) || isNaN(fontsize)) { + fontsize = fs_button._conf.data.initValue.label; + } + fs_button.set('label', ''+fontsize); + } + + if (!this._isElement(elm, 'body') && !this._isElement(elm, 'img')) { + this.toolbar.enableButton(fn_button); + this.toolbar.enableButton(fs_button); + this.toolbar.enableButton('forecolor'); + this.toolbar.enableButton('backcolor'); + } + if (this._isElement(elm, 'img')) { + if (Y.Overlay) { + this.toolbar.enableButton('createlink'); + } + } + if (this._hasParent(elm, 'blockquote')) { + this.toolbar.selectButton('indent'); + this.toolbar.disableButton('indent'); + this.toolbar.enableButton('outdent'); + } + if (this._hasParent(elm, 'ol') || this._hasParent(elm, 'ul')) { + this.toolbar.disableButton('indent'); + } + this._lastButton = null; + + }, + /** + * @private + * @method _handleInsertImageClick + * @description Opens the Image Properties Window when the insert Image button is clicked or an Image is Double Clicked. + */ + _handleInsertImageClick: function() { + if (this.get('limitCommands')) { + if (!this.toolbar.getButtonByValue('insertimage')) { + YAHOO.log('Toolbar Button for (insertimage) was not found, skipping exec.', 'info', 'SimpleEditor'); + return false; + } + } + + this.toolbar.set('disabled', true); //Disable the toolbar when the prompt is showing + var _handleAEC = function() { + var el = this.currentElement[0], + src = 'http://'; + if (!el) { + el = this._getSelectedElement(); + } + if (el) { + if (el.getAttribute('src')) { + src = el.getAttribute('src', 2); + if (src.indexOf(this.get('blankimage')) != -1) { + src = this.STR_IMAGE_HERE; + } + } + } + var str = prompt(this.STR_IMAGE_URL + ': ', src); + if ((str !== '') && (str !== null)) { + el.setAttribute('src', str); + } else if (str === '') { + el.parentNode.removeChild(el); + this.currentElement = []; + this.nodeChange(); + } else if ((str === null)) { + src = el.getAttribute('src', 2); + if (src.indexOf(this.get('blankimage')) != -1) { + el.parentNode.removeChild(el); + this.currentElement = []; + this.nodeChange(); + } + } + this.closeWindow(); + this.toolbar.set('disabled', false); + this.unsubscribe('afterExecCommand', _handleAEC, this, true); + }; + this.on('afterExecCommand', _handleAEC, this, true); + }, + /** + * @private + * @method _handleInsertImageWindowClose + * @description Handles the closing of the Image Properties Window. + */ + _handleInsertImageWindowClose: function() { + this.nodeChange(); + }, + /** + * @private + * @method _isLocalFile + * @param {String} url THe url/string to check + * @description Checks to see if a string (href or img src) is possibly a local file reference.. + */ + _isLocalFile: function(url) { + if ((url) && (url !== '') && ((url.indexOf('file:/') != -1) || (url.indexOf(':\\') != -1))) { + return true; + } + return false; + }, + /** + * @private + * @method _handleCreateLinkClick + * @description Handles the opening of the Link Properties Window when the Create Link button is clicked or an href is doubleclicked. + */ + _handleCreateLinkClick: function() { + if (this.get('limitCommands')) { + if (!this.toolbar.getButtonByValue('createlink')) { + YAHOO.log('Toolbar Button for (createlink) was not found, skipping exec.', 'info', 'SimpleEditor'); + return false; + } + } + + this.toolbar.set('disabled', true); //Disable the toolbar when the prompt is showing + + var _handleAEC = function() { + var el = this.currentElement[0], + url = ''; + + if (el) { + if (el.getAttribute('href', 2) !== null) { + url = el.getAttribute('href', 2); + } + } + var str = prompt(this.STR_LINK_URL + ': ', url); + if ((str !== '') && (str !== null)) { + var urlValue = str; + if ((urlValue.indexOf(':/'+'/') == -1) && (urlValue.substring(0,1) != '/') && (urlValue.substring(0, 6).toLowerCase() != 'mailto')) { + if ((urlValue.indexOf('@') != -1) && (urlValue.substring(0, 6).toLowerCase() != 'mailto')) { + //Found an @ sign, prefix with mailto: + urlValue = 'mailto:' + urlValue; + } else { + /* :// not found adding */ + if (urlValue.substring(0, 1) != '#') { + //urlValue = 'http:/'+'/' + urlValue; + } + } + } + el.setAttribute('href', urlValue); + } else if (str !== null) { + var _span = this._getDoc().createElement('span'); + _span.innerHTML = el.innerHTML; + Dom.addClass(_span, 'yui-non'); + el.parentNode.replaceChild(_span, el); + } + this.closeWindow(); + this.toolbar.set('disabled', false); + this.unsubscribe('afterExecCommand', _handleAEC, this, true); + }; + this.on('afterExecCommand', _handleAEC, this); + + }, + /** + * @private + * @method _handleCreateLinkWindowClose + * @description Handles the closing of the Link Properties Window. + */ + _handleCreateLinkWindowClose: function() { + this.nodeChange(); + this.currentElement = []; + }, + /** + * @method render + * @description Calls the private method _render in a setTimeout to allow for other things on the page to continue to load. + */ + render: function() { + if (this._rendered) { + return false; + } + YAHOO.log('Render', 'info', 'SimpleEditor'); + + if (this.get('node')) { + this._textarea = true; + if (this.get('node').get('tagName').toLowerCase() !== 'textarea') { + this._textarea = false; + } + } else { + YAHOO.log('No Element', 'error', 'SimpleEditor'); + return false; + } + this._rendered = true; + Y.later(4, this, this._render); + }, + /** + * @private + * @method _render + * @description Causes the toolbar and the editor to render and replace the textarea. + */ + _render: function() { + YAHOO.log('_render'); + this.set('textarea', this.get('node')); + + this.get('element_cont').setStyle('display', 'none'); + this.get('element_cont').addClass(this.CLASS_CONTAINER); + + this.set('iframe', this._createIframe()); + + Y.later(10, this, this._setInitialContent, false); + + this.get('editor_wrapper').appendChild(this.get('iframe')); + + if (this.get('disabled')) { + this._disableEditor(true); + } + + var tbarConf = this.get('toolbar'); + if (!tbarConf) { + tbarConf = this._defaultToolbar; + } + //Create Toolbar instance + if (tbarConf instanceof Y.Toolbar.Bar) { + this.toolbar = tbarConf; + //Set the toolbar to disabled until content is loaded + this.toolbar.set('disabled', true); + } else { + tbarConf.node = this.get('toolbar_cont'); + //Set the toolbar to disabled until content is loaded + tbarConf.disabled = true; + this.toolbar = new Y.Toolbar.Bar(tbarConf); + } + + YAHOO.log('fireEvent::toolbarLoaded', 'info', 'SimpleEditor'); + this.fire('toolbarLoaded', { type: 'toolbarLoaded' }); + + + this.toolbar.on('toolbarCollapsed', function() { + if (this.currentWindow) { + this.moveWindow(); + } + }, this, true); + this.toolbar.on('toolbarExpanded', function() { + if (this.currentWindow) { + this.moveWindow(); + } + }, this, true); + this.toolbar.on('fontsizeClick', this._handleFontSize, this, true); + + this.toolbar.on('colorPickerClicked', function(o) { + this._handleColorPicker(o); + this.STOP_EXEC_COMMAND = true; + }, this, true); + + this.toolbar.on('alignClick', this._handleAlign, this, true); + this.on('afterNodeChange', this._handleAfterNodeChange, this, true); + this.toolbar.on('insertimageClick', this._handleInsertImageClick, this, true); + this.on('windowinsertimageClose', this._handleInsertImageWindowClose, this, true); + this.toolbar.on('createlinkClick', this._handleCreateLinkClick, this, true); + this.on('windowcreatelinkClose', this._handleCreateLinkWindowClose, this, true); + + + //Replace Textarea with editable area + this.get('node').get('parentNode').replaceChild(this.get('element_cont'), this.get('node')); + + this.get('node').setStyle('visibility', 'hidden'); + this.get('node').setStyle('position', 'absolute'); + this.get('node').setStyle('top', '-9999px'); + this.get('node').setStyle('left', '-9999px'); + this.get('element_cont').appendChild(this.get('node')); + this.get('element_cont').setStyle('display', 'block'); + + + this.get('iframe').get('parentNode').addClass(this.CLASS_EDITABLE_CONT); + this.get('iframe').addClass(this.CLASS_EDITABLE); + + //Set height and width of editor container + this.get('element_cont').setStyle('width', this.get('width')); + this.get('iframe').get('parentNode').setStyle('height', this.get('height')); + + this.get('iframe').setStyle('width', '100%'); //WIDTH + this.get('iframe').setStyle('height', '100%'); + + Y.later(0, this, this._setupAfterElement); + this.fire('afterRender', { type: 'afterRender' }); + }, + /** + * @method execCommand + * @param {String} action The "execCommand" action to try to execute (Example: bold, insertimage, inserthtml) + * @param {String} value (optional) The value for a given action such as action: fontname value: 'Verdana' + * @description This method attempts to try and level the differences in the various browsers and their support for execCommand actions + */ + execCommand: function(action, value) { + var beforeExec = this.fireEvent('beforeExecCommand', { type: 'beforeExecCommand', target: this, args: arguments }); + if ((beforeExec === false) || (this.STOP_EXEC_COMMAND)) { + this.STOP_EXEC_COMMAND = false; + return false; + } + this._lastCommand = action; + this._setMarkupType(action); + if (this.browser.ie) { + this._getWindow().focus(); + } + var exec = true; + + if (this.get('limitCommands')) { + if (!this.toolbar.getButtonByValue(action)) { + YAHOO.log('Toolbar Button for (' + action + ') was not found, skipping exec.', 'info', 'SimpleEditor'); + exec = false; + } + } + + this.editorDirty = true; + + if ((typeof this['cmd_' + action.toLowerCase()] == 'function') && exec) { + YAHOO.log('Found execCommand override method: (cmd_' + action.toLowerCase() + ')', 'info', 'SimpleEditor'); + var retValue = this['cmd_' + action.toLowerCase()](value); + exec = retValue[0]; + if (retValue[1]) { + action = retValue[1]; + } + if (retValue[2]) { + value = retValue[2]; + } + } + if (exec) { + YAHOO.log('execCommand::(' + action + '), (' + value + ')', 'info', 'SimpleEditor'); + try { + this._getDoc().execCommand(action, false, value); + } catch(e) { + YAHOO.log('execCommand Failed', 'error', 'SimpleEditor'); + } + } else { + YAHOO.log('OVERRIDE::execCommand::(' + action + '),(' + value + ') skipped', 'warn', 'SimpleEditor'); + } + this.on('afterExecCommand', function() { + this.unsubscribeAll('afterExecCommand'); + this.nodeChange(); + }, this, true); + this.fireEvent('afterExecCommand', { type: 'afterExecCommand', target: this }); + + }, + /* {{{ Command Overrides */ + + /** + * @method cmd_bold + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('bold') is used. + */ + cmd_bold: function(value) { + if (!this.browser.webkit) { + var el = this._getSelectedElement(); + if (el && this._isElement(el, 'span') && this._hasSelection()) { + if (el.style.fontWeight == 'bold') { + el.style.fontWeight = ''; + var b = this._getDoc().createElement('b'), + par = el.parentNode; + par.replaceChild(b, el); + b.appendChild(el); + } + } + } + return [true]; + }, + /** + * @method cmd_italic + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('italic') is used. + */ + + cmd_italic: function(value) { + if (!this.browser.webkit) { + var el = this._getSelectedElement(); + if (el && this._isElement(el, 'span') && this._hasSelection()) { + if (el.style.fontStyle == 'italic') { + el.style.fontStyle = ''; + var i = this._getDoc().createElement('i'), + par = el.parentNode; + par.replaceChild(i, el); + i.appendChild(el); + } + } + } + return [true]; + }, + + + /** + * @method cmd_underline + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('underline') is used. + */ + cmd_underline: function(value) { + if (!this.browser.webkit) { + var el = this._getSelectedElement(); + if (el && this._isElement(el, 'span')) { + if (el.style.textDecoration == 'underline') { + el.style.textDecoration = 'none'; + } else { + el.style.textDecoration = 'underline'; + } + return [false]; + } + } + return [true]; + }, + /** + * @method cmd_backcolor + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('backcolor') is used. + */ + cmd_backcolor: function(value) { + var exec = true, + el = this._getSelectedElement(), + action = 'backcolor'; + + if (this.browser.gecko || this.browser.opera) { + this._setEditorStyle(true); + action = 'hilitecolor'; + } + + if (!this._isElement(el, 'body') && !this._hasSelection()) { + el.style.backgroundColor = value; + this._selectNode(el); + exec = false; + } else { + if (this.get('insert')) { + el = this._createInsertElement({ backgroundColor: value }); + } else { + this._createCurrentElement('span', { backgroundColor: value, color: el.style.color, fontSize: el.style.fontSize, fontFamily: el.style.fontFamily }); + this._selectNode(this.currentElement[0]); + } + exec = false; + } + + return [exec, action]; + }, + /** + * @method cmd_forecolor + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('forecolor') is used. + */ + cmd_forecolor: function(value) { + var exec = true, + el = this._getSelectedElement(); + + if (!this._isElement(el, 'body') && !this._hasSelection()) { + Dom.setStyle(el, 'color', value); + this._selectNode(el); + exec = false; + } else { + if (this.get('insert')) { + el = this._createInsertElement({ color: value }); + } else { + this._createCurrentElement('span', { color: value, fontSize: el.style.fontSize, fontFamily: el.style.fontFamily, backgroundColor: el.style.backgroundColor }); + this._selectNode(this.currentElement[0]); + } + exec = false; + } + return [exec]; + }, + /** + * @method cmd_unlink + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('unlink') is used. + */ + cmd_unlink: function(value) { + this._swapEl(this.currentElement[0], 'span', function(el) { + el.className = 'yui-non'; + }); + return [false]; + }, + /** + * @method cmd_createlink + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('createlink') is used. + */ + cmd_createlink: function(value) { + var el = this._getSelectedElement(), _a = null; + if (this._hasParent(el, 'a')) { + this.currentElement[0] = this._hasParent(el, 'a'); + } else if (this._isElement(el, 'li')) { + _a = this._getDoc().createElement('a'); + _a.innerHTML = el.innerHTML; + el.innerHTML = ''; + el.appendChild(_a); + this.currentElement[0] = _a; + } else if (!this._isElement(el, 'a')) { + this._createCurrentElement('a'); + _a = this._swapEl(this.currentElement[0], 'a'); + this.currentElement[0] = _a; + } else { + this.currentElement[0] = el; + } + return [false]; + }, + /** + * @method cmd_insertimage + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('insertimage') is used. + */ + cmd_insertimage: function(value) { + var exec = true, _img = null, action = 'insertimage', + el = this._getSelectedElement(); + + if (value === '') { + value = this.get('blankimage'); + } + + /* + * @knownissue Safari Cursor Position + * @browser Safari 2.x + * @description The issue here is that we have no way of knowing where the cursor position is + * inside of the iframe, so we have to place the newly inserted data in the best place that we can. + */ + + YAHOO.log('InsertImage: ' + el.tagName, 'info', 'SimpleEditor'); + if (this._isElement(el, 'img')) { + this.currentElement[0] = el; + exec = false; + } else { + if (this._getDoc().queryCommandEnabled(action)) { + this._getDoc().execCommand(action, false, value); + var imgs = this._getDoc().getElementsByTagName('img'); + for (var i = 0; i < imgs.length; i++) { + if (!Dom.hasClass(imgs[i], 'yui-img')) { + Dom.addClass(imgs[i], 'yui-img'); + this.currentElement[0] = imgs[i]; + } + } + exec = false; + } else { + if (el == this._getDoc().body) { + _img = this._getDoc().createElement('img'); + _img.setAttribute('src', value); + Dom.addClass(_img, 'yui-img'); + this._getDoc().body.appendChild(_img); + } else { + this._createCurrentElement('img'); + _img = this._getDoc().createElement('img'); + _img.setAttribute('src', value); + Dom.addClass(_img, 'yui-img'); + this.currentElement[0].parentNode.replaceChild(_img, this.currentElement[0]); + } + this.currentElement[0] = _img; + exec = false; + } + } + return [exec]; + }, + /** + * @method cmd_inserthtml + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('inserthtml') is used. + */ + cmd_inserthtml: function(value) { + var exec = true, action = 'inserthtml', _span = null, _range = null; + /* + * @knownissue Safari cursor position + * @browser Safari 2.x + * @description The issue here is that we have no way of knowing where the cursor position is + * inside of the iframe, so we have to place the newly inserted data in the best place that we can. + */ + if (this.browser.webkit && !this._getDoc().queryCommandEnabled(action)) { + YAHOO.log('More Safari DOM tricks (inserthtml)', 'info', 'EditorSafari'); + this._createCurrentElement('img'); + _span = this._getDoc().createElement('span'); + _span.innerHTML = value; + this.currentElement[0].parentNode.replaceChild(_span, this.currentElement[0]); + exec = false; + } else if (this.browser.ie) { + _range = this._getRange(); + if (_range.item) { + _range.item(0).outerHTML = value; + } else { + _range.pasteHTML(value); + } + exec = false; + } + return [exec]; + }, + /** + * @method cmd_list + * @param tag The tag of the list you want to create (eg, ul or ol) + * @description This is a combined execCommand override method. It is called from the cmd_insertorderedlist and cmd_insertunorderedlist methods. + */ + cmd_list: function(tag) { + var exec = true, list = null, li = 0, el = null, str = '', + selEl = this._getSelectedElement(), action = 'insertorderedlist'; + if (tag == 'ul') { + action = 'insertunorderedlist'; + } + /* + * @knownissue Safari 2.+ doesn't support ordered and unordered lists + * @browser Safari 2.x + * The issue with this workaround is that when applied to a set of text + * that has BR's in it, Safari may or may not pick up the individual items as + * list items. This is fixed in WebKit (Safari 3) + * 2.6.0: Seems there are still some issues with List Creation and Safari 3, reverting to previously working Safari 2.x code + */ + //if ((this.browser.webkit && !this._getDoc().queryCommandEnabled(action))) { + if (this.browser.webkit && !this.browser.webkit4) { + if (this._isElement(selEl, 'li') && this._isElement(selEl.parentNode, tag)) { + YAHOO.log('We already have a list, undo it', 'info', 'SimpleEditor'); + el = selEl.parentNode; + list = this._getDoc().createElement('span'); + Dom.addClass(list, 'yui-non'); + str = ''; + var lis = el.getElementsByTagName('li'); + for (li = 0; li < lis.length; li++) { + str += '
- Control Shift B sets text to bold
- Control Shift I sets text to italic
- Control Shift U underlines text
- Control Shift L adds an HTML link
' + lis[li].innerHTML + ''; + } + list.innerHTML = str; + this.currentElement[0] = el; + this.currentElement[0].parentNode.replaceChild(list, this.currentElement[0]); + } else { + YAHOO.log('Create list item', 'info', 'SimpleEditor'); + this._createCurrentElement(tag.toLowerCase()); + list = this._getDoc().createElement(tag); + for (li = 0; li < this.currentElement.length; li++) { + var newli = this._getDoc().createElement('li'); + newli.innerHTML = this.currentElement[li].innerHTML + ' '; + list.appendChild(newli); + if (li > 0) { + this.currentElement[li].parentNode.removeChild(this.currentElement[li]); + } + } + + var items = list.firstChild.innerHTML.split('
'); + if (items.length > 0) { + list.innerHTML = ''; + for (var i = 0; i < items.length; i++) { + var item = this._getDoc().createElement('li'); + item.innerHTML = items[i]; + list.appendChild(item); + } + } + + this.currentElement[0].parentNode.replaceChild(list, this.currentElement[0]); + this.currentElement[0] = list; + var _h = this.currentElement[0].firstChild; + _h = Dom.getElementsByClassName('yui-non', 'span', _h)[0]; + this._getSelection().setBaseAndExtent(_h, 1, _h, _h.innerText.length); + } + exec = false; + } else { + el = this._getSelectedElement(); + YAHOO.log(el.tagName); + if (this._isElement(el, 'li') && this._isElement(el.parentNode, tag) || (this.browser.ie && this._isElement(this._getRange().parentElement, 'li')) || (this.browser.ie && this._isElement(el, 'ul')) || (this.browser.ie && this._isElement(el, 'ol'))) { //we are in a list.. + YAHOO.log('We already have a list, undo it', 'info', 'SimpleEditor'); + if (this.browser.ie) { + if ((this.browser.ie && this._isElement(el, 'ul')) || (this.browser.ie && this._isElement(el, 'ol'))) { + el = el.getElementsByTagName('li')[0]; + } + YAHOO.log('Undo IE', 'info', 'SimpleEditor'); + str = ''; + var lis2 = el.parentNode.getElementsByTagName('li'); + for (var j = 0; j < lis2.length; j++) { + str += lis2[j].innerHTML + '
'; + } + var newEl = this._getDoc().createElement('span'); + newEl.innerHTML = str; + el.parentNode.parentNode.replaceChild(newEl, el.parentNode); + } else { + this.nodeChange(); + this._getDoc().execCommand(action, '', el.parentNode); + this.nodeChange(); + } + exec = false; + } + if (this.browser.opera) { + var self = this; + window.setTimeout(function() { + var liso = self._getDoc().getElementsByTagName('li'); + for (var i = 0; i < liso.length; i++) { + if (liso[i].innerHTML.toLowerCase() == '
') { + liso[i].parentNode.parentNode.removeChild(liso[i].parentNode); + } + } + },30); + } + if (this.browser.ie && exec) { + var html = ''; + if (this._getRange().html) { + html = '' + this._getRange().html+ ' '; + } else { + var t = this._getRange().text.split('\n'); + if (t.length > 1) { + html = ''; + for (var ie = 0; ie < t.length; ie++) { + html += '' + t[ie] + ' '; + } + } else { + var txt = this._getRange().text; + if (txt === '') { + html = '' + txt + ' '; + } else { + html = '' + txt + ' '; + } + } + } + this._getRange().pasteHTML('<' + tag + '>' + html + '' + tag + '>'); + var new_item = this._getDoc().getElementById('new_list_item'); + if (new_item) { + var range = this._getDoc().body.createTextRange(); + range.moveToElementText(new_item); + range.collapse(false); + range.select(); + new_item.id = ''; + } + exec = false; + } + } + return exec; + }, + /** + * @method cmd_insertorderedlist + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('insertorderedlist ') is used. + */ + cmd_insertorderedlist: function(value) { + return [this.cmd_list('ol')]; + }, + /** + * @method cmd_insertunorderedlist + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('insertunorderedlist') is used. + */ + cmd_insertunorderedlist: function(value) { + return [this.cmd_list('ul')]; + }, + /** + * @method cmd_fontname + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('fontname') is used. + */ + cmd_fontname: function(value) { + var exec = true, + selEl = this._getSelectedElement(); + + this.currentFont = value; + if (selEl && selEl.tagName && !this._hasSelection() && !this._isElement(selEl, 'body') && !this.get('insert')) { + Dom.setStyle(selEl, 'fontFamily', value); + exec = false; + } else if (this.get('insert') && !this._hasSelection()) { + YAHOO.log('No selection and no selected element and we are in insert mode', 'info', 'SimpleEditor'); + var el = this._createInsertElement({ fontFamily: value }); + exec = false; + } + return [exec]; + }, + /** + * @method cmd_fontsize + * @param value Value passed from the execCommand method + * @description This is an execCommand override method. It is called from execCommand when the execCommand('fontsize') is used. + */ + cmd_fontsize: function(value) { + var el = null, go = true; + el = this._getSelectedElement(); + if (this.browser.webkit) { + if (this.currentElement[0]) { + if (el == this.currentElement[0]) { + go = false; + Dom.setStyle(el, 'fontSize', value); + this._selectNode(el); + this.currentElement[0] = el; + } + } + } + if (go) { + if (!this._isElement(this._getSelectedElement(), 'body') && (!this._hasSelection())) { + el = this._getSelectedElement(); + Dom.setStyle(el, 'fontSize', value); + if (this.get('insert') && this.browser.ie) { + var r = this._getRange(); + r.collapse(false); + r.select(); + } else { + this._selectNode(el); + } + } else if (this.currentElement && (this.currentElement.length > 0) && (!this._hasSelection()) && (!this.get('insert'))) { + Dom.setStyle(this.currentElement, 'fontSize', value); + } else { + if (this.get('insert') && !this._hasSelection()) { + el = this._createInsertElement({ fontSize: value }); + this.currentElement[0] = el; + this._selectNode(this.currentElement[0]); + } else { + this._createCurrentElement('span', {'fontSize': value, fontFamily: el.style.fontFamily, color: el.style.color, backgroundColor: el.style.backgroundColor }); + this._selectNode(this.currentElement[0]); + } + } + } + return [false]; + }, + /* }}} */ + /** + * @private + * @method _swapEl + * @param {HTMLElement} el The element to swap with + * @param {String} tagName The tagname of the element that you wish to create + * @param {Function} callback (optional) A function to run on the element after it is created, but before it is replaced. An element reference is passed to this function. + * @description This function will create a new element in the DOM and populate it with the contents of another element. Then it will assume it's place. + */ + _swapEl: function(el, tagName, callback) { + var _el = this._getDoc().createElement(tagName); + if (el) { + _el.innerHTML = el.innerHTML; + } + if (typeof callback == 'function') { + callback.call(this, _el); + } + if (el) { + el.parentNode.replaceChild(_el, el); + } + return _el; + }, + /** + * @private + * @method _createInsertElement + * @description Creates a new "currentElement" then adds some text (and other things) to make it selectable and stylable. Then the user can continue typing. + * @param {Object} css (optional) Object literal containing styles to apply to the new element. + * @return {HTMLElement} + */ + _createInsertElement: function(css) { + this._createCurrentElement('span', css); + var el = this.currentElement[0]; + if (this.browser.webkit) { + //Little Safari Hackery here.. + el.innerHTML = ' '; + el = el.firstChild; + this._getSelection().setBaseAndExtent(el, 1, el, el.innerText.length); + } else if (this.browser.ie || this.browser.opera) { + el.innerHTML = ' '; + } + this.focus(); + this._selectNode(el, true); + return el; + }, + /** + * @private + * @method _createCurrentElement + * @param {String} tagName (optional defaults to a) The tagname of the element that you wish to create + * @param {Object} tagStyle (optional) Object literal containing styles to apply to the new element. + * @description This is a work around for the various browser issues with execCommand. This method will runexecCommand('fontname', false, 'yui-tmp')
on the given selection. + * It will then search the document for an element with the font-family set to yui-tmp and replace that with another span that has other information in it, then assign the new span to the + *this.currentElement
array, so we now have element references to the elements that were just modified. At this point we can use standard DOM manipulation to change them as we see fit. + */ + _createCurrentElement: function(tagName, tagStyle) { + tagName = ((tagName) ? tagName : 'a'); + var tar = null, + el = [], + _doc = this._getDoc(); + + if (this.currentFont) { + if (!tagStyle) { + tagStyle = {}; + } + tagStyle.fontFamily = this.currentFont; + this.currentFont = null; + } + this.currentElement = []; + + var _elCreate = function(tagName, tagStyle) { + var el = null; + tagName = ((tagName) ? tagName : 'span'); + tagName = tagName.toLowerCase(); + switch (tagName) { + case 'h1': + case 'h2': + case 'h3': + case 'h4': + case 'h5': + case 'h6': + el = _doc.createElement(tagName); + break; + default: + el = _doc.createElement(tagName); + if (tagName === 'span') { + Dom.addClass(el, 'yui-tag-' + tagName); + Dom.addClass(el, 'yui-tag'); + el.setAttribute('tag', tagName); + } + //console.log(tagStyle); + if (tagStyle) { + Y.each(tagStyle, function(v, k) { + el.style[k] = v; + }); + } + break; + } + return el; + }; + + if (!this._hasSelection()) { + if (this._getDoc().queryCommandEnabled('insertimage')) { + this._getDoc().execCommand('insertimage', false, 'yui-tmp-img'); + var imgs = this._getDoc().getElementsByTagName('img'); + for (var j = 0; j < imgs.length; j++) { + if (imgs[j].getAttribute('src', 2) == 'yui-tmp-img') { + el = _elCreate(tagName, tagStyle); + imgs[j].parentNode.replaceChild(el, imgs[j]); + this.currentElement[this.currentElement.length] = el; + } + } + } else { + if (this.currentEvent) { + tar = Event.getTarget(this.currentEvent); + } else { + //For Safari.. + tar = this._getDoc().body; + } + } + if (tar) { + /* + * @knownissue Safari Cursor Position + * @browser Safari 2.x + * @description The issue here is that we have no way of knowing where the cursor position is + * inside of the iframe, so we have to place the newly inserted data in the best place that we can. + */ + el = _elCreate(tagName, tagStyle); + if (this._isElement(tar, 'body') || this._isElement(tar, 'html')) { + if (this._isElement(tar, 'html')) { + tar = this._getDoc().body; + } + tar.appendChild(el); + } else if (tar.nextSibling) { + tar.parentNode.insertBefore(el, tar.nextSibling); + } else { + tar.parentNode.appendChild(el); + } + //this.currentElement = el; + this.currentElement[this.currentElement.length] = el; + this.currentEvent = null; + if (this.browser.webkit) { + //Force Safari to focus the new element + this._getSelection().setBaseAndExtent(el, 0, el, 0); + if (this.browser.webkit3) { + this._getSelection().collapseToStart(); + } else { + this._getSelection().collapse(true); + } + } + } + } else { + //Force CSS Styling for this action... + this._setEditorStyle(true); + this._getDoc().execCommand('fontname', false, 'yui-tmp'); + var _tmp = [], __tmp, __els = ['font', 'span', 'i', 'b', 'u', 'li']; + + if (!this._isElement(this._getSelectedElement(), 'body')) { + __els[__els.length] = this._getDoc().getElementsByTagName(this._getSelectedElement().tagName); + __els[__els.length] = this._getDoc().getElementsByTagName(this._getSelectedElement().parentNode.tagName); + } + for (var _els = 0; _els < __els.length; _els++) { + var _tmp1 = this._getDoc().getElementsByTagName(__els[_els]); + for (var e = 0; e < _tmp1.length; e++) { + _tmp[_tmp.length] = _tmp1[e]; + } + } + + + for (var i = 0; i < _tmp.length; i++) { + if ((Dom.getStyle(_tmp[i], 'fontFamily') == 'yui-tmp') || (_tmp[i].face && (_tmp[i].face == 'yui-tmp'))) { + if (tagName !== 'span') { + el = _elCreate(tagName, tagStyle); + } else { + el = _elCreate(_tmp[i].tagName, tagStyle); + } + el.innerHTML = _tmp[i].innerHTML; + if (this._isElement(_tmp[i], 'ol') || (this._isElement(_tmp[i], 'ul'))) { + var fc = _tmp[i].getElementsByTagName('li')[0]; + _tmp[i].style.fontFamily = 'inherit'; + fc.style.fontFamily = 'inherit'; + el.innerHTML = fc.innerHTML; + fc.innerHTML = ''; + fc.appendChild(el); + this.currentElement[this.currentElement.length] = el; + } else if (this._isElement(_tmp[i], 'li')) { + _tmp[i].innerHTML = ''; + _tmp[i].appendChild(el); + _tmp[i].style.fontFamily = 'inherit'; + this.currentElement[this.currentElement.length] = el; + } else { + if (_tmp[i].parentNode) { + _tmp[i].parentNode.replaceChild(el, _tmp[i]); + this.currentElement[this.currentElement.length] = el; + this.currentEvent = null; + if (this.browser.webkit) { + //Force Safari to focus the new element + this._getSelection().setBaseAndExtent(el, 0, el, 0); + if (this.browser.webkit3) { + this._getSelection().collapseToStart(); + } else { + this._getSelection().collapse(true); + } + } + if (this.browser.ie && tagStyle && tagStyle.fontSize) { + this._getSelection().empty(); + } + if (this.browser.gecko) { + this._getSelection().collapseToStart(); + } + } + } + } + } + var len = this.currentElement.length; + for (var o = 0; o < len; o++) { + if ((o + 1) != len) { //Skip the last one in the list + if (this.currentElement[o] && this.currentElement[o].nextSibling) { + if (this._isElement(this.currentElement[o], 'br')) { + this.currentElement[this.currentElement.length] = this.currentElement[o].nextSibling; + } + } + } + } + } + }, + /** + * @method saveHTML + * @description Cleans the HTML with the cleanHTML method then places that string back into the textarea. + * @return String + */ + saveHTML: function() { + var html = this.cleanHTML(); + if (this._textarea) { + this.get('node').set('value', html); + } else { + this.get('node').set('innerHTML', html); + } + if (this.get('saveEl') !== this.get('node')) { + var out = this.get('saveEl'); + if (out) { + if (out.get('tagName').toLowerCase() === 'textarea') { + out.set('value', html); + } else { + out.set('innerHTML', html); + } + } + } + return html; + }, + /** + * @method setEditorHTML + * @param {String} incomingHTML The html content to load into the editor + * @description Loads HTML into the editors body + */ + setEditorHTML: function(incomingHTML) { + var html = this._cleanIncomingHTML(incomingHTML); + html = html.replace(/RIGHT_BRACKET/gi, '{'); + html = html.replace(/LEFT_BRACKET/gi, '}'); + this._getDoc().body.innerHTML = html; + this.nodeChange(); + }, + /** + * @method getEditorHTML + * @description Gets the unprocessed/unfiltered HTML from the editor + */ + getEditorHTML: function() { + try { + var b = this._getDoc().body; + if (b === null) { + YAHOO.log('Body is null, returning null.', 'error', 'SimpleEditor'); + return null; + } + return this._getDoc().body.innerHTML; + } catch (e) { + return ''; + } + }, + /** + * @method show + * @description This method needs to be called if the Editor was hidden (like in a TabView or Panel). It is used to reset the editor after being in a container that was set to display none. + */ + show: function() { + if (this.browser.gecko) { + this._setDesignMode('on'); + this.focus(); + } + if (this.browser.webkit) { + var self = this; + window.setTimeout(function() { + self._setInitialContent.call(self); + }, 10); + } + //Adding this will close all other Editor window's when showing this one. + if (this.currentWindow) { + this.closeWindow(); + } + //Put the iframe back in place + this.get('iframe').setStyle('position', 'static'); + this.get('iframe').setStyle('left', ''); + }, + /** + * @method hide + * @description This method needs to be called if the Editor is to be hidden (like in a TabView or Panel). It should be called to clear timeouts and close open editor windows. + */ + hide: function() { + //Adding this will close all other Editor window's. + if (this.currentWindow) { + this.closeWindow(); + } + if (this._fixNodesTimer) { + clearTimeout(this._fixNodesTimer); + this._fixNodesTimer = null; + } + if (this._nodeChangeTimer) { + clearTimeout(this._nodeChangeTimer); + this._nodeChangeTimer = null; + } + this._lastNodeChange = 0; + //Move the iframe off of the screen, so that in containers with visiblity hidden, IE will not cover other elements. + this.get('iframe').setStyle('position', 'absolute'); + this.get('iframe').setStyle('left', '-9999px'); + }, + /** + * @method _cleanIncomingHTML + * @param {String} html The unfiltered HTML + * @description Process the HTML with a few regexes to clean it up and stabilize the input + * @return {String} The filtered HTML + */ + _cleanIncomingHTML: function(html) { + html = html.replace(/{/gi, 'RIGHT_BRACKET'); + html = html.replace(/}/gi, 'LEFT_BRACKET'); + + html = html.replace(/]*)>/gi, ''); + html = html.replace(/<\/strong>/gi, ''); + + //replace embed before em check + html = html.replace(/