PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/lists/editor_plugin_src.js

#
JavaScript | 688 lines | 591 code | 65 blank | 32 comment | 181 complexity | f9be125e4533524cc0fb64f7ffc0a1b1 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. /**
  2. * editor_plugin_src.js
  3. *
  4. * Copyright 2011, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://tinymce.moxiecode.com/license
  8. * Contributing: http://tinymce.moxiecode.com/contributing
  9. */
  10. (function() {
  11. var each = tinymce.each, Event = tinymce.dom.Event, bookmark;
  12. // Skips text nodes that only contain whitespace since they aren't semantically important.
  13. function skipWhitespaceNodes(e, next) {
  14. while (e && (e.nodeType === 8 || (e.nodeType === 3 && /^[ \t\n\r]*$/.test(e.nodeValue)))) {
  15. e = next(e);
  16. }
  17. return e;
  18. }
  19. function skipWhitespaceNodesBackwards(e) {
  20. return skipWhitespaceNodes(e, function(e) { return e.previousSibling; });
  21. }
  22. function skipWhitespaceNodesForwards(e) {
  23. return skipWhitespaceNodes(e, function(e) { return e.nextSibling; });
  24. }
  25. function hasParentInList(ed, e, list) {
  26. return ed.dom.getParent(e, function(p) {
  27. return tinymce.inArray(list, p) !== -1;
  28. });
  29. }
  30. function isList(e) {
  31. return e && (e.tagName === 'OL' || e.tagName === 'UL');
  32. }
  33. function splitNestedLists(element, dom) {
  34. var tmp, nested, wrapItem;
  35. tmp = skipWhitespaceNodesBackwards(element.lastChild);
  36. while (isList(tmp)) {
  37. nested = tmp;
  38. tmp = skipWhitespaceNodesBackwards(nested.previousSibling);
  39. }
  40. if (nested) {
  41. wrapItem = dom.create('li', { style: 'list-style-type: none;'});
  42. dom.split(element, nested);
  43. dom.insertAfter(wrapItem, nested);
  44. wrapItem.appendChild(nested);
  45. wrapItem.appendChild(nested);
  46. element = wrapItem.previousSibling;
  47. }
  48. return element;
  49. }
  50. function attemptMergeWithAdjacent(e, allowDifferentListStyles, mergeParagraphs) {
  51. e = attemptMergeWithPrevious(e, allowDifferentListStyles, mergeParagraphs);
  52. return attemptMergeWithNext(e, allowDifferentListStyles, mergeParagraphs);
  53. }
  54. function attemptMergeWithPrevious(e, allowDifferentListStyles, mergeParagraphs) {
  55. var prev = skipWhitespaceNodesBackwards(e.previousSibling);
  56. if (prev) {
  57. return attemptMerge(prev, e, allowDifferentListStyles ? prev : false, mergeParagraphs);
  58. } else {
  59. return e;
  60. }
  61. }
  62. function attemptMergeWithNext(e, allowDifferentListStyles, mergeParagraphs) {
  63. var next = skipWhitespaceNodesForwards(e.nextSibling);
  64. if (next) {
  65. return attemptMerge(e, next, allowDifferentListStyles ? next : false, mergeParagraphs);
  66. } else {
  67. return e;
  68. }
  69. }
  70. function attemptMerge(e1, e2, differentStylesMasterElement, mergeParagraphs) {
  71. if (canMerge(e1, e2, !!differentStylesMasterElement, mergeParagraphs)) {
  72. return merge(e1, e2, differentStylesMasterElement);
  73. } else if (e1 && e1.tagName === 'LI' && isList(e2)) {
  74. // Fix invalidly nested lists.
  75. e1.appendChild(e2);
  76. }
  77. return e2;
  78. }
  79. function canMerge(e1, e2, allowDifferentListStyles, mergeParagraphs) {
  80. if (!e1 || !e2) {
  81. return false;
  82. } else if (e1.tagName === 'LI' && e2.tagName === 'LI') {
  83. return e2.style.listStyleType === 'none' || containsOnlyAList(e2);
  84. } else if (isList(e1)) {
  85. return (e1.tagName === e2.tagName && (allowDifferentListStyles || e1.style.listStyleType === e2.style.listStyleType)) || isListForIndent(e2);
  86. } else if (mergeParagraphs && e1.tagName === 'P' && e2.tagName === 'P') {
  87. return true;
  88. } else {
  89. return false;
  90. }
  91. }
  92. function isListForIndent(e) {
  93. var firstLI = skipWhitespaceNodesForwards(e.firstChild), lastLI = skipWhitespaceNodesBackwards(e.lastChild);
  94. return firstLI && lastLI && isList(e) && firstLI === lastLI && (isList(firstLI) || firstLI.style.listStyleType === 'none' || containsOnlyAList(firstLI));
  95. }
  96. function containsOnlyAList(e) {
  97. var firstChild = skipWhitespaceNodesForwards(e.firstChild), lastChild = skipWhitespaceNodesBackwards(e.lastChild);
  98. return firstChild && lastChild && firstChild === lastChild && isList(firstChild);
  99. }
  100. function merge(e1, e2, masterElement) {
  101. var lastOriginal = skipWhitespaceNodesBackwards(e1.lastChild), firstNew = skipWhitespaceNodesForwards(e2.firstChild);
  102. if (e1.tagName === 'P') {
  103. e1.appendChild(e1.ownerDocument.createElement('br'));
  104. }
  105. while (e2.firstChild) {
  106. e1.appendChild(e2.firstChild);
  107. }
  108. if (masterElement) {
  109. e1.style.listStyleType = masterElement.style.listStyleType;
  110. }
  111. e2.parentNode.removeChild(e2);
  112. attemptMerge(lastOriginal, firstNew, false);
  113. return e1;
  114. }
  115. function findItemToOperateOn(e, dom) {
  116. var item;
  117. if (!dom.is(e, 'li,ol,ul')) {
  118. item = dom.getParent(e, 'li');
  119. if (item) {
  120. e = item;
  121. }
  122. }
  123. return e;
  124. }
  125. tinymce.create('tinymce.plugins.Lists', {
  126. init: function(ed, url) {
  127. var enterDownInEmptyList = false;
  128. function isTriggerKey(e) {
  129. return e.keyCode === 9 && (ed.queryCommandState('InsertUnorderedList') || ed.queryCommandState('InsertOrderedList'));
  130. };
  131. function isEnterInEmptyListItem(ed, e) {
  132. var sel = ed.selection, n;
  133. if (e.keyCode === 13) {
  134. n = sel.getStart();
  135. // Get start will return BR if the LI only contains a BR
  136. if (n.tagName == 'BR' && n.parentNode.tagName == 'LI')
  137. n = n.parentNode;
  138. // Check for empty LI or a LI with just one BR since Gecko and WebKit uses BR elements to place the caret
  139. enterDownInEmptyList = sel.isCollapsed() && n && n.tagName === 'LI' && (n.childNodes.length === 0 || (n.firstChild.nodeName == 'BR' && n.childNodes.length === 1));
  140. return enterDownInEmptyList;
  141. }
  142. };
  143. function cancelKeys(ed, e) {
  144. if (isTriggerKey(e) || isEnterInEmptyListItem(ed, e)) {
  145. return Event.cancel(e);
  146. }
  147. };
  148. function imageJoiningListItem(ed, e) {
  149. if (!tinymce.isGecko)
  150. return;
  151. var n = ed.selection.getStart();
  152. if (e.keyCode != 8 || n.tagName !== 'IMG')
  153. return;
  154. function lastLI(node) {
  155. var child = node.firstChild;
  156. var li = null;
  157. do {
  158. if (!child)
  159. break;
  160. if (child.tagName === 'LI')
  161. li = child;
  162. } while (child = child.nextSibling);
  163. return li;
  164. }
  165. function addChildren(parentNode, destination) {
  166. while (parentNode.childNodes.length > 0)
  167. destination.appendChild(parentNode.childNodes[0]);
  168. }
  169. var ul;
  170. if (n.parentNode.previousSibling.tagName === 'UL' || n.parentNode.previousSibling.tagName === 'OL')
  171. ul = n.parentNode.previousSibling;
  172. else if (n.parentNode.previousSibling.previousSibling.tagName === 'UL' || n.parentNode.previousSibling.previousSibling.tagName === 'OL')
  173. ul = n.parentNode.previousSibling.previousSibling;
  174. else
  175. return;
  176. var li = lastLI(ul);
  177. // move the caret to the end of the list item
  178. var rng = ed.dom.createRng();
  179. rng.setStart(li, 1);
  180. rng.setEnd(li, 1);
  181. ed.selection.setRng(rng);
  182. ed.selection.collapse(true);
  183. // save a bookmark at the end of the list item
  184. var bookmark = ed.selection.getBookmark();
  185. // copy the image an its text to the list item
  186. var clone = n.parentNode.cloneNode(true);
  187. if (clone.tagName === 'P' || clone.tagName === 'DIV')
  188. addChildren(clone, li);
  189. else
  190. li.appendChild(clone);
  191. // remove the old copy of the image
  192. n.parentNode.parentNode.removeChild(n.parentNode);
  193. // move the caret where we saved the bookmark
  194. ed.selection.moveToBookmark(bookmark);
  195. }
  196. this.ed = ed;
  197. ed.addCommand('Indent', this.indent, this);
  198. ed.addCommand('Outdent', this.outdent, this);
  199. ed.addCommand('InsertUnorderedList', function() {
  200. this.applyList('UL', 'OL');
  201. }, this);
  202. ed.addCommand('InsertOrderedList', function() {
  203. this.applyList('OL', 'UL');
  204. }, this);
  205. ed.onInit.add(function() {
  206. ed.editorCommands.addCommands({
  207. 'outdent': function() {
  208. var sel = ed.selection, dom = ed.dom;
  209. function hasStyleIndent(n) {
  210. n = dom.getParent(n, dom.isBlock);
  211. return n && (parseInt(ed.dom.getStyle(n, 'margin-left') || 0, 10) + parseInt(ed.dom.getStyle(n, 'padding-left') || 0, 10)) > 0;
  212. }
  213. return hasStyleIndent(sel.getStart()) || hasStyleIndent(sel.getEnd()) || ed.queryCommandState('InsertOrderedList') || ed.queryCommandState('InsertUnorderedList');
  214. }
  215. }, 'state');
  216. });
  217. ed.onKeyUp.add(function(ed, e) {
  218. var n, rng;
  219. if (isTriggerKey(e)) {
  220. ed.execCommand(e.shiftKey ? 'Outdent' : 'Indent', true, null);
  221. return Event.cancel(e);
  222. } else if (enterDownInEmptyList && isEnterInEmptyListItem(ed, e)) {
  223. if (ed.queryCommandState('InsertOrderedList')) {
  224. ed.execCommand('InsertOrderedList');
  225. } else {
  226. ed.execCommand('InsertUnorderedList');
  227. }
  228. n = ed.selection.getStart();
  229. if (n && n.tagName === 'LI') {
  230. // Fix the caret position on IE since it jumps back up to the previous list item.
  231. n = ed.dom.getParent(n, 'ol,ul').nextSibling;
  232. if (n && n.tagName === 'P') {
  233. if (!n.firstChild) {
  234. n.appendChild(ed.getDoc().createTextNode(''));
  235. }
  236. rng = ed.dom.createRng();
  237. rng.setStart(n.firstChild, 1);
  238. rng.setEnd(n.firstChild, 1);
  239. ed.selection.setRng(rng);
  240. }
  241. }
  242. return Event.cancel(e);
  243. }
  244. });
  245. ed.onKeyPress.add(cancelKeys);
  246. ed.onKeyDown.add(cancelKeys);
  247. ed.onKeyDown.add(imageJoiningListItem);
  248. },
  249. applyList: function(targetListType, oppositeListType) {
  250. var t = this, ed = t.ed, dom = ed.dom, applied = [], hasSameType = false, hasOppositeType = false, hasNonList = false, actions,
  251. selectedBlocks = ed.selection.getSelectedBlocks();
  252. function cleanupBr(e) {
  253. if (e && e.tagName === 'BR') {
  254. dom.remove(e);
  255. }
  256. }
  257. function makeList(element) {
  258. var list = dom.create(targetListType), li;
  259. function adjustIndentForNewList(element) {
  260. // If there's a margin-left, outdent one level to account for the extra list margin.
  261. if (element.style.marginLeft || element.style.paddingLeft) {
  262. t.adjustPaddingFunction(false)(element);
  263. }
  264. }
  265. if (element.tagName === 'LI') {
  266. // No change required.
  267. } else if (element.tagName === 'P' || element.tagName === 'DIV' || element.tagName === 'BODY') {
  268. processBrs(element, function(startSection, br, previousBR) {
  269. doWrapList(startSection, br, element.tagName === 'BODY' ? null : startSection.parentNode);
  270. li = startSection.parentNode;
  271. adjustIndentForNewList(li);
  272. cleanupBr(br);
  273. });
  274. if (element.tagName === 'P' || selectedBlocks.length > 1) {
  275. dom.split(li.parentNode.parentNode, li.parentNode);
  276. }
  277. attemptMergeWithAdjacent(li.parentNode, true);
  278. return;
  279. } else {
  280. // Put the list around the element.
  281. li = dom.create('li');
  282. dom.insertAfter(li, element);
  283. li.appendChild(element);
  284. adjustIndentForNewList(element);
  285. element = li;
  286. }
  287. dom.insertAfter(list, element);
  288. list.appendChild(element);
  289. attemptMergeWithAdjacent(list, true);
  290. applied.push(element);
  291. }
  292. function doWrapList(start, end, template) {
  293. var li, n = start, tmp, i;
  294. while (!dom.isBlock(start.parentNode) && start.parentNode !== dom.getRoot()) {
  295. start = dom.split(start.parentNode, start.previousSibling);
  296. start = start.nextSibling;
  297. n = start;
  298. }
  299. if (template) {
  300. li = template.cloneNode(true);
  301. start.parentNode.insertBefore(li, start);
  302. while (li.firstChild) dom.remove(li.firstChild);
  303. li = dom.rename(li, 'li');
  304. } else {
  305. li = dom.create('li');
  306. start.parentNode.insertBefore(li, start);
  307. }
  308. while (n && n != end) {
  309. tmp = n.nextSibling;
  310. li.appendChild(n);
  311. n = tmp;
  312. }
  313. if (li.childNodes.length === 0) {
  314. li.innerHTML = '<br _mce_bogus="1" />';
  315. }
  316. makeList(li);
  317. }
  318. function processBrs(element, callback) {
  319. var startSection, previousBR, END_TO_START = 3, START_TO_END = 1,
  320. breakElements = 'br,ul,ol,p,div,h1,h2,h3,h4,h5,h6,table,blockquote,address,pre,form,center,dl';
  321. function isAnyPartSelected(start, end) {
  322. var r = dom.createRng(), sel;
  323. bookmark.keep = true;
  324. ed.selection.moveToBookmark(bookmark);
  325. bookmark.keep = false;
  326. sel = ed.selection.getRng(true);
  327. if (!end) {
  328. end = start.parentNode.lastChild;
  329. }
  330. r.setStartBefore(start);
  331. r.setEndAfter(end);
  332. return !(r.compareBoundaryPoints(END_TO_START, sel) > 0 || r.compareBoundaryPoints(START_TO_END, sel) <= 0);
  333. }
  334. function nextLeaf(br) {
  335. if (br.nextSibling)
  336. return br.nextSibling;
  337. if (!dom.isBlock(br.parentNode) && br.parentNode !== dom.getRoot())
  338. return nextLeaf(br.parentNode);
  339. }
  340. // Split on BRs within the range and process those.
  341. startSection = element.firstChild;
  342. // First mark the BRs that have any part of the previous section selected.
  343. var trailingContentSelected = false;
  344. each(dom.select(breakElements, element), function(br) {
  345. var b;
  346. if (br.hasAttribute && br.hasAttribute('_mce_bogus')) {
  347. return true; // Skip the bogus Brs that are put in to appease Firefox and Safari.
  348. }
  349. if (isAnyPartSelected(startSection, br)) {
  350. dom.addClass(br, '_mce_tagged_br');
  351. startSection = nextLeaf(br);
  352. }
  353. });
  354. trailingContentSelected = (startSection && isAnyPartSelected(startSection, undefined));
  355. startSection = element.firstChild;
  356. each(dom.select(breakElements, element), function(br) {
  357. // Got a section from start to br.
  358. var tmp = nextLeaf(br);
  359. if (br.hasAttribute && br.hasAttribute('_mce_bogus')) {
  360. return true; // Skip the bogus Brs that are put in to appease Firefox and Safari.
  361. }
  362. if (dom.hasClass(br, '_mce_tagged_br')) {
  363. callback(startSection, br, previousBR);
  364. previousBR = null;
  365. } else {
  366. previousBR = br;
  367. }
  368. startSection = tmp;
  369. });
  370. if (trailingContentSelected) {
  371. callback(startSection, undefined, previousBR);
  372. }
  373. }
  374. function wrapList(element) {
  375. processBrs(element, function(startSection, br, previousBR) {
  376. // Need to indent this part
  377. doWrapList(startSection, br);
  378. cleanupBr(br);
  379. cleanupBr(previousBR);
  380. });
  381. }
  382. function changeList(element) {
  383. if (tinymce.inArray(applied, element) !== -1) {
  384. return;
  385. }
  386. if (element.parentNode.tagName === oppositeListType) {
  387. dom.split(element.parentNode, element);
  388. makeList(element);
  389. attemptMergeWithNext(element.parentNode, false);
  390. }
  391. applied.push(element);
  392. }
  393. function convertListItemToParagraph(element) {
  394. var child, nextChild, mergedElement, splitLast;
  395. if (tinymce.inArray(applied, element) !== -1) {
  396. return;
  397. }
  398. element = splitNestedLists(element, dom);
  399. while (dom.is(element.parentNode, 'ol,ul,li')) {
  400. dom.split(element.parentNode, element);
  401. }
  402. // Push the original element we have from the selection, not the renamed one.
  403. applied.push(element);
  404. element = dom.rename(element, 'p');
  405. mergedElement = attemptMergeWithAdjacent(element, false, ed.settings.force_br_newlines);
  406. if (mergedElement === element) {
  407. // Now split out any block elements that can't be contained within a P.
  408. // Manually iterate to ensure we handle modifications correctly (doesn't work with tinymce.each)
  409. child = element.firstChild;
  410. while (child) {
  411. if (dom.isBlock(child)) {
  412. child = dom.split(child.parentNode, child);
  413. splitLast = true;
  414. nextChild = child.nextSibling && child.nextSibling.firstChild;
  415. } else {
  416. nextChild = child.nextSibling;
  417. if (splitLast && child.tagName === 'BR') {
  418. dom.remove(child);
  419. }
  420. splitLast = false;
  421. }
  422. child = nextChild;
  423. }
  424. }
  425. }
  426. each(selectedBlocks, function(e) {
  427. e = findItemToOperateOn(e, dom);
  428. if (e.tagName === oppositeListType || (e.tagName === 'LI' && e.parentNode.tagName === oppositeListType)) {
  429. hasOppositeType = true;
  430. } else if (e.tagName === targetListType || (e.tagName === 'LI' && e.parentNode.tagName === targetListType)) {
  431. hasSameType = true;
  432. } else {
  433. hasNonList = true;
  434. }
  435. });
  436. if (hasNonList || hasOppositeType || selectedBlocks.length === 0) {
  437. actions = {
  438. 'LI': changeList,
  439. 'H1': makeList,
  440. 'H2': makeList,
  441. 'H3': makeList,
  442. 'H4': makeList,
  443. 'H5': makeList,
  444. 'H6': makeList,
  445. 'P': makeList,
  446. 'BODY': makeList,
  447. 'DIV': selectedBlocks.length > 1 ? makeList : wrapList,
  448. defaultAction: wrapList
  449. };
  450. } else {
  451. actions = {
  452. defaultAction: convertListItemToParagraph
  453. };
  454. }
  455. this.process(actions);
  456. },
  457. indent: function() {
  458. var ed = this.ed, dom = ed.dom, indented = [];
  459. function createWrapItem(element) {
  460. var wrapItem = dom.create('li', { style: 'list-style-type: none;'});
  461. dom.insertAfter(wrapItem, element);
  462. return wrapItem;
  463. }
  464. function createWrapList(element) {
  465. var wrapItem = createWrapItem(element),
  466. list = dom.getParent(element, 'ol,ul'),
  467. listType = list.tagName,
  468. listStyle = dom.getStyle(list, 'list-style-type'),
  469. attrs = {},
  470. wrapList;
  471. if (listStyle !== '') {
  472. attrs.style = 'list-style-type: ' + listStyle + ';';
  473. }
  474. wrapList = dom.create(listType, attrs);
  475. wrapItem.appendChild(wrapList);
  476. return wrapList;
  477. }
  478. function indentLI(element) {
  479. if (!hasParentInList(ed, element, indented)) {
  480. element = splitNestedLists(element, dom);
  481. var wrapList = createWrapList(element);
  482. wrapList.appendChild(element);
  483. attemptMergeWithAdjacent(wrapList.parentNode, false);
  484. attemptMergeWithAdjacent(wrapList, false);
  485. indented.push(element);
  486. }
  487. }
  488. this.process({
  489. 'LI': indentLI,
  490. defaultAction: this.adjustPaddingFunction(true)
  491. });
  492. },
  493. outdent: function() {
  494. var t = this, ed = t.ed, dom = ed.dom, outdented = [];
  495. function outdentLI(element) {
  496. var listElement, targetParent, align;
  497. if (!hasParentInList(ed, element, outdented)) {
  498. if (dom.getStyle(element, 'margin-left') !== '' || dom.getStyle(element, 'padding-left') !== '') {
  499. return t.adjustPaddingFunction(false)(element);
  500. }
  501. align = dom.getStyle(element, 'text-align', true);
  502. if (align === 'center' || align === 'right') {
  503. dom.setStyle(element, 'text-align', 'left');
  504. return;
  505. }
  506. element = splitNestedLists(element, dom);
  507. listElement = element.parentNode;
  508. targetParent = element.parentNode.parentNode;
  509. if (targetParent.tagName === 'P') {
  510. dom.split(targetParent, element.parentNode);
  511. } else {
  512. dom.split(listElement, element);
  513. if (targetParent.tagName === 'LI') {
  514. // Nested list, need to split the LI and go back out to the OL/UL element.
  515. dom.split(targetParent, element);
  516. } else if (!dom.is(targetParent, 'ol,ul')) {
  517. dom.rename(element, 'p');
  518. }
  519. }
  520. outdented.push(element);
  521. }
  522. }
  523. this.process({
  524. 'LI': outdentLI,
  525. defaultAction: this.adjustPaddingFunction(false)
  526. });
  527. each(outdented, attemptMergeWithAdjacent);
  528. },
  529. process: function(actions) {
  530. var t = this, sel = t.ed.selection, dom = t.ed.dom, selectedBlocks, r;
  531. function processElement(element) {
  532. dom.removeClass(element, '_mce_act_on');
  533. if (!element || element.nodeType !== 1) {
  534. return;
  535. }
  536. element = findItemToOperateOn(element, dom);
  537. var action = actions[element.tagName];
  538. if (!action) {
  539. action = actions.defaultAction;
  540. }
  541. action(element);
  542. }
  543. function recurse(element) {
  544. t.splitSafeEach(element.childNodes, processElement);
  545. }
  546. function brAtEdgeOfSelection(container, offset) {
  547. return offset >= 0 && container.hasChildNodes() && offset < container.childNodes.length &&
  548. container.childNodes[offset].tagName === 'BR';
  549. }
  550. selectedBlocks = sel.getSelectedBlocks();
  551. if (selectedBlocks.length === 0) {
  552. selectedBlocks = [ dom.getRoot() ];
  553. }
  554. r = sel.getRng(true);
  555. if (!r.collapsed) {
  556. if (brAtEdgeOfSelection(r.endContainer, r.endOffset - 1)) {
  557. r.setEnd(r.endContainer, r.endOffset - 1);
  558. sel.setRng(r);
  559. }
  560. if (brAtEdgeOfSelection(r.startContainer, r.startOffset)) {
  561. r.setStart(r.startContainer, r.startOffset + 1);
  562. sel.setRng(r);
  563. }
  564. }
  565. bookmark = sel.getBookmark();
  566. actions.OL = actions.UL = recurse;
  567. t.splitSafeEach(selectedBlocks, processElement);
  568. sel.moveToBookmark(bookmark);
  569. bookmark = null;
  570. // Avoids table or image handles being left behind in Firefox.
  571. t.ed.execCommand('mceRepaint');
  572. },
  573. splitSafeEach: function(elements, f) {
  574. if (tinymce.isGecko && (/Firefox\/[12]\.[0-9]/.test(navigator.userAgent) ||
  575. /Firefox\/3\.[0-4]/.test(navigator.userAgent))) {
  576. this.classBasedEach(elements, f);
  577. } else {
  578. each(elements, f);
  579. }
  580. },
  581. classBasedEach: function(elements, f) {
  582. var dom = this.ed.dom, nodes, element;
  583. // Mark nodes
  584. each(elements, function(element) {
  585. dom.addClass(element, '_mce_act_on');
  586. });
  587. nodes = dom.select('._mce_act_on');
  588. while (nodes.length > 0) {
  589. element = nodes.shift();
  590. dom.removeClass(element, '_mce_act_on');
  591. f(element);
  592. nodes = dom.select('._mce_act_on');
  593. }
  594. },
  595. adjustPaddingFunction: function(isIndent) {
  596. var indentAmount, indentUnits, ed = this.ed;
  597. indentAmount = ed.settings.indentation;
  598. indentUnits = /[a-z%]+/i.exec(indentAmount);
  599. indentAmount = parseInt(indentAmount, 10);
  600. return function(element) {
  601. var currentIndent, newIndentAmount;
  602. currentIndent = parseInt(ed.dom.getStyle(element, 'margin-left') || 0, 10) + parseInt(ed.dom.getStyle(element, 'padding-left') || 0, 10);
  603. if (isIndent) {
  604. newIndentAmount = currentIndent + indentAmount;
  605. } else {
  606. newIndentAmount = currentIndent - indentAmount;
  607. }
  608. ed.dom.setStyle(element, 'padding-left', '');
  609. ed.dom.setStyle(element, 'margin-left', newIndentAmount > 0 ? newIndentAmount + indentUnits : '');
  610. };
  611. },
  612. getInfo: function() {
  613. return {
  614. longname : 'Lists',
  615. author : 'Moxiecode Systems AB',
  616. authorurl : 'http://tinymce.moxiecode.com',
  617. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/lists',
  618. version : tinymce.majorVersion + "." + tinymce.minorVersion
  619. };
  620. }
  621. });
  622. tinymce.PluginManager.add("lists", tinymce.plugins.Lists);
  623. }());