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

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

Added Dojo 1.9.3 release.

  • Property svn:executable set to *
File size: 3.0 KB
Line 
1define([
2        "dojo",
3        "dijit",
4        "dojox",
5        "dijit/_editor/_Plugin",
6        "dijit/form/Button",
7        "dojo/_base/connect",
8        "dojo/_base/declare",
9        "dojo/i18n",
10        "dojo/i18n!dojox/editor/plugins/nls/Preview"
11], function(dojo, dijit, dojox, _Plugin) {
12
13var Preview = dojo.declare("dojox.editor.plugins.Preview", _Plugin, {
14        // summary:
15        //              This plugin provides Preview capability to the editor.  When
16        //              clicked, the document in the editor frame will displayed in a separate
17        //              window/tab
18
19        // Over-ride indicating that the command processing is done all by this plugin.
20        useDefaultCommand: false,
21
22        // styles: [public] String
23        //              A string of CSS styles to apply to the previewed content, if any.
24        styles: "",
25
26        // stylesheets: [public] Array
27        //              An array of stylesheets to import into the preview, if any.
28        stylesheets: null,
29
30        // iconClassPrefix: [const] String
31        //              The CSS class name for the button node icon.
32        iconClassPrefix: "dijitAdditionalEditorIcon",
33
34        _initButton: function(){
35                // summary:
36                //              Over-ride for creation of the preview button.
37                this._nlsResources = dojo.i18n.getLocalization("dojox.editor.plugins", "Preview");
38                this.button = new dijit.form.Button({
39                        label: this._nlsResources["preview"],
40                        showLabel: false,
41                        iconClass: this.iconClassPrefix + " " + this.iconClassPrefix + "Preview",
42                        tabIndex: "-1",
43                        onClick: dojo.hitch(this, "_preview")
44                });
45        },
46
47        setEditor: function(editor){
48                // summary:
49                //              Over-ride for the setting of the editor.
50                // editor: Object
51                //              The editor to configure for this plugin to use.
52                this.editor = editor;
53                this._initButton();
54        },
55
56        updateState: function(){
57                // summary:
58                //              Over-ride for button state control for disabled to work.
59                this.button.set("disabled", this.get("disabled"));
60        },
61       
62        _preview: function(){
63                // summary:
64                //              Function to trigger previewing of the editor document
65                // tags:
66                //              private
67                try{
68                        var content = this.editor.get("value");
69                        var head = "\t\t<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n";
70                        var i;
71                        // Apply the stylesheets, then apply the styles.
72                        if(this.stylesheets){
73                                for(i = 0; i < this.stylesheets.length; i++){
74                                        head += "\t\t<link rel='stylesheet' type='text/css' href='" + this.stylesheets[i] + "'>\n";
75                                }
76                        }
77                        if(this.styles){
78                                head += ("\t\t<style>" + this.styles + "</style>\n");
79                        }
80                        content = "<html>\n\t<head>\n" + head + "\t</head>\n\t<body>\n" + content + "\n\t</body>\n</html>";
81                        var win = window.open("javascript: ''", this._nlsResources["preview"], "status=1,menubar=0,location=0,toolbar=0");
82                        win.document.open();
83                        win.document.write(content);
84                        win.document.close();
85
86                }catch(e){
87                        console.warn(e);
88                }
89        }
90});
91
92// Register this plugin.
93dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
94        if(o.plugin){ return; }
95        var name = o.args.name.toLowerCase();
96        if(name === "preview"){
97                o.plugin = new Preview({
98                        styles: ("styles" in o.args)?o.args.styles:"",
99                        stylesheets: ("stylesheets" in o.args)? o.args.stylesheets:null
100                });
101        }
102});
103
104return Preview;
105
106});
Note: See TracBrowser for help on using the repository browser.