You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

13395 line
336 KiB

  1. (function(win) {
  2. var whiteSpaceRe = /^\s*|\s*$/g,
  3. undefined, isRegExpBroken = 'B'.replace(/A(.)|B/, '$1') === '$1';
  4. var tinymce = {
  5. majorVersion : '3',
  6. minorVersion : '3.9.3',
  7. releaseDate : '2010-12-20',
  8. _init : function() {
  9. var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v;
  10. t.isOpera = win.opera && opera.buildNumber;
  11. t.isWebKit = /WebKit/.test(ua);
  12. t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName);
  13. t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
  14. t.isGecko = !t.isWebKit && /Gecko/.test(ua);
  15. t.isMac = ua.indexOf('Mac') != -1;
  16. t.isAir = /adobeair/i.test(ua);
  17. t.isIDevice = /(iPad|iPhone)/.test(ua);
  18. // TinyMCE .NET webcontrol might be setting the values for TinyMCE
  19. if (win.tinyMCEPreInit) {
  20. t.suffix = tinyMCEPreInit.suffix;
  21. t.baseURL = tinyMCEPreInit.base;
  22. t.query = tinyMCEPreInit.query;
  23. return;
  24. }
  25. // Get suffix and base
  26. t.suffix = '';
  27. // If base element found, add that infront of baseURL
  28. nl = d.getElementsByTagName('base');
  29. for (i=0; i<nl.length; i++) {
  30. if (v = nl[i].href) {
  31. // Host only value like http://site.com or http://site.com:8008
  32. if (/^https?:\/\/[^\/]+$/.test(v))
  33. v += '/';
  34. base = v ? v.match(/.*\//)[0] : ''; // Get only directory
  35. }
  36. }
  37. function getBase(n) {
  38. if (n.src && /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src)) {
  39. if (/_(src|dev)\.js/g.test(n.src))
  40. t.suffix = '_src';
  41. if ((p = n.src.indexOf('?')) != -1)
  42. t.query = n.src.substring(p + 1);
  43. t.baseURL = n.src.substring(0, n.src.lastIndexOf('/'));
  44. // If path to script is relative and a base href was found add that one infront
  45. // the src property will always be an absolute one on non IE browsers and IE 8
  46. // so this logic will basically only be executed on older IE versions
  47. if (base && t.baseURL.indexOf('://') == -1 && t.baseURL.indexOf('/') !== 0)
  48. t.baseURL = base + t.baseURL;
  49. return t.baseURL;
  50. }
  51. return null;
  52. };
  53. // Check document
  54. nl = d.getElementsByTagName('script');
  55. for (i=0; i<nl.length; i++) {
  56. if (getBase(nl[i]))
  57. return;
  58. }
  59. // Check head
  60. n = d.getElementsByTagName('head')[0];
  61. if (n) {
  62. nl = n.getElementsByTagName('script');
  63. for (i=0; i<nl.length; i++) {
  64. if (getBase(nl[i]))
  65. return;
  66. }
  67. }
  68. return;
  69. },
  70. is : function(o, t) {
  71. if (!t)
  72. return o !== undefined;
  73. if (t == 'array' && (o.hasOwnProperty && o instanceof Array))
  74. return true;
  75. return typeof(o) == t;
  76. },
  77. each : function(o, cb, s) {
  78. var n, l;
  79. if (!o)
  80. return 0;
  81. s = s || o;
  82. if (o.length !== undefined) {
  83. // Indexed arrays, needed for Safari
  84. for (n=0, l = o.length; n < l; n++) {
  85. if (cb.call(s, o[n], n, o) === false)
  86. return 0;
  87. }
  88. } else {
  89. // Hashtables
  90. for (n in o) {
  91. if (o.hasOwnProperty(n)) {
  92. if (cb.call(s, o[n], n, o) === false)
  93. return 0;
  94. }
  95. }
  96. }
  97. return 1;
  98. },
  99. trim : function(s) {
  100. return (s ? '' + s : '').replace(whiteSpaceRe, '');
  101. },
  102. create : function(s, p) {
  103. var t = this, sp, ns, cn, scn, c, de = 0;
  104. // Parse : <prefix> <class>:<super class>
  105. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  106. cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
  107. // Create namespace for new class
  108. ns = t.createNS(s[3].replace(/\.\w+$/, ''));
  109. // Class already exists
  110. if (ns[cn])
  111. return;
  112. // Make pure static class
  113. if (s[2] == 'static') {
  114. ns[cn] = p;
  115. if (this.onCreate)
  116. this.onCreate(s[2], s[3], ns[cn]);
  117. return;
  118. }
  119. // Create default constructor
  120. if (!p[cn]) {
  121. p[cn] = function() {};
  122. de = 1;
  123. }
  124. // Add constructor and methods
  125. ns[cn] = p[cn];
  126. t.extend(ns[cn].prototype, p);
  127. // Extend
  128. if (s[5]) {
  129. sp = t.resolve(s[5]).prototype;
  130. scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
  131. // Extend constructor
  132. c = ns[cn];
  133. if (de) {
  134. // Add passthrough constructor
  135. ns[cn] = function() {
  136. return sp[scn].apply(this, arguments);
  137. };
  138. } else {
  139. // Add inherit constructor
  140. ns[cn] = function() {
  141. this.parent = sp[scn];
  142. return c.apply(this, arguments);
  143. };
  144. }
  145. ns[cn].prototype[cn] = ns[cn];
  146. // Add super methods
  147. t.each(sp, function(f, n) {
  148. ns[cn].prototype[n] = sp[n];
  149. });
  150. // Add overridden methods
  151. t.each(p, function(f, n) {
  152. // Extend methods if needed
  153. if (sp[n]) {
  154. ns[cn].prototype[n] = function() {
  155. this.parent = sp[n];
  156. return f.apply(this, arguments);
  157. };
  158. } else {
  159. if (n != cn)
  160. ns[cn].prototype[n] = f;
  161. }
  162. });
  163. }
  164. // Add static methods
  165. t.each(p['static'], function(f, n) {
  166. ns[cn][n] = f;
  167. });
  168. if (this.onCreate)
  169. this.onCreate(s[2], s[3], ns[cn].prototype);
  170. },
  171. walk : function(o, f, n, s) {
  172. s = s || this;
  173. if (o) {
  174. if (n)
  175. o = o[n];
  176. tinymce.each(o, function(o, i) {
  177. if (f.call(s, o, i, n) === false)
  178. return false;
  179. tinymce.walk(o, f, n, s);
  180. });
  181. }
  182. },
  183. createNS : function(n, o) {
  184. var i, v;
  185. o = o || win;
  186. n = n.split('.');
  187. for (i=0; i<n.length; i++) {
  188. v = n[i];
  189. if (!o[v])
  190. o[v] = {};
  191. o = o[v];
  192. }
  193. return o;
  194. },
  195. resolve : function(n, o) {
  196. var i, l;
  197. o = o || win;
  198. n = n.split('.');
  199. for (i = 0, l = n.length; i < l; i++) {
  200. o = o[n[i]];
  201. if (!o)
  202. break;
  203. }
  204. return o;
  205. },
  206. addUnload : function(f, s) {
  207. var t = this;
  208. f = {func : f, scope : s || this};
  209. if (!t.unloads) {
  210. function unload() {
  211. var li = t.unloads, o, n;
  212. if (li) {
  213. // Call unload handlers
  214. for (n in li) {
  215. o = li[n];
  216. if (o && o.func)
  217. o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy
  218. }
  219. // Detach unload function
  220. if (win.detachEvent) {
  221. win.detachEvent('onbeforeunload', fakeUnload);
  222. win.detachEvent('onunload', unload);
  223. } else if (win.removeEventListener)
  224. win.removeEventListener('unload', unload, false);
  225. // Destroy references
  226. t.unloads = o = li = w = unload = 0;
  227. // Run garbarge collector on IE
  228. if (win.CollectGarbage)
  229. CollectGarbage();
  230. }
  231. };
  232. function fakeUnload() {
  233. var d = document;
  234. // Is there things still loading, then do some magic
  235. if (d.readyState == 'interactive') {
  236. function stop() {
  237. // Prevent memory leak
  238. d.detachEvent('onstop', stop);
  239. // Call unload handler
  240. if (unload)
  241. unload();
  242. d = 0;
  243. };
  244. // Fire unload when the currently loading page is stopped
  245. if (d)
  246. d.attachEvent('onstop', stop);
  247. // Remove onstop listener after a while to prevent the unload function
  248. // to execute if the user presses cancel in an onbeforeunload
  249. // confirm dialog and then presses the browser stop button
  250. win.setTimeout(function() {
  251. if (d)
  252. d.detachEvent('onstop', stop);
  253. }, 0);
  254. }
  255. };
  256. // Attach unload handler
  257. if (win.attachEvent) {
  258. win.attachEvent('onunload', unload);
  259. win.attachEvent('onbeforeunload', fakeUnload);
  260. } else if (win.addEventListener)
  261. win.addEventListener('unload', unload, false);
  262. // Setup initial unload handler array
  263. t.unloads = [f];
  264. } else
  265. t.unloads.push(f);
  266. return f;
  267. },
  268. removeUnload : function(f) {
  269. var u = this.unloads, r = null;
  270. tinymce.each(u, function(o, i) {
  271. if (o && o.func == f) {
  272. u.splice(i, 1);
  273. r = f;
  274. return false;
  275. }
  276. });
  277. return r;
  278. },
  279. explode : function(s, d) {
  280. return s ? tinymce.map(s.split(d || ','), tinymce.trim) : s;
  281. },
  282. _addVer : function(u) {
  283. var v;
  284. if (!this.query)
  285. return u;
  286. v = (u.indexOf('?') == -1 ? '?' : '&') + this.query;
  287. if (u.indexOf('#') == -1)
  288. return u + v;
  289. return u.replace('#', v + '#');
  290. },
  291. // Fix function for IE 9 where regexps isn't working correctly
  292. // Todo: remove me once MS fixes the bug
  293. _replace : function(find, replace, str) {
  294. // On IE9 we have to fake $x replacement
  295. if (isRegExpBroken) {
  296. return str.replace(find, function() {
  297. var val = replace, args = arguments, i;
  298. for (i = 0; i < args.length - 2; i++) {
  299. if (args[i] === undefined) {
  300. val = val.replace(new RegExp('\\$' + i, 'g'), '');
  301. } else {
  302. val = val.replace(new RegExp('\\$' + i, 'g'), args[i]);
  303. }
  304. }
  305. return val;
  306. });
  307. }
  308. return str.replace(find, replace);
  309. }
  310. };
  311. // Initialize the API
  312. tinymce._init();
  313. // Expose tinymce namespace to the global namespace (window)
  314. win.tinymce = win.tinyMCE = tinymce;
  315. })(window);
  316. (function($, tinymce) {
  317. var is = tinymce.is, attrRegExp = /^(href|src|style)$/i, undefined;
  318. // jQuery is undefined
  319. if (!$)
  320. return alert("Load jQuery first!");
  321. // Stick jQuery into the tinymce namespace
  322. tinymce.$ = $;
  323. // Setup adapter
  324. tinymce.adapter = {
  325. patchEditor : function(editor) {
  326. var fn = $.fn;
  327. // Adapt the css function to make sure that the _mce_style
  328. // attribute gets updated with the new style information
  329. function css(name, value) {
  330. var self = this;
  331. // Remove _mce_style when set operation occurs
  332. if (value)
  333. self.removeAttr('_mce_style');
  334. return fn.css.apply(self, arguments);
  335. };
  336. // Apapt the attr function to make sure that it uses the _mce_ prefixed variants
  337. function attr(name, value) {
  338. var self = this;
  339. // Update/retrive _mce_ attribute variants
  340. if (attrRegExp.test(name)) {
  341. if (value !== undefined) {
  342. // Use TinyMCE behavior when setting the specifc attributes
  343. self.each(function(i, node) {
  344. editor.dom.setAttrib(node, name, value);
  345. });
  346. return self;
  347. } else
  348. return self.attr('_mce_' + name);
  349. }
  350. // Default behavior
  351. return fn.attr.apply(self, arguments);
  352. };
  353. function htmlPatchFunc(func) {
  354. // Returns a modified function that processes
  355. // the HTML before executing the action this makes sure
  356. // that href/src etc gets moved into the _mce_ variants
  357. return function(content) {
  358. if (content)
  359. content = editor.dom.processHTML(content);
  360. return func.call(this, content);
  361. };
  362. };
  363. // Patch various jQuery functions to handle tinymce specific attribute and content behavior
  364. // we don't patch the jQuery.fn directly since it will most likely break compatibility
  365. // with other jQuery logic on the page. Only instances created by TinyMCE should be patched.
  366. function patch(jq) {
  367. // Patch some functions, only patch the object once
  368. if (jq.css !== css) {
  369. // Patch css/attr to use the _mce_ prefixed attribute variants
  370. jq.css = css;
  371. jq.attr = attr;
  372. // Patch HTML functions to use the DOMUtils.processHTML filter logic
  373. jq.html = htmlPatchFunc(fn.html);
  374. jq.append = htmlPatchFunc(fn.append);
  375. jq.prepend = htmlPatchFunc(fn.prepend);
  376. jq.after = htmlPatchFunc(fn.after);
  377. jq.before = htmlPatchFunc(fn.before);
  378. jq.replaceWith = htmlPatchFunc(fn.replaceWith);
  379. jq.tinymce = editor;
  380. // Each pushed jQuery instance needs to be patched
  381. // as well for example when traversing the DOM
  382. jq.pushStack = function() {
  383. return patch(fn.pushStack.apply(this, arguments));
  384. };
  385. }
  386. return jq;
  387. };
  388. // Add a $ function on each editor instance this one is scoped for the editor document object
  389. // this way you can do chaining like this tinymce.get(0).$('p').append('text').css('color', 'red');
  390. editor.$ = function(selector, scope) {
  391. var doc = editor.getDoc();
  392. return patch($(selector || doc, doc || scope));
  393. };
  394. }
  395. };
  396. // Patch in core NS functions
  397. tinymce.extend = $.extend;
  398. tinymce.extend(tinymce, {
  399. map : $.map,
  400. grep : function(a, f) {return $.grep(a, f || function(){return 1;});},
  401. inArray : function(a, v) {return $.inArray(v, a || []);}
  402. /* Didn't iterate stylesheets
  403. each : function(o, cb, s) {
  404. if (!o)
  405. return 0;
  406. var r = 1;
  407. $.each(o, function(nr, el){
  408. if (cb.call(s, el, nr, o) === false) {
  409. r = 0;
  410. return false;
  411. }
  412. });
  413. return r;
  414. }*/
  415. });
  416. // Patch in functions in various clases
  417. // Add a "#ifndefjquery" statement around each core API function you add below
  418. var patches = {
  419. 'tinymce.dom.DOMUtils' : {
  420. /*
  421. addClass : function(e, c) {
  422. if (is(e, 'array') && is(e[0], 'string'))
  423. e = e.join(',#');
  424. return (e && $(is(e, 'string') ? '#' + e : e)
  425. .addClass(c)
  426. .attr('class')) || false;
  427. },
  428. hasClass : function(n, c) {
  429. return $(is(n, 'string') ? '#' + n : n).hasClass(c);
  430. },
  431. removeClass : function(e, c) {
  432. if (!e)
  433. return false;
  434. var r = [];
  435. $(is(e, 'string') ? '#' + e : e)
  436. .removeClass(c)
  437. .each(function(){
  438. r.push(this.className);
  439. });
  440. return r.length == 1 ? r[0] : r;
  441. },
  442. */
  443. select : function(pattern, scope) {
  444. var t = this;
  445. return $.find(pattern, t.get(scope) || t.get(t.settings.root_element) || t.doc, []);
  446. },
  447. is : function(n, patt) {
  448. return $(this.get(n)).is(patt);
  449. }
  450. /*
  451. show : function(e) {
  452. if (is(e, 'array') && is(e[0], 'string'))
  453. e = e.join(',#');
  454. $(is(e, 'string') ? '#' + e : e).css('display', 'block');
  455. },
  456. hide : function(e) {
  457. if (is(e, 'array') && is(e[0], 'string'))
  458. e = e.join(',#');
  459. $(is(e, 'string') ? '#' + e : e).css('display', 'none');
  460. },
  461. isHidden : function(e) {
  462. return $(is(e, 'string') ? '#' + e : e).is(':hidden');
  463. },
  464. insertAfter : function(n, e) {
  465. return $(is(e, 'string') ? '#' + e : e).after(n);
  466. },
  467. replace : function(o, n, k) {
  468. n = $(is(n, 'string') ? '#' + n : n);
  469. if (k)
  470. n.children().appendTo(o);
  471. n.replaceWith(o);
  472. },
  473. setStyle : function(n, na, v) {
  474. if (is(n, 'array') && is(n[0], 'string'))
  475. n = n.join(',#');
  476. $(is(n, 'string') ? '#' + n : n).css(na, v);
  477. },
  478. getStyle : function(n, na, c) {
  479. return $(is(n, 'string') ? '#' + n : n).css(na);
  480. },
  481. setStyles : function(e, o) {
  482. if (is(e, 'array') && is(e[0], 'string'))
  483. e = e.join(',#');
  484. $(is(e, 'string') ? '#' + e : e).css(o);
  485. },
  486. setAttrib : function(e, n, v) {
  487. var t = this, s = t.settings;
  488. if (is(e, 'array') && is(e[0], 'string'))
  489. e = e.join(',#');
  490. e = $(is(e, 'string') ? '#' + e : e);
  491. switch (n) {
  492. case "style":
  493. e.each(function(i, v){
  494. if (s.keep_values)
  495. $(v).attr('_mce_style', v);
  496. v.style.cssText = v;
  497. });
  498. break;
  499. case "class":
  500. e.each(function(){
  501. this.className = v;
  502. });
  503. break;
  504. case "src":
  505. case "href":
  506. e.each(function(i, v){
  507. if (s.keep_values) {
  508. if (s.url_converter)
  509. v = s.url_converter.call(s.url_converter_scope || t, v, n, v);
  510. t.setAttrib(v, '_mce_' + n, v);
  511. }
  512. });
  513. break;
  514. }
  515. if (v !== null && v.length !== 0)
  516. e.attr(n, '' + v);
  517. else
  518. e.removeAttr(n);
  519. },
  520. setAttribs : function(e, o) {
  521. var t = this;
  522. $.each(o, function(n, v){
  523. t.setAttrib(e,n,v);
  524. });
  525. }
  526. */
  527. }
  528. /*
  529. 'tinymce.dom.Event' : {
  530. add : function (o, n, f, s) {
  531. var lo, cb;
  532. cb = function(e) {
  533. e.target = e.target || this;
  534. f.call(s || this, e);
  535. };
  536. if (is(o, 'array') && is(o[0], 'string'))
  537. o = o.join(',#');
  538. o = $(is(o, 'string') ? '#' + o : o);
  539. if (n == 'init') {
  540. o.ready(cb, s);
  541. } else {
  542. if (s) {
  543. o.bind(n, s, cb);
  544. } else {
  545. o.bind(n, cb);
  546. }
  547. }
  548. lo = this._jqLookup || (this._jqLookup = []);
  549. lo.push({func : f, cfunc : cb});
  550. return cb;
  551. },
  552. remove : function(o, n, f) {
  553. // Find cfunc
  554. $(this._jqLookup).each(function() {
  555. if (this.func === f)
  556. f = this.cfunc;
  557. });
  558. if (is(o, 'array') && is(o[0], 'string'))
  559. o = o.join(',#');
  560. $(is(o, 'string') ? '#' + o : o).unbind(n,f);
  561. return true;
  562. }
  563. }
  564. */
  565. };
  566. // Patch functions after a class is created
  567. tinymce.onCreate = function(ty, c, p) {
  568. tinymce.extend(p, patches[c]);
  569. };
  570. })(window.jQuery, tinymce);
  571. tinymce.create('tinymce.util.Dispatcher', {
  572. scope : null,
  573. listeners : null,
  574. Dispatcher : function(s) {
  575. this.scope = s || this;
  576. this.listeners = [];
  577. },
  578. add : function(cb, s) {
  579. this.listeners.push({cb : cb, scope : s || this.scope});
  580. return cb;
  581. },
  582. addToTop : function(cb, s) {
  583. this.listeners.unshift({cb : cb, scope : s || this.scope});
  584. return cb;
  585. },
  586. remove : function(cb) {
  587. var l = this.listeners, o = null;
  588. tinymce.each(l, function(c, i) {
  589. if (cb == c.cb) {
  590. o = cb;
  591. l.splice(i, 1);
  592. return false;
  593. }
  594. });
  595. return o;
  596. },
  597. dispatch : function() {
  598. var s, a = arguments, i, li = this.listeners, c;
  599. // Needs to be a real loop since the listener count might change while looping
  600. // And this is also more efficient
  601. for (i = 0; i<li.length; i++) {
  602. c = li[i];
  603. s = c.cb.apply(c.scope, a);
  604. if (s === false)
  605. break;
  606. }
  607. return s;
  608. }
  609. });
  610. (function() {
  611. var each = tinymce.each;
  612. tinymce.create('tinymce.util.URI', {
  613. URI : function(u, s) {
  614. var t = this, o, a, b;
  615. // Trim whitespace
  616. u = tinymce.trim(u);
  617. // Default settings
  618. s = t.settings = s || {};
  619. // Strange app protocol or local anchor
  620. if (/^(mailto|tel|news|javascript|about|data):/i.test(u) || /^\s*#/.test(u)) {
  621. t.source = u;
  622. return;
  623. }
  624. // Absolute path with no host, fake host and protocol
  625. if (u.indexOf('/') === 0 && u.indexOf('//') !== 0)
  626. u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;
  627. // Relative path http:// or protocol relative //path
  628. if (!/^\w*:?\/\//.test(u))
  629. u = (s.base_uri.protocol || 'http') + '://mce_host' + t.toAbsPath(s.base_uri.path, u);
  630. // Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
  631. u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
  632. u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u);
  633. each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
  634. var s = u[i];
  635. // Zope 3 workaround, they use @@something
  636. if (s)
  637. s = s.replace(/\(mce_at\)/g, '@@');
  638. t[v] = s;
  639. });
  640. if (b = s.base_uri) {
  641. if (!t.protocol)
  642. t.protocol = b.protocol;
  643. if (!t.userInfo)
  644. t.userInfo = b.userInfo;
  645. if (!t.port && t.host == 'mce_host')
  646. t.port = b.port;
  647. if (!t.host || t.host == 'mce_host')
  648. t.host = b.host;
  649. t.source = '';
  650. }
  651. //t.path = t.path || '/';
  652. },
  653. setPath : function(p) {
  654. var t = this;
  655. p = /^(.*?)\/?(\w+)?$/.exec(p);
  656. // Update path parts
  657. t.path = p[0];
  658. t.directory = p[1];
  659. t.file = p[2];
  660. // Rebuild source
  661. t.source = '';
  662. t.getURI();
  663. },
  664. toRelative : function(u) {
  665. var t = this, o;
  666. if (u === "./")
  667. return u;
  668. u = new tinymce.util.URI(u, {base_uri : t});
  669. // Not on same domain/port or protocol
  670. if ((u.host != 'mce_host' && t.host != u.host && u.host) || t.port != u.port || t.protocol != u.protocol)
  671. return u.getURI();
  672. o = t.toRelPath(t.path, u.path);
  673. // Add query
  674. if (u.query)
  675. o += '?' + u.query;
  676. // Add anchor
  677. if (u.anchor)
  678. o += '#' + u.anchor;
  679. return o;
  680. },
  681. toAbsolute : function(u, nh) {
  682. var u = new tinymce.util.URI(u, {base_uri : this});
  683. return u.getURI(this.host == u.host && this.protocol == u.protocol ? nh : 0);
  684. },
  685. toRelPath : function(base, path) {
  686. var items, bp = 0, out = '', i, l;
  687. // Split the paths
  688. base = base.substring(0, base.lastIndexOf('/'));
  689. base = base.split('/');
  690. items = path.split('/');
  691. if (base.length >= items.length) {
  692. for (i = 0, l = base.length; i < l; i++) {
  693. if (i >= items.length || base[i] != items[i]) {
  694. bp = i + 1;
  695. break;
  696. }
  697. }
  698. }
  699. if (base.length < items.length) {
  700. for (i = 0, l = items.length; i < l; i++) {
  701. if (i >= base.length || base[i] != items[i]) {
  702. bp = i + 1;
  703. break;
  704. }
  705. }
  706. }
  707. if (bp == 1)
  708. return path;
  709. for (i = 0, l = base.length - (bp - 1); i < l; i++)
  710. out += "../";
  711. for (i = bp - 1, l = items.length; i < l; i++) {
  712. if (i != bp - 1)
  713. out += "/" + items[i];
  714. else
  715. out += items[i];
  716. }
  717. return out;
  718. },
  719. toAbsPath : function(base, path) {
  720. var i, nb = 0, o = [], tr, outPath;
  721. // Split paths
  722. tr = /\/$/.test(path) ? '/' : '';
  723. base = base.split('/');
  724. path = path.split('/');
  725. // Remove empty chunks
  726. each(base, function(k) {
  727. if (k)
  728. o.push(k);
  729. });
  730. base = o;
  731. // Merge relURLParts chunks
  732. for (i = path.length - 1, o = []; i >= 0; i--) {
  733. // Ignore empty or .
  734. if (path[i].length == 0 || path[i] == ".")
  735. continue;
  736. // Is parent
  737. if (path[i] == '..') {
  738. nb++;
  739. continue;
  740. }
  741. // Move up
  742. if (nb > 0) {
  743. nb--;
  744. continue;
  745. }
  746. o.push(path[i]);
  747. }
  748. i = base.length - nb;
  749. // If /a/b/c or /
  750. if (i <= 0)
  751. outPath = o.reverse().join('/');
  752. else
  753. outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
  754. // Add front / if it's needed
  755. if (outPath.indexOf('/') !== 0)
  756. outPath = '/' + outPath;
  757. // Add traling / if it's needed
  758. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1)
  759. outPath += tr;
  760. return outPath;
  761. },
  762. getURI : function(nh) {
  763. var s, t = this;
  764. // Rebuild source
  765. if (!t.source || nh) {
  766. s = '';
  767. if (!nh) {
  768. if (t.protocol)
  769. s += t.protocol + '://';
  770. if (t.userInfo)
  771. s += t.userInfo + '@';
  772. if (t.host)
  773. s += t.host;
  774. if (t.port)
  775. s += ':' + t.port;
  776. }
  777. if (t.path)
  778. s += t.path;
  779. if (t.query)
  780. s += '?' + t.query;
  781. if (t.anchor)
  782. s += '#' + t.anchor;
  783. t.source = s;
  784. }
  785. return t.source;
  786. }
  787. });
  788. })();
  789. (function() {
  790. var each = tinymce.each;
  791. tinymce.create('static tinymce.util.Cookie', {
  792. getHash : function(n) {
  793. var v = this.get(n), h;
  794. if (v) {
  795. each(v.split('&'), function(v) {
  796. v = v.split('=');
  797. h = h || {};
  798. h[unescape(v[0])] = unescape(v[1]);
  799. });
  800. }
  801. return h;
  802. },
  803. setHash : function(n, v, e, p, d, s) {
  804. var o = '';
  805. each(v, function(v, k) {
  806. o += (!o ? '' : '&') + escape(k) + '=' + escape(v);
  807. });
  808. this.set(n, o, e, p, d, s);
  809. },
  810. get : function(n) {
  811. var c = document.cookie, e, p = n + "=", b;
  812. // Strict mode
  813. if (!c)
  814. return;
  815. b = c.indexOf("; " + p);
  816. if (b == -1) {
  817. b = c.indexOf(p);
  818. if (b != 0)
  819. return null;
  820. } else
  821. b += 2;
  822. e = c.indexOf(";", b);
  823. if (e == -1)
  824. e = c.length;
  825. return unescape(c.substring(b + p.length, e));
  826. },
  827. set : function(n, v, e, p, d, s) {
  828. document.cookie = n + "=" + escape(v) +
  829. ((e) ? "; expires=" + e.toGMTString() : "") +
  830. ((p) ? "; path=" + escape(p) : "") +
  831. ((d) ? "; domain=" + d : "") +
  832. ((s) ? "; secure" : "");
  833. },
  834. remove : function(n, p) {
  835. var d = new Date();
  836. d.setTime(d.getTime() - 1000);
  837. this.set(n, '', d, p, d);
  838. }
  839. });
  840. })();
  841. tinymce.create('static tinymce.util.JSON', {
  842. serialize : function(o) {
  843. var i, v, s = tinymce.util.JSON.serialize, t;
  844. if (o == null)
  845. return 'null';
  846. t = typeof o;
  847. if (t == 'string') {
  848. v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
  849. return '"' + o.replace(/([\u0080-\uFFFF\x00-\x1f\"])/g, function(a, b) {
  850. i = v.indexOf(b);
  851. if (i + 1)
  852. return '\\' + v.charAt(i + 1);
  853. a = b.charCodeAt().toString(16);
  854. return '\\u' + '0000'.substring(a.length) + a;
  855. }) + '"';
  856. }
  857. if (t == 'object') {
  858. if (o.hasOwnProperty && o instanceof Array) {
  859. for (i=0, v = '['; i<o.length; i++)
  860. v += (i > 0 ? ',' : '') + s(o[i]);
  861. return v + ']';
  862. }
  863. v = '{';
  864. for (i in o)
  865. v += typeof o[i] != 'function' ? (v.length > 1 ? ',"' : '"') + i + '":' + s(o[i]) : '';
  866. return v + '}';
  867. }
  868. return '' + o;
  869. },
  870. parse : function(s) {
  871. try {
  872. return eval('(' + s + ')');
  873. } catch (ex) {
  874. // Ignore
  875. }
  876. }
  877. });
  878. tinymce.create('static tinymce.util.XHR', {
  879. send : function(o) {
  880. var x, t, w = window, c = 0;
  881. // Default settings
  882. o.scope = o.scope || this;
  883. o.success_scope = o.success_scope || o.scope;
  884. o.error_scope = o.error_scope || o.scope;
  885. o.async = o.async === false ? false : true;
  886. o.data = o.data || '';
  887. function get(s) {
  888. x = 0;
  889. try {
  890. x = new ActiveXObject(s);
  891. } catch (ex) {
  892. }
  893. return x;
  894. };
  895. x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP');
  896. if (x) {
  897. if (x.overrideMimeType)
  898. x.overrideMimeType(o.content_type);
  899. x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async);
  900. if (o.content_type)
  901. x.setRequestHeader('Content-Type', o.content_type);
  902. x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  903. x.send(o.data);
  904. function ready() {
  905. if (!o.async || x.readyState == 4 || c++ > 10000) {
  906. if (o.success && c < 10000 && x.status == 200)
  907. o.success.call(o.success_scope, '' + x.responseText, x, o);
  908. else if (o.error)
  909. o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o);
  910. x = null;
  911. } else
  912. w.setTimeout(ready, 10);
  913. };
  914. // Syncronous request
  915. if (!o.async)
  916. return ready();
  917. // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
  918. t = w.setTimeout(ready, 10);
  919. }
  920. }
  921. });
  922. (function() {
  923. var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR;
  924. tinymce.create('tinymce.util.JSONRequest', {
  925. JSONRequest : function(s) {
  926. this.settings = extend({
  927. }, s);
  928. this.count = 0;
  929. },
  930. send : function(o) {
  931. var ecb = o.error, scb = o.success;
  932. o = extend(this.settings, o);
  933. o.success = function(c, x) {
  934. c = JSON.parse(c);
  935. if (typeof(c) == 'undefined') {
  936. c = {
  937. error : 'JSON Parse error.'
  938. };
  939. }
  940. if (c.error)
  941. ecb.call(o.error_scope || o.scope, c.error, x);
  942. else
  943. scb.call(o.success_scope || o.scope, c.result);
  944. };
  945. o.error = function(ty, x) {
  946. ecb.call(o.error_scope || o.scope, ty, x);
  947. };
  948. o.data = JSON.serialize({
  949. id : o.id || 'c' + (this.count++),
  950. method : o.method,
  951. params : o.params
  952. });
  953. // JSON content type for Ruby on rails. Bug: #1883287
  954. o.content_type = 'application/json';
  955. XHR.send(o);
  956. },
  957. 'static' : {
  958. sendRPC : function(o) {
  959. return new tinymce.util.JSONRequest().send(o);
  960. }
  961. }
  962. });
  963. }());
  964. (function(tinymce) {
  965. // Shorten names
  966. var each = tinymce.each,
  967. is = tinymce.is,
  968. isWebKit = tinymce.isWebKit,
  969. isIE = tinymce.isIE,
  970. blockRe = /^(H[1-6R]|P|DIV|ADDRESS|PRE|FORM|T(ABLE|BODY|HEAD|FOOT|H|R|D)|LI|OL|UL|CAPTION|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|NOSCRIPT|MENU|ISINDEX|SAMP)$/,
  971. boolAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  972. mceAttribs = makeMap('src,href,style,coords,shape'),
  973. encodedChars = {'&' : '&amp;', '"' : '&quot;', '<' : '&lt;', '>' : '&gt;'},
  974. encodeCharsRe = /[<>&\"]/g,
  975. simpleSelectorRe = /^([a-z0-9],?)+$/i,
  976. tagRegExp = /<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)(\s*\/?)>/g,
  977. attrRegExp = /(\w+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;
  978. function makeMap(str) {
  979. var map = {}, i;
  980. str = str.split(',');
  981. for (i = str.length; i >= 0; i--)
  982. map[str[i]] = 1;
  983. return map;
  984. };
  985. tinymce.create('tinymce.dom.DOMUtils', {
  986. doc : null,
  987. root : null,
  988. files : null,
  989. pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
  990. props : {
  991. "for" : "htmlFor",
  992. "class" : "className",
  993. className : "className",
  994. checked : "checked",
  995. disabled : "disabled",
  996. maxlength : "maxLength",
  997. readonly : "readOnly",
  998. selected : "selected",
  999. value : "value",
  1000. id : "id",
  1001. name : "name",
  1002. type : "type"
  1003. },
  1004. DOMUtils : function(d, s) {
  1005. var t = this, globalStyle;
  1006. t.doc = d;
  1007. t.win = window;
  1008. t.files = {};
  1009. t.cssFlicker = false;
  1010. t.counter = 0;
  1011. t.stdMode = d.documentMode >= 8;
  1012. t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
  1013. t.settings = s = tinymce.extend({
  1014. keep_values : false,
  1015. hex_colors : 1,
  1016. process_html : 1
  1017. }, s);
  1018. // Fix IE6SP2 flicker and check it failed for pre SP2
  1019. if (tinymce.isIE6) {
  1020. try {
  1021. d.execCommand('BackgroundImageCache', false, true);
  1022. } catch (e) {
  1023. t.cssFlicker = true;
  1024. }
  1025. }
  1026. // Build styles list
  1027. if (s.valid_styles) {
  1028. t._styles = {};
  1029. // Convert styles into a rule list
  1030. each(s.valid_styles, function(value, key) {
  1031. t._styles[key] = tinymce.explode(value);
  1032. });
  1033. }
  1034. tinymce.addUnload(t.destroy, t);
  1035. },
  1036. getRoot : function() {
  1037. var t = this, s = t.settings;
  1038. return (s && t.get(s.root_element)) || t.doc.body;
  1039. },
  1040. getViewPort : function(w) {
  1041. var d, b;
  1042. w = !w ? this.win : w;
  1043. d = w.document;
  1044. b = this.boxModel ? d.documentElement : d.body;
  1045. // Returns viewport size excluding scrollbars
  1046. return {
  1047. x : w.pageXOffset || b.scrollLeft,
  1048. y : w.pageYOffset || b.scrollTop,
  1049. w : w.innerWidth || b.clientWidth,
  1050. h : w.innerHeight || b.clientHeight
  1051. };
  1052. },
  1053. getRect : function(e) {
  1054. var p, t = this, sr;
  1055. e = t.get(e);
  1056. p = t.getPos(e);
  1057. sr = t.getSize(e);
  1058. return {
  1059. x : p.x,
  1060. y : p.y,
  1061. w : sr.w,
  1062. h : sr.h
  1063. };
  1064. },
  1065. getSize : function(e) {
  1066. var t = this, w, h;
  1067. e = t.get(e);
  1068. w = t.getStyle(e, 'width');
  1069. h = t.getStyle(e, 'height');
  1070. // Non pixel value, then force offset/clientWidth
  1071. if (w.indexOf('px') === -1)
  1072. w = 0;
  1073. // Non pixel value, then force offset/clientWidth
  1074. if (h.indexOf('px') === -1)
  1075. h = 0;
  1076. return {
  1077. w : parseInt(w) || e.offsetWidth || e.clientWidth,
  1078. h : parseInt(h) || e.offsetHeight || e.clientHeight
  1079. };
  1080. },
  1081. getParent : function(n, f, r) {
  1082. return this.getParents(n, f, r, false);
  1083. },
  1084. getParents : function(n, f, r, c) {
  1085. var t = this, na, se = t.settings, o = [];
  1086. n = t.get(n);
  1087. c = c === undefined;
  1088. if (se.strict_root)
  1089. r = r || t.getRoot();
  1090. // Wrap node name as func
  1091. if (is(f, 'string')) {
  1092. na = f;
  1093. if (f === '*') {
  1094. f = function(n) {return n.nodeType == 1;};
  1095. } else {
  1096. f = function(n) {
  1097. return t.is(n, na);
  1098. };
  1099. }
  1100. }
  1101. while (n) {
  1102. if (n == r || !n.nodeType || n.nodeType === 9)
  1103. break;
  1104. if (!f || f(n)) {
  1105. if (c)
  1106. o.push(n);
  1107. else
  1108. return n;
  1109. }
  1110. n = n.parentNode;
  1111. }
  1112. return c ? o : null;
  1113. },
  1114. get : function(e) {
  1115. var n;
  1116. if (e && this.doc && typeof(e) == 'string') {
  1117. n = e;
  1118. e = this.doc.getElementById(e);
  1119. // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
  1120. if (e && e.id !== n)
  1121. return this.doc.getElementsByName(n)[1];
  1122. }
  1123. return e;
  1124. },
  1125. getNext : function(node, selector) {
  1126. return this._findSib(node, selector, 'nextSibling');
  1127. },
  1128. getPrev : function(node, selector) {
  1129. return this._findSib(node, selector, 'previousSibling');
  1130. },
  1131. add : function(p, n, a, h, c) {
  1132. var t = this;
  1133. return this.run(p, function(p) {
  1134. var e, k;
  1135. e = is(n, 'string') ? t.doc.createElement(n) : n;
  1136. t.setAttribs(e, a);
  1137. if (h) {
  1138. if (h.nodeType)
  1139. e.appendChild(h);
  1140. else
  1141. t.setHTML(e, h);
  1142. }
  1143. return !c ? p.appendChild(e) : e;
  1144. });
  1145. },
  1146. create : function(n, a, h) {
  1147. return this.add(this.doc.createElement(n), n, a, h, 1);
  1148. },
  1149. createHTML : function(n, a, h) {
  1150. var o = '', t = this, k;
  1151. o += '<' + n;
  1152. for (k in a) {
  1153. if (a.hasOwnProperty(k))
  1154. o += ' ' + k + '="' + t.encode(a[k]) + '"';
  1155. }
  1156. // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
  1157. if (typeof(h) != "undefined")
  1158. return o + '>' + h + '</' + n + '>';
  1159. return o + ' />';
  1160. },
  1161. remove : function(node, keep_children) {
  1162. return this.run(node, function(node) {
  1163. var parent, child;
  1164. parent = node.parentNode;
  1165. if (!parent)
  1166. return null;
  1167. if (keep_children) {
  1168. while (child = node.firstChild) {
  1169. // IE 8 will crash if you don't remove completely empty text nodes
  1170. if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue)
  1171. parent.insertBefore(child, node);
  1172. else
  1173. node.removeChild(child);
  1174. }
  1175. }
  1176. return parent.removeChild(node);
  1177. });
  1178. },
  1179. setStyle : function(n, na, v) {
  1180. var t = this;
  1181. return t.run(n, function(e) {
  1182. var s, i;
  1183. s = e.style;
  1184. // Camelcase it, if needed
  1185. na = na.replace(/-(\D)/g, function(a, b){
  1186. return b.toUpperCase();
  1187. });
  1188. // Default px suffix on these
  1189. if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
  1190. v += 'px';
  1191. switch (na) {
  1192. case 'opacity':
  1193. // IE specific opacity
  1194. if (isIE) {
  1195. s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
  1196. if (!n.currentStyle || !n.currentStyle.hasLayout)
  1197. s.display = 'inline-block';
  1198. }
  1199. // Fix for older browsers
  1200. s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
  1201. break;
  1202. case 'float':
  1203. isIE ? s.styleFloat = v : s.cssFloat = v;
  1204. break;
  1205. default:
  1206. s[na] = v || '';
  1207. }
  1208. // Force update of the style data
  1209. if (t.settings.update_styles)
  1210. t.setAttrib(e, '_mce_style');
  1211. });
  1212. },
  1213. getStyle : function(n, na, c) {
  1214. n = this.get(n);
  1215. if (!n)
  1216. return false;
  1217. // Gecko
  1218. if (this.doc.defaultView && c) {
  1219. // Remove camelcase
  1220. na = na.replace(/[A-Z]/g, function(a){
  1221. return '-' + a;
  1222. });
  1223. try {
  1224. return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
  1225. } catch (ex) {
  1226. // Old safari might fail
  1227. return null;
  1228. }
  1229. }
  1230. // Camelcase it, if needed
  1231. na = na.replace(/-(\D)/g, function(a, b){
  1232. return b.toUpperCase();
  1233. });
  1234. if (na == 'float')
  1235. na = isIE ? 'styleFloat' : 'cssFloat';
  1236. // IE & Opera
  1237. if (n.currentStyle && c)
  1238. return n.currentStyle[na];
  1239. return n.style[na];
  1240. },
  1241. setStyles : function(e, o) {
  1242. var t = this, s = t.settings, ol;
  1243. ol = s.update_styles;
  1244. s.update_styles = 0;
  1245. each(o, function(v, n) {
  1246. t.setStyle(e, n, v);
  1247. });
  1248. // Update style info
  1249. s.update_styles = ol;
  1250. if (s.update_styles)
  1251. t.setAttrib(e, s.cssText);
  1252. },
  1253. setAttrib : function(e, n, v) {
  1254. var t = this;
  1255. // Whats the point
  1256. if (!e || !n)
  1257. return;
  1258. // Strict XML mode
  1259. if (t.settings.strict)
  1260. n = n.toLowerCase();
  1261. return this.run(e, function(e) {
  1262. var s = t.settings;
  1263. switch (n) {
  1264. case "style":
  1265. if (!is(v, 'string')) {
  1266. each(v, function(v, n) {
  1267. t.setStyle(e, n, v);
  1268. });
  1269. return;
  1270. }
  1271. // No mce_style for elements with these since they might get resized by the user
  1272. if (s.keep_values) {
  1273. if (v && !t._isRes(v))
  1274. e.setAttribute('_mce_style', v, 2);
  1275. else
  1276. e.removeAttribute('_mce_style', 2);
  1277. }
  1278. e.style.cssText = v;
  1279. break;
  1280. case "class":
  1281. e.className = v || ''; // Fix IE null bug
  1282. break;
  1283. case "src":
  1284. case "href":
  1285. if (s.keep_values) {
  1286. if (s.url_converter)
  1287. v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
  1288. t.setAttrib(e, '_mce_' + n, v, 2);
  1289. }
  1290. break;
  1291. case "shape":
  1292. e.setAttribute('_mce_style', v);
  1293. break;
  1294. }
  1295. if (is(v) && v !== null && v.length !== 0)
  1296. e.setAttribute(n, '' + v, 2);
  1297. else
  1298. e.removeAttribute(n, 2);
  1299. });
  1300. },
  1301. setAttribs : function(e, o) {
  1302. var t = this;
  1303. return this.run(e, function(e) {
  1304. each(o, function(v, n) {
  1305. t.setAttrib(e, n, v);
  1306. });
  1307. });
  1308. },
  1309. getAttrib : function(e, n, dv) {
  1310. var v, t = this;
  1311. e = t.get(e);
  1312. if (!e || e.nodeType !== 1)
  1313. return false;
  1314. if (!is(dv))
  1315. dv = '';
  1316. // Try the mce variant for these
  1317. if (/^(src|href|style|coords|shape)$/.test(n)) {
  1318. v = e.getAttribute("_mce_" + n);
  1319. if (v)
  1320. return v;
  1321. }
  1322. if (isIE && t.props[n]) {
  1323. v = e[t.props[n]];
  1324. v = v && v.nodeValue ? v.nodeValue : v;
  1325. }
  1326. if (!v)
  1327. v = e.getAttribute(n, 2);
  1328. // Check boolean attribs
  1329. if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
  1330. if (e[t.props[n]] === true && v === '')
  1331. return n;
  1332. return v ? n : '';
  1333. }
  1334. // Inner input elements will override attributes on form elements
  1335. if (e.nodeName === "FORM" && e.getAttributeNode(n))
  1336. return e.getAttributeNode(n).nodeValue;
  1337. if (n === 'style') {
  1338. v = v || e.style.cssText;
  1339. if (v) {
  1340. v = t.serializeStyle(t.parseStyle(v), e.nodeName);
  1341. if (t.settings.keep_values && !t._isRes(v))
  1342. e.setAttribute('_mce_style', v);
  1343. }
  1344. }
  1345. // Remove Apple and WebKit stuff
  1346. if (isWebKit && n === "class" && v)
  1347. v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
  1348. // Handle IE issues
  1349. if (isIE) {
  1350. switch (n) {
  1351. case 'rowspan':
  1352. case 'colspan':
  1353. // IE returns 1 as default value
  1354. if (v === 1)
  1355. v = '';
  1356. break;
  1357. case 'size':
  1358. // IE returns +0 as default value for size
  1359. if (v === '+0' || v === 20 || v === 0)
  1360. v = '';
  1361. break;
  1362. case 'width':
  1363. case 'height':
  1364. case 'vspace':
  1365. case 'checked':
  1366. case 'disabled':
  1367. case 'readonly':
  1368. if (v === 0)
  1369. v = '';
  1370. break;
  1371. case 'hspace':
  1372. // IE returns -1 as default value
  1373. if (v === -1)
  1374. v = '';
  1375. break;
  1376. case 'maxlength':
  1377. case 'tabindex':
  1378. // IE returns default value
  1379. if (v === 32768 || v === 2147483647 || v === '32768')
  1380. v = '';
  1381. break;
  1382. case 'multiple':
  1383. case 'compact':
  1384. case 'noshade':
  1385. case 'nowrap':
  1386. if (v === 65535)
  1387. return n;
  1388. return dv;
  1389. case 'shape':
  1390. v = v.toLowerCase();
  1391. break;
  1392. default:
  1393. // IE has odd anonymous function for event attributes
  1394. if (n.indexOf('on') === 0 && v)
  1395. v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
  1396. }
  1397. }
  1398. return (v !== undefined && v !== null && v !== '') ? '' + v : dv;
  1399. },
  1400. getPos : function(n, ro) {
  1401. var t = this, x = 0, y = 0, e, d = t.doc, r;
  1402. n = t.get(n);
  1403. ro = ro || d.body;
  1404. if (n) {
  1405. // Use getBoundingClientRect on IE, Opera has it but it's not perfect
  1406. if (isIE && !t.stdMode) {
  1407. n = n.getBoundingClientRect();
  1408. e = t.boxModel ? d.documentElement : d.body;
  1409. x = t.getStyle(t.select('html')[0], 'borderWidth'); // Remove border
  1410. x = (x == 'medium' || t.boxModel && !t.isIE6) && 2 || x;
  1411. return {x : n.left + e.scrollLeft - x, y : n.top + e.scrollTop - x};
  1412. }
  1413. r = n;
  1414. while (r && r != ro && r.nodeType) {
  1415. x += r.offsetLeft || 0;
  1416. y += r.offsetTop || 0;
  1417. r = r.offsetParent;
  1418. }
  1419. r = n.parentNode;
  1420. while (r && r != ro && r.nodeType) {
  1421. x -= r.scrollLeft || 0;
  1422. y -= r.scrollTop || 0;
  1423. r = r.parentNode;
  1424. }
  1425. }
  1426. return {x : x, y : y};
  1427. },
  1428. parseStyle : function(st) {
  1429. var t = this, s = t.settings, o = {};
  1430. if (!st)
  1431. return o;
  1432. function compress(p, s, ot) {
  1433. var t, r, b, l;
  1434. // Get values and check it it needs compressing
  1435. t = o[p + '-top' + s];
  1436. if (!t)
  1437. return;
  1438. r = o[p + '-right' + s];
  1439. if (t != r)
  1440. return;
  1441. b = o[p + '-bottom' + s];
  1442. if (r != b)
  1443. return;
  1444. l = o[p + '-left' + s];
  1445. if (b != l)
  1446. return;
  1447. // Compress
  1448. o[ot] = l;
  1449. delete o[p + '-top' + s];
  1450. delete o[p + '-right' + s];
  1451. delete o[p + '-bottom' + s];
  1452. delete o[p + '-left' + s];
  1453. };
  1454. function compress2(ta, a, b, c) {
  1455. var t;
  1456. t = o[a];
  1457. if (!t)
  1458. return;
  1459. t = o[b];
  1460. if (!t)
  1461. return;
  1462. t = o[c];
  1463. if (!t)
  1464. return;
  1465. // Compress
  1466. o[ta] = o[a] + ' ' + o[b] + ' ' + o[c];
  1467. delete o[a];
  1468. delete o[b];
  1469. delete o[c];
  1470. };
  1471. st = st.replace(/&(#?[a-z0-9]+);/g, '&$1_MCE_SEMI_'); // Protect entities
  1472. each(st.split(';'), function(v) {
  1473. var sv, ur = [];
  1474. if (v) {
  1475. v = v.replace(/_MCE_SEMI_/g, ';'); // Restore entities
  1476. v = v.replace(/url\([^\)]+\)/g, function(v) {ur.push(v);return 'url(' + ur.length + ')';});
  1477. v = v.split(':');
  1478. sv = tinymce.trim(v[1]);
  1479. sv = sv.replace(/url\(([^\)]+)\)/g, function(a, b) {return ur[parseInt(b) - 1];});
  1480. sv = sv.replace(/rgb\([^\)]+\)/g, function(v) {
  1481. return t.toHex(v);
  1482. });
  1483. if (s.url_converter) {
  1484. sv = sv.replace(/url\([\'\"]?([^\)\'\"]+)[\'\"]?\)/g, function(x, c) {
  1485. return 'url(' + s.url_converter.call(s.url_converter_scope || t, t.decode(c), 'style', null) + ')';
  1486. });
  1487. }
  1488. o[tinymce.trim(v[0]).toLowerCase()] = sv;
  1489. }
  1490. });
  1491. compress("border", "", "border");
  1492. compress("border", "-width", "border-width");
  1493. compress("border", "-color", "border-color");
  1494. compress("border", "-style", "border-style");
  1495. compress("padding", "", "padding");
  1496. compress("margin", "", "margin");
  1497. compress2('border', 'border-width', 'border-style', 'border-color');
  1498. if (isIE) {
  1499. // Remove pointless border
  1500. if (o.border == 'medium none')
  1501. o.border = '';
  1502. }
  1503. return o;
  1504. },
  1505. serializeStyle : function(o, name) {
  1506. var t = this, s = '';
  1507. function add(v, k) {
  1508. if (k && v) {
  1509. // Remove browser specific styles like -moz- or -webkit-
  1510. if (k.indexOf('-') === 0)
  1511. return;
  1512. switch (k) {
  1513. case 'font-weight':
  1514. // Opera will output bold as 700
  1515. if (v == 700)
  1516. v = 'bold';
  1517. break;
  1518. case 'color':
  1519. case 'background-color':
  1520. v = v.toLowerCase();
  1521. break;
  1522. }
  1523. s += (s ? ' ' : '') + k + ': ' + v + ';';
  1524. }
  1525. };
  1526. // Validate style output
  1527. if (name && t._styles) {
  1528. each(t._styles['*'], function(name) {
  1529. add(o[name], name);
  1530. });
  1531. each(t._styles[name.toLowerCase()], function(name) {
  1532. add(o[name], name);
  1533. });
  1534. } else
  1535. each(o, add);
  1536. return s;
  1537. },
  1538. loadCSS : function(u) {
  1539. var t = this, d = t.doc, head;
  1540. if (!u)
  1541. u = '';
  1542. head = t.select('head')[0];
  1543. each(u.split(','), function(u) {
  1544. var link;
  1545. if (t.files[u])
  1546. return;
  1547. t.files[u] = true;
  1548. link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
  1549. // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
  1550. // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
  1551. // It's ugly but it seems to work fine.
  1552. if (isIE && d.documentMode && d.recalc) {
  1553. link.onload = function() {
  1554. d.recalc();
  1555. link.onload = null;
  1556. };
  1557. }
  1558. head.appendChild(link);
  1559. });
  1560. },
  1561. addClass : function(e, c) {
  1562. return this.run(e, function(e) {
  1563. var o;
  1564. if (!c)
  1565. return 0;
  1566. if (this.hasClass(e, c))
  1567. return e.className;
  1568. o = this.removeClass(e, c);
  1569. return e.className = (o != '' ? (o + ' ') : '') + c;
  1570. });
  1571. },
  1572. removeClass : function(e, c) {
  1573. var t = this, re;
  1574. return t.run(e, function(e) {
  1575. var v;
  1576. if (t.hasClass(e, c)) {
  1577. if (!re)
  1578. re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
  1579. v = e.className.replace(re, ' ');
  1580. v = tinymce.trim(v != ' ' ? v : '');
  1581. e.className = v;
  1582. // Empty class attr
  1583. if (!v) {
  1584. e.removeAttribute('class');
  1585. e.removeAttribute('className');
  1586. }
  1587. return v;
  1588. }
  1589. return e.className;
  1590. });
  1591. },
  1592. hasClass : function(n, c) {
  1593. n = this.get(n);
  1594. if (!n || !c)
  1595. return false;
  1596. return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
  1597. },
  1598. show : function(e) {
  1599. return this.setStyle(e, 'display', 'block');
  1600. },
  1601. hide : function(e) {
  1602. return this.setStyle(e, 'display', 'none');
  1603. },
  1604. isHidden : function(e) {
  1605. e = this.get(e);
  1606. return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
  1607. },
  1608. uniqueId : function(p) {
  1609. return (!p ? 'mce_' : p) + (this.counter++);
  1610. },
  1611. setHTML : function(e, h) {
  1612. var t = this;
  1613. return this.run(e, function(e) {
  1614. var x, i, nl, n, p, x;
  1615. h = t.processHTML(h);
  1616. if (isIE) {
  1617. function set() {
  1618. // Remove all child nodes
  1619. while (e.firstChild)
  1620. e.firstChild.removeNode();
  1621. try {
  1622. // IE will remove comments from the beginning
  1623. // unless you padd the contents with something
  1624. e.innerHTML = '<br />' + h;
  1625. e.removeChild(e.firstChild);
  1626. } catch (ex) {
  1627. // IE sometimes produces an unknown runtime error on innerHTML if it's an block element within a block element for example a div inside a p
  1628. // This seems to fix this problem
  1629. // Create new div with HTML contents and a BR infront to keep comments
  1630. x = t.create('div');
  1631. x.innerHTML = '<br />' + h;
  1632. // Add all children from div to target
  1633. each (x.childNodes, function(n, i) {
  1634. // Skip br element
  1635. if (i)
  1636. e.appendChild(n);
  1637. });
  1638. }
  1639. };
  1640. // IE has a serious bug when it comes to paragraphs it can produce an invalid
  1641. // DOM tree if contents like this <p><ul><li>Item 1</li></ul></p> is inserted
  1642. // It seems to be that IE doesn't like a root block element placed inside another root block element
  1643. if (t.settings.fix_ie_paragraphs)
  1644. h = h.replace(/<p><\/p>|<p([^>]+)><\/p>|<p[^\/+]\/>/gi, '<p$1 _mce_keep="true">&nbsp;</p>');
  1645. set();
  1646. if (t.settings.fix_ie_paragraphs) {
  1647. // Check for odd paragraphs this is a sign of a broken DOM
  1648. nl = e.getElementsByTagName("p");
  1649. for (i = nl.length - 1, x = 0; i >= 0; i--) {
  1650. n = nl[i];
  1651. if (!n.hasChildNodes()) {
  1652. if (!n._mce_keep) {
  1653. x = 1; // Is broken
  1654. break;
  1655. }
  1656. n.removeAttribute('_mce_keep');
  1657. }
  1658. }
  1659. }
  1660. // Time to fix the madness IE left us
  1661. if (x) {
  1662. // So if we replace the p elements with divs and mark them and then replace them back to paragraphs
  1663. // after we use innerHTML we can fix the DOM tree
  1664. h = h.replace(/<p ([^>]+)>|<p>/ig, '<div $1 _mce_tmp="1">');
  1665. h = h.replace(/<\/p>/gi, '</div>');
  1666. // Set the new HTML with DIVs
  1667. set();
  1668. // Replace all DIV elements with the _mce_tmp attibute back to paragraphs
  1669. // This is needed since IE has a annoying bug see above for details
  1670. // This is a slow process but it has to be done. :(
  1671. if (t.settings.fix_ie_paragraphs) {
  1672. nl = e.getElementsByTagName("DIV");
  1673. for (i = nl.length - 1; i >= 0; i--) {
  1674. n = nl[i];
  1675. // Is it a temp div
  1676. if (n._mce_tmp) {
  1677. // Create new paragraph
  1678. p = t.doc.createElement('p');
  1679. // Copy all attributes
  1680. n.cloneNode(false).outerHTML.replace(/([a-z0-9\-_]+)=/gi, function(a, b) {
  1681. var v;
  1682. if (b !== '_mce_tmp') {
  1683. v = n.getAttribute(b);
  1684. if (!v && b === 'class')
  1685. v = n.className;
  1686. p.setAttribute(b, v);
  1687. }
  1688. });
  1689. // Append all children to new paragraph
  1690. for (x = 0; x<n.childNodes.length; x++)
  1691. p.appendChild(n.childNodes[x].cloneNode(true));
  1692. // Replace div with new paragraph
  1693. n.swapNode(p);
  1694. }
  1695. }
  1696. }
  1697. }
  1698. } else
  1699. e.innerHTML = h;
  1700. return h;
  1701. });
  1702. },
  1703. processHTML : function(h) {
  1704. var t = this, s = t.settings, codeBlocks = [];
  1705. if (!s.process_html)
  1706. return h;
  1707. if (isIE) {
  1708. h = h.replace(/&apos;/g, '&#39;'); // IE can't handle apos
  1709. h = h.replace(/\s+(disabled|checked|readonly|selected)\s*=\s*[\"\']?(false|0)[\"\']?/gi, ''); // IE doesn't handle default values correct
  1710. }
  1711. // Force tags open, and on IE9 replace $1$2 that got left behind due to bugs in their RegExp engine
  1712. h = tinymce._replace(/<a( )([^>]+)\/>|<a\/>/gi, '<a$1$2></a>', h); // Force open
  1713. // Store away src and href in _mce_src and mce_href since browsers mess them up
  1714. if (s.keep_values) {
  1715. // Wrap scripts and styles in comments for serialization purposes
  1716. if (/<script|noscript|style/i.test(h)) {
  1717. function trim(s) {
  1718. // Remove prefix and suffix code for element
  1719. s = s.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n');
  1720. s = s.replace(/^[\r\n]*|[\r\n]*$/g, '');
  1721. s = s.replace(/^\s*(\/\/\s*<!--|\/\/\s*<!\[CDATA\[|<!--|<!\[CDATA\[)[\r\n]*/g, '');
  1722. s = s.replace(/\s*(\/\/\s*\]\]>|\/\/\s*-->|\]\]>|-->|\]\]-->)\s*$/g, '');
  1723. return s;
  1724. };
  1725. // Wrap the script contents in CDATA and keep them from executing
  1726. h = h.replace(/<script([^>]+|)>([\s\S]*?)<\/script>/gi, function(v, attribs, text) {
  1727. // Force type attribute
  1728. if (!attribs)
  1729. attribs = ' type="text/javascript"';
  1730. // Convert the src attribute of the scripts
  1731. attribs = attribs.replace(/src=\"([^\"]+)\"?/i, function(a, url) {
  1732. if (s.url_converter)
  1733. url = t.encode(s.url_converter.call(s.url_converter_scope || t, t.decode(url), 'src', 'script'));
  1734. return '_mce_src="' + url + '"';
  1735. });
  1736. // Wrap text contents
  1737. if (tinymce.trim(text)) {
  1738. codeBlocks.push(trim(text));
  1739. text = '<!--\nMCE_SCRIPT:' + (codeBlocks.length - 1) + '\n// -->';
  1740. }
  1741. return '<mce:script' + attribs + '>' + text + '</mce:script>';
  1742. });
  1743. // Wrap style elements
  1744. h = h.replace(/<style([^>]+|)>([\s\S]*?)<\/style>/gi, function(v, attribs, text) {
  1745. // Wrap text contents
  1746. if (text) {
  1747. codeBlocks.push(trim(text));
  1748. text = '<!--\nMCE_SCRIPT:' + (codeBlocks.length - 1) + '\n-->';
  1749. }
  1750. return '<mce:style' + attribs + '>' + text + '</mce:style><style ' + attribs + ' _mce_bogus="1">' + text + '</style>';
  1751. });
  1752. // Wrap noscript elements
  1753. h = h.replace(/<noscript([^>]+|)>([\s\S]*?)<\/noscript>/g, function(v, attribs, text) {
  1754. return '<mce:noscript' + attribs + '><!--' + t.encode(text).replace(/--/g, '&#45;&#45;') + '--></mce:noscript>';
  1755. });
  1756. }
  1757. h = tinymce._replace(/<!\[CDATA\[([\s\S]+)\]\]>/g, '<!--[CDATA[$1]]-->', h);
  1758. // This function processes the attributes in the HTML string to force boolean
  1759. // attributes to the attr="attr" format and convert style, src and href to _mce_ versions
  1760. function processTags(html) {
  1761. return html.replace(tagRegExp, function(match, elm_name, attrs, end) {
  1762. return '<' + elm_name + attrs.replace(attrRegExp, function(match, name, value, val2, val3) {
  1763. var mceValue;
  1764. name = name.toLowerCase();
  1765. value = value || val2 || val3 || "";
  1766. // Treat boolean attributes
  1767. if (boolAttrs[name]) {
  1768. // false or 0 is treated as a missing attribute
  1769. if (value === 'false' || value === '0')
  1770. return;
  1771. return name + '="' + name + '"';
  1772. }
  1773. // Is attribute one that needs special treatment
  1774. if (mceAttribs[name] && attrs.indexOf('_mce_' + name) == -1) {
  1775. mceValue = t.decode(value);
  1776. // Convert URLs to relative/absolute ones
  1777. if (s.url_converter && (name == "src" || name == "href"))
  1778. mceValue = s.url_converter.call(s.url_converter_scope || t, mceValue, name, elm_name);
  1779. // Process styles lowercases them and compresses them
  1780. if (name == 'style')
  1781. mceValue = t.serializeStyle(t.parseStyle(mceValue), name);
  1782. return name + '="' + value + '"' + ' _mce_' + name + '="' + t.encode(mceValue) + '"';
  1783. }
  1784. return match;
  1785. }) + end + '>';
  1786. });
  1787. };
  1788. h = processTags(h);
  1789. // Restore script blocks
  1790. h = h.replace(/MCE_SCRIPT:([0-9]+)/g, function(val, idx) {
  1791. return codeBlocks[idx];
  1792. });
  1793. }
  1794. return h;
  1795. },
  1796. getOuterHTML : function(e) {
  1797. var d;
  1798. e = this.get(e);
  1799. if (!e)
  1800. return null;
  1801. if (e.outerHTML !== undefined)
  1802. return e.outerHTML;
  1803. d = (e.ownerDocument || this.doc).createElement("body");
  1804. d.appendChild(e.cloneNode(true));
  1805. return d.innerHTML;
  1806. },
  1807. setOuterHTML : function(e, h, d) {
  1808. var t = this;
  1809. function setHTML(e, h, d) {
  1810. var n, tp;
  1811. tp = d.createElement("body");
  1812. tp.innerHTML = h;
  1813. n = tp.lastChild;
  1814. while (n) {
  1815. t.insertAfter(n.cloneNode(true), e);
  1816. n = n.previousSibling;
  1817. }
  1818. t.remove(e);
  1819. };
  1820. return this.run(e, function(e) {
  1821. e = t.get(e);
  1822. // Only set HTML on elements
  1823. if (e.nodeType == 1) {
  1824. d = d || e.ownerDocument || t.doc;
  1825. if (isIE) {
  1826. try {
  1827. // Try outerHTML for IE it sometimes produces an unknown runtime error
  1828. if (isIE && e.nodeType == 1)
  1829. e.outerHTML = h;
  1830. else
  1831. setHTML(e, h, d);
  1832. } catch (ex) {
  1833. // Fix for unknown runtime error
  1834. setHTML(e, h, d);
  1835. }
  1836. } else
  1837. setHTML(e, h, d);
  1838. }
  1839. });
  1840. },
  1841. decode : function(s) {
  1842. var e, n, v;
  1843. // Look for entities to decode
  1844. if (/&[\w#]+;/.test(s)) {
  1845. // Decode the entities using a div element not super efficient but less code
  1846. e = this.doc.createElement("div");
  1847. e.innerHTML = s;
  1848. n = e.firstChild;
  1849. v = '';
  1850. if (n) {
  1851. do {
  1852. v += n.nodeValue;
  1853. } while (n = n.nextSibling);
  1854. }
  1855. return v || s;
  1856. }
  1857. return s;
  1858. },
  1859. encode : function(str) {
  1860. return ('' + str).replace(encodeCharsRe, function(chr) {
  1861. return encodedChars[chr];
  1862. });
  1863. },
  1864. insertAfter : function(node, reference_node) {
  1865. reference_node = this.get(reference_node);
  1866. return this.run(node, function(node) {
  1867. var parent, nextSibling;
  1868. parent = reference_node.parentNode;
  1869. nextSibling = reference_node.nextSibling;
  1870. if (nextSibling)
  1871. parent.insertBefore(node, nextSibling);
  1872. else
  1873. parent.appendChild(node);
  1874. return node;
  1875. });
  1876. },
  1877. isBlock : function(n) {
  1878. if (n.nodeType && n.nodeType !== 1)
  1879. return false;
  1880. n = n.nodeName || n;
  1881. return blockRe.test(n);
  1882. },
  1883. replace : function(n, o, k) {
  1884. var t = this;
  1885. if (is(o, 'array'))
  1886. n = n.cloneNode(true);
  1887. return t.run(o, function(o) {
  1888. if (k) {
  1889. each(tinymce.grep(o.childNodes), function(c) {
  1890. n.appendChild(c);
  1891. });
  1892. }
  1893. return o.parentNode.replaceChild(n, o);
  1894. });
  1895. },
  1896. rename : function(elm, name) {
  1897. var t = this, newElm;
  1898. if (elm.nodeName != name.toUpperCase()) {
  1899. // Rename block element
  1900. newElm = t.create(name);
  1901. // Copy attribs to new block
  1902. each(t.getAttribs(elm), function(attr_node) {
  1903. t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName));
  1904. });
  1905. // Replace block
  1906. t.replace(newElm, elm, 1);
  1907. }
  1908. return newElm || elm;
  1909. },
  1910. findCommonAncestor : function(a, b) {
  1911. var ps = a, pe;
  1912. while (ps) {
  1913. pe = b;
  1914. while (pe && ps != pe)
  1915. pe = pe.parentNode;
  1916. if (ps == pe)
  1917. break;
  1918. ps = ps.parentNode;
  1919. }
  1920. if (!ps && a.ownerDocument)
  1921. return a.ownerDocument.documentElement;
  1922. return ps;
  1923. },
  1924. toHex : function(s) {
  1925. var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s);
  1926. function hex(s) {
  1927. s = parseInt(s).toString(16);
  1928. return s.length > 1 ? s : '0' + s; // 0 -> 00
  1929. };
  1930. if (c) {
  1931. s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]);
  1932. return s;
  1933. }
  1934. return s;
  1935. },
  1936. getClasses : function() {
  1937. var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov;
  1938. if (t.classes)
  1939. return t.classes;
  1940. function addClasses(s) {
  1941. // IE style imports
  1942. each(s.imports, function(r) {
  1943. addClasses(r);
  1944. });
  1945. each(s.cssRules || s.rules, function(r) {
  1946. // Real type or fake it on IE
  1947. switch (r.type || 1) {
  1948. // Rule
  1949. case 1:
  1950. if (r.selectorText) {
  1951. each(r.selectorText.split(','), function(v) {
  1952. v = v.replace(/^\s*|\s*$|^\s\./g, "");
  1953. // Is internal or it doesn't contain a class
  1954. if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
  1955. return;
  1956. // Remove everything but class name
  1957. ov = v;
  1958. v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v);
  1959. // Filter classes
  1960. if (f && !(v = f(v, ov)))
  1961. return;
  1962. if (!lo[v]) {
  1963. cl.push({'class' : v});
  1964. lo[v] = 1;
  1965. }
  1966. });
  1967. }
  1968. break;
  1969. // Import
  1970. case 3:
  1971. addClasses(r.styleSheet);
  1972. break;
  1973. }
  1974. });
  1975. };
  1976. try {
  1977. each(t.doc.styleSheets, addClasses);
  1978. } catch (ex) {
  1979. // Ignore
  1980. }
  1981. if (cl.length > 0)
  1982. t.classes = cl;
  1983. return cl;
  1984. },
  1985. run : function(e, f, s) {
  1986. var t = this, o;
  1987. if (t.doc && typeof(e) === 'string')
  1988. e = t.get(e);
  1989. if (!e)
  1990. return false;
  1991. s = s || this;
  1992. if (!e.nodeType && (e.length || e.length === 0)) {
  1993. o = [];
  1994. each(e, function(e, i) {
  1995. if (e) {
  1996. if (typeof(e) == 'string')
  1997. e = t.doc.getElementById(e);
  1998. o.push(f.call(s, e, i));
  1999. }
  2000. });
  2001. return o;
  2002. }
  2003. return f.call(s, e);
  2004. },
  2005. getAttribs : function(n) {
  2006. var o;
  2007. n = this.get(n);
  2008. if (!n)
  2009. return [];
  2010. if (isIE) {
  2011. o = [];
  2012. // Object will throw exception in IE
  2013. if (n.nodeName == 'OBJECT')
  2014. return n.attributes;
  2015. // IE doesn't keep the selected attribute if you clone option elements
  2016. if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected'))
  2017. o.push({specified : 1, nodeName : 'selected'});
  2018. // It's crazy that this is faster in IE but it's because it returns all attributes all the time
  2019. n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) {
  2020. o.push({specified : 1, nodeName : a});
  2021. });
  2022. return o;
  2023. }
  2024. return n.attributes;
  2025. },
  2026. destroy : function(s) {
  2027. var t = this;
  2028. if (t.events)
  2029. t.events.destroy();
  2030. t.win = t.doc = t.root = t.events = null;
  2031. // Manual destroy then remove unload handler
  2032. if (!s)
  2033. tinymce.removeUnload(t.destroy);
  2034. },
  2035. createRng : function() {
  2036. var d = this.doc;
  2037. return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
  2038. },
  2039. nodeIndex : function(node, normalized) {
  2040. var idx = 0, lastNodeType, lastNode, nodeType;
  2041. if (node) {
  2042. for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
  2043. nodeType = node.nodeType;
  2044. // Normalize text nodes
  2045. if (normalized && nodeType == 3) {
  2046. if (nodeType == lastNodeType || !node.nodeValue.length)
  2047. continue;
  2048. }
  2049. idx++;
  2050. lastNodeType = nodeType;
  2051. }
  2052. }
  2053. return idx;
  2054. },
  2055. split : function(pe, e, re) {
  2056. var t = this, r = t.createRng(), bef, aft, pa;
  2057. // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense
  2058. // but we don't want that in our code since it serves no purpose for the end user
  2059. // For example if this is chopped:
  2060. // <p>text 1<span><b>CHOP</b></span>text 2</p>
  2061. // would produce:
  2062. // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
  2063. // this function will then trim of empty edges and produce:
  2064. // <p>text 1</p><b>CHOP</b><p>text 2</p>
  2065. function trim(node) {
  2066. var i, children = node.childNodes;
  2067. if (node.nodeType == 1 && node.getAttribute('_mce_type') == 'bookmark')
  2068. return;
  2069. for (i = children.length - 1; i >= 0; i--)
  2070. trim(children[i]);
  2071. if (node.nodeType != 9) {
  2072. // Keep non whitespace text nodes
  2073. if (node.nodeType == 3 && node.nodeValue.length > 0) {
  2074. // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
  2075. if (!t.isBlock(node.parentNode) || tinymce.trim(node.nodeValue).length > 0)
  2076. return;
  2077. }
  2078. if (node.nodeType == 1) {
  2079. // If the only child is a bookmark then move it up
  2080. children = node.childNodes;
  2081. if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('_mce_type') == 'bookmark')
  2082. node.parentNode.insertBefore(children[0], node);
  2083. // Keep non empty elements or img, hr etc
  2084. if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName))
  2085. return;
  2086. }
  2087. t.remove(node);
  2088. }
  2089. return node;
  2090. };
  2091. if (pe && e) {
  2092. // Get before chunk
  2093. r.setStart(pe.parentNode, t.nodeIndex(pe));
  2094. r.setEnd(e.parentNode, t.nodeIndex(e));
  2095. bef = r.extractContents();
  2096. // Get after chunk
  2097. r = t.createRng();
  2098. r.setStart(e.parentNode, t.nodeIndex(e) + 1);
  2099. r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1);
  2100. aft = r.extractContents();
  2101. // Insert before chunk
  2102. pa = pe.parentNode;
  2103. pa.insertBefore(trim(bef), pe);
  2104. // Insert middle chunk
  2105. if (re)
  2106. pa.replaceChild(re, e);
  2107. else
  2108. pa.insertBefore(e, pe);
  2109. // Insert after chunk
  2110. pa.insertBefore(trim(aft), pe);
  2111. t.remove(pe);
  2112. return re || e;
  2113. }
  2114. },
  2115. bind : function(target, name, func, scope) {
  2116. var t = this;
  2117. if (!t.events)
  2118. t.events = new tinymce.dom.EventUtils();
  2119. return t.events.add(target, name, func, scope || this);
  2120. },
  2121. unbind : function(target, name, func) {
  2122. var t = this;
  2123. if (!t.events)
  2124. t.events = new tinymce.dom.EventUtils();
  2125. return t.events.remove(target, name, func);
  2126. },
  2127. _findSib : function(node, selector, name) {
  2128. var t = this, f = selector;
  2129. if (node) {
  2130. // If expression make a function of it using is
  2131. if (is(f, 'string')) {
  2132. f = function(node) {
  2133. return t.is(node, selector);
  2134. };
  2135. }
  2136. // Loop all siblings
  2137. for (node = node[name]; node; node = node[name]) {
  2138. if (f(node))
  2139. return node;
  2140. }
  2141. }
  2142. return null;
  2143. },
  2144. _isRes : function(c) {
  2145. // Is live resizble element
  2146. return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c);
  2147. }
  2148. /*
  2149. walk : function(n, f, s) {
  2150. var d = this.doc, w;
  2151. if (d.createTreeWalker) {
  2152. w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  2153. while ((n = w.nextNode()) != null)
  2154. f.call(s || this, n);
  2155. } else
  2156. tinymce.walk(n, f, 'childNodes', s);
  2157. }
  2158. */
  2159. /*
  2160. toRGB : function(s) {
  2161. var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s);
  2162. if (c) {
  2163. // #FFF -> #FFFFFF
  2164. if (!is(c[3]))
  2165. c[3] = c[2] = c[1];
  2166. return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")";
  2167. }
  2168. return s;
  2169. }
  2170. */
  2171. });
  2172. tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0});
  2173. })(tinymce);
  2174. (function(ns) {
  2175. // Range constructor
  2176. function Range(dom) {
  2177. var t = this,
  2178. doc = dom.doc,
  2179. EXTRACT = 0,
  2180. CLONE = 1,
  2181. DELETE = 2,
  2182. TRUE = true,
  2183. FALSE = false,
  2184. START_OFFSET = 'startOffset',
  2185. START_CONTAINER = 'startContainer',
  2186. END_CONTAINER = 'endContainer',
  2187. END_OFFSET = 'endOffset',
  2188. extend = tinymce.extend,
  2189. nodeIndex = dom.nodeIndex;
  2190. extend(t, {
  2191. // Inital states
  2192. startContainer : doc,
  2193. startOffset : 0,
  2194. endContainer : doc,
  2195. endOffset : 0,
  2196. collapsed : TRUE,
  2197. commonAncestorContainer : doc,
  2198. // Range constants
  2199. START_TO_START : 0,
  2200. START_TO_END : 1,
  2201. END_TO_END : 2,
  2202. END_TO_START : 3,
  2203. // Public methods
  2204. setStart : setStart,
  2205. setEnd : setEnd,
  2206. setStartBefore : setStartBefore,
  2207. setStartAfter : setStartAfter,
  2208. setEndBefore : setEndBefore,
  2209. setEndAfter : setEndAfter,
  2210. collapse : collapse,
  2211. selectNode : selectNode,
  2212. selectNodeContents : selectNodeContents,
  2213. compareBoundaryPoints : compareBoundaryPoints,
  2214. deleteContents : deleteContents,
  2215. extractContents : extractContents,
  2216. cloneContents : cloneContents,
  2217. insertNode : insertNode,
  2218. surroundContents : surroundContents,
  2219. cloneRange : cloneRange
  2220. });
  2221. function setStart(n, o) {
  2222. _setEndPoint(TRUE, n, o);
  2223. };
  2224. function setEnd(n, o) {
  2225. _setEndPoint(FALSE, n, o);
  2226. };
  2227. function setStartBefore(n) {
  2228. setStart(n.parentNode, nodeIndex(n));
  2229. };
  2230. function setStartAfter(n) {
  2231. setStart(n.parentNode, nodeIndex(n) + 1);
  2232. };
  2233. function setEndBefore(n) {
  2234. setEnd(n.parentNode, nodeIndex(n));
  2235. };
  2236. function setEndAfter(n) {
  2237. setEnd(n.parentNode, nodeIndex(n) + 1);
  2238. };
  2239. function collapse(ts) {
  2240. if (ts) {
  2241. t[END_CONTAINER] = t[START_CONTAINER];
  2242. t[END_OFFSET] = t[START_OFFSET];
  2243. } else {
  2244. t[START_CONTAINER] = t[END_CONTAINER];
  2245. t[START_OFFSET] = t[END_OFFSET];
  2246. }
  2247. t.collapsed = TRUE;
  2248. };
  2249. function selectNode(n) {
  2250. setStartBefore(n);
  2251. setEndAfter(n);
  2252. };
  2253. function selectNodeContents(n) {
  2254. setStart(n, 0);
  2255. setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
  2256. };
  2257. function compareBoundaryPoints(h, r) {
  2258. var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET];
  2259. // Check START_TO_START
  2260. if (h === 0)
  2261. return _compareBoundaryPoints(sc, so, sc, so);
  2262. // Check START_TO_END
  2263. if (h === 1)
  2264. return _compareBoundaryPoints(sc, so, ec, eo);
  2265. // Check END_TO_END
  2266. if (h === 2)
  2267. return _compareBoundaryPoints(ec, eo, ec, eo);
  2268. // Check END_TO_START
  2269. if (h === 3)
  2270. return _compareBoundaryPoints(ec, eo, sc, so);
  2271. };
  2272. function deleteContents() {
  2273. _traverse(DELETE);
  2274. };
  2275. function extractContents() {
  2276. return _traverse(EXTRACT);
  2277. };
  2278. function cloneContents() {
  2279. return _traverse(CLONE);
  2280. };
  2281. function insertNode(n) {
  2282. var startContainer = this[START_CONTAINER],
  2283. startOffset = this[START_OFFSET], nn, o;
  2284. // Node is TEXT_NODE or CDATA
  2285. if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) {
  2286. if (!startOffset) {
  2287. // At the start of text
  2288. startContainer.parentNode.insertBefore(n, startContainer);
  2289. } else if (startOffset >= startContainer.nodeValue.length) {
  2290. // At the end of text
  2291. dom.insertAfter(n, startContainer);
  2292. } else {
  2293. // Middle, need to split
  2294. nn = startContainer.splitText(startOffset);
  2295. startContainer.parentNode.insertBefore(n, nn);
  2296. }
  2297. } else {
  2298. // Insert element node
  2299. if (startContainer.childNodes.length > 0)
  2300. o = startContainer.childNodes[startOffset];
  2301. if (o)
  2302. startContainer.insertBefore(n, o);
  2303. else
  2304. startContainer.appendChild(n);
  2305. }
  2306. };
  2307. function surroundContents(n) {
  2308. var f = t.extractContents();
  2309. t.insertNode(n);
  2310. n.appendChild(f);
  2311. t.selectNode(n);
  2312. };
  2313. function cloneRange() {
  2314. return extend(new Range(dom), {
  2315. startContainer : t[START_CONTAINER],
  2316. startOffset : t[START_OFFSET],
  2317. endContainer : t[END_CONTAINER],
  2318. endOffset : t[END_OFFSET],
  2319. collapsed : t.collapsed,
  2320. commonAncestorContainer : t.commonAncestorContainer
  2321. });
  2322. };
  2323. // Private methods
  2324. function _getSelectedNode(container, offset) {
  2325. var child;
  2326. if (container.nodeType == 3 /* TEXT_NODE */)
  2327. return container;
  2328. if (offset < 0)
  2329. return container;
  2330. child = container.firstChild;
  2331. while (child && offset > 0) {
  2332. --offset;
  2333. child = child.nextSibling;
  2334. }
  2335. if (child)
  2336. return child;
  2337. return container;
  2338. };
  2339. function _isCollapsed() {
  2340. return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
  2341. };
  2342. function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
  2343. var c, offsetC, n, cmnRoot, childA, childB;
  2344. // In the first case the boundary-points have the same container. A is before B
  2345. // if its offset is less than the offset of B, A is equal to B if its offset is
  2346. // equal to the offset of B, and A is after B if its offset is greater than the
  2347. // offset of B.
  2348. if (containerA == containerB) {
  2349. if (offsetA == offsetB)
  2350. return 0; // equal
  2351. if (offsetA < offsetB)
  2352. return -1; // before
  2353. return 1; // after
  2354. }
  2355. // In the second case a child node C of the container of A is an ancestor
  2356. // container of B. In this case, A is before B if the offset of A is less than or
  2357. // equal to the index of the child node C and A is after B otherwise.
  2358. c = containerB;
  2359. while (c && c.parentNode != containerA)
  2360. c = c.parentNode;
  2361. if (c) {
  2362. offsetC = 0;
  2363. n = containerA.firstChild;
  2364. while (n != c && offsetC < offsetA) {
  2365. offsetC++;
  2366. n = n.nextSibling;
  2367. }
  2368. if (offsetA <= offsetC)
  2369. return -1; // before
  2370. return 1; // after
  2371. }
  2372. // In the third case a child node C of the container of B is an ancestor container
  2373. // of A. In this case, A is before B if the index of the child node C is less than
  2374. // the offset of B and A is after B otherwise.
  2375. c = containerA;
  2376. while (c && c.parentNode != containerB) {
  2377. c = c.parentNode;
  2378. }
  2379. if (c) {
  2380. offsetC = 0;
  2381. n = containerB.firstChild;
  2382. while (n != c && offsetC < offsetB) {
  2383. offsetC++;
  2384. n = n.nextSibling;
  2385. }
  2386. if (offsetC < offsetB)
  2387. return -1; // before
  2388. return 1; // after
  2389. }
  2390. // In the fourth case, none of three other cases hold: the containers of A and B
  2391. // are siblings or descendants of sibling nodes. In this case, A is before B if
  2392. // the container of A is before the container of B in a pre-order traversal of the
  2393. // Ranges' context tree and A is after B otherwise.
  2394. cmnRoot = dom.findCommonAncestor(containerA, containerB);
  2395. childA = containerA;
  2396. while (childA && childA.parentNode != cmnRoot)
  2397. childA = childA.parentNode;
  2398. if (!childA)
  2399. childA = cmnRoot;
  2400. childB = containerB;
  2401. while (childB && childB.parentNode != cmnRoot)
  2402. childB = childB.parentNode;
  2403. if (!childB)
  2404. childB = cmnRoot;
  2405. if (childA == childB)
  2406. return 0; // equal
  2407. n = cmnRoot.firstChild;
  2408. while (n) {
  2409. if (n == childA)
  2410. return -1; // before
  2411. if (n == childB)
  2412. return 1; // after
  2413. n = n.nextSibling;
  2414. }
  2415. };
  2416. function _setEndPoint(st, n, o) {
  2417. var ec, sc;
  2418. if (st) {
  2419. t[START_CONTAINER] = n;
  2420. t[START_OFFSET] = o;
  2421. } else {
  2422. t[END_CONTAINER] = n;
  2423. t[END_OFFSET] = o;
  2424. }
  2425. // If one boundary-point of a Range is set to have a root container
  2426. // other than the current one for the Range, the Range is collapsed to
  2427. // the new position. This enforces the restriction that both boundary-
  2428. // points of a Range must have the same root container.
  2429. ec = t[END_CONTAINER];
  2430. while (ec.parentNode)
  2431. ec = ec.parentNode;
  2432. sc = t[START_CONTAINER];
  2433. while (sc.parentNode)
  2434. sc = sc.parentNode;
  2435. if (sc == ec) {
  2436. // The start position of a Range is guaranteed to never be after the
  2437. // end position. To enforce this restriction, if the start is set to
  2438. // be at a position after the end, the Range is collapsed to that
  2439. // position.
  2440. if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0)
  2441. t.collapse(st);
  2442. } else
  2443. t.collapse(st);
  2444. t.collapsed = _isCollapsed();
  2445. t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]);
  2446. };
  2447. function _traverse(how) {
  2448. var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
  2449. if (t[START_CONTAINER] == t[END_CONTAINER])
  2450. return _traverseSameContainer(how);
  2451. for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  2452. if (p == t[START_CONTAINER])
  2453. return _traverseCommonStartContainer(c, how);
  2454. ++endContainerDepth;
  2455. }
  2456. for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  2457. if (p == t[END_CONTAINER])
  2458. return _traverseCommonEndContainer(c, how);
  2459. ++startContainerDepth;
  2460. }
  2461. depthDiff = startContainerDepth - endContainerDepth;
  2462. startNode = t[START_CONTAINER];
  2463. while (depthDiff > 0) {
  2464. startNode = startNode.parentNode;
  2465. depthDiff--;
  2466. }
  2467. endNode = t[END_CONTAINER];
  2468. while (depthDiff < 0) {
  2469. endNode = endNode.parentNode;
  2470. depthDiff++;
  2471. }
  2472. // ascend the ancestor hierarchy until we have a common parent.
  2473. for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
  2474. startNode = sp;
  2475. endNode = ep;
  2476. }
  2477. return _traverseCommonAncestors(startNode, endNode, how);
  2478. };
  2479. function _traverseSameContainer(how) {
  2480. var frag, s, sub, n, cnt, sibling, xferNode;
  2481. if (how != DELETE)
  2482. frag = doc.createDocumentFragment();
  2483. // If selection is empty, just return the fragment
  2484. if (t[START_OFFSET] == t[END_OFFSET])
  2485. return frag;
  2486. // Text node needs special case handling
  2487. if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) {
  2488. // get the substring
  2489. s = t[START_CONTAINER].nodeValue;
  2490. sub = s.substring(t[START_OFFSET], t[END_OFFSET]);
  2491. // set the original text node to its new value
  2492. if (how != CLONE) {
  2493. t[START_CONTAINER].deleteData(t[START_OFFSET], t[END_OFFSET] - t[START_OFFSET]);
  2494. // Nothing is partially selected, so collapse to start point
  2495. t.collapse(TRUE);
  2496. }
  2497. if (how == DELETE)
  2498. return;
  2499. frag.appendChild(doc.createTextNode(sub));
  2500. return frag;
  2501. }
  2502. // Copy nodes between the start/end offsets.
  2503. n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]);
  2504. cnt = t[END_OFFSET] - t[START_OFFSET];
  2505. while (cnt > 0) {
  2506. sibling = n.nextSibling;
  2507. xferNode = _traverseFullySelected(n, how);
  2508. if (frag)
  2509. frag.appendChild( xferNode );
  2510. --cnt;
  2511. n = sibling;
  2512. }
  2513. // Nothing is partially selected, so collapse to start point
  2514. if (how != CLONE)
  2515. t.collapse(TRUE);
  2516. return frag;
  2517. };
  2518. function _traverseCommonStartContainer(endAncestor, how) {
  2519. var frag, n, endIdx, cnt, sibling, xferNode;
  2520. if (how != DELETE)
  2521. frag = doc.createDocumentFragment();
  2522. n = _traverseRightBoundary(endAncestor, how);
  2523. if (frag)
  2524. frag.appendChild(n);
  2525. endIdx = nodeIndex(endAncestor);
  2526. cnt = endIdx - t[START_OFFSET];
  2527. if (cnt <= 0) {
  2528. // Collapse to just before the endAncestor, which
  2529. // is partially selected.
  2530. if (how != CLONE) {
  2531. t.setEndBefore(endAncestor);
  2532. t.collapse(FALSE);
  2533. }
  2534. return frag;
  2535. }
  2536. n = endAncestor.previousSibling;
  2537. while (cnt > 0) {
  2538. sibling = n.previousSibling;
  2539. xferNode = _traverseFullySelected(n, how);
  2540. if (frag)
  2541. frag.insertBefore(xferNode, frag.firstChild);
  2542. --cnt;
  2543. n = sibling;
  2544. }
  2545. // Collapse to just before the endAncestor, which
  2546. // is partially selected.
  2547. if (how != CLONE) {
  2548. t.setEndBefore(endAncestor);
  2549. t.collapse(FALSE);
  2550. }
  2551. return frag;
  2552. };
  2553. function _traverseCommonEndContainer(startAncestor, how) {
  2554. var frag, startIdx, n, cnt, sibling, xferNode;
  2555. if (how != DELETE)
  2556. frag = doc.createDocumentFragment();
  2557. n = _traverseLeftBoundary(startAncestor, how);
  2558. if (frag)
  2559. frag.appendChild(n);
  2560. startIdx = nodeIndex(startAncestor);
  2561. ++startIdx; // Because we already traversed it....
  2562. cnt = t[END_OFFSET] - startIdx;
  2563. n = startAncestor.nextSibling;
  2564. while (cnt > 0) {
  2565. sibling = n.nextSibling;
  2566. xferNode = _traverseFullySelected(n, how);
  2567. if (frag)
  2568. frag.appendChild(xferNode);
  2569. --cnt;
  2570. n = sibling;
  2571. }
  2572. if (how != CLONE) {
  2573. t.setStartAfter(startAncestor);
  2574. t.collapse(TRUE);
  2575. }
  2576. return frag;
  2577. };
  2578. function _traverseCommonAncestors(startAncestor, endAncestor, how) {
  2579. var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
  2580. if (how != DELETE)
  2581. frag = doc.createDocumentFragment();
  2582. n = _traverseLeftBoundary(startAncestor, how);
  2583. if (frag)
  2584. frag.appendChild(n);
  2585. commonParent = startAncestor.parentNode;
  2586. startOffset = nodeIndex(startAncestor);
  2587. endOffset = nodeIndex(endAncestor);
  2588. ++startOffset;
  2589. cnt = endOffset - startOffset;
  2590. sibling = startAncestor.nextSibling;
  2591. while (cnt > 0) {
  2592. nextSibling = sibling.nextSibling;
  2593. n = _traverseFullySelected(sibling, how);
  2594. if (frag)
  2595. frag.appendChild(n);
  2596. sibling = nextSibling;
  2597. --cnt;
  2598. }
  2599. n = _traverseRightBoundary(endAncestor, how);
  2600. if (frag)
  2601. frag.appendChild(n);
  2602. if (how != CLONE) {
  2603. t.setStartAfter(startAncestor);
  2604. t.collapse(TRUE);
  2605. }
  2606. return frag;
  2607. };
  2608. function _traverseRightBoundary(root, how) {
  2609. var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER];
  2610. if (next == root)
  2611. return _traverseNode(next, isFullySelected, FALSE, how);
  2612. parent = next.parentNode;
  2613. clonedParent = _traverseNode(parent, FALSE, FALSE, how);
  2614. while (parent) {
  2615. while (next) {
  2616. prevSibling = next.previousSibling;
  2617. clonedChild = _traverseNode(next, isFullySelected, FALSE, how);
  2618. if (how != DELETE)
  2619. clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
  2620. isFullySelected = TRUE;
  2621. next = prevSibling;
  2622. }
  2623. if (parent == root)
  2624. return clonedParent;
  2625. next = parent.previousSibling;
  2626. parent = parent.parentNode;
  2627. clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how);
  2628. if (how != DELETE)
  2629. clonedGrandParent.appendChild(clonedParent);
  2630. clonedParent = clonedGrandParent;
  2631. }
  2632. };
  2633. function _traverseLeftBoundary(root, how) {
  2634. var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
  2635. if (next == root)
  2636. return _traverseNode(next, isFullySelected, TRUE, how);
  2637. parent = next.parentNode;
  2638. clonedParent = _traverseNode(parent, FALSE, TRUE, how);
  2639. while (parent) {
  2640. while (next) {
  2641. nextSibling = next.nextSibling;
  2642. clonedChild = _traverseNode(next, isFullySelected, TRUE, how);
  2643. if (how != DELETE)
  2644. clonedParent.appendChild(clonedChild);
  2645. isFullySelected = TRUE;
  2646. next = nextSibling;
  2647. }
  2648. if (parent == root)
  2649. return clonedParent;
  2650. next = parent.nextSibling;
  2651. parent = parent.parentNode;
  2652. clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how);
  2653. if (how != DELETE)
  2654. clonedGrandParent.appendChild(clonedParent);
  2655. clonedParent = clonedGrandParent;
  2656. }
  2657. };
  2658. function _traverseNode(n, isFullySelected, isLeft, how) {
  2659. var txtValue, newNodeValue, oldNodeValue, offset, newNode;
  2660. if (isFullySelected)
  2661. return _traverseFullySelected(n, how);
  2662. if (n.nodeType == 3 /* TEXT_NODE */) {
  2663. txtValue = n.nodeValue;
  2664. if (isLeft) {
  2665. offset = t[START_OFFSET];
  2666. newNodeValue = txtValue.substring(offset);
  2667. oldNodeValue = txtValue.substring(0, offset);
  2668. } else {
  2669. offset = t[END_OFFSET];
  2670. newNodeValue = txtValue.substring(0, offset);
  2671. oldNodeValue = txtValue.substring(offset);
  2672. }
  2673. if (how != CLONE)
  2674. n.nodeValue = oldNodeValue;
  2675. if (how == DELETE)
  2676. return;
  2677. newNode = n.cloneNode(FALSE);
  2678. newNode.nodeValue = newNodeValue;
  2679. return newNode;
  2680. }
  2681. if (how == DELETE)
  2682. return;
  2683. return n.cloneNode(FALSE);
  2684. };
  2685. function _traverseFullySelected(n, how) {
  2686. if (how != DELETE)
  2687. return how == CLONE ? n.cloneNode(TRUE) : n;
  2688. n.parentNode.removeChild(n);
  2689. };
  2690. };
  2691. ns.Range = Range;
  2692. })(tinymce.dom);
  2693. (function() {
  2694. function Selection(selection) {
  2695. var t = this, invisibleChar = '\uFEFF', range, lastIERng, dom = selection.dom, TRUE = true, FALSE = false;
  2696. // Returns a W3C DOM compatible range object by using the IE Range API
  2697. function getRange() {
  2698. var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed;
  2699. // If selection is outside the current document just return an empty range
  2700. element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  2701. if (element.ownerDocument != dom.doc)
  2702. return domRange;
  2703. // Handle control selection or text selection of a image
  2704. if (ieRange.item || !element.hasChildNodes()) {
  2705. domRange.setStart(element.parentNode, dom.nodeIndex(element));
  2706. domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
  2707. return domRange;
  2708. }
  2709. collapsed = selection.isCollapsed();
  2710. function findEndPoint(start) {
  2711. var marker, container, offset, nodes, startIndex = 0, endIndex, index, parent, checkRng, position;
  2712. // Setup temp range and collapse it
  2713. checkRng = ieRange.duplicate();
  2714. checkRng.collapse(start);
  2715. // Create marker and insert it at the end of the endpoints parent
  2716. marker = dom.create('a');
  2717. parent = checkRng.parentElement();
  2718. // If parent doesn't have any children then set the container to that parent and the index to 0
  2719. if (!parent.hasChildNodes()) {
  2720. domRange[start ? 'setStart' : 'setEnd'](parent, 0);
  2721. return;
  2722. }
  2723. parent.appendChild(marker);
  2724. checkRng.moveToElementText(marker);
  2725. position = ieRange.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', checkRng);
  2726. if (position > 0) {
  2727. // The position is after the end of the parent element.
  2728. // This is the case where IE puts the caret to the left edge of a table.
  2729. domRange[start ? 'setStartAfter' : 'setEndAfter'](parent);
  2730. dom.remove(marker);
  2731. return;
  2732. }
  2733. // Setup node list and endIndex
  2734. nodes = tinymce.grep(parent.childNodes);
  2735. endIndex = nodes.length - 1;
  2736. // Perform a binary search for the position
  2737. while (startIndex <= endIndex) {
  2738. index = Math.floor((startIndex + endIndex) / 2);
  2739. // Insert marker and check it's position relative to the selection
  2740. parent.insertBefore(marker, nodes[index]);
  2741. checkRng.moveToElementText(marker);
  2742. position = ieRange.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', checkRng);
  2743. if (position > 0) {
  2744. // Marker is to the right
  2745. startIndex = index + 1;
  2746. } else if (position < 0) {
  2747. // Marker is to the left
  2748. endIndex = index - 1;
  2749. } else {
  2750. // Maker is where we are
  2751. found = true;
  2752. break;
  2753. }
  2754. }
  2755. // Setup container
  2756. container = position > 0 || index == 0 ? marker.nextSibling : marker.previousSibling;
  2757. // Handle element selection
  2758. if (container.nodeType == 1) {
  2759. dom.remove(marker);
  2760. // Find offset and container
  2761. offset = dom.nodeIndex(container);
  2762. container = container.parentNode;
  2763. // Move the offset if we are setting the end or the position is after an element
  2764. if (!start || index > 0)
  2765. offset++;
  2766. } else {
  2767. // Calculate offset within text node
  2768. if (position > 0 || index == 0) {
  2769. checkRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', ieRange);
  2770. offset = checkRng.text.length;
  2771. } else {
  2772. checkRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', ieRange);
  2773. offset = container.nodeValue.length - checkRng.text.length;
  2774. }
  2775. dom.remove(marker);
  2776. }
  2777. domRange[start ? 'setStart' : 'setEnd'](container, offset);
  2778. };
  2779. // Find start point
  2780. findEndPoint(true);
  2781. // Find end point if needed
  2782. if (!collapsed)
  2783. findEndPoint();
  2784. return domRange;
  2785. };
  2786. this.addRange = function(rng) {
  2787. var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, doc = selection.dom.doc, body = doc.body;
  2788. function setEndPoint(start) {
  2789. var container, offset, marker, tmpRng, nodes;
  2790. marker = dom.create('a');
  2791. container = start ? startContainer : endContainer;
  2792. offset = start ? startOffset : endOffset;
  2793. tmpRng = ieRng.duplicate();
  2794. if (container == doc) {
  2795. container = body;
  2796. offset = 0;
  2797. }
  2798. if (container.nodeType == 3) {
  2799. container.parentNode.insertBefore(marker, container);
  2800. tmpRng.moveToElementText(marker);
  2801. tmpRng.moveStart('character', offset);
  2802. dom.remove(marker);
  2803. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  2804. } else {
  2805. nodes = container.childNodes;
  2806. if (nodes.length) {
  2807. if (offset >= nodes.length) {
  2808. dom.insertAfter(marker, nodes[nodes.length - 1]);
  2809. } else {
  2810. container.insertBefore(marker, nodes[offset]);
  2811. }
  2812. tmpRng.moveToElementText(marker);
  2813. } else {
  2814. // Empty node selection for example <div>|</div>
  2815. marker = doc.createTextNode(invisibleChar);
  2816. container.appendChild(marker);
  2817. tmpRng.moveToElementText(marker.parentNode);
  2818. tmpRng.collapse(TRUE);
  2819. }
  2820. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  2821. dom.remove(marker);
  2822. }
  2823. }
  2824. // Destroy cached range
  2825. this.destroy();
  2826. // Setup some shorter versions
  2827. startContainer = rng.startContainer;
  2828. startOffset = rng.startOffset;
  2829. endContainer = rng.endContainer;
  2830. endOffset = rng.endOffset;
  2831. ieRng = body.createTextRange();
  2832. // If single element selection then try making a control selection out of it
  2833. if (startContainer == endContainer && startContainer.nodeType == 1 && startOffset == endOffset - 1) {
  2834. if (startOffset == endOffset - 1) {
  2835. try {
  2836. ctrlRng = body.createControlRange();
  2837. ctrlRng.addElement(startContainer.childNodes[startOffset]);
  2838. ctrlRng.select();
  2839. ctrlRng.scrollIntoView();
  2840. return;
  2841. } catch (ex) {
  2842. // Ignore
  2843. }
  2844. }
  2845. }
  2846. // Set start/end point of selection
  2847. setEndPoint(true);
  2848. setEndPoint();
  2849. // Select the new range and scroll it into view
  2850. ieRng.select();
  2851. ieRng.scrollIntoView();
  2852. };
  2853. this.getRangeAt = function() {
  2854. // Setup new range if the cache is empty
  2855. if (!range || !tinymce.dom.RangeUtils.compareRanges(lastIERng, selection.getRng())) {
  2856. range = getRange();
  2857. // Store away text range for next call
  2858. lastIERng = selection.getRng();
  2859. }
  2860. // IE will say that the range is equal then produce an invalid argument exception
  2861. // if you perform specific operations in a keyup event. For example Ctrl+Del.
  2862. // This hack will invalidate the range cache if the exception occurs
  2863. try {
  2864. range.startContainer.nextSibling;
  2865. } catch (ex) {
  2866. range = getRange();
  2867. lastIERng = null;
  2868. }
  2869. // Return cached range
  2870. return range;
  2871. };
  2872. this.destroy = function() {
  2873. // Destroy cached range and last IE range to avoid memory leaks
  2874. lastIERng = range = null;
  2875. };
  2876. };
  2877. // Expose the selection object
  2878. tinymce.dom.TridentSelection = Selection;
  2879. })();
  2880. (function(tinymce) {
  2881. // Shorten names
  2882. var each = tinymce.each, DOM = tinymce.DOM, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, Event;
  2883. tinymce.create('tinymce.dom.EventUtils', {
  2884. EventUtils : function() {
  2885. this.inits = [];
  2886. this.events = [];
  2887. },
  2888. add : function(o, n, f, s) {
  2889. var cb, t = this, el = t.events, r;
  2890. if (n instanceof Array) {
  2891. r = [];
  2892. each(n, function(n) {
  2893. r.push(t.add(o, n, f, s));
  2894. });
  2895. return r;
  2896. }
  2897. // Handle array
  2898. if (o && o.hasOwnProperty && o instanceof Array) {
  2899. r = [];
  2900. each(o, function(o) {
  2901. o = DOM.get(o);
  2902. r.push(t.add(o, n, f, s));
  2903. });
  2904. return r;
  2905. }
  2906. o = DOM.get(o);
  2907. if (!o)
  2908. return;
  2909. // Setup event callback
  2910. cb = function(e) {
  2911. // Is all events disabled
  2912. if (t.disabled)
  2913. return;
  2914. e = e || window.event;
  2915. // Patch in target, preventDefault and stopPropagation in IE it's W3C valid
  2916. if (e && isIE) {
  2917. if (!e.target)
  2918. e.target = e.srcElement;
  2919. // Patch in preventDefault, stopPropagation methods for W3C compatibility
  2920. tinymce.extend(e, t._stoppers);
  2921. }
  2922. if (!s)
  2923. return f(e);
  2924. return f.call(s, e);
  2925. };
  2926. if (n == 'unload') {
  2927. tinymce.unloads.unshift({func : cb});
  2928. return cb;
  2929. }
  2930. if (n == 'init') {
  2931. if (t.domLoaded)
  2932. cb();
  2933. else
  2934. t.inits.push(cb);
  2935. return cb;
  2936. }
  2937. // Store away listener reference
  2938. el.push({
  2939. obj : o,
  2940. name : n,
  2941. func : f,
  2942. cfunc : cb,
  2943. scope : s
  2944. });
  2945. t._add(o, n, cb);
  2946. return f;
  2947. },
  2948. remove : function(o, n, f) {
  2949. var t = this, a = t.events, s = false, r;
  2950. // Handle array
  2951. if (o && o.hasOwnProperty && o instanceof Array) {
  2952. r = [];
  2953. each(o, function(o) {
  2954. o = DOM.get(o);
  2955. r.push(t.remove(o, n, f));
  2956. });
  2957. return r;
  2958. }
  2959. o = DOM.get(o);
  2960. each(a, function(e, i) {
  2961. if (e.obj == o && e.name == n && (!f || (e.func == f || e.cfunc == f))) {
  2962. a.splice(i, 1);
  2963. t._remove(o, n, e.cfunc);
  2964. s = true;
  2965. return false;
  2966. }
  2967. });
  2968. return s;
  2969. },
  2970. clear : function(o) {
  2971. var t = this, a = t.events, i, e;
  2972. if (o) {
  2973. o = DOM.get(o);
  2974. for (i = a.length - 1; i >= 0; i--) {
  2975. e = a[i];
  2976. if (e.obj === o) {
  2977. t._remove(e.obj, e.name, e.cfunc);
  2978. e.obj = e.cfunc = null;
  2979. a.splice(i, 1);
  2980. }
  2981. }
  2982. }
  2983. },
  2984. cancel : function(e) {
  2985. if (!e)
  2986. return false;
  2987. this.stop(e);
  2988. return this.prevent(e);
  2989. },
  2990. stop : function(e) {
  2991. if (e.stopPropagation)
  2992. e.stopPropagation();
  2993. else
  2994. e.cancelBubble = true;
  2995. return false;
  2996. },
  2997. prevent : function(e) {
  2998. if (e.preventDefault)
  2999. e.preventDefault();
  3000. else
  3001. e.returnValue = false;
  3002. return false;
  3003. },
  3004. destroy : function() {
  3005. var t = this;
  3006. each(t.events, function(e, i) {
  3007. t._remove(e.obj, e.name, e.cfunc);
  3008. e.obj = e.cfunc = null;
  3009. });
  3010. t.events = [];
  3011. t = null;
  3012. },
  3013. _add : function(o, n, f) {
  3014. if (o.attachEvent)
  3015. o.attachEvent('on' + n, f);
  3016. else if (o.addEventListener)
  3017. o.addEventListener(n, f, false);
  3018. else
  3019. o['on' + n] = f;
  3020. },
  3021. _remove : function(o, n, f) {
  3022. if (o) {
  3023. try {
  3024. if (o.detachEvent)
  3025. o.detachEvent('on' + n, f);
  3026. else if (o.removeEventListener)
  3027. o.removeEventListener(n, f, false);
  3028. else
  3029. o['on' + n] = null;
  3030. } catch (ex) {
  3031. // Might fail with permission denined on IE so we just ignore that
  3032. }
  3033. }
  3034. },
  3035. _pageInit : function(win) {
  3036. var t = this;
  3037. // Keep it from running more than once
  3038. if (t.domLoaded)
  3039. return;
  3040. t.domLoaded = true;
  3041. each(t.inits, function(c) {
  3042. c();
  3043. });
  3044. t.inits = [];
  3045. },
  3046. _wait : function(win) {
  3047. var t = this, doc = win.document;
  3048. // No need since the document is already loaded
  3049. if (win.tinyMCE_GZ && tinyMCE_GZ.loaded) {
  3050. t.domLoaded = 1;
  3051. return;
  3052. }
  3053. // Use IE method
  3054. if (doc.attachEvent) {
  3055. doc.attachEvent("onreadystatechange", function() {
  3056. if (doc.readyState === "complete") {
  3057. doc.detachEvent("onreadystatechange", arguments.callee);
  3058. t._pageInit(win);
  3059. }
  3060. });
  3061. if (doc.documentElement.doScroll && win == win.top) {
  3062. (function() {
  3063. if (t.domLoaded)
  3064. return;
  3065. try {
  3066. // If IE is used, use the trick by Diego Perini
  3067. // http://javascript.nwbox.com/IEContentLoaded/
  3068. doc.documentElement.doScroll("left");
  3069. } catch (ex) {
  3070. setTimeout(arguments.callee, 0);
  3071. return;
  3072. }
  3073. t._pageInit(win);
  3074. })();
  3075. }
  3076. } else if (doc.addEventListener) {
  3077. t._add(win, 'DOMContentLoaded', function() {
  3078. t._pageInit(win);
  3079. });
  3080. }
  3081. t._add(win, 'load', function() {
  3082. t._pageInit(win);
  3083. });
  3084. },
  3085. _stoppers : {
  3086. preventDefault : function() {
  3087. this.returnValue = false;
  3088. },
  3089. stopPropagation : function() {
  3090. this.cancelBubble = true;
  3091. }
  3092. }
  3093. });
  3094. Event = tinymce.dom.Event = new tinymce.dom.EventUtils();
  3095. // Dispatch DOM content loaded event for IE and Safari
  3096. Event._wait(window);
  3097. tinymce.addUnload(function() {
  3098. Event.destroy();
  3099. });
  3100. })(tinymce);
  3101. (function(tinymce) {
  3102. tinymce.dom.Element = function(id, settings) {
  3103. var t = this, dom, el;
  3104. t.settings = settings = settings || {};
  3105. t.id = id;
  3106. t.dom = dom = settings.dom || tinymce.DOM;
  3107. // Only IE leaks DOM references, this is a lot faster
  3108. if (!tinymce.isIE)
  3109. el = dom.get(t.id);
  3110. tinymce.each(
  3111. ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' +
  3112. 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' +
  3113. 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' +
  3114. 'isHidden,setHTML,get').split(/,/)
  3115. , function(k) {
  3116. t[k] = function() {
  3117. var a = [id], i;
  3118. for (i = 0; i < arguments.length; i++)
  3119. a.push(arguments[i]);
  3120. a = dom[k].apply(dom, a);
  3121. t.update(k);
  3122. return a;
  3123. };
  3124. });
  3125. tinymce.extend(t, {
  3126. on : function(n, f, s) {
  3127. return tinymce.dom.Event.add(t.id, n, f, s);
  3128. },
  3129. getXY : function() {
  3130. return {
  3131. x : parseInt(t.getStyle('left')),
  3132. y : parseInt(t.getStyle('top'))
  3133. };
  3134. },
  3135. getSize : function() {
  3136. var n = dom.get(t.id);
  3137. return {
  3138. w : parseInt(t.getStyle('width') || n.clientWidth),
  3139. h : parseInt(t.getStyle('height') || n.clientHeight)
  3140. };
  3141. },
  3142. moveTo : function(x, y) {
  3143. t.setStyles({left : x, top : y});
  3144. },
  3145. moveBy : function(x, y) {
  3146. var p = t.getXY();
  3147. t.moveTo(p.x + x, p.y + y);
  3148. },
  3149. resizeTo : function(w, h) {
  3150. t.setStyles({width : w, height : h});
  3151. },
  3152. resizeBy : function(w, h) {
  3153. var s = t.getSize();
  3154. t.resizeTo(s.w + w, s.h + h);
  3155. },
  3156. update : function(k) {
  3157. var b;
  3158. if (tinymce.isIE6 && settings.blocker) {
  3159. k = k || '';
  3160. // Ignore getters
  3161. if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
  3162. return;
  3163. // Remove blocker on remove
  3164. if (k == 'remove') {
  3165. dom.remove(t.blocker);
  3166. return;
  3167. }
  3168. if (!t.blocker) {
  3169. t.blocker = dom.uniqueId();
  3170. b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
  3171. dom.setStyle(b, 'opacity', 0);
  3172. } else
  3173. b = dom.get(t.blocker);
  3174. dom.setStyles(b, {
  3175. left : t.getStyle('left', 1),
  3176. top : t.getStyle('top', 1),
  3177. width : t.getStyle('width', 1),
  3178. height : t.getStyle('height', 1),
  3179. display : t.getStyle('display', 1),
  3180. zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1
  3181. });
  3182. }
  3183. }
  3184. });
  3185. };
  3186. })(tinymce);
  3187. (function(tinymce) {
  3188. function trimNl(s) {
  3189. return s.replace(/[\n\r]+/g, '');
  3190. };
  3191. // Shorten names
  3192. var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each;
  3193. tinymce.create('tinymce.dom.Selection', {
  3194. Selection : function(dom, win, serializer) {
  3195. var t = this;
  3196. t.dom = dom;
  3197. t.win = win;
  3198. t.serializer = serializer;
  3199. // Add events
  3200. each([
  3201. 'onBeforeSetContent',
  3202. 'onBeforeGetContent',
  3203. 'onSetContent',
  3204. 'onGetContent'
  3205. ], function(e) {
  3206. t[e] = new tinymce.util.Dispatcher(t);
  3207. });
  3208. // No W3C Range support
  3209. if (!t.win.getSelection)
  3210. t.tridentSel = new tinymce.dom.TridentSelection(t);
  3211. if (tinymce.isIE && dom.boxModel)
  3212. this._fixIESelection();
  3213. // Prevent leaks
  3214. tinymce.addUnload(t.destroy, t);
  3215. },
  3216. getContent : function(s) {
  3217. var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n;
  3218. s = s || {};
  3219. wb = wa = '';
  3220. s.get = true;
  3221. s.format = s.format || 'html';
  3222. t.onBeforeGetContent.dispatch(t, s);
  3223. if (s.format == 'text')
  3224. return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : ''));
  3225. if (r.cloneContents) {
  3226. n = r.cloneContents();
  3227. if (n)
  3228. e.appendChild(n);
  3229. } else if (is(r.item) || is(r.htmlText))
  3230. e.innerHTML = r.item ? r.item(0).outerHTML : r.htmlText;
  3231. else
  3232. e.innerHTML = r.toString();
  3233. // Keep whitespace before and after
  3234. if (/^\s/.test(e.innerHTML))
  3235. wb = ' ';
  3236. if (/\s+$/.test(e.innerHTML))
  3237. wa = ' ';
  3238. s.getInner = true;
  3239. s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa;
  3240. t.onGetContent.dispatch(t, s);
  3241. return s.content;
  3242. },
  3243. setContent : function(h, s) {
  3244. var t = this, r = t.getRng(), c, d = t.win.document;
  3245. s = s || {format : 'html'};
  3246. s.set = true;
  3247. h = s.content = t.dom.processHTML(h);
  3248. // Dispatch before set content event
  3249. t.onBeforeSetContent.dispatch(t, s);
  3250. h = s.content;
  3251. if (r.insertNode) {
  3252. // Make caret marker since insertNode places the caret in the beginning of text after insert
  3253. h += '<span id="__caret">_</span>';
  3254. // Delete and insert new node
  3255. if (r.startContainer == d && r.endContainer == d) {
  3256. // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
  3257. d.body.innerHTML = h;
  3258. } else {
  3259. r.deleteContents();
  3260. if (d.body.childNodes.length == 0) {
  3261. d.body.innerHTML = h;
  3262. } else {
  3263. // createContextualFragment doesn't exists in IE 9 DOMRanges
  3264. if (r.createContextualFragment) {
  3265. r.insertNode(r.createContextualFragment(h));
  3266. } else {
  3267. // Fake createContextualFragment call in IE 9
  3268. var frag = d.createDocumentFragment(), temp = d.createElement('div');
  3269. frag.appendChild(temp);
  3270. temp.outerHTML = h;
  3271. r.insertNode(frag);
  3272. }
  3273. }
  3274. }
  3275. // Move to caret marker
  3276. c = t.dom.get('__caret');
  3277. // Make sure we wrap it compleatly, Opera fails with a simple select call
  3278. r = d.createRange();
  3279. r.setStartBefore(c);
  3280. r.setEndBefore(c);
  3281. t.setRng(r);
  3282. // Remove the caret position
  3283. t.dom.remove('__caret');
  3284. } else {
  3285. if (r.item) {
  3286. // Delete content and get caret text selection
  3287. d.execCommand('Delete', false, null);
  3288. r = t.getRng();
  3289. }
  3290. r.pasteHTML(h);
  3291. }
  3292. // Dispatch set content event
  3293. t.onSetContent.dispatch(t, s);
  3294. },
  3295. getStart : function() {
  3296. var rng = this.getRng(), startElement, parentElement, checkRng, node;
  3297. if (rng.duplicate || rng.item) {
  3298. // Control selection, return first item
  3299. if (rng.item)
  3300. return rng.item(0);
  3301. // Get start element
  3302. checkRng = rng.duplicate();
  3303. checkRng.collapse(1);
  3304. startElement = checkRng.parentElement();
  3305. // Check if range parent is inside the start element, then return the inner parent element
  3306. // This will fix issues when a single element is selected, IE would otherwise return the wrong start element
  3307. parentElement = node = rng.parentElement();
  3308. while (node = node.parentNode) {
  3309. if (node == startElement) {
  3310. startElement = parentElement;
  3311. break;
  3312. }
  3313. }
  3314. // If start element is body element try to move to the first child if it exists
  3315. if (startElement && startElement.nodeName == 'BODY')
  3316. return startElement.firstChild || startElement;
  3317. return startElement;
  3318. } else {
  3319. startElement = rng.startContainer;
  3320. if (startElement.nodeType == 1 && startElement.hasChildNodes())
  3321. startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)];
  3322. if (startElement && startElement.nodeType == 3)
  3323. return startElement.parentNode;
  3324. return startElement;
  3325. }
  3326. },
  3327. getEnd : function() {
  3328. var t = this, r = t.getRng(), e, eo;
  3329. if (r.duplicate || r.item) {
  3330. if (r.item)
  3331. return r.item(0);
  3332. r = r.duplicate();
  3333. r.collapse(0);
  3334. e = r.parentElement();
  3335. if (e && e.nodeName == 'BODY')
  3336. return e.lastChild || e;
  3337. return e;
  3338. } else {
  3339. e = r.endContainer;
  3340. eo = r.endOffset;
  3341. if (e.nodeType == 1 && e.hasChildNodes())
  3342. e = e.childNodes[eo > 0 ? eo - 1 : eo];
  3343. if (e && e.nodeType == 3)
  3344. return e.parentNode;
  3345. return e;
  3346. }
  3347. },
  3348. getBookmark : function(type, normalized) {
  3349. var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles;
  3350. function findIndex(name, element) {
  3351. var index = 0;
  3352. each(dom.select(name), function(node, i) {
  3353. if (node == element)
  3354. index = i;
  3355. });
  3356. return index;
  3357. };
  3358. if (type == 2) {
  3359. function getLocation() {
  3360. var rng = t.getRng(true), root = dom.getRoot(), bookmark = {};
  3361. function getPoint(rng, start) {
  3362. var container = rng[start ? 'startContainer' : 'endContainer'],
  3363. offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0;
  3364. if (container.nodeType == 3) {
  3365. if (normalized) {
  3366. for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling)
  3367. offset += node.nodeValue.length;
  3368. }
  3369. point.push(offset);
  3370. } else {
  3371. childNodes = container.childNodes;
  3372. if (offset >= childNodes.length && childNodes.length) {
  3373. after = 1;
  3374. offset = Math.max(0, childNodes.length - 1);
  3375. }
  3376. point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after);
  3377. }
  3378. for (; container && container != root; container = container.parentNode)
  3379. point.push(t.dom.nodeIndex(container, normalized));
  3380. return point;
  3381. };
  3382. bookmark.start = getPoint(rng, true);
  3383. if (!t.isCollapsed())
  3384. bookmark.end = getPoint(rng);
  3385. return bookmark;
  3386. };
  3387. return getLocation();
  3388. }
  3389. // Handle simple range
  3390. if (type)
  3391. return {rng : t.getRng()};
  3392. rng = t.getRng();
  3393. id = dom.uniqueId();
  3394. collapsed = tinyMCE.activeEditor.selection.isCollapsed();
  3395. styles = 'overflow:hidden;line-height:0px';
  3396. // Explorer method
  3397. if (rng.duplicate || rng.item) {
  3398. // Text selection
  3399. if (!rng.item) {
  3400. rng2 = rng.duplicate();
  3401. // Insert start marker
  3402. rng.collapse();
  3403. rng.pasteHTML('<span _mce_type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
  3404. // Insert end marker
  3405. if (!collapsed) {
  3406. rng2.collapse(false);
  3407. rng2.pasteHTML('<span _mce_type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
  3408. }
  3409. } else {
  3410. // Control selection
  3411. element = rng.item(0);
  3412. name = element.nodeName;
  3413. return {name : name, index : findIndex(name, element)};
  3414. }
  3415. } else {
  3416. element = t.getNode();
  3417. name = element.nodeName;
  3418. if (name == 'IMG')
  3419. return {name : name, index : findIndex(name, element)};
  3420. // W3C method
  3421. rng2 = rng.cloneRange();
  3422. // Insert end marker
  3423. if (!collapsed) {
  3424. rng2.collapse(false);
  3425. rng2.insertNode(dom.create('span', {_mce_type : "bookmark", id : id + '_end', style : styles}, chr));
  3426. }
  3427. rng.collapse(true);
  3428. rng.insertNode(dom.create('span', {_mce_type : "bookmark", id : id + '_start', style : styles}, chr));
  3429. }
  3430. t.moveToBookmark({id : id, keep : 1});
  3431. return {id : id};
  3432. },
  3433. moveToBookmark : function(bookmark) {
  3434. var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset;
  3435. // Clear selection cache
  3436. if (t.tridentSel)
  3437. t.tridentSel.destroy();
  3438. if (bookmark) {
  3439. if (bookmark.start) {
  3440. rng = dom.createRng();
  3441. root = dom.getRoot();
  3442. function setEndPoint(start) {
  3443. var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
  3444. if (point) {
  3445. // Find container node
  3446. for (node = root, i = point.length - 1; i >= 1; i--) {
  3447. children = node.childNodes;
  3448. if (children.length)
  3449. node = children[point[i]];
  3450. }
  3451. // Set offset within container node
  3452. if (start)
  3453. rng.setStart(node, point[0]);
  3454. else
  3455. rng.setEnd(node, point[0]);
  3456. }
  3457. };
  3458. setEndPoint(true);
  3459. setEndPoint();
  3460. t.setRng(rng);
  3461. } else if (bookmark.id) {
  3462. function restoreEndPoint(suffix) {
  3463. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
  3464. if (marker) {
  3465. node = marker.parentNode;
  3466. if (suffix == 'start') {
  3467. if (!keep) {
  3468. idx = dom.nodeIndex(marker);
  3469. } else {
  3470. node = marker.firstChild;
  3471. idx = 1;
  3472. }
  3473. startContainer = endContainer = node;
  3474. startOffset = endOffset = idx;
  3475. } else {
  3476. if (!keep) {
  3477. idx = dom.nodeIndex(marker);
  3478. } else {
  3479. node = marker.firstChild;
  3480. idx = 1;
  3481. }
  3482. endContainer = node;
  3483. endOffset = idx;
  3484. }
  3485. if (!keep) {
  3486. prev = marker.previousSibling;
  3487. next = marker.nextSibling;
  3488. // Remove all marker text nodes
  3489. each(tinymce.grep(marker.childNodes), function(node) {
  3490. if (node.nodeType == 3)
  3491. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  3492. });
  3493. // Remove marker but keep children if for example contents where inserted into the marker
  3494. // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature
  3495. while (marker = dom.get(bookmark.id + '_' + suffix))
  3496. dom.remove(marker, 1);
  3497. // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
  3498. // and we are sniffing since adding a lot of detection code for a browser with 3% of the market isn't worth the effort. Sorry, Opera but it's just a fact
  3499. if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) {
  3500. idx = prev.nodeValue.length;
  3501. prev.appendData(next.nodeValue);
  3502. dom.remove(next);
  3503. if (suffix == 'start') {
  3504. startContainer = endContainer = prev;
  3505. startOffset = endOffset = idx;
  3506. } else {
  3507. endContainer = prev;
  3508. endOffset = idx;
  3509. }
  3510. }
  3511. }
  3512. }
  3513. };
  3514. function addBogus(node) {
  3515. // Adds a bogus BR element for empty block elements
  3516. // on non IE browsers just to have a place to put the caret
  3517. if (!isIE && dom.isBlock(node) && !node.innerHTML)
  3518. node.innerHTML = '<br _mce_bogus="1" />';
  3519. return node;
  3520. };
  3521. // Restore start/end points
  3522. restoreEndPoint('start');
  3523. restoreEndPoint('end');
  3524. if (startContainer) {
  3525. rng = dom.createRng();
  3526. rng.setStart(addBogus(startContainer), startOffset);
  3527. rng.setEnd(addBogus(endContainer), endOffset);
  3528. t.setRng(rng);
  3529. }
  3530. } else if (bookmark.name) {
  3531. t.select(dom.select(bookmark.name)[bookmark.index]);
  3532. } else if (bookmark.rng)
  3533. t.setRng(bookmark.rng);
  3534. }
  3535. },
  3536. select : function(node, content) {
  3537. var t = this, dom = t.dom, rng = dom.createRng(), idx;
  3538. idx = dom.nodeIndex(node);
  3539. rng.setStart(node.parentNode, idx);
  3540. rng.setEnd(node.parentNode, idx + 1);
  3541. // Find first/last text node or BR element
  3542. if (content) {
  3543. function setPoint(node, start) {
  3544. var walker = new tinymce.dom.TreeWalker(node, node);
  3545. do {
  3546. // Text node
  3547. if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
  3548. if (start)
  3549. rng.setStart(node, 0);
  3550. else
  3551. rng.setEnd(node, node.nodeValue.length);
  3552. return;
  3553. }
  3554. // BR element
  3555. if (node.nodeName == 'BR') {
  3556. if (start)
  3557. rng.setStartBefore(node);
  3558. else
  3559. rng.setEndBefore(node);
  3560. return;
  3561. }
  3562. } while (node = (start ? walker.next() : walker.prev()));
  3563. };
  3564. setPoint(node, 1);
  3565. setPoint(node);
  3566. }
  3567. t.setRng(rng);
  3568. return node;
  3569. },
  3570. isCollapsed : function() {
  3571. var t = this, r = t.getRng(), s = t.getSel();
  3572. if (!r || r.item)
  3573. return false;
  3574. if (r.compareEndPoints)
  3575. return r.compareEndPoints('StartToEnd', r) === 0;
  3576. return !s || r.collapsed;
  3577. },
  3578. collapse : function(b) {
  3579. var t = this, r = t.getRng(), n;
  3580. // Control range on IE
  3581. if (r.item) {
  3582. n = r.item(0);
  3583. r = this.win.document.body.createTextRange();
  3584. r.moveToElementText(n);
  3585. }
  3586. r.collapse(!!b);
  3587. t.setRng(r);
  3588. },
  3589. getSel : function() {
  3590. var t = this, w = this.win;
  3591. return w.getSelection ? w.getSelection() : w.document.selection;
  3592. },
  3593. getRng : function(w3c) {
  3594. var t = this, s, r, elm, doc = t.win.document;
  3595. // Found tridentSel object then we need to use that one
  3596. if (w3c && t.tridentSel)
  3597. return t.tridentSel.getRangeAt(0);
  3598. try {
  3599. if (s = t.getSel())
  3600. r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : doc.createRange());
  3601. } catch (ex) {
  3602. // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
  3603. }
  3604. // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
  3605. if (tinymce.isIE && r.setStart && doc.selection.createRange().item) {
  3606. elm = doc.selection.createRange().item(0);
  3607. r = doc.createRange();
  3608. r.setStartBefore(elm);
  3609. r.setEndAfter(elm);
  3610. }
  3611. // No range found then create an empty one
  3612. // This can occur when the editor is placed in a hidden container element on Gecko
  3613. // Or on IE when there was an exception
  3614. if (!r)
  3615. r = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  3616. if (t.selectedRange && t.explicitRange) {
  3617. if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) {
  3618. // Safari, Opera and Chrome only ever select text which causes the range to change.
  3619. // This lets us use the originally set range if the selection hasn't been changed by the user.
  3620. r = t.explicitRange;
  3621. } else {
  3622. t.selectedRange = null;
  3623. t.explicitRange = null;
  3624. }
  3625. }
  3626. return r;
  3627. },
  3628. setRng : function(r) {
  3629. var s, t = this;
  3630. if (!t.tridentSel) {
  3631. s = t.getSel();
  3632. if (s) {
  3633. t.explicitRange = r;
  3634. s.removeAllRanges();
  3635. s.addRange(r);
  3636. t.selectedRange = s.getRangeAt(0);
  3637. }
  3638. } else {
  3639. // Is W3C Range
  3640. if (r.cloneRange) {
  3641. t.tridentSel.addRange(r);
  3642. return;
  3643. }
  3644. // Is IE specific range
  3645. try {
  3646. r.select();
  3647. } catch (ex) {
  3648. // Needed for some odd IE bug #1843306
  3649. }
  3650. }
  3651. },
  3652. setNode : function(n) {
  3653. var t = this;
  3654. t.setContent(t.dom.getOuterHTML(n));
  3655. return n;
  3656. },
  3657. getNode : function() {
  3658. var t = this, rng = t.getRng(), sel = t.getSel(), elm;
  3659. if (rng.setStart) {
  3660. // Range maybe lost after the editor is made visible again
  3661. if (!rng)
  3662. return t.dom.getRoot();
  3663. elm = rng.commonAncestorContainer;
  3664. // Handle selection a image or other control like element such as anchors
  3665. if (!rng.collapsed) {
  3666. if (rng.startContainer == rng.endContainer) {
  3667. if (rng.startOffset - rng.endOffset < 2) {
  3668. if (rng.startContainer.hasChildNodes())
  3669. elm = rng.startContainer.childNodes[rng.startOffset];
  3670. }
  3671. }
  3672. // If the anchor node is a element instead of a text node then return this element
  3673. if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
  3674. return sel.anchorNode.childNodes[sel.anchorOffset];
  3675. }
  3676. if (elm && elm.nodeType == 3)
  3677. return elm.parentNode;
  3678. return elm;
  3679. }
  3680. return rng.item ? rng.item(0) : rng.parentElement();
  3681. },
  3682. getSelectedBlocks : function(st, en) {
  3683. var t = this, dom = t.dom, sb, eb, n, bl = [];
  3684. sb = dom.getParent(st || t.getStart(), dom.isBlock);
  3685. eb = dom.getParent(en || t.getEnd(), dom.isBlock);
  3686. if (sb)
  3687. bl.push(sb);
  3688. if (sb && eb && sb != eb) {
  3689. n = sb;
  3690. while ((n = n.nextSibling) && n != eb) {
  3691. if (dom.isBlock(n))
  3692. bl.push(n);
  3693. }
  3694. }
  3695. if (eb && sb != eb)
  3696. bl.push(eb);
  3697. return bl;
  3698. },
  3699. destroy : function(s) {
  3700. var t = this;
  3701. t.win = null;
  3702. if (t.tridentSel)
  3703. t.tridentSel.destroy();
  3704. // Manual destroy then remove unload handler
  3705. if (!s)
  3706. tinymce.removeUnload(t.destroy);
  3707. },
  3708. // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
  3709. _fixIESelection : function() {
  3710. var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng;
  3711. // Make HTML element unselectable since we are going to handle selection by hand
  3712. doc.documentElement.unselectable = true;
  3713. // Return range from point or null if it failed
  3714. function rngFromPoint(x, y) {
  3715. var rng = body.createTextRange();
  3716. try {
  3717. rng.moveToPoint(x, y);
  3718. } catch (ex) {
  3719. // IE sometimes throws and exception, so lets just ignore it
  3720. rng = null;
  3721. }
  3722. return rng;
  3723. };
  3724. // Fires while the selection is changing
  3725. function selectionChange(e) {
  3726. var pointRng;
  3727. // Check if the button is down or not
  3728. if (e.button) {
  3729. // Create range from mouse position
  3730. pointRng = rngFromPoint(e.x, e.y);
  3731. if (pointRng) {
  3732. // Check if pointRange is before/after selection then change the endPoint
  3733. if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
  3734. pointRng.setEndPoint('StartToStart', startRng);
  3735. else
  3736. pointRng.setEndPoint('EndToEnd', startRng);
  3737. pointRng.select();
  3738. }
  3739. } else
  3740. endSelection();
  3741. }
  3742. // Removes listeners
  3743. function endSelection() {
  3744. dom.unbind(doc, 'mouseup', endSelection);
  3745. dom.unbind(doc, 'mousemove', selectionChange);
  3746. started = 0;
  3747. };
  3748. // Detect when user selects outside BODY
  3749. dom.bind(doc, 'mousedown', function(e) {
  3750. if (e.target.nodeName === 'HTML') {
  3751. if (started)
  3752. endSelection();
  3753. started = 1;
  3754. // Setup start position
  3755. startRng = rngFromPoint(e.x, e.y);
  3756. if (startRng) {
  3757. // Listen for selection change events
  3758. dom.bind(doc, 'mouseup', endSelection);
  3759. dom.bind(doc, 'mousemove', selectionChange);
  3760. dom.win.focus();
  3761. startRng.select();
  3762. }
  3763. }
  3764. });
  3765. }
  3766. });
  3767. })(tinymce);
  3768. (function(tinymce) {
  3769. tinymce.create('tinymce.dom.XMLWriter', {
  3770. node : null,
  3771. XMLWriter : function(s) {
  3772. // Get XML document
  3773. function getXML() {
  3774. var i = document.implementation;
  3775. if (!i || !i.createDocument) {
  3776. // Try IE objects
  3777. try {return new ActiveXObject('MSXML2.DOMDocument');} catch (ex) {}
  3778. try {return new ActiveXObject('Microsoft.XmlDom');} catch (ex) {}
  3779. } else
  3780. return i.createDocument('', '', null);
  3781. };
  3782. this.doc = getXML();
  3783. // Since Opera and WebKit doesn't escape > into &gt; we need to do it our self to normalize the output for all browsers
  3784. this.valid = tinymce.isOpera || tinymce.isWebKit;
  3785. this.reset();
  3786. },
  3787. reset : function() {
  3788. var t = this, d = t.doc;
  3789. if (d.firstChild)
  3790. d.removeChild(d.firstChild);
  3791. t.node = d.appendChild(d.createElement("html"));
  3792. },
  3793. writeStartElement : function(n) {
  3794. var t = this;
  3795. t.node = t.node.appendChild(t.doc.createElement(n));
  3796. },
  3797. writeAttribute : function(n, v) {
  3798. if (this.valid)
  3799. v = v.replace(/>/g, '%MCGT%');
  3800. this.node.setAttribute(n, v);
  3801. },
  3802. writeEndElement : function() {
  3803. this.node = this.node.parentNode;
  3804. },
  3805. writeFullEndElement : function() {
  3806. var t = this, n = t.node;
  3807. n.appendChild(t.doc.createTextNode(""));
  3808. t.node = n.parentNode;
  3809. },
  3810. writeText : function(v) {
  3811. if (this.valid)
  3812. v = v.replace(/>/g, '%MCGT%');
  3813. this.node.appendChild(this.doc.createTextNode(v));
  3814. },
  3815. writeCDATA : function(v) {
  3816. this.node.appendChild(this.doc.createCDATASection(v));
  3817. },
  3818. writeComment : function(v) {
  3819. // Fix for bug #2035694
  3820. if (tinymce.isIE)
  3821. v = v.replace(/^\-|\-$/g, ' ');
  3822. this.node.appendChild(this.doc.createComment(v.replace(/\-\-/g, ' ')));
  3823. },
  3824. getContent : function() {
  3825. var h;
  3826. h = this.doc.xml || new XMLSerializer().serializeToString(this.doc);
  3827. h = h.replace(/<\?[^?]+\?>|<html[^>]*>|<\/html>|<html\/>|<!DOCTYPE[^>]+>/g, '');
  3828. h = h.replace(/ ?\/>/g, ' />');
  3829. if (this.valid)
  3830. h = h.replace(/\%MCGT%/g, '&gt;');
  3831. return h;
  3832. }
  3833. });
  3834. })(tinymce);
  3835. (function(tinymce) {
  3836. var attrsCharsRegExp = /[&\"<>]/g, textCharsRegExp = /[<>&]/g, encodedChars = {'&' : '&amp;', '"' : '&quot;', '<' : '&lt;', '>' : '&gt;'};
  3837. tinymce.create('tinymce.dom.StringWriter', {
  3838. str : null,
  3839. tags : null,
  3840. count : 0,
  3841. settings : null,
  3842. indent : null,
  3843. StringWriter : function(s) {
  3844. this.settings = tinymce.extend({
  3845. indent_char : ' ',
  3846. indentation : 0
  3847. }, s);
  3848. this.reset();
  3849. },
  3850. reset : function() {
  3851. this.indent = '';
  3852. this.str = "";
  3853. this.tags = [];
  3854. this.count = 0;
  3855. },
  3856. writeStartElement : function(n) {
  3857. this._writeAttributesEnd();
  3858. this.writeRaw('<' + n);
  3859. this.tags.push(n);
  3860. this.inAttr = true;
  3861. this.count++;
  3862. this.elementCount = this.count;
  3863. this.attrs = {};
  3864. },
  3865. writeAttribute : function(n, v) {
  3866. var t = this;
  3867. if (!t.attrs[n]) {
  3868. t.writeRaw(" " + t.encode(n, true) + '="' + t.encode(v, true) + '"');
  3869. t.attrs[n] = v;
  3870. }
  3871. },
  3872. writeEndElement : function() {
  3873. var n;
  3874. if (this.tags.length > 0) {
  3875. n = this.tags.pop();
  3876. if (this._writeAttributesEnd(1))
  3877. this.writeRaw('</' + n + '>');
  3878. if (this.settings.indentation > 0)
  3879. this.writeRaw('\n');
  3880. }
  3881. },
  3882. writeFullEndElement : function() {
  3883. if (this.tags.length > 0) {
  3884. this._writeAttributesEnd();
  3885. this.writeRaw('</' + this.tags.pop() + '>');
  3886. if (this.settings.indentation > 0)
  3887. this.writeRaw('\n');
  3888. }
  3889. },
  3890. writeText : function(v) {
  3891. this._writeAttributesEnd();
  3892. this.writeRaw(this.encode(v));
  3893. this.count++;
  3894. },
  3895. writeCDATA : function(v) {
  3896. this._writeAttributesEnd();
  3897. this.writeRaw('<![CDATA[' + v + ']]>');
  3898. this.count++;
  3899. },
  3900. writeComment : function(v) {
  3901. this._writeAttributesEnd();
  3902. this.writeRaw('<!--' + v + '-->');
  3903. this.count++;
  3904. },
  3905. writeRaw : function(v) {
  3906. this.str += v;
  3907. },
  3908. encode : function(s, attr) {
  3909. return s.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(v) {
  3910. return encodedChars[v];
  3911. });
  3912. },
  3913. getContent : function() {
  3914. return this.str;
  3915. },
  3916. _writeAttributesEnd : function(s) {
  3917. if (!this.inAttr)
  3918. return;
  3919. this.inAttr = false;
  3920. if (s && this.elementCount == this.count) {
  3921. this.writeRaw(' />');
  3922. return false;
  3923. }
  3924. this.writeRaw('>');
  3925. return true;
  3926. }
  3927. });
  3928. })(tinymce);
  3929. (function(tinymce) {
  3930. // Shorten names
  3931. var extend = tinymce.extend, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, isIE = tinymce.isIE, isGecko = tinymce.isGecko;
  3932. function wildcardToRE(s) {
  3933. return s.replace(/([?+*])/g, '.$1');
  3934. };
  3935. tinymce.create('tinymce.dom.Serializer', {
  3936. Serializer : function(s) {
  3937. var t = this;
  3938. t.key = 0;
  3939. t.onPreProcess = new Dispatcher(t);
  3940. t.onPostProcess = new Dispatcher(t);
  3941. try {
  3942. t.writer = new tinymce.dom.XMLWriter();
  3943. } catch (ex) {
  3944. // IE might throw exception if ActiveX is disabled so we then switch to the slightly slower StringWriter
  3945. t.writer = new tinymce.dom.StringWriter();
  3946. }
  3947. // IE9 broke the XML attributes order so it can't be used anymore
  3948. if (tinymce.isIE && document.documentMode > 8) {
  3949. t.writer = new tinymce.dom.StringWriter();
  3950. }
  3951. // Default settings
  3952. t.settings = s = extend({
  3953. dom : tinymce.DOM,
  3954. valid_nodes : 0,
  3955. node_filter : 0,
  3956. attr_filter : 0,
  3957. invalid_attrs : /^(_mce_|_moz_|sizset|sizcache)/,
  3958. closed : /^(br|hr|input|meta|img|link|param|area)$/,
  3959. entity_encoding : 'named',
  3960. entities : '160,nbsp,161,iexcl,162,cent,163,pound,164,curren,165,yen,166,brvbar,167,sect,168,uml,169,copy,170,ordf,171,laquo,172,not,173,shy,174,reg,175,macr,176,deg,177,plusmn,178,sup2,179,sup3,180,acute,181,micro,182,para,183,middot,184,cedil,185,sup1,186,ordm,187,raquo,188,frac14,189,frac12,190,frac34,191,iquest,192,Agrave,193,Aacute,194,Acirc,195,Atilde,196,Auml,197,Aring,198,AElig,199,Ccedil,200,Egrave,201,Eacute,202,Ecirc,203,Euml,204,Igrave,205,Iacute,206,Icirc,207,Iuml,208,ETH,209,Ntilde,210,Ograve,211,Oacute,212,Ocirc,213,Otilde,214,Ouml,215,times,216,Oslash,217,Ugrave,218,Uacute,219,Ucirc,220,Uuml,221,Yacute,222,THORN,223,szlig,224,agrave,225,aacute,226,acirc,227,atilde,228,auml,229,aring,230,aelig,231,ccedil,232,egrave,233,eacute,234,ecirc,235,euml,236,igrave,237,iacute,238,icirc,239,iuml,240,eth,241,ntilde,242,ograve,243,oacute,244,ocirc,245,otilde,246,ouml,247,divide,248,oslash,249,ugrave,250,uacute,251,ucirc,252,uuml,253,yacute,254,thorn,255,yuml,402,fnof,913,Alpha,914,Beta,915,Gamma,916,Delta,917,Epsilon,918,Zeta,919,Eta,920,Theta,921,Iota,922,Kappa,923,Lambda,924,Mu,925,Nu,926,Xi,927,Omicron,928,Pi,929,Rho,931,Sigma,932,Tau,933,Upsilon,934,Phi,935,Chi,936,Psi,937,Omega,945,alpha,946,beta,947,gamma,948,delta,949,epsilon,950,zeta,951,eta,952,theta,953,iota,954,kappa,955,lambda,956,mu,957,nu,958,xi,959,omicron,960,pi,961,rho,962,sigmaf,963,sigma,964,tau,965,upsilon,966,phi,967,chi,968,psi,969,omega,977,thetasym,978,upsih,982,piv,8226,bull,8230,hellip,8242,prime,8243,Prime,8254,oline,8260,frasl,8472,weierp,8465,image,8476,real,8482,trade,8501,alefsym,8592,larr,8593,uarr,8594,rarr,8595,darr,8596,harr,8629,crarr,8656,lArr,8657,uArr,8658,rArr,8659,dArr,8660,hArr,8704,forall,8706,part,8707,exist,8709,empty,8711,nabla,8712,isin,8713,notin,8715,ni,8719,prod,8721,sum,8722,minus,8727,lowast,8730,radic,8733,prop,8734,infin,8736,ang,8743,and,8744,or,8745,cap,8746,cup,8747,int,8756,there4,8764,sim,8773,cong,8776,asymp,8800,ne,8801,equiv,8804,le,8805,ge,8834,sub,8835,sup,8836,nsub,8838,sube,8839,supe,8853,oplus,8855,otimes,8869,perp,8901,sdot,8968,lceil,8969,rceil,8970,lfloor,8971,rfloor,9001,lang,9002,rang,9674,loz,9824,spades,9827,clubs,9829,hearts,9830,diams,338,OElig,339,oelig,352,Scaron,353,scaron,376,Yuml,710,circ,732,tilde,8194,ensp,8195,emsp,8201,thinsp,8204,zwnj,8205,zwj,8206,lrm,8207,rlm,8211,ndash,8212,mdash,8216,lsquo,8217,rsquo,8218,sbquo,8220,ldquo,8221,rdquo,8222,bdquo,8224,dagger,8225,Dagger,8240,permil,8249,lsaquo,8250,rsaquo,8364,euro',
  3961. valid_elements : '*[*]',
  3962. extended_valid_elements : 0,
  3963. invalid_elements : 0,
  3964. fix_table_elements : 1,
  3965. fix_list_elements : true,
  3966. fix_content_duplication : true,
  3967. convert_fonts_to_spans : false,
  3968. font_size_classes : 0,
  3969. apply_source_formatting : 0,
  3970. indent_mode : 'simple',
  3971. indent_char : '\t',
  3972. indent_levels : 1,
  3973. remove_linebreaks : 1,
  3974. remove_redundant_brs : 1,
  3975. element_format : 'xhtml'
  3976. }, s);
  3977. t.dom = s.dom;
  3978. t.schema = s.schema;
  3979. // Use raw entities if no entities are defined
  3980. if (s.entity_encoding == 'named' && !s.entities)
  3981. s.entity_encoding = 'raw';
  3982. if (s.remove_redundant_brs) {
  3983. t.onPostProcess.add(function(se, o) {
  3984. // Remove single BR at end of block elements since they get rendered
  3985. o.content = o.content.replace(/(<br \/>\s*)+<\/(p|h[1-6]|div|li)>/gi, function(a, b, c) {
  3986. // Check if it's a single element
  3987. if (/^<br \/>\s*<\//.test(a))
  3988. return '</' + c + '>';
  3989. return a;
  3990. });
  3991. });
  3992. }
  3993. // Remove XHTML element endings i.e. produce crap :) XHTML is better
  3994. if (s.element_format == 'html') {
  3995. t.onPostProcess.add(function(se, o) {
  3996. o.content = o.content.replace(/<([^>]+) \/>/g, '<$1>');
  3997. });
  3998. }
  3999. if (s.fix_list_elements) {
  4000. t.onPreProcess.add(function(se, o) {
  4001. var nl, x, a = ['ol', 'ul'], i, n, p, r = /^(OL|UL)$/, np;
  4002. function prevNode(e, n) {
  4003. var a = n.split(','), i;
  4004. while ((e = e.previousSibling) != null) {
  4005. for (i=0; i<a.length; i++) {
  4006. if (e.nodeName == a[i])
  4007. return e;
  4008. }
  4009. }
  4010. return null;
  4011. };
  4012. for (x=0; x<a.length; x++) {
  4013. nl = t.dom.select(a[x], o.node);
  4014. for (i=0; i<nl.length; i++) {
  4015. n = nl[i];
  4016. p = n.parentNode;
  4017. if (r.test(p.nodeName)) {
  4018. np = prevNode(n, 'LI');
  4019. if (!np) {
  4020. np = t.dom.create('li');
  4021. np.innerHTML = '&nbsp;';
  4022. np.appendChild(n);
  4023. p.insertBefore(np, p.firstChild);
  4024. } else
  4025. np.appendChild(n);
  4026. }
  4027. }
  4028. }
  4029. });
  4030. }
  4031. if (s.fix_table_elements) {
  4032. t.onPreProcess.add(function(se, o) {
  4033. each(t.dom.select('p table', o.node).reverse(), function(n) {
  4034. var parent = t.dom.getParent(n.parentNode, 'table,p');
  4035. if (parent.nodeName != 'TABLE') {
  4036. try {
  4037. t.dom.split(parent, n);
  4038. } catch (ex) {
  4039. // IE can sometimes fire an unknown runtime error so we just ignore it
  4040. }
  4041. }
  4042. });
  4043. });
  4044. }
  4045. },
  4046. setEntities : function(s) {
  4047. var t = this, a, i, l = {}, v;
  4048. // No need to setup more than once
  4049. if (t.entityLookup)
  4050. return;
  4051. // Build regex and lookup array
  4052. a = s.split(',');
  4053. for (i = 0; i < a.length; i += 2) {
  4054. v = a[i];
  4055. // Don't add default &amp; &quot; etc.
  4056. if (v == 34 || v == 38 || v == 60 || v == 62)
  4057. continue;
  4058. l[String.fromCharCode(a[i])] = a[i + 1];
  4059. v = parseInt(a[i]).toString(16);
  4060. }
  4061. t.entityLookup = l;
  4062. },
  4063. setRules : function(s) {
  4064. var t = this;
  4065. t._setup();
  4066. t.rules = {};
  4067. t.wildRules = [];
  4068. t.validElements = {};
  4069. return t.addRules(s);
  4070. },
  4071. addRules : function(s) {
  4072. var t = this, dr;
  4073. if (!s)
  4074. return;
  4075. t._setup();
  4076. each(s.split(','), function(s) {
  4077. var p = s.split(/\[|\]/), tn = p[0].split('/'), ra, at, wat, va = [];
  4078. // Extend with default rules
  4079. if (dr)
  4080. at = tinymce.extend([], dr.attribs);
  4081. // Parse attributes
  4082. if (p.length > 1) {
  4083. each(p[1].split('|'), function(s) {
  4084. var ar = {}, i;
  4085. at = at || [];
  4086. // Parse attribute rule
  4087. s = s.replace(/::/g, '~');
  4088. s = /^([!\-])?([\w*.?~_\-]+|)([=:<])?(.+)?$/.exec(s);
  4089. s[2] = s[2].replace(/~/g, ':');
  4090. // Add required attributes
  4091. if (s[1] == '!') {
  4092. ra = ra || [];
  4093. ra.push(s[2]);
  4094. }
  4095. // Remove inherited attributes
  4096. if (s[1] == '-') {
  4097. for (i = 0; i <at.length; i++) {
  4098. if (at[i].name == s[2]) {
  4099. at.splice(i, 1);
  4100. return;
  4101. }
  4102. }
  4103. }
  4104. switch (s[3]) {
  4105. // Add default attrib values
  4106. case '=':
  4107. ar.defaultVal = s[4] || '';
  4108. break;
  4109. // Add forced attrib values
  4110. case ':':
  4111. ar.forcedVal = s[4];
  4112. break;
  4113. // Add validation values
  4114. case '<':
  4115. ar.validVals = s[4].split('?');
  4116. break;
  4117. }
  4118. if (/[*.?]/.test(s[2])) {
  4119. wat = wat || [];
  4120. ar.nameRE = new RegExp('^' + wildcardToRE(s[2]) + '$');
  4121. wat.push(ar);
  4122. } else {
  4123. ar.name = s[2];
  4124. at.push(ar);
  4125. }
  4126. va.push(s[2]);
  4127. });
  4128. }
  4129. // Handle element names
  4130. each(tn, function(s, i) {
  4131. var pr = s.charAt(0), x = 1, ru = {};
  4132. // Extend with default rule data
  4133. if (dr) {
  4134. if (dr.noEmpty)
  4135. ru.noEmpty = dr.noEmpty;
  4136. if (dr.fullEnd)
  4137. ru.fullEnd = dr.fullEnd;
  4138. if (dr.padd)
  4139. ru.padd = dr.padd;
  4140. }
  4141. // Handle prefixes
  4142. switch (pr) {
  4143. case '-':
  4144. ru.noEmpty = true;
  4145. break;
  4146. case '+':
  4147. ru.fullEnd = true;
  4148. break;
  4149. case '#':
  4150. ru.padd = true;
  4151. break;
  4152. default:
  4153. x = 0;
  4154. }
  4155. tn[i] = s = s.substring(x);
  4156. t.validElements[s] = 1;
  4157. // Add element name or element regex
  4158. if (/[*.?]/.test(tn[0])) {
  4159. ru.nameRE = new RegExp('^' + wildcardToRE(tn[0]) + '$');
  4160. t.wildRules = t.wildRules || {};
  4161. t.wildRules.push(ru);
  4162. } else {
  4163. ru.name = tn[0];
  4164. // Store away default rule
  4165. if (tn[0] == '@')
  4166. dr = ru;
  4167. t.rules[s] = ru;
  4168. }
  4169. ru.attribs = at;
  4170. if (ra)
  4171. ru.requiredAttribs = ra;
  4172. if (wat) {
  4173. // Build valid attributes regexp
  4174. s = '';
  4175. each(va, function(v) {
  4176. if (s)
  4177. s += '|';
  4178. s += '(' + wildcardToRE(v) + ')';
  4179. });
  4180. ru.validAttribsRE = new RegExp('^' + s.toLowerCase() + '$');
  4181. ru.wildAttribs = wat;
  4182. }
  4183. });
  4184. });
  4185. // Build valid elements regexp
  4186. s = '';
  4187. each(t.validElements, function(v, k) {
  4188. if (s)
  4189. s += '|';
  4190. if (k != '@')
  4191. s += k;
  4192. });
  4193. t.validElementsRE = new RegExp('^(' + wildcardToRE(s.toLowerCase()) + ')$');
  4194. //console.debug(t.validElementsRE.toString());
  4195. //console.dir(t.rules);
  4196. //console.dir(t.wildRules);
  4197. },
  4198. findRule : function(n) {
  4199. var t = this, rl = t.rules, i, r;
  4200. t._setup();
  4201. // Exact match
  4202. r = rl[n];
  4203. if (r)
  4204. return r;
  4205. // Try wildcards
  4206. rl = t.wildRules;
  4207. for (i = 0; i < rl.length; i++) {
  4208. if (rl[i].nameRE.test(n))
  4209. return rl[i];
  4210. }
  4211. return null;
  4212. },
  4213. findAttribRule : function(ru, n) {
  4214. var i, wa = ru.wildAttribs;
  4215. for (i = 0; i < wa.length; i++) {
  4216. if (wa[i].nameRE.test(n))
  4217. return wa[i];
  4218. }
  4219. return null;
  4220. },
  4221. serialize : function(n, o) {
  4222. var h, t = this, doc, oldDoc, impl, selected;
  4223. t._setup();
  4224. o = o || {};
  4225. o.format = o.format || 'html';
  4226. t.processObj = o;
  4227. // IE looses the selected attribute on option elements so we need to store it
  4228. // See: http://support.microsoft.com/kb/829907
  4229. if (isIE) {
  4230. selected = [];
  4231. each(n.getElementsByTagName('option'), function(n) {
  4232. var v = t.dom.getAttrib(n, 'selected');
  4233. selected.push(v ? v : null);
  4234. });
  4235. }
  4236. n = n.cloneNode(true);
  4237. // IE looses the selected attribute on option elements so we need to restore it
  4238. if (isIE) {
  4239. each(n.getElementsByTagName('option'), function(n, i) {
  4240. t.dom.setAttrib(n, 'selected', selected[i]);
  4241. });
  4242. }
  4243. // Nodes needs to be attached to something in WebKit/Opera
  4244. // Older builds of Opera crashes if you attach the node to an document created dynamically
  4245. // and since we can't feature detect a crash we need to sniff the acutal build number
  4246. // This fix will make DOM ranges and make Sizzle happy!
  4247. impl = n.ownerDocument.implementation;
  4248. if (impl.createHTMLDocument) {
  4249. // Create an empty HTML document
  4250. doc = impl.createHTMLDocument("");
  4251. // Add the element or it's children if it's a body element to the new document
  4252. each(n.nodeName == 'BODY' ? n.childNodes : [n], function(node) {
  4253. doc.body.appendChild(doc.importNode(node, true));
  4254. });
  4255. // Grab first child or body element for serialization
  4256. if (n.nodeName != 'BODY')
  4257. n = doc.body.firstChild;
  4258. else
  4259. n = doc.body;
  4260. // set the new document in DOMUtils so createElement etc works
  4261. oldDoc = t.dom.doc;
  4262. t.dom.doc = doc;
  4263. }
  4264. t.key = '' + (parseInt(t.key) + 1);
  4265. // Pre process
  4266. if (!o.no_events) {
  4267. o.node = n;
  4268. t.onPreProcess.dispatch(t, o);
  4269. }
  4270. // Serialize HTML DOM into a string
  4271. t.writer.reset();
  4272. t._info = o;
  4273. t._serializeNode(n, o.getInner);
  4274. // Post process
  4275. o.content = t.writer.getContent();
  4276. // Restore the old document if it was changed
  4277. if (oldDoc)
  4278. t.dom.doc = oldDoc;
  4279. if (!o.no_events)
  4280. t.onPostProcess.dispatch(t, o);
  4281. t._postProcess(o);
  4282. o.node = null;
  4283. return tinymce.trim(o.content);
  4284. },
  4285. // Internal functions
  4286. _postProcess : function(o) {
  4287. var t = this, s = t.settings, h = o.content, sc = [], p;
  4288. if (o.format == 'html') {
  4289. // Protect some elements
  4290. p = t._protect({
  4291. content : h,
  4292. patterns : [
  4293. {pattern : /(<script[^>]*>)(.*?)(<\/script>)/g},
  4294. {pattern : /(<noscript[^>]*>)(.*?)(<\/noscript>)/g},
  4295. {pattern : /(<style[^>]*>)(.*?)(<\/style>)/g},
  4296. {pattern : /(<pre[^>]*>)(.*?)(<\/pre>)/g, encode : 1},
  4297. {pattern : /(<!--\[CDATA\[)(.*?)(\]\]-->)/g}
  4298. ]
  4299. });
  4300. h = p.content;
  4301. // Entity encode
  4302. if (s.entity_encoding !== 'raw')
  4303. h = t._encode(h);
  4304. // Use BR instead of &nbsp; padded P elements inside editor and use <p>&nbsp;</p> outside editor
  4305. /* if (o.set)
  4306. h = h.replace(/<p>\s+(&nbsp;|&#160;|\u00a0|<br \/>)\s+<\/p>/g, '<p><br /></p>');
  4307. else
  4308. h = h.replace(/<p>\s+(&nbsp;|&#160;|\u00a0|<br \/>)\s+<\/p>/g, '<p>$1</p>');*/
  4309. // Since Gecko and Safari keeps whitespace in the DOM we need to
  4310. // remove it inorder to match other browsers. But I think Gecko and Safari is right.
  4311. // This process is only done when getting contents out from the editor.
  4312. if (!o.set) {
  4313. // We need to replace paragraph whitespace with an nbsp before indentation to keep the \u00a0 char
  4314. h = tinymce._replace(/<p>\s+<\/p>|<p([^>]+)>\s+<\/p>/g, s.entity_encoding == 'numeric' ? '<p$1>&#160;</p>' : '<p$1>&nbsp;</p>', h);
  4315. if (s.remove_linebreaks) {
  4316. h = h.replace(/\r?\n|\r/g, ' ');
  4317. h = tinymce._replace(/(<[^>]+>)\s+/g, '$1 ', h);
  4318. h = tinymce._replace(/\s+(<\/[^>]+>)/g, ' $1', h);
  4319. h = tinymce._replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object) ([^>]+)>\s+/g, '<$1 $2>', h); // Trim block start
  4320. h = tinymce._replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>\s+/g, '<$1>', h); // Trim block start
  4321. h = tinymce._replace(/\s+<\/(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>/g, '</$1>', h); // Trim block end
  4322. }
  4323. // Simple indentation
  4324. if (s.apply_source_formatting && s.indent_mode == 'simple') {
  4325. // Add line breaks before and after block elements
  4326. h = tinymce._replace(/<(\/?)(ul|hr|table|meta|link|tbody|tr|object|body|head|html|map)(|[^>]+)>\s*/g, '\n<$1$2$3>\n', h);
  4327. h = tinymce._replace(/\s*<(p|h[1-6]|blockquote|div|title|style|pre|script|td|li|area)(|[^>]+)>/g, '\n<$1$2>', h);
  4328. h = tinymce._replace(/<\/(p|h[1-6]|blockquote|div|title|style|pre|script|td|li)>\s*/g, '</$1>\n', h);
  4329. h = h.replace(/\n\n/g, '\n');
  4330. }
  4331. }
  4332. h = t._unprotect(h, p);
  4333. // Restore CDATA sections
  4334. h = tinymce._replace(/<!--\[CDATA\[([\s\S]+)\]\]-->/g, '<![CDATA[$1]]>', h);
  4335. // Restore the \u00a0 character if raw mode is enabled
  4336. if (s.entity_encoding == 'raw')
  4337. h = tinymce._replace(/<p>&nbsp;<\/p>|<p([^>]+)>&nbsp;<\/p>/g, '<p$1>\u00a0</p>', h);
  4338. // Restore noscript elements
  4339. h = h.replace(/<noscript([^>]+|)>([\s\S]*?)<\/noscript>/g, function(v, attribs, text) {
  4340. return '<noscript' + attribs + '>' + t.dom.decode(text.replace(/<!--|-->/g, '')) + '</noscript>';
  4341. });
  4342. }
  4343. o.content = h;
  4344. },
  4345. _serializeNode : function(n, inner) {
  4346. var t = this, s = t.settings, w = t.writer, hc, el, cn, i, l, a, at, no, v, nn, ru, ar, iv, closed, keep, type, scopeName;
  4347. if (!s.node_filter || s.node_filter(n)) {
  4348. switch (n.nodeType) {
  4349. case 1: // Element
  4350. if (n.hasAttribute ? n.hasAttribute('_mce_bogus') : n.getAttribute('_mce_bogus'))
  4351. return;
  4352. iv = keep = false;
  4353. hc = n.hasChildNodes();
  4354. nn = n.getAttribute('_mce_name') || n.nodeName.toLowerCase();
  4355. // Get internal type
  4356. type = n.getAttribute('_mce_type');
  4357. if (type) {
  4358. if (!t._info.cleanup) {
  4359. iv = true;
  4360. return;
  4361. } else
  4362. keep = 1;
  4363. }
  4364. // Add correct prefix on IE
  4365. if (isIE) {
  4366. scopeName = n.scopeName;
  4367. if (scopeName && scopeName !== 'HTML' && scopeName !== 'html')
  4368. nn = scopeName + ':' + nn;
  4369. }
  4370. // Remove mce prefix on IE needed for the abbr element
  4371. if (nn.indexOf('mce:') === 0)
  4372. nn = nn.substring(4);
  4373. // Check if valid
  4374. if (!keep) {
  4375. if (!t.validElementsRE || !t.validElementsRE.test(nn) || (t.invalidElementsRE && t.invalidElementsRE.test(nn)) || inner) {
  4376. iv = true;
  4377. break;
  4378. }
  4379. }
  4380. if (isIE) {
  4381. // Fix IE content duplication (DOM can have multiple copies of the same node)
  4382. if (s.fix_content_duplication) {
  4383. if (n._mce_serialized == t.key)
  4384. return;
  4385. n._mce_serialized = t.key;
  4386. }
  4387. // IE sometimes adds a / infront of the node name
  4388. if (nn.charAt(0) == '/')
  4389. nn = nn.substring(1);
  4390. } else if (isGecko) {
  4391. // Ignore br elements
  4392. if (n.nodeName === 'BR' && n.getAttribute('type') == '_moz')
  4393. return;
  4394. }
  4395. // Check if valid child
  4396. if (s.validate_children) {
  4397. if (t.elementName && !t.schema.isValid(t.elementName, nn)) {
  4398. iv = true;
  4399. break;
  4400. }
  4401. t.elementName = nn;
  4402. }
  4403. ru = t.findRule(nn);
  4404. // No valid rule for this element could be found then skip it
  4405. if (!ru) {
  4406. iv = true;
  4407. break;
  4408. }
  4409. nn = ru.name || nn;
  4410. closed = s.closed.test(nn);
  4411. // Skip empty nodes or empty node name in IE
  4412. if ((!hc && ru.noEmpty) || (isIE && !nn)) {
  4413. iv = true;
  4414. break;
  4415. }
  4416. // Check required
  4417. if (ru.requiredAttribs) {
  4418. a = ru.requiredAttribs;
  4419. for (i = a.length - 1; i >= 0; i--) {
  4420. if (this.dom.getAttrib(n, a[i]) !== '')
  4421. break;
  4422. }
  4423. // None of the required was there
  4424. if (i == -1) {
  4425. iv = true;
  4426. break;
  4427. }
  4428. }
  4429. w.writeStartElement(nn);
  4430. // Add ordered attributes
  4431. if (ru.attribs) {
  4432. for (i=0, at = ru.attribs, l = at.length; i<l; i++) {
  4433. a = at[i];
  4434. v = t._getAttrib(n, a);
  4435. if (v !== null)
  4436. w.writeAttribute(a.name, v);
  4437. }
  4438. }
  4439. // Add wild attributes
  4440. if (ru.validAttribsRE) {
  4441. at = t.dom.getAttribs(n);
  4442. for (i=at.length-1; i>-1; i--) {
  4443. no = at[i];
  4444. if (no.specified) {
  4445. a = no.nodeName.toLowerCase();
  4446. if (s.invalid_attrs.test(a) || !ru.validAttribsRE.test(a))
  4447. continue;
  4448. ar = t.findAttribRule(ru, a);
  4449. v = t._getAttrib(n, ar, a);
  4450. if (v !== null)
  4451. w.writeAttribute(a, v);
  4452. }
  4453. }
  4454. }
  4455. // Keep type attribute
  4456. if (type && keep)
  4457. w.writeAttribute('_mce_type', type);
  4458. // Write text from script
  4459. if (nn === 'script' && tinymce.trim(n.innerHTML)) {
  4460. w.writeText('// '); // Padd it with a comment so it will parse on older browsers
  4461. w.writeCDATA(n.innerHTML.replace(/<!--|-->|<\[CDATA\[|\]\]>/g, '')); // Remove comments and cdata stuctures
  4462. hc = false;
  4463. break;
  4464. }
  4465. // Padd empty nodes with a &nbsp;
  4466. if (ru.padd) {
  4467. // If it has only one bogus child, padd it anyway workaround for <td><br /></td> bug
  4468. if (hc && (cn = n.firstChild) && cn.nodeType === 1 && n.childNodes.length === 1) {
  4469. if (cn.hasAttribute ? cn.hasAttribute('_mce_bogus') : cn.getAttribute('_mce_bogus'))
  4470. w.writeText('\u00a0');
  4471. } else if (!hc)
  4472. w.writeText('\u00a0'); // No children then padd it
  4473. }
  4474. break;
  4475. case 3: // Text
  4476. // Check if valid child
  4477. if (s.validate_children && t.elementName && !t.schema.isValid(t.elementName, '#text'))
  4478. return;
  4479. return w.writeText(n.nodeValue);
  4480. case 4: // CDATA
  4481. return w.writeCDATA(n.nodeValue);
  4482. case 8: // Comment
  4483. return w.writeComment(n.nodeValue);
  4484. }
  4485. } else if (n.nodeType == 1)
  4486. hc = n.hasChildNodes();
  4487. if (hc && !closed) {
  4488. cn = n.firstChild;
  4489. while (cn) {
  4490. t._serializeNode(cn);
  4491. t.elementName = nn;
  4492. cn = cn.nextSibling;
  4493. }
  4494. }
  4495. // Write element end
  4496. if (!iv) {
  4497. if (!closed)
  4498. w.writeFullEndElement();
  4499. else
  4500. w.writeEndElement();
  4501. }
  4502. },
  4503. _protect : function(o) {
  4504. var t = this;
  4505. o.items = o.items || [];
  4506. function enc(s) {
  4507. return s.replace(/[\r\n\\]/g, function(c) {
  4508. if (c === '\n')
  4509. return '\\n';
  4510. else if (c === '\\')
  4511. return '\\\\';
  4512. return '\\r';
  4513. });
  4514. };
  4515. function dec(s) {
  4516. return s.replace(/\\[\\rn]/g, function(c) {
  4517. if (c === '\\n')
  4518. return '\n';
  4519. else if (c === '\\\\')
  4520. return '\\';
  4521. return '\r';
  4522. });
  4523. };
  4524. each(o.patterns, function(p) {
  4525. o.content = dec(enc(o.content).replace(p.pattern, function(x, a, b, c) {
  4526. b = dec(b);
  4527. if (p.encode)
  4528. b = t._encode(b);
  4529. o.items.push(b);
  4530. return a + '<!--mce:' + (o.items.length - 1) + '-->' + c;
  4531. }));
  4532. });
  4533. return o;
  4534. },
  4535. _unprotect : function(h, o) {
  4536. h = h.replace(/\<!--mce:([0-9]+)--\>/g, function(a, b) {
  4537. return o.items[parseInt(b)];
  4538. });
  4539. o.items = [];
  4540. return h;
  4541. },
  4542. _encode : function(h) {
  4543. var t = this, s = t.settings, l;
  4544. // Entity encode
  4545. if (s.entity_encoding !== 'raw') {
  4546. if (s.entity_encoding.indexOf('named') != -1) {
  4547. t.setEntities(s.entities);
  4548. l = t.entityLookup;
  4549. h = h.replace(/[\u007E-\uFFFF]/g, function(a) {
  4550. var v;
  4551. if (v = l[a])
  4552. a = '&' + v + ';';
  4553. return a;
  4554. });
  4555. }
  4556. if (s.entity_encoding.indexOf('numeric') != -1) {
  4557. h = h.replace(/[\u007E-\uFFFF]/g, function(a) {
  4558. return '&#' + a.charCodeAt(0) + ';';
  4559. });
  4560. }
  4561. }
  4562. return h;
  4563. },
  4564. _setup : function() {
  4565. var t = this, s = this.settings;
  4566. if (t.done)
  4567. return;
  4568. t.done = 1;
  4569. t.setRules(s.valid_elements);
  4570. t.addRules(s.extended_valid_elements);
  4571. if (s.invalid_elements)
  4572. t.invalidElementsRE = new RegExp('^(' + wildcardToRE(s.invalid_elements.replace(/,/g, '|').toLowerCase()) + ')$');
  4573. if (s.attrib_value_filter)
  4574. t.attribValueFilter = s.attribValueFilter;
  4575. },
  4576. _getAttrib : function(n, a, na) {
  4577. var i, v;
  4578. na = na || a.name;
  4579. if (a.forcedVal && (v = a.forcedVal)) {
  4580. if (v === '{$uid}')
  4581. return this.dom.uniqueId();
  4582. return v;
  4583. }
  4584. v = this.dom.getAttrib(n, na);
  4585. switch (na) {
  4586. case 'rowspan':
  4587. case 'colspan':
  4588. // Whats the point? Remove usless attribute value
  4589. if (v == '1')
  4590. v = '';
  4591. break;
  4592. }
  4593. if (this.attribValueFilter)
  4594. v = this.attribValueFilter(na, v, n);
  4595. if (a.validVals) {
  4596. for (i = a.validVals.length - 1; i >= 0; i--) {
  4597. if (v == a.validVals[i])
  4598. break;
  4599. }
  4600. if (i == -1)
  4601. return null;
  4602. }
  4603. if (v === '' && typeof(a.defaultVal) != 'undefined') {
  4604. v = a.defaultVal;
  4605. if (v === '{$uid}')
  4606. return this.dom.uniqueId();
  4607. return v;
  4608. } else {
  4609. // Remove internal mceItemXX classes when content is extracted from editor
  4610. if (na == 'class' && this.processObj.get)
  4611. v = v.replace(/\s?mceItem\w+\s?/g, '');
  4612. }
  4613. if (v === '')
  4614. return null;
  4615. return v;
  4616. }
  4617. });
  4618. })(tinymce);
  4619. (function(tinymce) {
  4620. tinymce.dom.ScriptLoader = function(settings) {
  4621. var QUEUED = 0,
  4622. LOADING = 1,
  4623. LOADED = 2,
  4624. states = {},
  4625. queue = [],
  4626. scriptLoadedCallbacks = {},
  4627. queueLoadedCallbacks = [],
  4628. loading = 0,
  4629. undefined;
  4630. function loadScript(url, callback) {
  4631. var t = this, dom = tinymce.DOM, elm, uri, loc, id;
  4632. // Execute callback when script is loaded
  4633. function done() {
  4634. dom.remove(id);
  4635. if (elm)
  4636. elm.onreadystatechange = elm.onload = elm = null;
  4637. callback();
  4638. };
  4639. id = dom.uniqueId();
  4640. if (tinymce.isIE6) {
  4641. uri = new tinymce.util.URI(url);
  4642. loc = location;
  4643. // If script is from same domain and we
  4644. // use IE 6 then use XHR since it's more reliable
  4645. if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol) {
  4646. tinymce.util.XHR.send({
  4647. url : tinymce._addVer(uri.getURI()),
  4648. success : function(content) {
  4649. // Create new temp script element
  4650. var script = dom.create('script', {
  4651. type : 'text/javascript'
  4652. });
  4653. // Evaluate script in global scope
  4654. script.text = content;
  4655. document.getElementsByTagName('head')[0].appendChild(script);
  4656. dom.remove(script);
  4657. done();
  4658. }
  4659. });
  4660. return;
  4661. }
  4662. }
  4663. // Create new script element
  4664. elm = dom.create('script', {
  4665. id : id,
  4666. type : 'text/javascript',
  4667. src : tinymce._addVer(url)
  4668. });
  4669. // Add onload listener for non IE browsers since IE9
  4670. // fires onload event before the script is parsed and executed
  4671. if (!tinymce.isIE)
  4672. elm.onload = done;
  4673. elm.onreadystatechange = function() {
  4674. var state = elm.readyState;
  4675. // Loaded state is passed on IE 6 however there
  4676. // are known issues with this method but we can't use
  4677. // XHR in a cross domain loading
  4678. if (state == 'complete' || state == 'loaded')
  4679. done();
  4680. };
  4681. // Most browsers support this feature so we report errors
  4682. // for those at least to help users track their missing plugins etc
  4683. // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option
  4684. /*elm.onerror = function() {
  4685. alert('Failed to load: ' + url);
  4686. };*/
  4687. // Add script to document
  4688. (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
  4689. };
  4690. this.isDone = function(url) {
  4691. return states[url] == LOADED;
  4692. };
  4693. this.markDone = function(url) {
  4694. states[url] = LOADED;
  4695. };
  4696. this.add = this.load = function(url, callback, scope) {
  4697. var item, state = states[url];
  4698. // Add url to load queue
  4699. if (state == undefined) {
  4700. queue.push(url);
  4701. states[url] = QUEUED;
  4702. }
  4703. if (callback) {
  4704. // Store away callback for later execution
  4705. if (!scriptLoadedCallbacks[url])
  4706. scriptLoadedCallbacks[url] = [];
  4707. scriptLoadedCallbacks[url].push({
  4708. func : callback,
  4709. scope : scope || this
  4710. });
  4711. }
  4712. };
  4713. this.loadQueue = function(callback, scope) {
  4714. this.loadScripts(queue, callback, scope);
  4715. };
  4716. this.loadScripts = function(scripts, callback, scope) {
  4717. var loadScripts;
  4718. function execScriptLoadedCallbacks(url) {
  4719. // Execute URL callback functions
  4720. tinymce.each(scriptLoadedCallbacks[url], function(callback) {
  4721. callback.func.call(callback.scope);
  4722. });
  4723. scriptLoadedCallbacks[url] = undefined;
  4724. };
  4725. queueLoadedCallbacks.push({
  4726. func : callback,
  4727. scope : scope || this
  4728. });
  4729. loadScripts = function() {
  4730. var loadingScripts = tinymce.grep(scripts);
  4731. // Current scripts has been handled
  4732. scripts.length = 0;
  4733. // Load scripts that needs to be loaded
  4734. tinymce.each(loadingScripts, function(url) {
  4735. // Script is already loaded then execute script callbacks directly
  4736. if (states[url] == LOADED) {
  4737. execScriptLoadedCallbacks(url);
  4738. return;
  4739. }
  4740. // Is script not loading then start loading it
  4741. if (states[url] != LOADING) {
  4742. states[url] = LOADING;
  4743. loading++;
  4744. loadScript(url, function() {
  4745. states[url] = LOADED;
  4746. loading--;
  4747. execScriptLoadedCallbacks(url);
  4748. // Load more scripts if they where added by the recently loaded script
  4749. loadScripts();
  4750. });
  4751. }
  4752. });
  4753. // No scripts are currently loading then execute all pending queue loaded callbacks
  4754. if (!loading) {
  4755. tinymce.each(queueLoadedCallbacks, function(callback) {
  4756. callback.func.call(callback.scope);
  4757. });
  4758. queueLoadedCallbacks.length = 0;
  4759. }
  4760. };
  4761. loadScripts();
  4762. };
  4763. };
  4764. // Global script loader
  4765. tinymce.ScriptLoader = new tinymce.dom.ScriptLoader();
  4766. })(tinymce);
  4767. tinymce.dom.TreeWalker = function(start_node, root_node) {
  4768. var node = start_node;
  4769. function findSibling(node, start_name, sibling_name, shallow) {
  4770. var sibling, parent;
  4771. if (node) {
  4772. // Walk into nodes if it has a start
  4773. if (!shallow && node[start_name])
  4774. return node[start_name];
  4775. // Return the sibling if it has one
  4776. if (node != root_node) {
  4777. sibling = node[sibling_name];
  4778. if (sibling)
  4779. return sibling;
  4780. // Walk up the parents to look for siblings
  4781. for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
  4782. sibling = parent[sibling_name];
  4783. if (sibling)
  4784. return sibling;
  4785. }
  4786. }
  4787. }
  4788. };
  4789. this.current = function() {
  4790. return node;
  4791. };
  4792. this.next = function(shallow) {
  4793. return (node = findSibling(node, 'firstChild', 'nextSibling', shallow));
  4794. };
  4795. this.prev = function(shallow) {
  4796. return (node = findSibling(node, 'lastChild', 'lastSibling', shallow));
  4797. };
  4798. };
  4799. (function() {
  4800. var transitional = {};
  4801. function unpack(lookup, data) {
  4802. var key;
  4803. function replace(value) {
  4804. return value.replace(/[A-Z]+/g, function(key) {
  4805. return replace(lookup[key]);
  4806. });
  4807. };
  4808. // Unpack lookup
  4809. for (key in lookup) {
  4810. if (lookup.hasOwnProperty(key))
  4811. lookup[key] = replace(lookup[key]);
  4812. }
  4813. // Unpack and parse data into object map
  4814. replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]/g, function(str, name, children) {
  4815. var i, map = {};
  4816. children = children.split(/\|/);
  4817. for (i = children.length - 1; i >= 0; i--)
  4818. map[children[i]] = 1;
  4819. transitional[name] = map;
  4820. });
  4821. };
  4822. // This is the XHTML 1.0 transitional elements with it's children packed to reduce it's size
  4823. // we will later include the attributes here and use it as a default for valid elements but it
  4824. // requires us to rewrite the serializer engine
  4825. unpack({
  4826. Z : '#|H|K|N|O|P',
  4827. Y : '#|X|form|R|Q',
  4828. X : 'p|T|div|U|W|isindex|fieldset|table',
  4829. W : 'pre|hr|blockquote|address|center|noframes',
  4830. U : 'ul|ol|dl|menu|dir',
  4831. ZC : '#|p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
  4832. T : 'h1|h2|h3|h4|h5|h6',
  4833. ZB : '#|X|S|Q',
  4834. S : 'R|P',
  4835. ZA : '#|a|G|J|M|O|P',
  4836. R : '#|a|H|K|N|O',
  4837. Q : 'noscript|P',
  4838. P : 'ins|del|script',
  4839. O : 'input|select|textarea|label|button',
  4840. N : 'M|L',
  4841. M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
  4842. L : 'sub|sup',
  4843. K : 'J|I',
  4844. J : 'tt|i|b|u|s|strike',
  4845. I : 'big|small|font|basefont',
  4846. H : 'G|F',
  4847. G : 'br|span|bdo',
  4848. F : 'object|applet|img|map|iframe'
  4849. }, 'script[]' +
  4850. 'style[]' +
  4851. 'object[#|param|X|form|a|H|K|N|O|Q]' +
  4852. 'param[]' +
  4853. 'p[S]' +
  4854. 'a[Z]' +
  4855. 'br[]' +
  4856. 'span[S]' +
  4857. 'bdo[S]' +
  4858. 'applet[#|param|X|form|a|H|K|N|O|Q]' +
  4859. 'h1[S]' +
  4860. 'img[]' +
  4861. 'map[X|form|Q|area]' +
  4862. 'h2[S]' +
  4863. 'iframe[#|X|form|a|H|K|N|O|Q]' +
  4864. 'h3[S]' +
  4865. 'tt[S]' +
  4866. 'i[S]' +
  4867. 'b[S]' +
  4868. 'u[S]' +
  4869. 's[S]' +
  4870. 'strike[S]' +
  4871. 'big[S]' +
  4872. 'small[S]' +
  4873. 'font[S]' +
  4874. 'basefont[]' +
  4875. 'em[S]' +
  4876. 'strong[S]' +
  4877. 'dfn[S]' +
  4878. 'code[S]' +
  4879. 'q[S]' +
  4880. 'samp[S]' +
  4881. 'kbd[S]' +
  4882. 'var[S]' +
  4883. 'cite[S]' +
  4884. 'abbr[S]' +
  4885. 'acronym[S]' +
  4886. 'sub[S]' +
  4887. 'sup[S]' +
  4888. 'input[]' +
  4889. 'select[optgroup|option]' +
  4890. 'optgroup[option]' +
  4891. 'option[]' +
  4892. 'textarea[]' +
  4893. 'label[S]' +
  4894. 'button[#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
  4895. 'h4[S]' +
  4896. 'ins[#|X|form|a|H|K|N|O|Q]' +
  4897. 'h5[S]' +
  4898. 'del[#|X|form|a|H|K|N|O|Q]' +
  4899. 'h6[S]' +
  4900. 'div[#|X|form|a|H|K|N|O|Q]' +
  4901. 'ul[li]' +
  4902. 'li[#|X|form|a|H|K|N|O|Q]' +
  4903. 'ol[li]' +
  4904. 'dl[dt|dd]' +
  4905. 'dt[S]' +
  4906. 'dd[#|X|form|a|H|K|N|O|Q]' +
  4907. 'menu[li]' +
  4908. 'dir[li]' +
  4909. 'pre[ZA]' +
  4910. 'hr[]' +
  4911. 'blockquote[#|X|form|a|H|K|N|O|Q]' +
  4912. 'address[S|p]' +
  4913. 'center[#|X|form|a|H|K|N|O|Q]' +
  4914. 'noframes[#|X|form|a|H|K|N|O|Q]' +
  4915. 'isindex[]' +
  4916. 'fieldset[#|legend|X|form|a|H|K|N|O|Q]' +
  4917. 'legend[S]' +
  4918. 'table[caption|col|colgroup|thead|tfoot|tbody|tr]' +
  4919. 'caption[S]' +
  4920. 'col[]' +
  4921. 'colgroup[col]' +
  4922. 'thead[tr]' +
  4923. 'tr[th|td]' +
  4924. 'th[#|X|form|a|H|K|N|O|Q]' +
  4925. 'form[#|X|a|H|K|N|O|Q]' +
  4926. 'noscript[#|X|form|a|H|K|N|O|Q]' +
  4927. 'td[#|X|form|a|H|K|N|O|Q]' +
  4928. 'tfoot[tr]' +
  4929. 'tbody[tr]' +
  4930. 'area[]' +
  4931. 'base[]' +
  4932. 'body[#|X|form|a|H|K|N|O|Q]'
  4933. );
  4934. tinymce.dom.Schema = function() {
  4935. var t = this, elements = transitional;
  4936. t.isValid = function(name, child_name) {
  4937. var element = elements[name];
  4938. return !!(element && (!child_name || element[child_name]));
  4939. };
  4940. };
  4941. })();
  4942. (function(tinymce) {
  4943. tinymce.dom.RangeUtils = function(dom) {
  4944. var INVISIBLE_CHAR = '\uFEFF';
  4945. this.walk = function(rng, callback) {
  4946. var startContainer = rng.startContainer,
  4947. startOffset = rng.startOffset,
  4948. endContainer = rng.endContainer,
  4949. endOffset = rng.endOffset,
  4950. ancestor, startPoint,
  4951. endPoint, node, parent, siblings, nodes;
  4952. // Handle table cell selection the table plugin enables
  4953. // you to fake select table cells and perform formatting actions on them
  4954. nodes = dom.select('td.mceSelected,th.mceSelected');
  4955. if (nodes.length > 0) {
  4956. tinymce.each(nodes, function(node) {
  4957. callback([node]);
  4958. });
  4959. return;
  4960. }
  4961. function collectSiblings(node, name, end_node) {
  4962. var siblings = [];
  4963. for (; node && node != end_node; node = node[name])
  4964. siblings.push(node);
  4965. return siblings;
  4966. };
  4967. function findEndPoint(node, root) {
  4968. do {
  4969. if (node.parentNode == root)
  4970. return node;
  4971. node = node.parentNode;
  4972. } while(node);
  4973. };
  4974. function walkBoundary(start_node, end_node, next) {
  4975. var siblingName = next ? 'nextSibling' : 'previousSibling';
  4976. for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) {
  4977. parent = node.parentNode;
  4978. siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName);
  4979. if (siblings.length) {
  4980. if (!next)
  4981. siblings.reverse();
  4982. callback(siblings);
  4983. }
  4984. }
  4985. };
  4986. // If index based start position then resolve it
  4987. if (startContainer.nodeType == 1 && startContainer.hasChildNodes())
  4988. startContainer = startContainer.childNodes[startOffset];
  4989. // If index based end position then resolve it
  4990. if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
  4991. endContainer = endContainer.childNodes[Math.min(startOffset == endOffset ? endOffset : endOffset - 1, endContainer.childNodes.length - 1)];
  4992. // Find common ancestor and end points
  4993. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  4994. // Same container
  4995. if (startContainer == endContainer)
  4996. return callback([startContainer]);
  4997. // Process left side
  4998. for (node = startContainer; node; node = node.parentNode) {
  4999. if (node == endContainer)
  5000. return walkBoundary(startContainer, ancestor, true);
  5001. if (node == ancestor)
  5002. break;
  5003. }
  5004. // Process right side
  5005. for (node = endContainer; node; node = node.parentNode) {
  5006. if (node == startContainer)
  5007. return walkBoundary(endContainer, ancestor);
  5008. if (node == ancestor)
  5009. break;
  5010. }
  5011. // Find start/end point
  5012. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  5013. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  5014. // Walk left leaf
  5015. walkBoundary(startContainer, startPoint, true);
  5016. // Walk the middle from start to end point
  5017. siblings = collectSiblings(
  5018. startPoint == startContainer ? startPoint : startPoint.nextSibling,
  5019. 'nextSibling',
  5020. endPoint == endContainer ? endPoint.nextSibling : endPoint
  5021. );
  5022. if (siblings.length)
  5023. callback(siblings);
  5024. // Walk right leaf
  5025. walkBoundary(endContainer, endPoint);
  5026. };
  5027. /* this.split = function(rng) {
  5028. var startContainer = rng.startContainer,
  5029. startOffset = rng.startOffset,
  5030. endContainer = rng.endContainer,
  5031. endOffset = rng.endOffset;
  5032. function splitText(node, offset) {
  5033. if (offset == node.nodeValue.length)
  5034. node.appendData(INVISIBLE_CHAR);
  5035. node = node.splitText(offset);
  5036. if (node.nodeValue === INVISIBLE_CHAR)
  5037. node.nodeValue = '';
  5038. return node;
  5039. };
  5040. // Handle single text node
  5041. if (startContainer == endContainer) {
  5042. if (startContainer.nodeType == 3) {
  5043. if (startOffset != 0)
  5044. startContainer = endContainer = splitText(startContainer, startOffset);
  5045. if (endOffset - startOffset != startContainer.nodeValue.length)
  5046. splitText(startContainer, endOffset - startOffset);
  5047. }
  5048. } else {
  5049. // Split startContainer text node if needed
  5050. if (startContainer.nodeType == 3 && startOffset != 0) {
  5051. startContainer = splitText(startContainer, startOffset);
  5052. startOffset = 0;
  5053. }
  5054. // Split endContainer text node if needed
  5055. if (endContainer.nodeType == 3 && endOffset != endContainer.nodeValue.length) {
  5056. endContainer = splitText(endContainer, endOffset).previousSibling;
  5057. endOffset = endContainer.nodeValue.length;
  5058. }
  5059. }
  5060. return {
  5061. startContainer : startContainer,
  5062. startOffset : startOffset,
  5063. endContainer : endContainer,
  5064. endOffset : endOffset
  5065. };
  5066. };
  5067. */
  5068. };
  5069. tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) {
  5070. if (rng1 && rng2) {
  5071. // Compare native IE ranges
  5072. if (rng1.item || rng1.duplicate) {
  5073. // Both are control ranges and the selected element matches
  5074. if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0))
  5075. return true;
  5076. // Both are text ranges and the range matches
  5077. if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1))
  5078. return true;
  5079. } else {
  5080. // Compare w3c ranges
  5081. return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset;
  5082. }
  5083. }
  5084. return false;
  5085. };
  5086. })(tinymce);
  5087. (function(tinymce) {
  5088. // Shorten class names
  5089. var DOM = tinymce.DOM, is = tinymce.is;
  5090. tinymce.create('tinymce.ui.Control', {
  5091. Control : function(id, s) {
  5092. this.id = id;
  5093. this.settings = s = s || {};
  5094. this.rendered = false;
  5095. this.onRender = new tinymce.util.Dispatcher(this);
  5096. this.classPrefix = '';
  5097. this.scope = s.scope || this;
  5098. this.disabled = 0;
  5099. this.active = 0;
  5100. },
  5101. setDisabled : function(s) {
  5102. var e;
  5103. if (s != this.disabled) {
  5104. e = DOM.get(this.id);
  5105. // Add accessibility title for unavailable actions
  5106. if (e && this.settings.unavailable_prefix) {
  5107. if (s) {
  5108. this.prevTitle = e.title;
  5109. e.title = this.settings.unavailable_prefix + ": " + e.title;
  5110. } else
  5111. e.title = this.prevTitle;
  5112. }
  5113. this.setState('Disabled', s);
  5114. this.setState('Enabled', !s);
  5115. this.disabled = s;
  5116. }
  5117. },
  5118. isDisabled : function() {
  5119. return this.disabled;
  5120. },
  5121. setActive : function(s) {
  5122. if (s != this.active) {
  5123. this.setState('Active', s);
  5124. this.active = s;
  5125. }
  5126. },
  5127. isActive : function() {
  5128. return this.active;
  5129. },
  5130. setState : function(c, s) {
  5131. var n = DOM.get(this.id);
  5132. c = this.classPrefix + c;
  5133. if (s)
  5134. DOM.addClass(n, c);
  5135. else
  5136. DOM.removeClass(n, c);
  5137. },
  5138. isRendered : function() {
  5139. return this.rendered;
  5140. },
  5141. renderHTML : function() {
  5142. },
  5143. renderTo : function(n) {
  5144. DOM.setHTML(n, this.renderHTML());
  5145. },
  5146. postRender : function() {
  5147. var t = this, b;
  5148. // Set pending states
  5149. if (is(t.disabled)) {
  5150. b = t.disabled;
  5151. t.disabled = -1;
  5152. t.setDisabled(b);
  5153. }
  5154. if (is(t.active)) {
  5155. b = t.active;
  5156. t.active = -1;
  5157. t.setActive(b);
  5158. }
  5159. },
  5160. remove : function() {
  5161. DOM.remove(this.id);
  5162. this.destroy();
  5163. },
  5164. destroy : function() {
  5165. tinymce.dom.Event.clear(this.id);
  5166. }
  5167. });
  5168. })(tinymce);
  5169. tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
  5170. Container : function(id, s) {
  5171. this.parent(id, s);
  5172. this.controls = [];
  5173. this.lookup = {};
  5174. },
  5175. add : function(c) {
  5176. this.lookup[c.id] = c;
  5177. this.controls.push(c);
  5178. return c;
  5179. },
  5180. get : function(n) {
  5181. return this.lookup[n];
  5182. }
  5183. });
  5184. tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
  5185. Separator : function(id, s) {
  5186. this.parent(id, s);
  5187. this.classPrefix = 'mceSeparator';
  5188. },
  5189. renderHTML : function() {
  5190. return tinymce.DOM.createHTML('span', {'class' : this.classPrefix});
  5191. }
  5192. });
  5193. (function(tinymce) {
  5194. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  5195. tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', {
  5196. MenuItem : function(id, s) {
  5197. this.parent(id, s);
  5198. this.classPrefix = 'mceMenuItem';
  5199. },
  5200. setSelected : function(s) {
  5201. this.setState('Selected', s);
  5202. this.selected = s;
  5203. },
  5204. isSelected : function() {
  5205. return this.selected;
  5206. },
  5207. postRender : function() {
  5208. var t = this;
  5209. t.parent();
  5210. // Set pending state
  5211. if (is(t.selected))
  5212. t.setSelected(t.selected);
  5213. }
  5214. });
  5215. })(tinymce);
  5216. (function(tinymce) {
  5217. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  5218. tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
  5219. Menu : function(id, s) {
  5220. var t = this;
  5221. t.parent(id, s);
  5222. t.items = {};
  5223. t.collapsed = false;
  5224. t.menuCount = 0;
  5225. t.onAddItem = new tinymce.util.Dispatcher(this);
  5226. },
  5227. expand : function(d) {
  5228. var t = this;
  5229. if (d) {
  5230. walk(t, function(o) {
  5231. if (o.expand)
  5232. o.expand();
  5233. }, 'items', t);
  5234. }
  5235. t.collapsed = false;
  5236. },
  5237. collapse : function(d) {
  5238. var t = this;
  5239. if (d) {
  5240. walk(t, function(o) {
  5241. if (o.collapse)
  5242. o.collapse();
  5243. }, 'items', t);
  5244. }
  5245. t.collapsed = true;
  5246. },
  5247. isCollapsed : function() {
  5248. return this.collapsed;
  5249. },
  5250. add : function(o) {
  5251. if (!o.settings)
  5252. o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
  5253. this.onAddItem.dispatch(this, o);
  5254. return this.items[o.id] = o;
  5255. },
  5256. addSeparator : function() {
  5257. return this.add({separator : true});
  5258. },
  5259. addMenu : function(o) {
  5260. if (!o.collapse)
  5261. o = this.createMenu(o);
  5262. this.menuCount++;
  5263. return this.add(o);
  5264. },
  5265. hasMenus : function() {
  5266. return this.menuCount !== 0;
  5267. },
  5268. remove : function(o) {
  5269. delete this.items[o.id];
  5270. },
  5271. removeAll : function() {
  5272. var t = this;
  5273. walk(t, function(o) {
  5274. if (o.removeAll)
  5275. o.removeAll();
  5276. else
  5277. o.remove();
  5278. o.destroy();
  5279. }, 'items', t);
  5280. t.items = {};
  5281. },
  5282. createMenu : function(o) {
  5283. var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
  5284. m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);
  5285. return m;
  5286. }
  5287. });
  5288. })(tinymce);
  5289. (function(tinymce) {
  5290. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element;
  5291. tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', {
  5292. DropMenu : function(id, s) {
  5293. s = s || {};
  5294. s.container = s.container || DOM.doc.body;
  5295. s.offset_x = s.offset_x || 0;
  5296. s.offset_y = s.offset_y || 0;
  5297. s.vp_offset_x = s.vp_offset_x || 0;
  5298. s.vp_offset_y = s.vp_offset_y || 0;
  5299. if (is(s.icons) && !s.icons)
  5300. s['class'] += ' mceNoIcons';
  5301. this.parent(id, s);
  5302. this.onShowMenu = new tinymce.util.Dispatcher(this);
  5303. this.onHideMenu = new tinymce.util.Dispatcher(this);
  5304. this.classPrefix = 'mceMenu';
  5305. },
  5306. createMenu : function(s) {
  5307. var t = this, cs = t.settings, m;
  5308. s.container = s.container || cs.container;
  5309. s.parent = t;
  5310. s.constrain = s.constrain || cs.constrain;
  5311. s['class'] = s['class'] || cs['class'];
  5312. s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
  5313. s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
  5314. m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
  5315. m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
  5316. return m;
  5317. },
  5318. update : function() {
  5319. var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
  5320. tw = s.max_width ? Math.min(tb.clientWidth, s.max_width) : tb.clientWidth;
  5321. th = s.max_height ? Math.min(tb.clientHeight, s.max_height) : tb.clientHeight;
  5322. if (!DOM.boxModel)
  5323. t.element.setStyles({width : tw + 2, height : th + 2});
  5324. else
  5325. t.element.setStyles({width : tw, height : th});
  5326. if (s.max_width)
  5327. DOM.setStyle(co, 'width', tw);
  5328. if (s.max_height) {
  5329. DOM.setStyle(co, 'height', th);
  5330. if (tb.clientHeight < s.max_height)
  5331. DOM.setStyle(co, 'overflow', 'hidden');
  5332. }
  5333. },
  5334. showMenu : function(x, y, px) {
  5335. var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix;
  5336. t.collapse(1);
  5337. if (t.isMenuVisible)
  5338. return;
  5339. if (!t.rendered) {
  5340. co = DOM.add(t.settings.container, t.renderNode());
  5341. each(t.items, function(o) {
  5342. o.postRender();
  5343. });
  5344. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  5345. } else
  5346. co = DOM.get('menu_' + t.id);
  5347. // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug
  5348. if (!tinymce.isOpera)
  5349. DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF});
  5350. DOM.show(co);
  5351. t.update();
  5352. x += s.offset_x || 0;
  5353. y += s.offset_y || 0;
  5354. vp.w -= 4;
  5355. vp.h -= 4;
  5356. // Move inside viewport if not submenu
  5357. if (s.constrain) {
  5358. w = co.clientWidth - ot;
  5359. h = co.clientHeight - ot;
  5360. mx = vp.x + vp.w;
  5361. my = vp.y + vp.h;
  5362. if ((x + s.vp_offset_x + w) > mx)
  5363. x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w);
  5364. if ((y + s.vp_offset_y + h) > my)
  5365. y = Math.max(0, (my - s.vp_offset_y) - h);
  5366. }
  5367. DOM.setStyles(co, {left : x , top : y});
  5368. t.element.update();
  5369. t.isMenuVisible = 1;
  5370. t.mouseClickFunc = Event.add(co, 'click', function(e) {
  5371. var m;
  5372. e = e.target;
  5373. if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) {
  5374. m = t.items[e.id];
  5375. if (m.isDisabled())
  5376. return;
  5377. dm = t;
  5378. while (dm) {
  5379. if (dm.hideMenu)
  5380. dm.hideMenu();
  5381. dm = dm.settings.parent;
  5382. }
  5383. if (m.settings.onclick)
  5384. m.settings.onclick(e);
  5385. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  5386. }
  5387. });
  5388. if (t.hasMenus()) {
  5389. t.mouseOverFunc = Event.add(co, 'mouseover', function(e) {
  5390. var m, r, mi;
  5391. e = e.target;
  5392. if (e && (e = DOM.getParent(e, 'tr'))) {
  5393. m = t.items[e.id];
  5394. if (t.lastMenu)
  5395. t.lastMenu.collapse(1);
  5396. if (m.isDisabled())
  5397. return;
  5398. if (e && DOM.hasClass(e, cp + 'ItemSub')) {
  5399. //p = DOM.getPos(s.container);
  5400. r = DOM.getRect(e);
  5401. m.showMenu((r.x + r.w - ot), r.y - ot, r.x);
  5402. t.lastMenu = m;
  5403. DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
  5404. }
  5405. }
  5406. });
  5407. }
  5408. t.onShowMenu.dispatch(t);
  5409. if (s.keyboard_focus) {
  5410. Event.add(co, 'keydown', t._keyHandler, t);
  5411. DOM.select('a', 'menu_' + t.id)[0].focus(); // Select first link
  5412. t._focusIdx = 0;
  5413. }
  5414. },
  5415. hideMenu : function(c) {
  5416. var t = this, co = DOM.get('menu_' + t.id), e;
  5417. if (!t.isMenuVisible)
  5418. return;
  5419. Event.remove(co, 'mouseover', t.mouseOverFunc);
  5420. Event.remove(co, 'click', t.mouseClickFunc);
  5421. Event.remove(co, 'keydown', t._keyHandler);
  5422. DOM.hide(co);
  5423. t.isMenuVisible = 0;
  5424. if (!c)
  5425. t.collapse(1);
  5426. if (t.element)
  5427. t.element.hide();
  5428. if (e = DOM.get(t.id))
  5429. DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive');
  5430. t.onHideMenu.dispatch(t);
  5431. },
  5432. add : function(o) {
  5433. var t = this, co;
  5434. o = t.parent(o);
  5435. if (t.isRendered && (co = DOM.get('menu_' + t.id)))
  5436. t._add(DOM.select('tbody', co)[0], o);
  5437. return o;
  5438. },
  5439. collapse : function(d) {
  5440. this.parent(d);
  5441. this.hideMenu(1);
  5442. },
  5443. remove : function(o) {
  5444. DOM.remove(o.id);
  5445. this.destroy();
  5446. return this.parent(o);
  5447. },
  5448. destroy : function() {
  5449. var t = this, co = DOM.get('menu_' + t.id);
  5450. Event.remove(co, 'mouseover', t.mouseOverFunc);
  5451. Event.remove(co, 'click', t.mouseClickFunc);
  5452. if (t.element)
  5453. t.element.remove();
  5454. DOM.remove(co);
  5455. },
  5456. renderNode : function() {
  5457. var t = this, s = t.settings, n, tb, co, w;
  5458. w = DOM.create('div', {id : 'menu_' + t.id, 'class' : s['class'], 'style' : 'position:absolute;left:0;top:0;z-index:200000'});
  5459. co = DOM.add(w, 'div', {id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
  5460. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  5461. if (s.menu_line)
  5462. DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
  5463. // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
  5464. n = DOM.add(co, 'table', {id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
  5465. tb = DOM.add(n, 'tbody');
  5466. each(t.items, function(o) {
  5467. t._add(tb, o);
  5468. });
  5469. t.rendered = true;
  5470. return w;
  5471. },
  5472. // Internal functions
  5473. _keyHandler : function(e) {
  5474. var t = this, kc = e.keyCode;
  5475. function focus(d) {
  5476. var i = t._focusIdx + d, e = DOM.select('a', 'menu_' + t.id)[i];
  5477. if (e) {
  5478. t._focusIdx = i;
  5479. e.focus();
  5480. }
  5481. };
  5482. switch (kc) {
  5483. case 38:
  5484. focus(-1); // Select first link
  5485. return;
  5486. case 40:
  5487. focus(1);
  5488. return;
  5489. case 13:
  5490. return;
  5491. case 27:
  5492. return this.hideMenu();
  5493. }
  5494. },
  5495. _add : function(tb, o) {
  5496. var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
  5497. if (s.separator) {
  5498. ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'});
  5499. DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'});
  5500. if (n = ro.previousSibling)
  5501. DOM.addClass(n, 'mceLast');
  5502. return;
  5503. }
  5504. n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
  5505. n = it = DOM.add(n, 'td');
  5506. n = a = DOM.add(n, 'a', {href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
  5507. DOM.addClass(it, s['class']);
  5508. // n = DOM.add(n, 'span', {'class' : 'item'});
  5509. ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
  5510. if (s.icon_src)
  5511. DOM.add(ic, 'img', {src : s.icon_src});
  5512. n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title);
  5513. if (o.settings.style)
  5514. DOM.setAttrib(n, 'style', o.settings.style);
  5515. if (tb.childNodes.length == 1)
  5516. DOM.addClass(ro, 'mceFirst');
  5517. if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator'))
  5518. DOM.addClass(ro, 'mceFirst');
  5519. if (o.collapse)
  5520. DOM.addClass(ro, cp + 'ItemSub');
  5521. if (n = ro.previousSibling)
  5522. DOM.removeClass(n, 'mceLast');
  5523. DOM.addClass(ro, 'mceLast');
  5524. }
  5525. });
  5526. })(tinymce);
  5527. (function(tinymce) {
  5528. var DOM = tinymce.DOM;
  5529. tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
  5530. Button : function(id, s) {
  5531. this.parent(id, s);
  5532. this.classPrefix = 'mceButton';
  5533. },
  5534. renderHTML : function() {
  5535. var cp = this.classPrefix, s = this.settings, h, l;
  5536. l = DOM.encode(s.label || '');
  5537. h = '<a id="' + this.id + '" href="javascript:;" class="' + cp + ' ' + cp + 'Enabled ' + s['class'] + (l ? ' ' + cp + 'Labeled' : '') +'" onmousedown="return false;" onclick="return false;" title="' + DOM.encode(s.title) + '">';
  5538. if (s.image)
  5539. h += '<img class="mceIcon" src="' + s.image + '" />' + l + '</a>';
  5540. else
  5541. h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '') + '</a>';
  5542. return h;
  5543. },
  5544. postRender : function() {
  5545. var t = this, s = t.settings;
  5546. tinymce.dom.Event.add(t.id, 'click', function(e) {
  5547. if (!t.isDisabled())
  5548. return s.onclick.call(s.scope, e);
  5549. });
  5550. }
  5551. });
  5552. })(tinymce);
  5553. (function(tinymce) {
  5554. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  5555. tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
  5556. ListBox : function(id, s) {
  5557. var t = this;
  5558. t.parent(id, s);
  5559. t.items = [];
  5560. t.onChange = new Dispatcher(t);
  5561. t.onPostRender = new Dispatcher(t);
  5562. t.onAdd = new Dispatcher(t);
  5563. t.onRenderMenu = new tinymce.util.Dispatcher(this);
  5564. t.classPrefix = 'mceListBox';
  5565. },
  5566. select : function(va) {
  5567. var t = this, fv, f;
  5568. if (va == undefined)
  5569. return t.selectByIndex(-1);
  5570. // Is string or number make function selector
  5571. if (va && va.call)
  5572. f = va;
  5573. else {
  5574. f = function(v) {
  5575. return v == va;
  5576. };
  5577. }
  5578. // Do we need to do something?
  5579. if (va != t.selectedValue) {
  5580. // Find item
  5581. each(t.items, function(o, i) {
  5582. if (f(o.value)) {
  5583. fv = 1;
  5584. t.selectByIndex(i);
  5585. return false;
  5586. }
  5587. });
  5588. if (!fv)
  5589. t.selectByIndex(-1);
  5590. }
  5591. },
  5592. selectByIndex : function(idx) {
  5593. var t = this, e, o;
  5594. if (idx != t.selectedIndex) {
  5595. e = DOM.get(t.id + '_text');
  5596. o = t.items[idx];
  5597. if (o) {
  5598. t.selectedValue = o.value;
  5599. t.selectedIndex = idx;
  5600. DOM.setHTML(e, DOM.encode(o.title));
  5601. DOM.removeClass(e, 'mceTitle');
  5602. } else {
  5603. DOM.setHTML(e, DOM.encode(t.settings.title));
  5604. DOM.addClass(e, 'mceTitle');
  5605. t.selectedValue = t.selectedIndex = null;
  5606. }
  5607. e = 0;
  5608. }
  5609. },
  5610. add : function(n, v, o) {
  5611. var t = this;
  5612. o = o || {};
  5613. o = tinymce.extend(o, {
  5614. title : n,
  5615. value : v
  5616. });
  5617. t.items.push(o);
  5618. t.onAdd.dispatch(t, o);
  5619. },
  5620. getLength : function() {
  5621. return this.items.length;
  5622. },
  5623. renderHTML : function() {
  5624. var h = '', t = this, s = t.settings, cp = t.classPrefix;
  5625. h = '<table id="' + t.id + '" cellpadding="0" cellspacing="0" class="' + cp + ' ' + cp + 'Enabled' + (s['class'] ? (' ' + s['class']) : '') + '"><tbody><tr>';
  5626. h += '<td>' + DOM.createHTML('a', {id : t.id + '_text', href : 'javascript:;', 'class' : 'mceText', onclick : "return false;", onmousedown : 'return false;'}, DOM.encode(t.settings.title)) + '</td>';
  5627. h += '<td>' + DOM.createHTML('a', {id : t.id + '_open', tabindex : -1, href : 'javascript:;', 'class' : 'mceOpen', onclick : "return false;", onmousedown : 'return false;'}, '<span></span>') + '</td>';
  5628. h += '</tr></tbody></table>';
  5629. return h;
  5630. },
  5631. showMenu : function() {
  5632. var t = this, p1, p2, e = DOM.get(this.id), m;
  5633. if (t.isDisabled() || t.items.length == 0)
  5634. return;
  5635. if (t.menu && t.menu.isMenuVisible)
  5636. return t.hideMenu();
  5637. if (!t.isMenuRendered) {
  5638. t.renderMenu();
  5639. t.isMenuRendered = true;
  5640. }
  5641. p1 = DOM.getPos(this.settings.menu_container);
  5642. p2 = DOM.getPos(e);
  5643. m = t.menu;
  5644. m.settings.offset_x = p2.x;
  5645. m.settings.offset_y = p2.y;
  5646. m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus
  5647. // Select in menu
  5648. if (t.oldID)
  5649. m.items[t.oldID].setSelected(0);
  5650. each(t.items, function(o) {
  5651. if (o.value === t.selectedValue) {
  5652. m.items[o.id].setSelected(1);
  5653. t.oldID = o.id;
  5654. }
  5655. });
  5656. m.showMenu(0, e.clientHeight);
  5657. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  5658. DOM.addClass(t.id, t.classPrefix + 'Selected');
  5659. //DOM.get(t.id + '_text').focus();
  5660. },
  5661. hideMenu : function(e) {
  5662. var t = this;
  5663. if (t.menu && t.menu.isMenuVisible) {
  5664. // Prevent double toogles by canceling the mouse click event to the button
  5665. if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
  5666. return;
  5667. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  5668. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  5669. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  5670. t.menu.hideMenu();
  5671. }
  5672. }
  5673. },
  5674. renderMenu : function() {
  5675. var t = this, m;
  5676. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  5677. menu_line : 1,
  5678. 'class' : t.classPrefix + 'Menu mceNoIcons',
  5679. max_width : 150,
  5680. max_height : 150
  5681. });
  5682. m.onHideMenu.add(t.hideMenu, t);
  5683. m.add({
  5684. title : t.settings.title,
  5685. 'class' : 'mceMenuItemTitle',
  5686. onclick : function() {
  5687. if (t.settings.onselect('') !== false)
  5688. t.select(''); // Must be runned after
  5689. }
  5690. });
  5691. each(t.items, function(o) {
  5692. // No value then treat it as a title
  5693. if (o.value === undefined) {
  5694. m.add({
  5695. title : o.title,
  5696. 'class' : 'mceMenuItemTitle',
  5697. onclick : function() {
  5698. if (t.settings.onselect('') !== false)
  5699. t.select(''); // Must be runned after
  5700. }
  5701. });
  5702. } else {
  5703. o.id = DOM.uniqueId();
  5704. o.onclick = function() {
  5705. if (t.settings.onselect(o.value) !== false)
  5706. t.select(o.value); // Must be runned after
  5707. };
  5708. m.add(o);
  5709. }
  5710. });
  5711. t.onRenderMenu.dispatch(t, m);
  5712. t.menu = m;
  5713. },
  5714. postRender : function() {
  5715. var t = this, cp = t.classPrefix;
  5716. Event.add(t.id, 'click', t.showMenu, t);
  5717. Event.add(t.id + '_text', 'focus', function() {
  5718. if (!t._focused) {
  5719. t.keyDownHandler = Event.add(t.id + '_text', 'keydown', function(e) {
  5720. var idx = -1, v, kc = e.keyCode;
  5721. // Find current index
  5722. each(t.items, function(v, i) {
  5723. if (t.selectedValue == v.value)
  5724. idx = i;
  5725. });
  5726. // Move up/down
  5727. if (kc == 38)
  5728. v = t.items[idx - 1];
  5729. else if (kc == 40)
  5730. v = t.items[idx + 1];
  5731. else if (kc == 13) {
  5732. // Fake select on enter
  5733. v = t.selectedValue;
  5734. t.selectedValue = null; // Needs to be null to fake change
  5735. t.settings.onselect(v);
  5736. return Event.cancel(e);
  5737. }
  5738. if (v) {
  5739. t.hideMenu();
  5740. t.select(v.value);
  5741. }
  5742. });
  5743. }
  5744. t._focused = 1;
  5745. });
  5746. Event.add(t.id + '_text', 'blur', function() {Event.remove(t.id + '_text', 'keydown', t.keyDownHandler); t._focused = 0;});
  5747. // Old IE doesn't have hover on all elements
  5748. if (tinymce.isIE6 || !DOM.boxModel) {
  5749. Event.add(t.id, 'mouseover', function() {
  5750. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  5751. DOM.addClass(t.id, cp + 'Hover');
  5752. });
  5753. Event.add(t.id, 'mouseout', function() {
  5754. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  5755. DOM.removeClass(t.id, cp + 'Hover');
  5756. });
  5757. }
  5758. t.onPostRender.dispatch(t, DOM.get(t.id));
  5759. },
  5760. destroy : function() {
  5761. this.parent();
  5762. Event.clear(this.id + '_text');
  5763. Event.clear(this.id + '_open');
  5764. }
  5765. });
  5766. })(tinymce);
  5767. (function(tinymce) {
  5768. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  5769. tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', {
  5770. NativeListBox : function(id, s) {
  5771. this.parent(id, s);
  5772. this.classPrefix = 'mceNativeListBox';
  5773. },
  5774. setDisabled : function(s) {
  5775. DOM.get(this.id).disabled = s;
  5776. },
  5777. isDisabled : function() {
  5778. return DOM.get(this.id).disabled;
  5779. },
  5780. select : function(va) {
  5781. var t = this, fv, f;
  5782. if (va == undefined)
  5783. return t.selectByIndex(-1);
  5784. // Is string or number make function selector
  5785. if (va && va.call)
  5786. f = va;
  5787. else {
  5788. f = function(v) {
  5789. return v == va;
  5790. };
  5791. }
  5792. // Do we need to do something?
  5793. if (va != t.selectedValue) {
  5794. // Find item
  5795. each(t.items, function(o, i) {
  5796. if (f(o.value)) {
  5797. fv = 1;
  5798. t.selectByIndex(i);
  5799. return false;
  5800. }
  5801. });
  5802. if (!fv)
  5803. t.selectByIndex(-1);
  5804. }
  5805. },
  5806. selectByIndex : function(idx) {
  5807. DOM.get(this.id).selectedIndex = idx + 1;
  5808. this.selectedValue = this.items[idx] ? this.items[idx].value : null;
  5809. },
  5810. add : function(n, v, a) {
  5811. var o, t = this;
  5812. a = a || {};
  5813. a.value = v;
  5814. if (t.isRendered())
  5815. DOM.add(DOM.get(this.id), 'option', a, n);
  5816. o = {
  5817. title : n,
  5818. value : v,
  5819. attribs : a
  5820. };
  5821. t.items.push(o);
  5822. t.onAdd.dispatch(t, o);
  5823. },
  5824. getLength : function() {
  5825. return this.items.length;
  5826. },
  5827. renderHTML : function() {
  5828. var h, t = this;
  5829. h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --');
  5830. each(t.items, function(it) {
  5831. h += DOM.createHTML('option', {value : it.value}, it.title);
  5832. });
  5833. h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox'}, h);
  5834. return h;
  5835. },
  5836. postRender : function() {
  5837. var t = this, ch;
  5838. t.rendered = true;
  5839. function onChange(e) {
  5840. var v = t.items[e.target.selectedIndex - 1];
  5841. if (v && (v = v.value)) {
  5842. t.onChange.dispatch(t, v);
  5843. if (t.settings.onselect)
  5844. t.settings.onselect(v);
  5845. }
  5846. };
  5847. Event.add(t.id, 'change', onChange);
  5848. // Accessibility keyhandler
  5849. Event.add(t.id, 'keydown', function(e) {
  5850. var bf;
  5851. Event.remove(t.id, 'change', ch);
  5852. bf = Event.add(t.id, 'blur', function() {
  5853. Event.add(t.id, 'change', onChange);
  5854. Event.remove(t.id, 'blur', bf);
  5855. });
  5856. if (e.keyCode == 13 || e.keyCode == 32) {
  5857. onChange(e);
  5858. return Event.cancel(e);
  5859. }
  5860. });
  5861. t.onPostRender.dispatch(t, DOM.get(t.id));
  5862. }
  5863. });
  5864. })(tinymce);
  5865. (function(tinymce) {
  5866. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  5867. tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
  5868. MenuButton : function(id, s) {
  5869. this.parent(id, s);
  5870. this.onRenderMenu = new tinymce.util.Dispatcher(this);
  5871. s.menu_container = s.menu_container || DOM.doc.body;
  5872. },
  5873. showMenu : function() {
  5874. var t = this, p1, p2, e = DOM.get(t.id), m;
  5875. if (t.isDisabled())
  5876. return;
  5877. if (!t.isMenuRendered) {
  5878. t.renderMenu();
  5879. t.isMenuRendered = true;
  5880. }
  5881. if (t.isMenuVisible)
  5882. return t.hideMenu();
  5883. p1 = DOM.getPos(t.settings.menu_container);
  5884. p2 = DOM.getPos(e);
  5885. m = t.menu;
  5886. m.settings.offset_x = p2.x;
  5887. m.settings.offset_y = p2.y;
  5888. m.settings.vp_offset_x = p2.x;
  5889. m.settings.vp_offset_y = p2.y;
  5890. m.settings.keyboard_focus = t._focused;
  5891. m.showMenu(0, e.clientHeight);
  5892. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  5893. t.setState('Selected', 1);
  5894. t.isMenuVisible = 1;
  5895. },
  5896. renderMenu : function() {
  5897. var t = this, m;
  5898. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  5899. menu_line : 1,
  5900. 'class' : this.classPrefix + 'Menu',
  5901. icons : t.settings.icons
  5902. });
  5903. m.onHideMenu.add(t.hideMenu, t);
  5904. t.onRenderMenu.dispatch(t, m);
  5905. t.menu = m;
  5906. },
  5907. hideMenu : function(e) {
  5908. var t = this;
  5909. // Prevent double toogles by canceling the mouse click event to the button
  5910. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';}))
  5911. return;
  5912. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  5913. t.setState('Selected', 0);
  5914. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  5915. if (t.menu)
  5916. t.menu.hideMenu();
  5917. }
  5918. t.isMenuVisible = 0;
  5919. },
  5920. postRender : function() {
  5921. var t = this, s = t.settings;
  5922. Event.add(t.id, 'click', function() {
  5923. if (!t.isDisabled()) {
  5924. if (s.onclick)
  5925. s.onclick(t.value);
  5926. t.showMenu();
  5927. }
  5928. });
  5929. }
  5930. });
  5931. })(tinymce);
  5932. (function(tinymce) {
  5933. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  5934. tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
  5935. SplitButton : function(id, s) {
  5936. this.parent(id, s);
  5937. this.classPrefix = 'mceSplitButton';
  5938. },
  5939. renderHTML : function() {
  5940. var h, t = this, s = t.settings, h1;
  5941. h = '<tbody><tr>';
  5942. if (s.image)
  5943. h1 = DOM.createHTML('img ', {src : s.image, 'class' : 'mceAction ' + s['class']});
  5944. else
  5945. h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
  5946. h += '<td>' + DOM.createHTML('a', {id : t.id + '_action', href : 'javascript:;', 'class' : 'mceAction ' + s['class'], onclick : "return false;", onmousedown : 'return false;', title : s.title}, h1) + '</td>';
  5947. h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']});
  5948. h += '<td>' + DOM.createHTML('a', {id : t.id + '_open', href : 'javascript:;', 'class' : 'mceOpen ' + s['class'], onclick : "return false;", onmousedown : 'return false;', title : s.title}, h1) + '</td>';
  5949. h += '</tr></tbody>';
  5950. return DOM.createHTML('table', {id : t.id, 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', onmousedown : 'return false;', title : s.title}, h);
  5951. },
  5952. postRender : function() {
  5953. var t = this, s = t.settings;
  5954. if (s.onclick) {
  5955. Event.add(t.id + '_action', 'click', function() {
  5956. if (!t.isDisabled())
  5957. s.onclick(t.value);
  5958. });
  5959. }
  5960. Event.add(t.id + '_open', 'click', t.showMenu, t);
  5961. Event.add(t.id + '_open', 'focus', function() {t._focused = 1;});
  5962. Event.add(t.id + '_open', 'blur', function() {t._focused = 0;});
  5963. // Old IE doesn't have hover on all elements
  5964. if (tinymce.isIE6 || !DOM.boxModel) {
  5965. Event.add(t.id, 'mouseover', function() {
  5966. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  5967. DOM.addClass(t.id, 'mceSplitButtonHover');
  5968. });
  5969. Event.add(t.id, 'mouseout', function() {
  5970. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  5971. DOM.removeClass(t.id, 'mceSplitButtonHover');
  5972. });
  5973. }
  5974. },
  5975. destroy : function() {
  5976. this.parent();
  5977. Event.clear(this.id + '_action');
  5978. Event.clear(this.id + '_open');
  5979. }
  5980. });
  5981. })(tinymce);
  5982. (function(tinymce) {
  5983. var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
  5984. tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
  5985. ColorSplitButton : function(id, s) {
  5986. var t = this;
  5987. t.parent(id, s);
  5988. t.settings = s = tinymce.extend({
  5989. colors : '000000,993300,333300,003300,003366,000080,333399,333333,800000,FF6600,808000,008000,008080,0000FF,666699,808080,FF0000,FF9900,99CC00,339966,33CCCC,3366FF,800080,999999,FF00FF,FFCC00,FFFF00,00FF00,00FFFF,00CCFF,993366,C0C0C0,FF99CC,FFCC99,FFFF99,CCFFCC,CCFFFF,99CCFF,CC99FF,FFFFFF',
  5990. grid_width : 8,
  5991. default_color : '#888888'
  5992. }, t.settings);
  5993. t.onShowMenu = new tinymce.util.Dispatcher(t);
  5994. t.onHideMenu = new tinymce.util.Dispatcher(t);
  5995. t.value = s.default_color;
  5996. },
  5997. showMenu : function() {
  5998. var t = this, r, p, e, p2;
  5999. if (t.isDisabled())
  6000. return;
  6001. if (!t.isMenuRendered) {
  6002. t.renderMenu();
  6003. t.isMenuRendered = true;
  6004. }
  6005. if (t.isMenuVisible)
  6006. return t.hideMenu();
  6007. e = DOM.get(t.id);
  6008. DOM.show(t.id + '_menu');
  6009. DOM.addClass(e, 'mceSplitButtonSelected');
  6010. p2 = DOM.getPos(e);
  6011. DOM.setStyles(t.id + '_menu', {
  6012. left : p2.x,
  6013. top : p2.y + e.clientHeight,
  6014. zIndex : 200000
  6015. });
  6016. e = 0;
  6017. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  6018. t.onShowMenu.dispatch(t);
  6019. if (t._focused) {
  6020. t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) {
  6021. if (e.keyCode == 27)
  6022. t.hideMenu();
  6023. });
  6024. DOM.select('a', t.id + '_menu')[0].focus(); // Select first link
  6025. }
  6026. t.isMenuVisible = 1;
  6027. },
  6028. hideMenu : function(e) {
  6029. var t = this;
  6030. // Prevent double toogles by canceling the mouse click event to the button
  6031. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
  6032. return;
  6033. if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
  6034. DOM.removeClass(t.id, 'mceSplitButtonSelected');
  6035. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  6036. Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
  6037. DOM.hide(t.id + '_menu');
  6038. }
  6039. t.onHideMenu.dispatch(t);
  6040. t.isMenuVisible = 0;
  6041. },
  6042. renderMenu : function() {
  6043. var t = this, m, i = 0, s = t.settings, n, tb, tr, w;
  6044. w = DOM.add(s.menu_container, 'div', {id : t.id + '_menu', 'class' : s['menu_class'] + ' ' + s['class'], style : 'position:absolute;left:0;top:-1000px;'});
  6045. m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
  6046. DOM.add(m, 'span', {'class' : 'mceMenuLine'});
  6047. n = DOM.add(m, 'table', {'class' : 'mceColorSplitMenu'});
  6048. tb = DOM.add(n, 'tbody');
  6049. // Generate color grid
  6050. i = 0;
  6051. each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
  6052. c = c.replace(/^#/, '');
  6053. if (!i--) {
  6054. tr = DOM.add(tb, 'tr');
  6055. i = s.grid_width - 1;
  6056. }
  6057. n = DOM.add(tr, 'td');
  6058. n = DOM.add(n, 'a', {
  6059. href : 'javascript:;',
  6060. style : {
  6061. backgroundColor : '#' + c
  6062. },
  6063. _mce_color : '#' + c
  6064. });
  6065. });
  6066. if (s.more_colors_func) {
  6067. n = DOM.add(tb, 'tr');
  6068. n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'});
  6069. n = DOM.add(n, 'a', {id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title);
  6070. Event.add(n, 'click', function(e) {
  6071. s.more_colors_func.call(s.more_colors_scope || this);
  6072. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  6073. });
  6074. }
  6075. DOM.addClass(m, 'mceColorSplitMenu');
  6076. Event.add(t.id + '_menu', 'click', function(e) {
  6077. var c;
  6078. e = e.target;
  6079. if (e.nodeName == 'A' && (c = e.getAttribute('_mce_color')))
  6080. t.setColor(c);
  6081. return Event.cancel(e); // Prevent IE auto save warning
  6082. });
  6083. return w;
  6084. },
  6085. setColor : function(c) {
  6086. var t = this;
  6087. DOM.setStyle(t.id + '_preview', 'backgroundColor', c);
  6088. t.value = c;
  6089. t.hideMenu();
  6090. t.settings.onselect(c);
  6091. },
  6092. postRender : function() {
  6093. var t = this, id = t.id;
  6094. t.parent();
  6095. DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'});
  6096. DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value);
  6097. },
  6098. destroy : function() {
  6099. this.parent();
  6100. Event.clear(this.id + '_menu');
  6101. Event.clear(this.id + '_more');
  6102. DOM.remove(this.id + '_menu');
  6103. }
  6104. });
  6105. })(tinymce);
  6106. tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
  6107. renderHTML : function() {
  6108. var t = this, h = '', c, co, dom = tinymce.DOM, s = t.settings, i, pr, nx, cl;
  6109. cl = t.controls;
  6110. for (i=0; i<cl.length; i++) {
  6111. // Get current control, prev control, next control and if the control is a list box or not
  6112. co = cl[i];
  6113. pr = cl[i - 1];
  6114. nx = cl[i + 1];
  6115. // Add toolbar start
  6116. if (i === 0) {
  6117. c = 'mceToolbarStart';
  6118. if (co.Button)
  6119. c += ' mceToolbarStartButton';
  6120. else if (co.SplitButton)
  6121. c += ' mceToolbarStartSplitButton';
  6122. else if (co.ListBox)
  6123. c += ' mceToolbarStartListBox';
  6124. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  6125. }
  6126. // Add toolbar end before list box and after the previous button
  6127. // This is to fix the o2k7 editor skins
  6128. if (pr && co.ListBox) {
  6129. if (pr.Button || pr.SplitButton)
  6130. h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '<!-- IE -->'));
  6131. }
  6132. // Render control HTML
  6133. // IE 8 quick fix, needed to propertly generate a hit area for anchors
  6134. if (dom.stdMode)
  6135. h += '<td style="position: relative">' + co.renderHTML() + '</td>';
  6136. else
  6137. h += '<td>' + co.renderHTML() + '</td>';
  6138. // Add toolbar start after list box and before the next button
  6139. // This is to fix the o2k7 editor skins
  6140. if (nx && co.ListBox) {
  6141. if (nx.Button || nx.SplitButton)
  6142. h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '<!-- IE -->'));
  6143. }
  6144. }
  6145. c = 'mceToolbarEnd';
  6146. if (co.Button)
  6147. c += ' mceToolbarEndButton';
  6148. else if (co.SplitButton)
  6149. c += ' mceToolbarEndSplitButton';
  6150. else if (co.ListBox)
  6151. c += ' mceToolbarEndListBox';
  6152. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  6153. return dom.createHTML('table', {id : t.id, 'class' : 'mceToolbar' + (s['class'] ? ' ' + s['class'] : ''), cellpadding : '0', cellspacing : '0', align : t.settings.align || ''}, '<tbody><tr>' + h + '</tr></tbody>');
  6154. }
  6155. });
  6156. (function(tinymce) {
  6157. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
  6158. tinymce.create('tinymce.AddOnManager', {
  6159. AddOnManager : function() {
  6160. var self = this;
  6161. self.items = [];
  6162. self.urls = {};
  6163. self.lookup = {};
  6164. self.onAdd = new Dispatcher(self);
  6165. },
  6166. get : function(n) {
  6167. return this.lookup[n];
  6168. },
  6169. requireLangPack : function(n) {
  6170. var s = tinymce.settings;
  6171. if (s && s.language)
  6172. tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
  6173. },
  6174. add : function(id, o) {
  6175. this.items.push(o);
  6176. this.lookup[id] = o;
  6177. this.onAdd.dispatch(this, id, o);
  6178. return o;
  6179. },
  6180. load : function(n, u, cb, s) {
  6181. var t = this;
  6182. if (t.urls[n])
  6183. return;
  6184. if (u.indexOf('/') != 0 && u.indexOf('://') == -1)
  6185. u = tinymce.baseURL + '/' + u;
  6186. t.urls[n] = u.substring(0, u.lastIndexOf('/'));
  6187. if (!t.lookup[n])
  6188. tinymce.ScriptLoader.add(u, cb, s);
  6189. }
  6190. });
  6191. // Create plugin and theme managers
  6192. tinymce.PluginManager = new tinymce.AddOnManager();
  6193. tinymce.ThemeManager = new tinymce.AddOnManager();
  6194. }(tinymce));
  6195. (function(tinymce) {
  6196. // Shorten names
  6197. var each = tinymce.each, extend = tinymce.extend,
  6198. DOM = tinymce.DOM, Event = tinymce.dom.Event,
  6199. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  6200. explode = tinymce.explode,
  6201. Dispatcher = tinymce.util.Dispatcher, undefined, instanceCounter = 0;
  6202. // Setup some URLs where the editor API is located and where the document is
  6203. tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  6204. if (!/[\/\\]$/.test(tinymce.documentBaseURL))
  6205. tinymce.documentBaseURL += '/';
  6206. tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL);
  6207. tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL);
  6208. // Add before unload listener
  6209. // This was required since IE was leaking memory if you added and removed beforeunload listeners
  6210. // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event
  6211. tinymce.onBeforeUnload = new Dispatcher(tinymce);
  6212. // Must be on window or IE will leak if the editor is placed in frame or iframe
  6213. Event.add(window, 'beforeunload', function(e) {
  6214. tinymce.onBeforeUnload.dispatch(tinymce, e);
  6215. });
  6216. tinymce.onAddEditor = new Dispatcher(tinymce);
  6217. tinymce.onRemoveEditor = new Dispatcher(tinymce);
  6218. tinymce.EditorManager = extend(tinymce, {
  6219. editors : [],
  6220. i18n : {},
  6221. activeEditor : null,
  6222. init : function(s) {
  6223. var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed;
  6224. function execCallback(se, n, s) {
  6225. var f = se[n];
  6226. if (!f)
  6227. return;
  6228. if (tinymce.is(f, 'string')) {
  6229. s = f.replace(/\.\w+$/, '');
  6230. s = s ? tinymce.resolve(s) : 0;
  6231. f = tinymce.resolve(f);
  6232. }
  6233. return f.apply(s || this, Array.prototype.slice.call(arguments, 2));
  6234. };
  6235. s = extend({
  6236. theme : "simple",
  6237. language : "en"
  6238. }, s);
  6239. t.settings = s;
  6240. // Legacy call
  6241. Event.add(document, 'init', function() {
  6242. var l, co;
  6243. execCallback(s, 'onpageload');
  6244. switch (s.mode) {
  6245. case "exact":
  6246. l = s.elements || '';
  6247. if(l.length > 0) {
  6248. each(explode(l), function(v) {
  6249. if (DOM.get(v)) {
  6250. ed = new tinymce.Editor(v, s);
  6251. el.push(ed);
  6252. ed.render(1);
  6253. } else {
  6254. each(document.forms, function(f) {
  6255. each(f.elements, function(e) {
  6256. if (e.name === v) {
  6257. v = 'mce_editor_' + instanceCounter++;
  6258. DOM.setAttrib(e, 'id', v);
  6259. ed = new tinymce.Editor(v, s);
  6260. el.push(ed);
  6261. ed.render(1);
  6262. }
  6263. });
  6264. });
  6265. }
  6266. });
  6267. }
  6268. break;
  6269. case "textareas":
  6270. case "specific_textareas":
  6271. function hasClass(n, c) {
  6272. return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c);
  6273. };
  6274. each(DOM.select('textarea'), function(v) {
  6275. if (s.editor_deselector && hasClass(v, s.editor_deselector))
  6276. return;
  6277. if (!s.editor_selector || hasClass(v, s.editor_selector)) {
  6278. // Can we use the name
  6279. e = DOM.get(v.name);
  6280. if (!v.id && !e)
  6281. v.id = v.name;
  6282. // Generate unique name if missing or already exists
  6283. if (!v.id || t.get(v.id))
  6284. v.id = DOM.uniqueId();
  6285. ed = new tinymce.Editor(v.id, s);
  6286. el.push(ed);
  6287. ed.render(1);
  6288. }
  6289. });
  6290. break;
  6291. }
  6292. // Call onInit when all editors are initialized
  6293. if (s.oninit) {
  6294. l = co = 0;
  6295. each(el, function(ed) {
  6296. co++;
  6297. if (!ed.initialized) {
  6298. // Wait for it
  6299. ed.onInit.add(function() {
  6300. l++;
  6301. // All done
  6302. if (l == co)
  6303. execCallback(s, 'oninit');
  6304. });
  6305. } else
  6306. l++;
  6307. // All done
  6308. if (l == co)
  6309. execCallback(s, 'oninit');
  6310. });
  6311. }
  6312. });
  6313. },
  6314. get : function(id) {
  6315. if (id === undefined)
  6316. return this.editors;
  6317. return this.editors[id];
  6318. },
  6319. getInstanceById : function(id) {
  6320. return this.get(id);
  6321. },
  6322. add : function(editor) {
  6323. var self = this, editors = self.editors;
  6324. // Add named and index editor instance
  6325. editors[editor.id] = editor;
  6326. editors.push(editor);
  6327. self._setActive(editor);
  6328. self.onAddEditor.dispatch(self, editor);
  6329. // Patch the tinymce.Editor instance with jQuery adapter logic
  6330. if (tinymce.adapter)
  6331. tinymce.adapter.patchEditor(editor);
  6332. return editor;
  6333. },
  6334. remove : function(editor) {
  6335. var t = this, i, editors = t.editors;
  6336. // Not in the collection
  6337. if (!editors[editor.id])
  6338. return null;
  6339. delete editors[editor.id];
  6340. for (i = 0; i < editors.length; i++) {
  6341. if (editors[i] == editor) {
  6342. editors.splice(i, 1);
  6343. break;
  6344. }
  6345. }
  6346. // Select another editor since the active one was removed
  6347. if (t.activeEditor == editor)
  6348. t._setActive(editors[0]);
  6349. editor.destroy();
  6350. t.onRemoveEditor.dispatch(t, editor);
  6351. return editor;
  6352. },
  6353. execCommand : function(c, u, v) {
  6354. var t = this, ed = t.get(v), w;
  6355. // Manager commands
  6356. switch (c) {
  6357. case "mceFocus":
  6358. ed.focus();
  6359. return true;
  6360. case "mceAddEditor":
  6361. case "mceAddControl":
  6362. if (!t.get(v))
  6363. new tinymce.Editor(v, t.settings).render();
  6364. return true;
  6365. case "mceAddFrameControl":
  6366. w = v.window;
  6367. // Add tinyMCE global instance and tinymce namespace to specified window
  6368. w.tinyMCE = tinyMCE;
  6369. w.tinymce = tinymce;
  6370. tinymce.DOM.doc = w.document;
  6371. tinymce.DOM.win = w;
  6372. ed = new tinymce.Editor(v.element_id, v);
  6373. ed.render();
  6374. // Fix IE memory leaks
  6375. if (tinymce.isIE) {
  6376. function clr() {
  6377. ed.destroy();
  6378. w.detachEvent('onunload', clr);
  6379. w = w.tinyMCE = w.tinymce = null; // IE leak
  6380. };
  6381. w.attachEvent('onunload', clr);
  6382. }
  6383. v.page_window = null;
  6384. return true;
  6385. case "mceRemoveEditor":
  6386. case "mceRemoveControl":
  6387. if (ed)
  6388. ed.remove();
  6389. return true;
  6390. case 'mceToggleEditor':
  6391. if (!ed) {
  6392. t.execCommand('mceAddControl', 0, v);
  6393. return true;
  6394. }
  6395. if (ed.isHidden())
  6396. ed.show();
  6397. else
  6398. ed.hide();
  6399. return true;
  6400. }
  6401. // Run command on active editor
  6402. if (t.activeEditor)
  6403. return t.activeEditor.execCommand(c, u, v);
  6404. return false;
  6405. },
  6406. execInstanceCommand : function(id, c, u, v) {
  6407. var ed = this.get(id);
  6408. if (ed)
  6409. return ed.execCommand(c, u, v);
  6410. return false;
  6411. },
  6412. triggerSave : function() {
  6413. each(this.editors, function(e) {
  6414. e.save();
  6415. });
  6416. },
  6417. addI18n : function(p, o) {
  6418. var lo, i18n = this.i18n;
  6419. if (!tinymce.is(p, 'string')) {
  6420. each(p, function(o, lc) {
  6421. each(o, function(o, g) {
  6422. each(o, function(o, k) {
  6423. if (g === 'common')
  6424. i18n[lc + '.' + k] = o;
  6425. else
  6426. i18n[lc + '.' + g + '.' + k] = o;
  6427. });
  6428. });
  6429. });
  6430. } else {
  6431. each(o, function(o, k) {
  6432. i18n[p + '.' + k] = o;
  6433. });
  6434. }
  6435. },
  6436. // Private methods
  6437. _setActive : function(editor) {
  6438. this.selectedInstance = this.activeEditor = editor;
  6439. }
  6440. });
  6441. })(tinymce);
  6442. (function(tinymce) {
  6443. // Shorten these names
  6444. var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend,
  6445. Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isGecko = tinymce.isGecko,
  6446. isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is,
  6447. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  6448. inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode;
  6449. tinymce.create('tinymce.Editor', {
  6450. Editor : function(id, s) {
  6451. var t = this;
  6452. t.id = t.editorId = id;
  6453. t.execCommands = {};
  6454. t.queryStateCommands = {};
  6455. t.queryValueCommands = {};
  6456. t.isNotDirty = false;
  6457. t.plugins = {};
  6458. // Add events to the editor
  6459. each([
  6460. 'onPreInit',
  6461. 'onBeforeRenderUI',
  6462. 'onPostRender',
  6463. 'onInit',
  6464. 'onRemove',
  6465. 'onActivate',
  6466. 'onDeactivate',
  6467. 'onClick',
  6468. 'onEvent',
  6469. 'onMouseUp',
  6470. 'onMouseDown',
  6471. 'onDblClick',
  6472. 'onKeyDown',
  6473. 'onKeyUp',
  6474. 'onKeyPress',
  6475. 'onContextMenu',
  6476. 'onSubmit',
  6477. 'onReset',
  6478. 'onPaste',
  6479. 'onPreProcess',
  6480. 'onPostProcess',
  6481. 'onBeforeSetContent',
  6482. 'onBeforeGetContent',
  6483. 'onSetContent',
  6484. 'onGetContent',
  6485. 'onLoadContent',
  6486. 'onSaveContent',
  6487. 'onNodeChange',
  6488. 'onChange',
  6489. 'onBeforeExecCommand',
  6490. 'onExecCommand',
  6491. 'onUndo',
  6492. 'onRedo',
  6493. 'onVisualAid',
  6494. 'onSetProgressState'
  6495. ], function(e) {
  6496. t[e] = new Dispatcher(t);
  6497. });
  6498. t.settings = s = extend({
  6499. id : id,
  6500. language : 'en',
  6501. docs_language : 'en',
  6502. theme : 'simple',
  6503. skin : 'default',
  6504. delta_width : 0,
  6505. delta_height : 0,
  6506. popup_css : '',
  6507. plugins : '',
  6508. document_base_url : tinymce.documentBaseURL,
  6509. add_form_submit_trigger : 1,
  6510. submit_patch : 1,
  6511. add_unload_trigger : 1,
  6512. convert_urls : 1,
  6513. relative_urls : 1,
  6514. remove_script_host : 1,
  6515. table_inline_editing : 0,
  6516. object_resizing : 1,
  6517. cleanup : 1,
  6518. accessibility_focus : 1,
  6519. custom_shortcuts : 1,
  6520. custom_undo_redo_keyboard_shortcuts : 1,
  6521. custom_undo_redo_restore_selection : 1,
  6522. custom_undo_redo : 1,
  6523. doctype : tinymce.isIE6 ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' : '<!DOCTYPE>', // Use old doctype on IE 6 to avoid horizontal scroll
  6524. visual_table_class : 'mceItemTable',
  6525. visual : 1,
  6526. font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large',
  6527. apply_source_formatting : 1,
  6528. directionality : 'ltr',
  6529. forced_root_block : 'p',
  6530. valid_elements : '@[id|class|style|title|dir<ltr?rtl|lang|xml::lang|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],a[rel|rev|charset|hreflang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur],strong/b,em/i,strike,u,#p,-ol[type|compact],-ul[type|compact],-li,br,img[longdesc|usemap|src|border|alt=|title|hspace|vspace|width|height|align],-sub,-sup,-blockquote[cite],-table[border|cellspacing|cellpadding|width|frame|rules|height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor|scope],#th[colspan|rowspan|width|height|align|valign|scope],caption,-div,-span,-code,-pre,address,-h1,-h2,-h3,-h4,-h5,-h6,hr[size|noshade],-font[face|size|color],dd,dl,dt,cite,abbr,acronym,del[datetime|cite],ins[datetime|cite],object[classid|width|height|codebase|*],param[name|value],embed[type|width|height|src|*],script[src|type],map[name],area[shape|coords|href|alt|target],bdo,button,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|valign|width],dfn,fieldset,form[action|accept|accept-charset|enctype|method],input[accept|alt|checked|disabled|maxlength|name|readonly|size|src|type|value|tabindex|accesskey],kbd,label[for],legend,noscript,optgroup[label|disabled],option[disabled|label|selected|value],q[cite],samp,select[disabled|multiple|name|size],small,textarea[cols|rows|disabled|name|readonly],tt,var,big',
  6531. hidden_input : 1,
  6532. padd_empty_editor : 1,
  6533. render_ui : 1,
  6534. init_theme : 1,
  6535. force_p_newlines : 1,
  6536. indentation : '30px',
  6537. keep_styles : 1,
  6538. fix_table_elements : 1,
  6539. inline_styles : 1,
  6540. convert_fonts_to_spans : true
  6541. }, s);
  6542. t.documentBaseURI = new tinymce.util.URI(s.document_base_url || tinymce.documentBaseURL, {
  6543. base_uri : tinyMCE.baseURI
  6544. });
  6545. t.baseURI = tinymce.baseURI;
  6546. // Call setup
  6547. t.execCallback('setup', t);
  6548. },
  6549. render : function(nst) {
  6550. var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader;
  6551. // Page is not loaded yet, wait for it
  6552. if (!Event.domLoaded) {
  6553. Event.add(document, 'init', function() {
  6554. t.render();
  6555. });
  6556. return;
  6557. }
  6558. tinyMCE.settings = s;
  6559. // Element not found, then skip initialization
  6560. if (!t.getElement())
  6561. return;
  6562. // Is a iPad/iPhone, then skip initialization. We need to sniff here since the
  6563. // browser says it has contentEditable support but there is no visible caret
  6564. // We will remove this check ones Apple implements full contentEditable support
  6565. if (tinymce.isIDevice)
  6566. return;
  6567. // Add hidden input for non input elements inside form elements
  6568. if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form'))
  6569. DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id);
  6570. if (tinymce.WindowManager)
  6571. t.windowManager = new tinymce.WindowManager(t);
  6572. if (s.encoding == 'xml') {
  6573. t.onGetContent.add(function(ed, o) {
  6574. if (o.save)
  6575. o.content = DOM.encode(o.content);
  6576. });
  6577. }
  6578. if (s.add_form_submit_trigger) {
  6579. t.onSubmit.addToTop(function() {
  6580. if (t.initialized) {
  6581. t.save();
  6582. t.isNotDirty = 1;
  6583. }
  6584. });
  6585. }
  6586. if (s.add_unload_trigger) {
  6587. t._beforeUnload = tinyMCE.onBeforeUnload.add(function() {
  6588. if (t.initialized && !t.destroyed && !t.isHidden())
  6589. t.save({format : 'raw', no_events : true});
  6590. });
  6591. }
  6592. tinymce.addUnload(t.destroy, t);
  6593. if (s.submit_patch) {
  6594. t.onBeforeRenderUI.add(function() {
  6595. var n = t.getElement().form;
  6596. if (!n)
  6597. return;
  6598. // Already patched
  6599. if (n._mceOldSubmit)
  6600. return;
  6601. // Check page uses id="submit" or name="submit" for it's submit button
  6602. if (!n.submit.nodeType && !n.submit.length) {
  6603. t.formElement = n;
  6604. n._mceOldSubmit = n.submit;
  6605. n.submit = function() {
  6606. // Save all instances
  6607. tinymce.triggerSave();
  6608. t.isNotDirty = 1;
  6609. return t.formElement._mceOldSubmit(t.formElement);
  6610. };
  6611. }
  6612. n = null;
  6613. });
  6614. }
  6615. // Load scripts
  6616. function loadScripts() {
  6617. if (s.language)
  6618. sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
  6619. if (s.theme && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme])
  6620. ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js');
  6621. each(explode(s.plugins), function(p) {
  6622. if (p && p.charAt(0) != '-' && !PluginManager.urls[p]) {
  6623. // Skip safari plugin, since it is removed as of 3.3b1
  6624. if (p == 'safari')
  6625. return;
  6626. PluginManager.load(p, 'plugins/' + p + '/editor_plugin' + tinymce.suffix + '.js');
  6627. }
  6628. });
  6629. // Init when que is loaded
  6630. sl.loadQueue(function() {
  6631. if (!t.removed)
  6632. t.init();
  6633. });
  6634. };
  6635. loadScripts();
  6636. },
  6637. init : function() {
  6638. var n, t = this, s = t.settings, w, h, e = t.getElement(), o, ti, u, bi, bc, re;
  6639. tinymce.add(t);
  6640. if (s.theme) {
  6641. s.theme = s.theme.replace(/-/, '');
  6642. o = ThemeManager.get(s.theme);
  6643. t.theme = new o();
  6644. if (t.theme.init && s.init_theme)
  6645. t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, ''));
  6646. }
  6647. // Create all plugins
  6648. each(explode(s.plugins.replace(/\-/g, '')), function(p) {
  6649. var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po;
  6650. if (c) {
  6651. po = new c(t, u);
  6652. t.plugins[p] = po;
  6653. if (po.init)
  6654. po.init(t, u);
  6655. }
  6656. });
  6657. // Setup popup CSS path(s)
  6658. if (s.popup_css !== false) {
  6659. if (s.popup_css)
  6660. s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css);
  6661. else
  6662. s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css");
  6663. }
  6664. if (s.popup_css_add)
  6665. s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add);
  6666. t.controlManager = new tinymce.ControlManager(t);
  6667. if (s.custom_undo_redo) {
  6668. // Add initial undo level
  6669. t.onBeforeExecCommand.add(function(ed, cmd, ui, val, a) {
  6670. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo)) {
  6671. if (!t.undoManager.hasUndo())
  6672. t.undoManager.add();
  6673. }
  6674. });
  6675. t.onExecCommand.add(function(ed, cmd, ui, val, a) {
  6676. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
  6677. t.undoManager.add();
  6678. });
  6679. }
  6680. t.onExecCommand.add(function(ed, c) {
  6681. // Don't refresh the select lists until caret move
  6682. if (!/^(FontName|FontSize)$/.test(c))
  6683. t.nodeChanged();
  6684. });
  6685. // Remove ghost selections on images and tables in Gecko
  6686. if (isGecko) {
  6687. function repaint(a, o) {
  6688. if (!o || !o.initial)
  6689. t.execCommand('mceRepaint');
  6690. };
  6691. t.onUndo.add(repaint);
  6692. t.onRedo.add(repaint);
  6693. t.onSetContent.add(repaint);
  6694. }
  6695. // Enables users to override the control factory
  6696. t.onBeforeRenderUI.dispatch(t, t.controlManager);
  6697. // Measure box
  6698. if (s.render_ui) {
  6699. w = s.width || e.style.width || e.offsetWidth;
  6700. h = s.height || e.style.height || e.offsetHeight;
  6701. t.orgDisplay = e.style.display;
  6702. re = /^[0-9\.]+(|px)$/i;
  6703. if (re.test('' + w))
  6704. w = Math.max(parseInt(w) + (o.deltaWidth || 0), 100);
  6705. if (re.test('' + h))
  6706. h = Math.max(parseInt(h) + (o.deltaHeight || 0), 100);
  6707. // Render UI
  6708. o = t.theme.renderUI({
  6709. targetNode : e,
  6710. width : w,
  6711. height : h,
  6712. deltaWidth : s.delta_width,
  6713. deltaHeight : s.delta_height
  6714. });
  6715. t.editorContainer = o.editorContainer;
  6716. }
  6717. // User specified a document.domain value
  6718. if (document.domain && location.hostname != document.domain)
  6719. tinymce.relaxedDomain = document.domain;
  6720. // Resize editor
  6721. DOM.setStyles(o.sizeContainer || o.editorContainer, {
  6722. width : w,
  6723. height : h
  6724. });
  6725. h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
  6726. if (h < 100)
  6727. h = 100;
  6728. t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">';
  6729. // We only need to override paths if we have to
  6730. // IE has a bug where it remove site absolute urls to relative ones if this is specified
  6731. if (s.document_base_url != tinymce.documentBaseURL)
  6732. t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />';
  6733. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  6734. if (tinymce.relaxedDomain)
  6735. t.iframeHTML += '<script type="text/javascript">document.domain = "' + tinymce.relaxedDomain + '";</script>';
  6736. bi = s.body_id || 'tinymce';
  6737. if (bi.indexOf('=') != -1) {
  6738. bi = t.getParam('body_id', '', 'hash');
  6739. bi = bi[t.id] || bi;
  6740. }
  6741. bc = s.body_class || '';
  6742. if (bc.indexOf('=') != -1) {
  6743. bc = t.getParam('body_class', '', 'hash');
  6744. bc = bc[t.id] || '';
  6745. }
  6746. t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '"></body></html>';
  6747. // Domain relaxing enabled, then set document domain
  6748. if (tinymce.relaxedDomain) {
  6749. // We need to write the contents here in IE since multiple writes messes up refresh button and back button
  6750. if (isIE || (tinymce.isOpera && parseFloat(opera.version()) >= 9.5))
  6751. u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";var ed = window.parent.tinyMCE.get("' + t.id + '");document.write(ed.iframeHTML);document.close();ed.setupIframe();})()';
  6752. else if (tinymce.isOpera)
  6753. u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";document.close();ed.setupIframe();})()';
  6754. }
  6755. // Create iframe
  6756. n = DOM.add(o.iframeContainer, 'iframe', {
  6757. id : t.id + "_ifr",
  6758. src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7
  6759. frameBorder : '0',
  6760. style : {
  6761. width : '100%',
  6762. height : h
  6763. }
  6764. });
  6765. t.contentAreaContainer = o.iframeContainer;
  6766. DOM.get(o.editorContainer).style.display = t.orgDisplay;
  6767. DOM.get(t.id).style.display = 'none';
  6768. if (!isIE || !tinymce.relaxedDomain)
  6769. t.setupIframe();
  6770. e = n = o = null; // Cleanup
  6771. },
  6772. setupIframe : function() {
  6773. var t = this, s = t.settings, e = DOM.get(t.id), d = t.getDoc(), h, b;
  6774. // Setup iframe body
  6775. if (!isIE || !tinymce.relaxedDomain) {
  6776. d.open();
  6777. d.write(t.iframeHTML);
  6778. d.close();
  6779. }
  6780. // Design mode needs to be added here Ctrl+A will fail otherwise
  6781. if (!isIE) {
  6782. try {
  6783. if (!s.readonly)
  6784. d.designMode = 'On';
  6785. } catch (ex) {
  6786. // Will fail on Gecko if the editor is placed in an hidden container element
  6787. // The design mode will be set ones the editor is focused
  6788. }
  6789. }
  6790. // IE needs to use contentEditable or it will display non secure items for HTTPS
  6791. if (isIE) {
  6792. // It will not steal focus if we hide it while setting contentEditable
  6793. b = t.getBody();
  6794. DOM.hide(b);
  6795. if (!s.readonly)
  6796. b.contentEditable = true;
  6797. DOM.show(b);
  6798. }
  6799. t.dom = new tinymce.dom.DOMUtils(t.getDoc(), {
  6800. keep_values : true,
  6801. url_converter : t.convertURL,
  6802. url_converter_scope : t,
  6803. hex_colors : s.force_hex_style_colors,
  6804. class_filter : s.class_filter,
  6805. update_styles : 1,
  6806. fix_ie_paragraphs : 1,
  6807. valid_styles : s.valid_styles
  6808. });
  6809. t.schema = new tinymce.dom.Schema();
  6810. t.serializer = new tinymce.dom.Serializer(extend(s, {
  6811. valid_elements : s.verify_html === false ? '*[*]' : s.valid_elements,
  6812. dom : t.dom,
  6813. schema : t.schema
  6814. }));
  6815. t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer);
  6816. t.formatter = new tinymce.Formatter(this);
  6817. // Register default formats
  6818. t.formatter.register({
  6819. alignleft : [
  6820. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},
  6821. {selector : 'img,table', styles : {'float' : 'left'}}
  6822. ],
  6823. aligncenter : [
  6824. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},
  6825. {selector : 'img', styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}},
  6826. {selector : 'table', styles : {marginLeft : 'auto', marginRight : 'auto'}}
  6827. ],
  6828. alignright : [
  6829. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},
  6830. {selector : 'img,table', styles : {'float' : 'right'}}
  6831. ],
  6832. alignfull : [
  6833. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}}
  6834. ],
  6835. bold : [
  6836. {inline : 'strong'},
  6837. {inline : 'span', styles : {fontWeight : 'bold'}},
  6838. {inline : 'b'}
  6839. ],
  6840. italic : [
  6841. {inline : 'em'},
  6842. {inline : 'span', styles : {fontStyle : 'italic'}},
  6843. {inline : 'i'}
  6844. ],
  6845. underline : [
  6846. {inline : 'span', styles : {textDecoration : 'underline'}, exact : true},
  6847. {inline : 'u'}
  6848. ],
  6849. strikethrough : [
  6850. {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true},
  6851. {inline : 'u'}
  6852. ],
  6853. forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false},
  6854. hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false},
  6855. fontname : {inline : 'span', styles : {fontFamily : '%value'}},
  6856. fontsize : {inline : 'span', styles : {fontSize : '%value'}},
  6857. fontsize_class : {inline : 'span', attributes : {'class' : '%value'}},
  6858. blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'},
  6859. removeformat : [
  6860. {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
  6861. {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
  6862. {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
  6863. ]
  6864. });
  6865. // Register default block formats
  6866. each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) {
  6867. t.formatter.register(name, {block : name, remove : 'all'});
  6868. });
  6869. // Register user defined formats
  6870. t.formatter.register(t.settings.formats);
  6871. t.undoManager = new tinymce.UndoManager(t);
  6872. // Pass through
  6873. t.undoManager.onAdd.add(function(um, l) {
  6874. if (!l.initial)
  6875. return t.onChange.dispatch(t, l, um);
  6876. });
  6877. t.undoManager.onUndo.add(function(um, l) {
  6878. return t.onUndo.dispatch(t, l, um);
  6879. });
  6880. t.undoManager.onRedo.add(function(um, l) {
  6881. return t.onRedo.dispatch(t, l, um);
  6882. });
  6883. t.forceBlocks = new tinymce.ForceBlocks(t, {
  6884. forced_root_block : s.forced_root_block
  6885. });
  6886. t.editorCommands = new tinymce.EditorCommands(t);
  6887. // Pass through
  6888. t.serializer.onPreProcess.add(function(se, o) {
  6889. return t.onPreProcess.dispatch(t, o, se);
  6890. });
  6891. t.serializer.onPostProcess.add(function(se, o) {
  6892. return t.onPostProcess.dispatch(t, o, se);
  6893. });
  6894. t.onPreInit.dispatch(t);
  6895. if (!s.gecko_spellcheck)
  6896. t.getBody().spellcheck = 0;
  6897. if (!s.readonly)
  6898. t._addEvents();
  6899. t.controlManager.onPostRender.dispatch(t, t.controlManager);
  6900. t.onPostRender.dispatch(t);
  6901. if (s.directionality)
  6902. t.getBody().dir = s.directionality;
  6903. if (s.nowrap)
  6904. t.getBody().style.whiteSpace = "nowrap";
  6905. if (s.custom_elements) {
  6906. function handleCustom(ed, o) {
  6907. each(explode(s.custom_elements), function(v) {
  6908. var n;
  6909. if (v.indexOf('~') === 0) {
  6910. v = v.substring(1);
  6911. n = 'span';
  6912. } else
  6913. n = 'div';
  6914. o.content = o.content.replace(new RegExp('<(' + v + ')([^>]*)>', 'g'), '<' + n + ' _mce_name="$1"$2>');
  6915. o.content = o.content.replace(new RegExp('</(' + v + ')>', 'g'), '</' + n + '>');
  6916. });
  6917. };
  6918. t.onBeforeSetContent.add(handleCustom);
  6919. t.onPostProcess.add(function(ed, o) {
  6920. if (o.set)
  6921. handleCustom(ed, o);
  6922. });
  6923. }
  6924. if (s.handle_node_change_callback) {
  6925. t.onNodeChange.add(function(ed, cm, n) {
  6926. t.execCallback('handle_node_change_callback', t.id, n, -1, -1, true, t.selection.isCollapsed());
  6927. });
  6928. }
  6929. if (s.save_callback) {
  6930. t.onSaveContent.add(function(ed, o) {
  6931. var h = t.execCallback('save_callback', t.id, o.content, t.getBody());
  6932. if (h)
  6933. o.content = h;
  6934. });
  6935. }
  6936. if (s.onchange_callback) {
  6937. t.onChange.add(function(ed, l) {
  6938. t.execCallback('onchange_callback', t, l);
  6939. });
  6940. }
  6941. if (s.convert_newlines_to_brs) {
  6942. t.onBeforeSetContent.add(function(ed, o) {
  6943. if (o.initial)
  6944. o.content = o.content.replace(/\r?\n/g, '<br />');
  6945. });
  6946. }
  6947. if (s.fix_nesting && isIE) {
  6948. t.onBeforeSetContent.add(function(ed, o) {
  6949. o.content = t._fixNesting(o.content);
  6950. });
  6951. }
  6952. if (s.preformatted) {
  6953. t.onPostProcess.add(function(ed, o) {
  6954. o.content = o.content.replace(/^\s*<pre.*?>/, '');
  6955. o.content = o.content.replace(/<\/pre>\s*$/, '');
  6956. if (o.set)
  6957. o.content = '<pre class="mceItemHidden">' + o.content + '</pre>';
  6958. });
  6959. }
  6960. if (s.verify_css_classes) {
  6961. t.serializer.attribValueFilter = function(n, v) {
  6962. var s, cl;
  6963. if (n == 'class') {
  6964. // Build regexp for classes
  6965. if (!t.classesRE) {
  6966. cl = t.dom.getClasses();
  6967. if (cl.length > 0) {
  6968. s = '';
  6969. each (cl, function(o) {
  6970. s += (s ? '|' : '') + o['class'];
  6971. });
  6972. t.classesRE = new RegExp('(' + s + ')', 'gi');
  6973. }
  6974. }
  6975. return !t.classesRE || /(\bmceItem\w+\b|\bmceTemp\w+\b)/g.test(v) || t.classesRE.test(v) ? v : '';
  6976. }
  6977. return v;
  6978. };
  6979. }
  6980. if (s.cleanup_callback) {
  6981. t.onBeforeSetContent.add(function(ed, o) {
  6982. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  6983. });
  6984. t.onPreProcess.add(function(ed, o) {
  6985. if (o.set)
  6986. t.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o);
  6987. if (o.get)
  6988. t.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o);
  6989. });
  6990. t.onPostProcess.add(function(ed, o) {
  6991. if (o.set)
  6992. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  6993. if (o.get)
  6994. o.content = t.execCallback('cleanup_callback', 'get_from_editor', o.content, o);
  6995. });
  6996. }
  6997. if (s.save_callback) {
  6998. t.onGetContent.add(function(ed, o) {
  6999. if (o.save)
  7000. o.content = t.execCallback('save_callback', t.id, o.content, t.getBody());
  7001. });
  7002. }
  7003. if (s.handle_event_callback) {
  7004. t.onEvent.add(function(ed, e, o) {
  7005. if (t.execCallback('handle_event_callback', e, ed, o) === false)
  7006. Event.cancel(e);
  7007. });
  7008. }
  7009. // Add visual aids when new contents is added
  7010. t.onSetContent.add(function() {
  7011. t.addVisual(t.getBody());
  7012. });
  7013. // Remove empty contents
  7014. if (s.padd_empty_editor) {
  7015. t.onPostProcess.add(function(ed, o) {
  7016. o.content = o.content.replace(/^(<p[^>]*>(&nbsp;|&#160;|\s|\u00a0|)<\/p>[\r\n]*|<br \/>[\r\n]*)$/, '');
  7017. });
  7018. }
  7019. if (isGecko) {
  7020. // Fix gecko link bug, when a link is placed at the end of block elements there is
  7021. // no way to move the caret behind the link. This fix adds a bogus br element after the link
  7022. function fixLinks(ed, o) {
  7023. each(ed.dom.select('a'), function(n) {
  7024. var pn = n.parentNode;
  7025. if (ed.dom.isBlock(pn) && pn.lastChild === n)
  7026. ed.dom.add(pn, 'br', {'_mce_bogus' : 1});
  7027. });
  7028. };
  7029. t.onExecCommand.add(function(ed, cmd) {
  7030. if (cmd === 'CreateLink')
  7031. fixLinks(ed);
  7032. });
  7033. t.onSetContent.add(t.selection.onSetContent.add(fixLinks));
  7034. if (!s.readonly) {
  7035. try {
  7036. // Design mode must be set here once again to fix a bug where
  7037. // Ctrl+A/Delete/Backspace didn't work if the editor was added using mceAddControl then removed then added again
  7038. d.designMode = 'Off';
  7039. d.designMode = 'On';
  7040. } catch (ex) {
  7041. // Will fail on Gecko if the editor is placed in an hidden container element
  7042. // The design mode will be set ones the editor is focused
  7043. }
  7044. }
  7045. }
  7046. // A small timeout was needed since firefox will remove. Bug: #1838304
  7047. setTimeout(function () {
  7048. if (t.removed)
  7049. return;
  7050. t.load({initial : true, format : (s.cleanup_on_startup ? 'html' : 'raw')});
  7051. t.startContent = t.getContent({format : 'raw'});
  7052. t.initialized = true;
  7053. t.onInit.dispatch(t);
  7054. t.execCallback('setupcontent_callback', t.id, t.getBody(), t.getDoc());
  7055. t.execCallback('init_instance_callback', t);
  7056. t.focus(true);
  7057. t.nodeChanged({initial : 1});
  7058. // Load specified content CSS last
  7059. if (s.content_css) {
  7060. tinymce.each(explode(s.content_css), function(u) {
  7061. t.dom.loadCSS(t.documentBaseURI.toAbsolute(u));
  7062. });
  7063. }
  7064. // Handle auto focus
  7065. if (s.auto_focus) {
  7066. setTimeout(function () {
  7067. var ed = tinymce.get(s.auto_focus);
  7068. ed.selection.select(ed.getBody(), 1);
  7069. ed.selection.collapse(1);
  7070. ed.getWin().focus();
  7071. }, 100);
  7072. }
  7073. }, 1);
  7074. e = null;
  7075. },
  7076. focus : function(sf) {
  7077. var oed, t = this, ce = t.settings.content_editable, ieRng, controlElm, doc = t.getDoc();
  7078. if (!sf) {
  7079. // Get selected control element
  7080. ieRng = t.selection.getRng();
  7081. if (ieRng.item) {
  7082. controlElm = ieRng.item(0);
  7083. }
  7084. // Is not content editable
  7085. if (!ce)
  7086. t.getWin().focus();
  7087. // Restore selected control element
  7088. // This is needed when for example an image is selected within a
  7089. // layer a call to focus will then remove the control selection
  7090. if (controlElm && controlElm.ownerDocument == doc) {
  7091. ieRng = doc.body.createControlRange();
  7092. ieRng.addElement(controlElm);
  7093. ieRng.select();
  7094. }
  7095. }
  7096. if (tinymce.activeEditor != t) {
  7097. if ((oed = tinymce.activeEditor) != null)
  7098. oed.onDeactivate.dispatch(oed, t);
  7099. t.onActivate.dispatch(t, oed);
  7100. }
  7101. tinymce._setActive(t);
  7102. },
  7103. execCallback : function(n) {
  7104. var t = this, f = t.settings[n], s;
  7105. if (!f)
  7106. return;
  7107. // Look through lookup
  7108. if (t.callbackLookup && (s = t.callbackLookup[n])) {
  7109. f = s.func;
  7110. s = s.scope;
  7111. }
  7112. if (is(f, 'string')) {
  7113. s = f.replace(/\.\w+$/, '');
  7114. s = s ? tinymce.resolve(s) : 0;
  7115. f = tinymce.resolve(f);
  7116. t.callbackLookup = t.callbackLookup || {};
  7117. t.callbackLookup[n] = {func : f, scope : s};
  7118. }
  7119. return f.apply(s || t, Array.prototype.slice.call(arguments, 1));
  7120. },
  7121. translate : function(s) {
  7122. var c = this.settings.language || 'en', i18n = tinymce.i18n;
  7123. if (!s)
  7124. return '';
  7125. return i18n[c + '.' + s] || s.replace(/{\#([^}]+)\}/g, function(a, b) {
  7126. return i18n[c + '.' + b] || '{#' + b + '}';
  7127. });
  7128. },
  7129. getLang : function(n, dv) {
  7130. return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}');
  7131. },
  7132. getParam : function(n, dv, ty) {
  7133. var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o;
  7134. if (ty === 'hash') {
  7135. o = {};
  7136. if (is(v, 'string')) {
  7137. each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) {
  7138. v = v.split('=');
  7139. if (v.length > 1)
  7140. o[tr(v[0])] = tr(v[1]);
  7141. else
  7142. o[tr(v[0])] = tr(v);
  7143. });
  7144. } else
  7145. o = v;
  7146. return o;
  7147. }
  7148. return v;
  7149. },
  7150. nodeChanged : function(o) {
  7151. var t = this, s = t.selection, n = (isIE ? s.getNode() : s.getStart()) || t.getBody();
  7152. // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
  7153. if (t.initialized) {
  7154. o = o || {};
  7155. n = isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n; // Fix for IE initial state
  7156. // Get parents and add them to object
  7157. o.parents = [];
  7158. t.dom.getParent(n, function(node) {
  7159. if (node.nodeName == 'BODY')
  7160. return true;
  7161. o.parents.push(node);
  7162. });
  7163. t.onNodeChange.dispatch(
  7164. t,
  7165. o ? o.controlManager || t.controlManager : t.controlManager,
  7166. n,
  7167. s.isCollapsed(),
  7168. o
  7169. );
  7170. }
  7171. },
  7172. addButton : function(n, s) {
  7173. var t = this;
  7174. t.buttons = t.buttons || {};
  7175. t.buttons[n] = s;
  7176. },
  7177. addCommand : function(n, f, s) {
  7178. this.execCommands[n] = {func : f, scope : s || this};
  7179. },
  7180. addQueryStateHandler : function(n, f, s) {
  7181. this.queryStateCommands[n] = {func : f, scope : s || this};
  7182. },
  7183. addQueryValueHandler : function(n, f, s) {
  7184. this.queryValueCommands[n] = {func : f, scope : s || this};
  7185. },
  7186. addShortcut : function(pa, desc, cmd_func, sc) {
  7187. var t = this, c;
  7188. if (!t.settings.custom_shortcuts)
  7189. return false;
  7190. t.shortcuts = t.shortcuts || {};
  7191. if (is(cmd_func, 'string')) {
  7192. c = cmd_func;
  7193. cmd_func = function() {
  7194. t.execCommand(c, false, null);
  7195. };
  7196. }
  7197. if (is(cmd_func, 'object')) {
  7198. c = cmd_func;
  7199. cmd_func = function() {
  7200. t.execCommand(c[0], c[1], c[2]);
  7201. };
  7202. }
  7203. each(explode(pa), function(pa) {
  7204. var o = {
  7205. func : cmd_func,
  7206. scope : sc || this,
  7207. desc : desc,
  7208. alt : false,
  7209. ctrl : false,
  7210. shift : false
  7211. };
  7212. each(explode(pa, '+'), function(v) {
  7213. switch (v) {
  7214. case 'alt':
  7215. case 'ctrl':
  7216. case 'shift':
  7217. o[v] = true;
  7218. break;
  7219. default:
  7220. o.charCode = v.charCodeAt(0);
  7221. o.keyCode = v.toUpperCase().charCodeAt(0);
  7222. }
  7223. });
  7224. t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o;
  7225. });
  7226. return true;
  7227. },
  7228. execCommand : function(cmd, ui, val, a) {
  7229. var t = this, s = 0, o, st;
  7230. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus))
  7231. t.focus();
  7232. o = {};
  7233. t.onBeforeExecCommand.dispatch(t, cmd, ui, val, o);
  7234. if (o.terminate)
  7235. return false;
  7236. // Command callback
  7237. if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) {
  7238. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  7239. return true;
  7240. }
  7241. // Registred commands
  7242. if (o = t.execCommands[cmd]) {
  7243. st = o.func.call(o.scope, ui, val);
  7244. // Fall through on true
  7245. if (st !== true) {
  7246. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  7247. return st;
  7248. }
  7249. }
  7250. // Plugin commands
  7251. each(t.plugins, function(p) {
  7252. if (p.execCommand && p.execCommand(cmd, ui, val)) {
  7253. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  7254. s = 1;
  7255. return false;
  7256. }
  7257. });
  7258. if (s)
  7259. return true;
  7260. // Theme commands
  7261. if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) {
  7262. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  7263. return true;
  7264. }
  7265. // Execute global commands
  7266. if (tinymce.GlobalCommands.execCommand(t, cmd, ui, val)) {
  7267. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  7268. return true;
  7269. }
  7270. // Editor commands
  7271. if (t.editorCommands.execCommand(cmd, ui, val)) {
  7272. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  7273. return true;
  7274. }
  7275. // Browser commands
  7276. t.getDoc().execCommand(cmd, ui, val);
  7277. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  7278. },
  7279. queryCommandState : function(cmd) {
  7280. var t = this, o, s;
  7281. // Is hidden then return undefined
  7282. if (t._isHidden())
  7283. return;
  7284. // Registred commands
  7285. if (o = t.queryStateCommands[cmd]) {
  7286. s = o.func.call(o.scope);
  7287. // Fall though on true
  7288. if (s !== true)
  7289. return s;
  7290. }
  7291. // Registred commands
  7292. o = t.editorCommands.queryCommandState(cmd);
  7293. if (o !== -1)
  7294. return o;
  7295. // Browser commands
  7296. try {
  7297. return this.getDoc().queryCommandState(cmd);
  7298. } catch (ex) {
  7299. // Fails sometimes see bug: 1896577
  7300. }
  7301. },
  7302. queryCommandValue : function(c) {
  7303. var t = this, o, s;
  7304. // Is hidden then return undefined
  7305. if (t._isHidden())
  7306. return;
  7307. // Registred commands
  7308. if (o = t.queryValueCommands[c]) {
  7309. s = o.func.call(o.scope);
  7310. // Fall though on true
  7311. if (s !== true)
  7312. return s;
  7313. }
  7314. // Registred commands
  7315. o = t.editorCommands.queryCommandValue(c);
  7316. if (is(o))
  7317. return o;
  7318. // Browser commands
  7319. try {
  7320. return this.getDoc().queryCommandValue(c);
  7321. } catch (ex) {
  7322. // Fails sometimes see bug: 1896577
  7323. }
  7324. },
  7325. show : function() {
  7326. var t = this;
  7327. DOM.show(t.getContainer());
  7328. DOM.hide(t.id);
  7329. t.load();
  7330. },
  7331. hide : function() {
  7332. var t = this, d = t.getDoc();
  7333. // Fixed bug where IE has a blinking cursor left from the editor
  7334. if (isIE && d)
  7335. d.execCommand('SelectAll');
  7336. // We must save before we hide so Safari doesn't crash
  7337. t.save();
  7338. DOM.hide(t.getContainer());
  7339. DOM.setStyle(t.id, 'display', t.orgDisplay);
  7340. },
  7341. isHidden : function() {
  7342. return !DOM.isHidden(this.id);
  7343. },
  7344. setProgressState : function(b, ti, o) {
  7345. this.onSetProgressState.dispatch(this, b, ti, o);
  7346. return b;
  7347. },
  7348. load : function(o) {
  7349. var t = this, e = t.getElement(), h;
  7350. if (e) {
  7351. o = o || {};
  7352. o.load = true;
  7353. // Double encode existing entities in the value
  7354. h = t.setContent(is(e.value) ? e.value : e.innerHTML, o);
  7355. o.element = e;
  7356. if (!o.no_events)
  7357. t.onLoadContent.dispatch(t, o);
  7358. o.element = e = null;
  7359. return h;
  7360. }
  7361. },
  7362. save : function(o) {
  7363. var t = this, e = t.getElement(), h, f;
  7364. if (!e || !t.initialized)
  7365. return;
  7366. o = o || {};
  7367. o.save = true;
  7368. // Add undo level will trigger onchange event
  7369. if (!o.no_events) {
  7370. t.undoManager.typing = 0;
  7371. t.undoManager.add();
  7372. }
  7373. o.element = e;
  7374. h = o.content = t.getContent(o);
  7375. if (!o.no_events)
  7376. t.onSaveContent.dispatch(t, o);
  7377. h = o.content;
  7378. if (!/TEXTAREA|INPUT/i.test(e.nodeName)) {
  7379. e.innerHTML = h;
  7380. // Update hidden form element
  7381. if (f = DOM.getParent(t.id, 'form')) {
  7382. each(f.elements, function(e) {
  7383. if (e.name == t.id) {
  7384. e.value = h;
  7385. return false;
  7386. }
  7387. });
  7388. }
  7389. } else
  7390. e.value = h;
  7391. o.element = e = null;
  7392. return h;
  7393. },
  7394. setContent : function(h, o) {
  7395. var t = this;
  7396. o = o || {};
  7397. o.format = o.format || 'html';
  7398. o.set = true;
  7399. o.content = h;
  7400. if (!o.no_events)
  7401. t.onBeforeSetContent.dispatch(t, o);
  7402. // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
  7403. // It will also be impossible to place the caret in the editor unless there is a BR element present
  7404. if (!tinymce.isIE && (h.length === 0 || /^\s+$/.test(h))) {
  7405. o.content = t.dom.setHTML(t.getBody(), '<br _mce_bogus="1" />');
  7406. o.format = 'raw';
  7407. }
  7408. o.content = t.dom.setHTML(t.getBody(), tinymce.trim(o.content));
  7409. if (o.format != 'raw' && t.settings.cleanup) {
  7410. o.getInner = true;
  7411. o.content = t.dom.setHTML(t.getBody(), t.serializer.serialize(t.getBody(), o));
  7412. }
  7413. if (!o.no_events)
  7414. t.onSetContent.dispatch(t, o);
  7415. return o.content;
  7416. },
  7417. getContent : function(o) {
  7418. var t = this, h;
  7419. o = o || {};
  7420. o.format = o.format || 'html';
  7421. o.get = true;
  7422. if (!o.no_events)
  7423. t.onBeforeGetContent.dispatch(t, o);
  7424. if (o.format != 'raw' && t.settings.cleanup) {
  7425. o.getInner = true;
  7426. h = t.serializer.serialize(t.getBody(), o);
  7427. } else
  7428. h = t.getBody().innerHTML;
  7429. h = h.replace(/^\s*|\s*$/g, '');
  7430. o.content = h;
  7431. if (!o.no_events)
  7432. t.onGetContent.dispatch(t, o);
  7433. return o.content;
  7434. },
  7435. isDirty : function() {
  7436. var t = this;
  7437. return tinymce.trim(t.startContent) != tinymce.trim(t.getContent({format : 'raw', no_events : 1})) && !t.isNotDirty;
  7438. },
  7439. getContainer : function() {
  7440. var t = this;
  7441. if (!t.container)
  7442. t.container = DOM.get(t.editorContainer || t.id + '_parent');
  7443. return t.container;
  7444. },
  7445. getContentAreaContainer : function() {
  7446. return this.contentAreaContainer;
  7447. },
  7448. getElement : function() {
  7449. return DOM.get(this.settings.content_element || this.id);
  7450. },
  7451. getWin : function() {
  7452. var t = this, e;
  7453. if (!t.contentWindow) {
  7454. e = DOM.get(t.id + "_ifr");
  7455. if (e)
  7456. t.contentWindow = e.contentWindow;
  7457. }
  7458. return t.contentWindow;
  7459. },
  7460. getDoc : function() {
  7461. var t = this, w;
  7462. if (!t.contentDocument) {
  7463. w = t.getWin();
  7464. if (w)
  7465. t.contentDocument = w.document;
  7466. }
  7467. return t.contentDocument;
  7468. },
  7469. getBody : function() {
  7470. return this.bodyElement || this.getDoc().body;
  7471. },
  7472. convertURL : function(u, n, e) {
  7473. var t = this, s = t.settings;
  7474. // Use callback instead
  7475. if (s.urlconverter_callback)
  7476. return t.execCallback('urlconverter_callback', u, e, true, n);
  7477. // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  7478. if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
  7479. return u;
  7480. // Convert to relative
  7481. if (s.relative_urls)
  7482. return t.documentBaseURI.toRelative(u);
  7483. // Convert to absolute
  7484. u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);
  7485. return u;
  7486. },
  7487. addVisual : function(e) {
  7488. var t = this, s = t.settings;
  7489. e = e || t.getBody();
  7490. if (!is(t.hasVisual))
  7491. t.hasVisual = s.visual;
  7492. each(t.dom.select('table,a', e), function(e) {
  7493. var v;
  7494. switch (e.nodeName) {
  7495. case 'TABLE':
  7496. v = t.dom.getAttrib(e, 'border');
  7497. if (!v || v == '0') {
  7498. if (t.hasVisual)
  7499. t.dom.addClass(e, s.visual_table_class);
  7500. else
  7501. t.dom.removeClass(e, s.visual_table_class);
  7502. }
  7503. return;
  7504. case 'A':
  7505. v = t.dom.getAttrib(e, 'name');
  7506. if (v) {
  7507. if (t.hasVisual)
  7508. t.dom.addClass(e, 'mceItemAnchor');
  7509. else
  7510. t.dom.removeClass(e, 'mceItemAnchor');
  7511. }
  7512. return;
  7513. }
  7514. });
  7515. t.onVisualAid.dispatch(t, e, t.hasVisual);
  7516. },
  7517. remove : function() {
  7518. var t = this, e = t.getContainer();
  7519. t.removed = 1; // Cancels post remove event execution
  7520. t.hide();
  7521. t.execCallback('remove_instance_callback', t);
  7522. t.onRemove.dispatch(t);
  7523. // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command
  7524. t.onExecCommand.listeners = [];
  7525. tinymce.remove(t);
  7526. DOM.remove(e);
  7527. },
  7528. destroy : function(s) {
  7529. var t = this;
  7530. // One time is enough
  7531. if (t.destroyed)
  7532. return;
  7533. if (!s) {
  7534. tinymce.removeUnload(t.destroy);
  7535. tinyMCE.onBeforeUnload.remove(t._beforeUnload);
  7536. // Manual destroy
  7537. if (t.theme && t.theme.destroy)
  7538. t.theme.destroy();
  7539. // Destroy controls, selection and dom
  7540. t.controlManager.destroy();
  7541. t.selection.destroy();
  7542. t.dom.destroy();
  7543. // Remove all events
  7544. // Don't clear the window or document if content editable
  7545. // is enabled since other instances might still be present
  7546. if (!t.settings.content_editable) {
  7547. Event.clear(t.getWin());
  7548. Event.clear(t.getDoc());
  7549. }
  7550. Event.clear(t.getBody());
  7551. Event.clear(t.formElement);
  7552. }
  7553. if (t.formElement) {
  7554. t.formElement.submit = t.formElement._mceOldSubmit;
  7555. t.formElement._mceOldSubmit = null;
  7556. }
  7557. t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null;
  7558. if (t.selection)
  7559. t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null;
  7560. t.destroyed = 1;
  7561. },
  7562. // Internal functions
  7563. _addEvents : function() {
  7564. // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset
  7565. var t = this, i, s = t.settings, dom = t.dom, lo = {
  7566. mouseup : 'onMouseUp',
  7567. mousedown : 'onMouseDown',
  7568. click : 'onClick',
  7569. keyup : 'onKeyUp',
  7570. keydown : 'onKeyDown',
  7571. keypress : 'onKeyPress',
  7572. submit : 'onSubmit',
  7573. reset : 'onReset',
  7574. contextmenu : 'onContextMenu',
  7575. dblclick : 'onDblClick',
  7576. paste : 'onPaste' // Doesn't work in all browsers yet
  7577. };
  7578. function eventHandler(e, o) {
  7579. var ty = e.type;
  7580. // Don't fire events when it's removed
  7581. if (t.removed)
  7582. return;
  7583. // Generic event handler
  7584. if (t.onEvent.dispatch(t, e, o) !== false) {
  7585. // Specific event handler
  7586. t[lo[e.fakeType || e.type]].dispatch(t, e, o);
  7587. }
  7588. };
  7589. // Add DOM events
  7590. each(lo, function(v, k) {
  7591. switch (k) {
  7592. case 'contextmenu':
  7593. if (tinymce.isOpera) {
  7594. // Fake contextmenu on Opera
  7595. dom.bind(t.getBody(), 'mousedown', function(e) {
  7596. if (e.ctrlKey) {
  7597. e.fakeType = 'contextmenu';
  7598. eventHandler(e);
  7599. }
  7600. });
  7601. } else
  7602. dom.bind(t.getBody(), k, eventHandler);
  7603. break;
  7604. case 'paste':
  7605. dom.bind(t.getBody(), k, function(e) {
  7606. eventHandler(e);
  7607. });
  7608. break;
  7609. case 'submit':
  7610. case 'reset':
  7611. dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler);
  7612. break;
  7613. default:
  7614. dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler);
  7615. }
  7616. });
  7617. dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) {
  7618. t.focus(true);
  7619. });
  7620. // Fixes bug where a specified document_base_uri could result in broken images
  7621. // This will also fix drag drop of images in Gecko
  7622. if (tinymce.isGecko) {
  7623. dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) {
  7624. var v;
  7625. e = e.target;
  7626. if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('_mce_src')))
  7627. e.src = t.documentBaseURI.toAbsolute(v);
  7628. });
  7629. }
  7630. // Set various midas options in Gecko
  7631. if (isGecko) {
  7632. function setOpts() {
  7633. var t = this, d = t.getDoc(), s = t.settings;
  7634. if (isGecko && !s.readonly) {
  7635. if (t._isHidden()) {
  7636. try {
  7637. if (!s.content_editable)
  7638. d.designMode = 'On';
  7639. } catch (ex) {
  7640. // Fails if it's hidden
  7641. }
  7642. }
  7643. try {
  7644. // Try new Gecko method
  7645. d.execCommand("styleWithCSS", 0, false);
  7646. } catch (ex) {
  7647. // Use old method
  7648. if (!t._isHidden())
  7649. try {d.execCommand("useCSS", 0, true);} catch (ex) {}
  7650. }
  7651. if (!s.table_inline_editing)
  7652. try {d.execCommand('enableInlineTableEditing', false, false);} catch (ex) {}
  7653. if (!s.object_resizing)
  7654. try {d.execCommand('enableObjectResizing', false, false);} catch (ex) {}
  7655. }
  7656. };
  7657. t.onBeforeExecCommand.add(setOpts);
  7658. t.onMouseDown.add(setOpts);
  7659. }
  7660. // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250
  7661. // WebKit can't even do simple things like selecting an image
  7662. // This also fixes so it's possible to select mceItemAnchors
  7663. if (tinymce.isWebKit) {
  7664. t.onClick.add(function(ed, e) {
  7665. e = e.target;
  7666. // Needs tobe the setBaseAndExtend or it will fail to select floated images
  7667. if (e.nodeName == 'IMG' || (e.nodeName == 'A' && dom.hasClass(e, 'mceItemAnchor'))) {
  7668. t.selection.getSel().setBaseAndExtent(e, 0, e, 1);
  7669. t.nodeChanged();
  7670. }
  7671. });
  7672. }
  7673. // Add node change handlers
  7674. t.onMouseUp.add(t.nodeChanged);
  7675. //t.onClick.add(t.nodeChanged);
  7676. t.onKeyUp.add(function(ed, e) {
  7677. var c = e.keyCode;
  7678. if ((c >= 33 && c <= 36) || (c >= 37 && c <= 40) || c == 13 || c == 45 || c == 46 || c == 8 || (tinymce.isMac && (c == 91 || c == 93)) || e.ctrlKey)
  7679. t.nodeChanged();
  7680. });
  7681. // Add reset handler
  7682. t.onReset.add(function() {
  7683. t.setContent(t.startContent, {format : 'raw'});
  7684. });
  7685. // Add shortcuts
  7686. if (s.custom_shortcuts) {
  7687. if (s.custom_undo_redo_keyboard_shortcuts) {
  7688. t.addShortcut('ctrl+z', t.getLang('undo_desc'), 'Undo');
  7689. t.addShortcut('ctrl+y', t.getLang('redo_desc'), 'Redo');
  7690. }
  7691. // Add default shortcuts for gecko
  7692. t.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold');
  7693. t.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic');
  7694. t.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline');
  7695. // BlockFormat shortcuts keys
  7696. for (i=1; i<=6; i++)
  7697. t.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]);
  7698. t.addShortcut('ctrl+7', '', ['FormatBlock', false, '<p>']);
  7699. t.addShortcut('ctrl+8', '', ['FormatBlock', false, '<div>']);
  7700. t.addShortcut('ctrl+9', '', ['FormatBlock', false, '<address>']);
  7701. function find(e) {
  7702. var v = null;
  7703. if (!e.altKey && !e.ctrlKey && !e.metaKey)
  7704. return v;
  7705. each(t.shortcuts, function(o) {
  7706. if (tinymce.isMac && o.ctrl != e.metaKey)
  7707. return;
  7708. else if (!tinymce.isMac && o.ctrl != e.ctrlKey)
  7709. return;
  7710. if (o.alt != e.altKey)
  7711. return;
  7712. if (o.shift != e.shiftKey)
  7713. return;
  7714. if (e.keyCode == o.keyCode || (e.charCode && e.charCode == o.charCode)) {
  7715. v = o;
  7716. return false;
  7717. }
  7718. });
  7719. return v;
  7720. };
  7721. t.onKeyUp.add(function(ed, e) {
  7722. var o = find(e);
  7723. if (o)
  7724. return Event.cancel(e);
  7725. });
  7726. t.onKeyPress.add(function(ed, e) {
  7727. var o = find(e);
  7728. if (o)
  7729. return Event.cancel(e);
  7730. });
  7731. t.onKeyDown.add(function(ed, e) {
  7732. var o = find(e);
  7733. if (o) {
  7734. o.func.call(o.scope);
  7735. return Event.cancel(e);
  7736. }
  7737. });
  7738. }
  7739. if (tinymce.isIE) {
  7740. // Fix so resize will only update the width and height attributes not the styles of an image
  7741. // It will also block mceItemNoResize items
  7742. dom.bind(t.getDoc(), 'controlselect', function(e) {
  7743. var re = t.resizeInfo, cb;
  7744. e = e.target;
  7745. // Don't do this action for non image elements
  7746. if (e.nodeName !== 'IMG')
  7747. return;
  7748. if (re)
  7749. dom.unbind(re.node, re.ev, re.cb);
  7750. if (!dom.hasClass(e, 'mceItemNoResize')) {
  7751. ev = 'resizeend';
  7752. cb = dom.bind(e, ev, function(e) {
  7753. var v;
  7754. e = e.target;
  7755. if (v = dom.getStyle(e, 'width')) {
  7756. dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, ''));
  7757. dom.setStyle(e, 'width', '');
  7758. }
  7759. if (v = dom.getStyle(e, 'height')) {
  7760. dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, ''));
  7761. dom.setStyle(e, 'height', '');
  7762. }
  7763. });
  7764. } else {
  7765. ev = 'resizestart';
  7766. cb = dom.bind(e, 'resizestart', Event.cancel, Event);
  7767. }
  7768. re = t.resizeInfo = {
  7769. node : e,
  7770. ev : ev,
  7771. cb : cb
  7772. };
  7773. });
  7774. t.onKeyDown.add(function(ed, e) {
  7775. switch (e.keyCode) {
  7776. case 8:
  7777. // Fix IE control + backspace browser bug
  7778. if (t.selection.getRng().item) {
  7779. ed.dom.remove(t.selection.getRng().item(0));
  7780. return Event.cancel(e);
  7781. }
  7782. }
  7783. });
  7784. /*if (t.dom.boxModel) {
  7785. t.getBody().style.height = '100%';
  7786. Event.add(t.getWin(), 'resize', function(e) {
  7787. var docElm = t.getDoc().documentElement;
  7788. docElm.style.height = (docElm.offsetHeight - 10) + 'px';
  7789. });
  7790. }*/
  7791. }
  7792. if (tinymce.isOpera) {
  7793. t.onClick.add(function(ed, e) {
  7794. Event.prevent(e);
  7795. });
  7796. }
  7797. // Add custom undo/redo handlers
  7798. if (s.custom_undo_redo) {
  7799. function addUndo() {
  7800. t.undoManager.typing = 0;
  7801. t.undoManager.add();
  7802. };
  7803. dom.bind(t.getDoc(), 'focusout', function(e) {
  7804. if (!t.removed && t.undoManager.typing)
  7805. addUndo();
  7806. });
  7807. t.onKeyUp.add(function(ed, e) {
  7808. if ((e.keyCode >= 33 && e.keyCode <= 36) || (e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 || e.keyCode == 45 || e.ctrlKey)
  7809. addUndo();
  7810. });
  7811. t.onKeyDown.add(function(ed, e) {
  7812. var rng, parent, bookmark;
  7813. // IE has a really odd bug where the DOM might include an node that doesn't have
  7814. // a proper structure. If you try to access nodeValue it would throw an illegal value exception.
  7815. // This seems to only happen when you delete contents and it seems to be avoidable if you refresh the element
  7816. // after you delete contents from it. See: #3008923
  7817. if (isIE && e.keyCode == 46) {
  7818. rng = t.selection.getRng();
  7819. if (rng.parentElement) {
  7820. parent = rng.parentElement();
  7821. // Select next word when ctrl key is used in combo with delete
  7822. if (e.ctrlKey) {
  7823. rng.moveEnd('word', 1);
  7824. rng.select();
  7825. }
  7826. // Delete contents
  7827. t.selection.getSel().clear();
  7828. // Check if we are within the same parent
  7829. if (rng.parentElement() == parent) {
  7830. bookmark = t.selection.getBookmark();
  7831. try {
  7832. // Update the HTML and hopefully it will remove the artifacts
  7833. parent.innerHTML = parent.innerHTML;
  7834. } catch (ex) {
  7835. // And since it's IE it can sometimes produce an unknown runtime error
  7836. }
  7837. // Restore the caret position
  7838. t.selection.moveToBookmark(bookmark);
  7839. }
  7840. // Block the default delete behavior since it might be broken
  7841. e.preventDefault();
  7842. return;
  7843. }
  7844. }
  7845. // Is caracter positon keys
  7846. if ((e.keyCode >= 33 && e.keyCode <= 36) || (e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 || e.keyCode == 45) {
  7847. if (t.undoManager.typing)
  7848. addUndo();
  7849. return;
  7850. }
  7851. if (!t.undoManager.typing) {
  7852. t.undoManager.add();
  7853. t.undoManager.typing = 1;
  7854. }
  7855. });
  7856. t.onMouseDown.add(function() {
  7857. if (t.undoManager.typing)
  7858. addUndo();
  7859. });
  7860. }
  7861. },
  7862. _isHidden : function() {
  7863. var s;
  7864. if (!isGecko)
  7865. return 0;
  7866. // Weird, wheres that cursor selection?
  7867. s = this.selection.getSel();
  7868. return (!s || !s.rangeCount || s.rangeCount == 0);
  7869. },
  7870. // Fix for bug #1867292
  7871. _fixNesting : function(s) {
  7872. var d = [], i;
  7873. s = s.replace(/<(\/)?([^\s>]+)[^>]*?>/g, function(a, b, c) {
  7874. var e;
  7875. // Handle end element
  7876. if (b === '/') {
  7877. if (!d.length)
  7878. return '';
  7879. if (c !== d[d.length - 1].tag) {
  7880. for (i=d.length - 1; i>=0; i--) {
  7881. if (d[i].tag === c) {
  7882. d[i].close = 1;
  7883. break;
  7884. }
  7885. }
  7886. return '';
  7887. } else {
  7888. d.pop();
  7889. if (d.length && d[d.length - 1].close) {
  7890. a = a + '</' + d[d.length - 1].tag + '>';
  7891. d.pop();
  7892. }
  7893. }
  7894. } else {
  7895. // Ignore these
  7896. if (/^(br|hr|input|meta|img|link|param)$/i.test(c))
  7897. return a;
  7898. // Ignore closed ones
  7899. if (/\/>$/.test(a))
  7900. return a;
  7901. d.push({tag : c}); // Push start element
  7902. }
  7903. return a;
  7904. });
  7905. // End all open tags
  7906. for (i=d.length - 1; i>=0; i--)
  7907. s += '</' + d[i].tag + '>';
  7908. return s;
  7909. }
  7910. });
  7911. })(tinymce);
  7912. (function(tinymce) {
  7913. // Added for compression purposes
  7914. var each = tinymce.each, undefined, TRUE = true, FALSE = false;
  7915. tinymce.EditorCommands = function(editor) {
  7916. var dom = editor.dom,
  7917. selection = editor.selection,
  7918. commands = {state: {}, exec : {}, value : {}},
  7919. settings = editor.settings,
  7920. bookmark;
  7921. function execCommand(command, ui, value) {
  7922. var func;
  7923. command = command.toLowerCase();
  7924. if (func = commands.exec[command]) {
  7925. func(command, ui, value);
  7926. return TRUE;
  7927. }
  7928. return FALSE;
  7929. };
  7930. function queryCommandState(command) {
  7931. var func;
  7932. command = command.toLowerCase();
  7933. if (func = commands.state[command])
  7934. return func(command);
  7935. return -1;
  7936. };
  7937. function queryCommandValue(command) {
  7938. var func;
  7939. command = command.toLowerCase();
  7940. if (func = commands.value[command])
  7941. return func(command);
  7942. return FALSE;
  7943. };
  7944. function addCommands(command_list, type) {
  7945. type = type || 'exec';
  7946. each(command_list, function(callback, command) {
  7947. each(command.toLowerCase().split(','), function(command) {
  7948. commands[type][command] = callback;
  7949. });
  7950. });
  7951. };
  7952. // Expose public methods
  7953. tinymce.extend(this, {
  7954. execCommand : execCommand,
  7955. queryCommandState : queryCommandState,
  7956. queryCommandValue : queryCommandValue,
  7957. addCommands : addCommands
  7958. });
  7959. // Private methods
  7960. function execNativeCommand(command, ui, value) {
  7961. if (ui === undefined)
  7962. ui = FALSE;
  7963. if (value === undefined)
  7964. value = null;
  7965. return editor.getDoc().execCommand(command, ui, value);
  7966. };
  7967. function isFormatMatch(name) {
  7968. return editor.formatter.match(name);
  7969. };
  7970. function toggleFormat(name, value) {
  7971. editor.formatter.toggle(name, value ? {value : value} : undefined);
  7972. };
  7973. function storeSelection(type) {
  7974. bookmark = selection.getBookmark(type);
  7975. };
  7976. function restoreSelection() {
  7977. selection.moveToBookmark(bookmark);
  7978. };
  7979. // Add execCommand overrides
  7980. addCommands({
  7981. // Ignore these, added for compatibility
  7982. 'mceResetDesignMode,mceBeginUndoLevel' : function() {},
  7983. // Add undo manager logic
  7984. 'mceEndUndoLevel,mceAddUndoLevel' : function() {
  7985. editor.undoManager.add();
  7986. },
  7987. 'Cut,Copy,Paste' : function(command) {
  7988. var doc = editor.getDoc(), failed;
  7989. // Try executing the native command
  7990. try {
  7991. execNativeCommand(command);
  7992. } catch (ex) {
  7993. // Command failed
  7994. failed = TRUE;
  7995. }
  7996. // Present alert message about clipboard access not being available
  7997. if (failed || !doc.queryCommandSupported(command)) {
  7998. if (tinymce.isGecko) {
  7999. editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) {
  8000. if (state)
  8001. open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank');
  8002. });
  8003. } else
  8004. editor.windowManager.alert(editor.getLang('clipboard_no_support'));
  8005. }
  8006. },
  8007. // Override unlink command
  8008. unlink : function(command) {
  8009. if (selection.isCollapsed())
  8010. selection.select(selection.getNode());
  8011. execNativeCommand(command);
  8012. selection.collapse(FALSE);
  8013. },
  8014. // Override justify commands to use the text formatter engine
  8015. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  8016. var align = command.substring(7);
  8017. // Remove all other alignments first
  8018. each('left,center,right,full'.split(','), function(name) {
  8019. if (align != name)
  8020. editor.formatter.remove('align' + name);
  8021. });
  8022. toggleFormat('align' + align);
  8023. },
  8024. // Override list commands to fix WebKit bug
  8025. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  8026. var listElm, listParent;
  8027. execNativeCommand(command);
  8028. // WebKit produces lists within block elements so we need to split them
  8029. // we will replace the native list creation logic to custom logic later on
  8030. // TODO: Remove this when the list creation logic is removed
  8031. listElm = dom.getParent(selection.getNode(), 'ol,ul');
  8032. if (listElm) {
  8033. listParent = listElm.parentNode;
  8034. // If list is within a text block then split that block
  8035. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  8036. storeSelection();
  8037. dom.split(listParent, listElm);
  8038. restoreSelection();
  8039. }
  8040. }
  8041. },
  8042. // Override commands to use the text formatter engine
  8043. 'Bold,Italic,Underline,Strikethrough' : function(command) {
  8044. toggleFormat(command);
  8045. },
  8046. // Override commands to use the text formatter engine
  8047. 'ForeColor,HiliteColor,FontName' : function(command, ui, value) {
  8048. toggleFormat(command, value);
  8049. },
  8050. FontSize : function(command, ui, value) {
  8051. var fontClasses, fontSizes;
  8052. // Convert font size 1-7 to styles
  8053. if (value >= 1 && value <= 7) {
  8054. fontSizes = tinymce.explode(settings.font_size_style_values);
  8055. fontClasses = tinymce.explode(settings.font_size_classes);
  8056. if (fontClasses)
  8057. value = fontClasses[value - 1] || value;
  8058. else
  8059. value = fontSizes[value - 1] || value;
  8060. }
  8061. toggleFormat(command, value);
  8062. },
  8063. RemoveFormat : function(command) {
  8064. editor.formatter.remove(command);
  8065. },
  8066. mceBlockQuote : function(command) {
  8067. toggleFormat('blockquote');
  8068. },
  8069. FormatBlock : function(command, ui, value) {
  8070. return toggleFormat(value || 'p');
  8071. },
  8072. mceCleanup : function() {
  8073. var bookmark = selection.getBookmark();
  8074. editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE});
  8075. selection.moveToBookmark(bookmark);
  8076. },
  8077. mceRemoveNode : function(command, ui, value) {
  8078. var node = value || selection.getNode();
  8079. // Make sure that the body node isn't removed
  8080. if (node != editor.getBody()) {
  8081. storeSelection();
  8082. editor.dom.remove(node, TRUE);
  8083. restoreSelection();
  8084. }
  8085. },
  8086. mceSelectNodeDepth : function(command, ui, value) {
  8087. var counter = 0;
  8088. dom.getParent(selection.getNode(), function(node) {
  8089. if (node.nodeType == 1 && counter++ == value) {
  8090. selection.select(node);
  8091. return FALSE;
  8092. }
  8093. }, editor.getBody());
  8094. },
  8095. mceSelectNode : function(command, ui, value) {
  8096. selection.select(value);
  8097. },
  8098. mceInsertContent : function(command, ui, value) {
  8099. selection.setContent(value);
  8100. },
  8101. mceInsertRawHTML : function(command, ui, value) {
  8102. selection.setContent('tiny_mce_marker');
  8103. editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value }));
  8104. },
  8105. mceSetContent : function(command, ui, value) {
  8106. editor.setContent(value);
  8107. },
  8108. 'Indent,Outdent' : function(command) {
  8109. var intentValue, indentUnit, value;
  8110. // Setup indent level
  8111. intentValue = settings.indentation;
  8112. indentUnit = /[a-z%]+$/i.exec(intentValue);
  8113. intentValue = parseInt(intentValue);
  8114. if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) {
  8115. each(selection.getSelectedBlocks(), function(element) {
  8116. if (command == 'outdent') {
  8117. value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue);
  8118. dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : '');
  8119. } else
  8120. dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit);
  8121. });
  8122. } else
  8123. execNativeCommand(command);
  8124. },
  8125. mceRepaint : function() {
  8126. var bookmark;
  8127. if (tinymce.isGecko) {
  8128. try {
  8129. storeSelection(TRUE);
  8130. if (selection.getSel())
  8131. selection.getSel().selectAllChildren(editor.getBody());
  8132. selection.collapse(TRUE);
  8133. restoreSelection();
  8134. } catch (ex) {
  8135. // Ignore
  8136. }
  8137. }
  8138. },
  8139. mceToggleFormat : function(command, ui, value) {
  8140. editor.formatter.toggle(value);
  8141. },
  8142. InsertHorizontalRule : function() {
  8143. selection.setContent('<hr />');
  8144. },
  8145. mceToggleVisualAid : function() {
  8146. editor.hasVisual = !editor.hasVisual;
  8147. editor.addVisual();
  8148. },
  8149. mceReplaceContent : function(command, ui, value) {
  8150. selection.setContent(value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'})));
  8151. },
  8152. mceInsertLink : function(command, ui, value) {
  8153. var link = dom.getParent(selection.getNode(), 'a');
  8154. if (tinymce.is(value, 'string'))
  8155. value = {href : value};
  8156. if (!link) {
  8157. execNativeCommand('CreateLink', FALSE, 'javascript:mctmp(0);');
  8158. each(dom.select('a[href=javascript:mctmp(0);]'), function(link) {
  8159. dom.setAttribs(link, value);
  8160. });
  8161. } else {
  8162. if (value.href)
  8163. dom.setAttribs(link, value);
  8164. else
  8165. editor.dom.remove(link, TRUE);
  8166. }
  8167. },
  8168. selectAll : function() {
  8169. var root = dom.getRoot(), rng = dom.createRng();
  8170. rng.setStart(root, 0);
  8171. rng.setEnd(root, root.childNodes.length);
  8172. editor.selection.setRng(rng);
  8173. }
  8174. });
  8175. // Add queryCommandState overrides
  8176. addCommands({
  8177. // Override justify commands
  8178. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  8179. return isFormatMatch('align' + command.substring(7));
  8180. },
  8181. 'Bold,Italic,Underline,Strikethrough' : function(command) {
  8182. return isFormatMatch(command);
  8183. },
  8184. mceBlockQuote : function() {
  8185. return isFormatMatch('blockquote');
  8186. },
  8187. Outdent : function() {
  8188. var node;
  8189. if (settings.inline_styles) {
  8190. if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  8191. return TRUE;
  8192. if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  8193. return TRUE;
  8194. }
  8195. return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE'));
  8196. },
  8197. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  8198. return dom.getParent(selection.getNode(), command == 'insertunorderedlist' ? 'UL' : 'OL');
  8199. }
  8200. }, 'state');
  8201. // Add queryCommandValue overrides
  8202. addCommands({
  8203. 'FontSize,FontName' : function(command) {
  8204. var value = 0, parent;
  8205. if (parent = dom.getParent(selection.getNode(), 'span')) {
  8206. if (command == 'fontsize')
  8207. value = parent.style.fontSize;
  8208. else
  8209. value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase();
  8210. }
  8211. return value;
  8212. }
  8213. }, 'value');
  8214. // Add undo manager logic
  8215. if (settings.custom_undo_redo) {
  8216. addCommands({
  8217. Undo : function() {
  8218. editor.undoManager.undo();
  8219. },
  8220. Redo : function() {
  8221. editor.undoManager.redo();
  8222. }
  8223. });
  8224. }
  8225. };
  8226. })(tinymce);
  8227. (function(tinymce) {
  8228. var Dispatcher = tinymce.util.Dispatcher;
  8229. tinymce.UndoManager = function(editor) {
  8230. var self, index = 0, data = [];
  8231. function getContent() {
  8232. return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}));
  8233. };
  8234. return self = {
  8235. typing : 0,
  8236. onAdd : new Dispatcher(self),
  8237. onUndo : new Dispatcher(self),
  8238. onRedo : new Dispatcher(self),
  8239. add : function(level) {
  8240. var i, settings = editor.settings, lastLevel;
  8241. level = level || {};
  8242. level.content = getContent();
  8243. // Add undo level if needed
  8244. lastLevel = data[index];
  8245. if (lastLevel && lastLevel.content == level.content) {
  8246. if (index > 0 || data.length == 1)
  8247. return null;
  8248. }
  8249. // Time to compress
  8250. if (settings.custom_undo_redo_levels) {
  8251. if (data.length > settings.custom_undo_redo_levels) {
  8252. for (i = 0; i < data.length - 1; i++)
  8253. data[i] = data[i + 1];
  8254. data.length--;
  8255. index = data.length;
  8256. }
  8257. }
  8258. // Get a non intrusive normalized bookmark
  8259. level.bookmark = editor.selection.getBookmark(2, true);
  8260. // Crop array if needed
  8261. if (index < data.length - 1) {
  8262. // Treat first level as initial
  8263. if (index == 0)
  8264. data = [];
  8265. else
  8266. data.length = index + 1;
  8267. }
  8268. data.push(level);
  8269. index = data.length - 1;
  8270. self.onAdd.dispatch(self, level);
  8271. editor.isNotDirty = 0;
  8272. return level;
  8273. },
  8274. undo : function() {
  8275. var level, i;
  8276. if (self.typing) {
  8277. self.add();
  8278. self.typing = 0;
  8279. }
  8280. if (index > 0) {
  8281. level = data[--index];
  8282. editor.setContent(level.content, {format : 'raw'});
  8283. editor.selection.moveToBookmark(level.bookmark);
  8284. self.onUndo.dispatch(self, level);
  8285. }
  8286. return level;
  8287. },
  8288. redo : function() {
  8289. var level;
  8290. if (index < data.length - 1) {
  8291. level = data[++index];
  8292. editor.setContent(level.content, {format : 'raw'});
  8293. editor.selection.moveToBookmark(level.bookmark);
  8294. self.onRedo.dispatch(self, level);
  8295. }
  8296. return level;
  8297. },
  8298. clear : function() {
  8299. data = [];
  8300. index = self.typing = 0;
  8301. },
  8302. hasUndo : function() {
  8303. return index > 0 || self.typing;
  8304. },
  8305. hasRedo : function() {
  8306. return index < data.length - 1;
  8307. }
  8308. };
  8309. };
  8310. })(tinymce);
  8311. (function(tinymce) {
  8312. // Shorten names
  8313. var Event = tinymce.dom.Event,
  8314. isIE = tinymce.isIE,
  8315. isGecko = tinymce.isGecko,
  8316. isOpera = tinymce.isOpera,
  8317. each = tinymce.each,
  8318. extend = tinymce.extend,
  8319. TRUE = true,
  8320. FALSE = false;
  8321. function cloneFormats(node) {
  8322. var clone, temp, inner;
  8323. do {
  8324. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) {
  8325. if (clone) {
  8326. temp = node.cloneNode(false);
  8327. temp.appendChild(clone);
  8328. clone = temp;
  8329. } else {
  8330. clone = inner = node.cloneNode(false);
  8331. }
  8332. clone.removeAttribute('id');
  8333. }
  8334. } while (node = node.parentNode);
  8335. if (clone)
  8336. return {wrapper : clone, inner : inner};
  8337. };
  8338. // Checks if the selection/caret is at the end of the specified block element
  8339. function isAtEnd(rng, par) {
  8340. var rng2 = par.ownerDocument.createRange();
  8341. rng2.setStart(rng.endContainer, rng.endOffset);
  8342. rng2.setEndAfter(par);
  8343. // Get number of characters to the right of the cursor if it's zero then we are at the end and need to merge the next block element
  8344. return rng2.cloneContents().textContent.length == 0;
  8345. };
  8346. function isEmpty(n) {
  8347. n = n.innerHTML;
  8348. n = n.replace(/<(img|hr|table|input|select|textarea)[ \>]/gi, '-'); // Keep these convert them to - chars
  8349. n = n.replace(/<[^>]+>/g, ''); // Remove all tags
  8350. return n.replace(/[ \u00a0\t\r\n]+/g, '') == '';
  8351. };
  8352. function splitList(selection, dom, li) {
  8353. var listBlock, block;
  8354. if (isEmpty(li)) {
  8355. listBlock = dom.getParent(li, 'ul,ol');
  8356. if (!dom.getParent(listBlock.parentNode, 'ul,ol')) {
  8357. dom.split(listBlock, li);
  8358. block = dom.create('p', 0, '<br _mce_bogus="1" />');
  8359. dom.replace(block, li);
  8360. selection.select(block, 1);
  8361. }
  8362. return FALSE;
  8363. }
  8364. return TRUE;
  8365. };
  8366. tinymce.create('tinymce.ForceBlocks', {
  8367. ForceBlocks : function(ed) {
  8368. var t = this, s = ed.settings, elm;
  8369. t.editor = ed;
  8370. t.dom = ed.dom;
  8371. elm = (s.forced_root_block || 'p').toLowerCase();
  8372. s.element = elm.toUpperCase();
  8373. ed.onPreInit.add(t.setup, t);
  8374. t.reOpera = new RegExp('(\\u00a0|&#160;|&nbsp;)<\/' + elm + '>', 'gi');
  8375. t.rePadd = new RegExp('<p( )([^>]+)><\\\/p>|<p( )([^>]+)\\\/>|<p( )([^>]+)>\\s+<\\\/p>|<p><\\\/p>|<p\\\/>|<p>\\s+<\\\/p>'.replace(/p/g, elm), 'gi');
  8376. t.reNbsp2BR1 = new RegExp('<p( )([^>]+)>[\\s\\u00a0]+<\\\/p>|<p>[\\s\\u00a0]+<\\\/p>'.replace(/p/g, elm), 'gi');
  8377. t.reNbsp2BR2 = new RegExp('<%p()([^>]+)>(&nbsp;|&#160;)<\\\/%p>|<%p>(&nbsp;|&#160;)<\\\/%p>'.replace(/%p/g, elm), 'gi');
  8378. t.reBR2Nbsp = new RegExp('<p( )([^>]+)>\\s*<br \\\/>\\s*<\\\/p>|<p>\\s*<br \\\/>\\s*<\\\/p>'.replace(/p/g, elm), 'gi');
  8379. function padd(ed, o) {
  8380. if (isOpera)
  8381. o.content = o.content.replace(t.reOpera, '</' + elm + '>');
  8382. o.content = tinymce._replace(t.rePadd, '<' + elm + '$1$2$3$4$5$6>\u00a0</' + elm + '>', o.content);
  8383. if (!isIE && !isOpera && o.set) {
  8384. // Use &nbsp; instead of BR in padded paragraphs
  8385. o.content = o.content.replace(t.reNbsp2BR1, '<' + elm + '$1$2><br /></' + elm + '>');
  8386. o.content = o.content.replace(t.reNbsp2BR2, '<' + elm + '$1$2><br /></' + elm + '>');
  8387. } else
  8388. o.content = tinymce._replace(t.reBR2Nbsp, '<' + elm + '$1$2>\u00a0</' + elm + '>', o.content);
  8389. };
  8390. ed.onBeforeSetContent.add(padd);
  8391. ed.onPostProcess.add(padd);
  8392. if (s.forced_root_block) {
  8393. ed.onInit.add(t.forceRoots, t);
  8394. ed.onSetContent.add(t.forceRoots, t);
  8395. ed.onBeforeGetContent.add(t.forceRoots, t);
  8396. }
  8397. },
  8398. setup : function() {
  8399. var t = this, ed = t.editor, s = ed.settings, dom = ed.dom, selection = ed.selection;
  8400. // Force root blocks when typing and when getting output
  8401. if (s.forced_root_block) {
  8402. ed.onBeforeExecCommand.add(t.forceRoots, t);
  8403. ed.onKeyUp.add(t.forceRoots, t);
  8404. ed.onPreProcess.add(t.forceRoots, t);
  8405. }
  8406. if (s.force_br_newlines) {
  8407. // Force IE to produce BRs on enter
  8408. if (isIE) {
  8409. ed.onKeyPress.add(function(ed, e) {
  8410. var n;
  8411. if (e.keyCode == 13 && selection.getNode().nodeName != 'LI') {
  8412. selection.setContent('<br id="__" /> ', {format : 'raw'});
  8413. n = dom.get('__');
  8414. n.removeAttribute('id');
  8415. selection.select(n);
  8416. selection.collapse();
  8417. return Event.cancel(e);
  8418. }
  8419. });
  8420. }
  8421. }
  8422. if (s.force_p_newlines) {
  8423. if (!isIE) {
  8424. ed.onKeyPress.add(function(ed, e) {
  8425. if (e.keyCode == 13 && !e.shiftKey && !t.insertPara(e))
  8426. Event.cancel(e);
  8427. });
  8428. } else {
  8429. // Ungly hack to for IE to preserve the formatting when you press
  8430. // enter at the end of a block element with formatted contents
  8431. // This logic overrides the browsers default logic with
  8432. // custom logic that enables us to control the output
  8433. tinymce.addUnload(function() {
  8434. t._previousFormats = 0; // Fix IE leak
  8435. });
  8436. ed.onKeyPress.add(function(ed, e) {
  8437. t._previousFormats = 0;
  8438. // Clone the current formats, this will later be applied to the new block contents
  8439. if (e.keyCode == 13 && !e.shiftKey && ed.selection.isCollapsed() && s.keep_styles)
  8440. t._previousFormats = cloneFormats(ed.selection.getStart());
  8441. });
  8442. ed.onKeyUp.add(function(ed, e) {
  8443. // Let IE break the element and the wrap the new caret location in the previous formats
  8444. if (e.keyCode == 13 && !e.shiftKey) {
  8445. var parent = ed.selection.getStart(), fmt = t._previousFormats;
  8446. // Parent is an empty block
  8447. if (!parent.hasChildNodes() && fmt) {
  8448. parent = dom.getParent(parent, dom.isBlock);
  8449. if (parent && parent.nodeName != 'LI') {
  8450. parent.innerHTML = '';
  8451. if (t._previousFormats) {
  8452. parent.appendChild(fmt.wrapper);
  8453. fmt.inner.innerHTML = '\uFEFF';
  8454. } else
  8455. parent.innerHTML = '\uFEFF';
  8456. selection.select(parent, 1);
  8457. ed.getDoc().execCommand('Delete', false, null);
  8458. t._previousFormats = 0;
  8459. }
  8460. }
  8461. }
  8462. });
  8463. }
  8464. if (isGecko) {
  8465. ed.onKeyDown.add(function(ed, e) {
  8466. if ((e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey)
  8467. t.backspaceDelete(e, e.keyCode == 8);
  8468. });
  8469. }
  8470. }
  8471. // Workaround for missing shift+enter support, http://bugs.webkit.org/show_bug.cgi?id=16973
  8472. if (tinymce.isWebKit) {
  8473. function insertBr(ed) {
  8474. var rng = selection.getRng(), br, div = dom.create('div', null, ' '), divYPos, vpHeight = dom.getViewPort(ed.getWin()).h;
  8475. // Insert BR element
  8476. rng.insertNode(br = dom.create('br'));
  8477. // Place caret after BR
  8478. rng.setStartAfter(br);
  8479. rng.setEndAfter(br);
  8480. selection.setRng(rng);
  8481. // Could not place caret after BR then insert an nbsp entity and move the caret
  8482. if (selection.getSel().focusNode == br.previousSibling) {
  8483. selection.select(dom.insertAfter(dom.doc.createTextNode('\u00a0'), br));
  8484. selection.collapse(TRUE);
  8485. }
  8486. // Create a temporary DIV after the BR and get the position as it
  8487. // seems like getPos() returns 0 for text nodes and BR elements.
  8488. dom.insertAfter(div, br);
  8489. divYPos = dom.getPos(div).y;
  8490. dom.remove(div);
  8491. // Scroll to new position, scrollIntoView can't be used due to bug: http://bugs.webkit.org/show_bug.cgi?id=16117
  8492. if (divYPos > vpHeight) // It is not necessary to scroll if the DIV is inside the view port.
  8493. ed.getWin().scrollTo(0, divYPos);
  8494. };
  8495. ed.onKeyPress.add(function(ed, e) {
  8496. if (e.keyCode == 13 && (e.shiftKey || (s.force_br_newlines && !dom.getParent(selection.getNode(), 'h1,h2,h3,h4,h5,h6,ol,ul')))) {
  8497. insertBr(ed);
  8498. Event.cancel(e);
  8499. }
  8500. });
  8501. }
  8502. // Padd empty inline elements within block elements
  8503. // For example: <p><strong><em></em></strong></p> becomes <p><strong><em>&nbsp;</em></strong></p>
  8504. ed.onPreProcess.add(function(ed, o) {
  8505. each(dom.select('p,h1,h2,h3,h4,h5,h6,div', o.node), function(p) {
  8506. if (isEmpty(p)) {
  8507. each(dom.select('span,em,strong,b,i', o.node), function(n) {
  8508. if (!n.hasChildNodes()) {
  8509. n.appendChild(ed.getDoc().createTextNode('\u00a0'));
  8510. return FALSE; // Break the loop one padding is enough
  8511. }
  8512. });
  8513. }
  8514. });
  8515. });
  8516. // IE specific fixes
  8517. if (isIE) {
  8518. // Replaces IE:s auto generated paragraphs with the specified element name
  8519. if (s.element != 'P') {
  8520. ed.onKeyPress.add(function(ed, e) {
  8521. t.lastElm = selection.getNode().nodeName;
  8522. });
  8523. ed.onKeyUp.add(function(ed, e) {
  8524. var bl, n = selection.getNode(), b = ed.getBody();
  8525. if (b.childNodes.length === 1 && n.nodeName == 'P') {
  8526. n = dom.rename(n, s.element);
  8527. selection.select(n);
  8528. selection.collapse();
  8529. ed.nodeChanged();
  8530. } else if (e.keyCode == 13 && !e.shiftKey && t.lastElm != 'P') {
  8531. bl = dom.getParent(n, 'p');
  8532. if (bl) {
  8533. dom.rename(bl, s.element);
  8534. ed.nodeChanged();
  8535. }
  8536. }
  8537. });
  8538. }
  8539. }
  8540. },
  8541. find : function(n, t, s) {
  8542. var ed = this.editor, w = ed.getDoc().createTreeWalker(n, 4, null, FALSE), c = -1;
  8543. while (n = w.nextNode()) {
  8544. c++;
  8545. // Index by node
  8546. if (t == 0 && n == s)
  8547. return c;
  8548. // Node by index
  8549. if (t == 1 && c == s)
  8550. return n;
  8551. }
  8552. return -1;
  8553. },
  8554. forceRoots : function(ed, e) {
  8555. var t = this, ed = t.editor, b = ed.getBody(), d = ed.getDoc(), se = ed.selection, s = se.getSel(), r = se.getRng(), si = -2, ei, so, eo, tr, c = -0xFFFFFF;
  8556. var nx, bl, bp, sp, le, nl = b.childNodes, i, n, eid;
  8557. // Fix for bug #1863847
  8558. //if (e && e.keyCode == 13)
  8559. // return TRUE;
  8560. // Wrap non blocks into blocks
  8561. for (i = nl.length - 1; i >= 0; i--) {
  8562. nx = nl[i];
  8563. // Ignore internal elements
  8564. if (nx.nodeType === 1 && nx.getAttribute('_mce_type')) {
  8565. bl = null;
  8566. continue;
  8567. }
  8568. // Is text or non block element
  8569. if (nx.nodeType === 3 || (!t.dom.isBlock(nx) && nx.nodeType !== 8 && !/^(script|mce:script|style|mce:style)$/i.test(nx.nodeName))) {
  8570. if (!bl) {
  8571. // Create new block but ignore whitespace
  8572. if (nx.nodeType != 3 || /[^\s]/g.test(nx.nodeValue)) {
  8573. // Store selection
  8574. if (si == -2 && r) {
  8575. if (!isIE || r.setStart) {
  8576. // If selection is element then mark it
  8577. if (r.startContainer.nodeType == 1 && (n = r.startContainer.childNodes[r.startOffset]) && n.nodeType == 1) {
  8578. // Save the id of the selected element
  8579. eid = n.getAttribute("id");
  8580. n.setAttribute("id", "__mce");
  8581. } else {
  8582. // If element is inside body, might not be the case in contentEdiable mode
  8583. if (ed.dom.getParent(r.startContainer, function(e) {return e === b;})) {
  8584. so = r.startOffset;
  8585. eo = r.endOffset;
  8586. si = t.find(b, 0, r.startContainer);
  8587. ei = t.find(b, 0, r.endContainer);
  8588. }
  8589. }
  8590. } else {
  8591. // Force control range into text range
  8592. if (r.item) {
  8593. tr = d.body.createTextRange();
  8594. tr.moveToElementText(r.item(0));
  8595. r = tr;
  8596. }
  8597. tr = d.body.createTextRange();
  8598. tr.moveToElementText(b);
  8599. tr.collapse(1);
  8600. bp = tr.move('character', c) * -1;
  8601. tr = r.duplicate();
  8602. tr.collapse(1);
  8603. sp = tr.move('character', c) * -1;
  8604. tr = r.duplicate();
  8605. tr.collapse(0);
  8606. le = (tr.move('character', c) * -1) - sp;
  8607. si = sp - bp;
  8608. ei = le;
  8609. }
  8610. }
  8611. // Uses replaceChild instead of cloneNode since it removes selected attribute from option elements on IE
  8612. // See: http://support.microsoft.com/kb/829907
  8613. bl = ed.dom.create(ed.settings.forced_root_block);
  8614. nx.parentNode.replaceChild(bl, nx);
  8615. bl.appendChild(nx);
  8616. }
  8617. } else {
  8618. if (bl.hasChildNodes())
  8619. bl.insertBefore(nx, bl.firstChild);
  8620. else
  8621. bl.appendChild(nx);
  8622. }
  8623. } else
  8624. bl = null; // Time to create new block
  8625. }
  8626. // Restore selection
  8627. if (si != -2) {
  8628. if (!isIE || r.setStart) {
  8629. bl = b.getElementsByTagName(ed.settings.element)[0];
  8630. r = d.createRange();
  8631. // Select last location or generated block
  8632. if (si != -1)
  8633. r.setStart(t.find(b, 1, si), so);
  8634. else
  8635. r.setStart(bl, 0);
  8636. // Select last location or generated block
  8637. if (ei != -1)
  8638. r.setEnd(t.find(b, 1, ei), eo);
  8639. else
  8640. r.setEnd(bl, 0);
  8641. if (s) {
  8642. s.removeAllRanges();
  8643. s.addRange(r);
  8644. }
  8645. } else {
  8646. try {
  8647. r = s.createRange();
  8648. r.moveToElementText(b);
  8649. r.collapse(1);
  8650. r.moveStart('character', si);
  8651. r.moveEnd('character', ei);
  8652. r.select();
  8653. } catch (ex) {
  8654. // Ignore
  8655. }
  8656. }
  8657. } else if ((!isIE || r.setStart) && (n = ed.dom.get('__mce'))) {
  8658. // Restore the id of the selected element
  8659. if (eid)
  8660. n.setAttribute('id', eid);
  8661. else
  8662. n.removeAttribute('id');
  8663. // Move caret before selected element
  8664. r = d.createRange();
  8665. r.setStartBefore(n);
  8666. r.setEndBefore(n);
  8667. se.setRng(r);
  8668. }
  8669. },
  8670. getParentBlock : function(n) {
  8671. var d = this.dom;
  8672. return d.getParent(n, d.isBlock);
  8673. },
  8674. insertPara : function(e) {
  8675. var t = this, ed = t.editor, dom = ed.dom, d = ed.getDoc(), se = ed.settings, s = ed.selection.getSel(), r = s.getRangeAt(0), b = d.body;
  8676. var rb, ra, dir, sn, so, en, eo, sb, eb, bn, bef, aft, sc, ec, n, vp = dom.getViewPort(ed.getWin()), y, ch, car;
  8677. // If root blocks are forced then use Operas default behavior since it's really good
  8678. // Removed due to bug: #1853816
  8679. // if (se.forced_root_block && isOpera)
  8680. // return TRUE;
  8681. // Setup before range
  8682. rb = d.createRange();
  8683. // If is before the first block element and in body, then move it into first block element
  8684. rb.setStart(s.anchorNode, s.anchorOffset);
  8685. rb.collapse(TRUE);
  8686. // Setup after range
  8687. ra = d.createRange();
  8688. // If is before the first block element and in body, then move it into first block element
  8689. ra.setStart(s.focusNode, s.focusOffset);
  8690. ra.collapse(TRUE);
  8691. // Setup start/end points
  8692. dir = rb.compareBoundaryPoints(rb.START_TO_END, ra) < 0;
  8693. sn = dir ? s.anchorNode : s.focusNode;
  8694. so = dir ? s.anchorOffset : s.focusOffset;
  8695. en = dir ? s.focusNode : s.anchorNode;
  8696. eo = dir ? s.focusOffset : s.anchorOffset;
  8697. // If selection is in empty table cell
  8698. if (sn === en && /^(TD|TH)$/.test(sn.nodeName)) {
  8699. if (sn.firstChild.nodeName == 'BR')
  8700. dom.remove(sn.firstChild); // Remove BR
  8701. // Create two new block elements
  8702. if (sn.childNodes.length == 0) {
  8703. ed.dom.add(sn, se.element, null, '<br />');
  8704. aft = ed.dom.add(sn, se.element, null, '<br />');
  8705. } else {
  8706. n = sn.innerHTML;
  8707. sn.innerHTML = '';
  8708. ed.dom.add(sn, se.element, null, n);
  8709. aft = ed.dom.add(sn, se.element, null, '<br />');
  8710. }
  8711. // Move caret into the last one
  8712. r = d.createRange();
  8713. r.selectNodeContents(aft);
  8714. r.collapse(1);
  8715. ed.selection.setRng(r);
  8716. return FALSE;
  8717. }
  8718. // If the caret is in an invalid location in FF we need to move it into the first block
  8719. if (sn == b && en == b && b.firstChild && ed.dom.isBlock(b.firstChild)) {
  8720. sn = en = sn.firstChild;
  8721. so = eo = 0;
  8722. rb = d.createRange();
  8723. rb.setStart(sn, 0);
  8724. ra = d.createRange();
  8725. ra.setStart(en, 0);
  8726. }
  8727. // Never use body as start or end node
  8728. sn = sn.nodeName == "HTML" ? d.body : sn; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  8729. sn = sn.nodeName == "BODY" ? sn.firstChild : sn;
  8730. en = en.nodeName == "HTML" ? d.body : en; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  8731. en = en.nodeName == "BODY" ? en.firstChild : en;
  8732. // Get start and end blocks
  8733. sb = t.getParentBlock(sn);
  8734. eb = t.getParentBlock(en);
  8735. bn = sb ? sb.nodeName : se.element; // Get block name to create
  8736. // Return inside list use default browser behavior
  8737. if (n = t.dom.getParent(sb, 'li,pre')) {
  8738. if (n.nodeName == 'LI')
  8739. return splitList(ed.selection, t.dom, n);
  8740. return TRUE;
  8741. }
  8742. // If caption or absolute layers then always generate new blocks within
  8743. if (sb && (sb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  8744. bn = se.element;
  8745. sb = null;
  8746. }
  8747. // If caption or absolute layers then always generate new blocks within
  8748. if (eb && (eb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  8749. bn = se.element;
  8750. eb = null;
  8751. }
  8752. // Use P instead
  8753. if (/(TD|TABLE|TH|CAPTION)/.test(bn) || (sb && bn == "DIV" && /left|right/gi.test(dom.getStyle(sb, 'float', 1)))) {
  8754. bn = se.element;
  8755. sb = eb = null;
  8756. }
  8757. // Setup new before and after blocks
  8758. bef = (sb && sb.nodeName == bn) ? sb.cloneNode(0) : ed.dom.create(bn);
  8759. aft = (eb && eb.nodeName == bn) ? eb.cloneNode(0) : ed.dom.create(bn);
  8760. // Remove id from after clone
  8761. aft.removeAttribute('id');
  8762. // Is header and cursor is at the end, then force paragraph under
  8763. if (/^(H[1-6])$/.test(bn) && isAtEnd(r, sb))
  8764. aft = ed.dom.create(se.element);
  8765. // Find start chop node
  8766. n = sc = sn;
  8767. do {
  8768. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  8769. break;
  8770. sc = n;
  8771. } while ((n = n.previousSibling ? n.previousSibling : n.parentNode));
  8772. // Find end chop node
  8773. n = ec = en;
  8774. do {
  8775. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  8776. break;
  8777. ec = n;
  8778. } while ((n = n.nextSibling ? n.nextSibling : n.parentNode));
  8779. // Place first chop part into before block element
  8780. if (sc.nodeName == bn)
  8781. rb.setStart(sc, 0);
  8782. else
  8783. rb.setStartBefore(sc);
  8784. rb.setEnd(sn, so);
  8785. bef.appendChild(rb.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  8786. // Place secnd chop part within new block element
  8787. try {
  8788. ra.setEndAfter(ec);
  8789. } catch(ex) {
  8790. //console.debug(s.focusNode, s.focusOffset);
  8791. }
  8792. ra.setStart(en, eo);
  8793. aft.appendChild(ra.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  8794. // Create range around everything
  8795. r = d.createRange();
  8796. if (!sc.previousSibling && sc.parentNode.nodeName == bn) {
  8797. r.setStartBefore(sc.parentNode);
  8798. } else {
  8799. if (rb.startContainer.nodeName == bn && rb.startOffset == 0)
  8800. r.setStartBefore(rb.startContainer);
  8801. else
  8802. r.setStart(rb.startContainer, rb.startOffset);
  8803. }
  8804. if (!ec.nextSibling && ec.parentNode.nodeName == bn)
  8805. r.setEndAfter(ec.parentNode);
  8806. else
  8807. r.setEnd(ra.endContainer, ra.endOffset);
  8808. // Delete and replace it with new block elements
  8809. r.deleteContents();
  8810. if (isOpera)
  8811. ed.getWin().scrollTo(0, vp.y);
  8812. // Never wrap blocks in blocks
  8813. if (bef.firstChild && bef.firstChild.nodeName == bn)
  8814. bef.innerHTML = bef.firstChild.innerHTML;
  8815. if (aft.firstChild && aft.firstChild.nodeName == bn)
  8816. aft.innerHTML = aft.firstChild.innerHTML;
  8817. // Padd empty blocks
  8818. if (isEmpty(bef))
  8819. bef.innerHTML = '<br />';
  8820. function appendStyles(e, en) {
  8821. var nl = [], nn, n, i;
  8822. e.innerHTML = '';
  8823. // Make clones of style elements
  8824. if (se.keep_styles) {
  8825. n = en;
  8826. do {
  8827. // We only want style specific elements
  8828. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(n.nodeName)) {
  8829. nn = n.cloneNode(FALSE);
  8830. dom.setAttrib(nn, 'id', ''); // Remove ID since it needs to be unique
  8831. nl.push(nn);
  8832. }
  8833. } while (n = n.parentNode);
  8834. }
  8835. // Append style elements to aft
  8836. if (nl.length > 0) {
  8837. for (i = nl.length - 1, nn = e; i >= 0; i--)
  8838. nn = nn.appendChild(nl[i]);
  8839. // Padd most inner style element
  8840. nl[0].innerHTML = isOpera ? '&nbsp;' : '<br />'; // Extra space for Opera so that the caret can move there
  8841. return nl[0]; // Move caret to most inner element
  8842. } else
  8843. e.innerHTML = isOpera ? '&nbsp;' : '<br />'; // Extra space for Opera so that the caret can move there
  8844. };
  8845. // Fill empty afterblook with current style
  8846. if (isEmpty(aft))
  8847. car = appendStyles(aft, en);
  8848. // Opera needs this one backwards for older versions
  8849. if (isOpera && parseFloat(opera.version()) < 9.5) {
  8850. r.insertNode(bef);
  8851. r.insertNode(aft);
  8852. } else {
  8853. r.insertNode(aft);
  8854. r.insertNode(bef);
  8855. }
  8856. // Normalize
  8857. aft.normalize();
  8858. bef.normalize();
  8859. function first(n) {
  8860. return d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE).nextNode() || n;
  8861. };
  8862. // Move cursor and scroll into view
  8863. r = d.createRange();
  8864. r.selectNodeContents(isGecko ? first(car || aft) : car || aft);
  8865. r.collapse(1);
  8866. s.removeAllRanges();
  8867. s.addRange(r);
  8868. // scrollIntoView seems to scroll the parent window in most browsers now including FF 3.0b4 so it's time to stop using it and do it our selfs
  8869. y = ed.dom.getPos(aft).y;
  8870. ch = aft.clientHeight;
  8871. // Is element within viewport
  8872. if (y < vp.y || y + ch > vp.y + vp.h) {
  8873. ed.getWin().scrollTo(0, y < vp.y ? y : y - vp.h + 25); // Needs to be hardcoded to roughly one line of text if a huge text block is broken into two blocks
  8874. //console.debug('SCROLL!', 'vp.y: ' + vp.y, 'y' + y, 'vp.h' + vp.h, 'clientHeight' + aft.clientHeight, 'yyy: ' + (y < vp.y ? y : y - vp.h + aft.clientHeight));
  8875. }
  8876. return FALSE;
  8877. },
  8878. backspaceDelete : function(e, bs) {
  8879. var t = this, ed = t.editor, b = ed.getBody(), dom = ed.dom, n, se = ed.selection, r = se.getRng(), sc = r.startContainer, n, w, tn, walker;
  8880. // Delete when caret is behind a element doesn't work correctly on Gecko see #3011651
  8881. if (!bs && r.collapsed && sc.nodeType == 1 && r.startOffset == sc.childNodes.length) {
  8882. walker = new tinymce.dom.TreeWalker(sc.lastChild, sc);
  8883. // Walk the dom backwards until we find a text node
  8884. for (n = sc.lastChild; n; n = walker.prev()) {
  8885. if (n.nodeType == 3) {
  8886. r.setStart(n, n.nodeValue.length);
  8887. r.collapse(true);
  8888. se.setRng(r);
  8889. return;
  8890. }
  8891. }
  8892. }
  8893. // The caret sometimes gets stuck in Gecko if you delete empty paragraphs
  8894. // This workaround removes the element by hand and moves the caret to the previous element
  8895. if (sc && ed.dom.isBlock(sc) && !/^(TD|TH)$/.test(sc.nodeName) && bs) {
  8896. if (sc.childNodes.length == 0 || (sc.childNodes.length == 1 && sc.firstChild.nodeName == 'BR')) {
  8897. // Find previous block element
  8898. n = sc;
  8899. while ((n = n.previousSibling) && !ed.dom.isBlock(n)) ;
  8900. if (n) {
  8901. if (sc != b.firstChild) {
  8902. // Find last text node
  8903. w = ed.dom.doc.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE);
  8904. while (tn = w.nextNode())
  8905. n = tn;
  8906. // Place caret at the end of last text node
  8907. r = ed.getDoc().createRange();
  8908. r.setStart(n, n.nodeValue ? n.nodeValue.length : 0);
  8909. r.setEnd(n, n.nodeValue ? n.nodeValue.length : 0);
  8910. se.setRng(r);
  8911. // Remove the target container
  8912. ed.dom.remove(sc);
  8913. }
  8914. return Event.cancel(e);
  8915. }
  8916. }
  8917. }
  8918. }
  8919. });
  8920. })(tinymce);
  8921. (function(tinymce) {
  8922. // Shorten names
  8923. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend;
  8924. tinymce.create('tinymce.ControlManager', {
  8925. ControlManager : function(ed, s) {
  8926. var t = this, i;
  8927. s = s || {};
  8928. t.editor = ed;
  8929. t.controls = {};
  8930. t.onAdd = new tinymce.util.Dispatcher(t);
  8931. t.onPostRender = new tinymce.util.Dispatcher(t);
  8932. t.prefix = s.prefix || ed.id + '_';
  8933. t._cls = {};
  8934. t.onPostRender.add(function() {
  8935. each(t.controls, function(c) {
  8936. c.postRender();
  8937. });
  8938. });
  8939. },
  8940. get : function(id) {
  8941. return this.controls[this.prefix + id] || this.controls[id];
  8942. },
  8943. setActive : function(id, s) {
  8944. var c = null;
  8945. if (c = this.get(id))
  8946. c.setActive(s);
  8947. return c;
  8948. },
  8949. setDisabled : function(id, s) {
  8950. var c = null;
  8951. if (c = this.get(id))
  8952. c.setDisabled(s);
  8953. return c;
  8954. },
  8955. add : function(c) {
  8956. var t = this;
  8957. if (c) {
  8958. t.controls[c.id] = c;
  8959. t.onAdd.dispatch(c, t);
  8960. }
  8961. return c;
  8962. },
  8963. createControl : function(n) {
  8964. var c, t = this, ed = t.editor;
  8965. each(ed.plugins, function(p) {
  8966. if (p.createControl) {
  8967. c = p.createControl(n, t);
  8968. if (c)
  8969. return false;
  8970. }
  8971. });
  8972. switch (n) {
  8973. case "|":
  8974. case "separator":
  8975. return t.createSeparator();
  8976. }
  8977. if (!c && ed.buttons && (c = ed.buttons[n]))
  8978. return t.createButton(n, c);
  8979. return t.add(c);
  8980. },
  8981. createDropMenu : function(id, s, cc) {
  8982. var t = this, ed = t.editor, c, bm, v, cls;
  8983. s = extend({
  8984. 'class' : 'mceDropDown',
  8985. constrain : ed.settings.constrain_menus
  8986. }, s);
  8987. s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin';
  8988. if (v = ed.getParam('skin_variant'))
  8989. s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1);
  8990. id = t.prefix + id;
  8991. cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu;
  8992. c = t.controls[id] = new cls(id, s);
  8993. c.onAddItem.add(function(c, o) {
  8994. var s = o.settings;
  8995. s.title = ed.getLang(s.title, s.title);
  8996. if (!s.onclick) {
  8997. s.onclick = function(v) {
  8998. if (s.cmd)
  8999. ed.execCommand(s.cmd, s.ui || false, s.value);
  9000. };
  9001. }
  9002. });
  9003. ed.onRemove.add(function() {
  9004. c.destroy();
  9005. });
  9006. // Fix for bug #1897785, #1898007
  9007. if (tinymce.isIE) {
  9008. c.onShowMenu.add(function() {
  9009. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  9010. ed.focus();
  9011. bm = ed.selection.getBookmark(1);
  9012. });
  9013. c.onHideMenu.add(function() {
  9014. if (bm) {
  9015. ed.selection.moveToBookmark(bm);
  9016. bm = 0;
  9017. }
  9018. });
  9019. }
  9020. return t.add(c);
  9021. },
  9022. createListBox : function(id, s, cc) {
  9023. var t = this, ed = t.editor, cmd, c, cls;
  9024. if (t.get(id))
  9025. return null;
  9026. s.title = ed.translate(s.title);
  9027. s.scope = s.scope || ed;
  9028. if (!s.onselect) {
  9029. s.onselect = function(v) {
  9030. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  9031. };
  9032. }
  9033. s = extend({
  9034. title : s.title,
  9035. 'class' : 'mce_' + id,
  9036. scope : s.scope,
  9037. control_manager : t
  9038. }, s);
  9039. id = t.prefix + id;
  9040. if (ed.settings.use_native_selects)
  9041. c = new tinymce.ui.NativeListBox(id, s);
  9042. else {
  9043. cls = cc || t._cls.listbox || tinymce.ui.ListBox;
  9044. c = new cls(id, s);
  9045. }
  9046. t.controls[id] = c;
  9047. // Fix focus problem in Safari
  9048. if (tinymce.isWebKit) {
  9049. c.onPostRender.add(function(c, n) {
  9050. // Store bookmark on mousedown
  9051. Event.add(n, 'mousedown', function() {
  9052. ed.bookmark = ed.selection.getBookmark(1);
  9053. });
  9054. // Restore on focus, since it might be lost
  9055. Event.add(n, 'focus', function() {
  9056. ed.selection.moveToBookmark(ed.bookmark);
  9057. ed.bookmark = null;
  9058. });
  9059. });
  9060. }
  9061. if (c.hideMenu)
  9062. ed.onMouseDown.add(c.hideMenu, c);
  9063. return t.add(c);
  9064. },
  9065. createButton : function(id, s, cc) {
  9066. var t = this, ed = t.editor, o, c, cls;
  9067. if (t.get(id))
  9068. return null;
  9069. s.title = ed.translate(s.title);
  9070. s.label = ed.translate(s.label);
  9071. s.scope = s.scope || ed;
  9072. if (!s.onclick && !s.menu_button) {
  9073. s.onclick = function() {
  9074. ed.execCommand(s.cmd, s.ui || false, s.value);
  9075. };
  9076. }
  9077. s = extend({
  9078. title : s.title,
  9079. 'class' : 'mce_' + id,
  9080. unavailable_prefix : ed.getLang('unavailable', ''),
  9081. scope : s.scope,
  9082. control_manager : t
  9083. }, s);
  9084. id = t.prefix + id;
  9085. if (s.menu_button) {
  9086. cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
  9087. c = new cls(id, s);
  9088. ed.onMouseDown.add(c.hideMenu, c);
  9089. } else {
  9090. cls = t._cls.button || tinymce.ui.Button;
  9091. c = new cls(id, s);
  9092. }
  9093. return t.add(c);
  9094. },
  9095. createMenuButton : function(id, s, cc) {
  9096. s = s || {};
  9097. s.menu_button = 1;
  9098. return this.createButton(id, s, cc);
  9099. },
  9100. createSplitButton : function(id, s, cc) {
  9101. var t = this, ed = t.editor, cmd, c, cls;
  9102. if (t.get(id))
  9103. return null;
  9104. s.title = ed.translate(s.title);
  9105. s.scope = s.scope || ed;
  9106. if (!s.onclick) {
  9107. s.onclick = function(v) {
  9108. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  9109. };
  9110. }
  9111. if (!s.onselect) {
  9112. s.onselect = function(v) {
  9113. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  9114. };
  9115. }
  9116. s = extend({
  9117. title : s.title,
  9118. 'class' : 'mce_' + id,
  9119. scope : s.scope,
  9120. control_manager : t
  9121. }, s);
  9122. id = t.prefix + id;
  9123. cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
  9124. c = t.add(new cls(id, s));
  9125. ed.onMouseDown.add(c.hideMenu, c);
  9126. return c;
  9127. },
  9128. createColorSplitButton : function(id, s, cc) {
  9129. var t = this, ed = t.editor, cmd, c, cls, bm;
  9130. if (t.get(id))
  9131. return null;
  9132. s.title = ed.translate(s.title);
  9133. s.scope = s.scope || ed;
  9134. if (!s.onclick) {
  9135. s.onclick = function(v) {
  9136. if (tinymce.isIE)
  9137. bm = ed.selection.getBookmark(1);
  9138. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  9139. };
  9140. }
  9141. if (!s.onselect) {
  9142. s.onselect = function(v) {
  9143. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  9144. };
  9145. }
  9146. s = extend({
  9147. title : s.title,
  9148. 'class' : 'mce_' + id,
  9149. 'menu_class' : ed.getParam('skin') + 'Skin',
  9150. scope : s.scope,
  9151. more_colors_title : ed.getLang('more_colors')
  9152. }, s);
  9153. id = t.prefix + id;
  9154. cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
  9155. c = new cls(id, s);
  9156. ed.onMouseDown.add(c.hideMenu, c);
  9157. // Remove the menu element when the editor is removed
  9158. ed.onRemove.add(function() {
  9159. c.destroy();
  9160. });
  9161. // Fix for bug #1897785, #1898007
  9162. if (tinymce.isIE) {
  9163. c.onShowMenu.add(function() {
  9164. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  9165. ed.focus();
  9166. bm = ed.selection.getBookmark(1);
  9167. });
  9168. c.onHideMenu.add(function() {
  9169. if (bm) {
  9170. ed.selection.moveToBookmark(bm);
  9171. bm = 0;
  9172. }
  9173. });
  9174. }
  9175. return t.add(c);
  9176. },
  9177. createToolbar : function(id, s, cc) {
  9178. var c, t = this, cls;
  9179. id = t.prefix + id;
  9180. cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
  9181. c = new cls(id, s);
  9182. if (t.get(id))
  9183. return null;
  9184. return t.add(c);
  9185. },
  9186. createSeparator : function(cc) {
  9187. var cls = cc || this._cls.separator || tinymce.ui.Separator;
  9188. return new cls();
  9189. },
  9190. setControlType : function(n, c) {
  9191. return this._cls[n.toLowerCase()] = c;
  9192. },
  9193. destroy : function() {
  9194. each(this.controls, function(c) {
  9195. c.destroy();
  9196. });
  9197. this.controls = null;
  9198. }
  9199. });
  9200. })(tinymce);
  9201. (function(tinymce) {
  9202. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera;
  9203. tinymce.create('tinymce.WindowManager', {
  9204. WindowManager : function(ed) {
  9205. var t = this;
  9206. t.editor = ed;
  9207. t.onOpen = new Dispatcher(t);
  9208. t.onClose = new Dispatcher(t);
  9209. t.params = {};
  9210. t.features = {};
  9211. },
  9212. open : function(s, p) {
  9213. var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u;
  9214. // Default some options
  9215. s = s || {};
  9216. p = p || {};
  9217. sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window
  9218. sh = isOpera ? vp.h : screen.height;
  9219. s.name = s.name || 'mc_' + new Date().getTime();
  9220. s.width = parseInt(s.width || 320);
  9221. s.height = parseInt(s.height || 240);
  9222. s.resizable = true;
  9223. s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0);
  9224. s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0);
  9225. p.inline = false;
  9226. p.mce_width = s.width;
  9227. p.mce_height = s.height;
  9228. p.mce_auto_focus = s.auto_focus;
  9229. if (mo) {
  9230. if (isIE) {
  9231. s.center = true;
  9232. s.help = false;
  9233. s.dialogWidth = s.width + 'px';
  9234. s.dialogHeight = s.height + 'px';
  9235. s.scroll = s.scrollbars || false;
  9236. }
  9237. }
  9238. // Build features string
  9239. each(s, function(v, k) {
  9240. if (tinymce.is(v, 'boolean'))
  9241. v = v ? 'yes' : 'no';
  9242. if (!/^(name|url)$/.test(k)) {
  9243. if (isIE && mo)
  9244. f += (f ? ';' : '') + k + ':' + v;
  9245. else
  9246. f += (f ? ',' : '') + k + '=' + v;
  9247. }
  9248. });
  9249. t.features = s;
  9250. t.params = p;
  9251. t.onOpen.dispatch(t, s, p);
  9252. u = s.url || s.file;
  9253. u = tinymce._addVer(u);
  9254. try {
  9255. if (isIE && mo) {
  9256. w = 1;
  9257. window.showModalDialog(u, window, f);
  9258. } else
  9259. w = window.open(u, s.name, f);
  9260. } catch (ex) {
  9261. // Ignore
  9262. }
  9263. if (!w)
  9264. alert(t.editor.getLang('popup_blocked'));
  9265. },
  9266. close : function(w) {
  9267. w.close();
  9268. this.onClose.dispatch(this);
  9269. },
  9270. createInstance : function(cl, a, b, c, d, e) {
  9271. var f = tinymce.resolve(cl);
  9272. return new f(a, b, c, d, e);
  9273. },
  9274. confirm : function(t, cb, s, w) {
  9275. w = w || window;
  9276. cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t))));
  9277. },
  9278. alert : function(tx, cb, s, w) {
  9279. var t = this;
  9280. w = w || window;
  9281. w.alert(t._decode(t.editor.getLang(tx, tx)));
  9282. if (cb)
  9283. cb.call(s || t);
  9284. },
  9285. resizeBy : function(dw, dh, win) {
  9286. win.resizeBy(dw, dh);
  9287. },
  9288. // Internal functions
  9289. _decode : function(s) {
  9290. return tinymce.DOM.decode(s).replace(/\\n/g, '\n');
  9291. }
  9292. });
  9293. }(tinymce));
  9294. (function(tinymce) {
  9295. function CommandManager() {
  9296. var execCommands = {}, queryStateCommands = {}, queryValueCommands = {};
  9297. function add(collection, cmd, func, scope) {
  9298. if (typeof(cmd) == 'string')
  9299. cmd = [cmd];
  9300. tinymce.each(cmd, function(cmd) {
  9301. collection[cmd.toLowerCase()] = {func : func, scope : scope};
  9302. });
  9303. };
  9304. tinymce.extend(this, {
  9305. add : function(cmd, func, scope) {
  9306. add(execCommands, cmd, func, scope);
  9307. },
  9308. addQueryStateHandler : function(cmd, func, scope) {
  9309. add(queryStateCommands, cmd, func, scope);
  9310. },
  9311. addQueryValueHandler : function(cmd, func, scope) {
  9312. add(queryValueCommands, cmd, func, scope);
  9313. },
  9314. execCommand : function(scope, cmd, ui, value, args) {
  9315. if (cmd = execCommands[cmd.toLowerCase()]) {
  9316. if (cmd.func.call(scope || cmd.scope, ui, value, args) !== false)
  9317. return true;
  9318. }
  9319. },
  9320. queryCommandValue : function() {
  9321. if (cmd = queryValueCommands[cmd.toLowerCase()])
  9322. return cmd.func.call(scope || cmd.scope, ui, value, args);
  9323. },
  9324. queryCommandState : function() {
  9325. if (cmd = queryStateCommands[cmd.toLowerCase()])
  9326. return cmd.func.call(scope || cmd.scope, ui, value, args);
  9327. }
  9328. });
  9329. };
  9330. tinymce.GlobalCommands = new CommandManager();
  9331. })(tinymce);
  9332. (function(tinymce) {
  9333. tinymce.Formatter = function(ed) {
  9334. var formats = {},
  9335. each = tinymce.each,
  9336. dom = ed.dom,
  9337. selection = ed.selection,
  9338. TreeWalker = tinymce.dom.TreeWalker,
  9339. rangeUtils = new tinymce.dom.RangeUtils(dom),
  9340. isValid = ed.schema.isValid,
  9341. isBlock = dom.isBlock,
  9342. forcedRootBlock = ed.settings.forced_root_block,
  9343. nodeIndex = dom.nodeIndex,
  9344. INVISIBLE_CHAR = '\uFEFF',
  9345. MCE_ATTR_RE = /^(src|href|style)$/,
  9346. FALSE = false,
  9347. TRUE = true,
  9348. undefined,
  9349. pendingFormats = {apply : [], remove : []};
  9350. function isArray(obj) {
  9351. return obj instanceof Array;
  9352. };
  9353. function getParents(node, selector) {
  9354. return dom.getParents(node, selector, dom.getRoot());
  9355. };
  9356. function isCaretNode(node) {
  9357. return node.nodeType === 1 && (node.face === 'mceinline' || node.style.fontFamily === 'mceinline');
  9358. };
  9359. // Public functions
  9360. function get(name) {
  9361. return name ? formats[name] : formats;
  9362. };
  9363. function register(name, format) {
  9364. if (name) {
  9365. if (typeof(name) !== 'string') {
  9366. each(name, function(format, name) {
  9367. register(name, format);
  9368. });
  9369. } else {
  9370. // Force format into array and add it to internal collection
  9371. format = format.length ? format : [format];
  9372. each(format, function(format) {
  9373. // Set deep to false by default on selector formats this to avoid removing
  9374. // alignment on images inside paragraphs when alignment is changed on paragraphs
  9375. if (format.deep === undefined)
  9376. format.deep = !format.selector;
  9377. // Default to true
  9378. if (format.split === undefined)
  9379. format.split = !format.selector || format.inline;
  9380. // Default to true
  9381. if (format.remove === undefined && format.selector && !format.inline)
  9382. format.remove = 'none';
  9383. // Mark format as a mixed format inline + block level
  9384. if (format.selector && format.inline) {
  9385. format.mixed = true;
  9386. format.block_expand = true;
  9387. }
  9388. // Split classes if needed
  9389. if (typeof(format.classes) === 'string')
  9390. format.classes = format.classes.split(/\s+/);
  9391. });
  9392. formats[name] = format;
  9393. }
  9394. }
  9395. };
  9396. function apply(name, vars, node) {
  9397. var formatList = get(name), format = formatList[0], bookmark, rng, i;
  9398. function moveStart(rng) {
  9399. var container = rng.startContainer,
  9400. offset = rng.startOffset,
  9401. walker, node;
  9402. // Move startContainer/startOffset in to a suitable node
  9403. if (container.nodeType == 1 || container.nodeValue === "") {
  9404. container = container.nodeType == 1 ? container.childNodes[offset] : container;
  9405. // Might fail if the offset is behind the last element in it's container
  9406. if (container) {
  9407. walker = new TreeWalker(container, container.parentNode);
  9408. for (node = walker.current(); node; node = walker.next()) {
  9409. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  9410. rng.setStart(node, 0);
  9411. break;
  9412. }
  9413. }
  9414. }
  9415. }
  9416. return rng;
  9417. };
  9418. function setElementFormat(elm, fmt) {
  9419. fmt = fmt || format;
  9420. if (elm) {
  9421. each(fmt.styles, function(value, name) {
  9422. dom.setStyle(elm, name, replaceVars(value, vars));
  9423. });
  9424. each(fmt.attributes, function(value, name) {
  9425. dom.setAttrib(elm, name, replaceVars(value, vars));
  9426. });
  9427. each(fmt.classes, function(value) {
  9428. value = replaceVars(value, vars);
  9429. if (!dom.hasClass(elm, value))
  9430. dom.addClass(elm, value);
  9431. });
  9432. }
  9433. };
  9434. function applyRngStyle(rng) {
  9435. var newWrappers = [], wrapName, wrapElm;
  9436. // Setup wrapper element
  9437. wrapName = format.inline || format.block;
  9438. wrapElm = dom.create(wrapName);
  9439. setElementFormat(wrapElm);
  9440. rangeUtils.walk(rng, function(nodes) {
  9441. var currentWrapElm;
  9442. function process(node) {
  9443. var nodeName = node.nodeName.toLowerCase(), parentName = node.parentNode.nodeName.toLowerCase(), found;
  9444. // Stop wrapping on br elements
  9445. if (isEq(nodeName, 'br')) {
  9446. currentWrapElm = 0;
  9447. // Remove any br elements when we wrap things
  9448. if (format.block)
  9449. dom.remove(node);
  9450. return;
  9451. }
  9452. // If node is wrapper type
  9453. if (format.wrapper && matchNode(node, name, vars)) {
  9454. currentWrapElm = 0;
  9455. return;
  9456. }
  9457. // Can we rename the block
  9458. if (format.block && !format.wrapper && isTextBlock(nodeName)) {
  9459. node = dom.rename(node, wrapName);
  9460. setElementFormat(node);
  9461. newWrappers.push(node);
  9462. currentWrapElm = 0;
  9463. return;
  9464. }
  9465. // Handle selector patterns
  9466. if (format.selector) {
  9467. // Look for matching formats
  9468. each(formatList, function(format) {
  9469. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  9470. setElementFormat(node, format);
  9471. found = true;
  9472. }
  9473. });
  9474. // Continue processing if a selector match wasn't found and a inline element is defined
  9475. if (!format.inline || found) {
  9476. currentWrapElm = 0;
  9477. return;
  9478. }
  9479. }
  9480. // Is it valid to wrap this item
  9481. if ((format.wrap_links !== false || nodeName != 'a') && isValid(wrapName, nodeName) && isValid(parentName, wrapName)) {
  9482. // Start wrapping
  9483. if (!currentWrapElm) {
  9484. // Wrap the node
  9485. currentWrapElm = wrapElm.cloneNode(FALSE);
  9486. node.parentNode.insertBefore(currentWrapElm, node);
  9487. newWrappers.push(currentWrapElm);
  9488. }
  9489. currentWrapElm.appendChild(node);
  9490. } else {
  9491. // Start a new wrapper for possible children
  9492. currentWrapElm = 0;
  9493. each(tinymce.grep(node.childNodes), process);
  9494. // End the last wrapper
  9495. currentWrapElm = 0;
  9496. }
  9497. };
  9498. // Process siblings from range
  9499. each(nodes, process);
  9500. });
  9501. // Cleanup
  9502. each(newWrappers, function(node) {
  9503. var childCount;
  9504. function getChildCount(node) {
  9505. var count = 0;
  9506. each(node.childNodes, function(node) {
  9507. if (!isWhiteSpaceNode(node) && !isBookmarkNode(node))
  9508. count++;
  9509. });
  9510. return count;
  9511. };
  9512. function mergeStyles(node) {
  9513. var child, clone;
  9514. each(node.childNodes, function(node) {
  9515. if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) {
  9516. child = node;
  9517. return FALSE; // break loop
  9518. }
  9519. });
  9520. // If child was found and of the same type as the current node
  9521. if (child && matchName(child, format)) {
  9522. clone = child.cloneNode(FALSE);
  9523. setElementFormat(clone);
  9524. dom.replace(clone, node, TRUE);
  9525. dom.remove(child, 1);
  9526. }
  9527. return clone || node;
  9528. };
  9529. childCount = getChildCount(node);
  9530. // Remove empty nodes
  9531. if (childCount === 0) {
  9532. dom.remove(node, 1);
  9533. return;
  9534. }
  9535. if (format.inline || format.wrapper) {
  9536. // Merges the current node with it's children of similar type to reduce the number of elements
  9537. if (!format.exact && childCount === 1)
  9538. node = mergeStyles(node);
  9539. // Remove/merge children
  9540. each(formatList, function(format) {
  9541. // Merge all children of similar type will move styles from child to parent
  9542. // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
  9543. // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
  9544. each(dom.select(format.inline, node), function(child) {
  9545. removeFormat(format, vars, child, format.exact ? child : null);
  9546. });
  9547. });
  9548. // Remove child if direct parent is of same type
  9549. if (matchNode(node.parentNode, name, vars)) {
  9550. dom.remove(node, 1);
  9551. node = 0;
  9552. return TRUE;
  9553. }
  9554. // Look for parent with similar style format
  9555. if (format.merge_with_parents) {
  9556. dom.getParent(node.parentNode, function(parent) {
  9557. if (matchNode(parent, name, vars)) {
  9558. dom.remove(node, 1);
  9559. node = 0;
  9560. return TRUE;
  9561. }
  9562. });
  9563. }
  9564. // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b>
  9565. if (node) {
  9566. node = mergeSiblings(getNonWhiteSpaceSibling(node), node);
  9567. node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE));
  9568. }
  9569. }
  9570. });
  9571. };
  9572. if (format) {
  9573. if (node) {
  9574. rng = dom.createRng();
  9575. rng.setStartBefore(node);
  9576. rng.setEndAfter(node);
  9577. applyRngStyle(expandRng(rng, formatList));
  9578. } else {
  9579. if (!selection.isCollapsed() || !format.inline) {
  9580. // Apply formatting to selection
  9581. bookmark = selection.getBookmark();
  9582. applyRngStyle(expandRng(selection.getRng(TRUE), formatList));
  9583. selection.moveToBookmark(bookmark);
  9584. selection.setRng(moveStart(selection.getRng(TRUE)));
  9585. ed.nodeChanged();
  9586. } else
  9587. performCaretAction('apply', name, vars);
  9588. }
  9589. }
  9590. };
  9591. function remove(name, vars, node) {
  9592. var formatList = get(name), format = formatList[0], bookmark, i, rng;
  9593. function moveStart(rng) {
  9594. var container = rng.startContainer,
  9595. offset = rng.startOffset,
  9596. walker, node, nodes, tmpNode;
  9597. // Convert text node into index if possible
  9598. if (container.nodeType == 3 && offset >= container.nodeValue.length - 1) {
  9599. container = container.parentNode;
  9600. offset = nodeIndex(container) + 1;
  9601. }
  9602. // Move startContainer/startOffset in to a suitable node
  9603. if (container.nodeType == 1) {
  9604. nodes = container.childNodes;
  9605. container = nodes[Math.min(offset, nodes.length - 1)];
  9606. walker = new TreeWalker(container);
  9607. // If offset is at end of the parent node walk to the next one
  9608. if (offset > nodes.length - 1)
  9609. walker.next();
  9610. for (node = walker.current(); node; node = walker.next()) {
  9611. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  9612. // IE has a "neat" feature where it moves the start node into the closest element
  9613. // we can avoid this by inserting an element before it and then remove it after we set the selection
  9614. tmpNode = dom.create('a', null, INVISIBLE_CHAR);
  9615. node.parentNode.insertBefore(tmpNode, node);
  9616. // Set selection and remove tmpNode
  9617. rng.setStart(node, 0);
  9618. selection.setRng(rng);
  9619. dom.remove(tmpNode);
  9620. return;
  9621. }
  9622. }
  9623. }
  9624. };
  9625. // Merges the styles for each node
  9626. function process(node) {
  9627. var children, i, l;
  9628. // Grab the children first since the nodelist might be changed
  9629. children = tinymce.grep(node.childNodes);
  9630. // Process current node
  9631. for (i = 0, l = formatList.length; i < l; i++) {
  9632. if (removeFormat(formatList[i], vars, node, node))
  9633. break;
  9634. }
  9635. // Process the children
  9636. if (format.deep) {
  9637. for (i = 0, l = children.length; i < l; i++)
  9638. process(children[i]);
  9639. }
  9640. };
  9641. function findFormatRoot(container) {
  9642. var formatRoot;
  9643. // Find format root
  9644. each(getParents(container.parentNode).reverse(), function(parent) {
  9645. var format;
  9646. // Find format root element
  9647. if (!formatRoot && parent.id != '_start' && parent.id != '_end') {
  9648. // Is the node matching the format we are looking for
  9649. format = matchNode(parent, name, vars);
  9650. if (format && format.split !== false)
  9651. formatRoot = parent;
  9652. }
  9653. });
  9654. return formatRoot;
  9655. };
  9656. function wrapAndSplit(format_root, container, target, split) {
  9657. var parent, clone, lastClone, firstClone, i, formatRootParent;
  9658. // Format root found then clone formats and split it
  9659. if (format_root) {
  9660. formatRootParent = format_root.parentNode;
  9661. for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) {
  9662. clone = parent.cloneNode(FALSE);
  9663. for (i = 0; i < formatList.length; i++) {
  9664. if (removeFormat(formatList[i], vars, clone, clone)) {
  9665. clone = 0;
  9666. break;
  9667. }
  9668. }
  9669. // Build wrapper node
  9670. if (clone) {
  9671. if (lastClone)
  9672. clone.appendChild(lastClone);
  9673. if (!firstClone)
  9674. firstClone = clone;
  9675. lastClone = clone;
  9676. }
  9677. }
  9678. // Never split block elements if the format is mixed
  9679. if (split && (!format.mixed || !isBlock(format_root)))
  9680. container = dom.split(format_root, container);
  9681. // Wrap container in cloned formats
  9682. if (lastClone) {
  9683. target.parentNode.insertBefore(lastClone, target);
  9684. firstClone.appendChild(target);
  9685. }
  9686. }
  9687. return container;
  9688. };
  9689. function splitToFormatRoot(container) {
  9690. return wrapAndSplit(findFormatRoot(container), container, container, true);
  9691. };
  9692. function unwrap(start) {
  9693. var node = dom.get(start ? '_start' : '_end'),
  9694. out = node[start ? 'firstChild' : 'lastChild'];
  9695. // If the end is placed within the start the result will be removed
  9696. // So this checks if the out node is a bookmark node if it is it
  9697. // checks for another more suitable node
  9698. if (isBookmarkNode(out))
  9699. out = out[start ? 'firstChild' : 'lastChild'];
  9700. dom.remove(node, true);
  9701. return out;
  9702. };
  9703. function removeRngStyle(rng) {
  9704. var startContainer, endContainer;
  9705. rng = expandRng(rng, formatList, TRUE);
  9706. if (format.split) {
  9707. startContainer = getContainer(rng, TRUE);
  9708. endContainer = getContainer(rng);
  9709. if (startContainer != endContainer) {
  9710. // Wrap start/end nodes in span element since these might be cloned/moved
  9711. startContainer = wrap(startContainer, 'span', {id : '_start', _mce_type : 'bookmark'});
  9712. endContainer = wrap(endContainer, 'span', {id : '_end', _mce_type : 'bookmark'});
  9713. // Split start/end
  9714. splitToFormatRoot(startContainer);
  9715. splitToFormatRoot(endContainer);
  9716. // Unwrap start/end to get real elements again
  9717. startContainer = unwrap(TRUE);
  9718. endContainer = unwrap();
  9719. } else
  9720. startContainer = endContainer = splitToFormatRoot(startContainer);
  9721. // Update range positions since they might have changed after the split operations
  9722. rng.startContainer = startContainer.parentNode;
  9723. rng.startOffset = nodeIndex(startContainer);
  9724. rng.endContainer = endContainer.parentNode;
  9725. rng.endOffset = nodeIndex(endContainer) + 1;
  9726. }
  9727. // Remove items between start/end
  9728. rangeUtils.walk(rng, function(nodes) {
  9729. each(nodes, function(node) {
  9730. process(node);
  9731. });
  9732. });
  9733. };
  9734. // Handle node
  9735. if (node) {
  9736. rng = dom.createRng();
  9737. rng.setStartBefore(node);
  9738. rng.setEndAfter(node);
  9739. removeRngStyle(rng);
  9740. return;
  9741. }
  9742. if (!selection.isCollapsed() || !format.inline) {
  9743. bookmark = selection.getBookmark();
  9744. removeRngStyle(selection.getRng(TRUE));
  9745. selection.moveToBookmark(bookmark);
  9746. // Check if start element still has formatting then we are at: "<b>text|</b>text" and need to move the start into the next text node
  9747. if (match(name, vars, selection.getStart())) {
  9748. moveStart(selection.getRng(true));
  9749. }
  9750. ed.nodeChanged();
  9751. } else
  9752. performCaretAction('remove', name, vars);
  9753. };
  9754. function toggle(name, vars, node) {
  9755. if (match(name, vars, node))
  9756. remove(name, vars, node);
  9757. else
  9758. apply(name, vars, node);
  9759. };
  9760. function matchNode(node, name, vars, similar) {
  9761. var formatList = get(name), format, i, classes;
  9762. function matchItems(node, format, item_name) {
  9763. var key, value, items = format[item_name], i;
  9764. // Check all items
  9765. if (items) {
  9766. // Non indexed object
  9767. if (items.length === undefined) {
  9768. for (key in items) {
  9769. if (items.hasOwnProperty(key)) {
  9770. if (item_name === 'attributes')
  9771. value = dom.getAttrib(node, key);
  9772. else
  9773. value = getStyle(node, key);
  9774. if (similar && !value && !format.exact)
  9775. return;
  9776. if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars)))
  9777. return;
  9778. }
  9779. }
  9780. } else {
  9781. // Only one match needed for indexed arrays
  9782. for (i = 0; i < items.length; i++) {
  9783. if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i]))
  9784. return format;
  9785. }
  9786. }
  9787. }
  9788. return format;
  9789. };
  9790. if (formatList && node) {
  9791. // Check each format in list
  9792. for (i = 0; i < formatList.length; i++) {
  9793. format = formatList[i];
  9794. // Name name, attributes, styles and classes
  9795. if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) {
  9796. // Match classes
  9797. if (classes = format.classes) {
  9798. for (i = 0; i < classes.length; i++) {
  9799. if (!dom.hasClass(node, classes[i]))
  9800. return;
  9801. }
  9802. }
  9803. return format;
  9804. }
  9805. }
  9806. }
  9807. };
  9808. function match(name, vars, node) {
  9809. var startNode, i;
  9810. function matchParents(node) {
  9811. // Find first node with similar format settings
  9812. node = dom.getParent(node, function(node) {
  9813. return !!matchNode(node, name, vars, true);
  9814. });
  9815. // Do an exact check on the similar format element
  9816. return matchNode(node, name, vars);
  9817. };
  9818. // Check specified node
  9819. if (node)
  9820. return matchParents(node);
  9821. // Check pending formats
  9822. if (selection.isCollapsed()) {
  9823. for (i = pendingFormats.apply.length - 1; i >= 0; i--) {
  9824. if (pendingFormats.apply[i].name == name)
  9825. return true;
  9826. }
  9827. for (i = pendingFormats.remove.length - 1; i >= 0; i--) {
  9828. if (pendingFormats.remove[i].name == name)
  9829. return false;
  9830. }
  9831. return matchParents(selection.getNode());
  9832. }
  9833. // Check selected node
  9834. node = selection.getNode();
  9835. if (matchParents(node))
  9836. return TRUE;
  9837. // Check start node if it's different
  9838. startNode = selection.getStart();
  9839. if (startNode != node) {
  9840. if (matchParents(startNode))
  9841. return TRUE;
  9842. }
  9843. return FALSE;
  9844. };
  9845. function matchAll(names, vars) {
  9846. var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name;
  9847. // If the selection is collapsed then check pending formats
  9848. if (selection.isCollapsed()) {
  9849. for (ni = 0; ni < names.length; ni++) {
  9850. // If the name is to be removed, then stop it from being added
  9851. for (i = pendingFormats.remove.length - 1; i >= 0; i--) {
  9852. name = names[ni];
  9853. if (pendingFormats.remove[i].name == name) {
  9854. checkedMap[name] = true;
  9855. break;
  9856. }
  9857. }
  9858. }
  9859. // If the format is to be applied
  9860. for (i = pendingFormats.apply.length - 1; i >= 0; i--) {
  9861. for (ni = 0; ni < names.length; ni++) {
  9862. name = names[ni];
  9863. if (!checkedMap[name] && pendingFormats.apply[i].name == name) {
  9864. checkedMap[name] = true;
  9865. matchedFormatNames.push(name);
  9866. }
  9867. }
  9868. }
  9869. }
  9870. // Check start of selection for formats
  9871. startElement = selection.getStart();
  9872. dom.getParent(startElement, function(node) {
  9873. var i, name;
  9874. for (i = 0; i < names.length; i++) {
  9875. name = names[i];
  9876. if (!checkedMap[name] && matchNode(node, name, vars)) {
  9877. checkedMap[name] = true;
  9878. matchedFormatNames.push(name);
  9879. }
  9880. }
  9881. });
  9882. return matchedFormatNames;
  9883. };
  9884. function canApply(name) {
  9885. var formatList = get(name), startNode, parents, i, x, selector;
  9886. if (formatList) {
  9887. startNode = selection.getStart();
  9888. parents = getParents(startNode);
  9889. for (x = formatList.length - 1; x >= 0; x--) {
  9890. selector = formatList[x].selector;
  9891. // Format is not selector based, then always return TRUE
  9892. if (!selector)
  9893. return TRUE;
  9894. for (i = parents.length - 1; i >= 0; i--) {
  9895. if (dom.is(parents[i], selector))
  9896. return TRUE;
  9897. }
  9898. }
  9899. }
  9900. return FALSE;
  9901. };
  9902. // Expose to public
  9903. tinymce.extend(this, {
  9904. get : get,
  9905. register : register,
  9906. apply : apply,
  9907. remove : remove,
  9908. toggle : toggle,
  9909. match : match,
  9910. matchAll : matchAll,
  9911. matchNode : matchNode,
  9912. canApply : canApply
  9913. });
  9914. // Private functions
  9915. function matchName(node, format) {
  9916. // Check for inline match
  9917. if (isEq(node, format.inline))
  9918. return TRUE;
  9919. // Check for block match
  9920. if (isEq(node, format.block))
  9921. return TRUE;
  9922. // Check for selector match
  9923. if (format.selector)
  9924. return dom.is(node, format.selector);
  9925. };
  9926. function isEq(str1, str2) {
  9927. str1 = str1 || '';
  9928. str2 = str2 || '';
  9929. str1 = '' + (str1.nodeName || str1);
  9930. str2 = '' + (str2.nodeName || str2);
  9931. return str1.toLowerCase() == str2.toLowerCase();
  9932. };
  9933. function getStyle(node, name) {
  9934. var styleVal = dom.getStyle(node, name);
  9935. // Force the format to hex
  9936. if (name == 'color' || name == 'backgroundColor')
  9937. styleVal = dom.toHex(styleVal);
  9938. // Opera will return bold as 700
  9939. if (name == 'fontWeight' && styleVal == 700)
  9940. styleVal = 'bold';
  9941. return '' + styleVal;
  9942. };
  9943. function replaceVars(value, vars) {
  9944. if (typeof(value) != "string")
  9945. value = value(vars);
  9946. else if (vars) {
  9947. value = value.replace(/%(\w+)/g, function(str, name) {
  9948. return vars[name] || str;
  9949. });
  9950. }
  9951. return value;
  9952. };
  9953. function isWhiteSpaceNode(node) {
  9954. return node && node.nodeType === 3 && /^([\s\r\n]+|)$/.test(node.nodeValue);
  9955. };
  9956. function wrap(node, name, attrs) {
  9957. var wrapper = dom.create(name, attrs);
  9958. node.parentNode.insertBefore(wrapper, node);
  9959. wrapper.appendChild(node);
  9960. return wrapper;
  9961. };
  9962. function expandRng(rng, format, remove) {
  9963. var startContainer = rng.startContainer,
  9964. startOffset = rng.startOffset,
  9965. endContainer = rng.endContainer,
  9966. endOffset = rng.endOffset, sibling, lastIdx;
  9967. // This function walks up the tree if there is no siblings before/after the node
  9968. function findParentContainer(container, child_name, sibling_name, root) {
  9969. var parent, child;
  9970. root = root || dom.getRoot();
  9971. for (;;) {
  9972. // Check if we can move up are we at root level or body level
  9973. parent = container.parentNode;
  9974. // Stop expanding on block elements or root depending on format
  9975. if (parent == root || (!format[0].block_expand && isBlock(parent)))
  9976. return container;
  9977. for (sibling = parent[child_name]; sibling && sibling != container; sibling = sibling[sibling_name]) {
  9978. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  9979. return container;
  9980. if (sibling.nodeType == 3 && !isWhiteSpaceNode(sibling))
  9981. return container;
  9982. }
  9983. container = container.parentNode;
  9984. }
  9985. return container;
  9986. };
  9987. // If index based start position then resolve it
  9988. if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
  9989. lastIdx = startContainer.childNodes.length - 1;
  9990. startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
  9991. if (startContainer.nodeType == 3)
  9992. startOffset = 0;
  9993. }
  9994. // If index based end position then resolve it
  9995. if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
  9996. lastIdx = endContainer.childNodes.length - 1;
  9997. endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
  9998. if (endContainer.nodeType == 3)
  9999. endOffset = endContainer.nodeValue.length;
  10000. }
  10001. // Exclude bookmark nodes if possible
  10002. if (isBookmarkNode(startContainer.parentNode))
  10003. startContainer = startContainer.parentNode;
  10004. if (isBookmarkNode(startContainer))
  10005. startContainer = startContainer.nextSibling || startContainer;
  10006. if (isBookmarkNode(endContainer.parentNode))
  10007. endContainer = endContainer.parentNode;
  10008. if (isBookmarkNode(endContainer))
  10009. endContainer = endContainer.previousSibling || endContainer;
  10010. // Move start/end point up the tree if the leaves are sharp and if we are in different containers
  10011. // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
  10012. // This will reduce the number of wrapper elements that needs to be created
  10013. // Move start point up the tree
  10014. if (format[0].inline || format[0].block_expand) {
  10015. startContainer = findParentContainer(startContainer, 'firstChild', 'nextSibling');
  10016. endContainer = findParentContainer(endContainer, 'lastChild', 'previousSibling');
  10017. }
  10018. // Expand start/end container to matching selector
  10019. if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
  10020. function findSelectorEndPoint(container, sibling_name) {
  10021. var parents, i, y;
  10022. if (container.nodeType == 3 && container.nodeValue.length == 0 && container[sibling_name])
  10023. container = container[sibling_name];
  10024. parents = getParents(container);
  10025. for (i = 0; i < parents.length; i++) {
  10026. for (y = 0; y < format.length; y++) {
  10027. if (dom.is(parents[i], format[y].selector))
  10028. return parents[i];
  10029. }
  10030. }
  10031. return container;
  10032. };
  10033. // Find new startContainer/endContainer if there is better one
  10034. startContainer = findSelectorEndPoint(startContainer, 'previousSibling');
  10035. endContainer = findSelectorEndPoint(endContainer, 'nextSibling');
  10036. }
  10037. // Expand start/end container to matching block element or text node
  10038. if (format[0].block || format[0].selector) {
  10039. function findBlockEndPoint(container, sibling_name, sibling_name2) {
  10040. var node;
  10041. // Expand to block of similar type
  10042. if (!format[0].wrapper)
  10043. node = dom.getParent(container, format[0].block);
  10044. // Expand to first wrappable block element or any block element
  10045. if (!node)
  10046. node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isBlock);
  10047. // Exclude inner lists from wrapping
  10048. if (node && format[0].wrapper)
  10049. node = getParents(node, 'ul,ol').reverse()[0] || node;
  10050. // Didn't find a block element look for first/last wrappable element
  10051. if (!node) {
  10052. node = container;
  10053. while (node[sibling_name] && !isBlock(node[sibling_name])) {
  10054. node = node[sibling_name];
  10055. // Break on BR but include it will be removed later on
  10056. // we can't remove it now since we need to check if it can be wrapped
  10057. if (isEq(node, 'br'))
  10058. break;
  10059. }
  10060. }
  10061. return node || container;
  10062. };
  10063. // Find new startContainer/endContainer if there is better one
  10064. startContainer = findBlockEndPoint(startContainer, 'previousSibling');
  10065. endContainer = findBlockEndPoint(endContainer, 'nextSibling');
  10066. // Non block element then try to expand up the leaf
  10067. if (format[0].block) {
  10068. if (!isBlock(startContainer))
  10069. startContainer = findParentContainer(startContainer, 'firstChild', 'nextSibling');
  10070. if (!isBlock(endContainer))
  10071. endContainer = findParentContainer(endContainer, 'lastChild', 'previousSibling');
  10072. }
  10073. }
  10074. // Setup index for startContainer
  10075. if (startContainer.nodeType == 1) {
  10076. startOffset = nodeIndex(startContainer);
  10077. startContainer = startContainer.parentNode;
  10078. }
  10079. // Setup index for endContainer
  10080. if (endContainer.nodeType == 1) {
  10081. endOffset = nodeIndex(endContainer) + 1;
  10082. endContainer = endContainer.parentNode;
  10083. }
  10084. // Return new range like object
  10085. return {
  10086. startContainer : startContainer,
  10087. startOffset : startOffset,
  10088. endContainer : endContainer,
  10089. endOffset : endOffset
  10090. };
  10091. }
  10092. function removeFormat(format, vars, node, compare_node) {
  10093. var i, attrs, stylesModified;
  10094. // Check if node matches format
  10095. if (!matchName(node, format))
  10096. return FALSE;
  10097. // Should we compare with format attribs and styles
  10098. if (format.remove != 'all') {
  10099. // Remove styles
  10100. each(format.styles, function(value, name) {
  10101. value = replaceVars(value, vars);
  10102. // Indexed array
  10103. if (typeof(name) === 'number') {
  10104. name = value;
  10105. compare_node = 0;
  10106. }
  10107. if (!compare_node || isEq(getStyle(compare_node, name), value))
  10108. dom.setStyle(node, name, '');
  10109. stylesModified = 1;
  10110. });
  10111. // Remove style attribute if it's empty
  10112. if (stylesModified && dom.getAttrib(node, 'style') == '') {
  10113. node.removeAttribute('style');
  10114. node.removeAttribute('_mce_style');
  10115. }
  10116. // Remove attributes
  10117. each(format.attributes, function(value, name) {
  10118. var valueOut;
  10119. value = replaceVars(value, vars);
  10120. // Indexed array
  10121. if (typeof(name) === 'number') {
  10122. name = value;
  10123. compare_node = 0;
  10124. }
  10125. if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) {
  10126. // Keep internal classes
  10127. if (name == 'class') {
  10128. value = dom.getAttrib(node, name);
  10129. if (value) {
  10130. // Build new class value where everything is removed except the internal prefixed classes
  10131. valueOut = '';
  10132. each(value.split(/\s+/), function(cls) {
  10133. if (/mce\w+/.test(cls))
  10134. valueOut += (valueOut ? ' ' : '') + cls;
  10135. });
  10136. // We got some internal classes left
  10137. if (valueOut) {
  10138. dom.setAttrib(node, name, valueOut);
  10139. return;
  10140. }
  10141. }
  10142. }
  10143. // IE6 has a bug where the attribute doesn't get removed correctly
  10144. if (name == "class")
  10145. node.removeAttribute('className');
  10146. // Remove mce prefixed attributes
  10147. if (MCE_ATTR_RE.test(name))
  10148. node.removeAttribute('_mce_' + name);
  10149. node.removeAttribute(name);
  10150. }
  10151. });
  10152. // Remove classes
  10153. each(format.classes, function(value) {
  10154. value = replaceVars(value, vars);
  10155. if (!compare_node || dom.hasClass(compare_node, value))
  10156. dom.removeClass(node, value);
  10157. });
  10158. // Check for non internal attributes
  10159. attrs = dom.getAttribs(node);
  10160. for (i = 0; i < attrs.length; i++) {
  10161. if (attrs[i].nodeName.indexOf('_') !== 0)
  10162. return FALSE;
  10163. }
  10164. }
  10165. // Remove the inline child if it's empty for example <b> or <span>
  10166. if (format.remove != 'none') {
  10167. removeNode(node, format);
  10168. return TRUE;
  10169. }
  10170. };
  10171. function removeNode(node, format) {
  10172. var parentNode = node.parentNode, rootBlockElm;
  10173. if (format.block) {
  10174. if (!forcedRootBlock) {
  10175. function find(node, next, inc) {
  10176. node = getNonWhiteSpaceSibling(node, next, inc);
  10177. return !node || (node.nodeName == 'BR' || isBlock(node));
  10178. };
  10179. // Append BR elements if needed before we remove the block
  10180. if (isBlock(node) && !isBlock(parentNode)) {
  10181. if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1))
  10182. node.insertBefore(dom.create('br'), node.firstChild);
  10183. if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1))
  10184. node.appendChild(dom.create('br'));
  10185. }
  10186. } else {
  10187. // Wrap the block in a forcedRootBlock if we are at the root of document
  10188. if (parentNode == dom.getRoot()) {
  10189. if (!format.list_block || !isEq(node, format.list_block)) {
  10190. each(tinymce.grep(node.childNodes), function(node) {
  10191. if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) {
  10192. if (!rootBlockElm)
  10193. rootBlockElm = wrap(node, forcedRootBlock);
  10194. else
  10195. rootBlockElm.appendChild(node);
  10196. } else
  10197. rootBlockElm = 0;
  10198. });
  10199. }
  10200. }
  10201. }
  10202. }
  10203. // Never remove nodes that isn't the specified inline element if a selector is specified too
  10204. if (format.selector && format.inline && !isEq(format.inline, node))
  10205. return;
  10206. dom.remove(node, 1);
  10207. };
  10208. function getNonWhiteSpaceSibling(node, next, inc) {
  10209. if (node) {
  10210. next = next ? 'nextSibling' : 'previousSibling';
  10211. for (node = inc ? node : node[next]; node; node = node[next]) {
  10212. if (node.nodeType == 1 || !isWhiteSpaceNode(node))
  10213. return node;
  10214. }
  10215. }
  10216. };
  10217. function isBookmarkNode(node) {
  10218. return node && node.nodeType == 1 && node.getAttribute('_mce_type') == 'bookmark';
  10219. };
  10220. function mergeSiblings(prev, next) {
  10221. var marker, sibling, tmpSibling;
  10222. function compareElements(node1, node2) {
  10223. // Not the same name
  10224. if (node1.nodeName != node2.nodeName)
  10225. return FALSE;
  10226. function getAttribs(node) {
  10227. var attribs = {};
  10228. each(dom.getAttribs(node), function(attr) {
  10229. var name = attr.nodeName.toLowerCase();
  10230. // Don't compare internal attributes or style
  10231. if (name.indexOf('_') !== 0 && name !== 'style')
  10232. attribs[name] = dom.getAttrib(node, name);
  10233. });
  10234. return attribs;
  10235. };
  10236. function compareObjects(obj1, obj2) {
  10237. var value, name;
  10238. for (name in obj1) {
  10239. // Obj1 has item obj2 doesn't have
  10240. if (obj1.hasOwnProperty(name)) {
  10241. value = obj2[name];
  10242. // Obj2 doesn't have obj1 item
  10243. if (value === undefined)
  10244. return FALSE;
  10245. // Obj2 item has a different value
  10246. if (obj1[name] != value)
  10247. return FALSE;
  10248. // Delete similar value
  10249. delete obj2[name];
  10250. }
  10251. }
  10252. // Check if obj 2 has something obj 1 doesn't have
  10253. for (name in obj2) {
  10254. // Obj2 has item obj1 doesn't have
  10255. if (obj2.hasOwnProperty(name))
  10256. return FALSE;
  10257. }
  10258. return TRUE;
  10259. };
  10260. // Attribs are not the same
  10261. if (!compareObjects(getAttribs(node1), getAttribs(node2)))
  10262. return FALSE;
  10263. // Styles are not the same
  10264. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style'))))
  10265. return FALSE;
  10266. return TRUE;
  10267. };
  10268. // Check if next/prev exists and that they are elements
  10269. if (prev && next) {
  10270. function findElementSibling(node, sibling_name) {
  10271. for (sibling = node; sibling; sibling = sibling[sibling_name]) {
  10272. if (sibling.nodeType == 3 && !isWhiteSpaceNode(sibling))
  10273. return node;
  10274. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  10275. return sibling;
  10276. }
  10277. return node;
  10278. };
  10279. // If previous sibling is empty then jump over it
  10280. prev = findElementSibling(prev, 'previousSibling');
  10281. next = findElementSibling(next, 'nextSibling');
  10282. // Compare next and previous nodes
  10283. if (compareElements(prev, next)) {
  10284. // Append nodes between
  10285. for (sibling = prev.nextSibling; sibling && sibling != next;) {
  10286. tmpSibling = sibling;
  10287. sibling = sibling.nextSibling;
  10288. prev.appendChild(tmpSibling);
  10289. }
  10290. // Remove next node
  10291. dom.remove(next);
  10292. // Move children into prev node
  10293. each(tinymce.grep(next.childNodes), function(node) {
  10294. prev.appendChild(node);
  10295. });
  10296. return prev;
  10297. }
  10298. }
  10299. return next;
  10300. };
  10301. function isTextBlock(name) {
  10302. return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name);
  10303. };
  10304. function getContainer(rng, start) {
  10305. var container, offset, lastIdx;
  10306. container = rng[start ? 'startContainer' : 'endContainer'];
  10307. offset = rng[start ? 'startOffset' : 'endOffset'];
  10308. if (container.nodeType == 1) {
  10309. lastIdx = container.childNodes.length - 1;
  10310. if (!start && offset)
  10311. offset--;
  10312. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  10313. }
  10314. return container;
  10315. };
  10316. function performCaretAction(type, name, vars) {
  10317. var i, currentPendingFormats = pendingFormats[type],
  10318. otherPendingFormats = pendingFormats[type == 'apply' ? 'remove' : 'apply'];
  10319. function hasPending() {
  10320. return pendingFormats.apply.length || pendingFormats.remove.length;
  10321. };
  10322. function resetPending() {
  10323. pendingFormats.apply = [];
  10324. pendingFormats.remove = [];
  10325. };
  10326. function perform(caret_node) {
  10327. // Apply pending formats
  10328. each(pendingFormats.apply.reverse(), function(item) {
  10329. apply(item.name, item.vars, caret_node);
  10330. });
  10331. // Remove pending formats
  10332. each(pendingFormats.remove.reverse(), function(item) {
  10333. remove(item.name, item.vars, caret_node);
  10334. });
  10335. dom.remove(caret_node, 1);
  10336. resetPending();
  10337. };
  10338. // Check if it already exists then ignore it
  10339. for (i = currentPendingFormats.length - 1; i >= 0; i--) {
  10340. if (currentPendingFormats[i].name == name)
  10341. return;
  10342. }
  10343. currentPendingFormats.push({name : name, vars : vars});
  10344. // Check if it's in the other type, then remove it
  10345. for (i = otherPendingFormats.length - 1; i >= 0; i--) {
  10346. if (otherPendingFormats[i].name == name)
  10347. otherPendingFormats.splice(i, 1);
  10348. }
  10349. // Pending apply or remove formats
  10350. if (hasPending()) {
  10351. ed.getDoc().execCommand('FontName', false, 'mceinline');
  10352. pendingFormats.lastRng = selection.getRng();
  10353. // IE will convert the current word
  10354. each(dom.select('font,span'), function(node) {
  10355. var bookmark;
  10356. if (isCaretNode(node)) {
  10357. bookmark = selection.getBookmark();
  10358. perform(node);
  10359. selection.moveToBookmark(bookmark);
  10360. ed.nodeChanged();
  10361. }
  10362. });
  10363. // Only register listeners once if we need to
  10364. if (!pendingFormats.isListening && hasPending()) {
  10365. pendingFormats.isListening = true;
  10366. each('onKeyDown,onKeyUp,onKeyPress,onMouseUp'.split(','), function(event) {
  10367. ed[event].addToTop(function(ed, e) {
  10368. // Do we have pending formats and is the selection moved has moved
  10369. if (hasPending() && !tinymce.dom.RangeUtils.compareRanges(pendingFormats.lastRng, selection.getRng())) {
  10370. each(dom.select('font,span'), function(node) {
  10371. var textNode, rng;
  10372. // Look for marker
  10373. if (isCaretNode(node)) {
  10374. textNode = node.firstChild;
  10375. if (textNode) {
  10376. perform(node);
  10377. rng = dom.createRng();
  10378. rng.setStart(textNode, textNode.nodeValue.length);
  10379. rng.setEnd(textNode, textNode.nodeValue.length);
  10380. selection.setRng(rng);
  10381. ed.nodeChanged();
  10382. } else
  10383. dom.remove(node);
  10384. }
  10385. });
  10386. // Always unbind and clear pending styles on keyup
  10387. if (e.type == 'keyup' || e.type == 'mouseup')
  10388. resetPending();
  10389. }
  10390. });
  10391. });
  10392. }
  10393. }
  10394. };
  10395. };
  10396. })(tinymce);
  10397. tinymce.onAddEditor.add(function(tinymce, ed) {
  10398. var filters, fontSizes, dom, settings = ed.settings;
  10399. if (settings.inline_styles) {
  10400. fontSizes = tinymce.explode(settings.font_size_style_values);
  10401. function replaceWithSpan(node, styles) {
  10402. tinymce.each(styles, function(value, name) {
  10403. if (value)
  10404. dom.setStyle(node, name, value);
  10405. });
  10406. dom.rename(node, 'span');
  10407. };
  10408. filters = {
  10409. font : function(dom, node) {
  10410. replaceWithSpan(node, {
  10411. backgroundColor : node.style.backgroundColor,
  10412. color : node.color,
  10413. fontFamily : node.face,
  10414. fontSize : fontSizes[parseInt(node.size) - 1]
  10415. });
  10416. },
  10417. u : function(dom, node) {
  10418. replaceWithSpan(node, {
  10419. textDecoration : 'underline'
  10420. });
  10421. },
  10422. strike : function(dom, node) {
  10423. replaceWithSpan(node, {
  10424. textDecoration : 'line-through'
  10425. });
  10426. }
  10427. };
  10428. function convert(editor, params) {
  10429. dom = editor.dom;
  10430. if (settings.convert_fonts_to_spans) {
  10431. tinymce.each(dom.select('font,u,strike', params.node), function(node) {
  10432. filters[node.nodeName.toLowerCase()](ed.dom, node);
  10433. });
  10434. }
  10435. };
  10436. ed.onPreProcess.add(convert);
  10437. ed.onInit.add(function() {
  10438. ed.selection.onSetContent.add(convert);
  10439. });
  10440. }
  10441. });