| 1 |
define([ |
| 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 |
|
| 13 |
var Preview = dojo.declare("dojox.editor.plugins.Preview", _Plugin, { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
useDefaultCommand: false, |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
styles: "", |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
stylesheets: null, |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
iconClassPrefix: "dijitAdditionalEditorIcon", |
| 33 |
|
| 34 |
_initButton: function(){ |
| 35 |
|
| 36 |
|
| 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 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
this.editor = editor; |
| 53 |
this._initButton(); |
| 54 |
}, |
| 55 |
|
| 56 |
updateState: function(){ |
| 57 |
|
| 58 |
|
| 59 |
this.button.set("disabled", this.get("disabled")); |
| 60 |
}, |
| 61 |
|
| 62 |
_preview: function(){ |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 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 |
|
| 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 |
|
| 93 |
dojo.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 |
|
| 104 |
return Preview; |
| 105 |
|
| 106 |
}); |