Debian Codegraph @

dijit/tests/editor/test_CustomPlugin.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5 <title>Editor Custom Plugin Test/Tutorial</title>
6
7 <script type="text/javascript" src="../boilerplate.js"></script>
8
9 <style>
10 .customIconHtmlToggle {
11 background-image: url('customIcon.gif'); /* custom editor icons sprite image */
12 background-repeat: no-repeat;
13 width: 18px;
14 height: 18px;
15 text-align: center;
16 }
17 </style>
18
19 <script type="text/javascript">
20 require([
21 "dojo/_base/declare",
22 "dojo/dom-construct",
23 "dojo/dom-geometry",
24 "dojo/dom-style",
25 "dojo/_base/lang",
26 "dojo/parser",
27 "dojo/sniff",
28 "dijit/registry",
29 "dijit/Editor",
30 "dijit/_editor/_Plugin",
31 "dijit/form/ToggleButton",
32 "dojo/domReady!"
33 ], function(declare, domConstruct, domGeom, domStyle, lang, parser, has, registry, Editor, _Plugin, ToggleButton){
34
35 var MyPlugin = declare("MyPlugin", _Plugin, {
36 buttonClass: ToggleButton,
37 useDefaultCommand: false,
38 name: "MyPlugin",
39
40 _initButton: function(){
41 this.command = "htmlToggle";
42 this.editor.commands[this.command] = "View HTML source"; // note: should be localized
43 this.iconClassPrefix = "customIcon";
44 this.inherited(arguments);
45 delete this.command; // kludge so setEditor doesn't make the button invisible
46 this.button.on("click", lang.hitch(this, "_toggleSource"));
47 },
48
49 destroy: function(f){
50 this.inherited(arguments);
51 if(this.sourceArea){ domConstruct.destroy(this.sourceArea); }
52 },
53
54 _toggleSource: function(){
55 this.source = !this.source;
56 if(!this.sourceArea){
57 this.sourceArea = document.createElement('textarea');
58 this.sourceArea.style.position = 'absolute';
59 this.sourceArea.setAttribute("aria-label", "sourceArea");
60 domConstruct.place(this.sourceArea, this.editor.domNode, "last");
61 }
62 if(this.source){
63 this.sourceArea.style.display = "";
64 this.sourceArea.value = this.editor.getValue();
65 domStyle.set(this.sourceArea, "borderWidth",
66 domStyle.get(this.editor.editingArea, "borderStyle") == "none" ? "0" :
67 domStyle.get(this.editor.editingArea, "borderWidth"));
68 domGeom.setMarginBox(this.sourceArea, domGeom.getMarginBox(this.editor.editingArea));
69 if(has("ie")){
70 //work around IE oddity with offsetParent mismatch
71 var p = domGeom.position(this.editor.editingArea);
72 domStyle.set(this.sourceArea, { left: p.x, top: p.y });
73 }
74 }else{
75 this.editor.setValue(this.sourceArea.value);
76 this.sourceArea.style.top = "-999px";
77 this.sourceArea.style.display = "none";
78 }
79
80 this.button.set('label', this.source ? "View WYSIWYG" : this.editor.commands["htmlToggle"]); // note: should be localized
81 }
82 });
83
84 /* the following code registers my plugin */
85 _Plugin.registry["MyPlugin"] = function(args){
86 return new MyPlugin({});
87 };
88
89 parser.parse();
90 });
91 </script>
92 </head>
93 <body class="claro" role="main">
94 <div id="editor1" data-dojo-type="dijit/Editor" data-dojo-props='"aria-label":"editorExtraPlugin",extraPlugins:["MyPlugin"], height: 150'><p>
95 This editor should have my custom plugin
96 </p></div>
97 </body>
98 </html>