心理咨询网
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.

ueditor.parse.js 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  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. if (handler._d && handler._d[key]) {
  244. var index = utils.indexOf(handler._d.els, element);
  245. if (index != -1) {
  246. handler._d.els.splice(index, 1);
  247. }
  248. handler._d.els.length == 0 && delete handler._d[key];
  249. }
  250. }
  251. }
  252. },
  253. loadFile: (function() {
  254. var tmpList = [];
  255. function getItem(doc, obj) {
  256. try {
  257. for (var i = 0, ci; (ci = tmpList[i++]); ) {
  258. if (ci.doc === doc && ci.url == (obj.src || obj.href)) {
  259. return ci;
  260. }
  261. }
  262. } catch (e) {
  263. return null;
  264. }
  265. }
  266. return function(doc, obj, fn) {
  267. var item = getItem(doc, obj);
  268. if (item) {
  269. if (item.ready) {
  270. fn && fn();
  271. } else {
  272. item.funs.push(fn);
  273. }
  274. return;
  275. }
  276. tmpList.push({
  277. doc: doc,
  278. url: obj.src || obj.href,
  279. funs: [fn]
  280. });
  281. if (!doc.body) {
  282. var html = [];
  283. for (var p in obj) {
  284. if (p == "tag") continue;
  285. html.push(p + '="' + obj[p] + '"');
  286. }
  287. doc.write(
  288. "<" + obj.tag + " " + html.join(" ") + " ></" + obj.tag + ">"
  289. );
  290. return;
  291. }
  292. if (obj.id && doc.getElementById(obj.id)) {
  293. return;
  294. }
  295. var element = doc.createElement(obj.tag);
  296. delete obj.tag;
  297. for (var p in obj) {
  298. element.setAttribute(p, obj[p]);
  299. }
  300. element.onload = element.onreadystatechange = function() {
  301. if (!this.readyState || /loaded|complete/.test(this.readyState)) {
  302. item = getItem(doc, obj);
  303. if (item.funs.length > 0) {
  304. item.ready = 1;
  305. for (var fi; (fi = item.funs.pop()); ) {
  306. fi();
  307. }
  308. }
  309. element.onload = element.onreadystatechange = null;
  310. }
  311. };
  312. element.onerror = function() {
  313. throw Error(
  314. "The load " + (obj.href || obj.src) + " fails,check the url"
  315. );
  316. };
  317. doc.getElementsByTagName("head")[0].appendChild(element);
  318. };
  319. })()
  320. };
  321. utils.each(
  322. ["String", "Function", "Array", "Number", "RegExp", "Object", "Boolean"],
  323. function(v) {
  324. utils["is" + v] = function(obj) {
  325. return Object.prototype.toString.apply(obj) == "[object " + v + "]";
  326. };
  327. }
  328. );
  329. var parselist = {};
  330. UE.parse = {
  331. register: function(parseName, fn) {
  332. parselist[parseName] = fn;
  333. },
  334. load: function(opt) {
  335. utils.each(parselist, function(v) {
  336. v.call(opt, utils);
  337. });
  338. }
  339. };
  340. uParse = function(selector, opt) {
  341. utils.domReady(function() {
  342. var contents;
  343. if (document.querySelectorAll) {
  344. contents = document.querySelectorAll(selector);
  345. } else {
  346. if (/^#/.test(selector)) {
  347. contents = [document.getElementById(selector.replace(/^#/, ""))];
  348. } else if (/^\./.test(selector)) {
  349. var contents = [];
  350. utils.each(document.getElementsByTagName("*"), function(node) {
  351. if (
  352. node.className &&
  353. new RegExp("\\b" + selector.replace(/^\./, "") + "\\b", "i").test(
  354. node.className
  355. )
  356. ) {
  357. contents.push(node);
  358. }
  359. });
  360. } else {
  361. contents = document.getElementsByTagName(selector);
  362. }
  363. }
  364. utils.each(contents, function(v) {
  365. UE.parse.load(utils.extend({ root: v, selector: selector }, opt));
  366. });
  367. });
  368. };
  369. })();
  370. UE.parse.register("insertcode", function(utils) {
  371. var pres = this.root.getElementsByTagName("pre");
  372. if (pres.length) {
  373. if (typeof XRegExp == "undefined") {
  374. var jsurl, cssurl;
  375. if (this.rootPath !== undefined) {
  376. jsurl =
  377. utils.removeLastbs(this.rootPath) +
  378. "/third-party/SyntaxHighlighter/shCore.js";
  379. cssurl =
  380. utils.removeLastbs(this.rootPath) +
  381. "/third-party/SyntaxHighlighter/shCoreDefault.css";
  382. } else {
  383. jsurl = this.highlightJsUrl;
  384. cssurl = this.highlightCssUrl;
  385. }
  386. utils.loadFile(document, {
  387. id: "syntaxhighlighter_css",
  388. tag: "link",
  389. rel: "stylesheet",
  390. type: "text/css",
  391. href: cssurl
  392. });
  393. utils.loadFile(
  394. document,
  395. {
  396. id: "syntaxhighlighter_js",
  397. src: jsurl,
  398. tag: "script",
  399. type: "text/javascript",
  400. defer: "defer"
  401. },
  402. function() {
  403. utils.each(pres, function(pi) {
  404. if (pi && /brush/i.test(pi.className)) {
  405. SyntaxHighlighter.highlight(pi);
  406. }
  407. });
  408. }
  409. );
  410. } else {
  411. utils.each(pres, function(pi) {
  412. if (pi && /brush/i.test(pi.className)) {
  413. SyntaxHighlighter.highlight(pi);
  414. }
  415. });
  416. }
  417. }
  418. });
  419. UE.parse.register("table", function(utils) {
  420. var me = this,
  421. root = this.root,
  422. tables = root.getElementsByTagName("table");
  423. if (tables.length) {
  424. var selector = this.selector;
  425. //追加默认的表格样式
  426. utils.cssRule(
  427. "table",
  428. selector +
  429. " table.noBorderTable td," +
  430. selector +
  431. " table.noBorderTable th," +
  432. selector +
  433. " table.noBorderTable caption{border:1px dashed #ddd !important}" +
  434. selector +
  435. " table.sortEnabled tr.firstRow th," +
  436. selector +
  437. " table.sortEnabled tr.firstRow td{padding-right:20px; background-repeat: no-repeat;" +
  438. "background-position: center right; background-image:url(" +
  439. this.rootPath +
  440. "themes/default/images/sortable.png);}" +
  441. selector +
  442. " table.sortEnabled tr.firstRow th:hover," +
  443. selector +
  444. " table.sortEnabled tr.firstRow td:hover{background-color: #EEE;}" +
  445. selector +
  446. " table{margin-bottom:10px;border-collapse:collapse;display:table;}" +
  447. selector +
  448. " td," +
  449. selector +
  450. " th{padding: 5px 10px;border: 1px solid #DDD;}" +
  451. selector +
  452. " caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}" +
  453. selector +
  454. " th{border-top:1px solid #BBB;background:#F7F7F7;}" +
  455. selector +
  456. " table tr.firstRow th{border-top:2px solid #BBB;background:#F7F7F7;}" +
  457. selector +
  458. " tr.ue-table-interlace-color-single td{ background: #fcfcfc; }" +
  459. selector +
  460. " tr.ue-table-interlace-color-double td{ background: #f7faff; }" +
  461. selector +
  462. " td p{margin:0;padding:0;width:auto;height:auto;}",
  463. document
  464. );
  465. //填充空的单元格
  466. utils.each("td th caption".split(" "), function(tag) {
  467. var cells = root.getElementsByTagName(tag);
  468. cells.length &&
  469. utils.each(cells, function(node) {
  470. if (!node.firstChild) {
  471. node.innerHTML = "&nbsp;";
  472. }
  473. });
  474. });
  475. //表格可排序
  476. var tables = root.getElementsByTagName("table");
  477. utils.each(tables, function(table) {
  478. if (/\bsortEnabled\b/.test(table.className)) {
  479. utils.on(table, "click", function(e) {
  480. var target = e.target || e.srcElement,
  481. cell = findParentByTagName(target, ["td", "th"]);
  482. var table = findParentByTagName(target, "table"),
  483. colIndex = utils.indexOf(table.rows[0].cells, cell),
  484. sortType = table.getAttribute("data-sort-type");
  485. if (colIndex != -1) {
  486. sortTable(table, colIndex, me.tableSortCompareFn || sortType);
  487. updateTable(table);
  488. }
  489. });
  490. }
  491. });
  492. //按照标签名查找父节点
  493. function findParentByTagName(target, tagNames) {
  494. var i,
  495. current = target;
  496. tagNames = utils.isArray(tagNames) ? tagNames : [tagNames];
  497. while (current) {
  498. for (i = 0; i < tagNames.length; i++) {
  499. if (current.tagName == tagNames[i].toUpperCase()) return current;
  500. }
  501. current = current.parentNode;
  502. }
  503. return null;
  504. }
  505. //表格排序
  506. function sortTable(table, sortByCellIndex, compareFn) {
  507. var rows = table.rows,
  508. trArray = [],
  509. flag = rows[0].cells[0].tagName === "TH",
  510. lastRowIndex = 0;
  511. for (var i = 0, len = rows.length; i < len; i++) {
  512. trArray[i] = rows[i];
  513. }
  514. var Fn = {
  515. reversecurrent: function(td1, td2) {
  516. return 1;
  517. },
  518. orderbyasc: function(td1, td2) {
  519. var value1 = td1.innerText || td1.textContent,
  520. value2 = td2.innerText || td2.textContent;
  521. return value1.localeCompare(value2);
  522. },
  523. reversebyasc: function(td1, td2) {
  524. var value1 = td1.innerHTML,
  525. value2 = td2.innerHTML;
  526. return value2.localeCompare(value1);
  527. },
  528. orderbynum: function(td1, td2) {
  529. var value1 = td1[utils.isIE ? "innerText" : "textContent"].match(
  530. /\d+/
  531. ),
  532. value2 = td2[utils.isIE ? "innerText" : "textContent"].match(/\d+/);
  533. if (value1) value1 = +value1[0];
  534. if (value2) value2 = +value2[0];
  535. return (value1 || 0) - (value2 || 0);
  536. },
  537. reversebynum: function(td1, td2) {
  538. var value1 = td1[utils.isIE ? "innerText" : "textContent"].match(
  539. /\d+/
  540. ),
  541. value2 = td2[utils.isIE ? "innerText" : "textContent"].match(/\d+/);
  542. if (value1) value1 = +value1[0];
  543. if (value2) value2 = +value2[0];
  544. return (value2 || 0) - (value1 || 0);
  545. }
  546. };
  547. //对表格设置排序的标记data-sort-type
  548. table.setAttribute(
  549. "data-sort-type",
  550. compareFn && typeof compareFn === "string" && Fn[compareFn]
  551. ? compareFn
  552. : ""
  553. );
  554. //th不参与排序
  555. flag && trArray.splice(0, 1);
  556. trArray = sort(trArray, function(tr1, tr2) {
  557. var result;
  558. if (compareFn && typeof compareFn === "function") {
  559. result = compareFn.call(
  560. this,
  561. tr1.cells[sortByCellIndex],
  562. tr2.cells[sortByCellIndex]
  563. );
  564. } else if (compareFn && typeof compareFn === "number") {
  565. result = 1;
  566. } else if (
  567. compareFn &&
  568. typeof compareFn === "string" &&
  569. Fn[compareFn]
  570. ) {
  571. result = Fn[compareFn].call(
  572. this,
  573. tr1.cells[sortByCellIndex],
  574. tr2.cells[sortByCellIndex]
  575. );
  576. } else {
  577. result = Fn["orderbyasc"].call(
  578. this,
  579. tr1.cells[sortByCellIndex],
  580. tr2.cells[sortByCellIndex]
  581. );
  582. }
  583. return result;
  584. });
  585. var fragment = table.ownerDocument.createDocumentFragment();
  586. for (var j = 0, len = trArray.length; j < len; j++) {
  587. fragment.appendChild(trArray[j]);
  588. }
  589. var tbody = table.getElementsByTagName("tbody")[0];
  590. if (!lastRowIndex) {
  591. tbody.appendChild(fragment);
  592. } else {
  593. tbody.insertBefore(
  594. fragment,
  595. rows[lastRowIndex - range.endRowIndex + range.beginRowIndex - 1]
  596. );
  597. }
  598. }
  599. //冒泡排序
  600. function sort(array, compareFn) {
  601. compareFn =
  602. compareFn ||
  603. function(item1, item2) {
  604. return item1.localeCompare(item2);
  605. };
  606. for (var i = 0, len = array.length; i < len; i++) {
  607. for (var j = i, length = array.length; j < length; j++) {
  608. if (compareFn(array[i], array[j]) > 0) {
  609. var t = array[i];
  610. array[i] = array[j];
  611. array[j] = t;
  612. }
  613. }
  614. }
  615. return array;
  616. }
  617. //更新表格
  618. function updateTable(table) {
  619. //给第一行设置firstRow的样式名称,在排序图标的样式上使用到
  620. if (!utils.hasClass(table.rows[0], "firstRow")) {
  621. for (var i = 1; i < table.rows.length; i++) {
  622. utils.removeClass(table.rows[i], "firstRow");
  623. }
  624. utils.addClass(table.rows[0], "firstRow");
  625. }
  626. }
  627. }
  628. });
  629. UE.parse.register("background", function(utils) {
  630. var me = this,
  631. root = me.root,
  632. p = root.getElementsByTagName("p"),
  633. styles;
  634. for (var i = 0, ci; (ci = p[i++]); ) {
  635. styles = ci.getAttribute("data-background");
  636. if (styles) {
  637. ci.parentNode.removeChild(ci);
  638. }
  639. }
  640. //追加默认的表格样式
  641. styles &&
  642. utils.cssRule(
  643. "ueditor_background",
  644. me.selector + "{" + styles + "}",
  645. document
  646. );
  647. });
  648. UE.parse.register("list", function(utils) {
  649. var customCss = [],
  650. customStyle = {
  651. cn: "cn-1-",
  652. cn1: "cn-2-",
  653. cn2: "cn-3-",
  654. num: "num-1-",
  655. num1: "num-2-",
  656. num2: "num-3-",
  657. dash: "dash",
  658. dot: "dot"
  659. };
  660. utils.extend(this, {
  661. liiconpath: "http://bs.baidu.com/listicon/",
  662. listDefaultPaddingLeft: "20"
  663. });
  664. var root = this.root,
  665. ols = root.getElementsByTagName("ol"),
  666. uls = root.getElementsByTagName("ul"),
  667. selector = this.selector;
  668. if (ols.length) {
  669. applyStyle.call(this, ols);
  670. }
  671. if (uls.length) {
  672. applyStyle.call(this, uls);
  673. }
  674. if (ols.length || uls.length) {
  675. customCss.push(selector + " .list-paddingleft-1{padding-left:0}");
  676. customCss.push(
  677. selector +
  678. " .list-paddingleft-2{padding-left:" +
  679. this.listDefaultPaddingLeft +
  680. "px}"
  681. );
  682. customCss.push(
  683. selector +
  684. " .list-paddingleft-3{padding-left:" +
  685. this.listDefaultPaddingLeft * 2 +
  686. "px}"
  687. );
  688. utils.cssRule(
  689. "list",
  690. selector +
  691. " ol," +
  692. selector +
  693. " ul{margin:0;padding:0;}\n" +
  694. selector +
  695. " li{clear:both;}\n" +
  696. customCss.join("\n"),
  697. document
  698. );
  699. }
  700. function applyStyle(nodes) {
  701. var T = this;
  702. utils.each(nodes, function(list) {
  703. if (list.className && /custom_/i.test(list.className)) {
  704. var listStyle = list.className.match(/custom_(\w+)/)[1];
  705. if (listStyle == "dash" || listStyle == "dot") {
  706. utils.pushItem(
  707. customCss,
  708. selector +
  709. " li.list-" +
  710. customStyle[listStyle] +
  711. "{background-image:url(" +
  712. T.liiconpath +
  713. customStyle[listStyle] +
  714. ".gif)}"
  715. );
  716. utils.pushItem(
  717. customCss,
  718. selector +
  719. " ul.custom_" +
  720. listStyle +
  721. "{list-style:none;} " +
  722. selector +
  723. " ul.custom_" +
  724. listStyle +
  725. " li{background-position:0 3px;background-repeat:no-repeat}"
  726. );
  727. } else {
  728. var index = 1;
  729. utils.each(list.childNodes, function(li) {
  730. if (li.tagName == "LI") {
  731. utils.pushItem(
  732. customCss,
  733. selector +
  734. " li.list-" +
  735. customStyle[listStyle] +
  736. index +
  737. "{background-image:url(" +
  738. T.liiconpath +
  739. "list-" +
  740. customStyle[listStyle] +
  741. index +
  742. ".gif)}"
  743. );
  744. index++;
  745. }
  746. });
  747. utils.pushItem(
  748. customCss,
  749. selector +
  750. " ol.custom_" +
  751. listStyle +
  752. "{list-style:none;}" +
  753. selector +
  754. " ol.custom_" +
  755. listStyle +
  756. " li{background-position:0 3px;background-repeat:no-repeat}"
  757. );
  758. }
  759. switch (listStyle) {
  760. case "cn":
  761. utils.pushItem(
  762. customCss,
  763. selector +
  764. " li.list-" +
  765. listStyle +
  766. "-paddingleft-1{padding-left:25px}"
  767. );
  768. utils.pushItem(
  769. customCss,
  770. selector +
  771. " li.list-" +
  772. listStyle +
  773. "-paddingleft-2{padding-left:40px}"
  774. );
  775. utils.pushItem(
  776. customCss,
  777. selector +
  778. " li.list-" +
  779. listStyle +
  780. "-paddingleft-3{padding-left:55px}"
  781. );
  782. break;
  783. case "cn1":
  784. utils.pushItem(
  785. customCss,
  786. selector +
  787. " li.list-" +
  788. listStyle +
  789. "-paddingleft-1{padding-left:30px}"
  790. );
  791. utils.pushItem(
  792. customCss,
  793. selector +
  794. " li.list-" +
  795. listStyle +
  796. "-paddingleft-2{padding-left:40px}"
  797. );
  798. utils.pushItem(
  799. customCss,
  800. selector +
  801. " li.list-" +
  802. listStyle +
  803. "-paddingleft-3{padding-left:55px}"
  804. );
  805. break;
  806. case "cn2":
  807. utils.pushItem(
  808. customCss,
  809. selector +
  810. " li.list-" +
  811. listStyle +
  812. "-paddingleft-1{padding-left:40px}"
  813. );
  814. utils.pushItem(
  815. customCss,
  816. selector +
  817. " li.list-" +
  818. listStyle +
  819. "-paddingleft-2{padding-left:55px}"
  820. );
  821. utils.pushItem(
  822. customCss,
  823. selector +
  824. " li.list-" +
  825. listStyle +
  826. "-paddingleft-3{padding-left:68px}"
  827. );
  828. break;
  829. case "num":
  830. case "num1":
  831. utils.pushItem(
  832. customCss,
  833. selector +
  834. " li.list-" +
  835. listStyle +
  836. "-paddingleft-1{padding-left:25px}"
  837. );
  838. break;
  839. case "num2":
  840. utils.pushItem(
  841. customCss,
  842. selector +
  843. " li.list-" +
  844. listStyle +
  845. "-paddingleft-1{padding-left:35px}"
  846. );
  847. utils.pushItem(
  848. customCss,
  849. selector +
  850. " li.list-" +
  851. listStyle +
  852. "-paddingleft-2{padding-left:40px}"
  853. );
  854. break;
  855. case "dash":
  856. utils.pushItem(
  857. customCss,
  858. selector +
  859. " li.list-" +
  860. listStyle +
  861. "-paddingleft{padding-left:35px}"
  862. );
  863. break;
  864. case "dot":
  865. utils.pushItem(
  866. customCss,
  867. selector +
  868. " li.list-" +
  869. listStyle +
  870. "-paddingleft{padding-left:20px}"
  871. );
  872. }
  873. }
  874. });
  875. }
  876. });
  877. })();