source: Dev/trunk/src/client/dojox/editor/plugins/SafePaste.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 3.5 KB
Line 
1define([
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
16var SafePaste = dojo.declare("dojox.editor.plugins.SafePaste", [PasteFromWord],{
17        // summary:
18        //              This plugin extends from the PasteFromWord plugin and provides
19        //              'safe pasting', meaning that it will not allow keyboard/menu pasting
20        //              into the dijit editor.  It still runs all of the word cleanup code,
21        //              including script strippers.  If you use this plugin, you don't need to
22        //              use the 'PasteFromWord Plugin'
23
24        _initButton: function(){
25                // summary:
26                //              Over-ride the editor paste controls
27
28                // Create instance local copy.
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                // Make it translucent so we can fade in the window when the RTE is created.
44                // the RTE has to be created 'visible, and this is a ncie trick to make the creation
45                // 'pretty'.
46                dojo.style(dojo.byId(this._uId + "_rte"), "opacity", 0.001);
47
48                // Link up the action buttons to perform the insert or cleanup.
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                // Create regular expressions for sripping out user-specified tags and register
54                // them with the filters.
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                // summary:
72                //              Overrides _Plugin.updateState().
73                // tags:
74                //              protected
75               
76                // Do nothing.
77        },
78       
79        setEditor: function(editor){
80                // summary:
81                //              Over-ride for the setting of the editor.
82                // editor: Object
83                //              The editor to configure for this plugin to use.
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// Register this plugin.
101dojo.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
113return SafePaste;
114
115});
Note: See TracBrowser for help on using the repository browser.