Changeset 2566:9bf417837888 for admin/js/jsToolBar/jsToolBar.js
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/js/jsToolBar/jsToolBar.js
r1759 r2566 8 8 * the Free Software Foundation; either version 2 of the License, or 9 9 * (at your option) any later version. 10 * 10 * 11 11 * DotClear is distributed in the hope that it will be useful, 12 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 * GNU General Public License for more details. 15 * 15 * 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with DotClear; if not, write to the Free Software … … 23 23 function jsToolBar(textarea) { 24 24 if (!document.createElement) { return; } 25 25 26 26 if (!textarea) { return; } 27 27 28 28 if ((typeof(document["selection"]) == "undefined") 29 29 && (typeof(textarea["setSelectionRange"]) == "undefined")) { 30 30 return; 31 31 } 32 32 33 33 this.textarea = textarea; 34 34 35 35 this.editor = document.createElement('div'); 36 36 this.editor.className = 'jstEditor'; 37 37 38 38 this.textarea.parentNode.insertBefore(this.editor,this.textarea); 39 39 this.editor.appendChild(this.textarea); 40 40 41 41 this.toolbar = document.createElement("div"); 42 42 this.toolbar.className = 'jstElements'; 43 43 this.editor.parentNode.insertBefore(this.toolbar,this.editor); 44 44 45 45 // Dragable resizing (only for gecko) 46 46 if (navigator.appName == 'Microsoft Internet Explorer') 47 47 { 48 48 if (this.editor.addEventListener) 49 { 49 { 50 50 this.handle = document.createElement('div'); 51 51 this.handle.className = 'jstHandle'; … … 56 56 } 57 57 } 58 58 59 59 this.context = null; 60 this.toolNodes = {}; // lorsque la toolbar est dessinée , cet objet est garni 60 this.toolNodes = {}; // lorsque la toolbar est dessinée , cet objet est garni 61 61 // de raccourcis vers les éléments DOM correspondants aux outils. 62 62 }; … … 70 70 jsButton.prototype.draw = function() { 71 71 if (!this.scope) return null; 72 72 73 73 var button = document.createElement('button'); 74 74 button.setAttribute('type','button'); … … 78 78 span.appendChild(document.createTextNode(this.title)); 79 79 button.appendChild(span); 80 80 81 81 if (this.icon != undefined) { 82 82 button.style.backgroundImage = 'url('+this.icon+')'; … … 99 99 span.className = 'jstSpacer'; 100 100 if (this.width) span.style.marginRight = this.width+'px'; 101 101 102 102 return span; 103 103 }; … … 112 112 jsCombo.prototype.draw = function() { 113 113 if (!this.scope || !this.options) return null; 114 114 115 115 var select = document.createElement('select'); 116 116 if (this.className) select.className = className; 117 117 select.title = this.title; 118 118 119 119 for (var o in this.options) { 120 120 //var opt = this.options[o]; … … 124 124 select.appendChild(option); 125 125 } 126 126 127 127 var This = this; 128 128 select.onchange = function() { 129 try { 129 try { 130 130 This.fn.call(This.scope, this.value); 131 131 } catch (e) { alert(e); } 132 132 133 133 return false; 134 134 }; 135 135 136 136 return select; 137 137 }; … … 142 142 mode: 'xhtml', 143 143 elements: {}, 144 144 145 145 getMode: function() { 146 146 return this.mode; 147 147 }, 148 148 149 149 setMode: function(mode) { 150 150 this.mode = mode || 'xhtml'; 151 151 }, 152 152 153 153 switchMode: function(mode) { 154 154 mode = mode || 'xhtml'; 155 155 this.draw(mode); 156 156 }, 157 157 158 158 button: function(toolName) { 159 159 var tool = this.elements[toolName]; … … 175 175 combo: function(toolName) { 176 176 var tool = this.elements[toolName]; 177 177 178 178 if( tool[this.mode] != undefined) { 179 179 180 180 var length = tool[this.mode].list.length; 181 181 182 182 if (typeof tool[this.mode].fn != 'function' || length == 0) { 183 183 return null; … … 190 190 return new jsCombo(tool.title, options, this, tool[this.mode].fn); 191 191 } 192 193 } 194 192 193 } 194 195 195 }, 196 196 draw: function(mode) { 197 197 this.setMode(mode); 198 198 199 199 // Empty toolbar 200 200 while (this.toolbar.hasChildNodes()) { … … 202 202 } 203 203 this.toolNodes = {}; // vide les raccourcis DOM/**/ 204 204 205 205 // Draw toolbar elements 206 206 var b, tool, newTool; 207 207 208 208 for (var i in this.elements) { 209 209 b = this.elements[i]; 210 210 211 211 var disabled = 212 212 b.type == undefined || b.type == '' 213 213 || (b.disabled != undefined && b.disabled) 214 214 || (b.context != undefined && b.context != null && b.context != this.context); 215 215 216 216 if (!disabled && typeof this[b.type] == 'function') { 217 217 tool = this[b.type](i); … … 224 224 } 225 225 }, 226 226 227 227 singleTag: function(stag,etag) { 228 228 stag = stag || null; 229 229 etag = etag || stag; 230 230 231 231 if (!stag || !etag) { return; } 232 232 233 233 this.encloseSelection(stag,etag); 234 234 }, 235 235 236 236 encloseSelection: function(prefix, suffix, fn) { 237 237 this.textarea.focus(); 238 238 239 239 prefix = prefix || ''; 240 240 suffix = suffix || ''; 241 241 242 242 var start, end, sel, scrollPos, subst, res; 243 243 244 244 if (typeof(document["selection"]) != "undefined") { 245 245 sel = document.selection.createRange().text; … … 250 250 sel = this.textarea.value.substring(start, end); 251 251 } 252 252 253 253 if (sel.match(/ $/)) { // exclude ending space char, if any 254 254 sel = sel.substring(0, sel.length - 1); 255 255 suffix = suffix + " "; 256 256 } 257 257 258 258 if (typeof(fn) == 'function') { 259 259 res = (sel) ? fn.call(this,sel) : fn(''); … … 261 261 res = (sel) ? sel : ''; 262 262 } 263 263 264 264 subst = prefix + res + suffix; 265 265 266 266 if (typeof(document["selection"]) != "undefined") { 267 267 var range = document.selection.createRange().text = subst; … … 278 278 } 279 279 }, 280 280 281 281 stripBaseURL: function(url) { 282 282 if (this.base_url != '') { … … 286 286 } 287 287 } 288 288 289 289 return url; 290 290 } … … 355 355 // spacer 356 356 jsToolBar.prototype.elements.space0 = { 357 type:'space', 357 type:'space', 358 358 format:{ 359 359 wysiwyg:true, … … 425 425 // spacer 426 426 jsToolBar.prototype.elements.space1 = { 427 type:'space', 427 type:'space', 428 428 format:{ 429 429 wysiwyg:true, … … 445 445 // spacer 446 446 jsToolBar.prototype.elements.space2 = { 447 type:'space', 447 type:'space', 448 448 format:{ 449 449 wysiwyg:true, … … 523 523 // spacer 524 524 jsToolBar.prototype.elements.space3 = { 525 type:'space', 525 type:'space', 526 526 format:{ 527 527 wysiwyg:true, … … 542 542 href = href || ''; 543 543 hreflang = hreflang || this.elements.link.default_hreflang; 544 544 545 545 href = window.prompt(this.elements.link.href_prompt,href); 546 546 if (!href) { return false; } 547 547 548 548 hreflang = window.prompt(this.elements.link.hreflang_prompt, 549 549 hreflang); 550 550 551 551 return { href: this.stripBaseURL(href), hreflang: hreflang }; 552 552 } … … 560 560 stag = stag+'>'; 561 561 var etag = '</a>'; 562 562 563 563 this.encloseSelection(stag,etag); 564 564 } … … 571 571 if (link.hreflang) { etag = etag+'|'+link.hreflang; } 572 572 etag = etag+']'; 573 573 574 574 this.encloseSelection(stag,etag); 575 575 }
Note: See TracChangeset
for help on using the changeset viewer.