| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | Xinha.version = |
|---|
| 36 | { |
|---|
| 37 | 'Release' : 'Trunk', |
|---|
| 38 | 'Head' : '$HeadURL:http://svn.xinha.webfactional.com/trunk/XinhaCore.js $'.replace(/^[^:]*:\s*(.*)\s*\$$/, '$1'), |
|---|
| 39 | 'Date' : '$LastChangedDate:2008-05-01 14:33:36 +0200 (Do, 01 Mai 2008) $'.replace(/^[^:]*:\s*([0-9-]*) ([0-9:]*) ([+0-9]*) \((.*)\)\s*\$/, '$4 $2 $3'), |
|---|
| 40 | 'Revision' : '$LastChangedRevision:999 $'.replace(/^[^:]*:\s*(.*)\s*\$$/, '$1'), |
|---|
| 41 | 'RevisionBy': '$LastChangedBy:ray $'.replace(/^[^:]*:\s*(.*)\s*\$$/, '$1') |
|---|
| 42 | }; |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | Xinha._resolveRelativeUrl = function( base, url ) |
|---|
| 46 | { |
|---|
| 47 | if(url.match(/^([^:]+\:)?\/\ |
|---|
| 48 | { |
|---|
| 49 | return url; |
|---|
| 50 | } |
|---|
| 51 | else |
|---|
| 52 | { |
|---|
| 53 | var b = base.split("/"); |
|---|
| 54 | if(b[b.length - 1] == "") |
|---|
| 55 | { |
|---|
| 56 | b.pop(); |
|---|
| 57 | } |
|---|
| 58 | var p = url.split("/"); |
|---|
| 59 | if(p[0] == ".") |
|---|
| 60 | { |
|---|
| 61 | p.shift(); |
|---|
| 62 | } |
|---|
| 63 | while(p[0] == "..") |
|---|
| 64 | { |
|---|
| 65 | b.pop(); |
|---|
| 66 | p.shift(); |
|---|
| 67 | } |
|---|
| 68 | return b.join("/") + "/" + p.join("/"); |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | if ( typeof _editor_url == "string" ) |
|---|
| 73 | { |
|---|
| 74 | |
|---|
| 75 | _editor_url = _editor_url.replace(/\x2f*$/, '/'); |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | if(!_editor_url.match(/^([^:]+\:)?\ |
|---|
| 79 | var path = window.location.toString().split("/"); |
|---|
| 80 | path.pop(); |
|---|
| 81 | _editor_url = Xinha._resolveRelativeUrl(path.join("/"), _editor_url); |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | else |
|---|
| 85 | { |
|---|
| 86 | alert("WARNING: _editor_url is not set! You should set this variable to the editor files path; it should preferably be an absolute path, like in '/htmlarea/', but it can be relative if you prefer. Further we will try to load the editor files correctly but we'll probably fail."); |
|---|
| 87 | _editor_url = ''; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | if ( typeof _editor_lang == "string" ) |
|---|
| 92 | { |
|---|
| 93 | _editor_lang = _editor_lang.toLowerCase(); |
|---|
| 94 | } |
|---|
| 95 | else |
|---|
| 96 | { |
|---|
| 97 | _editor_lang = "en"; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | if ( typeof _editor_skin !== "string" ) |
|---|
| 102 | { |
|---|
| 103 | _editor_skin = ""; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | var __xinhas = []; |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | Xinha.agt = navigator.userAgent.toLowerCase(); |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | Xinha.is_ie = ((Xinha.agt.indexOf("msie") != -1) && (Xinha.agt.indexOf("opera") == -1)); |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | Xinha.ie_version= parseFloat(Xinha.agt.substring(Xinha.agt.indexOf("msie")+5)); |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | Xinha.is_opera = (Xinha.agt.indexOf("opera") != -1); |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | if(Xinha.is_opera && Xinha.agt.match(/opera[\/ ]([0-9.]+)/)) |
|---|
| 137 | { |
|---|
| 138 | Xinha.opera_version = parseFloat(RegExp.$1); |
|---|
| 139 | } |
|---|
| 140 | else |
|---|
| 141 | { |
|---|
| 142 | Xinha.opera_version = 0; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | Xinha.is_khtml = (Xinha.agt.indexOf("khtml") != -1); |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | Xinha.is_webkit = (Xinha.agt.indexOf("applewebkit") != -1); |
|---|
| 152 | Xinha.webkit_version = parseInt(navigator.appVersion.replace(/.*?AppleWebKit\/([\d]).*?/,'$1')); |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | Xinha.is_safari = (Xinha.agt.indexOf("safari") != -1); |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | Xinha.is_mac = (Xinha.agt.indexOf("mac") != -1); |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | Xinha.is_mac_ie = (Xinha.is_ie && Xinha.is_mac); |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | Xinha.is_win_ie = (Xinha.is_ie && !Xinha.is_mac); |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | Xinha.is_gecko = (navigator.product == "Gecko") || Xinha.is_opera; |
|---|
| 175 | Xinha.is_real_gecko = (navigator.product == "Gecko" && !Xinha.is_webkit); |
|---|
| 176 | Xinha.is_ff3 = Xinha.is_real_gecko && parseInt(navigator.productSub) >= 2007121016; |
|---|
| 177 | Xinha.is_ff2 = Xinha.is_real_gecko && parseInt(navigator.productSub) < 2007121016; |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | Xinha.isRunLocally = document.URL.toLowerCase().search(/^file:/) != -1; |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | Xinha.is_designMode = (typeof document.designMode != 'undefined' && !Xinha.is_ie); |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | Xinha.checkSupportedBrowser = function() |
|---|
| 195 | { |
|---|
| 196 | return Xinha.is_real_gecko || (Xinha.is_opera && Xinha.opera_version >= 9.2) || Xinha.ie_version >= 5.5 || Xinha.webkit_version >= 522; |
|---|
| 197 | }; |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | Xinha.isSupportedBrowser = Xinha.checkSupportedBrowser(); |
|---|
| 203 | |
|---|
| 204 | if ( Xinha.isRunLocally && Xinha.isSupportedBrowser) |
|---|
| 205 | { |
|---|
| 206 | alert('Xinha *must* be installed on a web server. Locally opened files (those that use the "file://" protocol) cannot properly function. Xinha will try to initialize but may not be correctly loaded.'); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | function Xinha(textarea, config) |
|---|
| 216 | { |
|---|
| 217 | if ( !Xinha.isSupportedBrowser ) return; |
|---|
| 218 | |
|---|
| 219 | if ( !textarea ) |
|---|
| 220 | { |
|---|
| 221 | throw new Error ("Tried to create Xinha without textarea specified."); |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | if ( typeof config == "undefined" ) |
|---|
| 225 | { |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | this.config = new Xinha.Config(); |
|---|
| 230 | } |
|---|
| 231 | else |
|---|
| 232 | { |
|---|
| 233 | this.config = config; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | if ( typeof textarea != 'object' ) |
|---|
| 237 | { |
|---|
| 238 | textarea = Xinha.getElementById('textarea', textarea); |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | this._textArea = textarea; |
|---|
| 244 | this._textArea.spellcheck = false; |
|---|
| 245 | Xinha.freeLater(this, '_textArea'); |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | this._initial_ta_size = |
|---|
| 253 | { |
|---|
| 254 | w: textarea.style.width ? textarea.style.width : ( textarea.offsetWidth ? ( textarea.offsetWidth + 'px' ) : ( textarea.cols + 'em') ), |
|---|
| 255 | h: textarea.style.height ? textarea.style.height : ( textarea.offsetHeight ? ( textarea.offsetHeight + 'px' ) : ( textarea.rows + 'em') ) |
|---|
| 256 | }; |
|---|
| 257 | |
|---|
| 258 | if ( document.getElementById("loading_" + textarea.id) || this.config.showLoading ) |
|---|
| 259 | { |
|---|
| 260 | if (!document.getElementById("loading_" + textarea.id)) |
|---|
| 261 | { |
|---|
| 262 | Xinha.createLoadingMessage(textarea); |
|---|
| 263 | } |
|---|
| 264 | this.setLoadingMessage(Xinha._lc("Constructing object")); |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | this._editMode = "wysiwyg"; |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | this.plugins = {}; |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | this._timerToolbar = null; |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | this._timerUndo = null; |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | this._undoQueue = [this.config.undoSteps]; |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | this._undoPos = -1; |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | this._customUndo = true; |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | this._mdoc = document; |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | this.doctype = ''; |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | this.__htmlarea_id_num = __xinhas.length; |
|---|
| 317 | __xinhas[this.__htmlarea_id_num] = this; |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | this._notifyListeners = {}; |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | var panels = |
|---|
| 327 | { |
|---|
| 328 | right: |
|---|
| 329 | { |
|---|
| 330 | on: true, |
|---|
| 331 | container: document.createElement('td'), |
|---|
| 332 | panels: [] |
|---|
| 333 | }, |
|---|
| 334 | left: |
|---|
| 335 | { |
|---|
| 336 | on: true, |
|---|
| 337 | container: document.createElement('td'), |
|---|
| 338 | panels: [] |
|---|
| 339 | }, |
|---|
| 340 | top: |
|---|
| 341 | { |
|---|
| 342 | on: true, |
|---|
| 343 | container: document.createElement('td'), |
|---|
| 344 | panels: [] |
|---|
| 345 | }, |
|---|
| 346 | bottom: |
|---|
| 347 | { |
|---|
| 348 | on: true, |
|---|
| 349 | container: document.createElement('td'), |
|---|
| 350 | panels: [] |
|---|
| 351 | } |
|---|
| 352 | }; |
|---|
| 353 | |
|---|
| 354 | for ( var i in panels ) |
|---|
| 355 | { |
|---|
| 356 | if(!panels[i].container) { continue; } |
|---|
| 357 | panels[i].div = panels[i].container; |
|---|
| 358 | panels[i].container.className = 'panels ' + i; |
|---|
| 359 | Xinha.freeLater(panels[i], 'container'); |
|---|
| 360 | Xinha.freeLater(panels[i], 'div'); |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | this._panels = panels; |
|---|
| 368 | |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | |
|---|
| 373 | this._statusBar = null; |
|---|
| 374 | |
|---|
| 375 | |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | this._statusBarTree = null; |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | this._statusBarTextMode = null; |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | |
|---|
| 388 | this._statusBarItems = []; |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | this._framework = {}; |
|---|
| 394 | |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | this._htmlArea = null; |
|---|
| 399 | |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | this._iframe = null; |
|---|
| 406 | |
|---|
| 407 | |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | this._doc = null; |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | this._toolBar = this._toolbar = null; |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | |
|---|
| 419 | |
|---|
| 420 | this._toolbarObjects = {}; |
|---|
| 421 | |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | Xinha.onload = function() { }; |
|---|
| 425 | Xinha.init = function() { Xinha.onload(); }; |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | |
|---|
| 431 | Xinha.RE_tagName = /(<\/|<)\s*([^ \t\n>]+)/ig; |
|---|
| 432 | |
|---|
| 433 | |
|---|
| 434 | |
|---|
| 435 | Xinha.RE_doctype = /(<!doctype((.|\n)*?)>)\n?/i; |
|---|
| 436 | |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | Xinha.RE_head = /<head>((.|\n)*?)<\/head>/i; |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | Xinha.RE_body = /<body[^>]*>((.|\n|\r|\t)*?)<\/body>/i; |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | |
|---|
| 447 | |
|---|
| 448 | Xinha.RE_Specials = /([\/\^$*+?.()|{}[\]])/g; |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | Xinha.escapeStringForRegExp = function (string) |
|---|
| 455 | { |
|---|
| 456 | return string.replace(Xinha.RE_Specials, '\\$1'); |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | |
|---|
| 460 | |
|---|
| 461 | Xinha.RE_email = /^[_a-z\d\-\.]{3,}@[_a-z\d\-]{2,}(\.[_a-z\d\-]{2,})+$/i; |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | |
|---|
| 465 | Xinha.RE_url = /(https?:\/\/)?(([a-z0-9_]+:[a-z0-9_]+@)?[a-z0-9_-]{2,}(\.[a-z0-9_-]{2,}){2,}(:[0-9]+)?(\/\S+)*)/i; |
|---|
| 466 | |
|---|
| 467 | |
|---|
| 468 | |
|---|
| 469 | |
|---|
| 470 | |
|---|
| 471 | |
|---|
| 472 | |
|---|
| 473 | |
|---|
| 474 | |
|---|
| 475 | Xinha.Config = function() |
|---|
| 476 | { |
|---|
| 477 | this.version = Xinha.version.Revision; |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | |
|---|
| 485 | |
|---|
| 486 | |
|---|
| 487 | |
|---|
| 488 | this.width = "auto"; |
|---|
| 489 | |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | this.height = "auto"; |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | this.sizeIncludesBars = true; |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | |
|---|
| 511 | |
|---|
| 512 | |
|---|
| 513 | |
|---|
| 514 | |
|---|
| 515 | |
|---|
| 516 | this.sizeIncludesPanels = true; |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | |
|---|
| 523 | |
|---|
| 524 | |
|---|
| 525 | |
|---|
| 526 | |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | |
|---|
| 530 | |
|---|
| 531 | |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | |
|---|
| 535 | this.panel_dimensions = |
|---|
| 536 | { |
|---|
| 537 | left: '200px', |
|---|
| 538 | right: '200px', |
|---|
| 539 | top: '100px', |
|---|
| 540 | bottom: '100px' |
|---|
| 541 | }; |
|---|
| 542 | |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | this.iframeWidth = null; |
|---|
| 551 | |
|---|
| 552 | |
|---|
| 553 | |
|---|
| 554 | |
|---|
| 555 | |
|---|
| 556 | |
|---|
| 557 | |
|---|
| 558 | this.statusBar = true; |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | |
|---|
| 565 | |
|---|
| 566 | |
|---|
| 567 | this.htmlareaPaste = false; |
|---|
| 568 | |
|---|
| 569 | |
|---|
| 570 | |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | |
|---|
| 574 | |
|---|
| 575 | |
|---|
| 576 | |
|---|
| 577 | |
|---|
| 578 | this.mozParaHandler = 'best'; |
|---|
| 579 | |
|---|
| 580 | |
|---|
| 581 | |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | |
|---|
| 585 | |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | |
|---|
| 590 | |
|---|
| 591 | |
|---|
| 592 | |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | |
|---|
| 599 | |
|---|
| 600 | this.getHtmlMethod = 'DOMwalk'; |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | this.undoSteps = 20; |
|---|
| 607 | |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | this.undoTimeout = 500; |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | |
|---|
| 618 | this.changeJustifyWithDirection = false; |
|---|
| 619 | |
|---|
| 620 | |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | |
|---|
| 624 | this.fullPage = false; |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | |
|---|
| 630 | |
|---|
| 631 | |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | |
|---|
| 636 | |
|---|
| 637 | |
|---|
| 638 | this.pageStyle = ""; |
|---|
| 639 | |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | this.pageStyleSheets = []; |
|---|
| 647 | |
|---|
| 648 | |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | |
|---|
| 653 | |
|---|
| 654 | this.baseHref = null; |
|---|
| 655 | |
|---|
| 656 | |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | |
|---|
| 660 | |
|---|
| 661 | |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | this.expandRelativeUrl = true; |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | |
|---|
| 672 | this.stripBaseHref = true; |
|---|
| 673 | |
|---|
| 674 | |
|---|
| 675 | |
|---|
| 676 | |
|---|
| 677 | |
|---|
| 678 | |
|---|
| 679 | |
|---|
| 680 | |
|---|
| 681 | this.stripSelfNamedAnchors = true; |
|---|
| 682 | |
|---|
| 683 | |
|---|
| 684 | |
|---|
| 685 | |
|---|
| 686 | |
|---|
| 687 | this.only7BitPrintablesInURLs = true; |
|---|
| 688 | |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | this.sevenBitClean = false; |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | |
|---|
| 708 | |
|---|
| 709 | this.specialReplacements = {}; |
|---|
| 710 | |
|---|
| 711 | |
|---|
| 712 | |
|---|
| 713 | |
|---|
| 714 | |
|---|
| 715 | |
|---|
| 716 | |
|---|
| 717 | this.inwardHtml = function (html) { return html } |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | this.outwardHtml = function (html) { return html } |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | |
|---|
| 731 | |
|---|
| 732 | |
|---|
| 733 | this.killWordOnPaste = true; |
|---|
| 734 | |
|---|
| 735 | |
|---|
| 736 | |
|---|
| 737 | |
|---|
| 738 | |
|---|
| 739 | this.makeLinkShowsTarget = true; |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | |
|---|
| 743 | |
|---|
| 744 | this.charSet = (typeof document.characterSet != 'undefined') ? document.characterSet : document.charset; |
|---|
| 745 | |
|---|
| 746 | |
|---|
| 747 | |
|---|
| 748 | |
|---|
| 749 | |
|---|
| 750 | |
|---|
| 751 | |
|---|
| 752 | |
|---|
| 753 | |
|---|
| 754 | |
|---|
| 755 | |
|---|
| 756 | this.browserQuirksMode = null; |
|---|
| 757 | |
|---|
| 758 | |
|---|
| 759 | this.imgURL = "images/"; |
|---|
| 760 | this.popupURL = "popups/"; |
|---|
| 761 | |
|---|
| 762 | |
|---|
| 763 | |
|---|
| 764 | |
|---|
| 765 | |
|---|
| 766 | |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | this.htmlRemoveTags = null; |
|---|
| 771 | |
|---|
| 772 | |
|---|
| 773 | |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | |
|---|
| 777 | |
|---|
| 778 | |
|---|
| 779 | |
|---|
| 780 | |
|---|
| 781 | |
|---|
| 782 | |
|---|
| 783 | |
|---|
| 784 | |
|---|
| 785 | |
|---|
| 786 | this.flowToolbars = true; |
|---|
| 787 | |
|---|
| 788 | |
|---|
| 789 | |
|---|
| 790 | |
|---|
| 791 | this.toolbarAlign = "left"; |
|---|
| 792 | |
|---|
| 793 | |
|---|
| 794 | |
|---|
| 795 | |
|---|
| 796 | |
|---|
| 797 | this.showLoading = false; |
|---|
| 798 | |
|---|
| 799 | |
|---|
| 800 | |
|---|
| 801 | |
|---|
| 802 | |
|---|
| 803 | |
|---|
| 804 | this.stripScripts = true; |
|---|
| 805 | |
|---|
| 806 | |
|---|
| 807 | |
|---|
| 808 | |
|---|
| 809 | |
|---|
| 810 | |
|---|
| 811 | |
|---|
| 812 | |
|---|
| 813 | this.convertUrlsToLinks = true; |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | |
|---|
| 818 | |
|---|
| 819 | |
|---|
| 820 | |
|---|
| 821 | this.colorPickerCellSize = '6px'; |
|---|
| 822 | |
|---|
| 823 | |
|---|
| 824 | |
|---|
| 825 | |
|---|
| 826 | this.colorPickerGranularity = 18; |
|---|
| 827 | |
|---|
| 828 | |
|---|
| 829 | |
|---|
| 830 | |
|---|
| 831 | this.colorPickerPosition = 'bottom,right'; |
|---|
| 832 | |
|---|
| 833 | |
|---|
| 834 | |
|---|
| 835 | |
|---|
| 836 | this.colorPickerWebSafe = false; |
|---|
| 837 | |
|---|
| 838 | |
|---|
| 839 | |
|---|
| 840 | |
|---|
| 841 | this.colorPickerSaveColors = 20; |
|---|
| 842 | |
|---|
| 843 | |
|---|
| 844 | |
|---|
| 845 | |
|---|
| 846 | |
|---|
| 847 | this.fullScreen = false; |
|---|
| 848 | |
|---|
| 849 | |
|---|
| 850 | |
|---|
| 851 | |
|---|
| 852 | |
|---|
| 853 | |
|---|
| 854 | this.fullScreenMargins = [0,0,0,0]; |
|---|
| 855 | |
|---|
| 856 | |
|---|
| 857 | |
|---|
| 858 | |
|---|
| 859 | |
|---|
| 860 | |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | |
|---|
| 868 | |
|---|
| 869 | |
|---|
| 870 | |
|---|
| 871 | |
|---|
| 872 | |
|---|
| 873 | |
|---|
| 874 | |
|---|
| 875 | |
|---|
| 876 | this.toolbar = |
|---|
| 877 | [ |
|---|
| 878 | ["popupeditor"], |
|---|
| 879 | ["separator","formatblock","fontname","fontsize","bold","italic","underline","strikethrough"], |
|---|
| 880 | ["separator","forecolor","hilitecolor","textindicator"], |
|---|
| 881 | ["separator","subscript","superscript"], |
|---|
| 882 | ["linebreak","separator","justifyleft","justifycenter","justifyright","justifyfull"], |
|---|
| 883 | ["separator","insertorderedlist","insertunorderedlist","outdent","indent"], |
|---|
| 884 | ["separator","inserthorizontalrule","createlink","insertimage","inserttable"], |
|---|
| 885 | ["linebreak","separator","undo","redo","selectall","print"], (Xinha.is_gecko ? [] : ["cut","copy","paste","overwrite","saveas"]), |
|---|
| 886 | ["separator","killword","clearfonts","removeformat","toggleborders","splitblock","lefttoright", "righttoleft"], |
|---|
| 887 | ["separator","htmlmode","showhelp","about"] |
|---|
| 888 | ]; |
|---|
| 889 | |
|---|
| 890 | |
|---|
| 891 | |
|---|
| 892 | |
|---|
| 893 | |
|---|
| 894 | |
|---|
| 895 | |
|---|
| 896 | |
|---|
| 897 | |
|---|
| 898 | |
|---|
| 899 | |
|---|
| 900 | |
|---|
| 901 | |
|---|
| 902 | |
|---|
| 903 | |
|---|
| 904 | |
|---|
| 905 | |
|---|
| 906 | |
|---|
| 907 | |
|---|
| 908 | this.fontname = |
|---|
| 909 | { |
|---|
| 910 | "— font —": '', |
|---|
| 911 | "Arial" : 'arial,helvetica,sans-serif', |
|---|
| 912 | "Courier New" : 'courier new,courier,monospace', |
|---|
| 913 | "Georgia" : 'georgia,times new roman,times,serif', |
|---|
| 914 | "Tahoma" : 'tahoma,arial,helvetica,sans-serif', |
|---|
| 915 | "Times New Roman" : 'times new roman,times,serif', |
|---|
| 916 | "Verdana" : 'verdana,arial,helvetica,sans-serif', |
|---|
| 917 | "impact" : 'impact', |
|---|
| 918 | "WingDings" : 'wingdings' |
|---|
| 919 | }; |
|---|
| 920 | |
|---|
| 921 | |
|---|
| 922 | |
|---|
| 923 | |
|---|
| 924 | |
|---|
| 925 | |
|---|
| 926 | |
|---|
| 927 | |
|---|
| 928 | |
|---|
| 929 | |
|---|
| 930 | |
|---|
| 931 | |
|---|
| 932 | |
|---|
| 933 | |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | |
|---|
| 937 | |
|---|
| 938 | this.fontsize = |
|---|
| 939 | { |
|---|
| 940 | "— size —": "", |
|---|
| 941 | "1 (8 pt)" : "1", |
|---|
| 942 | "2 (10 pt)": "2", |
|---|
| 943 | "3 (12 pt)": "3", |
|---|
| 944 | "4 (14 pt)": "4", |
|---|
| 945 | "5 (18 pt)": "5", |
|---|
| 946 | "6 (24 pt)": "6", |
|---|
| 947 | "7 (36 pt)": "7" |
|---|
| 948 | }; |
|---|
| 949 | |
|---|
| 950 | |
|---|
| 951 | |
|---|
| 952 | |
|---|
| 953 | |
|---|
| 954 | |
|---|
| 955 | |
|---|
| 956 | |
|---|
| 957 | |
|---|
| 958 | |
|---|
| 959 | |
|---|
| 960 | |
|---|
| 961 | |
|---|
| 962 | |
|---|
| 963 | |
|---|
| 964 | |
|---|
| 965 | |
|---|
| 966 | this.formatblock = |
|---|
| 967 | { |
|---|
| 968 | "— format —": "", |
|---|
| 969 | "Heading 1": "h1", |
|---|
| 970 | "Heading 2": "h2", |
|---|
| 971 | "Heading 3": "h3", |
|---|
| 972 | "Heading 4": "h4", |
|---|
| 973 | "Heading 5": "h5", |
|---|
| 974 | "Heading 6": "h6", |
|---|
| 975 | "Normal" : "p", |
|---|
| 976 | "Address" : "address", |
|---|
| 977 | "Formatted": "pre" |
|---|
| 978 | }; |
|---|
| 979 | |
|---|
| 980 | this.dialogOptions = |
|---|
| 981 | { |
|---|
| 982 | 'centered' : true, |
|---|
| 983 | 'greyout':true, |
|---|
| 984 | 'closeOnEscape':true |
|---|
| 985 | }; |
|---|
| 986 | |
|---|
| 987 | |
|---|
| 988 | |
|---|
| 989 | |
|---|
| 990 | |
|---|
| 991 | this.customSelects = {}; |
|---|
| 992 | |
|---|
| 993 | |
|---|
| 994 | |
|---|
| 995 | |
|---|
| 996 | |
|---|
| 997 | |
|---|
| 998 | this.debug = true; |
|---|
| 999 | |
|---|
| 1000 | this.URIs = |
|---|
| 1001 | { |
|---|
| 1002 | "blank": _editor_url + "popups/blank.html", |
|---|
| 1003 | "link": _editor_url + "modules/CreateLink/link.html", |
|---|
| 1004 | "insert_image": _editor_url + "modules/InsertImage/insert_image.html", |
|---|
| 1005 | "insert_table": _editor_url + "modules/InsertTable/insert_table.html", |
|---|
| 1006 | "select_color": _editor_url + "popups/select_color.html", |
|---|
| 1007 | "about": _editor_url + "popups/about.html", |
|---|
| 1008 | "help": _editor_url + "popups/editor_help.html" |
|---|
| 1009 | }; |
|---|
| 1010 | |
|---|
| 1011 | |
|---|
| 1012 | |
|---|
| 1013 | |
|---|
| 1014 | |
|---|
| 1015 | |
|---|
| 1016 | |
|---|
| 1017 | |
|---|
| 1018 | |
|---|
| 1019 | |
|---|
| 1020 | |
|---|
| 1021 | |
|---|
| 1022 | |
|---|
| 1023 | |
|---|
| 1024 | |
|---|
| 1025 | |
|---|
| 1026 | |
|---|
| 1027 | |
|---|
| 1028 | |
|---|
| 1029 | |
|---|
| 1030 | |
|---|
| 1031 | |
|---|
| 1032 | |
|---|
| 1033 | |
|---|
| 1034 | this.btnList = |
|---|
| 1035 | { |
|---|
| 1036 | bold: [ "Bold", Xinha._lc({key: 'button_bold', string: ["ed_buttons_main.gif",3,2]}, 'Xinha'), false, function(e) { e.execCommand("bold"); } ], |
|---|
| 1037 | italic: [ "Italic", Xinha._lc({key: 'button_italic', string: ["ed_buttons_main.gif",2,2]}, 'Xinha'), false, function(e) { e.execCommand("italic"); } ], |
|---|
| 1038 | underline: [ "Underline", Xinha._lc({key: 'button_underline', string: ["ed_buttons_main.gif",2,0]}, 'Xinha'), false, function(e) { e.execCommand("underline"); } ], |
|---|
| 1039 | strikethrough: [ "Strikethrough", Xinha._lc({key: 'button_strikethrough', string: ["ed_buttons_main.gif",3,0]}, 'Xinha'), false, function(e) { e.execCommand("strikethrough"); } ], |
|---|
| 1040 | subscript: [ "Subscript", Xinha._lc({key: 'button_subscript', string: ["ed_buttons_main.gif",3,1]}, 'Xinha'), false, function(e) { e.execCommand("subscript"); } ], |
|---|
| 1041 | superscript: [ "Superscript", Xinha._lc({key: 'button_superscript', string: ["ed_buttons_main.gif",2,1]}, 'Xinha'), false, function(e) { e.execCommand("superscript"); } ], |
|---|
| 1042 | |
|---|
| 1043 | justifyleft: [ "Justify Left", ["ed_buttons_main.gif",0,0], false, function(e) { e.execCommand("justifyleft"); } ], |
|---|
| 1044 | justifycenter: [ "Justify Center", ["ed_buttons_main.gif",1,1], false, function(e){ e.execCommand("justifycenter"); } ], |
|---|
| 1045 | justifyright: [ "Justify Right", ["ed_buttons_main.gif",1,0], false, function(e) { e.execCommand("justifyright"); } ], |
|---|
| 1046 | justifyfull: [ "Justify Full", ["ed_buttons_main.gif",0,1], false, function(e) { e.execCommand("justifyfull"); } ], |
|---|
| 1047 | |
|---|
| 1048 | orderedlist: [ "Ordered List", ["ed_buttons_main.gif",0,3], false, function(e) { e.execCommand("insertorderedlist"); } ], |
|---|
| 1049 | unorderedlist: [ "Bulleted List", ["ed_buttons_main.gif",1,3], false, function(e) { e.execCommand("insertunorderedlist"); } ], |
|---|
| 1050 | insertorderedlist: [ "Ordered List", ["ed_buttons_main.gif",0,3], false, function(e) { e.execCommand("insertorderedlist"); } ], |
|---|
| 1051 | insertunorderedlist: [ "Bulleted List", ["ed_buttons_main.gif",1,3], false, function(e) { e.execCommand("insertunorderedlist"); } ], |
|---|
| 1052 | |
|---|
| 1053 | outdent: [ "Decrease Indent", ["ed_buttons_main.gif",1,2], false, function(e) { e.execCommand("outdent"); } ], |
|---|
| 1054 | indent: [ "Increase Indent",["ed_buttons_main.gif",0,2], false, function(e) { e.execCommand("indent"); } ], |
|---|
| 1055 | forecolor: [ "Font Color", ["ed_buttons_main.gif",3,3], false, function(e) { e.execCommand("forecolor"); } ], |
|---|
| 1056 | hilitecolor: [ "Background Color", ["ed_buttons_main.gif",2,3], false, function(e) { e.execCommand("hilitecolor"); } ], |
|---|
| 1057 | |
|---|
| 1058 | undo: [ "Undoes your last action", ["ed_buttons_main.gif",4,2], false, function(e) { e.execCommand("undo"); } ], |
|---|
| 1059 | redo: [ "Redoes your last action", ["ed_buttons_main.gif",5,2], false, function(e) { e.execCommand("redo"); } ], |
|---|
| 1060 | cut: [ "Cut selection", ["ed_buttons_main.gif",5,0], false, function (e, cmd) { e.execCommand(cmd); } ], |
|---|
| 1061 | copy: [ "Copy selection", ["ed_buttons_main.gif",4,0], false, function (e, cmd) { e.execCommand(cmd); } ], |
|---|
| 1062 | paste: [ "Paste from clipboard", ["ed_buttons_main.gif",4,1], false, function (e, cmd) { e.execCommand(cmd); } ], |
|---|
| 1063 | selectall: [ "Select all", "ed_selectall.gif", false, function(e) {e.execCommand("selectall");} ], |
|---|
| 1064 | |
|---|
| 1065 | inserthorizontalrule: [ "Horizontal Rule", ["ed_buttons_main.gif",6,0], false, function(e) { e.execCommand("inserthorizontalrule"); } ], |
|---|
| 1066 | createlink: [ "Insert Web Link", ["ed_buttons_main.gif",6,1], false, function(e) { e._createLink(); } ], |
|---|
| 1067 | insertimage: [ "Insert/Modify Image", ["ed_buttons_main.gif",6,3], false, function(e) { e.execCommand("insertimage"); } ], |
|---|
| 1068 | inserttable: [ "Insert Table", ["ed_buttons_main.gif",6,2], false, function(e) { e.execCommand("inserttable"); } ], |
|---|
| 1069 | |
|---|
| 1070 | htmlmode: [ "Toggle HTML Source", ["ed_buttons_main.gif",7,0], true, function(e) { e.execCommand("htmlmode"); } ], |
|---|
| 1071 | toggleborders: [ "Toggle Borders", ["ed_buttons_main.gif",7,2], false, function(e) { e._toggleBorders(); } ], |
|---|
| 1072 | print: [ "Print document", ["ed_buttons_main.gif",8,1], false, function(e) { if(Xinha.is_gecko) {e._iframe.contentWindow.print(); } else { e.focusEditor(); print(); } } ], |
|---|
| 1073 | saveas: [ "Save as", "ed_saveas.gif", false, function(e) { e.execCommand("saveas",false,"noname.htm"); } ], |
|---|
| 1074 | about: [ "About this editor", ["ed_buttons_main.gif",8,2], true, function(e) { e.execCommand("about"); } ], |
|---|
| 1075 | showhelp: [ "Help using editor", ["ed_buttons_main.gif",9,2], true, function(e) { e.execCommand("showhelp"); } ], |
|---|
| 1076 | |
|---|
| 1077 | splitblock: [ "Split Block", "ed_splitblock.gif", false, function(e) { e._splitBlock(); } ], |
|---|
| 1078 | lefttoright: [ "Direction left to right", ["ed_buttons_main.gif",0,4], false, function(e) { e.execCommand("lefttoright"); } ], |
|---|
| 1079 | righttoleft: [ "Direction right to left", ["ed_buttons_main.gif",1,4], false, function(e) { e.execCommand("righttoleft"); } ], |
|---|
| 1080 | overwrite: [ "Insert/Overwrite", "ed_overwrite.gif", false, function(e) { e.execCommand("overwrite"); } ], |
|---|
| 1081 | |
|---|
| 1082 | wordclean: [ "MS Word Cleaner", ["ed_buttons_main.gif",5,3], false, function(e) { e._wordClean(); } ], |
|---|
| 1083 | clearfonts: [ "Clear Inline Font Specifications", ["ed_buttons_main.gif",5,4], true, function(e) { e._clearFonts(); } ], |
|---|
| 1084 | removeformat: [ "Remove formatting", ["ed_buttons_main.gif",4,4], false, function(e) { e.execCommand("removeformat"); } ], |
|---|
| 1085 | killword: [ "Clear MSOffice tags", ["ed_buttons_main.gif",4,3], false, function(e) { e.execCommand("killword"); } ] |
|---|
| 1086 | }; |
|---|
| 1087 | |
|---|
| 1088 | |
|---|
| 1089 | |
|---|
| 1090 | for ( var i in this.btnList ) |
|---|
| 1091 | { |
|---|
| 1092 | var btn = this.btnList[i]; |
|---|
| 1093 | |
|---|
| 1094 | if ( typeof btn != 'object' ) |
|---|
| 1095 | { |
|---|
| 1096 | continue; |
|---|
| 1097 | } |
|---|
| 1098 | if ( typeof btn[1] != 'string' ) |
|---|
| 1099 | { |
|---|
| 1100 | btn[1][0] = _editor_url + this.imgURL + btn[1][0]; |
|---|
| 1101 | } |
|---|
| 1102 | else |
|---|
| 1103 | { |
|---|
| 1104 | btn[1] = _editor_url + this.imgURL + btn[1]; |
|---|
| 1105 | } |
|---|
| 1106 | btn[0] = Xinha._lc(btn[0]); |
|---|
| 1107 | } |
|---|
| 1108 | |
|---|
| 1109 | }; |
|---|
| 1110 | |
|---|
| 1111 | |
|---|
| 1112 | |
|---|
| 1113 | |
|---|
| 1114 | |
|---|
| 1115 | |
|---|
| 1116 | |
|---|
| 1117 | |
|---|
| 1118 | |
|---|
| 1119 | |
|---|
| 1120 | |
|---|
| 1121 | |
|---|
| 1122 | |
|---|
| 1123 | |
|---|
| 1124 | |
|---|
| 1125 | |
|---|
| 1126 | |
|---|
| 1127 | |
|---|
| 1128 | |
|---|
| 1129 | |
|---|
| 1130 | |
|---|
| 1131 | |
|---|
| 1132 | |
|---|
| 1133 | |
|---|
| 1134 | |
|---|
| 1135 | |
|---|
| 1136 | |
|---|
| 1137 | |
|---|
| 1138 | |
|---|
| 1139 | |
|---|
| 1140 | |
|---|
| 1141 | |
|---|
| 1142 | |
|---|
| 1143 | |
|---|
| 1144 | |
|---|
| 1145 | |
|---|
| 1146 | |
|---|
| 1147 | |
|---|
| 1148 | Xinha.Config.prototype.registerButton = function(id, tooltip, image, textMode, action, context) |
|---|
| 1149 | { |
|---|
| 1150 | var the_id; |
|---|
| 1151 | if ( typeof id == "string" ) |
|---|
| 1152 | { |
|---|
| 1153 | the_id = id; |
|---|
| 1154 | } |
|---|
| 1155 | else if ( typeof id == "object" ) |
|---|
| 1156 | { |
|---|
| 1157 | the_id = id.id; |
|---|
| 1158 | } |
|---|
| 1159 | else |
|---|
| 1160 | { |
|---|
| 1161 | alert("ERROR [Xinha.Config::registerButton]:\ninvalid arguments"); |
|---|
| 1162 | return false; |
|---|
| 1163 | } |
|---|
| 1164 | |
|---|
| 1165 | |
|---|
| 1166 | |
|---|
| 1167 | |
|---|
| 1168 | |
|---|
| 1169 | |
|---|
| 1170 | |
|---|
| 1171 | |
|---|
| 1172 | switch ( typeof id ) |
|---|
| 1173 | { |
|---|
| 1174 | case "string": |
|---|
| 1175 | this.btnList[id] = [ tooltip, image, textMode, action, context ]; |
|---|
| 1176 | break; |
|---|
| 1177 | case "object": |
|---|
| 1178 | this.btnList[id.id] = [ id.tooltip, id.image, id.textMode, id.action, id.context ]; |
|---|
| 1179 | break; |
|---|
| 1180 | } |
|---|
| 1181 | }; |
|---|
| 1182 | |
|---|
| 1183 | Xinha.prototype.registerPanel = function(side, object) |
|---|
| 1184 | { |
|---|
| 1185 | if ( !side ) |
|---|
| 1186 | { |
|---|
| 1187 | side = 'right'; |
|---|
| 1188 | } |
|---|
| 1189 | this.setLoadingMessage('Register ' + side + ' panel '); |
|---|
| 1190 | var panel = this.addPanel(side); |
|---|
| 1191 | if ( object ) |
|---|
| 1192 | { |
|---|
| 1193 | object.drawPanelIn(panel); |
|---|
| 1194 | } |
|---|
| 1195 | }; |
|---|
| 1196 | |
|---|
| 1197 | |
|---|
| 1198 | |
|---|
| 1199 | |
|---|
| 1200 | |
|---|
| 1201 | |
|---|
| 1202 | |
|---|
| 1203 | Xinha.Config.prototype.registerDropdown = function(object) |
|---|
| 1204 | { |
|---|
| 1205 | |
|---|
| 1206 | |
|---|
| 1207 | |
|---|
| 1208 | |
|---|
| 1209 | |
|---|
| 1210 | |
|---|
| 1211 | |
|---|
| 1212 | |
|---|
| 1213 | |
|---|
| 1214 | this.customSelects[object.id] = object; |
|---|
| 1215 | }; |
|---|
| 1216 | |
|---|
| 1217 | |
|---|
| 1218 | |
|---|
| 1219 | |
|---|
| 1220 | |
|---|
| 1221 | |
|---|
| 1222 | |
|---|
| 1223 | |
|---|
| 1224 | |
|---|
| 1225 | |
|---|
| 1226 | |
|---|
| 1227 | Xinha.Config.prototype.hideSomeButtons = function(remove) |
|---|
| 1228 | { |
|---|
| 1229 | var toolbar = this.toolbar; |
|---|
| 1230 | for ( var i = toolbar.length; --i >= 0; ) |
|---|
| 1231 | { |
|---|
| 1232 | var line = toolbar[i]; |
|---|
| 1233 | for ( var j = line.length; --j >= 0; ) |
|---|
| 1234 | { |
|---|
| 1235 | if ( remove.indexOf(" " + line[j] + " ") >= 0 ) |
|---|
| 1236 | { |
|---|
| 1237 | var len = 1; |
|---|
| 1238 | if ( /separator|space/.test(line[j + 1]) ) |
|---|
| 1239 | { |
|---|
| 1240 | len = 2; |
|---|
| 1241 | } |
|---|
| 1242 | line.splice(j, len); |
|---|
| 1243 | } |
|---|
| 1244 | } |
|---|
| 1245 | } |
|---|
| 1246 | }; |
|---|
| 1247 | |
|---|
| 1248 | |
|---|
| 1249 | |
|---|
| 1250 | |
|---|
| 1251 | |
|---|
| 1252 | |
|---|
| 1253 | |
|---|
| 1254 | |
|---|
| 1255 | |
|---|
| 1256 | |
|---|
| 1257 | |
|---|
| 1258 | |
|---|
| 1259 | |
|---|
| 1260 | Xinha.Config.prototype.addToolbarElement = function(id, where, position) |
|---|
| 1261 | { |
|---|
| 1262 | var toolbar = this.toolbar; |
|---|
| 1263 | var a, i, j, o, sid; |
|---|
| 1264 | var idIsArray = false; |
|---|
| 1265 | var whereIsArray = false; |
|---|
| 1266 | var whereLength = 0; |
|---|
| 1267 | var whereJ = 0; |
|---|
| 1268 | var whereI = 0; |
|---|
| 1269 | var exists = false; |
|---|
| 1270 | var found = false; |
|---|
| 1271 | |
|---|
| 1272 | if ( ( id && typeof id == "object" ) && ( id.constructor == Array ) ) |
|---|
| 1273 | { |
|---|
| 1274 | idIsArray = true; |
|---|
| 1275 | } |
|---|
| 1276 | if ( ( where && typeof where == "object" ) && ( where.constructor == Array ) ) |
|---|
| 1277 | { |
|---|
| 1278 | whereIsArray = true; |
|---|
| 1279 | whereLength = where.length; |
|---|
| 1280 | } |
|---|
| 1281 | |
|---|
| 1282 | if ( idIsArray ) |
|---|
| 1283 | { |
|---|
| 1284 | for ( i = 0; i < id.length; ++i ) |
|---|
| 1285 | { |
|---|
| 1286 | if ( ( id[i] != "separator" ) && ( id[i].indexOf("T[") !== 0) ) |
|---|
| 1287 | { |
|---|
| 1288 | sid = id[i]; |
|---|
| 1289 | } |
|---|
| 1290 | } |
|---|
| 1291 | } |
|---|
| 1292 | else |
|---|
| 1293 | { |
|---|
| 1294 | sid = id; |
|---|
| 1295 | } |
|---|
| 1296 | |
|---|
| 1297 | for ( i = 0; i < toolbar.length; ++i ) { |
|---|
| 1298 | a = toolbar[i]; |
|---|
| 1299 | for ( j = 0; j < a.length; ++j ) { |
|---|
| 1300 | |
|---|
| 1301 | if ( a[j] == sid ) { |
|---|
| 1302 | return; |
|---|
| 1303 | } |
|---|
| 1304 | } |
|---|
| 1305 | } |
|---|
| 1306 | |
|---|
| 1307 | |
|---|
| 1308 | for ( i = 0; !found && i < toolbar.length; ++i ) |
|---|
| 1309 | { |
|---|
| 1310 | a = toolbar[i]; |
|---|
| 1311 | for ( j = 0; !found && j < a.length; ++j ) |
|---|
| 1312 | { |
|---|
| 1313 | if ( whereIsArray ) |
|---|
| 1314 | { |
|---|
| 1315 | for ( o = 0; o < whereLength; ++o ) |
|---|
| 1316 | { |
|---|
| 1317 | if ( a[j] == where[o] ) |
|---|
| 1318 | { |
|---|
| 1319 | if ( o === 0 ) |
|---|
| 1320 | { |
|---|
| 1321 | found = true; |
|---|
| 1322 | j--; |
|---|
| 1323 | break; |
|---|
| 1324 | } |
|---|
| 1325 | else |
|---|
| 1326 | { |
|---|
| 1327 | whereI = i; |
|---|
| 1328 | whereJ = j; |
|---|
| 1329 | whereLength = o; |
|---|
| 1330 | } |
|---|
| 1331 | } |
|---|
| 1332 | } |
|---|
| 1333 | } |
|---|
| 1334 | else |
|---|
| 1335 | { |
|---|
| 1336 | |
|---|
| 1337 | if ( a[j] == where ) |
|---|
| 1338 | { |
|---|
| 1339 | found = true; |
|---|
| 1340 | break; |
|---|
| 1341 | } |
|---|
| 1342 | } |
|---|
| 1343 | } |
|---|
| 1344 | } |
|---|
| 1345 | |
|---|
| 1346 | |
|---|
| 1347 | if ( !found && whereIsArray ) |
|---|
| 1348 | { |
|---|
| 1349 | if ( where.length != whereLength ) |
|---|
| 1350 | { |
|---|
| 1351 | j = whereJ; |
|---|
| 1352 | a = toolbar[whereI]; |
|---|
| 1353 | found = true; |
|---|
| 1354 | } |
|---|
| 1355 | } |
|---|
| 1356 | if ( found ) |
|---|
| 1357 | { |
|---|
| 1358 | |
|---|
| 1359 | if ( position === 0 ) |
|---|
| 1360 | { |
|---|
| 1361 | if ( idIsArray) |
|---|
| 1362 | { |
|---|
| 1363 | a[j] = id[id.length-1]; |
|---|
| 1364 | for ( i = id.length-1; --i >= 0; ) |
|---|
| 1365 | { |
|---|
| 1366 | a.splice(j, 0, id[i]); |
|---|
| 1367 | } |
|---|
| 1368 | } |
|---|
| 1369 | else |
|---|
| 1370 | { |
|---|
| 1371 | a[j] = id; |
|---|
| 1372 | } |
|---|
| 1373 | } |
|---|
| 1374 | else |
|---|
| 1375 | { |
|---|
| 1376 | |
|---|
| 1377 | if ( position < 0 ) |
|---|
| 1378 | { |
|---|
| 1379 | j = j + position + 1; |
|---|
| 1380 | } |
|---|
| 1381 | else if ( position > 0 ) |
|---|
| 1382 | { |
|---|
| 1383 | j = j + position; |
|---|
| 1384 | } |
|---|
| 1385 | if ( idIsArray ) |
|---|
| 1386 | { |
|---|
| 1387 | for ( i = id.length; --i >= 0; ) |
|---|
| 1388 | { |
|---|
| 1389 | a.splice(j, 0, id[i]); |
|---|
| 1390 | } |
|---|
| 1391 | } |
|---|
| 1392 | else |
|---|
| 1393 | { |
|---|
| 1394 | a.splice(j, 0, id); |
|---|
| 1395 | } |
|---|
| 1396 | } |
|---|
| 1397 | } |
|---|
| 1398 | else |
|---|
| 1399 | { |
|---|
| 1400 | |
|---|
| 1401 | toolbar[0].splice(0, 0, "separator"); |
|---|
| 1402 | if ( idIsArray) |
|---|
| 1403 | { |
|---|
| 1404 | for ( i = id.length; --i >= 0; ) |
|---|
| 1405 | { |
|---|
| 1406 | toolbar[0].splice(0, 0, id[i]); |
|---|
| 1407 | } |
|---|
| 1408 | } |
|---|
| 1409 | else |
|---|
| 1410 | { |
|---|
| 1411 | toolbar[0].splice(0, 0, id); |
|---|
| 1412 | } |
|---|
| 1413 | } |
|---|
| 1414 | }; |
|---|
| 1415 | |
|---|
| 1416 | |
|---|
| 1417 | |
|---|
| 1418 | Xinha.Config.prototype.removeToolbarElement = Xinha.Config.prototype.hideSomeButtons; |
|---|
| 1419 | |
|---|
| 1420 | |
|---|
| 1421 | |
|---|
| 1422 | |
|---|
| 1423 | Xinha.replaceAll = function(config) |
|---|
| 1424 | { |
|---|
| 1425 | var tas = document.getElementsByTagName("textarea"); |
|---|
| 1426 | |
|---|
| 1427 | for ( var i = tas.length; i > 0; (new Xinha(tas[--i], config)).generate() ) |
|---|
| 1428 | { |
|---|
| 1429 | |
|---|
| 1430 | } |
|---|
| 1431 | }; |
|---|
| 1432 | |
|---|
| 1433 | |
|---|
| 1434 | |
|---|
| 1435 | |
|---|
| 1436 | |
|---|
| 1437 | Xinha.replace = function(id, config) |
|---|
| 1438 | { |
|---|
| 1439 | var ta = Xinha.getElementById("textarea", id); |
|---|
| 1440 | return ta ? (new Xinha(ta, config)).generate() : null; |
|---|
| 1441 | }; |
|---|
| 1442 | |
|---|
| 1443 | |
|---|
| 1444 | |
|---|
| 1445 | |
|---|
| 1446 | |
|---|
| 1447 | Xinha.prototype._createToolbar = function () |
|---|
| 1448 | { |
|---|
| 1449 | this.setLoadingMessage(Xinha._lc('Create Toolbar')); |
|---|
| 1450 | var editor = this; |
|---|
| 1451 | |
|---|
| 1452 | var toolbar = document.createElement("div"); |
|---|
| 1453 | |
|---|
| 1454 | this._toolBar = this._toolbar = toolbar; |
|---|
| 1455 | toolbar.className = "toolbar"; |
|---|
| 1456 | toolbar.unselectable = "1"; |
|---|
| 1457 | toolbar.align = this.config.toolbarAlign; |
|---|
| 1458 | |
|---|
| 1459 | Xinha.freeLater(this, '_toolBar'); |
|---|
| 1460 | Xinha.freeLater(this, '_toolbar'); |
|---|
| 1461 | |
|---|
| 1462 | var tb_row = null; |
|---|
| 1463 | var tb_objects = {}; |
|---|
| 1464 | this._toolbarObjects = tb_objects; |
|---|
| 1465 | |
|---|
| 1466 | this._createToolbar1(editor, toolbar, tb_objects); |
|---|
| 1467 | this._htmlArea.appendChild(toolbar); |
|---|
| 1468 | |
|---|
| 1469 | return toolbar; |
|---|
| 1470 | }; |
|---|
| 1471 | |
|---|
| 1472 | |
|---|
| 1473 | |
|---|
| 1474 | |
|---|
| 1475 | |
|---|
| 1476 | Xinha.prototype._setConfig = function(config) |
|---|
| 1477 | { |
|---|
| 1478 | this.config = config; |
|---|
| 1479 | }; |
|---|
| 1480 | |
|---|
| 1481 | |
|---|
| 1482 | |
|---|
| 1483 | Xinha.prototype._addToolbar = function() |
|---|
| 1484 | { |
|---|
| 1485 | this._createToolbar1(this, this._toolbar, this._toolbarObjects); |
|---|
| 1486 | }; |
|---|
| 1487 | |
|---|
| 1488 | |
|---|
| 1489 | |
|---|
| 1490 | |
|---|
| 1491 | |
|---|
| 1492 | |
|---|
| 1493 | |
|---|
| 1494 | Xinha._createToolbarBreakingElement = function() |
|---|
| 1495 | { |
|---|
| 1496 | var brk = document.createElement('div'); |
|---|
| 1497 | brk.style.height = '1px'; |
|---|
| 1498 | brk.style.width = '1px'; |
|---|
| 1499 | brk.style.lineHeight = '1px'; |
|---|
| 1500 | brk.style.fontSize = '1px'; |
|---|
| 1501 | brk.style.clear = 'both'; |
|---|
| 1502 | return brk; |
|---|
| 1503 | }; |
|---|
| 1504 | |
|---|
| 1505 | |
|---|
| 1506 | |
|---|
| 1507 | |
|---|
| 1508 | |
|---|
| 1509 | |
|---|
| 1510 | Xinha.prototype._createToolbar1 = function (editor, toolbar, tb_objects) |
|---|
| 1511 | { |
|---|
| 1512 | var tb_row; |
|---|
| 1513 | |
|---|
| 1514 | |
|---|
| 1515 | |
|---|
| 1516 | if ( editor.config.flowToolbars ) |
|---|
| 1517 | { |
|---|
| 1518 | toolbar.appendChild(Xinha._createToolbarBreakingElement()); |
|---|
| 1519 | } |
|---|
| 1520 | |
|---|
| 1521 | |
|---|
| 1522 | function newLine() |
|---|
| 1523 | { |
|---|
| 1524 | if ( typeof tb_row != 'undefined' && tb_row.childNodes.length === 0) |
|---|
| 1525 | { |
|---|
| 1526 | return; |
|---|
| 1527 | } |
|---|
| 1528 | |
|---|
| 1529 | var table = document.createElement("table"); |
|---|
| 1530 | table.border = "0px"; |
|---|
| 1531 | table.cellSpacing = "0px"; |
|---|
| 1532 | table.cellPadding = "0px"; |
|---|
| 1533 | if ( editor.config.flowToolbars ) |
|---|
| 1534 | { |
|---|
| 1535 | if ( Xinha.is_ie ) |
|---|
| 1536 | { |
|---|
| 1537 | table.style.styleFloat = "left"; |
|---|
| 1538 | } |
|---|
| 1539 | else |
|---|
| 1540 | { |
|---|
| 1541 | table.style.cssFloat = "left"; |
|---|
| 1542 | } |
|---|
| 1543 | } |
|---|
| 1544 | |
|---|
| 1545 | toolbar.appendChild(table); |
|---|
| 1546 | |
|---|
| 1547 | |
|---|
| 1548 | var tb_body = document.createElement("tbody"); |
|---|
| 1549 | table.appendChild(tb_body); |
|---|
| 1550 | tb_row = document.createElement("tr"); |
|---|
| 1551 | tb_body.appendChild(tb_row); |
|---|
| 1552 | |
|---|
| 1553 | table.className = 'toolbarRow'; |
|---|
| 1554 | } |
|---|
| 1555 | |
|---|
| 1556 | |
|---|
| 1557 | newLine(); |
|---|
| 1558 | |
|---|
| 1559 | |
|---|
| 1560 | |
|---|
| 1561 | |
|---|
| 1562 | function setButtonStatus(id, newval) |
|---|
| 1563 | { |
|---|
| 1564 | var oldval = this[id]; |
|---|
| 1565 | var el = this.element; |
|---|
| 1566 | if ( oldval != newval ) |
|---|
| 1567 | { |
|---|
| 1568 | switch (id) |
|---|
| 1569 | { |
|---|
| 1570 | case "enabled": |
|---|
| 1571 | if ( newval ) |
|---|
| 1572 | { |
|---|
| 1573 | Xinha._removeClass(el, "buttonDisabled"); |
|---|
| 1574 | el.disabled = false; |
|---|
| 1575 | } |
|---|
| 1576 | else |
|---|
| 1577 | { |
|---|
| 1578 | Xinha._addClass(el, "buttonDisabled"); |
|---|
| 1579 | el.disabled = true; |
|---|
| 1580 | } |
|---|
| 1581 | break; |
|---|
| 1582 | case "active": |
|---|
| 1583 | if ( newval ) |
|---|
| 1584 | { |
|---|
| 1585 | Xinha._addClass(el, "buttonPressed"); |
|---|
| 1586 | } |
|---|
| 1587 | else |
|---|
| 1588 | { |
|---|
| 1589 | Xinha._removeClass(el, "buttonPressed"); |
|---|
| 1590 | } |
|---|
| 1591 | break; |
|---|
| 1592 | } |
|---|
| 1593 | this[id] = newval; |
|---|
| 1594 | } |
|---|
| 1595 | } |
|---|
| 1596 | |
|---|
| 1597 | |
|---|
| 1598 | |
|---|
| 1599 | |
|---|
| 1600 | |
|---|
| 1601 | function createSelect(txt) |
|---|
| 1602 | { |
|---|
| 1603 | var options = null; |
|---|
| 1604 | var el = null; |
|---|
| 1605 | var cmd = null; |
|---|
| 1606 | var customSelects = editor.config.customSelects; |
|---|
| 1607 | var context = null; |
|---|
| 1608 | var tooltip = ""; |
|---|
| 1609 | switch (txt) |
|---|
| 1610 | { |
|---|
| 1611 | case "fontsize": |
|---|
| 1612 | case "fontname": |
|---|
| 1613 | case "formatblock": |
|---|
| 1614 | |
|---|
| 1615 | |
|---|
| 1616 | |
|---|
| 1617 | |
|---|
| 1618 | |
|---|
| 1619 | |
|---|
| 1620 | |
|---|
| 1621 | options = editor.config[txt]; |
|---|
| 1622 | cmd = txt; |
|---|
| 1623 | break; |
|---|
| 1624 | default: |
|---|
| 1625 | |
|---|
| 1626 | cmd = txt; |
|---|
| 1627 | var dropdown = customSelects[cmd]; |
|---|
| 1628 | if ( typeof dropdown != "undefined" ) |
|---|
| 1629 | { |
|---|
| 1630 | options = dropdown.options; |
|---|
| 1631 | context = dropdown.context; |
|---|
| 1632 | if ( typeof dropdown.tooltip != "undefined" ) |
|---|
| 1633 | { |
|---|
| 1634 | tooltip = dropdown.tooltip; |
|---|
| 1635 | } |
|---|
| 1636 | } |
|---|
| 1637 | else |
|---|
| 1638 | { |
|---|
| 1639 | alert("ERROR [createSelect]:\nCan't find the requested dropdown definition"); |
|---|
| 1640 | } |
|---|
| 1641 | break; |
|---|
| 1642 | } |
|---|
| 1643 | if ( options ) |
|---|
| 1644 | { |
|---|
| 1645 | el = document.createElement("select"); |
|---|
| 1646 | el.title = tooltip; |
|---|
| 1647 | var obj = |
|---|
| 1648 | { |
|---|
| 1649 | name : txt, |
|---|
| 1650 | element : el, |
|---|
| 1651 | enabled : true, |
|---|
| 1652 | text : false, |
|---|
| 1653 | cmd : cmd, |
|---|
| 1654 | state : setButtonStatus, |
|---|
| 1655 | context : context |
|---|
| 1656 | }; |
|---|
| 1657 | |
|---|
| 1658 | Xinha.freeLater(obj); |
|---|
| 1659 | |
|---|
| 1660 | tb_objects[txt] = obj; |
|---|
| 1661 | |
|---|
| 1662 | for ( var i in options ) |
|---|
| 1663 | { |
|---|
| 1664 | |
|---|
| 1665 | if ( typeof(options[i]) != 'string' ) |
|---|
| 1666 | { |
|---|
| 1667 | continue; |
|---|
| 1668 | } |
|---|
| 1669 | var op = document.createElement("option"); |
|---|
| 1670 | op.innerHTML = Xinha._lc(i); |
|---|
| 1671 | op.value = options[i]; |
|---|
| 1672 | el.appendChild(op); |
|---|
| 1673 | } |
|---|
| 1674 | Xinha._addEvent(el, "change", function () { editor._comboSelected(el, txt); } ); |
|---|
| 1675 | } |
|---|
| 1676 | return el; |
|---|
| 1677 | } |
|---|
| 1678 | |
|---|
| 1679 | |
|---|
| 1680 | function createButton(txt) |
|---|
| 1681 | { |
|---|
| 1682 | |
|---|
| 1683 | var el, btn, obj = null; |
|---|
| 1684 | switch (txt) |
|---|
| 1685 | { |
|---|
| 1686 | case "separator": |
|---|
| 1687 | if ( editor.config.flowToolbars ) |
|---|
| 1688 | { |
|---|
| 1689 | newLine(); |
|---|
| 1690 | } |
|---|
| 1691 | el = document.createElement("div"); |
|---|
| 1692 | el.className = "separator"; |
|---|
| 1693 | break; |
|---|
| 1694 | case "space": |
|---|
| 1695 | el = document.createElement("div"); |
|---|
| 1696 | el.className = "space"; |
|---|
| 1697 | break; |
|---|
| 1698 | case "linebreak": |
|---|
| 1699 | newLine(); |
|---|
| 1700 | return false; |
|---|
| 1701 | case "textindicator": |
|---|
| 1702 | el = document.createElement("div"); |
|---|
| 1703 | el.appendChild(document.createTextNode("A")); |
|---|
| 1704 | el.className = "indicator"; |
|---|
| 1705 | el.title = Xinha._lc("Current style"); |
|---|
| 1706 | obj = |
|---|
| 1707 | { |
|---|
| 1708 | name : txt, |
|---|
| 1709 | element : el, |
|---|
| 1710 | enabled : true, |
|---|
| 1711 | active : false, |
|---|
| 1712 | text : false, |
|---|
| 1713 | cmd : "textindicator", |
|---|
| 1714 | state : setButtonStatus |
|---|
| 1715 | }; |
|---|
| 1716 | |
|---|
| 1717 | Xinha.freeLater(obj); |
|---|
| 1718 | |
|---|
| 1719 | tb_objects[txt] = obj; |
|---|
| 1720 | break; |
|---|
| 1721 | default: |
|---|
| 1722 | btn = editor.config.btnList[txt]; |
|---|
| 1723 | } |
|---|
| 1724 | if ( !el && btn ) |
|---|
| 1725 | { |
|---|
| 1726 | el = document.createElement("a"); |
|---|
| 1727 | el.style.display = 'block'; |
|---|
| 1728 | el.href = 'javascript:void(0)'; |
|---|
| 1729 | el.style.textDecoration = 'none'; |
|---|
| 1730 | el.title = btn[0]; |
|---|
| 1731 | el.className = "button"; |
|---|
| 1732 | el.style.direction = "ltr"; |
|---|
| 1733 | |
|---|
| 1734 | |
|---|
| 1735 | obj = |
|---|
| 1736 | { |
|---|
| 1737 | name : txt, |
|---|
| 1738 | element : el, |
|---|
| 1739 | enabled : true, |
|---|
| 1740 | active : false, |
|---|
| 1741 | text : btn[2], |
|---|
| 1742 | cmd : btn[3], |
|---|
| 1743 | state : setButtonStatus, |
|---|
| 1744 | context : btn[4] || null |
|---|
| 1745 | }; |
|---|
| 1746 | Xinha.freeLater(el); |
|---|
| 1747 | Xinha.freeLater(obj); |
|---|
| 1748 | |
|---|
| 1749 | tb_objects[txt] = obj; |
|---|
| 1750 | |
|---|
| 1751 | |
|---|
| 1752 | el.ondrag = function() { return false; }; |
|---|
| 1753 | |
|---|
| 1754 | |
|---|
| 1755 | Xinha._addEvent( |
|---|
| 1756 | el, |
|---|
| 1757 | "mouseout", |
|---|
| 1758 | function(ev) |
|---|
| 1759 | { |
|---|
| 1760 | if ( obj.enabled ) |
|---|
| 1761 | { |
|---|
| 1762 | |
|---|
| 1763 | Xinha._removeClass(el, "buttonActive"); |
|---|
| 1764 | if ( obj.active ) |
|---|
| 1765 | { |
|---|
| 1766 | Xinha._addClass(el, "buttonPressed"); |
|---|
| 1767 | } |
|---|
| 1768 | } |
|---|
| 1769 | } |
|---|
| 1770 | ); |
|---|
| 1771 | |
|---|
| 1772 | Xinha._addEvent( |
|---|
| 1773 | el, |
|---|
| 1774 | "mousedown", |
|---|
| 1775 | function(ev) |
|---|
| 1776 | { |
|---|
| 1777 | if ( obj.enabled ) |
|---|
| 1778 | { |
|---|
| 1779 | Xinha._addClass(el, "buttonActive"); |
|---|
| 1780 | Xinha._removeClass(el, "buttonPressed"); |
|---|
| 1781 | Xinha._stopEvent(Xinha.is_ie ? window.event : ev); |
|---|
| 1782 | } |
|---|
| 1783 | } |
|---|
| 1784 | ); |
|---|
| 1785 | |
|---|
| 1786 | |
|---|
| 1787 | Xinha._addEvent( |
|---|
| 1788 | el, |
|---|
| 1789 | "click", |
|---|
| 1790 | function(ev) |
|---|
| 1791 | { |
|---|
| 1792 | ev = ev || window.event; |
|---|
| 1793 | editor.btnClickEvent = {clientX : ev.clientX, clientY : ev.clientY}; |
|---|
| 1794 | if ( obj.enabled ) |
|---|
| 1795 | { |
|---|
| 1796 | Xinha._removeClass(el, "buttonActive"); |
|---|
| 1797 | |
|---|
| 1798 | if ( Xinha.is_gecko ) |
|---|
| 1799 | { |
|---|
| 1800 | editor.activateEditor(); |
|---|
| 1801 | } |
|---|
| 1802 | obj.cmd(editor, obj.name, obj); |
|---|
| 1803 | Xinha._stopEvent(ev); |
|---|
| 1804 | } |
|---|
| 1805 | } |
|---|
| 1806 | ); |
|---|
| 1807 | |
|---|
| 1808 | var i_contain = Xinha.makeBtnImg(btn[1]); |
|---|
| 1809 | var img = i_contain.firstChild; |
|---|
| 1810 | Xinha.freeLater(i_contain); |
|---|
| 1811 | Xinha.freeLater(img); |
|---|
| 1812 | |
|---|
| 1813 | el.appendChild(i_contain); |
|---|
| 1814 | |
|---|
| 1815 | obj.imgel = img; |
|---|
| 1816 | obj.swapImage = function(newimg) |
|---|
| 1817 | { |
|---|
| 1818 | if ( typeof newimg != 'string' ) |
|---|
| 1819 | { |
|---|
| 1820 | img.src = newimg[0]; |
|---|
| 1821 | img.style.position = 'relative'; |
|---|
| 1822 | img.style.top = newimg[2] ? ('-' + (18 * (newimg[2] + 1)) + 'px') : '-18px'; |
|---|
| 1823 | img.style.left = newimg[1] ? ('-' + (18 * (newimg[1] + 1)) + 'px') : '-18px'; |
|---|
| 1824 | } |
|---|
| 1825 | else |
|---|
| 1826 | { |
|---|
| 1827 | obj.imgel.src = newimg; |
|---|
| 1828 | img.style.top = '0px'; |
|---|
| 1829 | img.style.left = '0px'; |
|---|
| 1830 | } |
|---|
| 1831 | }; |
|---|
| 1832 | |
|---|
| 1833 | } |
|---|
| 1834 | else if( !el ) |
|---|
| 1835 | { |
|---|
| 1836 | el = createSelect(txt); |
|---|
| 1837 | } |
|---|
| 1838 | |
|---|
| 1839 | return el; |
|---|
| 1840 | } |
|---|
| 1841 | |
|---|
| 1842 | var first = true; |
|---|
| 1843 | for ( var i = 0; i < this.config.toolbar.length; ++i ) |
|---|
| 1844 | { |
|---|
| 1845 | if ( !first ) |
|---|
| 1846 | { |
|---|
| 1847 | |
|---|
| 1848 | } |
|---|
| 1849 | else |
|---|
| 1850 | { |
|---|
| 1851 | first = false; |
|---|
| 1852 | } |
|---|
| 1853 | if ( this.config.toolbar[i] === null ) |
|---|
| 1854 | { |
|---|
| 1855 | this.config.toolbar[i] = ['separator']; |
|---|
| 1856 | } |
|---|
| 1857 | var group = this.config.toolbar[i]; |
|---|
| 1858 | |
|---|
| 1859 | for ( var j = 0; j < group.length; ++j ) |
|---|
| 1860 | { |
|---|
| 1861 | var code = group[j]; |
|---|
| 1862 | var tb_cell; |
|---|
| 1863 | if ( /^([IT])\[(.*?)\]/.test(code) ) |
|---|
| 1864 | { |
|---|
| 1865 | |
|---|
| 1866 | var l7ed = RegExp.$1 == "I"; |
|---|
| 1867 | var label = RegExp.$2; |
|---|
| 1868 | if ( l7ed ) |
|---|
| 1869 | { |
|---|
| 1870 | label = Xinha._lc(label); |
|---|
| 1871 | } |
|---|
| 1872 | tb_cell = document.createElement("td"); |
|---|
| 1873 | tb_row.appendChild(tb_cell); |
|---|
| 1874 | tb_cell.className = "label"; |
|---|
| 1875 | tb_cell.innerHTML = label; |
|---|
| 1876 | } |
|---|
| 1877 | else if ( typeof code != 'function' ) |
|---|
| 1878 | { |
|---|
| 1879 | var tb_element = createButton(code); |
|---|
| 1880 | if ( tb_element ) |
|---|
| 1881 | { |
|---|
| 1882 | tb_cell = document.createElement("td"); |
|---|
| 1883 | tb_cell.className = 'toolbarElement'; |
|---|
| 1884 | tb_row.appendChild(tb_cell); |
|---|
| 1885 | tb_cell.appendChild(tb_element); |
|---|
| 1886 | } |
|---|
| 1887 | else if ( tb_element === null ) |
|---|
| 1888 | { |
|---|
| 1889 | alert("FIXME: Unknown toolbar item: " + code); |
|---|
| 1890 | } |
|---|
| 1891 | } |
|---|
| 1892 | } |
|---|
| 1893 | } |
|---|
| 1894 | |
|---|
| 1895 | if ( editor.config.flowToolbars ) |
|---|
| 1896 | { |
|---|
| 1897 | toolbar.appendChild(Xinha._createToolbarBreakingElement()); |
|---|
| 1898 | } |
|---|
| 1899 | |
|---|
| 1900 | return toolbar; |
|---|
| 1901 | }; |
|---|
| 1902 | |
|---|
| 1903 | |
|---|
| 1904 | |
|---|
| 1905 | var use_clone_img = false; |
|---|
| 1906 | |
|---|
| 1907 | |
|---|
| 1908 | |
|---|
| 1909 | |
|---|
| 1910 | Xinha.makeBtnImg = function(imgDef, doc) |
|---|
| 1911 | { |
|---|
| 1912 | if ( !doc ) |
|---|
| 1913 | { |
|---|
| 1914 | doc = document; |
|---|
| 1915 | } |
|---|
| 1916 | |
|---|
| 1917 | if ( !doc._xinhaImgCache ) |
|---|
| 1918 | { |
|---|
| 1919 | doc._xinhaImgCache = {}; |
|---|
| 1920 | Xinha.freeLater(doc._xinhaImgCache); |
|---|
| 1921 | } |
|---|
| 1922 | |
|---|
| 1923 | var i_contain = null; |
|---|
| 1924 | if ( Xinha.is_ie && ( ( !doc.compatMode ) || ( doc.compatMode && doc.compatMode == "BackCompat" ) ) ) |
|---|
| 1925 | { |
|---|
| 1926 | i_contain = doc.createElement('span'); |
|---|
| 1927 | } |
|---|
| 1928 | else |
|---|
| 1929 | { |
|---|
| 1930 | i_contain = doc.createElement('div'); |
|---|
| 1931 | i_contain.style.position = 'relative'; |
|---|
| 1932 | } |
|---|
| 1933 | |
|---|
| 1934 | i_contain.style.overflow = 'hidden'; |
|---|
| 1935 | i_contain.style.width = "18px"; |
|---|
| 1936 | i_contain.style.height = "18px"; |
|---|
| 1937 | i_contain.className = 'buttonImageContainer'; |
|---|
| 1938 | |
|---|
| 1939 | var img = null; |
|---|
| 1940 | if ( typeof imgDef == 'string' ) |
|---|
| 1941 | { |
|---|
| 1942 | if ( doc._xinhaImgCache[imgDef] ) |
|---|
| 1943 | { |
|---|
| 1944 | img = doc._xinhaImgCache[imgDef].cloneNode(); |
|---|
| 1945 | } |
|---|
| 1946 | else |
|---|
| 1947 | { |
|---|
| 1948 | img = doc.createElement("img"); |
|---|
| 1949 | img.src = imgDef; |
|---|
| 1950 | img.style.width = "18px"; |
|---|
| 1951 | img.style.height = "18px"; |
|---|
| 1952 | if ( use_clone_img ) |
|---|
| 1953 | { |
|---|
| 1954 | doc._xinhaImgCache[imgDef] = img.cloneNode(); |
|---|
| 1955 | } |
|---|
| 1956 | } |
|---|
| 1957 | } |
|---|
| 1958 | else |
|---|
| 1959 | { |
|---|
| 1960 | if ( doc._xinhaImgCache[imgDef[0]] ) |
|---|
| 1961 | { |
|---|
| 1962 | img = doc._xinhaImgCache[imgDef[0]].cloneNode(); |
|---|
| 1963 | } |
|---|
| 1964 | else |
|---|
| 1965 | { |
|---|
| 1966 | img = doc.createElement("img"); |
|---|
| 1967 | img.src = imgDef[0]; |
|---|
| 1968 | img.style.position = 'relative'; |
|---|
| 1969 | if ( use_clone_img ) |
|---|
| 1970 | { |
|---|
| 1971 | doc._xinhaImgCache[imgDef[0]] = img.cloneNode(); |
|---|
| 1972 | } |
|---|
| 1973 | } |
|---|
| 1974 | |
|---|
| 1975 | |
|---|
| 1976 | |
|---|
| 1977 | img.style.top = imgDef[2] ? ('-' + (18 * (imgDef[2] + 1)) + 'px') : '-18px'; |
|---|
| 1978 | img.style.left = imgDef[1] ? ('-' + (18 * (imgDef[1] + 1)) + 'px') : '-18px'; |
|---|
| 1979 | } |
|---|
| 1980 | i_contain.appendChild(img); |
|---|
| 1981 | return i_contain; |
|---|
| 1982 | }; |
|---|
| 1983 | |
|---|
| 1984 | |
|---|
| 1985 | |
|---|
| 1986 | |
|---|
| 1987 | Xinha.prototype._createStatusBar = function() |
|---|
| 1988 | { |
|---|
| 1989 | this.setLoadingMessage(Xinha._lc('Create Statusbar')); |
|---|
| 1990 | var statusbar = document.createElement("div"); |
|---|
| 1991 | statusbar.className = "statusBar"; |
|---|
| 1992 | this._statusBar = statusbar; |
|---|
| 1993 | Xinha.freeLater(this, '_statusBar'); |
|---|
| 1994 | |
|---|
| 1995 | |
|---|
| 1996 | |
|---|
| 1997 | var div = document.createElement("span"); |
|---|
| 1998 | div.className = "statusBarTree"; |
|---|
| 1999 | div.innerHTML = Xinha._lc("Path") + ": "; |
|---|
| 2000 | |
|---|
| 2001 | this._statusBarTree = div; |
|---|
| 2002 | Xinha.freeLater(this, '_statusBarTree'); |
|---|
| 2003 | this._statusBar.appendChild(div); |
|---|
| 2004 | |
|---|
| 2005 | div = document.createElement("span"); |
|---|
| 2006 | div.innerHTML = Xinha._lc("You are in TEXT MODE. Use the [<>] button to switch back to WYSIWYG."); |
|---|
| 2007 | div.style.display = "none"; |
|---|
| 2008 | |
|---|
| 2009 | this._statusBarTextMode = div; |
|---|
| 2010 | Xinha.freeLater(this, '_statusBarTextMode'); |
|---|
| 2011 | this._statusBar.appendChild(div); |
|---|
| 2012 | |
|---|
| 2013 | if ( !this.config.statusBar ) |
|---|
| 2014 | { |
|---|
| 2015 | |
|---|
| 2016 | statusbar.style.display = "none"; |
|---|
| 2017 | } |
|---|
| 2018 | return statusbar; |
|---|
| 2019 | }; |
|---|
| 2020 | |
|---|
| 2021 | |
|---|
| 2022 | |
|---|
| 2023 | |
|---|
| 2024 | Xinha.prototype.generate = function () |
|---|
| 2025 | { |
|---|
| 2026 | if ( !Xinha.isSupportedBrowser ) return; |
|---|
| 2027 | |
|---|
| 2028 | var i; |
|---|
| 2029 | var editor = this; |
|---|
| 2030 | var url; |
|---|
| 2031 | var found = false; |
|---|
| 2032 | var links = document.getElementsByTagName("link"); |
|---|
| 2033 | |
|---|
| 2034 | if (!document.getElementById("XinhaCoreDesign")) |
|---|
| 2035 | { |
|---|
| 2036 | _editor_css = (typeof _editor_css == "string") ? _editor_css : "Xinha.css"; |
|---|
| 2037 | for(i = 0; i<links.length; i++) |
|---|
| 2038 | { |
|---|
| 2039 | if ( ( links[i].rel == "stylesheet" ) && ( links[i].href == _editor_url + _editor_css ) ) |
|---|
| 2040 | { |
|---|
| 2041 | found = true; |
|---|
| 2042 | } |
|---|
| 2043 | } |
|---|
| 2044 | if ( !found ) |
|---|
| 2045 | { |
|---|
| 2046 | Xinha.loadStyle(_editor_css,null,"XinhaCoreDesign",true); |
|---|
| 2047 | } |
|---|
| 2048 | } |
|---|
| 2049 | |
|---|
| 2050 | if ( _editor_skin !== "" && !document.getElementById("XinhaSkin")) |
|---|
| 2051 | { |
|---|
| 2052 | found = false; |
|---|
| 2053 | for(i = 0; i<links.length; i++) |
|---|
| 2054 | { |
|---|
| 2055 | if ( ( links[i].rel == "stylesheet" ) && ( links[i].href == _editor_url + 'skins/' + _editor_skin + '/skin.css' ) ) |
|---|
| 2056 | { |
|---|
| 2057 | found = true; |
|---|
| 2058 | } |
|---|
| 2059 | } |
|---|
| 2060 | if ( !found ) |
|---|
| 2061 | { |
|---|
| 2062 | Xinha.loadStyle('skins/' + _editor_skin + '/skin.css',null,"XinhaSkin") |
|---|
| 2063 | } |
|---|
| 2064 | } |
|---|
| 2065 | |
|---|
| 2066 | |
|---|
| 2067 | if (Xinha.is_ie) |
|---|
| 2068 | { |
|---|
| 2069 | url = _editor_url + 'modules/InternetExplorer/InternetExplorer.js'; |
|---|
| 2070 | if ( !Xinha.loadPlugins([{plugin:"InternetExplorer",url:url}], function() { editor.generate(); } ) ) |
|---|
| 2071 | { |
|---|
| 2072 | return false; |
|---|
| 2073 | } |
|---|
| 2074 | editor._browserSpecificPlugin = editor.registerPlugin('InternetExplorer'); |
|---|
| 2075 | } |
|---|
| 2076 | else if (Xinha.is_webkit) |
|---|
| 2077 | { |
|---|
| 2078 | url = _editor_url + 'modules/WebKit/WebKit.js'; |
|---|
| 2079 | if ( !Xinha.loadPlugins([{plugin:"WebKit",url:url}], function() { editor.generate(); } ) ) |
|---|
| 2080 | { |
|---|
| 2081 | |
|---|
| 2082 | return false; |
|---|
| 2083 | } |
|---|
| 2084 | editor._browserSpecificPlugin = editor.registerPlugin('WebKit'); |
|---|
| 2085 | } |
|---|
| 2086 | else if (Xinha.is_opera) |
|---|
| 2087 | { |
|---|
| 2088 | url = _editor_url + 'modules/Opera/Opera.js'; |
|---|
| 2089 | if ( !Xinha.loadPlugins([{plugin:"Opera",url:url}], function() { editor.generate(); } ) ) |
|---|
| 2090 | { |
|---|
| 2091 | return false; |
|---|
| 2092 | } |
|---|
| 2093 | editor._browserSpecificPlugin = editor.registerPlugin('Opera'); |
|---|
| 2094 | } |
|---|
| 2095 | else if (Xinha.is_gecko) |
|---|
| 2096 | { |
|---|
| 2097 | url = _editor_url + 'modules/Gecko/Gecko.js'; |
|---|
| 2098 | if ( !Xinha.loadPlugins([{plugin:"Gecko",url:url}], function() { editor.generate(); } ) ) |
|---|
| 2099 | { |
|---|
| 2100 | return false; |
|---|
| 2101 | } |
|---|
| 2102 | editor._browserSpecificPlugin = editor.registerPlugin('Gecko'); |
|---|
| 2103 | } |
|---|
| 2104 | |
|---|
| 2105 | if ( typeof Dialog == 'undefined' && !Xinha._loadback( _editor_url + 'modules/Dialogs/dialog.js', this.generate, this ) ) |
|---|
| 2106 | { |
|---|
| 2107 | return false; |
|---|
| 2108 | } |
|---|
| 2109 | |
|---|
| 2110 | if ( typeof Xinha.Dialog == 'undefined' && !Xinha._loadback( _editor_url + 'modules/Dialogs/XinhaDialog.js' , this.generate, this ) ) |
|---|
| 2111 | { |
|---|
| 2112 | return false; |
|---|
| 2113 | } |
|---|
| 2114 | |
|---|
| 2115 | url = _editor_url + 'modules/FullScreen/full-screen.js'; |
|---|
| 2116 | if ( !Xinha.loadPlugins([{plugin:"FullScreen",url:url}], function() { editor.generate(); } )) |
|---|
| 2117 | { |
|---|
| 2118 | return false; |
|---|
| 2119 | } |
|---|
| 2120 | |
|---|
| 2121 | url = _editor_url + 'modules/ColorPicker/ColorPicker.js'; |
|---|
| 2122 | if ( !Xinha.loadPlugins([{plugin:"ColorPicker",url:url}], function() { editor.generate(); } ) ) |
|---|
| 2123 | { |
|---|
| 2124 | return false; |
|---|
| 2125 | } |
|---|
| 2126 | else if ( typeof ColorPicker != 'undefined') editor.registerPlugin('ColorPicker'); |
|---|
| 2127 | |
|---|
| 2128 | var toolbar = editor.config.toolbar; |
|---|
| 2129 | for ( i = toolbar.length; --i >= 0; ) |
|---|
| 2130 | { |
|---|
| 2131 | for ( var j = toolbar[i].length; --j >= 0; ) |
|---|
| 2132 | { |
|---|
| 2133 | switch (toolbar[i][j]) |
|---|
| 2134 | { |
|---|
| 2135 | case "popupeditor": |
|---|
| 2136 | editor.registerPlugin('FullScreen'); |
|---|
| 2137 | break; |
|---|
| 2138 | case "insertimage": |
|---|
| 2139 | url = _editor_url + 'modules/InsertImage/insert_image.js'; |
|---|
| 2140 | if ( typeof Xinha.prototype._insertImage == 'undefined' && !Xinha.loadPlugins([{plugin:"InsertImage",url:url}], function() { editor.generate(); } ) ) |
|---|
| 2141 | { |
|---|
| 2142 | return false; |
|---|
| 2143 | } |
|---|
| 2144 | else if ( typeof InsertImage != 'undefined') editor.registerPlugin('InsertImage'); |
|---|
| 2145 | break; |
|---|
| 2146 | case "createlink": |
|---|
| 2147 | url = _editor_url + 'modules/CreateLink/link.js'; |
|---|
| 2148 | if ( typeof Linker == 'undefined' && !Xinha.loadPlugins([{plugin:"CreateLink",url:url}], function() { editor.generate(); } )) |
|---|
| 2149 | { |
|---|
| 2150 | return false; |
|---|
| 2151 | } |
|---|
| 2152 | else if ( typeof CreateLink != 'undefined') editor.registerPlugin('CreateLink'); |
|---|
| 2153 | break; |
|---|
| 2154 | case "inserttable": |
|---|
| 2155 | url = _editor_url + 'modules/InsertTable/insert_table.js'; |
|---|
| 2156 | if ( !Xinha.loadPlugins([{plugin:"InsertTable",url:url}], function() { editor.generate(); } ) ) |
|---|
| 2157 | { |
|---|
| 2158 | return false; |
|---|
| 2159 | } |
|---|
| 2160 | else if ( typeof InsertTable != 'undefined') editor.registerPlugin('InsertTable'); |
|---|
| 2161 | break; |
|---|
| 2162 | } |
|---|
| 2163 | } |
|---|
| 2164 | } |
|---|
| 2165 | |
|---|
| 2166 | |
|---|
| 2167 | if ( Xinha.is_gecko && editor.config.mozParaHandler != 'built-in' ) |
|---|
| 2168 | { |
|---|
| 2169 | if ( !Xinha.loadPlugins([{plugin:"EnterParagraphs",url: _editor_url + 'modules/Gecko/paraHandlerBest.js'}], function() { editor.generate(); } ) ) |
|---|
| 2170 | { |
|---|
| 2171 | return false; |
|---|
| 2172 | } |
|---|
| 2173 | editor.registerPlugin('EnterParagraphs'); |
|---|
| 2174 | } |
|---|
| 2175 | |
|---|
| 2176 | if (Xinha.ie_version == 8) |
|---|
| 2177 | { |
|---|
| 2178 | this.config.getHtmlMethod = 'TransformInnerHTML'; |
|---|
| 2179 | } |
|---|
| 2180 | |
|---|
| 2181 | switch (this.config.getHtmlMethod) |
|---|
| 2182 | { |
|---|
| 2183 | case 'TransformInnerHTML': |
|---|
| 2184 | var getHtmlMethodPlugin = _editor_url + 'modules/GetHtml/TransformInnerHTML.js'; |
|---|
| 2185 | break; |
|---|
| 2186 | default: |
|---|
| 2187 | var getHtmlMethodPlugin = _editor_url + 'modules/GetHtml/DOMwalk.js'; |
|---|
| 2188 | break; |
|---|
| 2189 | } |
|---|
| 2190 | |
|---|
| 2191 | if ( !Xinha.loadPlugins([{plugin:"GetHtmlImplementation",url:getHtmlMethodPlugin}], function() { editor.generate(); })) |
|---|
| 2192 | { |
|---|
| 2193 | return false; |
|---|
| 2194 | } |
|---|
| 2195 | else editor.registerPlugin('GetHtmlImplementation'); |
|---|
| 2196 | |
|---|
| 2197 | |
|---|
| 2198 | |
|---|
| 2199 | |
|---|
| 2200 | this.setLoadingMessage(Xinha._lc('Generate Xinha framework')); |
|---|
| 2201 | |
|---|
| 2202 | this._framework = |
|---|
| 2203 | { |
|---|
| 2204 | 'table': document.createElement('table'), |
|---|
| 2205 | 'tbody': document.createElement('tbody'), |
|---|
| 2206 | 'tb_row': document.createElement('tr'), |
|---|
| 2207 | 'tb_cell': document.createElement('td'), |
|---|
| 2208 | |
|---|
| 2209 | 'tp_row': document.createElement('tr'), |
|---|
| 2210 | 'tp_cell': this._panels.top.container, |
|---|
| 2211 | |
|---|
| 2212 | 'ler_row': document.createElement('tr'), |
|---|
| 2213 | 'lp_cell': this._panels.left.container, |
|---|
| 2214 | 'ed_cell': document.createElement('td'), |
|---|
| 2215 | 'rp_cell': this._panels.right.container, |
|---|
| 2216 | |
|---|
| 2217 | 'bp_row': document.createElement('tr'), |
|---|
| 2218 | 'bp_cell': this._panels.bottom.container, |
|---|
| 2219 | |
|---|
| 2220 | 'sb_row': document.createElement('tr'), |
|---|
| 2221 | 'sb_cell': document.createElement('td') |
|---|
| 2222 | |
|---|
| 2223 | }; |
|---|
| 2224 | Xinha.freeLater(this._framework); |
|---|
| 2225 | |
|---|
| 2226 | var fw = this._framework; |
|---|
| 2227 | fw.table.border = "0"; |
|---|
| 2228 | fw.table.cellPadding = "0"; |
|---|
| 2229 | fw.table.cellSpacing = "0"; |
|---|
| 2230 | |
|---|
| 2231 | fw.tb_row.style.verticalAlign = 'top'; |
|---|
| 2232 | fw.tp_row.style.verticalAlign = 'top'; |
|---|
| 2233 | fw.ler_row.style.verticalAlign= 'top'; |
|---|
| 2234 | fw.bp_row.style.verticalAlign = 'top'; |
|---|
| 2235 | fw.sb_row.style.verticalAlign = 'top'; |
|---|
| 2236 | fw.ed_cell.style.position = 'relative'; |
|---|
| 2237 | |
|---|
| 2238 | |
|---|
| 2239 | |
|---|
| 2240 | |
|---|
| 2241 | |
|---|
| 2242 | |
|---|
| 2243 | fw.tb_row.appendChild(fw.tb_cell); |
|---|
| 2244 | fw.tb_cell.colSpan = 3; |
|---|
| 2245 | |
|---|
| 2246 | fw.tp_row.appendChild(fw.tp_cell); |
|---|
| 2247 | fw.tp_cell.colSpan = 3; |
|---|
| 2248 | |
|---|
| 2249 | fw.ler_row.appendChild(fw.lp_cell); |
|---|
| 2250 | fw.ler_row.appendChild(fw.ed_cell); |
|---|
| 2251 | fw.ler_row.appendChild(fw.rp_cell); |
|---|
| 2252 | |
|---|
| 2253 | fw.bp_row.appendChild(fw.bp_cell); |
|---|
| 2254 | fw.bp_cell.colSpan = 3; |
|---|
| 2255 | |
|---|
| 2256 | fw.sb_row.appendChild(fw.sb_cell); |
|---|
| 2257 | fw.sb_cell.colSpan = 3; |
|---|
| 2258 | |
|---|
| 2259 | |
|---|
| 2260 | fw.tbody.appendChild(fw.tb_row); |
|---|
| 2261 | fw.tbody.appendChild(fw.tp_row); |
|---|
| 2262 | fw.tbody.appendChild(fw.ler_row); |
|---|
| 2263 | fw.tbody.appendChild(fw.bp_row); |
|---|
| 2264 | fw.tbody.appendChild(fw.sb_row); |
|---|
| 2265 | |
|---|
| 2266 | |
|---|
| 2267 | fw.table.appendChild(fw.tbody); |
|---|
| 2268 | |
|---|
| 2269 | var xinha = fw.table; |
|---|
| 2270 | this._htmlArea = xinha; |
|---|
| 2271 | Xinha.freeLater(this, '_htmlArea'); |
|---|
| 2272 | xinha.className = "htmlarea"; |
|---|
| 2273 | |
|---|
| 2274 | |
|---|
| 2275 | fw.tb_cell.appendChild( this._createToolbar() ); |
|---|
| 2276 | |
|---|
| 2277 | |
|---|
| 2278 | var iframe = document.createElement("iframe"); |
|---|
| 2279 | iframe.src = this.popupURL(editor.config.URIs.blank); |
|---|
| 2280 | iframe.id = "XinhaIFrame_" + this._textArea.id; |
|---|
| 2281 | fw.ed_cell.appendChild(iframe); |
|---|
| 2282 | this._iframe = iframe; |
|---|
| 2283 | this._iframe.className = 'xinha_iframe'; |
|---|
| 2284 | Xinha.freeLater(this, '_iframe'); |
|---|
| 2285 | |
|---|
| 2286 | |
|---|
| 2287 | var statusbar = this._createStatusBar(); |
|---|
| 2288 | fw.sb_cell.appendChild(statusbar); |
|---|
| 2289 | |
|---|
| 2290 | |
|---|
| 2291 | var textarea = this._textArea; |
|---|
| 2292 | textarea.parentNode.insertBefore(xinha, textarea); |
|---|
| 2293 | textarea.className = 'xinha_textarea'; |
|---|
| 2294 | |
|---|
| 2295 | |
|---|
| 2296 | Xinha.removeFromParent(textarea); |
|---|
| 2297 | fw.ed_cell.appendChild(textarea); |
|---|
| 2298 | |
|---|
| 2299 | |
|---|
| 2300 | Xinha.addDom0Event( |
|---|
| 2301 | this._textArea, |
|---|
| 2302 | 'click', |
|---|
| 2303 | function() |
|---|
| 2304 | { |
|---|
| 2305 | if ( Xinha._currentlyActiveEditor != this) |
|---|
| 2306 | { |
|---|
| 2307 | editor.updateToolbar(); |
|---|
| 2308 | } |
|---|
| 2309 | return true; |
|---|
| 2310 | }); |
|---|
| 2311 | |
|---|
| 2312 | |
|---|
| 2313 | if ( textarea.form ) |
|---|
| 2314 | { |
|---|
| 2315 | |
|---|
| 2316 | Xinha.prependDom0Event( |
|---|
| 2317 | this._textArea.form, |
|---|
| 2318 | 'submit', |
|---|
| 2319 | function() |
|---|
| 2320 | { |
|---|
| 2321 | editor.firePluginEvent('onBeforeSubmit'); |
|---|
| 2322 | editor._textArea.value = editor.outwardHtml(editor.getHTML()); |
|---|
| 2323 | return true; |
|---|
| 2324 | } |
|---|
| 2325 | ); |
|---|
| 2326 | |
|---|
| 2327 | var initialTAContent = textarea.value; |
|---|
| 2328 | |
|---|
| 2329 | |
|---|
| 2330 | Xinha.prependDom0Event( |
|---|
| 2331 | this._textArea.form, |
|---|
| 2332 | 'reset', |
|---|
| 2333 | function() |
|---|
| 2334 | { |
|---|
| 2335 | editor.setHTML(editor.inwardHtml(initialTAContent)); |
|---|
| 2336 | editor.updateToolbar(); |
|---|
| 2337 | return true; |
|---|
| 2338 | } |
|---|
| 2339 | ); |
|---|
| 2340 | |
|---|
| 2341 | |
|---|
| 2342 | |
|---|
| 2343 | if ( !textarea.form.xinha_submit ) |
|---|
| 2344 | { |
|---|
| 2345 | try |
|---|
| 2346 | { |
|---|
| 2347 | textarea.form.xinha_submit = textarea.form.submit; |
|---|
| 2348 | textarea.form.submit = function() |
|---|
| 2349 | { |
|---|
| 2350 | this.onsubmit(); |
|---|
| 2351 | this.xinha_submit(); |
|---|
| 2352 | } |
|---|
| 2353 | } catch(ex) {} |
|---|
| 2354 | } |
|---|
| 2355 | } |
|---|
| 2356 | |
|---|
| 2357 | |
|---|
| 2358 | |
|---|
| 2359 | |
|---|
| 2360 | Xinha.prependDom0Event( |
|---|
| 2361 | window, |
|---|
| 2362 | 'unload', |
|---|
| 2363 | function() |
|---|
| 2364 | { |
|---|
| 2365 | editor.firePluginEvent('onBeforeUnload'); |
|---|
| 2366 | textarea.value = editor.outwardHtml(editor.getHTML()); |
|---|
| 2367 | if (!Xinha.is_ie) |
|---|
| 2368 | { |
|---|
| 2369 | xinha.parentNode.replaceChild(textarea,xinha); |
|---|
| 2370 | } |
|---|
| 2371 | return true; |
|---|
| 2372 | } |
|---|
| 2373 | ); |
|---|
| 2374 | |
|---|
| 2375 | |
|---|
| 2376 | textarea.style.display = "none"; |
|---|
| 2377 | |
|---|
| 2378 | |
|---|
| 2379 | editor.initSize(); |
|---|
| 2380 | this.setLoadingMessage(Xinha._lc('Finishing')); |
|---|
| 2381 | |
|---|
| 2382 | editor._iframeLoadDone = false; |
|---|
| 2383 | if (Xinha.is_opera) |
|---|
| 2384 | { |
|---|
| 2385 | editor.initIframe(); |
|---|
| 2386 | } |
|---|
| 2387 | else |
|---|
| 2388 | Xinha._addEvent( |
|---|
| 2389 | this._iframe, |
|---|
| 2390 | 'load', |
|---|
| 2391 | function(e) |
|---|
| 2392 | { |
|---|
| 2393 | if ( !editor._iframeLoadDone ) |
|---|
| 2394 | { |
|---|
| 2395 | editor._iframeLoadDone = true; |
|---|
| 2396 | editor.initIframe(); |
|---|
| 2397 | } |
|---|
| 2398 | return true; |
|---|
| 2399 | } |
|---|
| 2400 | ); |
|---|
| 2401 | |
|---|
| 2402 | }; |
|---|
| 2403 | |
|---|
| 2404 | |
|---|
| 2405 | |
|---|
| 2406 | |
|---|
| 2407 | |
|---|
| 2408 | |
|---|
| 2409 | |
|---|
| 2410 | |
|---|
| 2411 | |
|---|
| 2412 | |
|---|
| 2413 | |
|---|
| 2414 | |
|---|
| 2415 | |
|---|
| 2416 | |
|---|
| 2417 | |
|---|
| 2418 | |
|---|
| 2419 | |
|---|
| 2420 | |
|---|
| 2421 | |
|---|
| 2422 | |
|---|
| 2423 | Xinha.prototype.initSize = function() |
|---|
| 2424 | { |
|---|
| 2425 | this.setLoadingMessage(Xinha._lc('Init editor size')); |
|---|
| 2426 | var editor = this; |
|---|
| 2427 | var width = null; |
|---|
| 2428 | var height = null; |
|---|
| 2429 | |
|---|
| 2430 | switch ( this.config.width ) |
|---|
| 2431 | { |
|---|
| 2432 | case 'auto': |
|---|
| 2433 | width = this._initial_ta_size.w; |
|---|
| 2434 | break; |
|---|
| 2435 | |
|---|
| 2436 | case 'toolbar': |
|---|
| 2437 | width = this._toolBar.offsetWidth + 'px'; |
|---|
| 2438 | break; |
|---|
| 2439 | |
|---|
| 2440 | default : |
|---|
| 2441 | |
|---|
| 2442 | |
|---|
| 2443 | width = /[^0-9]/.test(this.config.width) ? this.config.width : this.config.width + 'px'; |
|---|
| 2444 | break; |
|---|
| 2445 | } |
|---|
| 2446 | |
|---|
| 2447 | switch ( this.config.height ) |
|---|
| 2448 | { |
|---|
| 2449 | case 'auto': |
|---|
| 2450 | height = this._initial_ta_size.h; |
|---|
| 2451 | break; |
|---|
| 2452 | |
|---|
| 2453 | default : |
|---|
| 2454 | |
|---|
| 2455 | |
|---|
| 2456 | height = /[^0-9]/.test(this.config.height) ? this.config.height : this.config.height + 'px'; |
|---|
| 2457 | break; |
|---|
| 2458 | } |
|---|
| 2459 | |
|---|
| 2460 | this.sizeEditor(width, height, this.config.sizeIncludesBars, this.config.sizeIncludesPanels); |
|---|
| 2461 | |
|---|
| 2462 | |
|---|
| 2463 | |
|---|
| 2464 | this.notifyOn('panel_change',function() { editor.sizeEditor(); }); |
|---|
| 2465 | }; |
|---|
| 2466 | |
|---|
| 2467 | |
|---|
| 2468 | |
|---|
| 2469 | |
|---|
| 2470 | |
|---|
| 2471 | |
|---|
| 2472 | |
|---|
| 2473 | |
|---|
| 2474 | Xinha.prototype.sizeEditor = function(width, height, includingBars, includingPanels) |
|---|
| 2475 | { |
|---|
| 2476 | if (this._risizing) return; |
|---|
| 2477 | this._risizing = true; |
|---|
| 2478 | |
|---|
| 2479 | var framework = this._framework; |
|---|
| 2480 | |
|---|
| 2481 | this.notifyOf('before_resize', {width:width, height:height}); |
|---|
| 2482 | this.firePluginEvent('onBeforeResize', width, height); |
|---|
| 2483 | |
|---|
| 2484 | |
|---|
| 2485 | this._iframe.style.height = '100%'; |
|---|
| 2486 | this._textArea.style.height = '100%'; |
|---|
| 2487 | this._iframe.style.width = ''; |
|---|
| 2488 | this._textArea.style.width = ''; |
|---|
| 2489 | |
|---|
| 2490 | if ( includingBars !== null ) |
|---|
| 2491 | { |
|---|
| 2492 | this._htmlArea.sizeIncludesToolbars = includingBars; |
|---|
| 2493 | } |
|---|
| 2494 | if ( includingPanels !== null ) |
|---|
| 2495 | { |
|---|
| 2496 | this._htmlArea.sizeIncludesPanels = includingPanels; |
|---|
| 2497 | } |
|---|
| 2498 | |
|---|
| 2499 | if ( width ) |
|---|
| 2500 | { |
|---|
| 2501 | this._htmlArea.style.width = width; |
|---|
| 2502 | if ( !this._htmlArea.sizeIncludesPanels ) |
|---|
| 2503 | { |
|---|
| 2504 | |
|---|
| 2505 | var rPanel = this._panels.right; |
|---|
| 2506 | if ( rPanel.on && rPanel.panels.length && Xinha.hasDisplayedChildren(rPanel.div) ) |
|---|
| 2507 | { |
|---|
| 2508 | this._htmlArea.style.width = (this._htmlArea.offsetWidth + parseInt(this.config.panel_dimensions.right, 10)) + 'px'; |
|---|
| 2509 | } |
|---|
| 2510 | |
|---|
| 2511 | var lPanel = this._panels.left; |
|---|
| 2512 | if ( lPanel.on && lPanel.panels.length && Xinha.hasDisplayedChildren(lPanel.div) ) |
|---|
| 2513 | { |
|---|
| 2514 | this._htmlArea.style.width = (this._htmlArea.offsetWidth + parseInt(this.config.panel_dimensions.left, 10)) + 'px'; |
|---|
| 2515 | } |
|---|
| 2516 | } |
|---|
| 2517 | } |
|---|
| 2518 | |
|---|
| 2519 | if ( height ) |
|---|
| 2520 | { |
|---|
| 2521 | this._htmlArea.style.height = height; |
|---|
| 2522 | if ( !this._htmlArea.sizeIncludesToolbars ) |
|---|
| 2523 | { |
|---|
| 2524 | |
|---|
| 2525 | this._htmlArea.style.height = (this._htmlArea.offsetHeight + this._toolbar.offsetHeight + this._statusBar.offsetHeight) + 'px'; |
|---|
| 2526 | } |
|---|
| 2527 | |
|---|
| 2528 | if ( !this._htmlArea.sizeIncludesPanels ) |
|---|
| 2529 | { |
|---|
| 2530 | |
|---|
| 2531 | var tPanel = this._panels.top; |
|---|
| 2532 | if ( tPanel.on && tPanel.panels.length && Xinha.hasDisplayedChildren(tPanel.div) ) |
|---|
| 2533 | { |
|---|
| 2534 | this._htmlArea.style.height = (this._htmlArea.offsetHeight + parseInt(this.config.panel_dimensions.top, 10)) + 'px'; |
|---|
| 2535 | } |
|---|
| 2536 | |
|---|
| 2537 | var bPanel = this._panels.bottom; |
|---|
| 2538 | if ( bPanel.on && bPanel.panels.length && Xinha.hasDisplayedChildren(bPanel.div) ) |
|---|
| 2539 | { |
|---|
| 2540 | this._htmlArea.style.height = (this._htmlArea.offsetHeight + parseInt(this.config.panel_dimensions.bottom, 10)) + 'px'; |
|---|
| 2541 | } |
|---|
| 2542 | } |
|---|
| 2543 | } |
|---|
| 2544 | |
|---|
| 2545 | |
|---|
| 2546 | |
|---|
| 2547 | |
|---|
| 2548 | width = this._htmlArea.offsetWidth; |
|---|
| 2549 | height = this._htmlArea.offsetHeight; |
|---|
| 2550 | |
|---|
| 2551 | |
|---|
| 2552 | |
|---|
| 2553 | var panels = this._panels; |
|---|
| 2554 | var editor = this; |
|---|
| 2555 | var col_span = 1; |
|---|
| 2556 | |
|---|
| 2557 | function panel_is_alive(pan) |
|---|
| 2558 | { |
|---|
| 2559 | if ( panels[pan].on && panels[pan].panels.length && Xinha.hasDisplayedChildren(panels[pan].container) ) |
|---|
| 2560 | { |
|---|
| 2561 | panels[pan].container.style.display = ''; |
|---|
| 2562 | return true; |
|---|
| 2563 | } |
|---|
| 2564 | |
|---|
| 2565 | else |
|---|
| 2566 | { |
|---|
| 2567 | panels[pan].container.style.display='none'; |
|---|
| 2568 | return false; |
|---|
| 2569 | } |
|---|
| 2570 | } |
|---|
| 2571 | |
|---|
| 2572 | if ( panel_is_alive('left') ) |
|---|
| 2573 | { |
|---|
| 2574 | col_span += 1; |
|---|
| 2575 | } |
|---|
| 2576 | |
|---|
| 2577 | |
|---|
| 2578 | |
|---|
| 2579 | |
|---|
| 2580 | |
|---|
| 2581 | |
|---|
| 2582 | if ( panel_is_alive('right') ) |
|---|
| 2583 | { |
|---|
| 2584 | col_span += 1; |
|---|
| 2585 | } |
|---|
| 2586 | |
|---|
| 2587 | |
|---|
| 2588 | |
|---|
| 2589 | |
|---|
| 2590 | |
|---|
| 2591 | |
|---|
| 2592 | framework.tb_cell.colSpan = col_span; |
|---|
| 2593 | framework.tp_cell.colSpan = col_span; |
|---|
| 2594 | framework.bp_cell.colSpan = col_span; |
|---|
| 2595 | framework.sb_cell.colSpan = col_span; |
|---|
| 2596 | |
|---|
| 2597 | |
|---|
| 2598 | if ( !framework.tp_row.childNodes.length ) |
|---|
| 2599 | { |
|---|
| 2600 | Xinha.removeFromParent(framework.tp_row); |
|---|
| 2601 | } |
|---|
| 2602 | else |
|---|
| 2603 | { |
|---|
| 2604 | if ( !Xinha.hasParentNode(framework.tp_row) ) |
|---|
| 2605 | { |
|---|
| 2606 | framework.tbody.insertBefore(framework.tp_row, framework.ler_row); |
|---|
| 2607 | } |
|---|
| 2608 | } |
|---|
| 2609 | |
|---|
| 2610 | |
|---|
| 2611 | if ( !framework.bp_row.childNodes.length ) |
|---|
| 2612 | { |
|---|
| 2613 | Xinha.removeFromParent(framework.bp_row); |
|---|
| 2614 | } |
|---|
| 2615 | else |
|---|
| 2616 | { |
|---|
| 2617 | if ( !Xinha.hasParentNode(framework.bp_row) ) |
|---|
| 2618 | { |
|---|
| 2619 | framework.tbody.insertBefore(framework.bp_row, framework.ler_row.nextSibling); |
|---|
| 2620 | } |
|---|
| 2621 | } |
|---|
| 2622 | |
|---|
| 2623 | |
|---|
| 2624 | if ( !this.config.statusBar ) |
|---|
| 2625 | { |
|---|
| 2626 | Xinha.removeFromParent(framework.sb_row); |
|---|
| 2627 | } |
|---|
| 2628 | else |
|---|
| 2629 | { |
|---|
| 2630 | if ( !Xinha.hasParentNode(framework.sb_row) ) |
|---|
| 2631 | { |
|---|
| 2632 | framework.table.appendChild(framework.sb_row); |
|---|
| 2633 | } |
|---|
| 2634 | } |
|---|
| 2635 | |
|---|
| 2636 | |
|---|
| 2637 | framework.lp_cell.style.width = this.config.panel_dimensions.left; |
|---|
| 2638 | framework.rp_cell.style.width = this.config.panel_dimensions.right; |
|---|
| 2639 | framework.tp_cell.style.height = this.config.panel_dimensions.top; |
|---|
| 2640 | framework.bp_cell.style.height = this.config.panel_dimensions.bottom; |
|---|
| 2641 | framework.tb_cell.style.height = this._toolBar.offsetHeight + 'px'; |
|---|
| 2642 | framework.sb_cell.style.height = this._statusBar.offsetHeight + 'px'; |
|---|
| 2643 | |
|---|
| 2644 | var edcellheight = height - this._toolBar.offsetHeight - this._statusBar.offsetHeight; |
|---|
| 2645 | if ( panel_is_alive('top') ) |
|---|
| 2646 | { |
|---|
| 2647 | edcellheight -= parseInt(this.config.panel_dimensions.top, 10); |
|---|
| 2648 | } |
|---|
| 2649 | if ( panel_is_alive('bottom') ) |
|---|
| 2650 | { |
|---|
| 2651 | edcellheight -= parseInt(this.config.panel_dimensions.bottom, 10); |
|---|
| 2652 | } |
|---|
| 2653 | this._iframe.style.height = edcellheight + 'px'; |
|---|
| 2654 | |
|---|
| 2655 | var edcellwidth = width; |
|---|
| 2656 | if ( panel_is_alive('left') ) |
|---|
| 2657 | { |
|---|
| 2658 | edcellwidth -= parseInt(this.config.panel_dimensions.left, 10); |
|---|
| 2659 | } |
|---|
| 2660 | if ( panel_is_alive('right') ) |
|---|
| 2661 | { |
|---|
| 2662 | edcellwidth -= parseInt(this.config.panel_dimensions.right, 10); |
|---|
| 2663 | } |
|---|
| 2664 | var iframeWidth = (this.config.iframeWidth)? parseInt(this.config.iframeWidth,10): null; |
|---|
| 2665 | this._iframe.style.width = (iframeWidth && iframeWidth < edcellwidth)? iframeWidth + "px": edcellwidth + "px"; |
|---|
| 2666 | |
|---|
| 2667 | this._textArea.style.height = this._iframe.style.height; |
|---|
| 2668 | this._textArea.style.width = this._iframe.style.width; |
|---|
| 2669 | |
|---|
| 2670 | this.notifyOf('resize', {width:this._htmlArea.offsetWidth, height:this._htmlArea.offsetHeight}); |
|---|
| 2671 | this.firePluginEvent('onResize',this._htmlArea.offsetWidth, this._htmlArea.offsetWidth); |
|---|
| 2672 | this._risizing = false; |
|---|
| 2673 | }; |
|---|
| 2674 | |
|---|
| 2675 | |
|---|
| 2676 | |
|---|
| 2677 | |
|---|
| 2678 | Xinha.prototype.registerPanel = function(side, object) |
|---|
| 2679 | { |
|---|
| 2680 | if ( !side ) |
|---|
| 2681 | { |
|---|
| 2682 | side = 'right'; |
|---|
| 2683 | } |
|---|
| 2684 | this.setLoadingMessage('Register ' + side + ' panel '); |
|---|
| 2685 | var panel = this.addPanel(side); |
|---|
| 2686 | if ( object ) |
|---|
| 2687 | { |
|---|
| 2688 | object.drawPanelIn(panel); |
|---|
| 2689 | } |
|---|
| 2690 | }; |
|---|
| 2691 | |
|---|
| 2692 | |
|---|
| 2693 | |
|---|
| 2694 | |
|---|
| 2695 | |
|---|
| 2696 | Xinha.prototype.addPanel = function(side) |
|---|
| 2697 | { |
|---|
| 2698 | var div = document.createElement('div'); |
|---|
| 2699 | div.side = side; |
|---|
| 2700 | if ( side == 'left' || side == 'right' ) |
|---|
| 2701 | { |
|---|
| 2702 | div.style.width = this.config.panel_dimensions[side]; |
|---|
| 2703 | if(this._iframe) div.style.height = this._iframe.style.height; |
|---|
| 2704 | } |
|---|
| 2705 | Xinha.addClasses(div, 'panel'); |
|---|
| 2706 | this._panels[side].panels.push(div); |
|---|
| 2707 | this._panels[side].div.appendChild(div); |
|---|
| 2708 | |
|---|
| 2709 | this.notifyOf('panel_change', {'action':'add','panel':div}); |
|---|
| 2710 | this.firePluginEvent('onPanelChange','add',div); |
|---|
| 2711 | return div; |
|---|
| 2712 | }; |
|---|
| 2713 | |
|---|
| 2714 | |
|---|
| 2715 | |
|---|
| 2716 | Xinha.prototype.removePanel = function(panel) |
|---|
| 2717 | { |
|---|
| 2718 | this._panels[panel.side].div.removeChild(panel); |
|---|
| 2719 | var clean = []; |
|---|
| 2720 | for ( var i = 0; i < this._panels[panel.side].panels.length; i++ ) |
|---|
| 2721 | { |
|---|
| 2722 | if ( this._panels[panel.side].panels[i] != panel ) |
|---|
| 2723 | { |
|---|
| 2724 | clean.push(this._panels[panel.side].panels[i]); |
|---|
| 2725 | } |
|---|
| 2726 | } |
|---|
| 2727 | this._panels[panel.side].panels = clean; |
|---|
| 2728 | this.notifyOf('panel_change', {'action':'remove','panel':panel}); |
|---|
| 2729 | this.firePluginEvent('onPanelChange','remove',panel); |
|---|
| 2730 | }; |
|---|
| 2731 | |
|---|
| 2732 | |
|---|
| 2733 | |
|---|
| 2734 | Xinha.prototype.hidePanel = function(panel) |
|---|
| 2735 | { |
|---|
| 2736 | if ( panel && panel.style.display != 'none' ) |
|---|
| 2737 | { |
|---|
| 2738 | try { var pos = this.scrollPos(this._iframe.contentWindow); } catch(e) { } |
|---|
| 2739 | panel.style.display = 'none'; |
|---|
| 2740 | this.notifyOf('panel_change', {'action':'hide','panel':panel}); |
|---|
| 2741 | this.firePluginEvent('onPanelChange','hide',panel); |
|---|
| 2742 | try { this._iframe.contentWindow.scrollTo(pos.x,pos.y)} catch(e) { } |
|---|
| 2743 | } |
|---|
| 2744 | }; |
|---|
| 2745 | |
|---|
| 2746 | |
|---|
| 2747 | |
|---|
| 2748 | Xinha.prototype.showPanel = function(panel) |
|---|
| 2749 | { |
|---|
| 2750 | if ( panel && panel.style.display == 'none' ) |
|---|
| 2751 | { |
|---|
| 2752 | try { var pos = this.scrollPos(this._iframe.contentWindow); } catch(e) {} |
|---|
| 2753 | panel.style.display = ''; |
|---|
| 2754 | this.notifyOf('panel_change', {'action':'show','panel':panel}); |
|---|
| 2755 | this.firePluginEvent('onPanelChange','show',panel); |
|---|
| 2756 | try { this._iframe.contentWindow.scrollTo(pos.x,pos.y)} catch(e) { } |
|---|
| 2757 | } |
|---|
| 2758 | }; |
|---|
| 2759 | |
|---|
| 2760 | |
|---|
| 2761 | |
|---|
| 2762 | Xinha.prototype.hidePanels = function(sides) |
|---|
| 2763 | { |
|---|
| 2764 | if ( typeof sides == 'undefined' ) |
|---|
| 2765 | { |
|---|
| 2766 | sides = ['left','right','top','bottom']; |
|---|
| 2767 | } |
|---|
| 2768 | |
|---|
| 2769 | var reShow = []; |
|---|
| 2770 | for ( var i = 0; i < sides.length;i++ ) |
|---|
| 2771 | { |
|---|
| 2772 | if ( this._panels[sides[i]].on ) |
|---|
| 2773 | { |
|---|
| 2774 | reShow.push(sides[i]); |
|---|
| 2775 | this._panels[sides[i]].on = false; |
|---|
| 2776 | } |
|---|
| 2777 | } |
|---|
| 2778 | this.notifyOf('panel_change', {'action':'multi_hide','sides':sides}); |
|---|
| 2779 | this.firePluginEvent('onPanelChange','multi_hide',sides); |
|---|
| 2780 | }; |
|---|
| 2781 | |
|---|
| 2782 | |
|---|
| 2783 | |
|---|
| 2784 | Xinha.prototype.showPanels = function(sides) |
|---|
| 2785 | { |
|---|
| 2786 | if ( typeof sides == 'undefined' ) |
|---|
| 2787 | { |
|---|
| 2788 | sides = ['left','right','top','bottom']; |
|---|
| 2789 | } |
|---|
| 2790 | |
|---|
| 2791 | var reHide = []; |
|---|
| 2792 | for ( var i = 0; i < sides.length; i++ ) |
|---|
| 2793 | { |
|---|
| 2794 | if ( !this._panels[sides[i]].on ) |
|---|
| 2795 | { |
|---|
| 2796 | reHide.push(sides[i]); |
|---|
| 2797 | this._panels[sides[i]].on = true; |
|---|
| 2798 | } |
|---|
| 2799 | } |
|---|
| 2800 | this.notifyOf('panel_change', {'action':'multi_show','sides':sides}); |
|---|
| 2801 | this.firePluginEvent('onPanelChange','multi_show',sides); |
|---|
| 2802 | }; |
|---|
| 2803 | |
|---|
| 2804 | |
|---|
| 2805 | |
|---|
| 2806 | |
|---|
| 2807 | Xinha.objectProperties = function(obj) |
|---|
| 2808 | { |
|---|
| 2809 | var props = []; |
|---|
| 2810 | for ( var x in obj ) |
|---|
| 2811 | { |
|---|
| 2812 | props[props.length] = x; |
|---|
| 2813 | } |
|---|
| 2814 | return props; |
|---|
| 2815 | }; |
|---|
| 2816 | |
|---|
| 2817 | |
|---|
| 2818 | |
|---|
| 2819 | |
|---|
| 2820 | |
|---|
| 2821 | |
|---|
| 2822 | |
|---|
| 2823 | |
|---|
| 2824 | |
|---|
| 2825 | |
|---|
| 2826 | |
|---|
| 2827 | Xinha.prototype.editorIsActivated = function() |
|---|
| 2828 | { |
|---|
| 2829 | try |
|---|
| 2830 | { |
|---|
| 2831 | return Xinha.is_designMode ? this._doc.designMode == 'on' : this._doc.body.contentEditable; |
|---|
| 2832 | } |
|---|
| 2833 | catch (ex) |
|---|
| 2834 | { |
|---|
| 2835 | return false; |
|---|
| 2836 | } |
|---|
| 2837 | }; |
|---|
| 2838 | |
|---|
| 2839 | |
|---|
| 2840 | |
|---|
| 2841 | |
|---|
| 2842 | |
|---|
| 2843 | Xinha._someEditorHasBeenActivated = false; |
|---|
| 2844 | |
|---|
| 2845 | |
|---|
| 2846 | |
|---|
| 2847 | |
|---|
| 2848 | Xinha._currentlyActiveEditor = null; |
|---|
| 2849 | |
|---|
| 2850 | |
|---|
| 2851 | |
|---|
| 2852 | |
|---|
| 2853 | |
|---|
| 2854 | Xinha.prototype.activateEditor = function() |
|---|
| 2855 | { |
|---|
| 2856 | |
|---|
| 2857 | if ( Xinha._currentlyActiveEditor ) |
|---|
| 2858 | { |
|---|
| 2859 | if ( Xinha._currentlyActiveEditor == this ) |
|---|
| 2860 | { |
|---|
| 2861 | return true; |
|---|
| 2862 | } |
|---|
| 2863 | Xinha._currentlyActiveEditor.deactivateEditor(); |
|---|
| 2864 | } |
|---|
| 2865 | |
|---|
| 2866 | if ( Xinha.is_designMode && this._doc.designMode != 'on' ) |
|---|
| 2867 | { |
|---|
| 2868 | try |
|---|
| 2869 | { |
|---|
| 2870 | |
|---|
| 2871 | if ( this._iframe.style.display == 'none' ) |
|---|
| 2872 | { |
|---|
| 2873 | this._iframe.style.display = ''; |
|---|
| 2874 | this._doc.designMode = 'on'; |
|---|
| 2875 | this._iframe.style.display = 'none'; |
|---|
| 2876 | } |
|---|
| 2877 | else |
|---|
| 2878 | { |
|---|
| 2879 | this._doc.designMode = 'on'; |
|---|
| 2880 | } |
|---|
| 2881 | } catch (ex) {} |
|---|
| 2882 | } |
|---|
| 2883 | else if ( Xinha.is_ie&& this._doc.body.contentEditable !== true ) |
|---|
| 2884 | { |
|---|
| 2885 | this._doc.body.contentEditable = true; |
|---|
| 2886 | } |
|---|
| 2887 | |
|---|
| 2888 | Xinha._someEditorHasBeenActivated = true; |
|---|
| 2889 | Xinha._currentlyActiveEditor = this; |
|---|
| 2890 | |
|---|
| 2891 | var editor = this; |
|---|
| 2892 | this.enableToolbar(); |
|---|
| 2893 | }; |
|---|
| 2894 | |
|---|
| 2895 | |
|---|
| 2896 | |
|---|
| 2897 | Xinha.prototype.deactivateEditor = function() |
|---|
| 2898 | { |
|---|
| 2899 | |
|---|
| 2900 | this.disableToolbar(); |
|---|
| 2901 | |
|---|
| 2902 | if ( Xinha.is_designMode && this._doc.designMode != 'off' ) |
|---|
| 2903 | { |
|---|
| 2904 | try |
|---|
| 2905 | { |
|---|
| 2906 | this._doc.designMode = 'off'; |
|---|
| 2907 | } catch (ex) {} |
|---|
| 2908 | } |
|---|
| 2909 | else if ( !Xinha.is_designMode && this._doc.body.contentEditable !== false ) |
|---|
| 2910 | { |
|---|
| 2911 | this._doc.body.contentEditable = false; |
|---|
| 2912 | } |
|---|
| 2913 | |
|---|
| 2914 | if ( Xinha._currentlyActiveEditor != this ) |
|---|
| 2915 | { |
|---|
| 2916 | |
|---|
| 2917 | |
|---|
| 2918 | return; |
|---|
| 2919 | |
|---|
| 2920 | |
|---|
| 2921 | } |
|---|
| 2922 | |
|---|
| 2923 | Xinha._currentlyActiveEditor = false; |
|---|
| 2924 | }; |
|---|
| 2925 | |
|---|
| 2926 | |
|---|
| 2927 | |
|---|
| 2928 | Xinha.prototype.initIframe = function() |
|---|
| 2929 | { |
|---|
| 2930 | this.disableToolbar(); |
|---|
| 2931 | var doc = null; |
|---|
| 2932 | var editor = this; |
|---|
| 2933 | try |
|---|
| 2934 | { |
|---|
| 2935 | if ( editor._iframe.contentDocument ) |
|---|
| 2936 | { |
|---|
| 2937 | this._doc = editor._iframe.contentDocument; |
|---|
| 2938 | } |
|---|
| 2939 | else |
|---|
| 2940 | { |
|---|
| 2941 | this._doc = editor._iframe.contentWindow.document; |
|---|
| 2942 | } |
|---|
| 2943 | doc = this._doc; |
|---|
| 2944 | |
|---|
| 2945 | if ( !doc ) |
|---|
| 2946 | { |
|---|
| 2947 | if ( Xinha.is_gecko ) |
|---|
| 2948 | { |
|---|
| 2949 | setTimeout(function() { editor.initIframe(); }, 50); |
|---|
| 2950 | return false; |
|---|
| 2951 | } |
|---|
| 2952 | else |
|---|
| 2953 | { |
|---|
| 2954 | alert("ERROR: IFRAME can't be initialized."); |
|---|
| 2955 | } |
|---|
| 2956 | } |
|---|
| 2957 | } |
|---|
| 2958 | catch(ex) |
|---|
| 2959 | { |
|---|
| 2960 | setTimeout(function() { editor.initIframe(); }, 50); |
|---|
| 2961 | } |
|---|
| 2962 | |
|---|
| 2963 | Xinha.freeLater(this, '_doc'); |
|---|
| 2964 | |
|---|
| 2965 | doc.open("text/html","replace"); |
|---|
| 2966 | var html = ''; |
|---|
| 2967 | if ( editor.config.browserQuirksMode === false ) |
|---|
| 2968 | { |
|---|
| 2969 | var doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'; |
|---|
| 2970 | } |
|---|
| 2971 | else if ( editor.config.browserQuirksMode === true ) |
|---|
| 2972 | { |
|---|
| 2973 | var doctype = ''; |
|---|
| 2974 | } |
|---|
| 2975 | else |
|---|
| 2976 | { |
|---|
| 2977 | var doctype = Xinha.getDoctype(document); |
|---|
| 2978 | } |
|---|
| 2979 | if ( !editor.config.fullPage ) |
|---|
| 2980 | { |
|---|
| 2981 | html += doctype + "\n"; |
|---|
| 2982 | html += "<html>\n"; |
|---|
| 2983 | html += "<head>\n"; |
|---|
| 2984 | html += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + editor.config.charSet + "\">\n"; |
|---|
| 2985 | if ( typeof editor.config.baseHref != 'undefined' && editor.config.baseHref !== null ) |
|---|
| 2986 | { |
|---|
| 2987 | html += "<base href=\"" + editor.config.baseHref + "\"/>\n"; |
|---|
| 2988 | } |
|---|
| 2989 | |
|---|
| 2990 | html += Xinha.addCoreCSS(); |
|---|
| 2991 | |
|---|
| 2992 | if ( typeof editor.config.pageStyleSheets !== 'undefined' ) |
|---|
| 2993 | { |
|---|
| 2994 | for ( var i = 0; i < editor.config.pageStyleSheets.length; i++ ) |
|---|
| 2995 | { |
|---|
| 2996 | if ( editor.config.pageStyleSheets[i].length > 0 ) |
|---|
| 2997 | { |
|---|
| 2998 | html += "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + editor.config.pageStyleSheets[i] + "\">"; |
|---|
| 2999 | |
|---|
| 3000 | } |
|---|
| 3001 | } |
|---|
| 3002 | } |
|---|
| 3003 | |
|---|
| 3004 | if ( editor.config.pageStyle ) |
|---|
| 3005 | { |
|---|
| 3006 | html += "<style type=\"text/css\">\n" + editor.config.pageStyle + "\n</style>"; |
|---|
| 3007 | } |
|---|
| 3008 | |
|---|
| 3009 | html += "</head>\n"; |
|---|
| 3010 | html += "<body" + (editor.config.bodyID ? (" id=\"" + editor.config.bodyID + "\"") : '') + ">\n"; |
|---|
| 3011 | html += editor.inwardHtml(editor._textArea.value); |
|---|
| 3012 | html += "</body>\n"; |
|---|
| 3013 | html += "</html>"; |
|---|
| 3014 | } |
|---|
| 3015 | else |
|---|
| 3016 | { |
|---|
| 3017 | html = editor.inwardHtml(editor._textArea.value); |
|---|
| 3018 | if ( html.match(Xinha.RE_doctype) ) |
|---|
| 3019 | { |
|---|
| 3020 | editor.setDoctype(RegExp.$1); |
|---|
| 3021 | |
|---|
| 3022 | } |
|---|
| 3023 | |
|---|
| 3024 | |
|---|
| 3025 | var match = html.match(/<link\s+[\s\S]*?["']\s*\/?>/gi); |
|---|
| 3026 | html = html.replace(/<link\s+[\s\S]*?["']\s*\/?>\s*/gi, ''); |
|---|
| 3027 | match ? html = html.replace(/<\/head>/i, match.join('\n') + "\n</head>") : null; |
|---|
| 3028 | } |
|---|
| 3029 | doc.write(html); |
|---|
| 3030 | doc.close(); |
|---|
| 3031 | if ( this.config.fullScreen ) |
|---|
| 3032 | { |
|---|
| 3033 | this._fullScreen(); |
|---|
| 3034 | } |
|---|
| 3035 | this.setEditorEvents(); |
|---|
| 3036 | }; |
|---|
| 3037 | |
|---|
| 3038 | /** |
|---|
| 3039 | * Delay a function until the document is ready for operations. |
|---|
| 3040 | * See ticket:547 |
|---|
| 3041 | * @public |
|---|
| 3042 | * @param {Function} f The function to call once the document is ready |
|---|
| 3043 | */ |
|---|
| 3044 | Xinha.prototype.whenDocReady = function(f) |
|---|
| 3045 | { |
|---|
| 3046 | var e = this; |
|---|
| 3047 | if ( this._doc && this._doc.body ) |
|---|
| 3048 | { |
|---|
| 3049 | f(); |
|---|
| 3050 | } |
|---|
| 3051 | else |
|---|
| 3052 | { |
|---|
| 3053 | setTimeout(function() { e.whenDocReady(f); }, 50); |
|---|
| 3054 | } |
|---|
| 3055 | }; |
|---|
| 3056 | |
|---|
| 3057 | |
|---|
| 3058 | /** Switches editor mode between wysiwyg and text (HTML) |
|---|
| 3059 | * @param {String} mode optional "textmode" or "wysiwyg", if omitted, toggles between modes. |
|---|
| 3060 | */ |
|---|
| 3061 | Xinha.prototype.setMode = function(mode) |
|---|
| 3062 | { |
|---|
| 3063 | var html; |
|---|
| 3064 | if ( typeof mode == "undefined" ) |
|---|
| 3065 | { |
|---|
| 3066 | mode = this._editMode == "textmode" ? "wysiwyg" : "textmode"; |
|---|
| 3067 | } |
|---|
| 3068 | switch ( mode ) |
|---|
| 3069 | { |
|---|
| 3070 | case "textmode": |
|---|
| 3071 | this.firePluginEvent('onBeforeMode', 'textmode'); |
|---|
| 3072 | this.setCC("iframe"); |
|---|
| 3073 | html = this.outwardHtml(this.getHTML()); |
|---|
| 3074 | this.setHTML(html); |
|---|
| 3075 | |
|---|
| 3076 | // Hide the iframe |
|---|
| 3077 | this.deactivateEditor(); |
|---|
| 3078 | this._iframe.style.display = 'none'; |
|---|
| 3079 | this._textArea.style.display = ''; |
|---|
| 3080 | |
|---|
| 3081 | if ( this.config.statusBar ) |
|---|
| 3082 | { |
|---|
| 3083 | this._statusBarTree.style.display = "none"; |
|---|
| 3084 | this._statusBarTextMode.style.display = ""; |
|---|
| 3085 | } |
|---|
| 3086 | this.findCC("textarea"); |
|---|
| 3087 | this.notifyOf('modechange', {'mode':'text'}); |
|---|
| 3088 | this.firePluginEvent('onMode', 'textmode'); |
|---|
| 3089 | break; |
|---|
| 3090 | |
|---|
| 3091 | case "wysiwyg": |
|---|
| 3092 | this.firePluginEvent('onBeforeMode', 'wysiwyg'); |
|---|
| 3093 | this.setCC("textarea"); |
|---|
| 3094 | html = this.inwardHtml(this.getHTML()); |
|---|
| 3095 | this.deactivateEditor(); |
|---|
| 3096 | this.setHTML(html); |
|---|
| 3097 | this._iframe.style.display = ''; |
|---|
| 3098 | this._textArea.style.display = "none"; |
|---|
| 3099 | this.activateEditor(); |
|---|
| 3100 | if ( this.config.statusBar ) |
|---|
| 3101 | { |
|---|
| 3102 | this._statusBarTree.style.display = ""; |
|---|
| 3103 | this._statusBarTextMode.style.display = "none"; |
|---|
| 3104 | } |
|---|
| 3105 | this.findCC("iframe"); |
|---|
| 3106 | this.notifyOf('modechange', {'mode':'wysiwyg'}); |
|---|
| 3107 | this.firePluginEvent('onMode', 'wysiwyg'); |
|---|
| 3108 | |
|---|
| 3109 | break; |
|---|
| 3110 | |
|---|
| 3111 | default: |
|---|
| 3112 | alert("Mode <" + mode + "> not defined!"); |
|---|
| 3113 | return false; |
|---|
| 3114 | } |
|---|
| 3115 | this._editMode = mode; |
|---|
| 3116 | }; |
|---|
| 3117 | /** Sets the HTML in fullpage mode. Actually the whole iframe document is rewritten. |
|---|
| 3118 | * @private |
|---|
| 3119 | * @param {String} html |
|---|
| 3120 | */ |
|---|
| 3121 | Xinha.prototype.setFullHTML = function(html) |
|---|
| 3122 | { |
|---|
| 3123 | var save_multiline = RegExp.multiline; |
|---|
| 3124 | RegExp.multiline = true; |
|---|
| 3125 | if ( html.match(Xinha.RE_doctype) ) |
|---|
| 3126 | { |
|---|
| 3127 | this.setDoctype(RegExp.$1); |
|---|
| 3128 | // html = html.replace(Xinha.RE_doctype, ""); |
|---|
| 3129 | } |
|---|
| 3130 | RegExp.multiline = save_multiline; |
|---|
| 3131 | // disabled to save body attributes see #459 |
|---|
| 3132 | if ( 0 ) |
|---|
| 3133 | { |
|---|
| 3134 | if ( html.match(Xinha.RE_head) ) |
|---|
| 3135 | { |
|---|
| 3136 | this._doc.getElementsByTagName("head")[0].innerHTML = RegExp.$1; |
|---|
| 3137 | } |
|---|
| 3138 | if ( html.match(Xinha.RE_body) ) |
|---|
| 3139 | { |
|---|
| 3140 | this._doc.getElementsByTagName("body")[0].innerHTML = RegExp.$1; |
|---|
| 3141 | } |
|---|
| 3142 | } |
|---|
| 3143 | else |
|---|
| 3144 | { |
|---|
| 3145 | // FIXME - can we do this without rewriting the entire document |
|---|
| 3146 | // does the above not work for IE? |
|---|
| 3147 | var reac = this.editorIsActivated(); |
|---|
| 3148 | if ( reac ) |
|---|
| 3149 | { |
|---|
| 3150 | this.deactivateEditor(); |
|---|
| 3151 | } |
|---|
| 3152 | var html_re = /<html>((.|\n)*?)<\/html>/i; |
|---|
| 3153 | html = html.replace(html_re, "$1"); |
|---|
| 3154 | this._doc.open("text/html","replace"); |
|---|
| 3155 | this._doc.write(html); |
|---|
| 3156 | this._doc.close(); |
|---|
| 3157 | if ( reac ) |
|---|
| 3158 | { |
|---|
| 3159 | this.activateEditor(); |
|---|
| 3160 | } |
|---|
| 3161 | this.setEditorEvents(); |
|---|
| 3162 | return true; |
|---|
| 3163 | } |
|---|
| 3164 | }; |
|---|
| 3165 | /** Initialize some event handlers |
|---|
| 3166 | * @private |
|---|
| 3167 | */ |
|---|
| 3168 | Xinha.prototype.setEditorEvents = function() |
|---|
| 3169 | { |
|---|
| 3170 | var editor=this; |
|---|
| 3171 | var doc = this._doc; |
|---|
| 3172 | |
|---|
| 3173 | editor.whenDocReady( |
|---|
| 3174 | function() |
|---|
| 3175 | { |
|---|
| 3176 | // if we have multiple editors some bug in Mozilla makes some lose editing ability |
|---|
| 3177 | Xinha._addEvents( |
|---|
| 3178 | doc, |
|---|
| 3179 | ["mousedown"], |
|---|
| 3180 | function() |
|---|
| 3181 | { |
|---|
| 3182 | editor.activateEditor(); |
|---|
| 3183 | return true; |
|---|
| 3184 | } |
|---|
| 3185 | ); |
|---|
| 3186 | if (Xinha.is_ie) |
|---|
| 3187 | { // #1019 Cusor not jumping to editable part of window when clicked in IE, see also #1039 |
|---|
| 3188 | Xinha._addEvent( |
|---|
| 3189 | editor._doc.getElementsByTagName("html")[0], |
|---|
| 3190 | "click", |
|---|
| 3191 | function() |
|---|
| 3192 | { |
|---|
| 3193 | if (editor._iframe.contentWindow.event.srcElement.tagName.toLowerCase() == 'html') // if clicked below the text (=body), the text cursor does not appear, see #1019 |
|---|
| 3194 | { |
|---|
| 3195 | var r = editor._doc.body.createTextRange(); |
|---|
| 3196 | r.collapse(); |
|---|
| 3197 | r.select() |
|---|
| 3198 | //setTimeout (function () { r.collapse(); r.select();},100); // won't do without timeout, dunno why |
|---|
| 3199 | } |
|---|
| 3200 | return true; |
|---|
| 3201 | } |
|---|
| 3202 | ); |
|---|
| 3203 | } |
|---|
| 3204 | |
|---|
| 3205 | |
|---|
| 3206 | Xinha._addEvents( |
|---|
| 3207 | doc, |
|---|
| 3208 | ["keydown", "keypress", "mousedown", "mouseup", "drag"], |
|---|
| 3209 | function (event) |
|---|
| 3210 | { |
|---|
| 3211 | return editor._editorEvent(Xinha.is_ie ? editor._iframe.contentWindow.event : event); |
|---|
| 3212 | } |
|---|
| 3213 | ); |
|---|
| 3214 | |
|---|
| 3215 | |
|---|
| 3216 | |
|---|
| 3217 | |
|---|
| 3218 | |
|---|
| 3219 | |
|---|
| 3220 | for ( var i in editor.plugins ) |
|---|
| 3221 | { |
|---|
| 3222 | var plugin = editor.plugins[i].instance; |
|---|
| 3223 | Xinha.refreshPlugin(plugin); |
|---|
| 3224 | } |
|---|
| 3225 | |
|---|
| 3226 | |
|---|
| 3227 | if ( typeof editor._onGenerate == "function" ) |
|---|
| 3228 | { |
|---|
| 3229 | editor._onGenerate(); |
|---|
| 3230 | } |
|---|
| 3231 | |
|---|
| 3232 | Xinha.addDom0Event(window, 'resize', function(e) { editor.sizeEditor(); }); |
|---|
| 3233 | editor.removeLoadingMessage(); |
|---|
| 3234 | } |
|---|
| 3235 | ); |
|---|
| 3236 | }; |
|---|
| 3237 | |
|---|
| 3238 | |
|---|
| 3239 | |
|---|
| 3240 | |
|---|
| 3241 | |
|---|
| 3242 | |
|---|
| 3243 | |
|---|
| 3244 | |
|---|
| 3245 | |
|---|
| 3246 | |
|---|
| 3247 | Xinha.prototype.registerPlugin = function() |
|---|
| 3248 | { |
|---|
| 3249 | if ( !Xinha.isSupportedBrowser ) return; |
|---|
| 3250 | |
|---|
| 3251 | var plugin = arguments[0]; |
|---|
| 3252 | |
|---|
| 3253 | |
|---|
| 3254 | if ( plugin === null || typeof plugin == 'undefined' || (typeof plugin == 'string' && typeof window[plugin] == 'undefined') ) |
|---|
| 3255 | { |
|---|
| 3256 | return false; |
|---|
| 3257 | } |
|---|
| 3258 | |
|---|
| 3259 | var args = []; |
|---|
| 3260 | for ( var i = 1; i < arguments.length; ++i ) |
|---|
| 3261 | { |
|---|
| 3262 | args.push(arguments[i]); |
|---|
| 3263 | } |
|---|
| 3264 | return this.registerPlugin2(plugin, args); |
|---|
| 3265 | }; |
|---|
| 3266 | |
|---|
| 3267 | |
|---|
| 3268 | |
|---|
| 3269 | |
|---|
| 3270 | |
|---|
| 3271 | |
|---|
| 3272 | Xinha.prototype.registerPlugin2 = function(plugin, args) |
|---|
| 3273 | { |
|---|
| 3274 | if ( typeof plugin == "string" && typeof window[plugin] == 'function' ) |
|---|
| 3275 | { |
|---|
| 3276 | plugin = window[plugin]; |
|---|
| 3277 | } |
|---|
| 3278 | if ( typeof plugin == "undefined" ) |
|---|
| 3279 | { |
|---|
| 3280 | |
|---|
| 3281 | return false; |
|---|
| 3282 | } |
|---|
| 3283 | var obj = new plugin(this, args); |
|---|
| 3284 | if ( obj ) |
|---|
| 3285 | { |
|---|
| 3286 | var clone = {}; |
|---|
| 3287 | var info = plugin._pluginInfo; |
|---|
| 3288 | for ( var i in info ) |
|---|
| 3289 | { |
|---|
| 3290 | clone[i] = info[i]; |
|---|
| 3291 | } |
|---|
| 3292 | clone.instance = obj; |
|---|
| 3293 | clone.args = args; |
|---|
| 3294 | this.plugins[plugin._pluginInfo.name] = clone; |
|---|
| 3295 | return obj; |
|---|
| 3296 | } |
|---|
| 3297 | else |
|---|
| 3298 | { |
|---|
| 3299 | alert("Can't register plugin " + plugin.toString() + "."); |
|---|
| 3300 | } |
|---|
| 3301 | }; |
|---|
| 3302 | |
|---|
| 3303 | |
|---|
| 3304 | |
|---|
| 3305 | |
|---|
| 3306 | |
|---|
| 3307 | |
|---|
| 3308 | |
|---|
| 3309 | |
|---|
| 3310 | |
|---|
| 3311 | Xinha.getPluginDir = function(plugin) |
|---|
| 3312 | { |
|---|
| 3313 | if (Xinha.externalPlugins[plugin]) |
|---|
| 3314 | { |
|---|
| 3315 | return Xinha.externalPlugins[plugin][0]; |
|---|
| 3316 | } |
|---|
| 3317 | else |
|---|
| 3318 | { |
|---|
| 3319 | return _editor_url + "plugins/" + plugin ; |
|---|
| 3320 | } |
|---|
| 3321 | } |
|---|
| 3322 | |
|---|
| 3323 | |
|---|
| 3324 | |
|---|
| 3325 | |
|---|
| 3326 | |
|---|
| 3327 | |
|---|
| 3328 | Xinha.loadPlugin = function(pluginName, callback, plugin_file) |
|---|
| 3329 | { |
|---|
| 3330 | if ( !Xinha.isSupportedBrowser ) return; |
|---|
| 3331 | |
|---|
| 3332 | Xinha.setLoadingMessage (Xinha._lc("Loading plugin $plugin="+pluginName+"$")); |
|---|
| 3333 | |
|---|
| 3334 | |
|---|
| 3335 | if ( typeof window['pluginName'] != 'undefined' ) |
|---|
| 3336 | { |
|---|
| 3337 | if ( callback ) |
|---|
| 3338 | { |
|---|
| 3339 | callback(pluginName); |
|---|
| 3340 | } |
|---|
| 3341 | return true; |
|---|
| 3342 | } |
|---|
| 3343 | |
|---|
| 3344 | if(!plugin_file) |
|---|
| 3345 | { |
|---|
| 3346 | var dir = this.getPluginDir(pluginName); |
|---|
| 3347 | var plugin = pluginName.replace(/([a-z])([A-Z])([a-z])/g, function (str, l1, l2, l3) { return l1 + "-" + l2.toLowerCase() + l3; }).toLowerCase() + ".js"; |
|---|
| 3348 | plugin_file = dir + "/" + plugin; |
|---|
| 3349 | } |
|---|
| 3350 | |
|---|
| 3351 | Xinha._loadback(plugin_file, callback ? function() { callback(pluginName); } : null); |
|---|
| 3352 | return false; |
|---|
| 3353 | }; |
|---|
| 3354 | |
|---|
| 3355 | |
|---|
| 3356 | |
|---|
| 3357 | |
|---|
| 3358 | Xinha._pluginLoadStatus = {}; |
|---|
| 3359 | |
|---|
| 3360 | Xinha.externalPlugins = {}; |
|---|
| 3361 | |
|---|
| 3362 | |
|---|
| 3363 | |
|---|
| 3364 | |
|---|
| 3365 | |
|---|
| 3366 | |
|---|
| 3367 | |
|---|
| 3368 | Xinha.loadPlugins = function(plugins, callbackIfNotReady,url) |
|---|
| 3369 | { |
|---|
| 3370 | if ( !Xinha.isSupportedBrowser ) return; |
|---|
| 3371 | Xinha.setLoadingMessage (Xinha._lc("Loading plugins")); |
|---|
| 3372 | var m; |
|---|
| 3373 | for (var i=0;i<plugins.length;i++) |
|---|
| 3374 | { |
|---|
| 3375 | if (typeof plugins[i] == 'object') |
|---|
| 3376 | { |
|---|
| 3377 | m = plugins[i].url.match(/(.*)(\/[^\/]*)$/); |
|---|
| 3378 | Xinha.externalPlugins[plugins[i].plugin] = [m[1],m[2]]; |
|---|
| 3379 | plugins[i] = plugins[i].plugin; |
|---|
| 3380 | } |
|---|
| 3381 | } |
|---|
| 3382 | |
|---|
| 3383 | |
|---|
| 3384 | var retVal = true; |
|---|
| 3385 | var nuPlugins = Xinha.cloneObject(plugins); |
|---|
| 3386 | |
|---|
| 3387 | while ( nuPlugins.length ) |
|---|
| 3388 | { |
|---|
| 3389 | var p = nuPlugins.pop(); |
|---|
| 3390 | if (p == 'FullScreen' && !Xinha.externalPlugins['FullScreen'] ) continue; |
|---|
| 3391 | |
|---|
| 3392 | if ( typeof Xinha._pluginLoadStatus[p] == 'undefined' ) |
|---|
| 3393 | { |
|---|
| 3394 | |
|---|
| 3395 | Xinha._pluginLoadStatus[p] = 'loading'; |
|---|
| 3396 | Xinha.loadPlugin(p, |
|---|
| 3397 | function(plugin) |
|---|
| 3398 | { |
|---|
| 3399 | if ( typeof window[plugin] != 'undefined' ) |
|---|
| 3400 | { |
|---|
| 3401 | Xinha._pluginLoadStatus[plugin] = 'ready'; |
|---|
| 3402 | } |
|---|
| 3403 | else |
|---|
| 3404 | { |
|---|
| 3405 | |
|---|
| 3406 | |
|---|
| 3407 | |
|---|
| 3408 | |
|---|
| 3409 | |
|---|
| 3410 | Xinha._pluginLoadStatus[plugin] = 'failed'; |
|---|
| 3411 | } |
|---|
| 3412 | },(Xinha.externalPlugins[p] ? Xinha.externalPlugins[p][0]+Xinha.externalPlugins[p][1] : url) |
|---|
| 3413 | ); |
|---|
| 3414 | retVal = false; |
|---|
| 3415 | } |
|---|
| 3416 | else |
|---|
| 3417 | { |
|---|
| 3418 | |
|---|
| 3419 | |
|---|
| 3420 | |
|---|
| 3421 | |
|---|
| 3422 | |
|---|
| 3423 | switch ( Xinha._pluginLoadStatus[p] ) |
|---|
| 3424 | { |
|---|
| 3425 | case 'failed': |
|---|
| 3426 | case 'ready' : |
|---|
| 3427 | break; |
|---|
| 3428 | |
|---|
| 3429 | |
|---|
| 3430 | default : |
|---|
| 3431 | retVal = false; |
|---|
| 3432 | break; |
|---|
| 3433 | } |
|---|
| 3434 | } |
|---|
| 3435 | } |
|---|
| 3436 | |
|---|
| 3437 | |
|---|
| 3438 | if ( retVal ) |
|---|
| 3439 | { |
|---|
| 3440 | return true; |
|---|
| 3441 | } |
|---|
| 3442 | |
|---|
| 3443 | |
|---|
| 3444 | |
|---|
| 3445 | if ( callbackIfNotReady ) |
|---|
| 3446 | { |
|---|
| 3447 | setTimeout(function() { if ( Xinha.loadPlugins(plugins, callbackIfNotReady) ) { callbackIfNotReady(); } }, 150); |
|---|
| 3448 | } |
|---|
| 3449 | return retVal; |
|---|
| 3450 | }; |
|---|
| 3451 | |
|---|
| 3452 | |
|---|
| 3453 | |
|---|
| 3454 | |
|---|
| 3455 | |
|---|
| 3456 | |
|---|
| 3457 | Xinha.refreshPlugin = function(plugin) |
|---|
| 3458 | { |
|---|
| 3459 | if ( plugin && typeof plugin.onGenerate == "function" ) |
|---|
| 3460 | { |
|---|
| 3461 | plugin.onGenerate(); |
|---|
| 3462 | } |
|---|
| 3463 | if ( plugin && typeof plugin.onGenerateOnce == "function" ) |
|---|
| 3464 | { |
|---|
| 3465 | plugin.onGenerateOnce(); |
|---|
| 3466 | plugin.onGenerateOnce = null; |
|---|
| 3467 | } |
|---|
| 3468 | }; |
|---|
| 3469 | |
|---|
| 3470 | |
|---|
| 3471 | |
|---|
| 3472 | |
|---|
| 3473 | |
|---|
| 3474 | |
|---|
| 3475 | |
|---|
| 3476 | |
|---|
| 3477 | |
|---|
| 3478 | |
|---|
| 3479 | |
|---|
| 3480 | |
|---|
| 3481 | |
|---|
| 3482 | |
|---|
| 3483 | |
|---|
| 3484 | |
|---|
| 3485 | |
|---|
| 3486 | |
|---|
| 3487 | |
|---|
| 3488 | |
|---|
| 3489 | |
|---|
| 3490 | |
|---|
| 3491 | |
|---|
| 3492 | |
|---|
| 3493 | |
|---|
| 3494 | |
|---|
| 3495 | |
|---|
| 3496 | |
|---|
| 3497 | |
|---|
| 3498 | |
|---|
| 3499 | |
|---|
| 3500 | Xinha.prototype.firePluginEvent = function(methodName) |
|---|
| 3501 | { |
|---|
| 3502 | |
|---|
| 3503 | var argsArray = [ ]; |
|---|
| 3504 | for(var i = 1; i < arguments.length; i++) |
|---|
| 3505 | { |
|---|
| 3506 | argsArray[i-1] = arguments[i]; |
|---|
| 3507 | } |
|---|
| 3508 | |
|---|
| 3509 | for ( var i in this.plugins ) |
|---|
| 3510 | { |
|---|
| 3511 | var plugin = this.plugins[i].instance; |
|---|
| 3512 | |
|---|
| 3513 | |
|---|
| 3514 | if ( plugin == this._browserSpecificPlugin) continue; |
|---|
| 3515 | |
|---|
| 3516 | if ( plugin && typeof plugin[methodName] == "function" ) |
|---|
| 3517 | { |
|---|
| 3518 | if ( plugin[methodName].apply(plugin, argsArray) ) |
|---|
| 3519 | { |
|---|
| 3520 | return true; |
|---|
| 3521 | } |
|---|
| 3522 | } |
|---|
| 3523 | } |
|---|
| 3524 | |
|---|
| 3525 | |
|---|
| 3526 | var plugin = this._browserSpecificPlugin; |
|---|
| 3527 | if ( plugin && typeof plugin[methodName] == "function" ) |
|---|
| 3528 | { |
|---|
| 3529 | if ( plugin[methodName].apply(plugin, argsArray) ) |
|---|
| 3530 | { |
|---|
| 3531 | return true; |
|---|
| 3532 | } |
|---|
| 3533 | } |
|---|
| 3534 | |
|---|
| 3535 | return false; |
|---|
| 3536 | } |
|---|
| 3537 | |
|---|
| 3538 | |
|---|
| 3539 | |
|---|
| 3540 | |
|---|
| 3541 | |
|---|
| 3542 | |
|---|
| 3543 | Xinha.loadStyle = function(style, plugin, id,prepend) |
|---|
| 3544 | { |
|---|
| 3545 | var url = _editor_url || ''; |
|---|
| 3546 | if ( plugin ) |
|---|
| 3547 | { |
|---|
| 3548 | url = Xinha.getPluginDir( plugin ) + "/"; |
|---|
| 3549 | } |
|---|
| 3550 | url += style; |
|---|
| 3551 | |
|---|
| 3552 | |
|---|
| 3553 | |
|---|
| 3554 | |
|---|
| 3555 | |
|---|
| 3556 | if ( /^\ |
|---|
| 3557 | { |
|---|
| 3558 | url = style; |
|---|
| 3559 | } |
|---|
| 3560 | var head = document.getElementsByTagName("head")[0]; |
|---|
| 3561 | var link = document.createElement("link"); |
|---|
| 3562 | link.rel = "stylesheet"; |
|---|
| 3563 | link.href = url; |
|---|
| 3564 | link.type = "text/css"; |
|---|
| 3565 | if (id) link.id = id; |
|---|
| 3566 | if (prepend && head.getElementsByTagName('link')[0]) |
|---|
| 3567 | { |
|---|
| 3568 | head.insertBefore(link,head.getElementsByTagName('link')[0]); |
|---|
| 3569 | } |
|---|
| 3570 | else |
|---|
| 3571 | { |
|---|
| 3572 | head.appendChild(link); |
|---|
| 3573 | } |
|---|
| 3574 | |
|---|
| 3575 | }; |
|---|
| 3576 | |
|---|
| 3577 | |
|---|
| 3578 | |
|---|
| 3579 | |
|---|
| 3580 | |
|---|
| 3581 | |
|---|
| 3582 | Xinha.prototype.debugTree = function() |
|---|
| 3583 | { |
|---|
| 3584 | var ta = document.createElement("textarea"); |
|---|
| 3585 | ta.style.width = "100%"; |
|---|
| 3586 | ta.style.height = "20em"; |
|---|
| 3587 | ta.value = ""; |
|---|
| 3588 | function debug(indent, str) |
|---|
| 3589 | { |
|---|
| 3590 | for ( ; --indent >= 0; ) |
|---|
| 3591 | { |
|---|
| 3592 | ta.value += " "; |
|---|
| 3593 | } |
|---|
| 3594 | ta.value += str + "\n"; |
|---|
| 3595 | } |
|---|
| 3596 | function _dt(root, level) |
|---|
| 3597 | { |
|---|
| 3598 | var tag = root.tagName.toLowerCase(), i; |
|---|
| 3599 | var ns = Xinha.is_ie ? root.scopeName : root.prefix; |
|---|
| 3600 | debug(level, "- " + tag + " [" + ns + "]"); |
|---|
| 3601 | for ( i = root.firstChild; i; i = i.nextSibling ) |
|---|
| 3602 | { |
|---|
| 3603 | if ( i.nodeType == 1 ) |
|---|
| 3604 | { |
|---|
| 3605 | _dt(i, level + 2); |
|---|
| 3606 | } |
|---|
| 3607 | } |
|---|
| 3608 | } |
|---|
| 3609 | _dt(this._doc.body, 0); |
|---|
| 3610 | document.body.appendChild(ta); |
|---|
| 3611 | }; |
|---|
| 3612 | |
|---|
| 3613 | |
|---|
| 3614 | |
|---|
| 3615 | |
|---|
| 3616 | Xinha.getInnerText = function(el) |
|---|
| 3617 | { |
|---|
| 3618 | var txt = '', i; |
|---|
| 3619 | for ( i = el.firstChild; i; i = i.nextSibling ) |
|---|
| 3620 | { |
|---|
| 3621 | if ( i.nodeType == 3 ) |
|---|
| 3622 | { |
|---|
| 3623 | txt += i.data; |
|---|
| 3624 | } |
|---|
| 3625 | else if ( i.nodeType == 1 ) |
|---|
| 3626 | { |
|---|
| 3627 | txt += Xinha.getInnerText(i); |
|---|
| 3628 | } |
|---|
| 3629 | } |
|---|
| 3630 | return txt; |
|---|
| 3631 | }; |
|---|
| 3632 | |
|---|
| 3633 | |
|---|
| 3634 | |
|---|
| 3635 | |
|---|
| 3636 | Xinha.prototype._wordClean = function() |
|---|
| 3637 | { |
|---|
| 3638 | var editor = this; |
|---|
| 3639 | var stats = |
|---|
| 3640 | { |
|---|
| 3641 | empty_tags : 0, |
|---|
| 3642 | mso_class : 0, |
|---|
| 3643 | mso_style : 0, |
|---|
| 3644 | mso_xmlel : 0, |
|---|
| 3645 | orig_len : this._doc.body.innerHTML.length, |
|---|
| 3646 | T : (new Date()).getTime() |
|---|
| 3647 | }; |
|---|
| 3648 | var stats_txt = |
|---|
| 3649 | { |
|---|
| 3650 | empty_tags : "Empty tags removed: ", |
|---|
| 3651 | mso_class : "MSO class names removed: ", |
|---|
| 3652 | mso_style : "MSO inline style removed: ", |
|---|
| 3653 | mso_xmlel : "MSO XML elements stripped: " |
|---|
| 3654 | }; |
|---|
| 3655 | |
|---|
| 3656 | function showStats() |
|---|
| 3657 | { |
|---|
| 3658 | var txt = "Xinha word cleaner stats: \n\n"; |
|---|
| 3659 | for ( var i in stats ) |
|---|
| 3660 | { |
|---|
| 3661 | if ( stats_txt[i] ) |
|---|
| 3662 | { |
|---|
| 3663 | txt += stats_txt[i] + stats[i] + "\n"; |
|---|
| 3664 | } |
|---|
| 3665 | } |
|---|
| 3666 | txt += "\nInitial document length: " + stats.orig_len + "\n"; |
|---|
| 3667 | txt += "Final document length: " + editor._doc.body.innerHTML.length + "\n"; |
|---|
| 3668 | txt += "Clean-up took " + (((new Date()).getTime() - stats.T) / 1000) + " seconds"; |
|---|
| 3669 | alert(txt); |
|---|
| 3670 | } |
|---|
| 3671 | |
|---|
| 3672 | function clearClass(node) |
|---|
| 3673 | { |
|---|
| 3674 | var newc = node.className.replace(/(^|\s)mso.*?(\s|$)/ig, ' '); |
|---|
| 3675 | if ( newc != node.className ) |
|---|
| 3676 | { |
|---|
| 3677 | node.className = newc; |
|---|
| 3678 | if ( ! ( /\S/.test(node.className) ) ) |
|---|
| 3679 | { |
|---|
| 3680 | node.removeAttribute("className"); |
|---|
| 3681 | ++stats.mso_class; |
|---|
| 3682 | } |
|---|
| 3683 | } |
|---|
| 3684 | } |
|---|
| 3685 | |
|---|
| 3686 | function clearStyle(node) |
|---|
| 3687 | { |
|---|
| 3688 | var declarations = node.style.cssText.split(/\s*;\s*/); |
|---|
| 3689 | for ( var i = declarations.length; --i >= 0; ) |
|---|
| 3690 | { |
|---|
| 3691 | if ( ( /^mso|^tab-stops/i.test(declarations[i]) ) || ( /^margin\s*:\s*0..\s+0..\s+0../i.test(declarations[i]) ) ) |
|---|
| 3692 | { |
|---|
| 3693 | ++stats.mso_style; |
|---|
| 3694 | declarations.splice(i, 1); |
|---|
| 3695 | } |
|---|
| 3696 | } |
|---|
| 3697 | node.style.cssText = declarations.join("; "); |
|---|
| 3698 | } |
|---|
| 3699 | |
|---|
| 3700 | var stripTag = null; |
|---|
| 3701 | if ( Xinha.is_ie ) |
|---|
| 3702 | { |
|---|
| 3703 | stripTag = function(el) |
|---|
| 3704 | { |
|---|
| 3705 | el.outerHTML = Xinha.htmlEncode(el.innerText); |
|---|
| 3706 | ++stats.mso_xmlel; |
|---|
| 3707 | }; |
|---|
| 3708 | } |
|---|
| 3709 | else |
|---|
| 3710 | { |
|---|
| 3711 | stripTag = function(el) |
|---|
| 3712 | { |
|---|
| 3713 | var txt = document.createTextNode(Xinha.getInnerText(el)); |
|---|
| 3714 | el.parentNode.insertBefore(txt, el); |
|---|
| 3715 | Xinha.removeFromParent(el); |
|---|
| 3716 | ++stats.mso_xmlel; |
|---|
| 3717 | }; |
|---|
| 3718 | } |
|---|
| 3719 | |
|---|
| 3720 | function checkEmpty(el) |
|---|
| 3721 | { |
|---|
| 3722 | |
|---|
| 3723 | |
|---|
| 3724 | if ( /^(span|b|strong|i|em|font|div|p)$/i.test(el.tagName) && !el.firstChild) |
|---|
| 3725 | { |
|---|
| 3726 | Xinha.removeFromParent(el); |
|---|
| 3727 | ++stats.empty_tags; |
|---|
| 3728 | } |
|---|
| 3729 | } |
|---|
| 3730 | |
|---|
| 3731 | function parseTree(root) |
|---|
| 3732 | { |
|---|
| 3733 | var tag = root.tagName.toLowerCase(), i, next; |
|---|
| 3734 | |
|---|
| 3735 | |
|---|
| 3736 | if ( ( Xinha.is_ie && root.scopeName != 'HTML' ) || ( !Xinha.is_ie && ( /:/.test(tag) ) ) ) |
|---|
| 3737 | { |
|---|
| 3738 | stripTag(root); |
|---|
| 3739 | return false; |
|---|
| 3740 | } |
|---|
| 3741 | else |
|---|
| 3742 | { |
|---|
| 3743 | clearClass(root); |
|---|
| 3744 | clearStyle(root); |
|---|
| 3745 | for ( i = root.firstChild; i; i = next ) |
|---|
| 3746 | { |
|---|
| 3747 | next = i.nextSibling; |
|---|
| 3748 | if ( i.nodeType == 1 && parseTree(i) ) |
|---|
| 3749 | { |
|---|
| 3750 | checkEmpty(i); |
|---|
| 3751 | } |
|---|
| 3752 | } |
|---|
| 3753 | } |
|---|
| 3754 | return true; |
|---|
| 3755 | } |
|---|
| 3756 | parseTree(this._doc.body); |
|---|
| 3757 | |
|---|
| 3758 | |
|---|
| 3759 | |
|---|
| 3760 | |
|---|
| 3761 | |
|---|
| 3762 | this.updateToolbar(); |
|---|
| 3763 | }; |
|---|
| 3764 | |
|---|
| 3765 | |
|---|
| 3766 | |
|---|
| 3767 | |
|---|
| 3768 | |
|---|
| 3769 | Xinha.prototype._clearFonts = function() |
|---|
| 3770 | { |
|---|
| 3771 | var D = this.getInnerHTML(); |
|---|
| 3772 | |
|---|
| 3773 | if ( confirm(Xinha._lc("Would you like to clear font typefaces?")) ) |
|---|
| 3774 | { |
|---|
| 3775 | D = D.replace(/face="[^"]*"/gi, ''); |
|---|
| 3776 | D = D.replace(/font-family:[^;}"']+;?/gi, ''); |
|---|
| 3777 | } |
|---|
| 3778 | |
|---|
| 3779 | if ( confirm(Xinha._lc("Would you like to clear font sizes?")) ) |
|---|
| 3780 | { |
|---|
| 3781 | D = D.replace(/size="[^"]*"/gi, ''); |
|---|
| 3782 | D = D.replace(/font-size:[^;}"']+;?/gi, ''); |
|---|
| 3783 | } |
|---|
| 3784 | |
|---|
| 3785 | if ( confirm(Xinha._lc("Would you like to clear font colours?")) ) |
|---|
| 3786 | { |
|---|
| 3787 | D = D.replace(/color="[^"]*"/gi, ''); |
|---|
| 3788 | D = D.replace(/([^-])color:[^;}"']+;?/gi, '$1'); |
|---|
| 3789 | } |
|---|
| 3790 | |
|---|
| 3791 | D = D.replace(/(style|class)="\s*"/gi, ''); |
|---|
| 3792 | D = D.replace(/<(font|span)\s*>/gi, ''); |
|---|
| 3793 | this.setHTML(D); |
|---|
| 3794 | this.updateToolbar(); |
|---|
| 3795 | }; |
|---|
| 3796 | |
|---|
| 3797 | Xinha.prototype._splitBlock = function() |
|---|
| 3798 | { |
|---|
| 3799 | this._doc.execCommand('formatblock', false, 'div'); |
|---|
| 3800 | }; |
|---|
| 3801 | |
|---|
| 3802 | /** Sometimes the display has to be refreshed to make DOM changes visible (?) (Gecko bug?) */ |
|---|
| 3803 | Xinha.prototype.forceRedraw = function() |
|---|
| 3804 | { |
|---|
| 3805 | this._doc.body.style.visibility = "hidden"; |
|---|
| 3806 | this._doc.body.style.visibility = ""; |
|---|
| 3807 | // this._doc.body.innerHTML = this.getInnerHTML(); |
|---|
| 3808 | }; |
|---|
| 3809 | |
|---|
| 3810 | /** Focuses the iframe window. |
|---|
| 3811 | * @returns {document} a reference to the editor document |
|---|
| 3812 | */ |
|---|
| 3813 | Xinha.prototype.focusEditor = function() |
|---|
| 3814 | { |
|---|
| 3815 | switch (this._editMode) |
|---|
| 3816 | { |
|---|
| 3817 | // notice the try { ... } catch block to avoid some rare exceptions in FireFox |
|---|
| 3818 | // (perhaps also in other Gecko browsers). Manual focus by user is required in |
|---|
| 3819 | // case of an error. Somebody has an idea? |
|---|
| 3820 | case "wysiwyg" : |
|---|
| 3821 | try |
|---|
| 3822 | { |
|---|
| 3823 | // We don't want to focus the field unless at least one field has been activated. |
|---|
| 3824 | if ( Xinha._someEditorHasBeenActivated ) |
|---|
| 3825 | { |
|---|
| 3826 | this.activateEditor(); |
|---|
| 3827 | this._iframe.contentWindow.focus(); |
|---|
| 3828 | } |
|---|
| 3829 | } catch (ex) {} |
|---|
| 3830 | break; |
|---|
| 3831 | case "textmode": |
|---|
| 3832 | try |
|---|
| 3833 | { |
|---|
| 3834 | this._textArea.focus(); |
|---|
| 3835 | } catch (e) {} |
|---|
| 3836 | break; |
|---|
| 3837 | default: |
|---|
| 3838 | alert("ERROR: mode " + this._editMode + " is not defined"); |
|---|
| 3839 | } |
|---|
| 3840 | return this._doc; |
|---|
| 3841 | }; |
|---|
| 3842 | |
|---|
| 3843 | |
|---|
| 3844 | |
|---|
| 3845 | |
|---|
| 3846 | Xinha.prototype._undoTakeSnapshot = function() |
|---|
| 3847 | { |
|---|
| 3848 | ++this._undoPos; |
|---|
| 3849 | if ( this._undoPos >= this.config.undoSteps ) |
|---|
| 3850 | { |
|---|
| 3851 | |
|---|
| 3852 | this._undoQueue.shift(); |
|---|
| 3853 | --this._undoPos; |
|---|
| 3854 | } |
|---|
| 3855 | |
|---|
| 3856 | var take = true; |
|---|
| 3857 | var txt = this.getInnerHTML(); |
|---|
| 3858 | if ( this._undoPos > 0 ) |
|---|
| 3859 | { |
|---|
| 3860 | take = (this._undoQueue[this._undoPos - 1] != txt); |
|---|
| 3861 | } |
|---|
| 3862 | if ( take ) |
|---|
| 3863 | { |
|---|
| 3864 | this._undoQueue[this._undoPos] = txt; |
|---|
| 3865 | } |
|---|
| 3866 | else |
|---|
| 3867 | { |
|---|
| 3868 | this._undoPos--; |
|---|
| 3869 | } |
|---|
| 3870 | }; |
|---|
| 3871 | |
|---|
| 3872 | |
|---|
| 3873 | |
|---|
| 3874 | Xinha.prototype.undo = function() |
|---|
| 3875 | { |
|---|
| 3876 | if ( this._undoPos > 0 ) |
|---|
| 3877 | { |
|---|
| 3878 | var txt = this._undoQueue[--this._undoPos]; |
|---|
| 3879 | if ( txt ) |
|---|
| 3880 | { |
|---|
| 3881 | this.setHTML(txt); |
|---|
| 3882 | } |
|---|
| 3883 | else |
|---|
| 3884 | { |
|---|
| 3885 | ++this._undoPos; |
|---|
| 3886 | } |
|---|
| 3887 | } |
|---|
| 3888 | }; |
|---|
| 3889 | |
|---|
| 3890 | |
|---|
| 3891 | |
|---|
| 3892 | Xinha.prototype.redo = function() |
|---|
| 3893 | { |
|---|
| 3894 | if ( this._undoPos < this._undoQueue.length - 1 ) |
|---|
| 3895 | { |
|---|
| 3896 | var txt = this._undoQueue[++this._undoPos]; |
|---|
| 3897 | if ( txt ) |
|---|
| 3898 | { |
|---|
| 3899 | this.setHTML(txt); |
|---|
| 3900 | } |
|---|
| 3901 | else |
|---|
| 3902 | { |
|---|
| 3903 | --this._undoPos; |
|---|
| 3904 | } |
|---|
| 3905 | } |
|---|
| 3906 | }; |
|---|
| 3907 | |
|---|
| 3908 | |
|---|
| 3909 | |
|---|
| 3910 | Xinha.prototype.disableToolbar = function(except) |
|---|
| 3911 | { |
|---|
| 3912 | if ( this._timerToolbar ) |
|---|
| 3913 | { |
|---|
| 3914 | clearTimeout(this._timerToolbar); |
|---|
| 3915 | } |
|---|
| 3916 | if ( typeof except == 'undefined' ) |
|---|
| 3917 | { |
|---|
| 3918 | except = [ ]; |
|---|
| 3919 | } |
|---|
| 3920 | else if ( typeof except != 'object' ) |
|---|
| 3921 | { |
|---|
| 3922 | except = [except]; |
|---|
| 3923 | } |
|---|
| 3924 | |
|---|
| 3925 | for ( var i in this._toolbarObjects ) |
|---|
| 3926 | { |
|---|
| 3927 | var btn = this._toolbarObjects[i]; |
|---|
| 3928 | if ( except.contains(i) ) |
|---|
| 3929 | { |
|---|
| 3930 | continue; |
|---|
| 3931 | } |
|---|
| 3932 | |
|---|
| 3933 | if ( typeof(btn.state) != 'function' ) |
|---|
| 3934 | { |
|---|
| 3935 | continue; |
|---|
| 3936 | } |
|---|
| 3937 | btn.state("enabled", false); |
|---|
| 3938 | } |
|---|
| 3939 | }; |
|---|
| 3940 | |
|---|
| 3941 | Xinha.prototype.enableToolbar = function() |
|---|
| 3942 | { |
|---|
| 3943 | this.updateToolbar(); |
|---|
| 3944 | }; |
|---|
| 3945 | |
|---|
| 3946 | |
|---|
| 3947 | |
|---|
| 3948 | |
|---|
| 3949 | |
|---|
| 3950 | |
|---|
| 3951 | |
|---|
| 3952 | |
|---|
| 3953 | |
|---|
| 3954 | Xinha.prototype.updateToolbar = function(noStatus) |
|---|
| 3955 | { |
|---|
| 3956 | if (this.suspendUpdateToolbar) return; |
|---|
| 3957 | |
|---|
| 3958 | var doc = this._doc; |
|---|
| 3959 | var text = (this._editMode == "textmode"); |
|---|
| 3960 | var ancestors = null; |
|---|
| 3961 | if ( !text ) |
|---|
| 3962 | { |
|---|
| 3963 | ancestors = this.getAllAncestors(); |
|---|
| 3964 | if ( this.config.statusBar && !noStatus ) |
|---|
| 3965 | { |
|---|
| 3966 | while ( this._statusBarItems.length ) |
|---|
| 3967 | { |
|---|
| 3968 | var item = this._statusBarItems.pop(); |
|---|
| 3969 | item.el = null; |
|---|
| 3970 | item.editor = null; |
|---|
| 3971 | item.onclick = null; |
|---|
| 3972 | item.oncontextmenu = null; |
|---|
| 3973 | item._xinha_dom0Events['click'] = null; |
|---|
| 3974 | item._xinha_dom0Events['contextmenu'] = null; |
|---|
| 3975 | item = null; |
|---|
| 3976 | } |
|---|
| 3977 | |
|---|
| 3978 | this._statusBarTree.innerHTML = Xinha._lc("Path") + ": "; |
|---|
| 3979 | for ( var i = ancestors.length; --i >= 0; ) |
|---|
| 3980 | { |
|---|
| 3981 | var el = ancestors[i]; |
|---|
| 3982 | if ( !el ) |
|---|
| 3983 | { |
|---|
| 3984 | |
|---|
| 3985 | |
|---|
| 3986 | |
|---|
| 3987 | |
|---|
| 3988 | continue; |
|---|
| 3989 | } |
|---|
| 3990 | var a = document.createElement("a"); |
|---|
| 3991 | a.href = "javascript:void(0)"; |
|---|
| 3992 | a.el = el; |
|---|
| 3993 | a.editor = this; |
|---|
| 3994 | this._statusBarItems.push(a); |
|---|
| 3995 | Xinha.addDom0Event( |
|---|
| 3996 | a, |
|---|
| 3997 | 'click', |
|---|
| 3998 | function() { |
|---|
| 3999 | this.blur(); |
|---|
| 4000 | this.editor.selectNodeContents(this.el); |
|---|
| 4001 | this.editor.updateToolbar(true); |
|---|
| 4002 | return false; |
|---|
| 4003 | } |
|---|
| 4004 | ); |
|---|
| 4005 | Xinha.addDom0Event( |
|---|
| 4006 | a, |
|---|
| 4007 | 'contextmenu', |
|---|
| 4008 | function() |
|---|
| 4009 | { |
|---|
| 4010 | |
|---|
| 4011 | this.blur(); |
|---|
| 4012 | var info = "Inline style:\n\n"; |
|---|
| 4013 | info += this.el.style.cssText.split(/;\s*/).join(";\n"); |
|---|
| 4014 | alert(info); |
|---|
| 4015 | return false; |
|---|
| 4016 | } |
|---|
| 4017 | ); |
|---|
| 4018 | var txt = el.tagName.toLowerCase(); |
|---|
| 4019 | if (typeof el.style != 'undefined') a.title = el.style.cssText; |
|---|
| 4020 | if ( el.id ) |
|---|
| 4021 | { |
|---|
| 4022 | txt += "#" + el.id; |
|---|
| 4023 | } |
|---|
| 4024 | if ( el.className ) |
|---|
| 4025 | { |
|---|
| 4026 | txt += "." + el.className; |
|---|
| 4027 | } |
|---|
| 4028 | a.appendChild(document.createTextNode(txt)); |
|---|
| 4029 | this._statusBarTree.appendChild(a); |
|---|
| 4030 | if ( i !== 0 ) |
|---|
| 4031 | { |
|---|
| 4032 | this._statusBarTree.appendChild(document.createTextNode(String.fromCharCode(0xbb))); |
|---|
| 4033 | } |
|---|
| 4034 | Xinha.freeLater(a); |
|---|
| 4035 | } |
|---|
| 4036 | } |
|---|
| 4037 | } |
|---|
| 4038 | |
|---|
| 4039 | for ( var cmd in this._toolbarObjects ) |
|---|
| 4040 | { |
|---|
| 4041 | var btn = this._toolbarObjects[cmd]; |
|---|
| 4042 | var inContext = true; |
|---|
| 4043 | |
|---|
| 4044 | if ( typeof(btn.state) != 'function' ) |
|---|
| 4045 | { |
|---|
| 4046 | continue; |
|---|
| 4047 | } |
|---|
| 4048 | if ( btn.context && !text ) |
|---|
| 4049 | { |
|---|
| 4050 | inContext = false; |
|---|
| 4051 | var context = btn.context; |
|---|
| 4052 | var attrs = []; |
|---|
| 4053 | if ( /(.*)\[(.*?)\]/.test(context) ) |
|---|
| 4054 | { |
|---|
| 4055 | context = RegExp.$1; |
|---|
| 4056 | attrs = RegExp.$2.split(","); |
|---|
| 4057 | } |
|---|
| 4058 | context = context.toLowerCase(); |
|---|
| 4059 | var match = (context == "*"); |
|---|
| 4060 | for ( var k = 0; k < ancestors.length; ++k ) |
|---|
| 4061 | { |
|---|
| 4062 | if ( !ancestors[k] ) |
|---|
| 4063 | { |
|---|
| 4064 | |
|---|
| 4065 | continue; |
|---|
| 4066 | } |
|---|
| 4067 | if ( match || ( ancestors[k].tagName.toLowerCase() == context ) ) |
|---|
| 4068 | { |
|---|
| 4069 | inContext = true; |
|---|
| 4070 | var contextSplit = null; |
|---|
| 4071 | var att = null; |
|---|
| 4072 | var comp = null; |
|---|
| 4073 | var attVal = null; |
|---|
| 4074 | for ( var ka = 0; ka < attrs.length; ++ka ) |
|---|
| 4075 | { |
|---|
| 4076 | contextSplit = attrs[ka].match(/(.*)(==|!=|===|!==|>|>=|<|<=)(.*)/); |
|---|
| 4077 | att = contextSplit[1]; |
|---|
| 4078 | comp = contextSplit[2]; |
|---|
| 4079 | attVal = contextSplit[3]; |
|---|
| 4080 | |
|---|
| 4081 | if (!eval(ancestors[k][att] + comp + attVal)) |
|---|
| 4082 | { |
|---|
| 4083 | inContext = false; |
|---|
| 4084 | break; |
|---|
| 4085 | } |
|---|
| 4086 | } |
|---|
| 4087 | if ( inContext ) |
|---|
| 4088 | { |
|---|
| 4089 | break; |
|---|
| 4090 | } |
|---|
| 4091 | } |
|---|
| 4092 | } |
|---|
| 4093 | } |
|---|
| 4094 | btn.state("enabled", (!text || btn.text) && inContext); |
|---|
| 4095 | if ( typeof cmd == "function" ) |
|---|
| 4096 | { |
|---|
| 4097 | continue; |
|---|
| 4098 | } |
|---|
| 4099 | |
|---|
| 4100 | var dropdown = this.config.customSelects[cmd]; |
|---|
| 4101 | if ( ( !text || btn.text ) && ( typeof dropdown != "undefined" ) ) |
|---|
| 4102 | { |
|---|
| 4103 | dropdown.refresh(this); |
|---|
| 4104 | continue; |
|---|
| 4105 | } |
|---|
| 4106 | switch (cmd) |
|---|
| 4107 | { |
|---|
| 4108 | case "fontname": |
|---|
| 4109 | case "fontsize": |
|---|
| 4110 | if ( !text ) |
|---|
| 4111 | { |
|---|
| 4112 | try |
|---|
| 4113 | { |
|---|
| 4114 | var value = ("" + doc.queryCommandValue(cmd)).toLowerCase(); |
|---|
| 4115 | if ( !value ) |
|---|
| 4116 | { |
|---|
| 4117 | btn.element.selectedIndex = 0; |
|---|
| 4118 | break; |
|---|
| 4119 | } |
|---|
| 4120 | |
|---|
| 4121 | |
|---|
| 4122 | |
|---|
| 4123 | |
|---|
| 4124 | |
|---|
| 4125 | var options = this.config[cmd]; |
|---|
| 4126 | var sIndex = 0; |
|---|
| 4127 | for ( var j in options ) |
|---|
| 4128 | { |
|---|
| 4129 | |
|---|
| 4130 | if ( ( j.toLowerCase() == value ) || ( options[j].substr(0, value.length).toLowerCase() == value ) ) |
|---|
| 4131 | { |
|---|
| 4132 | btn.element.selectedIndex = sIndex; |
|---|
| 4133 | throw "ok"; |
|---|
| 4134 | } |
|---|
| 4135 | ++sIndex; |
|---|
| 4136 | } |
|---|
| 4137 | btn.element.selectedIndex = 0; |
|---|
| 4138 | } catch(ex) {} |
|---|
| 4139 | } |
|---|
| 4140 | break; |
|---|
| 4141 | |
|---|
| 4142 | |
|---|
| 4143 | |
|---|
| 4144 | |
|---|
| 4145 | |
|---|
| 4146 | case "formatblock": |
|---|
| 4147 | var blocks = []; |
|---|
| 4148 | for ( var indexBlock in this.config.formatblock ) |
|---|
| 4149 | { |
|---|
| 4150 | |
|---|
| 4151 | if ( typeof this.config.formatblock[indexBlock] == 'string' ) |
|---|
| 4152 | { |
|---|
| 4153 | blocks[blocks.length] = this.config.formatblock[indexBlock]; |
|---|
| 4154 | } |
|---|
| 4155 | } |
|---|
| 4156 | |
|---|
| 4157 | var deepestAncestor = this._getFirstAncestor(this.getSelection(), blocks); |
|---|
| 4158 | if ( deepestAncestor ) |
|---|
| 4159 | { |
|---|
| 4160 | for ( var x = 0; x < blocks.length; x++ ) |
|---|
| 4161 | { |
|---|
| 4162 | if ( blocks[x].toLowerCase() == deepestAncestor.tagName.toLowerCase() ) |
|---|
| 4163 | { |
|---|
| 4164 | btn.element.selectedIndex = x; |
|---|
| 4165 | } |
|---|
| 4166 | } |
|---|
| 4167 | } |
|---|
| 4168 | else |
|---|
| 4169 | { |
|---|
| 4170 | btn.element.selectedIndex = 0; |
|---|
| 4171 | } |
|---|
| 4172 | break; |
|---|
| 4173 | |
|---|
| 4174 | case "textindicator": |
|---|
| 4175 | if ( !text ) |
|---|
| 4176 | { |
|---|
| 4177 | try |
|---|
| 4178 | { |
|---|
| 4179 | var style = btn.element.style; |
|---|
| 4180 | style.backgroundColor = Xinha._makeColor(doc.queryCommandValue(Xinha.is_ie ? "backcolor" : "hilitecolor")); |
|---|
| 4181 | if ( /transparent/i.test(style.backgroundColor) ) |
|---|
| 4182 | { |
|---|
| 4183 | |
|---|
| 4184 | style.backgroundColor = Xinha._makeColor(doc.queryCommandValue("backcolor")); |
|---|
| 4185 | } |
|---|
| 4186 | style.color = Xinha._makeColor(doc.queryCommandValue("forecolor")); |
|---|
| 4187 | style.fontFamily = doc.queryCommandValue("fontname"); |
|---|
| 4188 | style.fontWeight = doc.queryCommandState("bold") ? "bold" : "normal"; |
|---|
| 4189 | style.fontStyle = doc.queryCommandState("italic") ? "italic" : "normal"; |
|---|
| 4190 | } catch (ex) { |
|---|
| 4191 | |
|---|
| 4192 | } |
|---|
| 4193 | } |
|---|
| 4194 | break; |
|---|
| 4195 | |
|---|
| 4196 | case "htmlmode": |
|---|
| 4197 | btn.state("active", text); |
|---|
| 4198 | break; |
|---|
| 4199 | |
|---|
| 4200 | case "lefttoright": |
|---|
| 4201 | case "righttoleft": |
|---|
| 4202 | var eltBlock = this.getParentElement(); |
|---|
| 4203 | while ( eltBlock && !Xinha.isBlockElement(eltBlock) ) |
|---|
| 4204 | { |
|---|
| 4205 | eltBlock = eltBlock.parentNode; |
|---|
| 4206 | } |
|---|
| 4207 | if ( eltBlock ) |
|---|
| 4208 | { |
|---|
| 4209 | btn.state("active", (eltBlock.style.direction == ((cmd == "righttoleft") ? "rtl" : "ltr"))); |
|---|
| 4210 | } |
|---|
| 4211 | break; |
|---|
| 4212 | |
|---|
| 4213 | default: |
|---|
| 4214 | cmd = cmd.replace(/(un)?orderedlist/i, "insert$1orderedlist"); |
|---|
| 4215 | try |
|---|
| 4216 | { |
|---|
| 4217 | btn.state("active", (!text && doc.queryCommandState(cmd))); |
|---|
| 4218 | } catch (ex) {} |
|---|
| 4219 | break; |
|---|
| 4220 | } |
|---|
| 4221 | } |
|---|
| 4222 | |
|---|
| 4223 | if ( this._customUndo && !this._timerUndo ) |
|---|
| 4224 | { |
|---|
| 4225 | this._undoTakeSnapshot(); |
|---|
| 4226 | var editor = this; |
|---|
| 4227 | this._timerUndo = setTimeout(function() { editor._timerUndo = null; }, this.config.undoTimeout); |
|---|
| 4228 | } |
|---|
| 4229 | this.firePluginEvent('onUpdateToolbar'); |
|---|
| 4230 | }; |
|---|
| 4231 | |
|---|
| 4232 | |
|---|
| 4233 | |
|---|
| 4234 | |
|---|
| 4235 | |
|---|
| 4236 | |
|---|
| 4237 | |
|---|
| 4238 | |
|---|
| 4239 | |
|---|
| 4240 | |
|---|
| 4241 | Xinha.getEditor = function(ref) |
|---|
| 4242 | { |
|---|
| 4243 | for ( var i = __xinhas.length; i--; ) |
|---|
| 4244 | { |
|---|
| 4245 | var editor = __xinhas[i]; |
|---|
| 4246 | if ( editor && ( editor._textArea.id == ref || editor._textArea.name == ref || editor._textArea == ref ) ) |
|---|
| 4247 | { |
|---|
| 4248 | return editor; |
|---|
| 4249 | } |
|---|
| 4250 | } |
|---|
| 4251 | return null; |
|---|
| 4252 | }; |
|---|
| 4253 | |
|---|
| 4254 | |
|---|
| 4255 | |
|---|
| 4256 | |
|---|
| 4257 | |
|---|
| 4258 | |
|---|
| 4259 | |
|---|
| 4260 | |
|---|
| 4261 | |
|---|
| 4262 | Xinha.prototype.getPluginInstance = function (plugin) |
|---|
| 4263 | { |
|---|
| 4264 | if (this.plugins[plugin]) |
|---|
| 4265 | { |
|---|
| 4266 | return this.plugins[plugin].instance; |
|---|
| 4267 | } |
|---|
| 4268 | else return null; |
|---|
| 4269 | }; |
|---|
| 4270 | |
|---|
| 4271 | |
|---|
| 4272 | |
|---|
| 4273 | Xinha.prototype.getAllAncestors = function() |
|---|
| 4274 | { |
|---|
| 4275 | var p = this.getParentElement(); |
|---|
| 4276 | var a = []; |
|---|
| 4277 | while ( p && (p.nodeType == 1) && ( p.tagName.toLowerCase() != 'body' ) ) |
|---|
| 4278 | { |
|---|
| 4279 | a.push(p); |
|---|
| 4280 | p = p.parentNode; |
|---|
| 4281 | } |
|---|
| 4282 | a.push(this._doc.body); |
|---|
| 4283 | return a; |
|---|
| 4284 | }; |
|---|
| 4285 | |
|---|
| 4286 | |
|---|
| 4287 | |
|---|
| 4288 | |
|---|
| 4289 | |
|---|
| 4290 | |
|---|
| 4291 | Xinha.prototype._getFirstAncestor = function(sel, types) |
|---|
| 4292 | { |
|---|
| 4293 | var prnt = this.activeElement(sel); |
|---|
| 4294 | if ( prnt === null ) |
|---|
| 4295 | { |
|---|
| 4296 | |
|---|
| 4297 | try |
|---|
| 4298 | { |
|---|
| 4299 | prnt = (Xinha.is_ie ? this.createRange(sel).parentElement() : this.createRange(sel).commonAncestorContainer); |
|---|
| 4300 | } |
|---|
| 4301 | catch(ex) |
|---|
| 4302 | { |
|---|
| 4303 | return null; |
|---|
| 4304 | } |
|---|
| 4305 | } |
|---|
| 4306 | |
|---|
| 4307 | if ( typeof types == 'string' ) |
|---|
| 4308 | { |
|---|
| 4309 | types = [types]; |
|---|
| 4310 | } |
|---|
| 4311 | |
|---|
| 4312 | while ( prnt ) |
|---|
| 4313 | { |
|---|
| 4314 | if ( prnt.nodeType == 1 ) |
|---|
| 4315 | { |
|---|
| 4316 | if ( types === null ) |
|---|
| 4317 | { |
|---|
| 4318 | return prnt; |
|---|
| 4319 | } |
|---|
| 4320 | if ( types.contains(prnt.tagName.toLowerCase()) ) |
|---|
| 4321 | { |
|---|
| 4322 | return prnt; |
|---|
| 4323 | } |
|---|
| 4324 | if ( prnt.tagName.toLowerCase() == 'body' ) |
|---|
| 4325 | { |
|---|
| 4326 | break; |
|---|
| 4327 | } |
|---|
| 4328 | if ( prnt.tagName.toLowerCase() == 'table' ) |
|---|
| 4329 | { |
|---|
| 4330 | break; |
|---|
| 4331 | } |
|---|
| 4332 | } |
|---|
| 4333 | prnt = prnt.parentNode; |
|---|
| 4334 | } |
|---|
| 4335 | |
|---|
| 4336 | return null; |
|---|
| 4337 | }; |
|---|
| 4338 | |
|---|
| 4339 | |
|---|
| 4340 | |
|---|
| 4341 | |
|---|
| 4342 | |
|---|
| 4343 | Xinha.prototype._getAncestorBlock = function(sel) |
|---|
| 4344 | { |
|---|
| 4345 | |
|---|
| 4346 | var prnt = (Xinha.is_ie ? this.createRange(sel).parentElement : this.createRange(sel).commonAncestorContainer); |
|---|
| 4347 | |
|---|
| 4348 | while ( prnt && ( prnt.nodeType == 1 ) ) |
|---|
| 4349 | { |
|---|
| 4350 | switch ( prnt.tagName.toLowerCase() ) |
|---|
| 4351 | { |
|---|
| 4352 | case 'div': |
|---|
| 4353 | case 'p': |
|---|
| 4354 | case 'address': |
|---|
| 4355 | case 'blockquote': |
|---|
| 4356 | case 'center': |
|---|
| 4357 | case 'del': |
|---|
| 4358 | case 'ins': |
|---|
| 4359 | case 'pre': |
|---|
| 4360 | case 'h1': |
|---|
| 4361 | case 'h2': |
|---|
| 4362 | case 'h3': |
|---|
| 4363 | case 'h4': |
|---|
| 4364 | case 'h5': |
|---|
| 4365 | case 'h6': |
|---|
| 4366 | case 'h7': |
|---|
| 4367 | |
|---|
| 4368 | return prnt; |
|---|
| 4369 | |
|---|
| 4370 | case 'body': |
|---|
| 4371 | case 'noframes': |
|---|
| 4372 | case 'dd': |
|---|
| 4373 | case 'li': |
|---|
| 4374 | case 'th': |
|---|
| 4375 | case 'td': |
|---|
| 4376 | case 'noscript' : |
|---|
| 4377 | |
|---|
| 4378 | return null; |
|---|
| 4379 | |
|---|
| 4380 | default: |
|---|
| 4381 | |
|---|
| 4382 | break; |
|---|
| 4383 | } |
|---|
| 4384 | } |
|---|
| 4385 | |
|---|
| 4386 | return null; |
|---|
| 4387 | }; |
|---|
| 4388 | |
|---|
| 4389 | |
|---|
| 4390 | |
|---|
| 4391 | |
|---|
| 4392 | |
|---|
| 4393 | Xinha.prototype._createImplicitBlock = function(type) |
|---|
| 4394 | { |
|---|
| 4395 | |
|---|
| 4396 | |
|---|
| 4397 | var sel = this.getSelection(); |
|---|
| 4398 | if ( Xinha.is_ie ) |
|---|
| 4399 | { |
|---|
| 4400 | sel.empty(); |
|---|
| 4401 | } |
|---|
| 4402 | else |
|---|
| 4403 | { |
|---|
| 4404 | sel.collapseToStart(); |
|---|
| 4405 | } |
|---|
| 4406 | |
|---|
| 4407 | var rng = this.createRange(sel); |
|---|
| 4408 | |
|---|
| 4409 | |
|---|
| 4410 | |
|---|
| 4411 | |
|---|
| 4412 | }; |
|---|
| 4413 | |
|---|
| 4414 | |
|---|
| 4415 | |
|---|
| 4416 | |
|---|
| 4417 | |
|---|
| 4418 | |
|---|
| 4419 | |
|---|
| 4420 | |
|---|
| 4421 | |
|---|
| 4422 | |
|---|
| 4423 | Xinha.prototype.surroundHTML = function(startTag, endTag) |
|---|
| 4424 | { |
|---|
| 4425 | var html = this.getSelectedHTML(); |
|---|
| 4426 | |
|---|
| 4427 | this.insertHTML(startTag + html + endTag); |
|---|
| 4428 | }; |
|---|
| 4429 | |
|---|
| 4430 | |
|---|
| 4431 | |
|---|
| 4432 | |
|---|
| 4433 | Xinha.prototype.hasSelectedText = function() |
|---|
| 4434 | { |
|---|
| 4435 | |
|---|
| 4436 | return this.getSelectedHTML() !== ''; |
|---|
| 4437 | }; |
|---|
| 4438 | |
|---|
| 4439 | |
|---|
| 4440 | |
|---|
| 4441 | |
|---|
| 4442 | |
|---|
| 4443 | |
|---|
| 4444 | |
|---|
| 4445 | |
|---|
| 4446 | |
|---|
| 4447 | |
|---|
| 4448 | |
|---|
| 4449 | Xinha.prototype._comboSelected = function(el, txt) |
|---|
| 4450 | { |
|---|
| 4451 | this.focusEditor(); |
|---|
| 4452 | var value = el.options[el.selectedIndex].value; |
|---|
| 4453 | switch (txt) |
|---|
| 4454 | { |
|---|
| 4455 | case "fontname": |
|---|
| 4456 | case "fontsize": |
|---|
| 4457 | this.execCommand(txt, false, value); |
|---|
| 4458 | break; |
|---|
| 4459 | case "formatblock": |
|---|
| 4460 | |
|---|
| 4461 | if ( !value ) |
|---|
| 4462 | { |
|---|
| 4463 | this.updateToolbar(); |
|---|
| 4464 | break; |
|---|
| 4465 | } |
|---|
| 4466 | if( !Xinha.is_gecko || value !== 'blockquote' ) |
|---|
| 4467 | { |
|---|
| 4468 | value = "<" + value + ">"; |
|---|
| 4469 | } |
|---|
| 4470 | this.execCommand(txt, false, value); |
|---|
| 4471 | break; |
|---|
| 4472 | default: |
|---|
| 4473 | |
|---|
| 4474 | var dropdown = this.config.customSelects[txt]; |
|---|
| 4475 | if ( typeof dropdown != "undefined" ) |
|---|
| 4476 | { |
|---|
| 4477 | dropdown.action(this); |
|---|
| 4478 | } |
|---|
| 4479 | else |
|---|
| 4480 | { |
|---|
| 4481 | alert("FIXME: combo box " + txt + " not implemented"); |
|---|
| 4482 | } |
|---|
| 4483 | break; |
|---|
| 4484 | } |
|---|
| 4485 | }; |
|---|
| 4486 | |
|---|
| 4487 | |
|---|
| 4488 | |
|---|
| 4489 | |
|---|
| 4490 | |
|---|
| 4491 | Xinha.prototype._colorSelector = function(cmdID) |
|---|
| 4492 | { |
|---|
| 4493 | var editor = this; |
|---|
| 4494 | |
|---|
| 4495 | |
|---|
| 4496 | |
|---|
| 4497 | if ( Xinha.is_gecko ) |
|---|
| 4498 | { |
|---|
| 4499 | try |
|---|
| 4500 | { |
|---|
| 4501 | editor._doc.execCommand('useCSS', false, false); |
|---|
| 4502 | editor._doc.execCommand('styleWithCSS', false, true); |
|---|
| 4503 | |
|---|
| 4504 | } catch (ex) {} |
|---|
| 4505 | } |
|---|
| 4506 | |
|---|
| 4507 | var btn = editor._toolbarObjects[cmdID].element; |
|---|
| 4508 | var initcolor; |
|---|
| 4509 | if ( cmdID == 'hilitecolor' ) |
|---|
| 4510 | { |
|---|
| 4511 | if ( Xinha.is_ie ) |
|---|
| 4512 | { |
|---|
| 4513 | cmdID = 'backcolor'; |
|---|
| 4514 | initcolor = Xinha._colorToRgb(editor._doc.queryCommandValue("backcolor")); |
|---|
| 4515 | } |
|---|
| 4516 | else |
|---|
| 4517 | { |
|---|
| 4518 | initcolor = Xinha._colorToRgb(editor._doc.queryCommandValue("hilitecolor")); |
|---|
| 4519 | } |
|---|
| 4520 | } |
|---|
| 4521 | else |
|---|
| 4522 | { |
|---|
| 4523 | initcolor = Xinha._colorToRgb(editor._doc.queryCommandValue("forecolor")); |
|---|
| 4524 | } |
|---|
| 4525 | var cback = function(color) { editor._doc.execCommand(cmdID, false, color); }; |
|---|
| 4526 | if ( Xinha.is_ie ) |
|---|
| 4527 | { |
|---|
| 4528 | var range = editor.createRange(editor.getSelection()); |
|---|
| 4529 | cback = function(color) |
|---|
| 4530 | { |
|---|
| 4531 | range.select(); |
|---|
| 4532 | editor._doc.execCommand(cmdID, false, color); |
|---|
| 4533 | }; |
|---|
| 4534 | } |
|---|
| 4535 | var picker = new Xinha.colorPicker( |
|---|
| 4536 | { |
|---|
| 4537 | cellsize:editor.config.colorPickerCellSize, |
|---|
| 4538 | callback:cback, |
|---|
| 4539 | granularity:editor.config.colorPickerGranularity, |
|---|
| 4540 | websafe:editor.config.colorPickerWebSafe, |
|---|
| 4541 | savecolors:editor.config.colorPickerSaveColors |
|---|
| 4542 | }); |
|---|
| 4543 | picker.open(editor.config.colorPickerPosition, btn, initcolor); |
|---|
| 4544 | }; |
|---|
| 4545 | |
|---|
| 4546 | |
|---|
| 4547 | |
|---|
| 4548 | |
|---|
| 4549 | |
|---|
| 4550 | |
|---|
| 4551 | |
|---|
| 4552 | |
|---|
| 4553 | |
|---|
| 4554 | |
|---|
| 4555 | |
|---|
| 4556 | |
|---|
| 4557 | |
|---|
| 4558 | |
|---|
| 4559 | |
|---|
| 4560 | Xinha.prototype.execCommand = function(cmdID, UI, param) |
|---|
| 4561 | { |
|---|
| 4562 | var editor = this; |
|---|
| 4563 | this.focusEditor(); |
|---|
| 4564 | cmdID = cmdID.toLowerCase(); |
|---|
| 4565 | |
|---|
| 4566 | |
|---|
| 4567 | if(this.firePluginEvent('onExecCommand', cmdID, UI, param)) |
|---|
| 4568 | { |
|---|
| 4569 | this.updateToolbar(); |
|---|
| 4570 | return false; |
|---|
| 4571 | } |
|---|
| 4572 | |
|---|
| 4573 | switch (cmdID) |
|---|
| 4574 | { |
|---|
| 4575 | case "htmlmode": |
|---|
| 4576 | this.setMode(); |
|---|
| 4577 | break; |
|---|
| 4578 | |
|---|
| 4579 | case "hilitecolor": |
|---|
| 4580 | case "forecolor": |
|---|
| 4581 | this._colorSelector(cmdID); |
|---|
| 4582 | break; |
|---|
| 4583 | |
|---|
| 4584 | case "createlink": |
|---|
| 4585 | this._createLink(); |
|---|
| 4586 | break; |
|---|
| 4587 | |
|---|
| 4588 | case "undo": |
|---|
| 4589 | case "redo": |
|---|
| 4590 | if (this._customUndo) |
|---|
| 4591 | { |
|---|
| 4592 | this[cmdID](); |
|---|
| 4593 | } |
|---|
| 4594 | else |
|---|
| 4595 | { |
|---|
| 4596 | this._doc.execCommand(cmdID, UI, param); |
|---|
| 4597 | } |
|---|
| 4598 | break; |
|---|
| 4599 | |
|---|
| 4600 | case "inserttable": |
|---|
| 4601 | this._insertTable(); |
|---|
| 4602 | break; |
|---|
| 4603 | |
|---|
| 4604 | case "insertimage": |
|---|
| 4605 | this._insertImage(); |
|---|
| 4606 | break; |
|---|
| 4607 | |
|---|
| 4608 | case "about": |
|---|
| 4609 | this._popupDialog(editor.config.URIs.about, null, this); |
|---|
| 4610 | break; |
|---|
| 4611 | |
|---|
| 4612 | case "showhelp": |
|---|
| 4613 | this._popupDialog(editor.config.URIs.help, null, this); |
|---|
| 4614 | break; |
|---|
| 4615 | |
|---|
| 4616 | case "killword": |
|---|
| 4617 | this._wordClean(); |
|---|
| 4618 | break; |
|---|
| 4619 | |
|---|
| 4620 | case "cut": |
|---|
| 4621 | case "copy": |
|---|
| 4622 | case "paste": |
|---|
| 4623 | this._doc.execCommand(cmdID, UI, param); |
|---|
| 4624 | if ( this.config.killWordOnPaste ) |
|---|
| 4625 | { |
|---|
| 4626 | this._wordClean(); |
|---|
| 4627 | } |
|---|
| 4628 | break; |
|---|
| 4629 | case "lefttoright": |
|---|
| 4630 | case "righttoleft": |
|---|
| 4631 | if (this.config.changeJustifyWithDirection) |
|---|
| 4632 | { |
|---|
| 4633 | this._doc.execCommand((cmdID == "righttoleft") ? "justifyright" : "justifyleft", UI, param); |
|---|
| 4634 | } |
|---|
| 4635 | var dir = (cmdID == "righttoleft") ? "rtl" : "ltr"; |
|---|
| 4636 | var el = this.getParentElement(); |
|---|
| 4637 | while ( el && !Xinha.isBlockElement(el) ) |
|---|
| 4638 | { |
|---|
| 4639 | el = el.parentNode; |
|---|
| 4640 | } |
|---|
| 4641 | if ( el ) |
|---|
| 4642 | { |
|---|
| 4643 | if ( el.style.direction == dir ) |
|---|
| 4644 | { |
|---|
| 4645 | el.style.direction = ""; |
|---|
| 4646 | } |
|---|
| 4647 | else |
|---|
| 4648 | { |
|---|
| 4649 | el.style.direction = dir; |
|---|
| 4650 | } |
|---|
| 4651 | } |
|---|
| 4652 | break; |
|---|
| 4653 | |
|---|
| 4654 | case 'justifyleft' : |
|---|
| 4655 | case 'justifyright' : |
|---|
| 4656 | { |
|---|
| 4657 | cmdID.match(/^justify(.*)$/); |
|---|
| 4658 | var ae = this.activeElement(this.getSelection()); |
|---|
| 4659 | if(ae && ae.tagName.toLowerCase() == 'img') |
|---|
| 4660 | { |
|---|
| 4661 | ae.align = ae.align == RegExp.$1 ? '' : RegExp.$1; |
|---|
| 4662 | } |
|---|
| 4663 | else |
|---|
| 4664 | { |
|---|
| 4665 | this._doc.execCommand(cmdID, UI, param); |
|---|
| 4666 | } |
|---|
| 4667 | } |
|---|
| 4668 | break; |
|---|
| 4669 | |
|---|
| 4670 | default: |
|---|
| 4671 | try |
|---|
| 4672 | { |
|---|
| 4673 | this._doc.execCommand(cmdID, UI, param); |
|---|
| 4674 | } |
|---|
| 4675 | catch(ex) |
|---|
| 4676 | { |
|---|
| 4677 | if ( this.config.debug ) |
|---|
| 4678 | { |
|---|
| 4679 | alert(ex + "\n\nby execCommand(" + cmdID + ");"); |
|---|
| 4680 | } |
|---|
| 4681 | } |
|---|
| 4682 | break; |
|---|
| 4683 | } |
|---|
| 4684 | |
|---|
| 4685 | this.updateToolbar(); |
|---|
| 4686 | return false; |
|---|
| 4687 | }; |
|---|
| 4688 | |
|---|
| 4689 | |
|---|
| 4690 | |
|---|
| 4691 | |
|---|
| 4692 | |
|---|
| 4693 | |
|---|
| 4694 | |
|---|
| 4695 | |
|---|
| 4696 | Xinha.prototype._editorEvent = function(ev) |
|---|
| 4697 | { |
|---|
| 4698 | var editor = this; |
|---|
| 4699 | |
|---|
| 4700 | |
|---|
| 4701 | if ( typeof editor._textArea['on'+ev.type] == "function" ) |
|---|
| 4702 | { |
|---|
| 4703 | editor._textArea['on'+ev.type](); |
|---|
| 4704 | } |
|---|
| 4705 | |
|---|
| 4706 | if ( this.isKeyEvent(ev) ) |
|---|
| 4707 | { |
|---|
| 4708 | |
|---|
| 4709 | if(editor.firePluginEvent('onKeyPress', ev)) |
|---|
| 4710 | { |
|---|
| 4711 | return false; |
|---|
| 4712 | } |
|---|
| 4713 | |
|---|
| 4714 | |
|---|
| 4715 | if ( this.isShortCut( ev ) ) |
|---|
| 4716 | { |
|---|
| 4717 | this._shortCuts(ev); |
|---|
| 4718 | } |
|---|
| 4719 | } |
|---|
| 4720 | |
|---|
| 4721 | if ( ev.type == 'mousedown' ) |
|---|
| 4722 | { |
|---|
| 4723 | if(editor.firePluginEvent('onMouseDown', ev)) |
|---|
| 4724 | { |
|---|
| 4725 | return false; |
|---|
| 4726 | } |
|---|
| 4727 | } |
|---|
| 4728 | |
|---|
| 4729 | |
|---|
| 4730 | |
|---|
| 4731 | |
|---|
| 4732 | |
|---|
| 4733 | |
|---|
| 4734 | if (this.currentModal) |
|---|
| 4735 | { |
|---|
| 4736 | return false; |
|---|
| 4737 | } |
|---|
| 4738 | |
|---|
| 4739 | |
|---|
| 4740 | if ( editor._timerToolbar ) |
|---|
| 4741 | { |
|---|
| 4742 | clearTimeout(editor._timerToolbar); |
|---|
| 4743 | } |
|---|
| 4744 | if (!this.suspendUpdateToolbar) |
|---|
| 4745 | { |
|---|
| 4746 | editor._timerToolbar = setTimeout( |
|---|
| 4747 | function() |
|---|
| 4748 | { |
|---|
| 4749 | editor.updateToolbar(); |
|---|
| 4750 | editor._timerToolbar = null; |
|---|
| 4751 | }, |
|---|
| 4752 | 250); |
|---|
| 4753 | } |
|---|
| 4754 | }; |
|---|
| 4755 | |
|---|
| 4756 | |
|---|
| 4757 | |
|---|
| 4758 | |
|---|
| 4759 | |
|---|
| 4760 | |
|---|
| 4761 | Xinha.prototype._shortCuts = function (ev) |
|---|
| 4762 | { |
|---|
| 4763 | var key = this.getKey(ev).toLowerCase(); |
|---|
| 4764 | var cmd = null; |
|---|
| 4765 | var value = null; |
|---|
| 4766 | switch (key) |
|---|
| 4767 | { |
|---|
| 4768 | |
|---|
| 4769 | |
|---|
| 4770 | case 'b': cmd = "bold"; break; |
|---|
| 4771 | case 'i': cmd = "italic"; break; |
|---|
| 4772 | case 'u': cmd = "underline"; break; |
|---|
| 4773 | case 's': cmd = "strikethrough"; break; |
|---|
| 4774 | case 'l': cmd = "justifyleft"; break; |
|---|
| 4775 | case 'e': cmd = "justifycenter"; break; |
|---|
| 4776 | case 'r': cmd = "justifyright"; break; |
|---|
| 4777 | case 'j': cmd = "justifyfull"; break; |
|---|
| 4778 | case 'z': cmd = "undo"; break; |
|---|
| 4779 | case 'y': cmd = "redo"; break; |
|---|
| 4780 | case 'v': cmd = "paste"; break; |
|---|
| 4781 | case 'n': |
|---|
| 4782 | cmd = "formatblock"; |
|---|
| 4783 | value = "p"; |
|---|
| 4784 | break; |
|---|
| 4785 | |
|---|
| 4786 | case '0': cmd = "killword"; break; |
|---|
| 4787 | |
|---|
| 4788 | |
|---|
| 4789 | case '1': |
|---|
| 4790 | case '2': |
|---|
| 4791 | case '3': |
|---|
| 4792 | case '4': |
|---|
| 4793 | case '5': |
|---|
| 4794 | case '6': |
|---|
| 4795 | cmd = "formatblock"; |
|---|
| 4796 | value = "h" + key; |
|---|
| 4797 | break; |
|---|
| 4798 | } |
|---|
| 4799 | if ( cmd ) |
|---|
| 4800 | { |
|---|
| 4801 | |
|---|
| 4802 | this.execCommand(cmd, false, value); |
|---|
| 4803 | Xinha._stopEvent(ev); |
|---|
| 4804 | } |
|---|
| 4805 | }; |
|---|
| 4806 | |
|---|
| 4807 | |
|---|
| 4808 | |
|---|
| 4809 | |
|---|
| 4810 | |
|---|
| 4811 | Xinha.prototype.convertNode = function(el, newTagName) |
|---|
| 4812 | { |
|---|
| 4813 | var newel = this._doc.createElement(newTagName); |
|---|
| 4814 | while ( el.firstChild ) |
|---|
| 4815 | { |
|---|
| 4816 | newel.appendChild(el.firstChild); |
|---|
| 4817 | } |
|---|
| 4818 | return newel; |
|---|
| 4819 | }; |
|---|
| 4820 | |
|---|
| 4821 | |
|---|
| 4822 | |
|---|
| 4823 | |
|---|
| 4824 | Xinha.prototype.scrollToElement = function(e) |
|---|
| 4825 | { |
|---|
| 4826 | if(!e) |
|---|
| 4827 | { |
|---|
| 4828 | e = this.getParentElement(); |
|---|
| 4829 | if(!e) return; |
|---|
| 4830 | } |
|---|
| 4831 | |
|---|
| 4832 | |
|---|
| 4833 | var position = Xinha.getElementTopLeft(e); |
|---|
| 4834 | this._iframe.contentWindow.scrollTo(position.left, position.top); |
|---|
| 4835 | }; |
|---|
| 4836 | |
|---|
| 4837 | |
|---|
| 4838 | |
|---|
| 4839 | |
|---|
| 4840 | |
|---|
| 4841 | |
|---|
| 4842 | Xinha.prototype.getEditorContent = function() |
|---|
| 4843 | { |
|---|
| 4844 | return this.outwardHtml(this.getHTML()); |
|---|
| 4845 | } |
|---|
| 4846 | |
|---|
| 4847 | |
|---|
| 4848 | |
|---|
| 4849 | |
|---|
| 4850 | |
|---|
| 4851 | |
|---|
| 4852 | Xinha.prototype.setEditorContent = function(html) |
|---|
| 4853 | { |
|---|
| 4854 | this.setHTML(this.inwardHtml(html)); |
|---|
| 4855 | } |
|---|
| 4856 | |
|---|
| 4857 | |
|---|
| 4858 | |
|---|
| 4859 | |
|---|
| 4860 | |
|---|
| 4861 | |
|---|
| 4862 | Xinha.prototype.getHTML = function() |
|---|
| 4863 | { |
|---|
| 4864 | var html = ''; |
|---|
| 4865 | switch ( this._editMode ) |
|---|
| 4866 | { |
|---|
| 4867 | case "wysiwyg": |
|---|
| 4868 | if ( !this.config.fullPage ) |
|---|
| 4869 | { |
|---|
| 4870 | html = Xinha.getHTML(this._doc.body, false, this).trim(); |
|---|
| 4871 | } |
|---|
| 4872 | else |
|---|
| 4873 | { |
|---|
| 4874 | html = this.doctype + "\n" + Xinha.getHTML(this._doc.documentElement, true, this); |
|---|
| 4875 | } |
|---|
| 4876 | break; |
|---|
| 4877 | case "textmode": |
|---|
| 4878 | html = this._textArea.value; |
|---|
| 4879 | break; |
|---|
| 4880 | default: |
|---|
| 4881 | alert("Mode <" + this._editMode + "> not defined!"); |
|---|
| 4882 | return false; |
|---|
| 4883 | } |
|---|
| 4884 | return html; |
|---|
| 4885 | }; |
|---|
| 4886 | |
|---|
| 4887 | |
|---|
| 4888 | |
|---|
| 4889 | |
|---|
| 4890 | |
|---|
| 4891 | |
|---|
| 4892 | |
|---|
| 4893 | |
|---|
| 4894 | |
|---|
| 4895 | |
|---|
| 4896 | Xinha.prototype.outwardHtml = function(html) |
|---|
| 4897 | { |
|---|
| 4898 | for ( var i in this.plugins ) |
|---|
| 4899 | { |
|---|
| 4900 | var plugin = this.plugins[i].instance; |
|---|
| 4901 | if ( plugin && typeof plugin.outwardHtml == "function" ) |
|---|
| 4902 | { |
|---|
| 4903 | html = plugin.outwardHtml(html); |
|---|
| 4904 | } |
|---|
| 4905 | } |
|---|
| 4906 | |
|---|
| 4907 | html = html.replace(/<(\/?)b(\s|>|\/)/ig, "<$1strong$2"); |
|---|
| 4908 | html = html.replace(/<(\/?)i(\s|>|\/)/ig, "<$1em$2"); |
|---|
| 4909 | html = html.replace(/<(\/?)strike(\s|>|\/)/ig, "<$1del$2"); |
|---|
| 4910 | |
|---|
| 4911 | |
|---|
| 4912 | html = html.replace(/(<[^>]*on(click|mouse(over|out|up|down))=['"])if\(window\.parent && window\.parent\.Xinha\)\{return false\}/gi,'$1'); |
|---|
| 4913 | |
|---|
| 4914 | // Figure out what our server name is, and how it's referenced |
|---|
| 4915 | var serverBase = location.href.replace(/(https?:\/\/[^\/]*)\/.*/, '$1') + '/'; |
|---|
| 4916 | |
|---|
| 4917 | |
|---|
| 4918 | |
|---|
| 4919 | |
|---|
| 4920 | |
|---|
| 4921 | html = html.replace(/https?:\/\/null\ |
|---|
| 4922 | |
|---|
| 4923 | |
|---|
| 4924 | |
|---|
| 4925 | |
|---|
| 4926 | html = html.replace(/((href|src|background)=[\'\"])\/+/ig, '$1' + serverBase); |
|---|
| 4927 | |
|---|
| 4928 | html = this.outwardSpecialReplacements(html); |
|---|
| 4929 | |
|---|
| 4930 | html = this.fixRelativeLinks(html); |
|---|
| 4931 | |
|---|
| 4932 | if ( this.config.sevenBitClean ) |
|---|
| 4933 | { |
|---|
| 4934 | html = html.replace(/[^ -~\r\n\t]/g, function(c) { return '&#'+c.charCodeAt(0)+';'; }); |
|---|
| 4935 | } |
|---|
| 4936 | |
|---|
| 4937 | //prevent execution of JavaScript (Ticket #685) |
|---|
| 4938 | html = html.replace(/(<script[^>]*((type=[\"\']text\/)|(language=[\"\'])))(freezescript)/gi,"$1javascript"); |
|---|
| 4939 | |
|---|
| 4940 | // If in fullPage mode, strip the coreCSS |
|---|
| 4941 | if(this.config.fullPage) |
|---|
| 4942 | { |
|---|
| 4943 | html = Xinha.stripCoreCSS(html); |
|---|
| 4944 | } |
|---|
| 4945 | |
|---|
| 4946 | if (typeof this.config.outwardHtml == 'function' ) |
|---|
| 4947 | { |
|---|
| 4948 | html = this.config.outwardHtml(html); |
|---|
| 4949 | } |
|---|
| 4950 | |
|---|
| 4951 | return html; |
|---|
| 4952 | }; |
|---|
| 4953 | |
|---|
| 4954 | /** Performs various transformations of the HTML to be edited |
|---|
| 4955 | * Plugins can provide their own, additional transformations by defining a plugin.prototype.inwardHtml() implematation, |
|---|
| 4956 | * which is called by this function |
|---|
| 4957 | * |
|---|
| 4958 | * @private |
|---|
| 4959 | * @see Xinha#outwardHtml |
|---|
| 4960 | * @param {String} html |
|---|
| 4961 | * @returns {String} transformed HTML |
|---|
| 4962 | */ |
|---|
| 4963 | Xinha.prototype.inwardHtml = function(html) |
|---|
| 4964 | { |
|---|
| 4965 | for ( var i in this.plugins ) |
|---|
| 4966 | { |
|---|
| 4967 | var plugin = this.plugins[i].instance; |
|---|
| 4968 | if ( plugin && typeof plugin.inwardHtml == "function" ) |
|---|
| 4969 | { |
|---|
| 4970 | html = plugin.inwardHtml(html); |
|---|
| 4971 | } |
|---|
| 4972 | } |
|---|
| 4973 | |
|---|
| 4974 | // Both IE and Gecko use strike instead of del (#523) |
|---|
| 4975 | html = html.replace(/<(\/?)del(\s|>|\/)/ig, "<$1strike$2"); |
|---|
| 4976 | |
|---|
| 4977 | // disable inline event handle inside Xinha iframe |
|---|
| 4978 | html = html.replace(/(<[^>]*on(click|mouse(over|out|up|down))=["'])/gi,'$1if(window.parent && window.parent.Xinha){return false}'); |
|---|
| 4979 | |
|---|
| 4980 | html = this.inwardSpecialReplacements(html); |
|---|
| 4981 | |
|---|
| 4982 | html = html.replace(/(<script[^>]*((type=[\"\']text\/)|(language=[\"\'])))(javascript)/gi,"$1freezescript"); |
|---|
| 4983 | |
|---|
| 4984 | // For IE's sake, make any URLs that are semi-absolute (="/....") to be |
|---|
| 4985 | // truely absolute |
|---|
| 4986 | var nullRE = new RegExp('((href|src|background)=[\'"])/+', 'gi'); |
|---|
| 4987 | html = html.replace(nullRE, '$1' + location.href.replace(/(https?:\/\/[^\/]*)\/.*/, '$1') + '/'); |
|---|
| 4988 | |
|---|
| 4989 | html = this.fixRelativeLinks(html); |
|---|
| 4990 | |
|---|
| 4991 | // If in fullPage mode, add the coreCSS |
|---|
| 4992 | if(this.config.fullPage) |
|---|
| 4993 | { |
|---|
| 4994 | html = Xinha.addCoreCSS(html); |
|---|
| 4995 | } |
|---|
| 4996 | |
|---|
| 4997 | if (typeof this.config.inwardHtml == 'function' ) |
|---|
| 4998 | { |
|---|
| 4999 | html = this.config.inwardHtml(html); |
|---|
| 5000 | } |
|---|
| 5001 | |
|---|
| 5002 | return html; |
|---|
| 5003 | }; |
|---|
| 5004 | /** Apply the replacements defined in Xinha.Config.specialReplacements |
|---|
| 5005 | * |
|---|
| 5006 | * @private |
|---|
| 5007 | * @see Xinha#inwardSpecialReplacements |
|---|
| 5008 | * @param {String} html |
|---|
| 5009 | * @returns {String} transformed HTML |
|---|
| 5010 | */ |
|---|
| 5011 | Xinha.prototype.outwardSpecialReplacements = function(html) |
|---|
| 5012 | { |
|---|
| 5013 | for ( var i in this.config.specialReplacements ) |
|---|
| 5014 | { |
|---|
| 5015 | var from = this.config.specialReplacements[i]; |
|---|
| 5016 | var to = i; // why are declaring a new variable here ? Seems to be better to just do : for (var to in config) |
|---|
| 5017 | // prevent iterating over wrong type |
|---|
| 5018 | if ( typeof from.replace != 'function' || typeof to.replace != 'function' ) |
|---|
| 5019 | { |
|---|
| 5020 | continue; |
|---|
| 5021 | } |
|---|
| 5022 | // alert('out : ' + from + '=>' + to); |
|---|
| 5023 | var reg = new RegExp(Xinha.escapeStringForRegExp(from), 'g'); |
|---|
| 5024 | html = html.replace(reg, to.replace(/\$/g, '$$$$')); |
|---|
| 5025 | //html = html.replace(from, to); |
|---|
| 5026 | } |
|---|
| 5027 | return html; |
|---|
| 5028 | }; |
|---|
| 5029 | /** Apply the replacements defined in Xinha.Config.specialReplacements |
|---|
| 5030 | * |
|---|
| 5031 | * @private |
|---|
| 5032 | * @see Xinha#outwardSpecialReplacements |
|---|
| 5033 | * @param {String} html |
|---|
| 5034 | * @returns {String} transformed HTML |
|---|
| 5035 | */ |
|---|
| 5036 | Xinha.prototype.inwardSpecialReplacements = function(html) |
|---|
| 5037 | { |
|---|
| 5038 | // alert("inward"); |
|---|
| 5039 | for ( var i in this.config.specialReplacements ) |
|---|
| 5040 | { |
|---|
| 5041 | var from = i; // why are declaring a new variable here ? Seems to be better to just do : for (var from in config) |
|---|
| 5042 | var to = this.config.specialReplacements[i]; |
|---|
| 5043 | // prevent iterating over wrong type |
|---|
| 5044 | if ( typeof from.replace != 'function' || typeof to.replace != 'function' ) |
|---|
| 5045 | { |
|---|
| 5046 | continue; |
|---|
| 5047 | } |
|---|
| 5048 | // alert('in : ' + from + '=>' + to); |
|---|
| 5049 | // |
|---|
| 5050 | // html = html.replace(reg, to); |
|---|
| 5051 | // html = html.replace(from, to); |
|---|
| 5052 | var reg = new RegExp(Xinha.escapeStringForRegExp(from), 'g'); |
|---|
| 5053 | html = html.replace(reg, to.replace(/\$/g, '$$$$')); // IE uses doubled dollar signs to escape backrefs, also beware that IE also implements $& $_ and $' like perl. |
|---|
| 5054 | } |
|---|
| 5055 | return html; |
|---|
| 5056 | }; |
|---|
| 5057 | |
|---|
| 5058 | |
|---|
| 5059 | |
|---|
| 5060 | |
|---|
| 5061 | |
|---|
| 5062 | |
|---|
| 5063 | |
|---|
| 5064 | |
|---|
| 5065 | |
|---|
| 5066 | |
|---|
| 5067 | Xinha.prototype.fixRelativeLinks = function(html) |
|---|
| 5068 | { |
|---|
| 5069 | if ( typeof this.config.expandRelativeUrl != 'undefined' && this.config.expandRelativeUrl ) |
|---|
| 5070 | var src = html.match(/(src|href)="([^"]*)"/gi); |
|---|
| 5071 | var b = document.location.href; |
|---|
| 5072 | if ( src ) |
|---|
| 5073 | { |
|---|
| 5074 | var url,url_m,relPath,base_m,absPath |
|---|
| 5075 | for ( var i=0;i<src.length;++i ) |
|---|
| 5076 | { |
|---|
| 5077 | url = src[i].match(/(src|href)="([^"]*)"/i); |
|---|
| 5078 | url_m = url[2].match( /\.\.\ |
|---|
| 5079 | if ( url_m ) |
|---|
| 5080 | { |
|---|
| 5081 | relPath = new RegExp( "(.*?)(([^\/]*\/){"+ url_m.length+"})[^\/]*$" ); |
|---|
| 5082 | base_m = b.match( relPath ); |
|---|
| 5083 | absPath = url[2].replace(/(\.\.\/)*/,base_m[1]); |
|---|
| 5084 | html = html.replace( new RegExp(Xinha.escapeStringForRegExp(url[2])),absPath ); |
|---|
| 5085 | } |
|---|
| 5086 | } |
|---|
| 5087 | } |
|---|
| 5088 | |
|---|
| 5089 | if ( typeof this.config.stripSelfNamedAnchors != 'undefined' && this.config.stripSelfNamedAnchors ) |
|---|
| 5090 | { |
|---|
| 5091 | var stripRe = new RegExp("((href|src|background)=\")("+Xinha.escapeStringForRegExp(unescape(document.location.href.replace(/&/g,'&'))) + ')([#?][^\'" ]*)', 'g'); |
|---|
| 5092 | html = html.replace(stripRe, '$1$4'); |
|---|
| 5093 | } |
|---|
| 5094 | |
|---|
| 5095 | if ( typeof this.config.stripBaseHref != 'undefined' && this.config.stripBaseHref ) |
|---|
| 5096 | { |
|---|
| 5097 | var baseRe = null; |
|---|
| 5098 | if ( typeof this.config.baseHref != 'undefined' && this.config.baseHref !== null ) |
|---|
| 5099 | { |
|---|
| 5100 | baseRe = new RegExp( "((href|src|background|action)=\")(" + Xinha.escapeStringForRegExp(this.config.baseHref.replace(/([^\/]\/)(?=.+\.)[^\/]*$/, "$1")) + ")", 'g' ); |
|---|
| 5101 | html = html.replace(baseRe, '$1'); |
|---|
| 5102 | } |
|---|
| 5103 | baseRe = new RegExp( "((href|src|background|action)=\")(" + Xinha.escapeStringForRegExp(document.location.href.replace( /^(https?:\/\/[^\/]*)(.*)/, '$1' )) + ")", 'g' ); |
|---|
| 5104 | html = html.replace(baseRe, '$1'); |
|---|
| 5105 | } |
|---|
| 5106 | |
|---|
| 5107 | return html; |
|---|
| 5108 | }; |
|---|
| 5109 | |
|---|
| 5110 | |
|---|
| 5111 | |
|---|
| 5112 | |
|---|
| 5113 | |
|---|
| 5114 | |
|---|
| 5115 | Xinha.prototype.getInnerHTML = function() |
|---|
| 5116 | { |
|---|
| 5117 | if ( !this._doc.body ) |
|---|
| 5118 | { |
|---|
| 5119 | return ''; |
|---|
| 5120 | } |
|---|
| 5121 | var html = ""; |
|---|
| 5122 | switch ( this._editMode ) |
|---|
| 5123 | { |
|---|
| 5124 | case "wysiwyg": |
|---|
| 5125 | if ( !this.config.fullPage ) |
|---|
| 5126 | { |
|---|
| 5127 | |
|---|
| 5128 | html = this._doc.body.innerHTML; |
|---|
| 5129 | } |
|---|
| 5130 | else |
|---|
| 5131 | { |
|---|
| 5132 | html = this.doctype + "\n" + this._doc.documentElement.innerHTML; |
|---|
| 5133 | } |
|---|
| 5134 | break; |
|---|
| 5135 | case "textmode" : |
|---|
| 5136 | html = this._textArea.value; |
|---|
| 5137 | break; |
|---|
| 5138 | default: |
|---|
| 5139 | alert("Mode <" + this._editMode + "> not defined!"); |
|---|
| 5140 | return false; |
|---|
| 5141 | } |
|---|
| 5142 | |
|---|
| 5143 | return html; |
|---|
| 5144 | }; |
|---|
| 5145 | |
|---|
| 5146 | |
|---|
| 5147 | |
|---|
| 5148 | |
|---|
| 5149 | |
|---|
| 5150 | |
|---|
| 5151 | Xinha.prototype.setHTML = function(html) |
|---|
| 5152 | { |
|---|
| 5153 | if ( !this.config.fullPage ) |
|---|
| 5154 | { |
|---|
| 5155 | this._doc.body.innerHTML = html; |
|---|
| 5156 | } |
|---|
| 5157 | else |
|---|
| 5158 | { |
|---|
| 5159 | this.setFullHTML(html); |
|---|
| 5160 | } |
|---|
| 5161 | this._textArea.value = html; |
|---|
| 5162 | }; |
|---|
| 5163 | |
|---|
| 5164 | |
|---|
| 5165 | |
|---|
| 5166 | |
|---|
| 5167 | |
|---|
| 5168 | |
|---|
| 5169 | Xinha.prototype.setDoctype = function(doctype) |
|---|
| 5170 | { |
|---|
| 5171 | this.doctype = doctype; |
|---|
| 5172 | }; |
|---|
| 5173 | |
|---|
| 5174 | |
|---|
| 5175 | |
|---|
| 5176 | |
|---|
| 5177 | |
|---|
| 5178 | |
|---|
| 5179 | |
|---|
| 5180 | |
|---|
| 5181 | |
|---|
| 5182 | |
|---|
| 5183 | |
|---|
| 5184 | Xinha._object = null; |
|---|
| 5185 | |
|---|
| 5186 | |
|---|
| 5187 | |
|---|
| 5188 | Array.prototype.isArray = true; |
|---|
| 5189 | |
|---|
| 5190 | |
|---|
| 5191 | RegExp.prototype.isRegExp = true; |
|---|
| 5192 | |
|---|
| 5193 | |
|---|
| 5194 | |
|---|
| 5195 | |
|---|
| 5196 | |
|---|
| 5197 | |
|---|
| 5198 | Xinha.cloneObject = function(obj) |
|---|
| 5199 | { |
|---|
| 5200 | if ( !obj ) |
|---|
| 5201 | { |
|---|
| 5202 | return null; |
|---|
| 5203 | } |
|---|
| 5204 | var newObj = (obj.isArray ) ? [] : {}; |
|---|
| 5205 | |
|---|
| 5206 | |
|---|
| 5207 | if ( obj.constructor.toString().match( /\s*function Function\(/ ) || typeof obj == 'function' ) |
|---|
| 5208 | { |
|---|
| 5209 | newObj = obj; |
|---|
| 5210 | } |
|---|
| 5211 | else if ( obj.isRegExp ) |
|---|
| 5212 | { |
|---|
| 5213 | newObj = eval( obj.toString() ); |
|---|
| 5214 | } |
|---|
| 5215 | else |
|---|
| 5216 | { |
|---|
| 5217 | for ( var n in obj ) |
|---|
| 5218 | { |
|---|
| 5219 | var node = obj[n]; |
|---|
| 5220 | if ( typeof node == 'object' ) |
|---|
| 5221 | { |
|---|
| 5222 | newObj[n] = Xinha.cloneObject(node); |
|---|
| 5223 | } |
|---|
| 5224 | else |
|---|
| 5225 | { |
|---|
| 5226 | newObj[n] = node; |
|---|
| 5227 | } |
|---|
| 5228 | } |
|---|
| 5229 | } |
|---|
| 5230 | |
|---|
| 5231 | return newObj; |
|---|
| 5232 | }; |
|---|
| 5233 | |
|---|
| 5234 | |
|---|
| 5235 | |
|---|
| 5236 | |
|---|
| 5237 | |
|---|
| 5238 | |
|---|
| 5239 | |
|---|
| 5240 | |
|---|
| 5241 | |
|---|
| 5242 | Xinha.flushEvents = function() |
|---|
| 5243 | { |
|---|
| 5244 | var x = 0; |
|---|
| 5245 | |
|---|
| 5246 | var e = Xinha._eventFlushers.pop(); |
|---|
| 5247 | while ( e ) |
|---|
| 5248 | { |
|---|
| 5249 | try |
|---|
| 5250 | { |
|---|
| 5251 | if ( e.length == 3 ) |
|---|
| 5252 | { |
|---|
| 5253 | Xinha._removeEvent(e[0], e[1], e[2]); |
|---|
| 5254 | x++; |
|---|
| 5255 | } |
|---|
| 5256 | else if ( e.length == 2 ) |
|---|
| 5257 | { |
|---|
| 5258 | e[0]['on' + e[1]] = null; |
|---|
| 5259 | e[0]._xinha_dom0Events[e[1]] = null; |
|---|
| 5260 | x++; |
|---|
| 5261 | } |
|---|
| 5262 | } |
|---|
| 5263 | catch(ex) |
|---|
| 5264 | { |
|---|
| 5265 | |
|---|
| 5266 | } |
|---|
| 5267 | e = Xinha._eventFlushers.pop(); |
|---|
| 5268 | } |
|---|
| 5269 | |
|---|
| 5270 | |
|---|
| 5271 | |
|---|
| 5272 | |
|---|
| 5273 | |
|---|
| 5274 | |
|---|
| 5275 | |
|---|
| 5276 | |
|---|
| 5277 | |
|---|
| 5278 | |
|---|
| 5279 | |
|---|
| 5280 | |
|---|
| 5281 | |
|---|
| 5282 | |
|---|
| 5283 | |
|---|
| 5284 | |
|---|
| 5285 | |
|---|
| 5286 | |
|---|
| 5287 | |
|---|
| 5288 | |
|---|
| 5289 | |
|---|
| 5290 | }; |
|---|
| 5291 | |
|---|
| 5292 | |
|---|
| 5293 | |
|---|
| 5294 | Xinha._eventFlushers = []; |
|---|
| 5295 | |
|---|
| 5296 | if ( document.addEventListener ) |
|---|
| 5297 | { |
|---|
| 5298 | |
|---|
| 5299 | |
|---|
| 5300 | |
|---|
| 5301 | |
|---|
| 5302 | |
|---|
| 5303 | |
|---|
| 5304 | |
|---|
| 5305 | |
|---|
| 5306 | |
|---|
| 5307 | |
|---|
| 5308 | Xinha._addEvent = function(el, evname, func) |
|---|
| 5309 | { |
|---|
| 5310 | el.addEventListener(evname, func, true); |
|---|
| 5311 | Xinha._eventFlushers.push([el, evname, func]); |
|---|
| 5312 | }; |
|---|
| 5313 | |
|---|
| 5314 | |
|---|
| 5315 | |
|---|
| 5316 | |
|---|
| 5317 | |
|---|
| 5318 | |
|---|
| 5319 | |
|---|
| 5320 | |
|---|
| 5321 | |
|---|
| 5322 | Xinha._removeEvent = function(el, evname, func) |
|---|
| 5323 | { |
|---|
| 5324 | el.removeEventListener(evname, func, true); |
|---|
| 5325 | }; |
|---|
| 5326 | |
|---|
| 5327 | |
|---|
| 5328 | |
|---|
| 5329 | |
|---|
| 5330 | |
|---|
| 5331 | |
|---|
| 5332 | Xinha._stopEvent = function(ev) |
|---|
| 5333 | { |
|---|
| 5334 | ev.preventDefault(); |
|---|
| 5335 | ev.stopPropagation(); |
|---|
| 5336 | }; |
|---|
| 5337 | } |
|---|
| 5338 | |
|---|
| 5339 | |
|---|
| 5340 | |
|---|
| 5341 | else if ( document.attachEvent ) |
|---|
| 5342 | { |
|---|
| 5343 | Xinha._addEvent = function(el, evname, func) |
|---|
| 5344 | { |
|---|
| 5345 | el.attachEvent("on" + evname, func); |
|---|
| 5346 | Xinha._eventFlushers.push([el, evname, func]); |
|---|
| 5347 | }; |
|---|
| 5348 | Xinha._removeEvent = function(el, evname, func) |
|---|
| 5349 | { |
|---|
| 5350 | el.detachEvent("on" + evname, func); |
|---|
| 5351 | }; |
|---|
| 5352 | Xinha._stopEvent = function(ev) |
|---|
| 5353 | { |
|---|
| 5354 | try |
|---|
| 5355 | { |
|---|
| 5356 | ev.cancelBubble = true; |
|---|
| 5357 | ev.returnValue = false; |
|---|
| 5358 | } |
|---|
| 5359 | catch (ex) |
|---|
| 5360 | { |
|---|
| 5361 | |
|---|
| 5362 | |
|---|
| 5363 | |
|---|
| 5364 | } |
|---|
| 5365 | }; |
|---|
| 5366 | } |
|---|
| 5367 | else |
|---|
| 5368 | { |
|---|
| 5369 | Xinha._addEvent = function(el, evname, func) |
|---|
| 5370 | { |
|---|
| 5371 | alert('_addEvent is not supported'); |
|---|
| 5372 | }; |
|---|
| 5373 | Xinha._removeEvent = function(el, evname, func) |
|---|
| 5374 | { |
|---|
| 5375 | alert('_removeEvent is not supported'); |
|---|
| 5376 | }; |
|---|
| 5377 | Xinha._stopEvent = function(ev) |
|---|
| 5378 | { |
|---|
| 5379 | alert('_stopEvent is not supported'); |
|---|
| 5380 | }; |
|---|
| 5381 | } |
|---|
| 5382 | |
|---|
| 5383 | |
|---|
| 5384 | |
|---|
| 5385 | |
|---|
| 5386 | |
|---|
| 5387 | |
|---|
| 5388 | |
|---|
| 5389 | |
|---|
| 5390 | Xinha._addEvents = function(el, evs, func) |
|---|
| 5391 | { |
|---|
| 5392 | for ( var i = evs.length; --i >= 0; ) |
|---|
| 5393 | { |
|---|
| 5394 | Xinha._addEvent(el, evs[i], func); |
|---|
| 5395 | } |
|---|
| 5396 | }; |
|---|
| 5397 | |
|---|
| 5398 | |
|---|
| 5399 | |
|---|
| 5400 | |
|---|
| 5401 | |
|---|
| 5402 | |
|---|
| 5403 | |
|---|
| 5404 | |
|---|
| 5405 | Xinha._removeEvents = function(el, evs, func) |
|---|
| 5406 | { |
|---|
| 5407 | for ( var i = evs.length; --i >= 0; ) |
|---|
| 5408 | { |
|---|
| 5409 | Xinha._removeEvent(el, evs[i], func); |
|---|
| 5410 | } |
|---|
| 5411 | }; |
|---|
| 5412 | |
|---|
| 5413 | |
|---|
| 5414 | |
|---|
| 5415 | |
|---|
| 5416 | |
|---|
| 5417 | |
|---|
| 5418 | |
|---|
| 5419 | |
|---|
| 5420 | Xinha.addOnloadHandler = function (func, scope) |
|---|
| 5421 | { |
|---|
| 5422 | scope = scope ? scope : window; |
|---|
| 5423 | |
|---|
| 5424 | var init = function () |
|---|
| 5425 | { |
|---|
| 5426 | |
|---|
| 5427 | if (arguments.callee.done) return; |
|---|
| 5428 | |
|---|
| 5429 | arguments.callee.done = true; |
|---|
| 5430 | |
|---|
| 5431 | if (Xinha.onloadTimer) clearInterval(Xinha.onloadTimer); |
|---|
| 5432 | |
|---|
| 5433 | func(); |
|---|
| 5434 | } |
|---|
| 5435 | if (Xinha.is_ie) |
|---|
| 5436 | { |
|---|
| 5437 | scope.document.write("<sc"+"ript id=__ie_onload defer src=javascript:void(0)><\/script>"); |
|---|
| 5438 | var script = scope.document.getElementById("__ie_onload"); |
|---|
| 5439 | script.onreadystatechange = function() |
|---|
| 5440 | { |
|---|
| 5441 | if (this.readyState == "loaded") |
|---|
| 5442 | { |
|---|
| 5443 | this.parentNode.removeChild(script); |
|---|
| 5444 | init(); |
|---|
| 5445 | } |
|---|
| 5446 | }; |
|---|
| 5447 | } |
|---|
| 5448 | else if (/applewebkit|KHTML/i.test(navigator.userAgent) ) |
|---|
| 5449 | { |
|---|
| 5450 | Xinha.onloadTimer = scope.setInterval(function() |
|---|
| 5451 | { |
|---|
| 5452 | if (/loaded|complete/.test(scope.document.readyState)) |
|---|
| 5453 | { |
|---|
| 5454 | init(); |
|---|
| 5455 | } |
|---|
| 5456 | }, 10); |
|---|
| 5457 | } |
|---|
| 5458 | else |
|---|
| 5459 | { |
|---|
| 5460 | scope.document.addEventListener("DOMContentLoaded", init, false); |
|---|
| 5461 | |
|---|
| 5462 | } |
|---|
| 5463 | Xinha._addEvent(scope, 'load', init); |
|---|
| 5464 | }; |
|---|
| 5465 | |
|---|
| 5466 | |
|---|
| 5467 | |
|---|
| 5468 | |
|---|
| 5469 | |
|---|
| 5470 | |
|---|
| 5471 | |
|---|
| 5472 | |
|---|
| 5473 | |
|---|
| 5474 | |
|---|
| 5475 | |
|---|
| 5476 | |
|---|
| 5477 | |
|---|
| 5478 | |
|---|
| 5479 | |
|---|
| 5480 | |
|---|
| 5481 | |
|---|
| 5482 | |
|---|
| 5483 | |
|---|
| 5484 | |
|---|
| 5485 | |
|---|
| 5486 | |
|---|
| 5487 | |
|---|
| 5488 | Xinha.addDom0Event = function(el, ev, fn) |
|---|
| 5489 | { |
|---|
| 5490 | Xinha._prepareForDom0Events(el, ev); |
|---|
| 5491 | el._xinha_dom0Events[ev].unshift(fn); |
|---|
| 5492 | }; |
|---|
| 5493 | |
|---|
| 5494 | |
|---|
| 5495 | |
|---|
| 5496 | |
|---|
| 5497 | |
|---|
| 5498 | |
|---|
| 5499 | |
|---|
| 5500 | |
|---|
| 5501 | |
|---|
| 5502 | |
|---|
| 5503 | |
|---|
| 5504 | |
|---|
| 5505 | |
|---|
| 5506 | |
|---|
| 5507 | Xinha.prependDom0Event = function(el, ev, fn) |
|---|
| 5508 | { |
|---|
| 5509 | Xinha._prepareForDom0Events(el, ev); |
|---|
| 5510 | el._xinha_dom0Events[ev].push(fn); |
|---|
| 5511 | }; |
|---|
| 5512 | |
|---|
| 5513 | Xinha.getEvent = function(ev) |
|---|
| 5514 | { |
|---|
| 5515 | return ev || window.event; |
|---|
| 5516 | } |
|---|
| 5517 | |
|---|
| 5518 | |
|---|
| 5519 | |
|---|
| 5520 | |
|---|
| 5521 | |
|---|
| 5522 | |
|---|
| 5523 | Xinha._prepareForDom0Events = function(el, ev) |
|---|
| 5524 | { |
|---|
| 5525 | |
|---|
| 5526 | if ( typeof el._xinha_dom0Events == 'undefined' ) |
|---|
| 5527 | { |
|---|
| 5528 | el._xinha_dom0Events = {}; |
|---|
| 5529 | Xinha.freeLater(el, '_xinha_dom0Events'); |
|---|
| 5530 | } |
|---|
| 5531 | |
|---|
| 5532 | |
|---|
| 5533 | if ( typeof el._xinha_dom0Events[ev] == 'undefined' ) |
|---|
| 5534 | { |
|---|
| 5535 | el._xinha_dom0Events[ev] = [ ]; |
|---|
| 5536 | if ( typeof el['on'+ev] == 'function' ) |
|---|
| 5537 | { |
|---|
| 5538 | el._xinha_dom0Events[ev].push(el['on'+ev]); |
|---|
| 5539 | } |
|---|
| 5540 | |
|---|
| 5541 | |
|---|
| 5542 | |
|---|
| 5543 | |
|---|
| 5544 | el['on'+ev] = function(event) |
|---|
| 5545 | { |
|---|
| 5546 | var a = el._xinha_dom0Events[ev]; |
|---|
| 5547 | |
|---|
| 5548 | var allOK = true; |
|---|
| 5549 | for ( var i = a.length; --i >= 0; ) |
|---|
| 5550 | { |
|---|
| 5551 | |
|---|
| 5552 | el._xinha_tempEventHandler = a[i]; |
|---|
| 5553 | if ( el._xinha_tempEventHandler(event) === false ) |
|---|
| 5554 | { |
|---|
| 5555 | el._xinha_tempEventHandler = null; |
|---|
| 5556 | allOK = false; |
|---|
| 5557 | break; |
|---|
| 5558 | } |
|---|
| 5559 | el._xinha_tempEventHandler = null; |
|---|
| 5560 | } |
|---|
| 5561 | return allOK; |
|---|
| 5562 | }; |
|---|
| 5563 | |
|---|
| 5564 | Xinha._eventFlushers.push([el, ev]); |
|---|
| 5565 | } |
|---|
| 5566 | }; |
|---|
| 5567 | |
|---|
| 5568 | Xinha.prototype.notifyOn = function(ev, fn) |
|---|
| 5569 | { |
|---|
| 5570 | if ( typeof this._notifyListeners[ev] == 'undefined' ) |
|---|
| 5571 | { |
|---|
| 5572 | this._notifyListeners[ev] = []; |
|---|
| 5573 | Xinha.freeLater(this, '_notifyListeners'); |
|---|
| 5574 | } |
|---|
| 5575 | this._notifyListeners[ev].push(fn); |
|---|
| 5576 | }; |
|---|
| 5577 | |
|---|
| 5578 | Xinha.prototype.notifyOf = function(ev, args) |
|---|
| 5579 | { |
|---|
| 5580 | if ( this._notifyListeners[ev] ) |
|---|
| 5581 | { |
|---|
| 5582 | for ( var i = 0; i < this._notifyListeners[ev].length; i++ ) |
|---|
| 5583 | { |
|---|
| 5584 | this._notifyListeners[ev][i](ev, args); |
|---|
| 5585 | } |
|---|
| 5586 | } |
|---|
| 5587 | }; |
|---|
| 5588 | |
|---|
| 5589 | |
|---|
| 5590 | |
|---|
| 5591 | |
|---|
| 5592 | |
|---|
| 5593 | |
|---|
| 5594 | |
|---|
| 5595 | Xinha._blockTags = " body form textarea fieldset ul ol dl li div " + |
|---|
| 5596 | "p h1 h2 h3 h4 h5 h6 quote pre table thead " + |
|---|
| 5597 | "tbody tfoot tr td th iframe address blockquote "; |
|---|
| 5598 | |
|---|
| 5599 | |
|---|
| 5600 | |
|---|
| 5601 | |
|---|
| 5602 | |
|---|
| 5603 | |
|---|
| 5604 | Xinha.isBlockElement = function(el) |
|---|
| 5605 | { |
|---|
| 5606 | return el && el.nodeType == 1 && (Xinha._blockTags.indexOf(" " + el.tagName.toLowerCase() + " ") != -1); |
|---|
| 5607 | }; |
|---|
| 5608 | |
|---|
| 5609 | |
|---|
| 5610 | |
|---|
| 5611 | |
|---|
| 5612 | |
|---|
| 5613 | |
|---|
| 5614 | Xinha._paraContainerTags = " body td th caption fieldset div"; |
|---|
| 5615 | |
|---|
| 5616 | |
|---|
| 5617 | |
|---|
| 5618 | |
|---|
| 5619 | |
|---|
| 5620 | Xinha.isParaContainer = function(el) |
|---|
| 5621 | { |
|---|
| 5622 | return el && el.nodeType == 1 && (Xinha._paraContainerTags.indexOf(" " + el.tagName.toLowerCase() + " ") != -1); |
|---|
| 5623 | }; |
|---|
| 5624 | |
|---|
| 5625 | |
|---|
| 5626 | |
|---|
| 5627 | |
|---|
| 5628 | |
|---|
| 5629 | |
|---|
| 5630 | |
|---|
| 5631 | |
|---|
| 5632 | |
|---|
| 5633 | Xinha._closingTags = " a abbr acronym address applet b bdo big blockquote button caption center cite code del dfn dir div dl em fieldset font form frameset h1 h2 h3 h4 h5 h6 i iframe ins kbd label legend map menu noframes noscript object ol optgroup pre q s samp script select small span strike strong style sub sup table textarea title tt u ul var "; |
|---|
| 5634 | |
|---|
| 5635 | |
|---|
| 5636 | |
|---|
| 5637 | |
|---|
| 5638 | |
|---|
| 5639 | |
|---|
| 5640 | Xinha.needsClosingTag = function(el) |
|---|
| 5641 | { |
|---|
| 5642 | return el && el.nodeType == 1 && (Xinha._closingTags.indexOf(" " + el.tagName.toLowerCase() + " ") != -1); |
|---|
| 5643 | }; |
|---|
| 5644 | |
|---|
| 5645 | |
|---|
| 5646 | |
|---|
| 5647 | |
|---|
| 5648 | |
|---|
| 5649 | |
|---|
| 5650 | Xinha.htmlEncode = function(str) |
|---|
| 5651 | { |
|---|
| 5652 | if ( typeof str.replace == 'undefined' ) |
|---|
| 5653 | { |
|---|
| 5654 | str = str.toString(); |
|---|
| 5655 | } |
|---|
| 5656 | |
|---|
| 5657 | str = str.replace(/&/ig, "&"); |
|---|
| 5658 | str = str.replace(/</ig, "<"); |
|---|
| 5659 | str = str.replace(/>/ig, ">"); |
|---|
| 5660 | str = str.replace(/\xA0/g, " "); |
|---|
| 5661 | str = str.replace(/\x22/g, """); |
|---|
| 5662 | |
|---|
| 5663 | |
|---|
| 5664 | return str; |
|---|
| 5665 | }; |
|---|
| 5666 | |
|---|
| 5667 | |
|---|
| 5668 | |
|---|
| 5669 | |
|---|
| 5670 | |
|---|
| 5671 | |
|---|
| 5672 | Xinha.prototype.stripBaseURL = function(string) |
|---|
| 5673 | { |
|---|
| 5674 | if ( this.config.baseHref === null || !this.config.stripBaseHref ) |
|---|
| 5675 | { |
|---|
| 5676 | return string; |
|---|
| 5677 | } |
|---|
| 5678 | var baseurl = this.config.baseHref.replace(/^(https?:\/\/[^\/]+)(.*)$/, '$1'); |
|---|
| 5679 | var basere = new RegExp(baseurl); |
|---|
| 5680 | return string.replace(basere, ""); |
|---|
| 5681 | }; |
|---|
| 5682 | |
|---|
| 5683 | |
|---|
| 5684 | |
|---|
| 5685 | |
|---|
| 5686 | String.prototype.trim = function() |
|---|
| 5687 | { |
|---|
| 5688 | return this.replace(/^\s+/, '').replace(/\s+$/, ''); |
|---|
| 5689 | }; |
|---|
| 5690 | |
|---|
| 5691 | |
|---|
| 5692 | |
|---|
| 5693 | |
|---|
| 5694 | |
|---|
| 5695 | |
|---|
| 5696 | Xinha._makeColor = function(v) |
|---|
| 5697 | { |
|---|
| 5698 | if ( typeof v != "number" ) |
|---|
| 5699 | { |
|---|
| 5700 | |
|---|
| 5701 | return v; |
|---|
| 5702 | } |
|---|
| 5703 | |
|---|
| 5704 | var r = v & 0xFF; |
|---|
| 5705 | var g = (v >> 8) & 0xFF; |
|---|
| 5706 | var b = (v >> 16) & 0xFF; |
|---|
| 5707 | return "rgb(" + r + "," + g + "," + b + ")"; |
|---|
| 5708 | }; |
|---|
| 5709 | |
|---|
| 5710 | |
|---|
| 5711 | |
|---|
| 5712 | |
|---|
| 5713 | |
|---|
| 5714 | |
|---|
| 5715 | Xinha._colorToRgb = function(v) |
|---|
| 5716 | { |
|---|
| 5717 | if ( !v ) |
|---|
| 5718 | { |
|---|
| 5719 | return ''; |
|---|
| 5720 | } |
|---|
| 5721 | var r,g,b; |
|---|
| 5722 | |
|---|
| 5723 | |
|---|
| 5724 | function hex(d) |
|---|
| 5725 | { |
|---|
| 5726 | return (d < 16) ? ("0" + d.toString(16)) : d.toString(16); |
|---|
| 5727 | } |
|---|
| 5728 | |
|---|
| 5729 | if ( typeof v == "number" ) |
|---|
| 5730 | { |
|---|
| 5731 | |
|---|
| 5732 | r = v & 0xFF; |
|---|
| 5733 | g = (v >> 8) & 0xFF; |
|---|
| 5734 | b = (v >> 16) & 0xFF; |
|---|
| 5735 | return "#" + hex(r) + hex(g) + hex(b); |
|---|
| 5736 | } |
|---|
| 5737 | |
|---|
| 5738 | if ( v.substr(0, 3) == "rgb" ) |
|---|
| 5739 | { |
|---|
| 5740 | |
|---|
| 5741 | var re = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/; |
|---|
| 5742 | if ( v.match(re) ) |
|---|
| 5743 | { |
|---|
| 5744 | r = parseInt(RegExp.$1, 10); |
|---|
| 5745 | g = parseInt(RegExp.$2, 10); |
|---|
| 5746 | b = parseInt(RegExp.$3, 10); |
|---|
| 5747 | return "#" + hex(r) + hex(g) + hex(b); |
|---|
| 5748 | } |
|---|
| 5749 | |
|---|
| 5750 | |
|---|
| 5751 | return null; |
|---|
| 5752 | } |
|---|
| 5753 | |
|---|
| 5754 | if ( v.substr(0, 1) == "#" ) |
|---|
| 5755 | { |
|---|
| 5756 | |
|---|
| 5757 | return v; |
|---|
| 5758 | } |
|---|
| 5759 | |
|---|
| 5760 | |
|---|
| 5761 | return null; |
|---|
| 5762 | }; |
|---|
| 5763 | |
|---|
| 5764 | |
|---|
| 5765 | |
|---|
| 5766 | |
|---|
| 5767 | |
|---|
| 5768 | |
|---|
| 5769 | |
|---|
| 5770 | |
|---|
| 5771 | Xinha.prototype._popupDialog = function(url, action, init) |
|---|
| 5772 | { |
|---|
| 5773 | Dialog(this.popupURL(url), action, init); |
|---|
| 5774 | }; |
|---|
| 5775 | |
|---|
| 5776 | |
|---|
| 5777 | |
|---|
| 5778 | |
|---|
| 5779 | |
|---|
| 5780 | |
|---|
| 5781 | |
|---|
| 5782 | |
|---|
| 5783 | Xinha.prototype.imgURL = function(file, plugin) |
|---|
| 5784 | { |
|---|
| 5785 | if ( typeof plugin == "undefined" ) |
|---|
| 5786 | { |
|---|
| 5787 | return _editor_url + file; |
|---|
| 5788 | } |
|---|
| 5789 | else |
|---|
| 5790 | { |
|---|
| 5791 | return _editor_url + "plugins/" + plugin + "/img/" + file; |
|---|
| 5792 | } |
|---|
| 5793 | }; |
|---|
| 5794 | |
|---|
| 5795 | |
|---|
| 5796 | |
|---|
| 5797 | |
|---|
| 5798 | |
|---|
| 5799 | |
|---|
| 5800 | Xinha.prototype.popupURL = function(file) |
|---|
| 5801 | { |
|---|
| 5802 | var url = ""; |
|---|
| 5803 | if ( file.match(/^plugin:\/\/(.*?)\/(.*)/) ) |
|---|
| 5804 | { |
|---|
| 5805 | var plugin = RegExp.$1; |
|---|
| 5806 | var popup = RegExp.$2; |
|---|
| 5807 | if ( ! ( /\.(html?|php)$/.test(popup) ) ) |
|---|
| 5808 | { |
|---|
| 5809 | popup += ".html"; |
|---|
| 5810 | } |
|---|
| 5811 | url = Xinha.getPluginDir(plugin) + "/popups/" + popup; |
|---|
| 5812 | } |
|---|
| 5813 | else if ( file.match(/^\/.*?/) || file.match(/^https?:\/\ |
|---|
| 5814 | { |
|---|
| 5815 | url = file; |
|---|
| 5816 | } |
|---|
| 5817 | else |
|---|
| 5818 | { |
|---|
| 5819 | url = _editor_url + this.config.popupURL + file; |
|---|
| 5820 | } |
|---|
| 5821 | return url; |
|---|
| 5822 | }; |
|---|
| 5823 | |
|---|
| 5824 | |
|---|
| 5825 | |
|---|
| 5826 | |
|---|
| 5827 | |
|---|
| 5828 | |
|---|
| 5829 | |
|---|
| 5830 | |
|---|
| 5831 | |
|---|
| 5832 | |
|---|
| 5833 | |
|---|
| 5834 | Xinha.getElementById = function(tag, id) |
|---|
| 5835 | { |
|---|
| 5836 | var el, i, objs = document.getElementsByTagName(tag); |
|---|
| 5837 | for ( i = objs.length; --i >= 0 && (el = objs[i]); ) |
|---|
| 5838 | { |
|---|
| 5839 | if ( el.id == id ) |
|---|
| 5840 | { |
|---|
| 5841 | return el; |
|---|
| 5842 | } |
|---|
| 5843 | } |
|---|
| 5844 | return null; |
|---|
| 5845 | }; |
|---|
| 5846 | |
|---|
| 5847 | |
|---|
| 5848 | |
|---|
| 5849 | |
|---|
| 5850 | |
|---|
| 5851 | |
|---|
| 5852 | Xinha.prototype._toggleBorders = function() |
|---|
| 5853 | { |
|---|
| 5854 | var tables = this._doc.getElementsByTagName('TABLE'); |
|---|
| 5855 | if ( tables.length !== 0 ) |
|---|
| 5856 | { |
|---|
| 5857 | if ( !this.borders ) |
|---|
| 5858 | { |
|---|
| 5859 | this.borders = true; |
|---|
| 5860 | } |
|---|
| 5861 | else |
|---|
| 5862 | { |
|---|
| 5863 | this.borders = false; |
|---|
| 5864 | } |
|---|
| 5865 | |
|---|
| 5866 | for ( var i=0; i < tables.length; i++ ) |
|---|
| 5867 | { |
|---|
| 5868 | if ( this.borders ) |
|---|
| 5869 | { |
|---|
| 5870 | Xinha._addClass(tables[i], 'htmtableborders'); |
|---|
| 5871 | } |
|---|
| 5872 | else |
|---|
| 5873 | { |
|---|
| 5874 | Xinha._removeClass(tables[i], 'htmtableborders'); |
|---|
| 5875 | } |
|---|
| 5876 | } |
|---|
| 5877 | } |
|---|
| 5878 | return true; |
|---|
| 5879 | }; |
|---|
| 5880 | |
|---|
| 5881 | |
|---|
| 5882 | |
|---|
| 5883 | |
|---|
| 5884 | |
|---|
| 5885 | |
|---|
| 5886 | |
|---|
| 5887 | Xinha.addCoreCSS = function(html) |
|---|
| 5888 | { |
|---|
| 5889 | var coreCSS = |
|---|
| 5890 | "<style title=\"XinhaInternalCSS\" type=\"text/css\">" |
|---|
| 5891 | + ".htmtableborders, .htmtableborders td, .htmtableborders th {border : 1px dashed lightgrey ! important;}\n" |
|---|
| 5892 | + "html, body { border: 0px; } \n" |
|---|
| 5893 | + "body { background-color: #ffffff; } \n" |
|---|
| 5894 | + "img, hr { cursor: default } \n" |
|---|
| 5895 | +"</style>\n"; |
|---|
| 5896 | |
|---|
| 5897 | if( html && /<head>/i.test(html)) |
|---|
| 5898 | { |
|---|
| 5899 | return html.replace(/<head>/i, '<head>' + coreCSS); |
|---|
| 5900 | } |
|---|
| 5901 | else if ( html) |
|---|
| 5902 | { |
|---|
| 5903 | return coreCSS + html; |
|---|
| 5904 | } |
|---|
| 5905 | else |
|---|
| 5906 | { |
|---|
| 5907 | return coreCSS; |
|---|
| 5908 | } |
|---|
| 5909 | } |
|---|
| 5910 | |
|---|
| 5911 | |
|---|
| 5912 | |
|---|
| 5913 | |
|---|
| 5914 | |
|---|
| 5915 | Xinha.prototype.addEditorStylesheet = function (stylesheet) |
|---|
| 5916 | { |
|---|
| 5917 | var style = this._doc.createElement("link"); |
|---|
| 5918 | style.rel = 'stylesheet'; |
|---|
| 5919 | style.type = 'text/css'; |
|---|
| 5920 | style.title = 'XinhaInternalCSS'; |
|---|
| 5921 | style.href = stylesheet; |
|---|
| 5922 | this._doc.getElementsByTagName("HEAD")[0].appendChild(style); |
|---|
| 5923 | } |
|---|
| 5924 | |
|---|
| 5925 | |
|---|
| 5926 | |
|---|
| 5927 | |
|---|
| 5928 | |
|---|
| 5929 | |
|---|
| 5930 | |
|---|
| 5931 | Xinha.stripCoreCSS = function(html) |
|---|
| 5932 | { |
|---|
| 5933 | return html.replace(/<style[^>]+title="XinhaInternalCSS"(.|\n)*?<\/style>/ig, '').replace(/<link[^>]+title="XinhaInternalCSS"(.|\n)*?>/ig, ''); |
|---|
| 5934 | } |
|---|
| 5935 | |
|---|
| 5936 | |
|---|
| 5937 | |
|---|
| 5938 | |
|---|
| 5939 | |
|---|
| 5940 | |
|---|
| 5941 | |
|---|
| 5942 | Xinha._removeClass = function(el, className) |
|---|
| 5943 | { |
|---|
| 5944 | if ( ! ( el && el.className ) ) |
|---|
| 5945 | { |
|---|
| 5946 | return; |
|---|
| 5947 | } |
|---|
| 5948 | var cls = el.className.split(" "); |
|---|
| 5949 | var ar = []; |
|---|
| 5950 | for ( var i = cls.length; i > 0; ) |
|---|
| 5951 | { |
|---|
| 5952 | if ( cls[--i] != className ) |
|---|
| 5953 | { |
|---|
| 5954 | ar[ar.length] = cls[i]; |
|---|
| 5955 | } |
|---|
| 5956 | } |
|---|
| 5957 | el.className = ar.join(" "); |
|---|
| 5958 | }; |
|---|
| 5959 | |
|---|
| 5960 | |
|---|
| 5961 | |
|---|
| 5962 | |
|---|
| 5963 | |
|---|
| 5964 | |
|---|
| 5965 | |
|---|
| 5966 | Xinha._addClass = function(el, className) |
|---|
| 5967 | { |
|---|
| 5968 | |
|---|
| 5969 | Xinha._removeClass(el, className); |
|---|
| 5970 | el.className += " " + className; |
|---|
| 5971 | }; |
|---|
| 5972 | |
|---|
| 5973 | |
|---|
| 5974 | |
|---|
| 5975 | |
|---|
| 5976 | |
|---|
| 5977 | |
|---|
| 5978 | |
|---|
| 5979 | |
|---|
| 5980 | Xinha.addClasses = function(el, classes) |
|---|
| 5981 | { |
|---|
| 5982 | if ( el !== null ) |
|---|
| 5983 | { |
|---|
| 5984 | var thiers = el.className.trim().split(' '); |
|---|
| 5985 | var ours = classes.split(' '); |
|---|
| 5986 | for ( var x = 0; x < ours.length; x++ ) |
|---|
| 5987 | { |
|---|
| 5988 | var exists = false; |
|---|
| 5989 | for ( var i = 0; exists === false && i < thiers.length; i++ ) |
|---|
| 5990 | { |
|---|
| 5991 | if ( thiers[i] == ours[x] ) |
|---|
| 5992 | { |
|---|
| 5993 | exists = true; |
|---|
| 5994 | } |
|---|
| 5995 | } |
|---|
| 5996 | if ( exists === false ) |
|---|
| 5997 | { |
|---|
| 5998 | thiers[thiers.length] = ours[x]; |
|---|
| 5999 | } |
|---|
| 6000 | } |
|---|
| 6001 | el.className = thiers.join(' ').trim(); |
|---|
| 6002 | } |
|---|
| 6003 | }; |
|---|
| 6004 | |
|---|
| 6005 | |
|---|
| 6006 | |
|---|
| 6007 | |
|---|
| 6008 | |
|---|
| 6009 | |
|---|
| 6010 | |
|---|
| 6011 | |
|---|
| 6012 | Xinha.removeClasses = function(el, classes) |
|---|
| 6013 | { |
|---|
| 6014 | var existing = el.className.trim().split(); |
|---|
| 6015 | var new_classes = []; |
|---|
| 6016 | var remove = classes.trim().split(); |
|---|
| 6017 | |
|---|
| 6018 | for ( var i = 0; i < existing.length; i++ ) |
|---|
| 6019 | { |
|---|
| 6020 | var found = false; |
|---|
| 6021 | for ( var x = 0; x < remove.length && !found; x++ ) |
|---|
| 6022 | { |
|---|
| 6023 | if ( existing[i] == remove[x] ) |
|---|
| 6024 | { |
|---|
| 6025 | found = true; |
|---|
| 6026 | } |
|---|
| 6027 | } |
|---|
| 6028 | if ( !found ) |
|---|
| 6029 | { |
|---|
| 6030 | new_classes[new_classes.length] = existing[i]; |
|---|
| 6031 | } |
|---|
| 6032 | } |
|---|
| 6033 | return new_classes.join(' '); |
|---|
| 6034 | }; |
|---|
| 6035 | |
|---|
| 6036 | |
|---|
| 6037 | |
|---|
| 6038 | |
|---|
| 6039 | Xinha.addClass = Xinha._addClass; |
|---|
| 6040 | |
|---|
| 6041 | |
|---|
| 6042 | |
|---|
| 6043 | Xinha.removeClass = Xinha._removeClass; |
|---|
| 6044 | |
|---|
| 6045 | |
|---|
| 6046 | |
|---|
| 6047 | Xinha._addClasses = Xinha.addClasses; |
|---|
| 6048 | |
|---|
| 6049 | |
|---|
| 6050 | |
|---|
| 6051 | Xinha._removeClasses = Xinha.removeClasses; |
|---|
| 6052 | |
|---|
| 6053 | |
|---|
| 6054 | |
|---|
| 6055 | |
|---|
| 6056 | |
|---|
| 6057 | |
|---|
| 6058 | |
|---|
| 6059 | Xinha._hasClass = function(el, className) |
|---|
| 6060 | { |
|---|
| 6061 | if ( ! ( el && el.className ) ) |
|---|
| 6062 | { |
|---|
| 6063 | return false; |
|---|
| 6064 | } |
|---|
| 6065 | var cls = el.className.split(" "); |
|---|
| 6066 | for ( var i = cls.length; i > 0; ) |
|---|
| 6067 | { |
|---|
| 6068 | if ( cls[--i] == className ) |
|---|
| 6069 | { |
|---|
| 6070 | return true; |
|---|
| 6071 | } |
|---|
| 6072 | } |
|---|
| 6073 | return false; |
|---|
| 6074 | }; |
|---|
| 6075 | |
|---|
| 6076 | |
|---|
| 6077 | |
|---|
| 6078 | |
|---|
| 6079 | |
|---|
| 6080 | |
|---|
| 6081 | |
|---|
| 6082 | |
|---|
| 6083 | |
|---|
| 6084 | |
|---|
| 6085 | |
|---|
| 6086 | |
|---|
| 6087 | |
|---|
| 6088 | Xinha._postback_send_charset = true; |
|---|
| 6089 | Xinha._postback = function(url, data, handler) |
|---|
| 6090 | { |
|---|
| 6091 | var req = null; |
|---|
| 6092 | req = Xinha.getXMLHTTPRequestObject(); |
|---|
| 6093 | |
|---|
| 6094 | var content = ''; |
|---|
| 6095 | if (typeof data == 'string') |
|---|
| 6096 | { |
|---|
| 6097 | content = data; |
|---|
| 6098 | } |
|---|
| 6099 | else if(typeof data == "object") |
|---|
| 6100 | { |
|---|
| 6101 | for ( var i in data ) |
|---|
| 6102 | { |
|---|
| 6103 | content += (content.length ? '&' : '') + i + '=' + encodeURIComponent(data[i]); |
|---|
| 6104 | } |
|---|
| 6105 | } |
|---|
| 6106 | |
|---|
| 6107 | function callBack() |
|---|
| 6108 | { |
|---|
| 6109 | if ( req.readyState == 4 ) |
|---|
| 6110 | { |
|---|
| 6111 | if ( req.status == 200 || Xinha.isRunLocally && req.status == 0 ) |
|---|
| 6112 | { |
|---|
| 6113 | if ( typeof handler == 'function' ) |
|---|
| 6114 | { |
|---|
| 6115 | handler(req.responseText, req); |
|---|
| 6116 | } |
|---|
| 6117 | } |
|---|
| 6118 | else if(Xinha._postback_send_charset) |
|---|
| 6119 | { |
|---|
| 6120 | Xinha._postback_send_charset = false; |
|---|
| 6121 | Xinha._postback(url,data,handler); |
|---|
| 6122 | } |
|---|
| 6123 | else |
|---|
| 6124 | { |
|---|
| 6125 | alert('An error has occurred: ' + req.statusText + '\nURL: ' + url); |
|---|
| 6126 | } |
|---|
| 6127 | } |
|---|
| 6128 | } |
|---|
| 6129 | |
|---|
| 6130 | req.onreadystatechange = callBack; |
|---|
| 6131 | |
|---|
| 6132 | req.open('POST', url, true); |
|---|
| 6133 | req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'+(Xinha._postback_send_charset ? '; charset=UTF-8' : '')); |
|---|
| 6134 | |
|---|
| 6135 | |
|---|
| 6136 | req.send(content); |
|---|
| 6137 | }; |
|---|
| 6138 | |
|---|
| 6139 | |
|---|
| 6140 | |
|---|
| 6141 | |
|---|
| 6142 | |
|---|
| 6143 | |
|---|
| 6144 | |
|---|
| 6145 | Xinha._getback = function(url, handler) |
|---|
| 6146 | { |
|---|
| 6147 | var req = null; |
|---|
| 6148 | req = Xinha.getXMLHTTPRequestObject(); |
|---|
| 6149 | |
|---|
| 6150 | function callBack() |
|---|
| 6151 | { |
|---|
| 6152 | if ( req.readyState == 4 ) |
|---|
| 6153 | { |
|---|
| 6154 | if ( req.status == 200 || Xinha.isRunLocally && req.status == 0 ) |
|---|
| 6155 | { |
|---|
| 6156 | handler(req.responseText, req); |
|---|
| 6157 | } |
|---|
| 6158 | else |
|---|
| 6159 | { |
|---|
| 6160 | alert('An error has occurred: ' + req.statusText + '\nURL: ' + url); |
|---|
| 6161 | } |
|---|
| 6162 | } |
|---|
| 6163 | } |
|---|
| 6164 | |
|---|
| 6165 | req.onreadystatechange = callBack; |
|---|
| 6166 | req.open('GET', url, true); |
|---|
| 6167 | req.send(null); |
|---|
| 6168 | }; |
|---|
| 6169 | |
|---|
| 6170 | |
|---|
| 6171 | |
|---|
| 6172 | Xinha._geturlcontent = function(url) |
|---|
| 6173 | { |
|---|
| 6174 | var req = null; |
|---|
| 6175 | req = Xinha.getXMLHTTPRequestObject(); |
|---|
| 6176 | |
|---|
| 6177 | |
|---|
| 6178 | req.open('GET', url, false); |
|---|
| 6179 | req.send(null); |
|---|
| 6180 | if ( req.status == 200 || Xinha.isRunLocally && req.status == 0 ) |
|---|
| 6181 | { |
|---|
| 6182 | return req.responseText; |
|---|
| 6183 | } |
|---|
| 6184 | else |
|---|
| 6185 | { |
|---|
| 6186 | return ''; |
|---|
| 6187 | } |
|---|
| 6188 | |
|---|
| 6189 | }; |
|---|
| 6190 | |
|---|
| 6191 | |
|---|
| 6192 | |
|---|
| 6193 | if (typeof dumpValues == 'undefined') |
|---|
| 6194 | { |
|---|
| 6195 | function dumpValues(o) |
|---|
| 6196 | { |
|---|
| 6197 | var s = ''; |
|---|
| 6198 | for (var prop in o) |
|---|
| 6199 | { |
|---|
| 6200 | if (window.console && typeof window.console.log == 'function') |
|---|
| 6201 | { |
|---|
| 6202 | if (typeof console.firebug != 'undefined') |
|---|
| 6203 | console.log(o); |
|---|
| 6204 | else |
|---|
| 6205 | console.log(prop + ' = ' + o[prop] + '\n'); |
|---|
| 6206 | } |
|---|
| 6207 | else |
|---|
| 6208 | { |
|---|
| 6209 | s += prop + ' = ' + o[prop] + '\n'; |
|---|
| 6210 | } |
|---|
| 6211 | } |
|---|
| 6212 | if (s) |
|---|
| 6213 | { |
|---|
| 6214 | if (document.getElementById('errors')) |
|---|
| 6215 | { |
|---|
| 6216 | document.getElementById('errors').value += s; |
|---|
| 6217 | } |
|---|
| 6218 | else |
|---|
| 6219 | { |
|---|
| 6220 | var x = window.open("", "debugger"); |
|---|
| 6221 | x.document.write('<pre>' + s + '</pre>'); |
|---|
| 6222 | } |
|---|
| 6223 | |
|---|
| 6224 | } |
|---|
| 6225 | } |
|---|
| 6226 | } |
|---|
| 6227 | if ( !Array.prototype.contains ) |
|---|
| 6228 | { |
|---|
| 6229 | |
|---|
| 6230 | |
|---|
| 6231 | |
|---|
| 6232 | |
|---|
| 6233 | Array.prototype.contains = function(needle) |
|---|
| 6234 | { |
|---|
| 6235 | var haystack = this; |
|---|
| 6236 | for ( var i = 0; i < haystack.length; i++ ) |
|---|
| 6237 | { |
|---|
| 6238 | if ( needle == haystack[i] ) |
|---|
| 6239 | { |
|---|
| 6240 | return true; |
|---|
| 6241 | } |
|---|
| 6242 | } |
|---|
| 6243 | return false; |
|---|
| 6244 | }; |
|---|
| 6245 | } |
|---|
| 6246 | |
|---|
| 6247 | if ( !Array.prototype.indexOf ) |
|---|
| 6248 | { |
|---|
| 6249 | |
|---|
| 6250 | |
|---|
| 6251 | |
|---|
| 6252 | |
|---|
| 6253 | Array.prototype.indexOf = function(needle) |
|---|
| 6254 | { |
|---|
| 6255 | var haystack = this; |
|---|
| 6256 | for ( var i = 0; i < haystack.length; i++ ) |
|---|
| 6257 | { |
|---|
| 6258 | if ( needle == haystack[i] ) |
|---|
| 6259 | { |
|---|
| 6260 | return i; |
|---|
| 6261 | } |
|---|
| 6262 | } |
|---|
| 6263 | return null; |
|---|
| 6264 | }; |
|---|
| 6265 | } |
|---|
| 6266 | if ( !Array.prototype.append ) |
|---|
| 6267 | { |
|---|
| 6268 | |
|---|
| 6269 | |
|---|
| 6270 | |
|---|
| 6271 | |
|---|
| 6272 | Array.prototype.append = function(a) |
|---|
| 6273 | { |
|---|
| 6274 | for ( var i = 0; i < a.length; i++ ) |
|---|
| 6275 | { |
|---|
| 6276 | this.push(a[i]); |
|---|
| 6277 | } |
|---|
| 6278 | return this; |
|---|
| 6279 | }; |
|---|
| 6280 | } |
|---|
| 6281 | |
|---|
| 6282 | |
|---|
| 6283 | |
|---|
| 6284 | |
|---|
| 6285 | |
|---|
| 6286 | Xinha.arrayContainsArray = function(a1, a2) |
|---|
| 6287 | { |
|---|
| 6288 | var all_found = true; |
|---|
| 6289 | for ( var x = 0; x < a2.length; x++ ) |
|---|
| 6290 | { |
|---|
| 6291 | var found = false; |
|---|
| 6292 | for ( var i = 0; i < a1.length; i++ ) |
|---|
| 6293 | { |
|---|
| 6294 | if ( a1[i] == a2[x] ) |
|---|
| 6295 | { |
|---|
| 6296 | found = true; |
|---|
| 6297 | break; |
|---|
| 6298 | } |
|---|
| 6299 | } |
|---|
| 6300 | if ( !found ) |
|---|
| 6301 | { |
|---|
| 6302 | all_found = false; |
|---|
| 6303 | break; |
|---|
| 6304 | } |
|---|
| 6305 | } |
|---|
| 6306 | return all_found; |
|---|
| 6307 | }; |
|---|
| 6308 | |
|---|
| 6309 | |
|---|
| 6310 | |
|---|
| 6311 | |
|---|
| 6312 | |
|---|
| 6313 | Xinha.arrayFilter = function(a1, filterfn) |
|---|
| 6314 | { |
|---|
| 6315 | var new_a = [ ]; |
|---|
| 6316 | for ( var x = 0; x < a1.length; x++ ) |
|---|
| 6317 | { |
|---|
| 6318 | if ( filterfn(a1[x]) ) |
|---|
| 6319 | { |
|---|
| 6320 | new_a[new_a.length] = a1[x]; |
|---|
| 6321 | } |
|---|
| 6322 | } |
|---|
| 6323 | return new_a; |
|---|
| 6324 | }; |
|---|
| 6325 | |
|---|
| 6326 | |
|---|
| 6327 | |
|---|
| 6328 | |
|---|
| 6329 | Xinha.collectionToArray = function(collection) |
|---|
| 6330 | { |
|---|
| 6331 | var array = [ ]; |
|---|
| 6332 | for ( var i = 0; i < collection.length; i++ ) |
|---|
| 6333 | { |
|---|
| 6334 | array.push(collection.item(i)); |
|---|
| 6335 | } |
|---|
| 6336 | return array; |
|---|
| 6337 | }; |
|---|
| 6338 | |
|---|
| 6339 | |
|---|
| 6340 | |
|---|
| 6341 | |
|---|
| 6342 | Xinha.uniq_count = 0; |
|---|
| 6343 | |
|---|
| 6344 | |
|---|
| 6345 | |
|---|
| 6346 | |
|---|
| 6347 | Xinha.uniq = function(prefix) |
|---|
| 6348 | { |
|---|
| 6349 | return prefix + Xinha.uniq_count++; |
|---|
| 6350 | }; |
|---|
| 6351 | |
|---|
| 6352 | |
|---|
| 6353 | |
|---|
| 6354 | |
|---|
| 6355 | |
|---|
| 6356 | |
|---|
| 6357 | |
|---|
| 6358 | |
|---|
| 6359 | |
|---|
| 6360 | Xinha._loadlang = function(context,url) |
|---|
| 6361 | { |
|---|
| 6362 | var lang; |
|---|
| 6363 | |
|---|
| 6364 | if ( typeof _editor_lcbackend == "string" ) |
|---|
| 6365 | { |
|---|
| 6366 | |
|---|
| 6367 | url = _editor_lcbackend; |
|---|
| 6368 | url = url.replace(/%lang%/, _editor_lang); |
|---|
| 6369 | url = url.replace(/%context%/, context); |
|---|
| 6370 | } |
|---|
| 6371 | else if (!url) |
|---|
| 6372 | { |
|---|
| 6373 | |
|---|
| 6374 | if ( context != 'Xinha') |
|---|
| 6375 | { |
|---|
| 6376 | url = Xinha.getPluginDir(context)+"/lang/"+_editor_lang+".js"; |
|---|
| 6377 | } |
|---|
| 6378 | else |
|---|
| 6379 | { |
|---|
| 6380 | Xinha.setLoadingMessage("Loading language"); |
|---|
| 6381 | url = _editor_url+"lang/"+_editor_lang+".js"; |
|---|
| 6382 | } |
|---|
| 6383 | } |
|---|
| 6384 | |
|---|
| 6385 | var langData = Xinha._geturlcontent(url); |
|---|
| 6386 | if ( langData !== "" ) |
|---|
| 6387 | { |
|---|
| 6388 | try |
|---|
| 6389 | { |
|---|
| 6390 | eval('lang = ' + langData); |
|---|
| 6391 | } |
|---|
| 6392 | catch(ex) |
|---|
| 6393 | { |
|---|
| 6394 | alert('Error reading Language-File ('+url+'):\n'+Error.toString()); |
|---|
| 6395 | lang = {}; |
|---|
| 6396 | } |
|---|
| 6397 | } |
|---|
| 6398 | else |
|---|
| 6399 | { |
|---|
| 6400 | lang = {}; |
|---|
| 6401 | } |
|---|
| 6402 | |
|---|
| 6403 | return lang; |
|---|
| 6404 | }; |
|---|
| 6405 | |
|---|
| 6406 | |
|---|
| 6407 | |
|---|
| 6408 | |
|---|
| 6409 | |
|---|
| 6410 | |
|---|
| 6411 | |
|---|
| 6412 | Xinha._lc = function(string, context, replace) |
|---|
| 6413 | { |
|---|
| 6414 | var url,ret; |
|---|
| 6415 | if (typeof context == 'object' && context.url && context.context) |
|---|
| 6416 | { |
|---|
| 6417 | url = context.url + _editor_lang + ".js"; |
|---|
| 6418 | context = context.context; |
|---|
| 6419 | } |
|---|
| 6420 | |
|---|
| 6421 | var m = null; |
|---|
| 6422 | if (typeof string == 'string') m = string.match(/\$(.*?)=(.*?)\$/g); |
|---|
| 6423 | if (m) |
|---|
| 6424 | { |
|---|
| 6425 | if (!replace) replace = {}; |
|---|
| 6426 | for (var i = 0;i<m.length;i++) |
|---|
| 6427 | { |
|---|
| 6428 | var n = m[i].match(/\$(.*?)=(.*?)\$/); |
|---|
| 6429 | replace[n[1]] = n[2]; |
|---|
| 6430 | string = string.replace(n[0],'$'+n[1]); |
|---|
| 6431 | } |
|---|
| 6432 | } |
|---|
| 6433 | if ( _editor_lang == "en" ) |
|---|
| 6434 | { |
|---|
| 6435 | if ( typeof string == 'object' && string.string ) |
|---|
| 6436 | { |
|---|
| 6437 | ret = string.string; |
|---|
| 6438 | } |
|---|
| 6439 | else |
|---|
| 6440 | { |
|---|
| 6441 | ret = string; |
|---|
| 6442 | } |
|---|
| 6443 | } |
|---|
| 6444 | else |
|---|
| 6445 | { |
|---|
| 6446 | if ( typeof Xinha._lc_catalog == 'undefined' ) |
|---|
| 6447 | { |
|---|
| 6448 | Xinha._lc_catalog = [ ]; |
|---|
| 6449 | } |
|---|
| 6450 | |
|---|
| 6451 | if ( typeof context == 'undefined' ) |
|---|
| 6452 | { |
|---|
| 6453 | context = 'Xinha'; |
|---|
| 6454 | } |
|---|
| 6455 | |
|---|
| 6456 | if ( typeof Xinha._lc_catalog[context] == 'undefined' ) |
|---|
| 6457 | { |
|---|
| 6458 | Xinha._lc_catalog[context] = Xinha._loadlang(context,url); |
|---|
| 6459 | } |
|---|
| 6460 | |
|---|
| 6461 | var key; |
|---|
| 6462 | if ( typeof string == 'object' && string.key ) |
|---|
| 6463 | { |
|---|
| 6464 | key = string.key; |
|---|
| 6465 | } |
|---|
| 6466 | else if ( typeof string == 'object' && string.string ) |
|---|
| 6467 | { |
|---|
| 6468 | key = string.string; |
|---|
| 6469 | } |
|---|
| 6470 | else |
|---|
| 6471 | { |
|---|
| 6472 | key = string; |
|---|
| 6473 | } |
|---|
| 6474 | |
|---|
| 6475 | if ( typeof Xinha._lc_catalog[context][key] == 'undefined' ) |
|---|
| 6476 | { |
|---|
| 6477 | if ( context=='Xinha' ) |
|---|
| 6478 | { |
|---|
| 6479 | |
|---|
| 6480 | if ( typeof string == 'object' && string.string ) |
|---|
| 6481 | { |
|---|
| 6482 | ret = string.string; |
|---|
| 6483 | } |
|---|
| 6484 | else |
|---|
| 6485 | { |
|---|
| 6486 | ret = string; |
|---|
| 6487 | } |
|---|
| 6488 | } |
|---|
| 6489 | else |
|---|
| 6490 | { |
|---|
| 6491 | |
|---|
| 6492 | return Xinha._lc(string, 'Xinha', replace); |
|---|
| 6493 | } |
|---|
| 6494 | } |
|---|
| 6495 | else |
|---|
| 6496 | { |
|---|
| 6497 | ret = Xinha._lc_catalog[context][key]; |
|---|
| 6498 | } |
|---|
| 6499 | } |
|---|
| 6500 | |
|---|
| 6501 | if ( typeof string == 'object' && string.replace ) |
|---|
| 6502 | { |
|---|
| 6503 | replace = string.replace; |
|---|
| 6504 | } |
|---|
| 6505 | if ( typeof replace != "undefined" ) |
|---|
| 6506 | { |
|---|
| 6507 | for ( var i in replace ) |
|---|
| 6508 | { |
|---|
| 6509 | ret = ret.replace('$'+i, replace[i]); |
|---|
| 6510 | } |
|---|
| 6511 | } |
|---|
| 6512 | |
|---|
| 6513 | return ret; |
|---|
| 6514 | }; |
|---|
| 6515 | |
|---|
| 6516 | |
|---|
| 6517 | |
|---|
| 6518 | |
|---|
| 6519 | Xinha.hasDisplayedChildren = function(el) |
|---|
| 6520 | { |
|---|
| 6521 | var children = el.childNodes; |
|---|
| 6522 | for ( var i = 0; i < children.length; i++ ) |
|---|
| 6523 | { |
|---|
| 6524 | if ( children[i].tagName ) |
|---|
| 6525 | { |
|---|
| 6526 | if ( children[i].style.display != 'none' ) |
|---|
| 6527 | { |
|---|
| 6528 | return true; |
|---|
| 6529 | } |
|---|
| 6530 | } |
|---|
| 6531 | } |
|---|
| 6532 | return false; |
|---|
| 6533 | }; |
|---|
| 6534 | |
|---|
| 6535 | |
|---|
| 6536 | |
|---|
| 6537 | |
|---|
| 6538 | |
|---|
| 6539 | |
|---|
| 6540 | |
|---|
| 6541 | |
|---|
| 6542 | |
|---|
| 6543 | |
|---|
| 6544 | |
|---|
| 6545 | |
|---|
| 6546 | Xinha._loadback = function(url, callback, scope, bonus) |
|---|
| 6547 | { |
|---|
| 6548 | if ( document.getElementById(url) ) |
|---|
| 6549 | { |
|---|
| 6550 | return true; |
|---|
| 6551 | } |
|---|
| 6552 | var t = !Xinha.is_ie ? "onload" : 'onreadystatechange'; |
|---|
| 6553 | var s = document.createElement("script"); |
|---|
| 6554 | s.type = "text/javascript"; |
|---|
| 6555 | s.src = url; |
|---|
| 6556 | s.id = url; |
|---|
| 6557 | if ( callback ) |
|---|
| 6558 | { |
|---|
| 6559 | s[t] = function() |
|---|
| 6560 | { |
|---|
| 6561 | if ( Xinha.is_ie && ( ! ( /loaded|complete/.test(window.event.srcElement.readyState) ) ) ) |
|---|
| 6562 | { |
|---|
| 6563 | return; |
|---|
| 6564 | } |
|---|
| 6565 | |
|---|
| 6566 | callback.call(scope ? scope : this, bonus); |
|---|
| 6567 | s[t] = null; |
|---|
| 6568 | }; |
|---|
| 6569 | } |
|---|
| 6570 | document.getElementsByTagName("head")[0].appendChild(s); |
|---|
| 6571 | return false; |
|---|
| 6572 | }; |
|---|
| 6573 | |
|---|
| 6574 | |
|---|
| 6575 | |
|---|
| 6576 | |
|---|
| 6577 | |
|---|
| 6578 | |
|---|
| 6579 | |
|---|
| 6580 | Xinha.makeEditors = function(editor_names, default_config, plugin_names) |
|---|
| 6581 | { |
|---|
| 6582 | if ( !Xinha.isSupportedBrowser ) return; |
|---|
| 6583 | |
|---|
| 6584 | if ( typeof default_config == 'function' ) |
|---|
| 6585 | { |
|---|
| 6586 | default_config = default_config(); |
|---|
| 6587 | } |
|---|
| 6588 | |
|---|
| 6589 | var editors = {}; |
|---|
| 6590 | var textarea; |
|---|
| 6591 | for ( var x = 0; x < editor_names.length; x++ ) |
|---|
| 6592 | { |
|---|
| 6593 | if ( typeof editor_names[x] == 'string' ) |
|---|
| 6594 | { |
|---|
| 6595 | textarea = Xinha.getElementById('textarea', editor_names[x] ); |
|---|
| 6596 | if (!textarea) |
|---|
| 6597 | { |
|---|
| 6598 | editor_names[x] = null; |
|---|
| 6599 | continue; |
|---|
| 6600 | } |
|---|
| 6601 | } |
|---|
| 6602 | |
|---|
| 6603 | else if ( typeof editor_names[x] == 'object' && editor_names[x].tagName && editor_names[x].tagName.toLowerCase() == 'textarea' ) |
|---|
| 6604 | { |
|---|
| 6605 | textarea = editor_names[x]; |
|---|
| 6606 | if ( !textarea.id ) |
|---|
| 6607 | { |
|---|
| 6608 | textarea.id = 'xinha_id_' + x; |
|---|
| 6609 | } |
|---|
| 6610 | } |
|---|
| 6611 | var editor = new Xinha(textarea, Xinha.cloneObject(default_config)); |
|---|
| 6612 | editor.registerPlugins(plugin_names); |
|---|
| 6613 | editors[textarea.id] = editor; |
|---|
| 6614 | } |
|---|
| 6615 | return editors; |
|---|
| 6616 | }; |
|---|
| 6617 | |
|---|
| 6618 | |
|---|
| 6619 | |
|---|
| 6620 | Xinha.startEditors = function(editors) |
|---|
| 6621 | { |
|---|
| 6622 | if ( !Xinha.isSupportedBrowser ) return; |
|---|
| 6623 | |
|---|
| 6624 | for ( var i in editors ) |
|---|
| 6625 | { |
|---|
| 6626 | if ( editors[i].generate ) |
|---|
| 6627 | { |
|---|
| 6628 | editors[i].generate(); |
|---|
| 6629 | } |
|---|
| 6630 | } |
|---|
| 6631 | }; |
|---|
| 6632 | |
|---|
| 6633 | |
|---|
| 6634 | |
|---|
| 6635 | |
|---|
| 6636 | Xinha.prototype.registerPlugins = function(plugin_names) |
|---|
| 6637 | { |
|---|
| 6638 | if ( !Xinha.isSupportedBrowser ) return; |
|---|
| 6639 | |
|---|
| 6640 | if ( plugin_names ) |
|---|
| 6641 | { |
|---|
| 6642 | for ( var i = 0; i < plugin_names.length; i++ ) |
|---|
| 6643 | { |
|---|
| 6644 | this.setLoadingMessage(Xinha._lc('Register plugin $plugin', 'Xinha', {'plugin': plugin_names[i]})); |
|---|
| 6645 | this.registerPlugin(plugin_names[i]); |
|---|
| 6646 | } |
|---|
| 6647 | } |
|---|
| 6648 | }; |
|---|
| 6649 | |
|---|
| 6650 | |
|---|
| 6651 | |
|---|
| 6652 | |
|---|
| 6653 | |
|---|
| 6654 | Xinha.base64_encode = function(input) |
|---|
| 6655 | { |
|---|
| 6656 | var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; |
|---|
| 6657 | var output = ""; |
|---|
| 6658 | var chr1, chr2, chr3; |
|---|
| 6659 | var enc1, enc2, enc3, enc4; |
|---|
| 6660 | var i = 0; |
|---|
| 6661 | |
|---|
| 6662 | do |
|---|
| 6663 | { |
|---|
| 6664 | chr1 = input.charCodeAt(i++); |
|---|
| 6665 | chr2 = input.charCodeAt(i++); |
|---|
| 6666 | chr3 = input.charCodeAt(i++); |
|---|
| 6667 | |
|---|
| 6668 | enc1 = chr1 >> 2; |
|---|
| 6669 | enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); |
|---|
| 6670 | enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); |
|---|
| 6671 | enc4 = chr3 & 63; |
|---|
| 6672 | |
|---|
| 6673 | if ( isNaN(chr2) ) |
|---|
| 6674 | { |
|---|
| 6675 | enc3 = enc4 = 64; |
|---|
| 6676 | } |
|---|
| 6677 | else if ( isNaN(chr3) ) |
|---|
| 6678 | { |
|---|
| 6679 | enc4 = 64; |
|---|
| 6680 | } |
|---|
| 6681 | |
|---|
| 6682 | output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); |
|---|
| 6683 | } while ( i < input.length ); |
|---|
| 6684 | |
|---|
| 6685 | return output; |
|---|
| 6686 | }; |
|---|
| 6687 | |
|---|
| 6688 | |
|---|
| 6689 | |
|---|
| 6690 | |
|---|
| 6691 | |
|---|
| 6692 | Xinha.base64_decode = function(input) |
|---|
| 6693 | { |
|---|
| 6694 | var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; |
|---|
| 6695 | var output = ""; |
|---|
| 6696 | var chr1, chr2, chr3; |
|---|
| 6697 | var enc1, enc2, enc3, enc4; |
|---|
| 6698 | var i = 0; |
|---|
| 6699 | |
|---|
| 6700 | |
|---|
| 6701 | input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); |
|---|
| 6702 | |
|---|
| 6703 | do |
|---|
| 6704 | { |
|---|
| 6705 | enc1 = keyStr.indexOf(input.charAt(i++)); |
|---|
| 6706 | enc2 = keyStr.indexOf(input.charAt(i++)); |
|---|
| 6707 | enc3 = keyStr.indexOf(input.charAt(i++)); |
|---|
| 6708 | enc4 = keyStr.indexOf(input.charAt(i++)); |
|---|
| 6709 | |
|---|
| 6710 | chr1 = (enc1 << 2) | (enc2 >> 4); |
|---|
| 6711 | chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); |
|---|
| 6712 | chr3 = ((enc3 & 3) << 6) | enc4; |
|---|
| 6713 | |
|---|
| 6714 | output = output + String.fromCharCode(chr1); |
|---|
| 6715 | |
|---|
| 6716 | if ( enc3 != 64 ) |
|---|
| 6717 | { |
|---|
| 6718 | output = output + String.fromCharCode(chr2); |
|---|
| 6719 | } |
|---|
| 6720 | if ( enc4 != 64 ) |
|---|
| 6721 | { |
|---|
| 6722 | output = output + String.fromCharCode(chr3); |
|---|
| 6723 | } |
|---|
| 6724 | } while ( i < input.length ); |
|---|
| 6725 | |
|---|
| 6726 | return output; |
|---|
| 6727 | }; |
|---|
| 6728 | |
|---|
| 6729 | |
|---|
| 6730 | |
|---|
| 6731 | |
|---|
| 6732 | Xinha.removeFromParent = function(el) |
|---|
| 6733 | { |
|---|
| 6734 | if ( !el.parentNode ) |
|---|
| 6735 | { |
|---|
| 6736 | return; |
|---|
| 6737 | } |
|---|
| 6738 | var pN = el.parentNode; |
|---|
| 6739 | pN.removeChild(el); |
|---|
| 6740 | return el; |
|---|
| 6741 | }; |
|---|
| 6742 | |
|---|
| 6743 | |
|---|
| 6744 | |
|---|
| 6745 | |
|---|
| 6746 | Xinha.hasParentNode = function(el) |
|---|
| 6747 | { |
|---|
| 6748 | if ( el.parentNode ) |
|---|
| 6749 | { |
|---|
| 6750 | |
|---|
| 6751 | |
|---|
| 6752 | if ( el.parentNode.nodeType == 11 ) |
|---|
| 6753 | { |
|---|
| 6754 | return false; |
|---|
| 6755 | } |
|---|
| 6756 | return true; |
|---|
| 6757 | } |
|---|
| 6758 | |
|---|
| 6759 | return false; |
|---|
| 6760 | }; |
|---|
| 6761 | |
|---|
| 6762 | |
|---|
| 6763 | |
|---|
| 6764 | |
|---|
| 6765 | |
|---|
| 6766 | Xinha.viewportSize = function(scope) |
|---|
| 6767 | { |
|---|
| 6768 | scope = (scope) ? scope : window; |
|---|
| 6769 | var x,y; |
|---|
| 6770 | if (scope.innerHeight) |
|---|
| 6771 | { |
|---|
| 6772 | x = scope.innerWidth; |
|---|
| 6773 | y = scope.innerHeight; |
|---|
| 6774 | } |
|---|
| 6775 | else if (scope.document.documentElement && scope.document.documentElement.clientHeight) |
|---|
| 6776 | |
|---|
| 6777 | { |
|---|
| 6778 | x = scope.document.documentElement.clientWidth; |
|---|
| 6779 | y = scope.document.documentElement.clientHeight; |
|---|
| 6780 | } |
|---|
| 6781 | else if (scope.document.body) |
|---|
| 6782 | { |
|---|
| 6783 | x = scope.document.body.clientWidth; |
|---|
| 6784 | y = scope.document.body.clientHeight; |
|---|
| 6785 | } |
|---|
| 6786 | return {'x':x,'y':y}; |
|---|
| 6787 | }; |
|---|
| 6788 | |
|---|
| 6789 | |
|---|
| 6790 | |
|---|
| 6791 | |
|---|
| 6792 | Xinha.pageSize = function(scope) |
|---|
| 6793 | { |
|---|
| 6794 | scope = (scope) ? scope : window; |
|---|
| 6795 | var x,y; |
|---|
| 6796 | |
|---|
| 6797 | var test1 = scope.document.body.scrollHeight; |
|---|
| 6798 | var test2 = scope.document.documentElement.scrollHeight; |
|---|
| 6799 | |
|---|
| 6800 | if (test1 > test2) |
|---|
| 6801 | { |
|---|
| 6802 | x = scope.document.body.scrollWidth; |
|---|
| 6803 | y = scope.document.body.scrollHeight; |
|---|
| 6804 | } |
|---|
| 6805 | else |
|---|
| 6806 | { |
|---|
| 6807 | x = scope.document.documentElement.scrollWidth; |
|---|
| 6808 | y = scope.document.documentElement.scrollHeight; |
|---|
| 6809 | } |
|---|
| 6810 | return {'x':x,'y':y}; |
|---|
| 6811 | }; |
|---|
| 6812 | |
|---|
| 6813 | |
|---|
| 6814 | |
|---|
| 6815 | |
|---|
| 6816 | Xinha.prototype.scrollPos = function(scope) |
|---|
| 6817 | { |
|---|
| 6818 | scope = (scope) ? scope : window; |
|---|
| 6819 | var x,y; |
|---|
| 6820 | if (typeof scope.pageYOffset != 'undefined') |
|---|
| 6821 | { |
|---|
| 6822 | x = scope.pageXOffset; |
|---|
| 6823 | y = scope.pageYOffset; |
|---|
| 6824 | } |
|---|
| 6825 | else if (scope.document.documentElement && typeof document.documentElement.scrollTop != 'undefined') |
|---|
| 6826 | |
|---|
| 6827 | { |
|---|
| 6828 | x = scope.document.documentElement.scrollLeft; |
|---|
| 6829 | y = scope.document.documentElement.scrollTop; |
|---|
| 6830 | } |
|---|
| 6831 | else if (scope.document.body) |
|---|
| 6832 | { |
|---|
| 6833 | x = scope.document.body.scrollLeft; |
|---|
| 6834 | y = scope.document.body.scrollTop; |
|---|
| 6835 | } |
|---|
| 6836 | return {'x':x,'y':y}; |
|---|
| 6837 | }; |
|---|
| 6838 | |
|---|
| 6839 | |
|---|
| 6840 | |
|---|
| 6841 | |
|---|
| 6842 | |
|---|
| 6843 | |
|---|
| 6844 | Xinha.getElementTopLeft = function(element) |
|---|
| 6845 | { |
|---|
| 6846 | var curleft = curtop = 0; |
|---|
| 6847 | if (element.offsetParent) |
|---|
| 6848 | { |
|---|
| 6849 | curleft = element.offsetLeft |
|---|
| 6850 | curtop = element.offsetTop |
|---|
| 6851 | while (element = element.offsetParent) |
|---|
| 6852 | { |
|---|
| 6853 | curleft += element.offsetLeft |
|---|
| 6854 | curtop += element.offsetTop |
|---|
| 6855 | } |
|---|
| 6856 | } |
|---|
| 6857 | return { top:curtop, left:curleft }; |
|---|
| 6858 | } |
|---|
| 6859 | |
|---|
| 6860 | |
|---|
| 6861 | |
|---|
| 6862 | |
|---|
| 6863 | Xinha.findPosX = function(obj) |
|---|
| 6864 | { |
|---|
| 6865 | var curleft = 0; |
|---|
| 6866 | if ( obj.offsetParent ) |
|---|
| 6867 | { |
|---|
| 6868 | return Xinha.getElementTopLeft(obj).left; |
|---|
| 6869 | } |
|---|
| 6870 | else if ( obj.x ) |
|---|
| 6871 | { |
|---|
| 6872 | curleft += obj.x; |
|---|
| 6873 | } |
|---|
| 6874 | return curleft; |
|---|
| 6875 | }; |
|---|
| 6876 | |
|---|
| 6877 | |
|---|
| 6878 | |
|---|
| 6879 | |
|---|
| 6880 | Xinha.findPosY = function(obj) |
|---|
| 6881 | { |
|---|
| 6882 | var curtop = 0; |
|---|
| 6883 | if ( obj.offsetParent ) |
|---|
| 6884 | { |
|---|
| 6885 | return Xinha.getElementTopLeft(obj).top; |
|---|
| 6886 | } |
|---|
| 6887 | else if ( obj.y ) |
|---|
| 6888 | { |
|---|
| 6889 | curtop += obj.y; |
|---|
| 6890 | } |
|---|
| 6891 | return curtop; |
|---|
| 6892 | }; |
|---|
| 6893 | |
|---|
| 6894 | Xinha.createLoadingMessages = function(xinha_editors) |
|---|
| 6895 | { |
|---|
| 6896 | if ( Xinha.loadingMessages || !Xinha.isSupportedBrowser ) |
|---|
| 6897 | { |
|---|
| 6898 | return; |
|---|
| 6899 | } |
|---|
| 6900 | Xinha.loadingMessages = []; |
|---|
| 6901 | |
|---|
| 6902 | for (var i=0;i<xinha_editors.length;i++) |
|---|
| 6903 | { |
|---|
| 6904 | if (!document.getElementById(xinha_editors[i])) continue; |
|---|
| 6905 | Xinha.loadingMessages.push(Xinha.createLoadingMessage(Xinha.getElementById('textarea', xinha_editors[i]))); |
|---|
| 6906 | } |
|---|
| 6907 | }; |
|---|
| 6908 | |
|---|
| 6909 | Xinha.createLoadingMessage = function(textarea,text) |
|---|
| 6910 | { |
|---|
| 6911 | if ( document.getElementById("loading_" + textarea.id) || !Xinha.isSupportedBrowser) |
|---|
| 6912 | { |
|---|
| 6913 | return; |
|---|
| 6914 | } |
|---|
| 6915 | |
|---|
| 6916 | |
|---|
| 6917 | var loading_message = document.createElement("div"); |
|---|
| 6918 | loading_message.id = "loading_" + textarea.id; |
|---|
| 6919 | loading_message.className = "loading"; |
|---|
| 6920 | |
|---|
| 6921 | loading_message.style.left = (Xinha.findPosX(textarea) + textarea.offsetWidth / 2) - 106 + 'px'; |
|---|
| 6922 | loading_message.style.top = (Xinha.findPosY(textarea) + textarea.offsetHeight / 2) - 50 + 'px'; |
|---|
| 6923 | |
|---|
| 6924 | var loading_main = document.createElement("div"); |
|---|
| 6925 | loading_main.className = "loading_main"; |
|---|
| 6926 | loading_main.id = "loading_main_" + textarea.id; |
|---|
| 6927 | loading_main.appendChild(document.createTextNode(Xinha._lc("Loading in progress. Please wait!"))); |
|---|
| 6928 | |
|---|
| 6929 | var loading_sub = document.createElement("div"); |
|---|
| 6930 | loading_sub.className = "loading_sub"; |
|---|
| 6931 | loading_sub.id = "loading_sub_" + textarea.id; |
|---|
| 6932 | text = text ? text : Xinha._lc("Loading Core"); |
|---|
| 6933 | loading_sub.appendChild(document.createTextNode(text)); |
|---|
| 6934 | loading_message.appendChild(loading_main); |
|---|
| 6935 | loading_message.appendChild(loading_sub); |
|---|
| 6936 | document.body.appendChild(loading_message); |
|---|
| 6937 | |
|---|
| 6938 | Xinha.freeLater(loading_message); |
|---|
| 6939 | Xinha.freeLater(loading_main); |
|---|
| 6940 | Xinha.freeLater(loading_sub); |
|---|
| 6941 | |
|---|
| 6942 | return loading_sub; |
|---|
| 6943 | }; |
|---|
| 6944 | |
|---|
| 6945 | Xinha.prototype.setLoadingMessage = function(subMessage, mainMessage) |
|---|
| 6946 | { |
|---|
| 6947 | if ( !document.getElementById("loading_sub_" + this._textArea.id) ) |
|---|
| 6948 | { |
|---|
| 6949 | return; |
|---|
| 6950 | } |
|---|
| 6951 | document.getElementById("loading_main_" + this._textArea.id).innerHTML = mainMessage ? mainMessage : Xinha._lc("Loading in progress. Please wait!"); |
|---|
| 6952 | document.getElementById("loading_sub_" + this._textArea.id).innerHTML = subMessage; |
|---|
| 6953 | }; |
|---|
| 6954 | |
|---|
| 6955 | Xinha.setLoadingMessage = function(string) |
|---|
| 6956 | { |
|---|
| 6957 | if (!Xinha.loadingMessages) return; |
|---|
| 6958 | for ( var i = 0; i < Xinha.loadingMessages.length; i++ ) |
|---|
| 6959 | { |
|---|
| 6960 | Xinha.loadingMessages[i].innerHTML = string; |
|---|
| 6961 | } |
|---|
| 6962 | }; |
|---|
| 6963 | |
|---|
| 6964 | Xinha.prototype.removeLoadingMessage = function() |
|---|
| 6965 | { |
|---|
| 6966 | if (document.getElementById("loading_" + this._textArea.id) ) |
|---|
| 6967 | { |
|---|
| 6968 | document.body.removeChild(document.getElementById("loading_" + this._textArea.id)); |
|---|
| 6969 | } |
|---|
| 6970 | }; |
|---|
| 6971 | |
|---|
| 6972 | Xinha.removeLoadingMessages = function(xinha_editors) |
|---|
| 6973 | { |
|---|
| 6974 | for (var i=0;i< xinha_editors.length;i++) |
|---|
| 6975 | { |
|---|
| 6976 | if (!document.getElementById(xinha_editors[i])) continue; |
|---|
| 6977 | var main = document.getElementById("loading_" + document.getElementById(xinha_editors[i]).id); |
|---|
| 6978 | main.parentNode.removeChild(main); |
|---|
| 6979 | } |
|---|
| 6980 | Xinha.loadingMessages = null; |
|---|
| 6981 | }; |
|---|
| 6982 | |
|---|
| 6983 | |
|---|
| 6984 | |
|---|
| 6985 | |
|---|
| 6986 | |
|---|
| 6987 | |
|---|
| 6988 | |
|---|
| 6989 | |
|---|
| 6990 | Xinha.toFree = []; |
|---|
| 6991 | |
|---|
| 6992 | |
|---|
| 6993 | |
|---|
| 6994 | |
|---|
| 6995 | |
|---|
| 6996 | |
|---|
| 6997 | |
|---|
| 6998 | |
|---|
| 6999 | Xinha.freeLater = function(obj,prop) |
|---|
| 7000 | { |
|---|
| 7001 | Xinha.toFree.push({o:obj,p:prop}); |
|---|
| 7002 | }; |
|---|
| 7003 | |
|---|
| 7004 | |
|---|
| 7005 | |
|---|
| 7006 | |
|---|
| 7007 | |
|---|
| 7008 | |
|---|
| 7009 | |
|---|
| 7010 | |
|---|
| 7011 | Xinha.free = function(obj, prop) |
|---|
| 7012 | { |
|---|
| 7013 | if ( obj && !prop ) |
|---|
| 7014 | { |
|---|
| 7015 | for ( var p in obj ) |
|---|
| 7016 | { |
|---|
| 7017 | Xinha.free(obj, p); |
|---|
| 7018 | } |
|---|
| 7019 | } |
|---|
| 7020 | else if ( obj ) |
|---|
| 7021 | { |
|---|
| 7022 | if ( prop.indexOf('src') == -1 ) |
|---|
| 7023 | { |
|---|
| 7024 | try { obj[prop] = null; } catch(x) {} |
|---|
| 7025 | } |
|---|
| 7026 | } |
|---|
| 7027 | }; |
|---|
| 7028 | |
|---|
| 7029 | |
|---|
| 7030 | |
|---|
| 7031 | |
|---|
| 7032 | |
|---|
| 7033 | |
|---|
| 7034 | |
|---|
| 7035 | |
|---|
| 7036 | Xinha.collectGarbageForIE = function() |
|---|
| 7037 | { |
|---|
| 7038 | Xinha.flushEvents(); |
|---|
| 7039 | for ( var x = 0; x < Xinha.toFree.length; x++ ) |
|---|
| 7040 | { |
|---|
| 7041 | Xinha.free(Xinha.toFree[x].o, Xinha.toFree[x].p); |
|---|
| 7042 | Xinha.toFree[x].o = null; |
|---|
| 7043 | } |
|---|
| 7044 | }; |
|---|
| 7045 | |
|---|
| 7046 | |
|---|
| 7047 | |
|---|
| 7048 | |
|---|
| 7049 | |
|---|
| 7050 | |
|---|
| 7051 | |
|---|
| 7052 | |
|---|
| 7053 | |
|---|
| 7054 | |
|---|
| 7055 | Xinha.prototype.insertNodeAtSelection = function(toBeInserted) { Xinha.notImplemented("insertNodeAtSelection"); } |
|---|
| 7056 | |
|---|
| 7057 | |
|---|
| 7058 | |
|---|
| 7059 | |
|---|
| 7060 | |
|---|
| 7061 | |
|---|
| 7062 | Xinha.prototype.getParentElement = function(sel) { Xinha.notImplemented("getParentElement"); } |
|---|
| 7063 | |
|---|
| 7064 | |
|---|
| 7065 | |
|---|
| 7066 | |
|---|
| 7067 | |
|---|
| 7068 | |
|---|
| 7069 | |
|---|
| 7070 | |
|---|
| 7071 | |
|---|
| 7072 | Xinha.prototype.activeElement = function(sel) { Xinha.notImplemented("activeElement"); } |
|---|
| 7073 | |
|---|
| 7074 | |
|---|
| 7075 | |
|---|
| 7076 | |
|---|
| 7077 | |
|---|
| 7078 | |
|---|
| 7079 | |
|---|
| 7080 | Xinha.prototype.selectionEmpty = function(sel) { Xinha.notImplemented("selectionEmpty"); } |
|---|
| 7081 | |
|---|
| 7082 | |
|---|
| 7083 | |
|---|
| 7084 | |
|---|
| 7085 | |
|---|
| 7086 | |
|---|
| 7087 | Xinha.prototype.saveSelection = function() { Xinha.notImplemented("saveSelection"); } |
|---|
| 7088 | |
|---|
| 7089 | |
|---|
| 7090 | |
|---|
| 7091 | |
|---|
| 7092 | Xinha.prototype.restoreSelection = function(savedSelection) { Xinha.notImplemented("restoreSelection"); } |
|---|
| 7093 | |
|---|
| 7094 | |
|---|
| 7095 | |
|---|
| 7096 | |
|---|
| 7097 | |
|---|
| 7098 | |
|---|
| 7099 | |
|---|
| 7100 | |
|---|
| 7101 | Xinha.prototype.selectNodeContents = function(node,pos) { Xinha.notImplemented("selectNodeContents"); } |
|---|
| 7102 | |
|---|
| 7103 | |
|---|
| 7104 | |
|---|
| 7105 | |
|---|
| 7106 | |
|---|
| 7107 | |
|---|
| 7108 | Xinha.prototype.insertHTML = function(html) { Xinha.notImplemented("insertHTML"); } |
|---|
| 7109 | |
|---|
| 7110 | |
|---|
| 7111 | |
|---|
| 7112 | |
|---|
| 7113 | |
|---|
| 7114 | Xinha.prototype.getSelectedHTML = function() { Xinha.notImplemented("getSelectedHTML"); } |
|---|
| 7115 | |
|---|
| 7116 | |
|---|
| 7117 | |
|---|
| 7118 | |
|---|
| 7119 | |
|---|
| 7120 | |
|---|
| 7121 | Xinha.prototype.getSelection = function() { Xinha.notImplemented("getSelection"); } |
|---|
| 7122 | |
|---|
| 7123 | |
|---|
| 7124 | |
|---|
| 7125 | |
|---|
| 7126 | |
|---|
| 7127 | |
|---|
| 7128 | Xinha.prototype.createRange = function(sel) { Xinha.notImplemented("createRange"); } |
|---|
| 7129 | |
|---|
| 7130 | |
|---|
| 7131 | |
|---|
| 7132 | |
|---|
| 7133 | |
|---|
| 7134 | |
|---|
| 7135 | |
|---|
| 7136 | Xinha.prototype.isKeyEvent = function(event) { Xinha.notImplemented("isKeyEvent"); } |
|---|
| 7137 | |
|---|
| 7138 | |
|---|
| 7139 | |
|---|
| 7140 | |
|---|
| 7141 | |
|---|
| 7142 | |
|---|
| 7143 | |
|---|
| 7144 | |
|---|
| 7145 | Xinha.prototype.isShortCut = function(keyEvent) |
|---|
| 7146 | { |
|---|
| 7147 | if(keyEvent.ctrlKey && !keyEvent.altKey) |
|---|
| 7148 | { |
|---|
| 7149 | return true; |
|---|
| 7150 | } |
|---|
| 7151 | |
|---|
| 7152 | return false; |
|---|
| 7153 | } |
|---|
| 7154 | |
|---|
| 7155 | |
|---|
| 7156 | |
|---|
| 7157 | |
|---|
| 7158 | |
|---|
| 7159 | |
|---|
| 7160 | |
|---|
| 7161 | |
|---|
| 7162 | Xinha.prototype.getKey = function(keyEvent) { Xinha.notImplemented("getKey"); } |
|---|
| 7163 | |
|---|
| 7164 | |
|---|
| 7165 | |
|---|
| 7166 | |
|---|
| 7167 | |
|---|
| 7168 | |
|---|
| 7169 | |
|---|
| 7170 | Xinha.getOuterHTML = function(element) { Xinha.notImplemented("getOuterHTML"); } |
|---|
| 7171 | |
|---|
| 7172 | |
|---|
| 7173 | |
|---|
| 7174 | |
|---|
| 7175 | |
|---|
| 7176 | |
|---|
| 7177 | Xinha.getXMLHTTPRequestObject = function() |
|---|
| 7178 | { |
|---|
| 7179 | try |
|---|
| 7180 | { |
|---|
| 7181 | if (typeof XMLHttpRequest != "undefined" && typeof XMLHttpRequest.constructor == 'function' ) |
|---|
| 7182 | { |
|---|
| 7183 | return new XMLHttpRequest(); |
|---|
| 7184 | } |
|---|
| 7185 | else if (typeof ActiveXObject == "function") |
|---|
| 7186 | { |
|---|
| 7187 | return new ActiveXObject("Microsoft.XMLHTTP"); |
|---|
| 7188 | } |
|---|
| 7189 | } |
|---|
| 7190 | catch(e) |
|---|
| 7191 | { |
|---|
| 7192 | Xinha.notImplemented('getXMLHTTPRequestObject'); |
|---|
| 7193 | } |
|---|
| 7194 | } |
|---|
| 7195 | |
|---|
| 7196 | |
|---|
| 7197 | |
|---|
| 7198 | |
|---|
| 7199 | |
|---|
| 7200 | |
|---|
| 7201 | |
|---|
| 7202 | Xinha.prototype._activeElement = function(sel) { return this.activeElement(sel); } |
|---|
| 7203 | |
|---|
| 7204 | |
|---|
| 7205 | |
|---|
| 7206 | |
|---|
| 7207 | |
|---|
| 7208 | |
|---|
| 7209 | Xinha.prototype._selectionEmpty = function(sel) { return this.selectionEmpty(sel); } |
|---|
| 7210 | |
|---|
| 7211 | |
|---|
| 7212 | |
|---|
| 7213 | |
|---|
| 7214 | |
|---|
| 7215 | Xinha.prototype._getSelection = function() { return this.getSelection(); } |
|---|
| 7216 | |
|---|
| 7217 | |
|---|
| 7218 | |
|---|
| 7219 | |
|---|
| 7220 | |
|---|
| 7221 | |
|---|
| 7222 | Xinha.prototype._createRange = function(sel) { return this.createRange(sel); } |
|---|
| 7223 | HTMLArea = Xinha; |
|---|
| 7224 | |
|---|
| 7225 | Xinha.init(); |
|---|
| 7226 | |
|---|
| 7227 | if ( Xinha.ie_version < 8 ) |
|---|
| 7228 | { |
|---|
| 7229 | Xinha.addDom0Event(window,'unload',Xinha.collectGarbageForIE); |
|---|
| 7230 | } |
|---|
| 7231 | Xinha.notImplemented = function(methodName) |
|---|
| 7232 | { |
|---|
| 7233 | throw new Error("Method Not Implemented", "Part of Xinha has tried to call the " + methodName + " method which has not been implemented."); |
|---|
| 7234 | } |
|---|