| 22 | | UnFormat._pluginInfo = { |
| 23 | | name : "UnFormat", |
| 24 | | version : "1.0", |
| 25 | | license : "htmlArea" |
| | 29 | UnFormat.prototype.onGenerateOnce = function(editor){ |
| | 30 | // Load assets |
| | 31 | var self = UnFormat; |
| | 32 | if (self.loading) return; |
| | 33 | self.loading = true; |
| | 34 | self.methodsReady = true; |
| | 35 | Xinha._getback(_editor_url + 'plugins/UnFormat/dialog.html', function(getback) { self.html = getback; self.dialogReady = true; }); |
| | 36 | } |
| | 37 | UnFormat.prototype.onUpdateToolbar = function(editor){ |
| | 38 | if (!(UnFormat.dialogReady && UnFormat.methodsReady)) |
| | 39 | { |
| | 40 | this.editor._toolbarObjects.UnFormat.state("enabled", false); |
| | 41 | } |
| | 42 | else this.onUpdateToolbar = null; |
| | 43 | |
| | 44 | } |
| | 45 | UnFormat.prototype.prepareDialog = function(editor){ |
| | 46 | var self = this; |
| | 47 | var editor = this.editor; |
| | 48 | |
| | 49 | var dialog = this.dialog = new Xinha.Dialog(editor, UnFormat.html, 'Xinha',{width:400}) |
| | 50 | // Connect the OK and Cancel buttons |
| | 51 | dialog.getElementById('ok').onclick = function() {self.apply();} |
| | 52 | dialog.getElementById('cancel').onclick = function() { self.dialog.hide()}; |
| | 53 | |
| | 54 | this.dialogReady = true; |
| | 55 | } |
| | 56 | UnFormat.prototype.show = function(editor){ |
| | 57 | if (!this.dialog) this.prepareDialog(); |
| | 58 | |
| | 59 | var editor = this.editor; |
| | 60 | |
| | 61 | var values = |
| | 62 | { |
| | 63 | "cleaning_area" : 'selection', |
| | 64 | "formatting" : '', |
| | 65 | "html_all" : '' |
| | 66 | } |
| | 67 | // now calling the show method of the Xinha.Dialog object to set the values and show the actual dialog |
| | 68 | this.dialog.show(values); |
| | 69 | this.dialog.onresize(); |
| | 70 | } |
| | 71 | UnFormat.prototype.apply = function(editor){ |
| | 72 | var editor = this.editor; |
| | 73 | var doc = editor._doc; |
| | 74 | var param = this.dialog.getValues(); |
| | 75 | |
| | 76 | // selection is only restored on dialog.hide() |
| | 77 | this.dialog.hide(); |
| | 78 | // assign the given arguments |
| | 79 | |
| | 80 | if (param["cleaning_area"] == "all") { |
| | 81 | var html = editor._doc.body.innerHTML; |
| | 82 | } else { |
| | 83 | var html = editor.getSelectedHTML(); |
| | 84 | } |
| | 85 | |
| | 86 | if (param.html_all) { |
| | 87 | html = html.replace(/<[\!]*?[^<>]*?>/g, ""); |
| | 88 | } |
| | 89 | |
| | 90 | if (param.formatting) { |
| | 91 | html = html.replace(/style="[^"]*"/gi, ""); |
| | 92 | html = html.replace(/<\/?font[^>]*>/gi,""); |
| | 93 | html = html.replace(/<\/?b>/gi,""); |
| | 94 | html = html.replace(/<\/?strong[^>]*>/gi,""); |
| | 95 | html = html.replace(/<\/?i>/gi,""); |
| | 96 | html = html.replace(/<\/?em[^>]*>/gi,""); |
| | 97 | html = html.replace(/<\/?u[^>]*>/gi,""); |
| | 98 | html = html.replace(/<\/?strike[^>]*>/gi,""); |
| | 99 | html = html.replace(/ align=[^\s|>]*/gi,""); |
| | 100 | html = html.replace(/ class=[^\s|>]*/gi,""); |
| | 101 | } |
| | 102 | if (param["cleaning_area"] == "all") { |
| | 103 | editor._doc.body.innerHTML = html; |
| | 104 | } else { |
| | 105 | editor.insertHTML(html); |
| | 106 | } |
| 27 | | |
| 28 | | |
| 29 | | UnFormat.prototype._lc = function(string) { |
| 30 | | return Xinha._lc(string, 'UnFormat'); |
| 31 | | }; |
| 32 | | |
| 33 | | UnFormat.prototype.buttonPress = function(editor){ |
| 34 | | editor._popupDialog( "plugin://UnFormat/unformat", function( param){ |
| 35 | | if (param) { |
| 36 | | if (param["cleaning_area"] == "all") { |
| 37 | | var html = editor._doc.body.innerHTML; |
| 38 | | } else { |
| 39 | | var html = editor.getSelectedHTML(); |
| 40 | | } |
| 41 | | |
| 42 | | if (param["html_all"]== true) { |
| 43 | | html = html.replace(/<[\!]*?[^<>]*?>/g, ""); |
| 44 | | } |
| 45 | | |
| 46 | | if (param["formatting"] == true) { |
| 47 | | html = html.replace(/style="[^"]*"/gi, ""); |
| 48 | | html = html.replace(/<\/?font[^>]*>/gi,""); |
| 49 | | html = html.replace(/<\/?b>/gi,""); |
| 50 | | html = html.replace(/<\/?strong[^>]*>/gi,""); |
| 51 | | html = html.replace(/<\/?i>/gi,""); |
| 52 | | html = html.replace(/<\/?em[^>]*>/gi,""); |
| 53 | | html = html.replace(/<\/?u[^>]*>/gi,""); |
| 54 | | html = html.replace(/<\/?strike[^>]*>/gi,""); |
| 55 | | html = html.replace(/ align=[^\s|>]*/gi,""); |
| 56 | | html = html.replace(/ class=[^\s|>]*/gi,""); |
| 57 | | } |
| 58 | | if (param["cleaning_area"] == "all") { |
| 59 | | editor._doc.body.innerHTML = html; |
| 60 | | } else { |
| 61 | | editor.insertHTML(html); |
| 62 | | } |
| 63 | | } else { return false; } |
| 64 | | }, null); |
| 65 | | }; |