root / trunk / web / dojo / dojox / editor / plugins / PasteFromWord.js
History | View | Annotate | Download (4.08 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
| 3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
| 4 |
see: http://dojotoolkit.org/license for details
|
| 5 |
*/
|
| 6 |
|
| 7 |
|
| 8 |
if(!dojo._hasResource["dojox.editor.plugins.PasteFromWord"]){ |
| 9 |
dojo._hasResource["dojox.editor.plugins.PasteFromWord"]=true; |
| 10 |
dojo.provide("dojox.editor.plugins.PasteFromWord");
|
| 11 |
dojo.require("dijit._editor._Plugin");
|
| 12 |
dojo.require("dijit.form.Button");
|
| 13 |
dojo.require("dijit.Dialog");
|
| 14 |
dojo.require("dojo.i18n");
|
| 15 |
dojo.require("dojo.string");
|
| 16 |
dojo.require("dojox.html.format");
|
| 17 |
dojo.requireLocalization("dojox.editor.plugins","PasteFromWord",null,"ROOT,ro"); |
| 18 |
dojo.declare("dojox.editor.plugins.PasteFromWord",dijit._editor._Plugin,{iconClassPrefix:"dijitAdditionalEditorIcon",width:"400px",height:"300px",_template:["<div class='dijitPasteFromWordEmbeddedRTE'>","<div style='width: ${width}; padding-top: 5px; padding-bottom: 5px;'>${instructions}</div>","<div id='${uId}_rte' style='width: ${width}; height: ${height}'></div>","<table style='width: ${width}' tabindex='-1'>","<tbody>","<tr>","<td align='center'>","<button type='button' dojoType='dijit.form.Button' id='${uId}_paste'>${paste}</button>"," ","<button type='button' dojoType='dijit.form.Button' id='${uId}_cancel'>${cancel}</button>","</td>","</tr>","</tbody>","</table>","</div>"].join(""),_filters:[{regexp:/(<meta\s*[^>]*\s*>)|(<\s*link\s* href="file:[^>]*\s*>)|(<\/?\s*\w+:[^>]*\s*>)/gi,handler:""},{regexp:/(?:<style([^>]*)>([\s\S]*?)<\/style>|<link\s+(?=[^>]*rel=['"]?stylesheet)([^>]*?href=(['"])([^>]*?)\4[^>\/]*)\/?>)/gi,handler:""},{regexp:/(class="Mso[^"]*")|(<!--(.|\s){1,}?-->)/gi,handler:""},{regexp:/(<p[^>]*>\s*(\ |\u00A0)*\s*<\/p[^>]*>)|(<p[^>]*>\s*<font[^>]*>\s*(\ |\u00A0)*\s*<\/\s*font\s*>\s<\/p[^>]*>)/ig,handler:""},{regexp:/(style="[^"]*mso-[^;][^"]*")|(style="margin:\s*[^;"]*;")/gi,handler:""},{regexp:/(<\s*script[^>]*>((.|\s)*?)<\\?\/\s*script\s*>)|(<\s*script\b([^<>]|\s)*>?)|(<[^>]*=(\s|)*[("|')]javascript:[^$1][(\s|.)]*[$1][^>]*>)/ig,handler:""}],_initButton:function(){ |
| 19 |
var _1=dojo.i18n.getLocalization("dojox.editor.plugins","PasteFromWord"); |
| 20 |
this.button=new dijit.form.Button({label:_1["pasteFromWord"],showLabel:false,iconClass:this.iconClassPrefix+" "+this.iconClassPrefix+"PasteFromWord",tabIndex:"-1",onClick:dojo.hitch(this,"_openDialog")}); |
| 21 |
this._uId=dijit.getUniqueId(this.editor.id); |
| 22 |
_1.uId=this._uId;
|
| 23 |
_1.width=this.width||"400px"; |
| 24 |
_1.height=this.height||"300px"; |
| 25 |
this._dialog=new dijit.Dialog({title:_1["pasteFromWord"]}).placeAt(dojo.body()); |
| 26 |
this._dialog.set("content",dojo.string.substitute(this._template,_1)); |
| 27 |
dojo.style(dojo.byId(this._uId+"_rte"),"opacity",0.001); |
| 28 |
this.connect(dijit.byId(this._uId+"_paste"),"onClick","_paste"); |
| 29 |
this.connect(dijit.byId(this._uId+"_cancel"),"onClick","_cancel"); |
| 30 |
this.connect(this._dialog,"onHide","_clearDialog"); |
| 31 |
},setEditor:function(_2){ |
| 32 |
this.editor=_2;
|
| 33 |
this._initButton();
|
| 34 |
},_openDialog:function(){ |
| 35 |
this._dialog.show();
|
| 36 |
if(!this._rte){ |
| 37 |
setTimeout(dojo.hitch(this,function(){ |
| 38 |
this._rte=new dijit._editor.RichText({height:this.height||"300px"},this._uId+"_rte"); |
| 39 |
this._rte.onLoadDeferred.addCallback(dojo.hitch(this,function(){ |
| 40 |
dojo.animateProperty({node:this._rte.domNode,properties:{opacity:{start:0.001,end:1}}}).play();
|
| 41 |
})); |
| 42 |
}),100);
|
| 43 |
} |
| 44 |
},_paste:function(){ |
| 45 |
var _3=dojox.html.format.prettyPrint(this._rte.get("value")); |
| 46 |
this._dialog.hide();
|
| 47 |
var i;
|
| 48 |
for(i=0;i<this._filters.length;i++){ |
| 49 |
var _4=this._filters[i]; |
| 50 |
_3=_3.replace(_4.regexp,_4.handler); |
| 51 |
} |
| 52 |
_3=dojox.html.format.prettyPrint(_3); |
| 53 |
this.editor.execCommand("inserthtml",_3); |
| 54 |
},_cancel:function(){ |
| 55 |
this._dialog.hide();
|
| 56 |
},_clearDialog:function(){ |
| 57 |
this._rte.set("value",""); |
| 58 |
},destroy:function(){ |
| 59 |
if(this._rte){ |
| 60 |
this._rte.destroy();
|
| 61 |
} |
| 62 |
if(this._dialog){ |
| 63 |
this._dialog.destroyRecursive();
|
| 64 |
} |
| 65 |
delete this._dialog; |
| 66 |
delete this._rte; |
| 67 |
this.inherited(arguments); |
| 68 |
}}); |
| 69 |
dojo.subscribe(dijit._scopeName+".Editor.getPlugin",null,function(o){ |
| 70 |
if(o.plugin){
|
| 71 |
return;
|
| 72 |
} |
| 73 |
var _5=o.args.name.toLowerCase();
|
| 74 |
if(_5==="pastefromword"){ |
| 75 |
o.plugin=new dojox.editor.plugins.PasteFromWord({width:("width" in o.args)?o.args.width:"400px",height:("height" in o.args)?o.args.width:"300px"}); |
| 76 |
} |
| 77 |
}); |
| 78 |
} |