| 1 |
define([ |
| 2 |
"dojo", |
| 3 |
"dijit", |
| 4 |
"dojox", |
| 5 |
"dojox/editor/plugins/PasteFromWord", |
| 6 |
"dijit/Dialog", |
| 7 |
"dojo/_base/connect", |
| 8 |
"dojo/_base/declare", |
| 9 |
"dojo/i18n", |
| 10 |
"dojo/string", |
| 11 |
"dojo/i18n!dojox/editor/plugins/nls/SafePaste", |
| 12 |
"dojo/i18n!dijit/nls/common", |
| 13 |
"dojo/i18n!dijit/_editor/nls/commands" |
| 14 |
], function(dojo, dijit, dojox, PasteFromWord) { |
| 15 |
|
| 16 |
var SafePaste = dojo.declare("dojox.editor.plugins.SafePaste", [PasteFromWord],{ |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
_initButton: function(){ |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
this._filters = this._filters.slice(0); |
| 30 |
var strings = dojo.i18n.getLocalization("dojox.editor.plugins", "SafePaste"); |
| 31 |
dojo.mixin(strings, dojo.i18n.getLocalization("dijit", "common")); |
| 32 |
dojo.mixin(strings, dojo.i18n.getLocalization("dijit._editor", "commands")); |
| 33 |
|
| 34 |
this._uId = dijit.getUniqueId(this.editor.id); |
| 35 |
|
| 36 |
strings.uId = this._uId; |
| 37 |
strings.width = this.width || "400px"; |
| 38 |
strings.height = this.height || "300px"; |
| 39 |
|
| 40 |
this._dialog = new dijit.Dialog({title: strings["paste"]}).placeAt(dojo.body()); |
| 41 |
this._dialog.set("content", dojo.string.substitute(this._template, strings)); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
dojo.style(dojo.byId(this._uId + "_rte"), "opacity", 0.001); |
| 47 |
|
| 48 |
|
| 49 |
this.connect(dijit.byId(this._uId + "_paste"), "onClick", "_paste"); |
| 50 |
this.connect(dijit.byId(this._uId + "_cancel"), "onClick", "_cancel"); |
| 51 |
this.connect(this._dialog, "onHide", "_clearDialog"); |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
dojo.forEach(this.stripTags, function(tag){ |
| 56 |
var tagName = tag + ""; |
| 57 |
var rxStartTag = new RegExp("<\\s*" + tagName + "[^>]*>", "igm"); |
| 58 |
var rxEndTag = new RegExp("<\\\\?\\/\\s*" + tagName + "\\s*>", "igm"); |
| 59 |
this._filters.push({regexp: |
| 60 |
rxStartTag, |
| 61 |
handler: "" |
| 62 |
}); |
| 63 |
this._filters.push({regexp: |
| 64 |
rxEndTag, |
| 65 |
handler: "" |
| 66 |
}); |
| 67 |
}, this); |
| 68 |
}, |
| 69 |
|
| 70 |
updateState: function(){ |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
}, |
| 78 |
|
| 79 |
setEditor: function(editor){ |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
this.editor = editor; |
| 85 |
this._initButton(); |
| 86 |
this.editor.onLoadDeferred.addCallback(dojo.hitch(this, function(){ |
| 87 |
var spFunc = dojo.hitch(this, function(e){ |
| 88 |
if(e){ |
| 89 |
dojo.stopEvent(e); |
| 90 |
} |
| 91 |
this._openDialog(); |
| 92 |
return true; |
| 93 |
}); |
| 94 |
this.connect(this.editor.editNode, "onpaste", spFunc); |
| 95 |
this.editor._pasteImpl = spFunc; |
| 96 |
})); |
| 97 |
} |
| 98 |
}); |
| 99 |
|
| 100 |
|
| 101 |
dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){ |
| 102 |
if(o.plugin){ return; } |
| 103 |
var name = o.args.name.toLowerCase(); |
| 104 |
if(name === "safepaste"){ |
| 105 |
o.plugin = new SafePaste({ |
| 106 |
width: (o.args.hasOwnProperty("width"))?o.args.width:"400px", |
| 107 |
height: (o.args.hasOwnProperty("height"))?o.args.width:"300px", |
| 108 |
stripTags: (o.args.hasOwnProperty("stripTags"))?o.args.stripTags:null |
| 109 |
}); |
| 110 |
} |
| 111 |
}); |
| 112 |
|
| 113 |
return SafePaste; |
| 114 |
|
| 115 |
}); |