diff --git a/layout/js/nicedit.js b/layout/js/nicedit.js index e3ef019..1421607 100644 --- a/layout/js/nicedit.js +++ b/layout/js/nicedit.js @@ -29,8 +29,8 @@ var nicEditorConfig = bkClass.extend({ 'hr' : {name : __('Horizontal Rule'), command : 'insertHorizontalRule', noActive : true} }, iconsPath : 'http://js.nicedit.com/nicEditIcons-latest.gif', - buttonList : ['save','bold','italic','underline','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','indent','outdent','image','upload','link','unlink','forecolor','bgcolor'], - iconList : {"xhtml":1,"bgcolor":2,"forecolor":3,"bold":4,"center":5,"hr":6,"indent":7,"italic":8,"justify":9,"left":10,"ol":11,"outdent":12,"removeformat":13,"right":14,"save":25,"strikethrough":16,"subscript":17,"superscript":18,"ul":19,"underline":20,"image":21,"link":22,"unlink":23,"close":24,"arrow":26,"upload":27} + buttonList : ['save','bold','italic','underline','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','indent','outdent','image','upload','link','unlink','forecolor','bgcolor','youtube'], + iconList : {"xhtml":1,"bgcolor":2,"forecolor":3,"bold":4,"center":5,"hr":6,"indent":7,"italic":8,"justify":9,"left":10,"ol":11,"outdent":12,"removeformat":13,"right":14,"save":25,"strikethrough":16,"subscript":17,"superscript":18,"ul":19,"underline":20,"image":21,"link":22,"unlink":23,"close":24,"arrow":26,"upload":27, "youtube": 27} }); ; @@ -102,12 +102,10 @@ var nicEditorSaveButton=nicEditorButton.extend({init:function(){if(!this.ne.opti var nicXHTML=bkClass.extend({stripAttributes:["_moz_dirty","_moz_resizing","_extended"],noShort:["style","title","script","textarea","a"],cssReplace:{"font-weight:bold;":"strong","font-style:italic;":"em"},sizes:{1:"xx-small",2:"x-small",3:"small",4:"medium",5:"large",6:"x-large"},construct:function(A){this.ne=A;if(this.ne.options.xhtml){A.addEvent("get",this.cleanup.closure(this))}},cleanup:function(A){var B=A.getElm();var C=this.toXHTML(B);A.content=C},toXHTML:function(C,A,L){var G="";var O="";var P="";var I=C.nodeType;var Q=C.nodeName.toLowerCase();var N=C.hasChildNodes&&C.hasChildNodes();var B=new Array();switch(I){case 1:var H=C.attributes;switch(Q){case"b":Q="strong";break;case"i":Q="em";break;case"font":Q="span";break}if(A){for(var F=0;F"}if(O==""&&Q=="span"){A=false}if(A){G+="<"+Q;if(Q!="br"){G+=O}}}if(!N&&!bkLib.inArray(this.noShort,M)){if(A){G+=" />"}}else{if(A){G+=">"}for(var F=0;F"}for(var F=0;F"}break;case 3:G+=C.nodeValue;break}return G}});nicEditors.registerPlugin(nicXHTML); - var nicCodeOptions = { buttons : { 'xhtml' : {name : 'Edit HTML', type : 'nicCodeButton'} } - }; var nicCodeButton=nicEditorAdvancedButton.extend({width:"350px",addPane:function(){this.addForm({"":{type:"title",txt:"Edit HTML"},code:{type:"content",value:this.ne.selectedInstance.getContent(),style:{width:"340px",height:"200px"}}})},submit:function(B){var A=this.inputs.code.value;this.ne.selectedInstance.setContent(A);this.removePane()}});nicEditors.registerPlugin(nicPlugin,nicCodeOptions); @@ -117,9 +115,48 @@ var nicBBCode=bkClass.extend({construct:function(A){this.ne=A;if(this.ne.options var nicUploadOptions = { buttons : { - 'upload' : {name : 'Upload Image', type : 'nicUploadButton'} + 'upload' : {name : 'Upload Image', type : 'nicUploadButton'}, + } }; var nicUploadButton=nicEditorAdvancedButton.extend({nicURI:"http://api.imgur.com/2/upload.json",errorText:"Failed to upload image",addPane:function(){if(typeof window.FormData==="undefined"){return this.onError("Image uploads are not supported in this browser, use Chrome, Firefox, or Safari instead.")}this.im=this.ne.selectedInstance.selElm().parentTag("IMG");var A=new bkElement("div").setStyle({padding:"10px"}).appendTo(this.pane.pane);new bkElement("div").setStyle({fontSize:"14px",fontWeight:"bold",paddingBottom:"5px"}).setContent("Insert an Image").appendTo(A);this.fileInput=new bkElement("input").setAttributes({type:"file"}).appendTo(A);this.progress=new bkElement("progress").setStyle({width:"100%",display:"none"}).setAttributes("max",100).appendTo(A);this.fileInput.onchange=this.uploadFile.closure(this)},onError:function(A){this.removePane();alert(A||"Failed to upload image")},uploadFile:function(){var B=this.fileInput.files[0];if(!B||!B.type.match(/image.*/)){this.onError("Only image files can be uploaded");return }this.fileInput.setStyle({display:"none"});this.setProgress(0);var A=new FormData();A.append("image",B);A.append("key","b7ea18a4ecbda8e92203fa4968d10660");var C=new XMLHttpRequest();C.open("POST",this.ne.options.uploadURI||this.nicURI);C.onload=function(){try{var D=JSON.parse(C.responseText)}catch(E){return this.onError()}this.onUploaded(D.upload)}.closure(this);C.onerror=this.onError.closure(this);C.upload.onprogress=function(D){this.setProgress(D.loaded/D.total)}.closure(this);C.send(A)},setProgress:function(A){this.progress.setStyle({display:"block"});if(A<0.98){this.progress.value=A}else{this.progress.removeAttribute("value")}},onUploaded:function(B){this.removePane();var D=B.links.original;if(!this.im){this.ne.selectedInstance.restoreRng();var C="javascript:nicImTemp();";this.ne.nicCommand("insertImage",D);this.im=this.findElm("IMG","src",D)}var A=parseInt(this.ne.selectedInstance.elm.getStyle("width"));if(this.im){this.im.setAttributes({src:D,width:(A&&B.image.width)?Math.min(A,B.image.width):""})}}});nicEditors.registerPlugin(nicPlugin,nicUploadOptions); + +var nicYouTubeOptions = { + buttons : { + 'youtube': {name : 'YouTube Link', type : 'nicYouTubeButton'} + } + +}; + +var nicYouTubeButton = nicEditorAdvancedButton.extend({ + + width: '350px', + + addPane: function () { + this.addForm({ + '': { type: 'title', txt: 'YouTube Url' }, + 'youTubeUrl': { type: 'text', txt: 'URL', value: 'http://', style: { width: '150px'} }, + 'height': { type: 'text', txt: 'Height', value: '560', style: { width: '150px'} }, + 'width': { type: 'text', txt: 'Width', value: '315', style: { width: '150px'} } + }); + }, + + submit: function (e) { + var code = this.inputs['youTubeUrl'].value; + var width = this.inputs['height'].value; + var height = this.inputs['width'].value; + + if (code.indexOf('watch?v=') > 0) { + code = code.replace('watch?v=','embed/'); + } + + var youTubeCode = ''; + + this.ne.selectedInstance.setContent(this.ne.selectedInstance.getContent() + youTubeCode); + this.removePane(); + } +}); + +nicEditors.registerPlugin(nicPlugin,nicYouTubeOptions); \ No newline at end of file