[795] | 1 | // FullPage Plugin for HTMLArea-3.0 |
---|
| 2 | // Implementation by Mihai Bazon. Sponsored by http://thycotic.com |
---|
| 3 | // |
---|
| 4 | // htmlArea v3.0 - Copyright (c) 2002 interactivetools.com, inc. |
---|
| 5 | // This notice MUST stay intact for use (see license.txt). |
---|
| 6 | // |
---|
| 7 | // A free WYSIWYG editor replacement for <textarea> fields. |
---|
| 8 | // For full source code and docs, visit http://www.interactivetools.com/ |
---|
| 9 | // |
---|
| 10 | // Version 3.0 developed by Mihai Bazon for InteractiveTools. |
---|
| 11 | // http://dynarch.com/mishoo |
---|
| 12 | // |
---|
| 13 | |
---|
| 14 | function FullPage(editor) { |
---|
| 15 | this.editor = editor; |
---|
| 16 | |
---|
| 17 | var cfg = editor.config; |
---|
| 18 | cfg.fullPage = true; |
---|
| 19 | var tt = FullPage.I18N; |
---|
| 20 | var self = this; |
---|
| 21 | |
---|
| 22 | cfg.registerButton("FP-docprop", tt["Document properties"], editor.imgURL("docprop.gif", "FullPage"), false, |
---|
| 23 | function(editor, id) { |
---|
| 24 | self.buttonPress(editor, id); |
---|
| 25 | }); |
---|
| 26 | |
---|
| 27 | // add a new line in the toolbar |
---|
| 28 | cfg.toolbar[0].splice(0, 0, "separator"); |
---|
| 29 | cfg.toolbar[0].splice(0, 0, "FP-docprop"); |
---|
| 30 | }; |
---|
| 31 | |
---|
| 32 | FullPage._pluginInfo = { |
---|
| 33 | name : "FullPage", |
---|
| 34 | version : "1.0", |
---|
| 35 | developer : "Mihai Bazon", |
---|
| 36 | developer_url : "http://dynarch.com/mishoo/", |
---|
| 37 | c_owner : "Mihai Bazon", |
---|
| 38 | sponsor : "Thycotic Software Ltd.", |
---|
| 39 | sponsor_url : "http://thycotic.com", |
---|
| 40 | license : "htmlArea" |
---|
| 41 | }; |
---|
| 42 | |
---|
| 43 | FullPage.prototype.buttonPress = function(editor, id) { |
---|
| 44 | var self = this; |
---|
| 45 | switch (id) { |
---|
| 46 | case "FP-docprop": |
---|
| 47 | var doc = editor._doc; |
---|
| 48 | var links = doc.getElementsByTagName("link"); |
---|
| 49 | var style1 = ''; |
---|
| 50 | var style2 = ''; |
---|
| 51 | for (var i = links.length; --i >= 0;) { |
---|
| 52 | var link = links[i]; |
---|
| 53 | if (/stylesheet/i.test(link.rel)) { |
---|
| 54 | if (/alternate/i.test(link.rel)) |
---|
| 55 | style2 = link.href; |
---|
| 56 | else |
---|
| 57 | style1 = link.href; |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | var title = doc.getElementsByTagName("title")[0]; |
---|
| 61 | title = title ? title.innerHTML : ''; |
---|
| 62 | var init = { |
---|
| 63 | f_doctype : editor.doctype, |
---|
| 64 | f_title : title, |
---|
| 65 | f_body_bgcolor : HTMLArea._colorToRgb(doc.body.style.backgroundColor), |
---|
| 66 | f_body_fgcolor : HTMLArea._colorToRgb(doc.body.style.color), |
---|
| 67 | f_base_style : style1, |
---|
| 68 | f_alt_style : style2, |
---|
| 69 | |
---|
| 70 | editor : editor |
---|
| 71 | }; |
---|
| 72 | editor._popupDialog("plugin://FullPage/docprop", function(params) { |
---|
| 73 | self.setDocProp(params); |
---|
| 74 | }, init); |
---|
| 75 | break; |
---|
| 76 | } |
---|
| 77 | }; |
---|
| 78 | |
---|
| 79 | FullPage.prototype.setDocProp = function(params) { |
---|
| 80 | var txt = ""; |
---|
| 81 | var doc = this.editor._doc; |
---|
| 82 | var head = doc.getElementsByTagName("head")[0]; |
---|
| 83 | var links = doc.getElementsByTagName("link"); |
---|
| 84 | var style1 = null; |
---|
| 85 | var style2 = null; |
---|
| 86 | for (var i = links.length; --i >= 0;) { |
---|
| 87 | var link = links[i]; |
---|
| 88 | if (/stylesheet/i.test(link.rel)) { |
---|
| 89 | if (/alternate/i.test(link.rel)) |
---|
| 90 | style2 = link; |
---|
| 91 | else |
---|
| 92 | style1 = link; |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | function createLink(alt) { |
---|
| 96 | var link = doc.createElement("link"); |
---|
| 97 | link.rel = alt ? "alternate stylesheet" : "stylesheet"; |
---|
| 98 | head.appendChild(link); |
---|
| 99 | return link; |
---|
| 100 | }; |
---|
| 101 | |
---|
| 102 | if (!style1 && params.f_base_style) |
---|
| 103 | style1 = createLink(false); |
---|
| 104 | if (params.f_base_style) |
---|
| 105 | style1.href = params.f_base_style; |
---|
| 106 | else if (style1) |
---|
| 107 | head.removeChild(style1); |
---|
| 108 | |
---|
| 109 | if (!style2 && params.f_alt_style) |
---|
| 110 | style2 = createLink(true); |
---|
| 111 | if (params.f_alt_style) |
---|
| 112 | style2.href = params.f_alt_style; |
---|
| 113 | else if (style2) |
---|
| 114 | head.removeChild(style2); |
---|
| 115 | |
---|
| 116 | for (var i in params) { |
---|
| 117 | var val = params[i]; |
---|
| 118 | switch (i) { |
---|
| 119 | case "f_title": |
---|
| 120 | var title = doc.getElementsByTagName("title")[0]; |
---|
| 121 | if (!title) { |
---|
| 122 | title = doc.createElement("title"); |
---|
| 123 | head.appendChild(title); |
---|
| 124 | } else while (node = title.lastChild) |
---|
| 125 | title.removeChild(node); |
---|
| 126 | if (!HTMLArea.is_ie) |
---|
| 127 | title.appendChild(doc.createTextNode(val)); |
---|
| 128 | else |
---|
| 129 | doc.title = val; |
---|
| 130 | break; |
---|
| 131 | case "f_doctype": |
---|
| 132 | this.editor.setDoctype(val); |
---|
| 133 | break; |
---|
| 134 | case "f_body_bgcolor": |
---|
| 135 | doc.body.style.backgroundColor = val; |
---|
| 136 | break; |
---|
| 137 | case "f_body_fgcolor": |
---|
| 138 | doc.body.style.color = val; |
---|
| 139 | break; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | }; |
---|