Debian Codegraph @

dojox/editor/plugins/PrettyPrint.js

raw symbols SCIP
1 define([
2 "dojo",
3 "dijit",
4 "dojox",
5 "dijit/_editor/_Plugin",
6 "dojo/_base/connect",
7 "dojo/_base/declare",
8 "dojox/html/format"
9 ], function(dojo, dijit, dojox, _Plugin) {
10
11 var PrettyPrint = dojo.declare("dojox.editor.plugins.PrettyPrint", _Plugin,{
12 // summary:
13 // This plugin provides a mechanism by which to 'beautify HTML'
14 // generated by the editor. It is by no means perfect.
15
16 // indentBy: [public] Integer
17 // The indentBy property configures if the plugin should use a
18 // set number of spaces for indent (between 1-5), or just tab.
19 // The default value is -1, which means tab.
20 indentBy: -1,
21
22 // lineLength: [public] Integer
23 // The lineLength property configures if the plugin should break up long
24 // text lines into N lines of 'lineLength' length. This parameter does not
25 // take into account indention depth, only text line length. The default is -1
26 // which means unlimited line length.
27 lineLength: -1,
28
29 // Over-ride indicating that the command processing is done all by this plugin.
30 useDefaultCommand: false,
31
32 // map: [public] Array
33 // An array of arrays that define out entity character to encoding mappings.
34 // see the dojox.html.entities definitions for more details. The default is
35 // HTML + cent, pound, yen, ellipsis, copyright, registered trademark.
36 entityMap: null,
37
38 // xhtml: [public] boolean
39 // Flag to denote that the PrettyPrint plugin try to generate XHTML compliant
40 // markup.
41
42 _initButton: function(){
43 // summary:
44 // Over-ride for creation of the resize button.
45 delete this.command;
46 },
47
48 setToolbar: function(toolbar){
49 // summary:
50 // Over-ride to do nothing.
51 // We don't want to append a button, we take over getValue.
52 },
53
54 setEditor: function(editor){
55 // summary:
56 // Over-ride to take over getValue of editor so that
57 // we can 'pretty' the output.
58 this.inherited(arguments);
59 var self = this;
60 this.editor.onLoadDeferred.addCallback(function(){
61 self.editor._prettyprint_getValue = self.editor.getValue;
62 self.editor.getValue = function(){
63 var val = self.editor._prettyprint_getValue(arguments);
64 return dojox.html.format.prettyPrint(val, self.indentBy, self.lineLength, self.entityMap, self.xhtml);
65 };
66
67 // The following are implemented as 'performance' functions. Don't prettyprint
68 // content on internal state changes, just on calls to actually get values.
69 self.editor._prettyprint_endEditing = self.editor._endEditing;
70 self.editor._prettyprint_onBlur = self.editor._onBlur;
71 self.editor._endEditing = function(ignore_caret){
72 var v = self.editor._prettyprint_getValue(true);
73 self.editor._undoedSteps=[];//clear undoed steps
74 self.editor._steps.push({text: v, bookmark: self.editor._getBookmark()});
75 }
76 self.editor._onBlur = function(e){
77 this.inherited("_onBlur", arguments);
78 var _c=self.editor._prettyprint_getValue(true);
79 if(_c!=self.editor.savedContent){
80 self.editor.onChange(_c);
81 self.editor.savedContent=_c;
82 }
83 }
84 });
85 }
86 });
87
88 // Register this plugin.
89 dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
90 if(o.plugin){ return; }
91 var name = o.args.name.toLowerCase();
92 if(name === "prettyprint"){
93 o.plugin = new PrettyPrint({
94 indentBy: ("indentBy" in o.args)?o.args.indentBy:-1,
95 lineLength: ("lineLength" in o.args)?o.args.lineLength:-1,
96 entityMap: ("entityMap" in o.args)?o.args.entityMap:dojox.html.entities.html.concat([
97 ["\u00A2","cent"],["\u00A3","pound"],["\u20AC","euro"],
98 ["\u00A5","yen"],["\u00A9","copy"],["\u00A7","sect"],
99 ["\u2026","hellip"],["\u00AE","reg"]
100 ]),
101 xhtml: ("xhtml" in o.args)?o.args.xhtml:false
102 });
103 }
104 });
105
106 return PrettyPrint;
107
108 });