ueditor.parse.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. /*!
  2. * UEditorPlus parse
  3. * version: 2.0.0
  4. */
  5. (function(){
  6. (function () {
  7. UE = window.UE || {};
  8. var isIE = !!window.ActiveXObject;
  9. //定义utils工具
  10. var utils = {
  11. removeLastbs: function (url) {
  12. return url.replace(/\/$/, "");
  13. },
  14. extend: function (t, s) {
  15. var a = arguments,
  16. notCover = this.isBoolean(a[a.length - 1]) ? a[a.length - 1] : false,
  17. len = this.isBoolean(a[a.length - 1]) ? a.length - 1 : a.length;
  18. for (var i = 1; i < len; i++) {
  19. var x = a[i];
  20. for (var k in x) {
  21. if (!notCover || !t.hasOwnProperty(k)) {
  22. t[k] = x[k];
  23. }
  24. }
  25. }
  26. return t;
  27. },
  28. isIE: isIE,
  29. cssRule: isIE
  30. ? function (key, style, doc) {
  31. var indexList, index;
  32. doc = doc || document;
  33. if (doc.indexList) {
  34. indexList = doc.indexList;
  35. } else {
  36. indexList = doc.indexList = {};
  37. }
  38. var sheetStyle;
  39. if (!indexList[key]) {
  40. if (style === undefined) {
  41. return "";
  42. }
  43. sheetStyle = doc.createStyleSheet(
  44. "",
  45. (index = doc.styleSheets.length)
  46. );
  47. indexList[key] = index;
  48. } else {
  49. sheetStyle = doc.styleSheets[indexList[key]];
  50. }
  51. if (style === undefined) {
  52. return sheetStyle.cssText;
  53. }
  54. sheetStyle.cssText = sheetStyle.cssText + "\n" + (style || "");
  55. }
  56. : function (key, style, doc) {
  57. doc = doc || document;
  58. var head = doc.getElementsByTagName("head")[0],
  59. node;
  60. if (!(node = doc.getElementById(key))) {
  61. if (style === undefined) {
  62. return "";
  63. }
  64. node = doc.createElement("style");
  65. node.id = key;
  66. head.appendChild(node);
  67. }
  68. if (style === undefined) {
  69. return node.innerHTML;
  70. }
  71. if (style !== "") {
  72. node.innerHTML = node.innerHTML + "\n" + style;
  73. } else {
  74. head.removeChild(node);
  75. }
  76. },
  77. domReady: function (onready) {
  78. var doc = window.document;
  79. if (doc.readyState === "complete") {
  80. onready();
  81. } else {
  82. if (isIE) {
  83. (function () {
  84. if (doc.isReady) return;
  85. try {
  86. doc.documentElement.doScroll("left");
  87. } catch (error) {
  88. setTimeout(arguments.callee, 0);
  89. return;
  90. }
  91. onready();
  92. })();
  93. window.attachEvent("onload", function () {
  94. onready();
  95. });
  96. } else {
  97. doc.addEventListener(
  98. "DOMContentLoaded",
  99. function () {
  100. doc.removeEventListener(
  101. "DOMContentLoaded",
  102. arguments.callee,
  103. false
  104. );
  105. onready();
  106. },
  107. false
  108. );
  109. window.addEventListener(
  110. "load",
  111. function () {
  112. onready();
  113. },
  114. false
  115. );
  116. }
  117. }
  118. },
  119. each: function (obj, iterator, context) {
  120. if (obj == null) return;
  121. if (obj.length === +obj.length) {
  122. for (var i = 0, l = obj.length; i < l; i++) {
  123. if (iterator.call(context, obj[i], i, obj) === false) return false;
  124. }
  125. } else {
  126. for (var key in obj) {
  127. if (obj.hasOwnProperty(key)) {
  128. if (iterator.call(context, obj[key], key, obj) === false)
  129. return false;
  130. }
  131. }
  132. }
  133. },
  134. inArray: function (arr, item) {
  135. var index = -1;
  136. this.each(arr, function (v, i) {
  137. if (v === item) {
  138. index = i;
  139. return false;
  140. }
  141. });
  142. return index;
  143. },
  144. pushItem: function (arr, item) {
  145. if (this.inArray(arr, item) == -1) {
  146. arr.push(item);
  147. }
  148. },
  149. trim: function (str) {
  150. return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, "");
  151. },
  152. indexOf: function (array, item, start) {
  153. var index = -1;
  154. start = this.isNumber(start) ? start : 0;
  155. this.each(array, function (v, i) {
  156. if (i >= start && v === item) {
  157. index = i;
  158. return false;
  159. }
  160. });
  161. return index;
  162. },
  163. hasClass: function (element, className) {
  164. className = className
  165. .replace(/(^[ ]+)|([ ]+$)/g, "")
  166. .replace(/[ ]{2,}/g, " ")
  167. .split(" ");
  168. for (var i = 0, ci, cls = element.className; (ci = className[i++]);) {
  169. if (!new RegExp("\\b" + ci + "\\b", "i").test(cls)) {
  170. return false;
  171. }
  172. }
  173. return i - 1 == className.length;
  174. },
  175. addClass: function (elm, classNames) {
  176. if (!elm) return;
  177. classNames = this.trim(classNames).replace(/[ ]{2,}/g, " ").split(" ");
  178. for (var i = 0, ci, cls = elm.className; (ci = classNames[i++]);) {
  179. if (!new RegExp("\\b" + ci + "\\b").test(cls)) {
  180. cls += " " + ci;
  181. }
  182. }
  183. elm.className = utils.trim(cls);
  184. },
  185. removeClass: function (elm, classNames) {
  186. classNames = this.isArray(classNames)
  187. ? classNames
  188. : this.trim(classNames).replace(/[ ]{2,}/g, " ").split(" ");
  189. for (var i = 0, ci, cls = elm.className; (ci = classNames[i++]);) {
  190. cls = cls.replace(new RegExp("\\b" + ci + "\\b"), "");
  191. }
  192. cls = this.trim(cls).replace(/[ ]{2,}/g, " ");
  193. elm.className = cls;
  194. !cls && elm.removeAttribute("className");
  195. },
  196. on: function (element, type, handler) {
  197. var types = this.isArray(type) ? type : type.split(/\s+/),
  198. k = types.length;
  199. if (k)
  200. while (k--) {
  201. type = types[k];
  202. if (element.addEventListener) {
  203. element.addEventListener(type, handler, false);
  204. } else {
  205. if (!handler._d) {
  206. handler._d = {
  207. els: []
  208. };
  209. }
  210. var key = type + handler.toString(),
  211. index = utils.indexOf(handler._d.els, element);
  212. if (!handler._d[key] || index == -1) {
  213. if (index == -1) {
  214. handler._d.els.push(element);
  215. }
  216. if (!handler._d[key]) {
  217. handler._d[key] = function (evt) {
  218. return handler.call(evt.srcElement, evt || window.event);
  219. };
  220. }
  221. element.attachEvent("on" + type, handler._d[key]);
  222. }
  223. }
  224. }
  225. element = null;
  226. },
  227. off: function (element, type, handler) {
  228. var types = this.isArray(type) ? type : type.split(/\s+/),
  229. k = types.length;
  230. if (k)
  231. while (k--) {
  232. type = types[k];
  233. if (element.removeEventListener) {
  234. element.removeEventListener(type, handler, false);
  235. } else {
  236. var key = type + handler.toString();
  237. try {
  238. element.detachEvent(
  239. "on" + type,
  240. handler._d ? handler._d[key] : handler
  241. );
  242. } catch (e) {
  243. }
  244. if (handler._d && handler._d[key]) {
  245. var index = utils.indexOf(handler._d.els, element);
  246. if (index != -1) {
  247. handler._d.els.splice(index, 1);
  248. }
  249. handler._d.els.length == 0 && delete handler._d[key];
  250. }
  251. }
  252. }
  253. },
  254. loadFile: (function () {
  255. var tmpList = [];
  256. function getItem(doc, obj) {
  257. try {
  258. for (var i = 0, ci; (ci = tmpList[i++]);) {
  259. if (ci.doc === doc && ci.url == (obj.src || obj.href)) {
  260. return ci;
  261. }
  262. }
  263. } catch (e) {
  264. return null;
  265. }
  266. }
  267. return function (doc, obj, fn) {
  268. var item = getItem(doc, obj);
  269. if (item) {
  270. if (item.ready) {
  271. fn && fn();
  272. } else {
  273. item.funs.push(fn);
  274. }
  275. return;
  276. }
  277. tmpList.push({
  278. doc: doc,
  279. url: obj.src || obj.href,
  280. funs: [fn]
  281. });
  282. if (!doc.body) {
  283. var html = [];
  284. for (var p in obj) {
  285. if (p == "tag") continue;
  286. html.push(p + '="' + obj[p] + '"');
  287. }
  288. doc.write(
  289. "<" + obj.tag + " " + html.join(" ") + " ></" + obj.tag + ">"
  290. );
  291. return;
  292. }
  293. if (obj.id && doc.getElementById(obj.id)) {
  294. return;
  295. }
  296. var element = doc.createElement(obj.tag);
  297. delete obj.tag;
  298. for (var p in obj) {
  299. element.setAttribute(p, obj[p]);
  300. }
  301. element.onload = element.onreadystatechange = function () {
  302. if (!this.readyState || /loaded|complete/.test(this.readyState)) {
  303. item = getItem(doc, obj);
  304. if (item.funs.length > 0) {
  305. item.ready = 1;
  306. for (var fi; (fi = item.funs.pop());) {
  307. fi();
  308. }
  309. }
  310. element.onload = element.onreadystatechange = null;
  311. }
  312. };
  313. element.onerror = function () {
  314. throw Error(
  315. "The load " + (obj.href || obj.src) + " fails,check the url"
  316. );
  317. };
  318. doc.getElementsByTagName("head")[0].appendChild(element);
  319. };
  320. })()
  321. };
  322. utils.each(
  323. ["String", "Function", "Array", "Number", "RegExp", "Object", "Boolean"],
  324. function (v) {
  325. utils["is" + v] = function (obj) {
  326. return Object.prototype.toString.apply(obj) == "[object " + v + "]";
  327. };
  328. }
  329. );
  330. var parselist = {};
  331. UE.parse = {
  332. register: function (parseName, fn) {
  333. parselist[parseName] = fn;
  334. },
  335. load: function (opt) {
  336. utils.each(parselist, function (v) {
  337. v.call(opt, utils);
  338. });
  339. }
  340. };
  341. uParse = function (selector, opt) {
  342. utils.domReady(function () {
  343. var contents;
  344. if (document.querySelectorAll) {
  345. contents = document.querySelectorAll(selector);
  346. } else {
  347. if (/^#/.test(selector)) {
  348. contents = [document.getElementById(selector.replace(/^#/, ""))];
  349. } else if (/^\./.test(selector)) {
  350. var contents = [];
  351. utils.each(document.getElementsByTagName("*"), function (node) {
  352. if (
  353. node.className &&
  354. new RegExp("\\b" + selector.replace(/^\./, "") + "\\b", "i").test(
  355. node.className
  356. )
  357. ) {
  358. contents.push(node);
  359. }
  360. });
  361. } else {
  362. contents = document.getElementsByTagName(selector);
  363. }
  364. }
  365. utils.each(contents, function (v) {
  366. UE.parse.load(utils.extend({root: v, selector: selector}, opt));
  367. });
  368. });
  369. };
  370. })();
  371. UE.parse.register("insertcode", function (utils) {
  372. var pres = this.root.getElementsByTagName("pre");
  373. if (pres.length) {
  374. if (typeof XRegExp == "undefined") {
  375. var jsurl, cssurl;
  376. if (this.rootPath !== undefined) {
  377. jsurl =
  378. utils.removeLastbs(this.rootPath) +
  379. "/third-party/SyntaxHighlighter/shCore.js";
  380. cssurl =
  381. utils.removeLastbs(this.rootPath) +
  382. "/third-party/SyntaxHighlighter/shCoreDefault.css";
  383. } else {
  384. jsurl = this.highlightJsUrl;
  385. cssurl = this.highlightCssUrl;
  386. }
  387. utils.loadFile(document, {
  388. id: "syntaxhighlighter_css",
  389. tag: "link",
  390. rel: "stylesheet",
  391. type: "text/css",
  392. href: cssurl
  393. });
  394. utils.loadFile(
  395. document,
  396. {
  397. id: "syntaxhighlighter_js",
  398. src: jsurl,
  399. tag: "script",
  400. type: "text/javascript",
  401. defer: "defer"
  402. },
  403. function () {
  404. utils.each(pres, function (pi) {
  405. if (pi && /brush/i.test(pi.className)) {
  406. SyntaxHighlighter.highlight(pi);
  407. }
  408. });
  409. }
  410. );
  411. } else {
  412. utils.each(pres, function (pi) {
  413. if (pi && /brush/i.test(pi.className)) {
  414. SyntaxHighlighter.highlight(pi);
  415. }
  416. });
  417. }
  418. }
  419. });
  420. UE.parse.register("table", function (utils) {
  421. var me = this,
  422. root = this.root,
  423. tables = root.getElementsByTagName("table");
  424. if (tables.length) {
  425. var selector = this.selector;
  426. //追加默认的表格样式
  427. utils.cssRule(
  428. "table",
  429. selector +
  430. " table.noBorderTable td," +
  431. selector +
  432. " table.noBorderTable th," +
  433. selector +
  434. " table.noBorderTable caption{border:1px dashed #ddd !important}" +
  435. selector +
  436. " table.sortEnabled tr.firstRow th," +
  437. selector +
  438. " table.sortEnabled tr.firstRow td{padding-right:20px; background-repeat: no-repeat;" +
  439. "background-position: center right; background-image:url(" +
  440. this.rootPath +
  441. "themes/default/images/sortable.png);}" +
  442. selector +
  443. " table.sortEnabled tr.firstRow th:hover," +
  444. selector +
  445. " table.sortEnabled tr.firstRow td:hover{background-color: #EEE;}" +
  446. selector +
  447. " table{margin-bottom:10px;border-collapse:collapse;display:table;}" +
  448. selector +
  449. " td," +
  450. selector +
  451. " th{padding: 5px 10px;border: 1px solid #DDD;}" +
  452. selector +
  453. " caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}" +
  454. selector +
  455. " th{border-top:1px solid #BBB;background:#F7F7F7;}" +
  456. selector +
  457. " table tr.firstRow th{border-top:2px solid #BBB;background:#F7F7F7;}" +
  458. selector +
  459. " tr.ue-table-interlace-color-single td{ background: #fcfcfc; }" +
  460. selector +
  461. " tr.ue-table-interlace-color-double td{ background: #f7faff; }" +
  462. selector +
  463. " td p{margin:0;padding:0;width:auto;height:auto;}",
  464. document
  465. );
  466. //填充空的单元格
  467. utils.each("td th caption".split(" "), function (tag) {
  468. var cells = root.getElementsByTagName(tag);
  469. cells.length &&
  470. utils.each(cells, function (node) {
  471. if (!node.firstChild) {
  472. node.innerHTML = "&nbsp;";
  473. }
  474. });
  475. });
  476. //表格可排序
  477. var tables = root.getElementsByTagName("table");
  478. utils.each(tables, function (table) {
  479. if (/\bsortEnabled\b/.test(table.className)) {
  480. utils.on(table, "click", function (e) {
  481. var target = e.target || e.srcElement,
  482. cell = findParentByTagName(target, ["td", "th"]);
  483. var table = findParentByTagName(target, "table"),
  484. colIndex = utils.indexOf(table.rows[0].cells, cell),
  485. sortType = table.getAttribute("data-sort-type");
  486. if (colIndex != -1) {
  487. sortTable(table, colIndex, me.tableSortCompareFn || sortType);
  488. updateTable(table);
  489. }
  490. });
  491. }
  492. });
  493. //按照标签名查找父节点
  494. function findParentByTagName(target, tagNames) {
  495. var i,
  496. current = target;
  497. tagNames = utils.isArray(tagNames) ? tagNames : [tagNames];
  498. while (current) {
  499. for (i = 0; i < tagNames.length; i++) {
  500. if (current.tagName == tagNames[i].toUpperCase()) return current;
  501. }
  502. current = current.parentNode;
  503. }
  504. return null;
  505. }
  506. //表格排序
  507. function sortTable(table, sortByCellIndex, compareFn) {
  508. var rows = table.rows,
  509. trArray = [],
  510. flag = rows[0].cells[0].tagName === "TH",
  511. lastRowIndex = 0;
  512. for (var i = 0, len = rows.length; i < len; i++) {
  513. trArray[i] = rows[i];
  514. }
  515. var Fn = {
  516. reversecurrent: function (td1, td2) {
  517. return 1;
  518. },
  519. orderbyasc: function (td1, td2) {
  520. var value1 = td1.innerText || td1.textContent,
  521. value2 = td2.innerText || td2.textContent;
  522. return value1.localeCompare(value2);
  523. },
  524. reversebyasc: function (td1, td2) {
  525. var value1 = td1.innerHTML,
  526. value2 = td2.innerHTML;
  527. return value2.localeCompare(value1);
  528. },
  529. orderbynum: function (td1, td2) {
  530. var value1 = td1[utils.isIE ? "innerText" : "textContent"].match(
  531. /\d+/
  532. ),
  533. value2 = td2[utils.isIE ? "innerText" : "textContent"].match(/\d+/);
  534. if (value1) value1 = +value1[0];
  535. if (value2) value2 = +value2[0];
  536. return (value1 || 0) - (value2 || 0);
  537. },
  538. reversebynum: function (td1, td2) {
  539. var value1 = td1[utils.isIE ? "innerText" : "textContent"].match(
  540. /\d+/
  541. ),
  542. value2 = td2[utils.isIE ? "innerText" : "textContent"].match(/\d+/);
  543. if (value1) value1 = +value1[0];
  544. if (value2) value2 = +value2[0];
  545. return (value2 || 0) - (value1 || 0);
  546. }
  547. };
  548. //对表格设置排序的标记data-sort-type
  549. table.setAttribute(
  550. "data-sort-type",
  551. compareFn && typeof compareFn === "string" && Fn[compareFn]
  552. ? compareFn
  553. : ""
  554. );
  555. //th不参与排序
  556. flag && trArray.splice(0, 1);
  557. trArray = sort(trArray, function (tr1, tr2) {
  558. var result;
  559. if (compareFn && typeof compareFn === "function") {
  560. result = compareFn.call(
  561. this,
  562. tr1.cells[sortByCellIndex],
  563. tr2.cells[sortByCellIndex]
  564. );
  565. } else if (compareFn && typeof compareFn === "number") {
  566. result = 1;
  567. } else if (
  568. compareFn &&
  569. typeof compareFn === "string" &&
  570. Fn[compareFn]
  571. ) {
  572. result = Fn[compareFn].call(
  573. this,
  574. tr1.cells[sortByCellIndex],
  575. tr2.cells[sortByCellIndex]
  576. );
  577. } else {
  578. result = Fn["orderbyasc"].call(
  579. this,
  580. tr1.cells[sortByCellIndex],
  581. tr2.cells[sortByCellIndex]
  582. );
  583. }
  584. return result;
  585. });
  586. var fragment = table.ownerDocument.createDocumentFragment();
  587. for (var j = 0, len = trArray.length; j < len; j++) {
  588. fragment.appendChild(trArray[j]);
  589. }
  590. var tbody = table.getElementsByTagName("tbody")[0];
  591. if (!lastRowIndex) {
  592. tbody.appendChild(fragment);
  593. } else {
  594. tbody.insertBefore(
  595. fragment,
  596. rows[lastRowIndex - range.endRowIndex + range.beginRowIndex - 1]
  597. );
  598. }
  599. }
  600. //冒泡排序
  601. function sort(array, compareFn) {
  602. compareFn =
  603. compareFn ||
  604. function (item1, item2) {
  605. return item1.localeCompare(item2);
  606. };
  607. for (var i = 0, len = array.length; i < len; i++) {
  608. for (var j = i, length = array.length; j < length; j++) {
  609. if (compareFn(array[i], array[j]) > 0) {
  610. var t = array[i];
  611. array[i] = array[j];
  612. array[j] = t;
  613. }
  614. }
  615. }
  616. return array;
  617. }
  618. //更新表格
  619. function updateTable(table) {
  620. //给第一行设置firstRow的样式名称,在排序图标的样式上使用到
  621. if (!utils.hasClass(table.rows[0], "firstRow")) {
  622. for (var i = 1; i < table.rows.length; i++) {
  623. utils.removeClass(table.rows[i], "firstRow");
  624. }
  625. utils.addClass(table.rows[0], "firstRow");
  626. }
  627. }
  628. }
  629. });
  630. UE.parse.register("background", function (utils) {
  631. var me = this,
  632. root = me.root,
  633. p = root.getElementsByTagName("p"),
  634. styles;
  635. for (var i = 0, ci; (ci = p[i++]);) {
  636. styles = ci.getAttribute("data-background");
  637. if (styles) {
  638. ci.parentNode.removeChild(ci);
  639. }
  640. }
  641. //追加默认的表格样式
  642. styles &&
  643. utils.cssRule(
  644. "ueditor_background",
  645. me.selector + "{" + styles + "}",
  646. document
  647. );
  648. });
  649. UE.parse.register("list", function (utils) {
  650. var customCss = [],
  651. customStyle = {
  652. cn: "cn-1-",
  653. cn1: "cn-2-",
  654. cn2: "cn-3-",
  655. num: "num-1-",
  656. num1: "num-2-",
  657. num2: "num-3-",
  658. dash: "dash",
  659. dot: "dot"
  660. };
  661. utils.extend(this, {
  662. liiconpath: "http://bs.baidu.com/listicon/",
  663. listDefaultPaddingLeft: "20"
  664. });
  665. var root = this.root,
  666. ols = root.getElementsByTagName("ol"),
  667. uls = root.getElementsByTagName("ul"),
  668. selector = this.selector;
  669. if (ols.length) {
  670. applyStyle.call(this, ols);
  671. }
  672. if (uls.length) {
  673. applyStyle.call(this, uls);
  674. }
  675. if (ols.length || uls.length) {
  676. customCss.push(selector + " .list-paddingleft-1{padding-left:0}");
  677. customCss.push(
  678. selector +
  679. " .list-paddingleft-2{padding-left:" +
  680. this.listDefaultPaddingLeft +
  681. "px}"
  682. );
  683. customCss.push(
  684. selector +
  685. " .list-paddingleft-3{padding-left:" +
  686. this.listDefaultPaddingLeft * 2 +
  687. "px}"
  688. );
  689. utils.cssRule(
  690. "list",
  691. selector +
  692. " ol," +
  693. selector +
  694. " ul{margin:0;padding:0;}\n" +
  695. selector +
  696. " li{clear:both;}\n" +
  697. customCss.join("\n"),
  698. document
  699. );
  700. }
  701. function applyStyle(nodes) {
  702. var T = this;
  703. utils.each(nodes, function (list) {
  704. if (list.className && /custom_/i.test(list.className)) {
  705. var listStyle = list.className.match(/custom_(\w+)/)[1];
  706. if (listStyle == "dash" || listStyle == "dot") {
  707. utils.pushItem(
  708. customCss,
  709. selector +
  710. " li.list-" +
  711. customStyle[listStyle] +
  712. "{background-image:url(" +
  713. T.liiconpath +
  714. customStyle[listStyle] +
  715. ".gif)}"
  716. );
  717. utils.pushItem(
  718. customCss,
  719. selector +
  720. " ul.custom_" +
  721. listStyle +
  722. "{list-style:none;} " +
  723. selector +
  724. " ul.custom_" +
  725. listStyle +
  726. " li{background-position:0 3px;background-repeat:no-repeat}"
  727. );
  728. } else {
  729. var index = 1;
  730. utils.each(list.childNodes, function (li) {
  731. if (li.tagName == "LI") {
  732. utils.pushItem(
  733. customCss,
  734. selector +
  735. " li.list-" +
  736. customStyle[listStyle] +
  737. index +
  738. "{background-image:url(" +
  739. T.liiconpath +
  740. "list-" +
  741. customStyle[listStyle] +
  742. index +
  743. ".gif)}"
  744. );
  745. index++;
  746. }
  747. });
  748. utils.pushItem(
  749. customCss,
  750. selector +
  751. " ol.custom_" +
  752. listStyle +
  753. "{list-style:none;}" +
  754. selector +
  755. " ol.custom_" +
  756. listStyle +
  757. " li{background-position:0 3px;background-repeat:no-repeat}"
  758. );
  759. }
  760. switch (listStyle) {
  761. case "cn":
  762. utils.pushItem(
  763. customCss,
  764. selector +
  765. " li.list-" +
  766. listStyle +
  767. "-paddingleft-1{padding-left:25px}"
  768. );
  769. utils.pushItem(
  770. customCss,
  771. selector +
  772. " li.list-" +
  773. listStyle +
  774. "-paddingleft-2{padding-left:40px}"
  775. );
  776. utils.pushItem(
  777. customCss,
  778. selector +
  779. " li.list-" +
  780. listStyle +
  781. "-paddingleft-3{padding-left:55px}"
  782. );
  783. break;
  784. case "cn1":
  785. utils.pushItem(
  786. customCss,
  787. selector +
  788. " li.list-" +
  789. listStyle +
  790. "-paddingleft-1{padding-left:30px}"
  791. );
  792. utils.pushItem(
  793. customCss,
  794. selector +
  795. " li.list-" +
  796. listStyle +
  797. "-paddingleft-2{padding-left:40px}"
  798. );
  799. utils.pushItem(
  800. customCss,
  801. selector +
  802. " li.list-" +
  803. listStyle +
  804. "-paddingleft-3{padding-left:55px}"
  805. );
  806. break;
  807. case "cn2":
  808. utils.pushItem(
  809. customCss,
  810. selector +
  811. " li.list-" +
  812. listStyle +
  813. "-paddingleft-1{padding-left:40px}"
  814. );
  815. utils.pushItem(
  816. customCss,
  817. selector +
  818. " li.list-" +
  819. listStyle +
  820. "-paddingleft-2{padding-left:55px}"
  821. );
  822. utils.pushItem(
  823. customCss,
  824. selector +
  825. " li.list-" +
  826. listStyle +
  827. "-paddingleft-3{padding-left:68px}"
  828. );
  829. break;
  830. case "num":
  831. case "num1":
  832. utils.pushItem(
  833. customCss,
  834. selector +
  835. " li.list-" +
  836. listStyle +
  837. "-paddingleft-1{padding-left:25px}"
  838. );
  839. break;
  840. case "num2":
  841. utils.pushItem(
  842. customCss,
  843. selector +
  844. " li.list-" +
  845. listStyle +
  846. "-paddingleft-1{padding-left:35px}"
  847. );
  848. utils.pushItem(
  849. customCss,
  850. selector +
  851. " li.list-" +
  852. listStyle +
  853. "-paddingleft-2{padding-left:40px}"
  854. );
  855. break;
  856. case "dash":
  857. utils.pushItem(
  858. customCss,
  859. selector +
  860. " li.list-" +
  861. listStyle +
  862. "-paddingleft{padding-left:35px}"
  863. );
  864. break;
  865. case "dot":
  866. utils.pushItem(
  867. customCss,
  868. selector +
  869. " li.list-" +
  870. listStyle +
  871. "-paddingleft{padding-left:20px}"
  872. );
  873. }
  874. }
  875. });
  876. }
  877. });
  878. })();