| 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 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
indentBy: -1, |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
lineLength: -1, |
| 28 |
|
| 29 |
|
| 30 |
useDefaultCommand: false, |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
entityMap: null, |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
_initButton: function(){ |
| 43 |
|
| 44 |
|
| 45 |
delete this.command; |
| 46 |
}, |
| 47 |
|
| 48 |
setToolbar: function(toolbar){ |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
}, |
| 53 |
|
| 54 |
setEditor: function(editor){ |
| 55 |
|
| 56 |
|
| 57 |
|
| 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 |
|
| 68 |
|
| 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=[]; |
| 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 |
|
| 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 |
}); |