/*
 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
 Code licensed under the BSD License:
 http://developer.yahoo.com/yui/license.html
 version: 3.3.0
 build: 3167
 */
YUI.add('frame',function(Y){var Frame=function(){Frame.superclass.constructor.apply(this,arguments);};Y.extend(Frame,Y.Base,{_ready:null,_rendered:null,_iframe:null,_instance:null,_create:function(cb){var win,doc,res,node;this._iframe=Y.Node.create(Frame.HTML);this._iframe.setStyle('visibility','hidden');this._iframe.set('src',this.get('src'));this.get('container').append(this._iframe);this._iframe.set('height','99%');var html='',extra_css=((this.get('extracss'))?'<style id="extra_css">'+this.get('extracss')+'</style>':'');html=Y.substitute(Frame.PAGE_HTML,{DIR:this.get('dir'),LANG:this.get('lang'),TITLE:this.get('title'),META:Frame.META,LINKED_CSS:this.get('linkedcss'),CONTENT:this.get('content'),BASE_HREF:this.get('basehref'),DEFAULT_CSS:Frame.DEFAULT_CSS,EXTRA_CSS:extra_css});if(Y.config.doc.compatMode!='BackCompat'){html=Frame.getDocType()+"\n"+html;}else{}
res=this._resolveWinDoc();res.doc.open();res.doc.write(html);res.doc.close();if(this.get('designMode')){res.doc.designMode='on';}
if(!res.doc.documentElement){var timer=Y.later(1,this,function(){if(res.doc&&res.doc.documentElement){cb(res);timer.cancel();}},null,true);}else{cb(res);}},_resolveWinDoc:function(c){var config=(c)?c:{};config.win=Y.Node.getDOMNode(this._iframe.get('contentWindow'));config.doc=Y.Node.getDOMNode(this._iframe.get('contentWindow.document'));if(!config.doc){config.doc=Y.config.doc;}
if(!config.win){config.win=Y.config.win;}
return config;},_onDomEvent:function(e){var xy,node;e.frameX=e.frameY=0;if(e.pageX>0||e.pageY>0){if(e.type.substring(0,3)!=='key'){node=this._instance.one('win');xy=this._iframe.getXY();e.frameX=xy[0]+e.pageX-node.get('scrollLeft');e.frameY=xy[1]+e.pageY-node.get('scrollTop');}}
e.frameTarget=e.target;e.frameCurrentTarget=e.currentTarget;e.frameEvent=e;this.fire('dom:'+e.type,e);},initializer:function(){this.publish('ready',{emitFacade:true,defaultFn:this._defReadyFn});},destructor:function(){var inst=this.getInstance();inst.one('doc').detachAll();inst=null;this._iframe.remove();},_DOMPaste:function(e){var inst=this.getInstance(),data='',win=inst.config.win;if(e._event.originalTarget){data=e._event.originalTarget;}
if(e._event.clipboardData){data=e._event.clipboardData.getData('Text');}
if(win.clipboardData){data=win.clipboardData.getData('Text');if(data===''){if(!win.clipboardData.setData('Text',data)){data=null;}}}
e.frameTarget=e.target;e.frameCurrentTarget=e.currentTarget;e.frameEvent=e;if(data){e.clipboardData={data:data,getData:function(){return data;}};}else{e.clipboardData=null;}
this.fire('dom:paste',e);},_defReadyFn:function(){var inst=this.getInstance(),fn=Y.bind(this._onDomEvent,this),kfn=((Y.UA.ie)?Y.throttle(fn,200):fn);inst.Node.DOM_EVENTS.activate=1;inst.Node.DOM_EVENTS.beforedeactivate=1;inst.Node.DOM_EVENTS.focusin=1;inst.Node.DOM_EVENTS.deactivate=1;inst.Node.DOM_EVENTS.focusout=1;Y.each(Frame.DOM_EVENTS,function(v,k){if(v===1){if(k!=='focus'&&k!=='blur'&&k!=='paste'){if(k.substring(0,3)==='key'){if(k==='keydown'){inst.on(k,fn,inst.config.doc);}else{inst.on(k,kfn,inst.config.doc);}}else{inst.on(k,fn,inst.config.doc);}}}},this);inst.Node.DOM_EVENTS.paste=1;inst.on('paste',Y.bind(this._DOMPaste,this),inst.one('body'));inst.on('focus',fn,inst.config.win);inst.on('blur',fn,inst.config.win);inst._use=inst.use;inst.use=Y.bind(this.use,this);this._iframe.setStyles({visibility:'inherit'});inst.one('body').setStyle('display','block');if(Y.UA.ie){this._fixIECursors();}},_fixIECursors:function(){var inst=this.getInstance(),tables=inst.all('table'),brs=inst.all('br'),si;if(tables.size()&&brs.size()){si=tables.item(0).get('sourceIndex');brs.each(function(n){var p=n.get('parentNode'),c=p.get('children'),b=p.all('>br');if(p.test('div')){if(c.size()>2){n.replace(inst.Node.create('<wbr>'));}else{if(n.get('sourceIndex')>si){if(b.size()){n.replace(inst.Node.create('<wbr>'));}}else{if(b.size()>1){n.replace(inst.Node.create('<wbr>'));}}}}});}},_onContentReady:function(e){if(!this._ready){this._ready=true;var inst=this.getInstance(),args=Y.clone(this.get('use'));this.fire('contentready');if(e){inst.config.doc=Y.Node.getDOMNode(e.target);}
args.push(Y.bind(function(){if(inst.Selection){inst.Selection.DEFAULT_BLOCK_TAG=this.get('defaultblock');}
this.fire('ready');},this));inst.use.apply(inst,args);inst.one('doc').get('documentElement').addClass('yui-js-enabled');}},_resolveBaseHref:function(href){if(!href||href===''){href=Y.config.doc.location.href;if(href.indexOf('?')!==-1){href=href.substring(0,href.indexOf('?'));}
href=href.substring(0,href.lastIndexOf('/'))+'/';}
return href;},_getHTML:function(html){if(this._ready){var inst=this.getInstance();html=inst.one('body').get('innerHTML');}
return html;},_setHTML:function(html){if(this._ready){var inst=this.getInstance();inst.one('body').set('innerHTML',html);}else{this.on('contentready',Y.bind(function(html,e){var inst=this.getInstance();inst.one('body').set('innerHTML',html);},this,html));}
return html;},_getLinkedCSS:function(urls){if(!Y.Lang.isArray(urls)){urls=[urls];}
var str='';if(!this._ready){Y.each(urls,function(v){if(v!==''){str+='<link rel="stylesheet" href="'+v+'" type="text/css">';}});}else{str=urls;}
return str;},_setLinkedCSS:function(css){if(this._ready){var inst=this.getInstance();inst.Get.css(css);}
return css;},_setExtraCSS:function(css){if(this._ready){var inst=this.getInstance(),node=inst.get('#extra_css');node.remove();inst.one('head').append('<style id="extra_css">'+css+'</style>');}
return css;},_instanceLoaded:function(inst){this._instance=inst;this._onContentReady();var doc=this._instance.config.doc;if(this.get('designMode')){if(!Y.UA.ie){try{doc.execCommand('styleWithCSS',false,false);doc.execCommand('insertbronreturn',false,false);}catch(err){}}}},use:function(){var inst=this.getInstance(),args=Y.Array(arguments),cb=false;if(Y.Lang.isFunction(args[args.length-1])){cb=args.pop();}
if(cb){args.push(function(){cb.apply(inst,arguments);});}
inst._use.apply(inst,args);},delegate:function(type,fn,cont,sel){var inst=this.getInstance();if(!inst){return false;}
if(!sel){sel=cont;cont='body';}
return inst.delegate(type,fn,cont,sel);},getInstance:function(){return this._instance;},render:function(node){if(this._rendered){return this;}
this._rendered=true;if(node){this.set('container',node);}
this._create(Y.bind(function(res){var inst,timer,cb=Y.bind(function(i){this._instanceLoaded(i);},this),args=Y.clone(this.get('use')),config={debug:false,win:res.win,doc:res.doc},fn=Y.bind(function(){config=this._resolveWinDoc(config);inst=YUI(config);try{inst.use('node-base',cb);if(timer){clearInterval(timer);}}catch(e){timer=setInterval(function(){fn();},350);}},this);args.push(fn);Y.use.apply(Y,args);},this));return this;},_handleFocus:function(){var inst=this.getInstance(),sel=new inst.Selection();if(sel.anchorNode){var n=sel.anchorNode,c=n.get('childNodes');if(c.size()==1){if(c.item(0).test('br')){sel.selectNode(n,true,false);}
if(c.item(0).test('p')){n=c.item(0).one('br.yui-cursor').get('parentNode');sel.selectNode(n,true,false);}}}},focus:function(fn){if(Y.UA.ie){try{Y.one('win').focus();this.getInstance().one('win').focus();}catch(ierr){}
if(fn===true){this._handleFocus();}
if(Y.Lang.isFunction(fn)){fn();}}else{try{Y.one('win').focus();Y.later(100,this,function(){this.getInstance().one('win').focus();if(fn===true){this._handleFocus();}
if(Y.Lang.isFunction(fn)){fn();}});}catch(ferr){}}
return this;},show:function(){this._iframe.setStyles({position:'static',left:''});if(Y.UA.gecko){try{this._instance.config.doc.designMode='on';}catch(e){}
this.focus();}
return this;},hide:function(){this._iframe.setStyles({position:'absolute',left:'-999999px'});return this;}},{DOM_EVENTS:{dblclick:1,click:1,paste:1,mouseup:1,mousedown:1,keyup:1,keydown:1,keypress:1,activate:1,deactivate:1,beforedeactivate:1,focusin:1,focusout:1},DEFAULT_CSS:'body { 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; } img { cursor: pointer !important; border: none; }',HTML:'<iframe border="0" frameBorder="0" marginWidth="0" marginHeight="0" leftMargin="0" topMargin="0" allowTransparency="true" width="100%" height="99%"></iframe>',PAGE_HTML:'<html dir="{DIR}" lang="{LANG}"><head><title>{TITLE}</title>{META}<base href="{BASE_HREF}"/>{LINKED_CSS}<style id="editor_css">{DEFAULT_CSS}</style>{EXTRA_CSS}</head><body>{CONTENT}</body></html>',getDocType:function(){var dt=Y.config.doc.doctype,str=Frame.DOC_TYPE;if(dt){str='<!DOCTYPE '+dt.name+((dt.publicId)?' '+dt.publicId:'')+((dt.systemId)?' '+dt.systemId:'')+'>';}else{if(Y.config.doc.all){dt=Y.config.doc.all[0];if(dt.nodeType){if(dt.nodeType===8){if(dt.nodeValue){if(dt.nodeValue.toLowerCase().indexOf('doctype')!==-1){str='<!'+dt.nodeValue+'>';}}}}}}
return str;},DOC_TYPE:'<!DOCTYPE HTML PUBLIC "-/'+'/W3C/'+'/DTD HTML 4.01/'+'/EN" "http:/'+'/www.w3.org/TR/html4/strict.dtd">',META:'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>',NAME:'frame',ATTRS:{title:{value:'Blank Page'},dir:{value:'ltr'},lang:{value:'en-US'},src:{value:'javascript'+((Y.UA.ie)?':false':':')+';'},designMode:{writeOnce:true,value:false},content:{value:'<br>',setter:'_setHTML',getter:'_getHTML'},basehref:{value:false,getter:'_resolveBaseHref'},use:{writeOnce:true,value:['substitute','node','node-style','selector-css3']},container:{value:'body',setter:function(n){return Y.one(n);}},node:{readOnly:true,value:null,getter:function(){return this._iframe;}},id:{writeOnce:true,getter:function(id){if(!id){id='iframe-'+Y.guid();}
return id;}},linkedcss:{value:'',getter:'_getLinkedCSS',setter:'_setLinkedCSS'},extracss:{value:'',setter:'_setExtraCSS'},host:{value:false},defaultblock:{value:'p'}}});Y.Frame=Frame;},'3.3.0',{requires:['base','node','selector-css3','substitute'],skinnable:false});YUI.add('selection',function(Y){var textContent='textContent',INNER_HTML='innerHTML',FONT_FAMILY='fontFamily';if(Y.UA.ie){textContent='nodeValue';}
Y.Selection=function(domEvent){var sel,par,ieNode,nodes,rng,i;if(Y.config.win.getSelection){sel=Y.config.win.getSelection();}else if(Y.config.doc.selection){sel=Y.config.doc.selection.createRange();}
this._selection=sel;if(sel.pasteHTML){this.isCollapsed=(sel.compareEndPoints('StartToEnd',sel))?false:true;if(this.isCollapsed){this.anchorNode=this.focusNode=Y.one(sel.parentElement());if(domEvent){ieNode=Y.config.doc.elementFromPoint(domEvent.clientX,domEvent.clientY);}
if(!ieNode){par=sel.parentElement();nodes=par.childNodes;rng=sel.duplicate();for(i=0;i<nodes.length;i++){if(rng.inRange(sel)){if(!ieNode){ieNode=nodes[i];}}}}
this.ieNode=ieNode;if(ieNode){if(ieNode.nodeType!==3){if(ieNode.firstChild){ieNode=ieNode.firstChild;}
if(ieNode&&ieNode.tagName&&ieNode.tagName.toLowerCase()==='body'){if(ieNode.firstChild){ieNode=ieNode.firstChild;}}}
this.anchorNode=this.focusNode=Y.Selection.resolve(ieNode);this.anchorOffset=this.focusOffset=(this.anchorNode.nodeValue)?this.anchorNode.nodeValue.length:0;this.anchorTextNode=this.focusTextNode=Y.one(ieNode);}}else{if(sel.htmlText){var n=Y.Node.create(sel.htmlText);if(n.get('id')){var id=n.get('id');this.anchorNode=this.focusNode=Y.one('#'+id);}else{n=n.get('childNodes');this.anchorNode=this.focusNode=n.item(0);}}}}else{this.isCollapsed=sel.isCollapsed;this.anchorNode=Y.Selection.resolve(sel.anchorNode);this.focusNode=Y.Selection.resolve(sel.focusNode);this.anchorOffset=sel.anchorOffset;this.focusOffset=sel.focusOffset;this.anchorTextNode=Y.one(sel.anchorNode);this.focusTextNode=Y.one(sel.focusNode);}
if(Y.Lang.isString(sel.text)){this.text=sel.text;}else{if(sel.toString){this.text=sel.toString();}else{this.text='';}}};Y.Selection.filter=function(blocks){var startTime=(new Date()).getTime();var nodes=Y.all(Y.Selection.ALL),baseNodes=Y.all('strong,em'),doc=Y.config.doc,hrs=doc.getElementsByTagName('hr'),classNames={},cssString='',ls;var startTime1=(new Date()).getTime();nodes.each(function(n){var raw=Y.Node.getDOMNode(n);if(raw.style[FONT_FAMILY]){classNames['.'+n._yuid]=raw.style[FONT_FAMILY];n.addClass(n._yuid);raw.style[FONT_FAMILY]='inherit';raw.removeAttribute('face');if(raw.getAttribute('style')===''){raw.removeAttribute('style');}
if(raw.getAttribute('style')){if(raw.getAttribute('style').toLowerCase()==='font-family: '){raw.removeAttribute('style');}}}});var endTime1=(new Date()).getTime();Y.all('.hr').addClass('yui-skip').addClass('yui-non');Y.each(hrs,function(hr){var el=doc.createElement('div');el.className='hr yui-non yui-skip';el.setAttribute('readonly',true);el.setAttribute('contenteditable',false);if(hr.parentNode){hr.parentNode.replaceChild(el,hr);}
var s=el.style;s.border='1px solid #ccc';s.lineHeight='0';s.fontSize='0';s.marginTop='5px';s.marginBottom='5px';s.marginLeft='0px';s.marginRight='0px';s.padding='0';});Y.each(classNames,function(v,k){cssString+=k+' { font-family: '+v.replace(/"/gi,'')+'; }';});Y.StyleSheet(cssString,'editor');baseNodes.each(function(n,k){var t=n.get('tagName').toLowerCase(),newTag='i';if(t==='strong'){newTag='b';}
Y.Selection.prototype._swap(baseNodes.item(k),newTag);});ls=Y.all('ol,ul');ls.each(function(v,k){var lis=v.all('li');if(!lis.size()){v.remove();}});if(blocks){Y.Selection.filterBlocks();}
var endTime=(new Date()).getTime();};Y.Selection.filterBlocks=function(){var startTime=(new Date()).getTime();var childs=Y.config.doc.body.childNodes,i,node,wrapped=false,doit=true,sel,single,br,divs,spans,c,s;if(childs){for(i=0;i<childs.length;i++){node=Y.one(childs[i]);if(!node.test(Y.Selection.BLOCKS)){doit=true;if(childs[i].nodeType==3){c=childs[i][textContent].match(Y.Selection.REG_CHAR);s=childs[i][textContent].match(Y.Selection.REG_NON);if(c===null&&s){doit=false;}}
if(doit){if(!wrapped){wrapped=[];}
wrapped.push(childs[i]);}}else{wrapped=Y.Selection._wrapBlock(wrapped);}}
wrapped=Y.Selection._wrapBlock(wrapped);}
single=Y.all(Y.Selection.DEFAULT_BLOCK_TAG);if(single.size()===1){br=single.item(0).all('br');if(br.size()===1){if(!br.item(0).test('.yui-cursor')){br.item(0).remove();}
var html=single.item(0).get('innerHTML');if(html===''||html===' '){single.set('innerHTML',Y.Selection.CURSOR);sel=new Y.Selection();sel.focusCursor(true,true);}}}else{single.each(function(p){var html=p.get('innerHTML');if(html===''){p.remove();}});}
if(!Y.UA.ie){}
var endTime=(new Date()).getTime();};Y.Selection.REG_CHAR=/[a-zA-Z-0-9_]/gi;Y.Selection.REG_NON=/[\s\S|\n|\t]/gi;Y.Selection.REG_NOHTML=/<\S[^><]*>/g;Y.Selection._wrapBlock=function(wrapped){if(wrapped){var newChild=Y.Node.create('<'+Y.Selection.DEFAULT_BLOCK_TAG+'></'+Y.Selection.DEFAULT_BLOCK_TAG+'>'),firstChild=Y.one(wrapped[0]),i;for(i=1;i<wrapped.length;i++){newChild.append(wrapped[i]);}
firstChild.replace(newChild);newChild.prepend(firstChild);}
return false;};Y.Selection.unfilter=function(){var nodes=Y.all('body [class]'),html='',nons,ids,body=Y.one('body');nodes.each(function(n){if(n.hasClass(n._yuid)){n.setStyle(FONT_FAMILY,n.getStyle(FONT_FAMILY));n.removeClass(n._yuid);if(n.getAttribute('class')===''){n.removeAttribute('class');}}});nons=Y.all('.yui-non');nons.each(function(n){if(!n.hasClass('yui-skip')&&n.get('innerHTML')===''){n.remove();}else{n.removeClass('yui-non').removeClass('yui-skip');}});ids=Y.all('body [id]');ids.each(function(n){if(n.get('id').indexOf('yui_3_')===0){n.removeAttribute('id');n.removeAttribute('_yuid');}});if(body){html=body.get('innerHTML');}
Y.all('.hr').addClass('yui-skip').addClass('yui-non');return html;};Y.Selection.resolve=function(n){if(n&&n.nodeType===3){try{n=n.parentNode;}catch(re){n='body';}}
return Y.one(n);};Y.Selection.getText=function(node){var txt=node.get('innerHTML').replace(Y.Selection.REG_NOHTML,'');txt=txt.replace('<span><br></span>','').replace('<br>','');return txt;};Y.Selection.DEFAULT_BLOCK_TAG='p';Y.Selection.ALL='[style],font[face]';Y.Selection.BLOCKS='p,div,ul,ol,table,style';Y.Selection.TMP='yui-tmp';Y.Selection.DEFAULT_TAG='span';Y.Selection.CURID='yui-cursor';Y.Selection.CUR_WRAPID='yui-cursor-wrapper';Y.Selection.CURSOR='<span><br class="yui-cursor"></span>';Y.Selection.hasCursor=function(){var cur=Y.all('#'+Y.Selection.CUR_WRAPID);return cur.size();};Y.Selection.cleanCursor=function(){var cur,sel='br.yui-cursor';cur=Y.all(sel);if(cur.size()){cur.each(function(b){var c=b.get('parentNode.parentNode.childNodes'),html;if(c.size()>1){b.remove();}else{html=Y.Selection.getText(c.item(0));if(html!==''){b.remove();}}});}};Y.Selection.prototype={text:null,isCollapsed:null,anchorNode:null,anchorOffset:null,anchorTextNode:null,focusNode:null,focusOffset:null,focusTextNode:null,_selection:null,_wrap:function(n,tag){var tmp=Y.Node.create('<'+tag+'></'+tag+'>');tmp.set(INNER_HTML,n.get(INNER_HTML));n.set(INNER_HTML,'');n.append(tmp);return Y.Node.getDOMNode(tmp);},_swap:function(n,tag){var tmp=Y.Node.create('<'+tag+'></'+tag+'>');tmp.set(INNER_HTML,n.get(INNER_HTML));n.replace(tmp,n);return Y.Node.getDOMNode(tmp);},getSelected:function(){Y.Selection.filter();Y.config.doc.execCommand('fontname',null,Y.Selection.TMP);var nodes=Y.all(Y.Selection.ALL),items=[];nodes.each(function(n,k){if(n.getStyle(FONT_FAMILY)==Y.Selection.TMP){n.setStyle(FONT_FAMILY,'');n.removeAttribute('face');if(n.getAttribute('style')===''){n.removeAttribute('style');}
if(!n.test('body')){items.push(Y.Node.getDOMNode(nodes.item(k)));}}});return Y.all(items);},insertContent:function(html){return this.insertAtCursor(html,this.anchorTextNode,this.anchorOffset,true);},insertAtCursor:function(html,node,offset,collapse){var cur=Y.Node.create('<'+Y.Selection.DEFAULT_TAG+' class="yui-non"></'+Y.Selection.DEFAULT_TAG+'>'),inHTML,txt,txt2,newNode,range=this.createRange(),b;if(node&&node.test('body')){b=Y.Node.create('<span></span>');node.append(b);node=b;}
if(range.pasteHTML){newNode=Y.Node.create(html);try{range.pasteHTML('<span id="rte-insert"></span>');}catch(e){}
inHTML=Y.one('#rte-insert');if(inHTML){inHTML.set('id','');inHTML.replace(newNode);return newNode;}else{Y.on('available',function(){inHTML.set('id','');inHTML.replace(newNode);},'#rte-insert');}}else{if(offset>0){inHTML=node.get(textContent);txt=Y.one(Y.config.doc.createTextNode(inHTML.substr(0,offset)));txt2=Y.one(Y.config.doc.createTextNode(inHTML.substr(offset)));node.replace(txt,node);newNode=Y.Node.create(html);if(newNode.get('nodeType')===11){b=Y.Node.create('<span></span>');b.append(newNode);newNode=b;}
txt.insert(newNode,'after');if(txt2){newNode.insert(cur,'after');cur.insert(txt2,'after');this.selectNode(cur,collapse);}}else{if(node.get('nodeType')===3){node=node.get('parentNode');}
newNode=Y.Node.create(html);html=node.get('innerHTML').replace(/\n/gi,'');if(html===''||html==='<br>'){node.append(newNode);}else{if(newNode.get('parentNode')){node.insert(newNode,'before');}else{Y.one('body').prepend(newNode);}}
if(node.get('firstChild').test('br')){node.get('firstChild').remove();}}}
return newNode;},wrapContent:function(tag){tag=(tag)?tag:Y.Selection.DEFAULT_TAG;if(!this.isCollapsed){var items=this.getSelected(),changed=[],range,last,first,range2;items.each(function(n,k){var t=n.get('tagName').toLowerCase();if(t==='font'){changed.push(this._swap(items.item(k),tag));}else{changed.push(this._wrap(items.item(k),tag));}},this);range=this.createRange();first=changed[0];last=changed[changed.length-1];if(this._selection.removeAllRanges){range.setStart(changed[0],0);range.setEnd(last,last.childNodes.length);this._selection.removeAllRanges();this._selection.addRange(range);}else{range.moveToElementText(Y.Node.getDOMNode(first));range2=this.createRange();range2.moveToElementText(Y.Node.getDOMNode(last));range.setEndPoint('EndToEnd',range2);range.select();}
changed=Y.all(changed);return changed;}else{return Y.all([]);}},replace:function(se,re){var range=this.createRange(),node,txt,index,newNode;if(range.getBookmark){index=range.getBookmark();txt=this.anchorNode.get('innerHTML').replace(se,re);this.anchorNode.set('innerHTML',txt);range.moveToBookmark(index);newNode=Y.one(range.parentElement());}else{node=this.anchorTextNode;txt=node.get(textContent);index=txt.indexOf(se);txt=txt.replace(se,'');node.set(textContent,txt);newNode=this.insertAtCursor(re,node,index,true);}
return newNode;},remove:function(){this._selection.removeAllRanges();return this;},createRange:function(){if(Y.config.doc.selection){return Y.config.doc.selection.createRange();}else{return Y.config.doc.createRange();}},selectNode:function(node,collapse,end){if(!node){return;}
end=end||0;node=Y.Node.getDOMNode(node);var range=this.createRange();if(range.selectNode){range.selectNode(node);this._selection.removeAllRanges();this._selection.addRange(range);if(collapse){try{this._selection.collapse(node,end);}catch(err){this._selection.collapse(node,0);}}}else{if(node.nodeType===3){node=node.parentNode;}
try{range.moveToElementText(node);}catch(e){}
if(collapse){range.collapse(((end)?false:true));}
range.select();}
return this;},setCursor:function(){this.removeCursor(false);return this.insertContent(Y.Selection.CURSOR);},getCursor:function(){return Y.all('#'+Y.Selection.CURID);},removeCursor:function(keep){var cur=this.getCursor();if(cur){if(keep){cur.removeAttribute('id');cur.set('innerHTML','<br class="yui-cursor">');}else{cur.remove();}}
return cur;},focusCursor:function(collapse,end){if(collapse!==false){collapse=true;}
if(end!==false){end=true;}
var cur=this.removeCursor(true);if(cur){cur.each(function(c){this.selectNode(c,collapse,end);},this);}},toString:function(){return'Selection Object';}};},'3.3.0',{requires:['node'],skinnable:false});YUI.add('exec-command',function(Y){var ExecCommand=function(){ExecCommand.superclass.constructor.apply(this,arguments);};Y.extend(ExecCommand,Y.Base,{_lastKey:null,_inst:null,command:function(action,value){var fn=ExecCommand.COMMANDS[action];if(fn){return fn.call(this,action,value);}else{return this._command(action,value);}},_command:function(action,value){var inst=this.getInstance();try{try{inst.config.doc.execCommand('styleWithCSS',null,1);}catch(e1){try{inst.config.doc.execCommand('useCSS',null,0);}catch(e2){}}
inst.config.doc.execCommand(action,null,value);}catch(e){}},getInstance:function(){if(!this._inst){this._inst=this.get('host').getInstance();}
return this._inst;},initializer:function(){Y.mix(this.get('host'),{execCommand:function(action,value){return this.exec.command(action,value);},_execCommand:function(action,value){return this.exec._command(action,value);}});this.get('host').on('dom:keypress',Y.bind(function(e){this._lastKey=e.keyCode;},this));}},{NAME:'execCommand',NS:'exec',ATTRS:{host:{value:false}},COMMANDS:{wrap:function(cmd,tag){var inst=this.getInstance();return(new inst.Selection()).wrapContent(tag);},inserthtml:function(cmd,html){var inst=this.getInstance();if(inst.Selection.hasCursor()||Y.UA.ie){return(new inst.Selection()).insertContent(html);}else{this._command('inserthtml',html);}},insertandfocus:function(cmd,html){var inst=this.getInstance(),out,sel;if(inst.Selection.hasCursor()){html+=inst.Selection.CURSOR;out=this.command('inserthtml',html);sel=new inst.Selection();sel.focusCursor(true,true);}else{this.command('inserthtml',html);}
return out;},insertbr:function(cmd){var inst=this.getInstance(),cur,sel=new inst.Selection();sel.setCursor();cur=sel.getCursor();cur.insert('<br>','before');sel.focusCursor(true,false);return((cur&&cur.previous)?cur.previous():null);},insertimage:function(cmd,img){return this.command('inserthtml','<img src="'+img+'">');},addclass:function(cmd,cls){var inst=this.getInstance();return(new inst.Selection()).getSelected().addClass(cls);},removeclass:function(cmd,cls){var inst=this.getInstance();return(new inst.Selection()).getSelected().removeClass(cls);},forecolor:function(cmd,val){var inst=this.getInstance(),sel=new inst.Selection(),n;if(!Y.UA.ie){this._command('useCSS',false);}
if(inst.Selection.hasCursor()){if(sel.isCollapsed){if(sel.anchorNode&&(sel.anchorNode.get('innerHTML')==='&nbsp;')){sel.anchorNode.setStyle('color',val);n=sel.anchorNode;}else{n=this.command('inserthtml','<span style="color: '+val+'">'+inst.Selection.CURSOR+'</span>');sel.focusCursor(true,true);}
return n;}else{return this._command(cmd,val);}}else{this._command(cmd,val);}},backcolor:function(cmd,val){var inst=this.getInstance(),sel=new inst.Selection(),n;if(Y.UA.gecko||Y.UA.opera){cmd='hilitecolor';}
if(!Y.UA.ie){this._command('useCSS',false);}
if(inst.Selection.hasCursor()){if(sel.isCollapsed){if(sel.anchorNode&&(sel.anchorNode.get('innerHTML')==='&nbsp;')){sel.anchorNode.setStyle('backgroundColor',val);n=sel.anchorNode;}else{n=this.command('inserthtml','<span style="background-color: '+val+'">'+inst.Selection.CURSOR+'</span>');sel.focusCursor(true,true);}
return n;}else{return this._command(cmd,val);}}else{this._command(cmd,val);}},hilitecolor:function(){return ExecCommand.COMMANDS.backcolor.apply(this,arguments);},fontname:function(cmd,val){this._command('fontname',val);var inst=this.getInstance(),sel=new inst.Selection();if(sel.isCollapsed&&(this._lastKey!=32)){if(sel.anchorNode.test('font')){sel.anchorNode.set('face',val);}}},fontsize:function(cmd,val){this._command('fontsize',val);var inst=this.getInstance(),sel=new inst.Selection();if(sel.isCollapsed&&sel.anchorNode&&(this._lastKey!=32)){if(Y.UA.webkit){if(sel.anchorNode.getStyle('lineHeight')){sel.anchorNode.setStyle('lineHeight','');}}
if(sel.anchorNode.test('font')){sel.anchorNode.set('size',val);}else if(Y.UA.gecko){var p=sel.anchorNode.ancestor(inst.Selection.DEFAULT_BLOCK_TAG);if(p){p.setStyle('fontSize','');}}}}}});var fixIETags=function(cmd,tag,rule){var inst=this.getInstance(),doc=inst.config.doc,sel=doc.selection.createRange(),o=doc.queryCommandValue(cmd),html,reg,m,p,d,s,c;if(o){html=sel.htmlText;reg=new RegExp(rule,'g');m=html.match(reg);if(m){html=html.replace(rule+';','').replace(rule,'');sel.pasteHTML('<var id="yui-ie-bs">');p=doc.getElementById('yui-ie-bs');d=doc.createElement('div');s=doc.createElement(tag);d.innerHTML=html;if(p.parentNode!==inst.config.doc.body){p=p.parentNode;}
c=d.childNodes;p.parentNode.replaceChild(s,p);Y.each(c,function(f){s.appendChild(f);});sel.collapse();sel.moveToElementText(s);sel.select();}}
this._command(cmd);};if(Y.UA.ie){ExecCommand.COMMANDS.bold=function(){fixIETags.call(this,'bold','b','FONT-WEIGHT: bold');}
ExecCommand.COMMANDS.italic=function(){fixIETags.call(this,'italic','i','FONT-STYLE: italic');}
ExecCommand.COMMANDS.underline=function(){fixIETags.call(this,'underline','u','TEXT-DECORATION: underline');}}
Y.namespace('Plugin');Y.Plugin.ExecCommand=ExecCommand;},'3.3.0',{requires:['frame'],skinnable:false});YUI.add('editor-tab',function(Y){var EditorTab=function(){EditorTab.superclass.constructor.apply(this,arguments);},HOST='host';Y.extend(EditorTab,Y.Base,{_onNodeChange:function(e){var action='indent';if(e.changedType==='tab'){if(!e.changedNode.test('li, li *')){e.changedEvent.halt();e.preventDefault();if(e.changedEvent.shiftKey){action='outdent';}
this.get(HOST).execCommand(action,'');}}},initializer:function(){this.get(HOST).on('nodeChange',Y.bind(this._onNodeChange,this));}},{NAME:'editorTab',NS:'tab',ATTRS:{host:{value:false}}});Y.namespace('Plugin');Y.Plugin.EditorTab=EditorTab;},'3.3.0',{requires:['editor-base'],skinnable:false});YUI.add('createlink-base',function(Y){var CreateLinkBase={};CreateLinkBase.STRINGS={PROMPT:'Please enter the URL for the link to point to:',DEFAULT:'http://'};Y.namespace('Plugin');Y.Plugin.CreateLinkBase=CreateLinkBase;Y.mix(Y.Plugin.ExecCommand.COMMANDS,{createlink:function(cmd){var inst=this.get('host').getInstance(),out,a,sel,holder,url=prompt(CreateLinkBase.STRINGS.PROMPT,CreateLinkBase.STRINGS.DEFAULT);if(url){holder=inst.config.doc.createElement('div');url=inst.config.doc.createTextNode(url);holder.appendChild(url);url=holder.innerHTML;this.get('host')._execCommand(cmd,url);sel=new inst.Selection();out=sel.getSelected();if(!sel.isCollapsed&&out.size()){a=out.item(0).one('a');if(a){out.item(0).replace(a);}
if(Y.UA.gecko){if(a.get('parentNode').test('span')){if(a.get('parentNode').one('br.yui-cursor')){a.get('parentNode').insert(a,'before');}}}}else{this.get('host').execCommand('inserthtml','<a href="'+url+'">'+url+'</a>');}}
return a;}});},'3.3.0',{requires:['editor-base'],skinnable:false});YUI.add('editor-base',function(Y){var EditorBase=function(){EditorBase.superclass.constructor.apply(this,arguments);},LAST_CHILD=':last-child',BODY='body';Y.extend(EditorBase,Y.Base,{frame:null,initializer:function(){var frame=new Y.Frame({designMode:true,title:EditorBase.STRINGS.title,use:EditorBase.USE,dir:this.get('dir'),extracss:this.get('extracss'),linkedcss:this.get('linkedcss'),defaultblock:this.get('defaultblock'),host:this}).plug(Y.Plugin.ExecCommand);frame.after('ready',Y.bind(this._afterFrameReady,this));frame.addTarget(this);this.frame=frame;this.publish('nodeChange',{emitFacade:true,bubbles:true,defaultFn:this._defNodeChangeFn});},destructor:function(){this.frame.destroy();this.detachAll();},copyStyles:function(from,to){if(from.test('a')){return;}
var styles=['color','fontSize','fontFamily','backgroundColor','fontStyle'],newStyles={};Y.each(styles,function(v){newStyles[v]=from.getStyle(v);});if(from.ancestor('b,strong')){newStyles.fontWeight='bold';}
if(from.ancestor('u')){if(!newStyles.textDecoration){newStyles.textDecoration='underline';}}
to.setStyles(newStyles);},_lastBookmark:null,_resolveChangedNode:function(n){var inst=this.getInstance(),lc,lc2,found;if(inst&&n&&n.test('html')){lc=inst.one(BODY).one(LAST_CHILD);while(!found){if(lc){lc2=lc.one(LAST_CHILD);if(lc2){lc=lc2;}else{found=true;}}else{found=true;}}
if(lc){if(lc.test('br')){if(lc.previous()){lc=lc.previous();}else{lc=lc.get('parentNode');}}
if(lc){n=lc;}}}
return n;},_defNodeChangeFn:function(e){var startTime=(new Date()).getTime();var inst=this.getInstance(),sel,cur,btag=inst.Selection.DEFAULT_BLOCK_TAG;if(Y.UA.ie){try{sel=inst.config.doc.selection.createRange();if(sel.getBookmark){this._lastBookmark=sel.getBookmark();}}catch(ie){}}
e.changedNode=this._resolveChangedNode(e.changedNode);switch(e.changedType){case'keydown':if(!Y.UA.gecko){if(!EditorBase.NC_KEYS[e.changedEvent.keyCode]&&!e.changedEvent.shiftKey&&!e.changedEvent.ctrlKey&&(e.changedEvent.keyCode!==13)){}}
break;case'tab':if(!e.changedNode.test('li, li *')&&!e.changedEvent.shiftKey){e.changedEvent.frameEvent.preventDefault();if(Y.UA.webkit){this.execCommand('inserttext','\t');}else if(Y.UA.gecko){this.frame.exec._command('inserthtml','<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>');}else if(Y.UA.ie){sel=new inst.Selection();sel._selection.pasteHTML(EditorBase.TABKEY);}}
break;}
if(Y.UA.webkit&&e.commands&&(e.commands.indent||e.commands.outdent)){var bq=inst.all('.webkit-indent-blockquote');if(bq.size()){bq.setStyle('margin','');}}
var changed=this.getDomPath(e.changedNode,false),cmds={},family,fsize,classes=[],fColor='',bColor='';if(e.commands){cmds=e.commands;}
Y.each(changed,function(el){var tag=el.tagName.toLowerCase(),cmd=EditorBase.TAG2CMD[tag];if(cmd){cmds[cmd]=1;}
var s=el.currentStyle||el.style;if((''+s.fontWeight)=='bold'){cmds.bold=1;}
if(Y.UA.ie){if(s.fontWeight>400){cmds.bold=1;}}
if(s.fontStyle=='italic'){cmds.italic=1;}
if(s.textDecoration=='underline'){cmds.underline=1;}
if(s.textDecoration=='line-through'){cmds.strikethrough=1;}
var n=inst.one(el);if(n.getStyle('fontFamily')){var family2=n.getStyle('fontFamily').split(',')[0].toLowerCase();if(family2){family=family2;}
if(family){family=family.replace(/'/g,'').replace(/"/g,'');}}
fsize=EditorBase.NORMALIZE_FONTSIZE(n);var cls=el.className.split(' ');Y.each(cls,function(v){if(v!==''&&(v.substr(0,4)!=='yui_')){classes.push(v);}});fColor=EditorBase.FILTER_RGB(n.getStyle('color'));var bColor2=EditorBase.FILTER_RGB(s.backgroundColor);if(bColor2!=='transparent'){if(bColor2!==''){bColor=bColor2;}}});e.dompath=inst.all(changed);e.classNames=classes;e.commands=cmds;if(!e.fontFamily){e.fontFamily=family;}
if(!e.fontSize){e.fontSize=fsize;}
if(!e.fontColor){e.fontColor=fColor;}
if(!e.backgroundColor){e.backgroundColor=bColor;}
var endTime=(new Date()).getTime();},getDomPath:function(node,nodeList){var domPath=[],domNode,inst=this.frame.getInstance();domNode=inst.Node.getDOMNode(node);while(domNode!==null){if((domNode===inst.config.doc.documentElement)||(domNode===inst.config.doc)||!domNode.tagName){domNode=null;break;}
if(!inst.DOM.inDoc(domNode)){domNode=null;break;}
if(domNode.nodeName&&domNode.nodeType&&(domNode.nodeType==1)){domPath.push(domNode);}
if(domNode==inst.config.doc.body){domNode=null;break;}
domNode=domNode.parentNode;}
if(domPath.length===0){domPath[0]=inst.config.doc.body;}
if(nodeList){return inst.all(domPath.reverse());}else{return domPath.reverse();}},_afterFrameReady:function(){var inst=this.frame.getInstance();this.frame.on('dom:mouseup',Y.bind(this._onFrameMouseUp,this));this.frame.on('dom:mousedown',Y.bind(this._onFrameMouseDown,this));this.frame.on('dom:keydown',Y.bind(this._onFrameKeyDown,this));if(Y.UA.ie){this.frame.on('dom:activate',Y.bind(this._onFrameActivate,this));this.frame.on('dom:beforedeactivate',Y.bind(this._beforeFrameDeactivate,this));}
this.frame.on('dom:keyup',Y.bind(this._onFrameKeyUp,this));this.frame.on('dom:keypress',Y.bind(this._onFrameKeyPress,this));inst.Selection.filter();this.fire('ready');},_beforeFrameDeactivate:function(){var inst=this.getInstance(),sel=inst.config.doc.selection.createRange();if((!sel.compareEndPoints('StartToEnd',sel))){sel.pasteHTML('<var id="yui-ie-cursor">');}},_onFrameActivate:function(){var inst=this.getInstance(),sel=new inst.Selection(),range=sel.createRange(),cur=inst.all('#yui-ie-cursor');if(cur.size()){cur.each(function(n){n.set('id','');range.moveToElementText(n._node);range.move('character',-1);range.move('character',1);range.select();range.text='';n.remove();});}},_onFrameMouseUp:function(e){this.fire('nodeChange',{changedNode:e.frameTarget,changedType:'mouseup',changedEvent:e.frameEvent});},_onFrameMouseDown:function(e){this.fire('nodeChange',{changedNode:e.frameTarget,changedType:'mousedown',changedEvent:e.frameEvent});},_currentSelection:null,_currentSelectionTimer:null,_currentSelectionClear:null,_onFrameKeyDown:function(e){var inst,sel;if(!this._currentSelection){if(this._currentSelectionTimer){this._currentSelectionTimer.cancel();}
this._currentSelectionTimer=Y.later(850,this,function(){this._currentSelectionClear=true;});inst=this.frame.getInstance();sel=new inst.Selection(e);this._currentSelection=sel;}else{sel=this._currentSelection;}
inst=this.frame.getInstance();sel=new inst.Selection();this._currentSelection=sel;if(sel&&sel.anchorNode){this.fire('nodeChange',{changedNode:sel.anchorNode,changedType:'keydown',changedEvent:e.frameEvent});if(EditorBase.NC_KEYS[e.keyCode]){this.fire('nodeChange',{changedNode:sel.anchorNode,changedType:EditorBase.NC_KEYS[e.keyCode],changedEvent:e.frameEvent});this.fire('nodeChange',{changedNode:sel.anchorNode,changedType:EditorBase.NC_KEYS[e.keyCode]+'-down',changedEvent:e.frameEvent});}}},_onFrameKeyPress:function(e){var sel=this._currentSelection;if(sel&&sel.anchorNode){this.fire('nodeChange',{changedNode:sel.anchorNode,changedType:'keypress',changedEvent:e.frameEvent});if(EditorBase.NC_KEYS[e.keyCode]){this.fire('nodeChange',{changedNode:sel.anchorNode,changedType:EditorBase.NC_KEYS[e.keyCode]+'-press',changedEvent:e.frameEvent});}}},_onFrameKeyUp:function(e){var sel=this._currentSelection;if(sel&&sel.anchorNode){this.fire('nodeChange',{changedNode:sel.anchorNode,changedType:'keyup',selection:sel,changedEvent:e.frameEvent});if(EditorBase.NC_KEYS[e.keyCode]){this.fire('nodeChange',{changedNode:sel.anchorNode,changedType:EditorBase.NC_KEYS[e.keyCode]+'-up',selection:sel,changedEvent:e.frameEvent});}}
if(this._currentSelectionClear){this._currentSelectionClear=this._currentSelection=null;}},execCommand:function(cmd,val){var ret=this.frame.execCommand(cmd,val),inst=this.frame.getInstance(),sel=new inst.Selection(),cmds={},e={changedNode:sel.anchorNode,changedType:'execcommand',nodes:ret};switch(cmd){case'forecolor':e.fontColor=val;break;case'backcolor':e.backgroundColor=val;break;case'fontsize':e.fontSize=val;break;case'fontname':e.fontFamily=val;break;}
cmds[cmd]=1;e.commands=cmds;this.fire('nodeChange',e);return ret;},getInstance:function(){return this.frame.getInstance();},render:function(node){this.frame.set('content',this.get('content'));this.frame.render(node);return this;},focus:function(fn){this.frame.focus(fn);return this;},show:function(){this.frame.show();return this;},hide:function(){this.frame.hide();return this;},getContent:function(){var html='',inst=this.getInstance();if(inst&&inst.Selection){html=inst.Selection.unfilter();}
html=html.replace(/ _yuid="([^>]*)"/g,'');return html;}},{NORMALIZE_FONTSIZE:function(n){var size=n.getStyle('fontSize'),oSize=size;switch(size){case'-webkit-xxx-large':size='48px';break;case'xx-large':size='32px';break;case'x-large':size='24px';break;case'large':size='18px';break;case'medium':size='16px';break;case'small':size='13px';break;case'x-small':size='10px';break;}
if(oSize!==size){n.setStyle('fontSize',size);}
return size;},TABKEY:'<span class="tab">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>',FILTER_RGB:function(css){if(css.toLowerCase().indexOf('rgb')!=-1){var exp=new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)","gi");var rgb=css.replace(exp,"$1,$2,$3,$4,$5").split(',');if(rgb.length==5){var r=parseInt(rgb[1],10).toString(16);var g=parseInt(rgb[2],10).toString(16);var b=parseInt(rgb[3],10).toString(16);r=r.length==1?'0'+r:r;g=g.length==1?'0'+g:g;b=b.length==1?'0'+b:b;css="#"+r+g+b;}}
return css;},TAG2CMD:{'b':'bold','strong':'bold','i':'italic','em':'italic','u':'underline','sup':'superscript','sub':'subscript','img':'insertimage','a':'createlink','ul':'insertunorderedlist','ol':'insertorderedlist'},NC_KEYS:{8:'backspace',9:'tab',13:'enter',32:'space',33:'pageup',34:'pagedown',35:'end',36:'home',37:'left',38:'up',39:'right',40:'down',46:'delete'},USE:['substitute','node','selector-css3','selection','stylesheet'],NAME:'editorBase',STRINGS:{title:'Rich Text Editor'},ATTRS:{content:{value:'<br class="yui-cursor">',setter:function(str){if(str.substr(0,1)==="\n"){str=str.substr(1);}
if(str===''){str='<br class="yui-cursor">';}
if(str===' '){if(Y.UA.gecko){str='<br class="yui-cursor">';}}
return this.frame.set('content',str);},getter:function(){return this.frame.get('content');}},dir:{writeOnce:true,value:'ltr'},linkedcss:{value:'',setter:function(css){if(this.frame){this.frame.set('linkedcss',css);}
return css;}},extracss:{value:false,setter:function(css){if(this.frame){this.frame.set('extracss',css);}
return css;}},defaultblock:{value:'p'}}});Y.EditorBase=EditorBase;},'3.3.0',{requires:['base','frame','node','exec-command','selection','editor-para'],skinnable:false});YUI.add('editor-lists',function(Y){var EditorLists=function(){EditorLists.superclass.constructor.apply(this,arguments);},LI='li',OL='ol',UL='ul',HOST='host';Y.extend(EditorLists,Y.Base,{_onNodeChange:function(e){var inst=this.get(HOST).getInstance(),sel,li,newLi,newList,sTab,par,moved=false,tag,focusEnd=false;if(Y.UA.ie&&e.changedType==='enter'){if(e.changedNode.test(LI+', '+LI+' *')){e.changedEvent.halt();e.preventDefault();li=e.changedNode;newLi=inst.Node.create('<'+LI+'>'+EditorLists.NON+'</'+LI+'>');if(!li.test(LI)){li=li.ancestor(LI);}
li.insert(newLi,'after');sel=new inst.Selection();sel.selectNode(newLi.get('firstChild'),true,false);}}
if(e.changedType==='tab'){if(e.changedNode.test(LI+', '+LI+' *')){e.changedEvent.halt();e.preventDefault();li=e.changedNode;sTab=e.changedEvent.shiftKey;par=li.ancestor(OL+','+UL);tag=UL;if(par.get('tagName').toLowerCase()===OL){tag=OL;}
if(!li.test(LI)){li=li.ancestor(LI);}
if(sTab){if(li.ancestor(LI)){li.ancestor(LI).insert(li,'after');moved=true;focusEnd=true;}}else{if(li.previous(LI)){newList=inst.Node.create('<'+tag+'></'+tag+'>');li.previous(LI).append(newList);newList.append(li);moved=true;}}}
if(moved){if(!li.test(LI)){li=li.ancestor(LI);}
li.all(EditorLists.REMOVE).remove();if(Y.UA.ie){li=li.append(EditorLists.NON).one(EditorLists.NON_SEL);}
(new inst.Selection()).selectNode(li,true,focusEnd);}}},initializer:function(){this.get(HOST).on('nodeChange',Y.bind(this._onNodeChange,this));}},{NON:'<span class="yui-non">&nbsp;</span>',NON_SEL:'span.yui-non',REMOVE:'br',NAME:'editorLists',NS:'lists',ATTRS:{host:{value:false}}});Y.namespace('Plugin');Y.Plugin.EditorLists=EditorLists;Y.mix(Y.Plugin.ExecCommand.COMMANDS,{insertunorderedlist:function(cmd){var inst=this.get('host').getInstance(),out;this.get('host')._execCommand(cmd,'');},insertorderedlist:function(cmd){var inst=this.get('host').getInstance(),out;this.get('host')._execCommand(cmd,'');}});},'3.3.0',{requires:['editor-base'],skinnable:false});YUI.add('editor-bidi',function(Y){var EditorBidi=function(){EditorBidi.superclass.constructor.apply(this,arguments);},HOST='host',DIR='dir',BODY='BODY',NODE_CHANGE='nodeChange',B_C_CHANGE='bidiContextChange',FIRST_P=BODY+' > p';Y.extend(EditorBidi,Y.Base,{lastDirection:null,firstEvent:null,_checkForChange:function(){var host=this.get(HOST),inst=host.getInstance(),sel=new inst.Selection(),node,direction;if(sel.isCollapsed){node=EditorBidi.blockParent(sel.focusNode);direction=node.getStyle('direction');if(direction!==this.lastDirection){host.fire(B_C_CHANGE,{changedTo:direction});this.lastDirection=direction;}}else{host.fire(B_C_CHANGE,{changedTo:'select'});this.lastDirection=null;}},_afterNodeChange:function(e){if(this.firstEvent||EditorBidi.EVENTS[e.changedType]){this._checkForChange();this.firstEvent=false;}},_afterMouseUp:function(e){this._checkForChange();this.firstEvent=false;},initializer:function(){var host=this.get(HOST);this.firstEvent=true;host.after(NODE_CHANGE,Y.bind(this._afterNodeChange,this));host.after('dom:mouseup',Y.bind(this._afterMouseUp,this));}},{EVENTS:{'backspace-up':true,'pageup-up':true,'pagedown-down':true,'end-up':true,'home-up':true,'left-up':true,'up-up':true,'right-up':true,'down-up':true,'delete-up':true},BLOCKS:Y.Selection.BLOCKS+',LI,HR,'+BODY,DIV_WRAPPER:'<DIV></DIV>',blockParent:function(node,wrap){var parent=node,divNode,firstChild;if(!parent){parent=Y.one(BODY);}
if(!parent.test(EditorBidi.BLOCKS)){parent=parent.ancestor(EditorBidi.BLOCKS);}
if(wrap&&parent.test(BODY)){divNode=Y.Node.create(EditorBidi.DIV_WRAPPER);parent.get('children').each(function(node,index){if(index===0){firstChild=node;}else{divNode.append(node);}});firstChild.replace(divNode);divNode.prepend(firstChild);parent=divNode;}
return parent;},_NODE_SELECTED:'bidiSelected',addParents:function(nodeArray){var i,parent,addParent;for(i=0;i<nodeArray.length;i+=1){nodeArray[i].setData(EditorBidi._NODE_SELECTED,true);}
for(i=0;i<nodeArray.length;i+=1){parent=nodeArray[i].get('parentNode');if(!parent.test(BODY)&&!parent.getData(EditorBidi._NODE_SELECTED)){addParent=true;parent.get('children').some(function(sibling){if(!sibling.getData(EditorBidi._NODE_SELECTED)){addParent=false;return true;}});if(addParent){nodeArray.push(parent);parent.setData(EditorBidi._NODE_SELECTED,true);}}}
for(i=0;i<nodeArray.length;i+=1){nodeArray[i].clearData(EditorBidi._NODE_SELECTED);}
return nodeArray;},NAME:'editorBidi',NS:'editorBidi',ATTRS:{host:{value:false}}});Y.namespace('Plugin');Y.Plugin.EditorBidi=EditorBidi;Y.Plugin.ExecCommand.COMMANDS.bidi=function(cmd,direction){var inst=this.getInstance(),sel=new inst.Selection(),returnValue,block,selected,selectedBlocks,dir;inst.Selection.filterBlocks();if(sel.isCollapsed){block=EditorBidi.blockParent(sel.anchorNode);if(!direction){dir=block.getAttribute(DIR);if(!dir||dir=='ltr'){direction='rtl';}else{direction='ltr';}}
block.setAttribute(DIR,direction);returnValue=block;}else{selected=sel.getSelected();selectedBlocks=[];selected.each(function(node){selectedBlocks.push(EditorBidi.blockParent(node));});selectedBlocks=inst.all(EditorBidi.addParents(selectedBlocks));selectedBlocks.setAttribute(DIR,direction);returnValue=selectedBlocks;}
this.get(HOST).get(HOST).editorBidi._checkForChange();return returnValue;};},'3.3.0',{requires:['editor-base'],skinnable:false});YUI.add('editor-para',function(Y){var EditorPara=function(){EditorPara.superclass.constructor.apply(this,arguments);},HOST='host',BODY='body',NODE_CHANGE='nodeChange',PARENT_NODE='parentNode',FIRST_P=BODY+' > p',P='p',BR='<br>',FC='firstChild',LI='li';Y.extend(EditorPara,Y.Base,{_fixFirstPara:function(){var host=this.get(HOST),inst=host.getInstance(),sel;inst.one('body').set('innerHTML','<'+P+'>'+inst.Selection.CURSOR+'</'+P+'>');var n=inst.one(FIRST_P);sel=new inst.Selection();sel.selectNode(n,true,false);},_onNodeChange:function(e){var host=this.get(HOST),inst=host.getInstance(),html,txt,par,d,sel,btag=inst.Selection.DEFAULT_BLOCK_TAG,inHTML,txt2,childs,aNode,index,node2,top,n,sib,ps,br,item,p,imgs,t,LAST_CHILD=':last-child';switch(e.changedType){case'enter-up':var para=((this._lastPara)?this._lastPara:e.changedNode),b=para.one('br.yui-cursor');if(this._lastPara){delete this._lastPara;}
if(b){if(b.previous()||b.next()){b.remove();}}
if(!para.test(btag)){var para2=para.ancestor(btag);if(para2){para=para2;para2=null;}}
if(para.test(btag)){var prev=para.previous(),lc,lc2,found=false;if(prev){lc=prev.one(LAST_CHILD);while(!found){if(lc){lc2=lc.one(LAST_CHILD);if(lc2){lc=lc2;}else{found=true;}}else{found=true;}}
if(lc){host.copyStyles(lc,para);}}}
break;case'enter':if(Y.UA.webkit){if(e.changedEvent.shiftKey){host.execCommand('insertbr');e.changedEvent.preventDefault();}}
if(Y.UA.gecko&&host.get('defaultblock')!=='p'){par=e.changedNode;if(!par.test(LI)&&!par.ancestor(LI)){if(!par.test(btag)){par=par.ancestor(btag);}
d=inst.Node.create('<'+btag+'></'+btag+'>');par.insert(d,'after');sel=new inst.Selection();if(sel.anchorOffset){inHTML=sel.anchorNode.get('textContent');txt=inst.one(inst.config.doc.createTextNode(inHTML.substr(0,sel.anchorOffset)));txt2=inst.one(inst.config.doc.createTextNode(inHTML.substr(sel.anchorOffset)));aNode=sel.anchorNode;aNode.setContent('');node2=aNode.cloneNode();node2.append(txt2);top=false;sib=aNode;while(!top){sib=sib.get(PARENT_NODE);if(sib&&!sib.test(btag)){n=sib.cloneNode();n.set('innerHTML','');n.append(node2);childs=sib.get('childNodes');var start=false;childs.each(function(c){if(start){n.append(c);}
if(c===aNode){start=true;}});aNode=sib;node2=n;}else{top=true;}}
txt2=node2;sel.anchorNode.append(txt);if(txt2){d.append(txt2);}}
if(d.get(FC)){d=d.get(FC);}
d.prepend(inst.Selection.CURSOR);sel.focusCursor(true,true);html=inst.Selection.getText(d);if(html!==''){inst.Selection.cleanCursor();}
e.changedEvent.preventDefault();}}
break;case'keydown':if(inst.config.doc.childNodes.length<2){var cont=inst.config.doc.body.innerHTML;if(cont&&cont.length<5&&cont.toLowerCase()==BR){this._fixFirstPara();}}
break;case'backspace-up':case'backspace-down':case'delete-up':if(!Y.UA.ie){ps=inst.all(FIRST_P);item=inst.one(BODY);if(ps.item(0)){item=ps.item(0);}
br=item.one('br');if(br){br.removeAttribute('id');br.removeAttribute('class');}
txt=inst.Selection.getText(item);txt=txt.replace(/ /g,'').replace(/\n/g,'');imgs=item.all('img');if(txt.length===0&&!imgs.size()){if(!item.test(P)){this._fixFirstPara();}
p=null;if(e.changedNode&&e.changedNode.test(P)){p=e.changedNode;}
if(!p&&host._lastPara&&host._lastPara.inDoc()){p=host._lastPara;}
if(p&&!p.test(P)){p=p.ancestor(P);}
if(p){if(!p.previous()&&p.get(PARENT_NODE)&&p.get(PARENT_NODE).test(BODY)){e.changedEvent.frameEvent.halt();}}}
if(Y.UA.webkit){if(e.changedNode){item=e.changedNode;if(item.test('li')&&(!item.previous()&&!item.next())){html=item.get('innerHTML').replace(BR,'');if(html===''){if(item.get(PARENT_NODE)){item.get(PARENT_NODE).replace(inst.Node.create(BR));e.changedEvent.frameEvent.halt();e.preventDefault();inst.Selection.filterBlocks();}}}}}}
if(Y.UA.gecko){d=e.changedNode;t=inst.config.doc.createTextNode(' ');d.appendChild(t);d.removeChild(t);}
break;}
if(Y.UA.gecko){if(e.changedNode&&!e.changedNode.test(btag)){var p=e.changedNode.ancestor(btag);if(p){this._lastPara=p;}}}},_afterEditorReady:function(){var host=this.get(HOST),inst=host.getInstance(),btag;if(inst){inst.Selection.filterBlocks();btag=inst.Selection.DEFAULT_BLOCK_TAG;FIRST_P=BODY+' > '+btag;P=btag;}},_afterContentChange:function(){var host=this.get(HOST),inst=host.getInstance();if(inst&&inst.Selection){inst.Selection.filterBlocks();}},_afterPaste:function(){var host=this.get(HOST),inst=host.getInstance(),sel=new inst.Selection();Y.later(50,host,function(){inst.Selection.filterBlocks();});},initializer:function(){var host=this.get(HOST);if(host.editorBR){Y.error('Can not plug EditorPara and EditorBR at the same time.');return;}
host.on(NODE_CHANGE,Y.bind(this._onNodeChange,this));host.after('ready',Y.bind(this._afterEditorReady,this));host.after('contentChange',Y.bind(this._afterContentChange,this));if(Y.Env.webkit){host.after('dom:paste',Y.bind(this._afterPaste,this));}}},{NAME:'editorPara',NS:'editorPara',ATTRS:{host:{value:false}}});Y.namespace('Plugin');Y.Plugin.EditorPara=EditorPara;},'3.3.0',{requires:['node'],skinnable:false});YUI.add('editor-br',function(Y){var EditorBR=function(){EditorBR.superclass.constructor.apply(this,arguments);},HOST='host',LI='li';Y.extend(EditorBR,Y.Base,{_onKeyDown:function(e){if(e.stopped){e.halt();return;}
if(e.keyCode==13){var host=this.get(HOST),inst=host.getInstance(),sel=new inst.Selection(),last='';if(sel){if(Y.UA.ie){if(!sel.anchorNode||(!sel.anchorNode.test(LI)&&!sel.anchorNode.ancestor(LI))){sel._selection.pasteHTML('<br>');sel._selection.collapse(false);sel._selection.select();e.halt();}}
if(Y.UA.webkit){if(!sel.anchorNode.test(LI)&&!sel.anchorNode.ancestor(LI)){host.frame._execCommand('insertlinebreak',null);e.halt();}}}}},_afterEditorReady:function(){var inst=this.get(HOST).getInstance();try{inst.config.doc.execCommand('insertbronreturn',null,true);}catch(bre){};if(Y.UA.ie||Y.UA.webkit){inst.on('keydown',Y.bind(this._onKeyDown,this),inst.config.doc);}},_onNodeChange:function(e){switch(e.changedType){case'backspace-up':case'backspace-down':case'delete-up':var inst=this.get(HOST).getInstance();var d=e.changedNode;var t=inst.config.doc.createTextNode(' ');d.appendChild(t);d.removeChild(t);break;}},initializer:function(){var host=this.get(HOST);if(host.editorPara){Y.error('Can not plug EditorBR and EditorPara at the same time.');return;}
host.after('ready',Y.bind(this._afterEditorReady,this));if(Y.UA.gecko){host.on('nodeChange',Y.bind(this._onNodeChange,this));}}},{NAME:'editorBR',NS:'editorBR',ATTRS:{host:{value:false}}});Y.namespace('Plugin');Y.Plugin.EditorBR=EditorBR;},'3.3.0',{requires:['node'],skinnable:false});YUI.add('editor',function(Y){},'3.3.0',{skinnable:false,use:['frame','selection','exec-command','editor-base','editor-para','editor-br','editor-bidi','createlink-base']});
