收费管理系统

neditor.parse.js 33KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. /*!
  2. * neditor parse
  3. * version: 2.1.18
  4. * build: Wed May 22 2019 09:16:49 GMT+0000 (UTC)
  5. */
  6. (function(){
  7. (function() {
  8. UE = window.UE || {};
  9. var isIE = !!window.ActiveXObject;
  10. //定义utils工具
  11. var utils = {
  12. removeLastbs: function(url) {
  13. return url.replace(/\/$/, "");
  14. },
  15. extend: function(t, s) {
  16. var a = arguments,
  17. notCover = this.isBoolean(a[a.length - 1]) ? a[a.length - 1] : false,
  18. len = this.isBoolean(a[a.length - 1]) ? a.length - 1 : a.length;
  19. for (var i = 1; i < len; i++) {
  20. var x = a[i];
  21. for (var k in x) {
  22. if (!notCover || !t.hasOwnProperty(k)) {
  23. t[k] = x[k];
  24. }
  25. }
  26. }
  27. return t;
  28. },
  29. isIE: isIE,
  30. cssRule: isIE
  31. ? function(key, style, doc) {
  32. var indexList, index;
  33. doc = doc || document;
  34. if (doc.indexList) {
  35. indexList = doc.indexList;
  36. } else {
  37. indexList = doc.indexList = {};
  38. }
  39. var sheetStyle;
  40. if (!indexList[key]) {
  41. if (style === undefined) {
  42. return "";
  43. }
  44. sheetStyle = doc.createStyleSheet(
  45. "",
  46. (index = doc.styleSheets.length)
  47. );
  48. indexList[key] = index;
  49. } else {
  50. sheetStyle = doc.styleSheets[indexList[key]];
  51. }
  52. if (style === undefined) {
  53. return sheetStyle.cssText;
  54. }
  55. sheetStyle.cssText = sheetStyle.cssText + "\n" + (style || "");
  56. }
  57. : function(key, style, doc) {
  58. doc = doc || document;
  59. var head = doc.getElementsByTagName("head")[0],
  60. node;
  61. if (!(node = doc.getElementById(key))) {
  62. if (style === undefined) {
  63. return "";
  64. }
  65. node = doc.createElement("style");
  66. node.id = key;
  67. head.appendChild(node);
  68. }
  69. if (style === undefined) {
  70. return node.innerHTML;
  71. }
  72. if (style !== "") {
  73. node.innerHTML = node.innerHTML + "\n" + style;
  74. } else {
  75. head.removeChild(node);
  76. }
  77. },
  78. domReady: function(onready) {
  79. var doc = window.document;
  80. if (doc.readyState === "complete") {
  81. onready();
  82. } else {
  83. if (isIE) {
  84. (function() {
  85. if (doc.isReady) return;
  86. try {
  87. doc.documentElement.doScroll("left");
  88. } catch (error) {
  89. setTimeout(arguments.callee, 0);
  90. return;
  91. }
  92. onready();
  93. })();
  94. window.attachEvent("onload", function() {
  95. onready();
  96. });
  97. } else {
  98. doc.addEventListener(
  99. "DOMContentLoaded",
  100. function() {
  101. doc.removeEventListener(
  102. "DOMContentLoaded",
  103. arguments.callee,
  104. false
  105. );
  106. onready();
  107. },
  108. false
  109. );
  110. window.addEventListener(
  111. "load",
  112. function() {
  113. onready();
  114. },
  115. false
  116. );
  117. }
  118. }
  119. },
  120. each: function(obj, iterator, context) {
  121. if (obj == null) return;
  122. if (obj.length === +obj.length) {
  123. for (var i = 0, l = obj.length; i < l; i++) {
  124. if (iterator.call(context, obj[i], i, obj) === false) return false;
  125. }
  126. } else {
  127. for (var key in obj) {
  128. if (obj.hasOwnProperty(key)) {
  129. if (iterator.call(context, obj[key], key, obj) === false)
  130. return false;
  131. }
  132. }
  133. }
  134. },
  135. inArray: function(arr, item) {
  136. var index = -1;
  137. this.each(arr, function(v, i) {
  138. if (v === item) {
  139. index = i;
  140. return false;
  141. }
  142. });
  143. return index;
  144. },
  145. pushItem: function(arr, item) {
  146. if (this.inArray(arr, item) == -1) {
  147. arr.push(item);
  148. }
  149. },
  150. trim: function(str) {
  151. return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, "");
  152. },
  153. indexOf: function(array, item, start) {
  154. var index = -1;
  155. start = this.isNumber(start) ? start : 0;
  156. this.each(array, function(v, i) {
  157. if (i >= start && v === item) {
  158. index = i;
  159. return false;
  160. }
  161. });
  162. return index;
  163. },
  164. hasClass: function(element, className) {
  165. className = className
  166. .replace(/(^[ ]+)|([ ]+$)/g, "")
  167. .replace(/[ ]{2,}/g, " ")
  168. .split(" ");
  169. for (var i = 0, ci, cls = element.className; (ci = className[i++]); ) {
  170. if (!new RegExp("\\b" + ci + "\\b", "i").test(cls)) {
  171. return false;
  172. }
  173. }
  174. return i - 1 == className.length;
  175. },
  176. addClass: function(elm, classNames) {
  177. if (!elm) return;
  178. classNames = this.trim(classNames).replace(/[ ]{2,}/g, " ").split(" ");
  179. for (var i = 0, ci, cls = elm.className; (ci = classNames[i++]); ) {
  180. if (!new RegExp("\\b" + ci + "\\b").test(cls)) {
  181. cls += " " + ci;
  182. }
  183. }
  184. elm.className = utils.trim(cls);
  185. },
  186. removeClass: function(elm, classNames) {
  187. classNames = this.isArray(classNames)
  188. ? classNames
  189. : this.trim(classNames).replace(/[ ]{2,}/g, " ").split(" ");
  190. for (var i = 0, ci, cls = elm.className; (ci = classNames[i++]); ) {
  191. cls = cls.replace(new RegExp("\\b" + ci + "\\b"), "");
  192. }
  193. cls = this.trim(cls).replace(/[ ]{2,}/g, " ");
  194. elm.className = cls;
  195. !cls && elm.removeAttribute("className");
  196. },
  197. on: function(element, type, handler) {
  198. var types = this.isArray(type) ? type : type.split(/\s+/),
  199. k = types.length;
  200. if (k)
  201. while (k--) {
  202. type = types[k];
  203. if (element.addEventListener) {
  204. element.addEventListener(type, handler, false);
  205. } else {
  206. if (!handler._d) {
  207. handler._d = {
  208. els: []
  209. };
  210. }
  211. var key = type + handler.toString(),
  212. index = utils.indexOf(handler._d.els, element);
  213. if (!handler._d[key] || index == -1) {
  214. if (index == -1) {
  215. handler._d.els.push(element);
  216. }
  217. if (!handler._d[key]) {
  218. handler._d[key] = function(evt) {
  219. return handler.call(evt.srcElement, evt || window.event);
  220. };
  221. }
  222. element.attachEvent("on" + type, handler._d[key]);
  223. }
  224. }
  225. }
  226. element = null;
  227. },
  228. off: function(element, type, handler) {
  229. var types = this.isArray(type) ? type : type.split(/\s+/),
  230. k = types.length;
  231. if (k)
  232. while (k--) {
  233. type = types[k];
  234. if (element.removeEventListener) {
  235. element.removeEventListener(type, handler, false);
  236. } else {
  237. var key = type + handler.toString();
  238. try {
  239. element.detachEvent(
  240. "on" + type,
  241. handler._d ? handler._d[key] : handler
  242. );
  243. } catch (e) {}
  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("charts", function(utils) {
  631. utils.cssRule(
  632. "chartsContainerHeight",
  633. ".edui-chart-container { height:" +
  634. (this.chartContainerHeight || 300) +
  635. "px}"
  636. );
  637. var resourceRoot = this.rootPath,
  638. containers = this.root,
  639. sources = null;
  640. //不存在指定的根路径, 则直接退出
  641. if (!resourceRoot) {
  642. return;
  643. }
  644. if ((sources = parseSources())) {
  645. loadResources();
  646. }
  647. function parseSources() {
  648. if (!containers) {
  649. return null;
  650. }
  651. return extractChartData(containers);
  652. }
  653. /**
  654. * 提取数据
  655. */
  656. function extractChartData(rootNode) {
  657. var data = [],
  658. tables = rootNode.getElementsByTagName("table");
  659. for (var i = 0, tableNode; (tableNode = tables[i]); i++) {
  660. if (tableNode.getAttribute("data-chart") !== null) {
  661. data.push(formatData(tableNode));
  662. }
  663. }
  664. return data.length ? data : null;
  665. }
  666. function formatData(tableNode) {
  667. var meta = tableNode.getAttribute("data-chart"),
  668. metaConfig = {},
  669. data = [];
  670. //提取table数据
  671. for (var i = 0, row; (row = tableNode.rows[i]); i++) {
  672. var rowData = [];
  673. for (var j = 0, cell; (cell = row.cells[j]); j++) {
  674. var value = cell.innerText || cell.textContent || "";
  675. rowData.push(cell.tagName == "TH" ? value : value | 0);
  676. }
  677. data.push(rowData);
  678. }
  679. //解析元信息
  680. meta = meta.split(";");
  681. for (var i = 0, metaData; (metaData = meta[i]); i++) {
  682. metaData = metaData.split(":");
  683. metaConfig[metaData[0]] = metaData[1];
  684. }
  685. return {
  686. table: tableNode,
  687. meta: metaConfig,
  688. data: data
  689. };
  690. }
  691. //加载资源
  692. function loadResources() {
  693. loadJQuery();
  694. }
  695. function loadJQuery() {
  696. //不存在jquery, 则加载jquery
  697. if (!window.jQuery) {
  698. utils.loadFile(
  699. document,
  700. {
  701. src: resourceRoot + "/third-party/jquery-1.10.2.min.js",
  702. tag: "script",
  703. type: "text/javascript",
  704. defer: "defer"
  705. },
  706. function() {
  707. loadHighcharts();
  708. }
  709. );
  710. } else {
  711. loadHighcharts();
  712. }
  713. }
  714. function loadHighcharts() {
  715. //不存在Highcharts, 则加载Highcharts
  716. if (!window.Highcharts) {
  717. utils.loadFile(
  718. document,
  719. {
  720. src: resourceRoot + "/third-party/highcharts/highcharts.js",
  721. tag: "script",
  722. type: "text/javascript",
  723. defer: "defer"
  724. },
  725. function() {
  726. loadTypeConfig();
  727. }
  728. );
  729. } else {
  730. loadTypeConfig();
  731. }
  732. }
  733. //加载图表差异化配置文件
  734. function loadTypeConfig() {
  735. utils.loadFile(
  736. document,
  737. {
  738. src: resourceRoot + "/dialogs/charts/chart.config.js",
  739. tag: "script",
  740. type: "text/javascript",
  741. defer: "defer"
  742. },
  743. function() {
  744. render();
  745. }
  746. );
  747. }
  748. //渲染图表
  749. function render() {
  750. var config = null,
  751. chartConfig = null,
  752. container = null;
  753. for (var i = 0, len = sources.length; i < len; i++) {
  754. config = sources[i];
  755. chartConfig = analysisConfig(config);
  756. container = createContainer(config.table);
  757. renderChart(container, typeConfig[config.meta.chartType], chartConfig);
  758. }
  759. }
  760. /**
  761. * 渲染图表
  762. * @param container 图表容器节点对象
  763. * @param typeConfig 图表类型配置
  764. * @param config 图表通用配置
  765. * */
  766. function renderChart(container, typeConfig, config) {
  767. $(container).highcharts(
  768. $.extend({}, typeConfig, {
  769. credits: {
  770. enabled: false
  771. },
  772. exporting: {
  773. enabled: false
  774. },
  775. title: {
  776. text: config.title,
  777. x: -20 //center
  778. },
  779. subtitle: {
  780. text: config.subTitle,
  781. x: -20
  782. },
  783. xAxis: {
  784. title: {
  785. text: config.xTitle
  786. },
  787. categories: config.categories
  788. },
  789. yAxis: {
  790. title: {
  791. text: config.yTitle
  792. },
  793. plotLines: [
  794. {
  795. value: 0,
  796. width: 1,
  797. color: "#808080"
  798. }
  799. ]
  800. },
  801. tooltip: {
  802. enabled: true,
  803. valueSuffix: config.suffix
  804. },
  805. legend: {
  806. layout: "vertical",
  807. align: "right",
  808. verticalAlign: "middle",
  809. borderWidth: 1
  810. },
  811. series: config.series
  812. })
  813. );
  814. }
  815. /**
  816. * 创建图表的容器
  817. * 新创建的容器会替换掉对应的table对象
  818. * */
  819. function createContainer(tableNode) {
  820. var container = document.createElement("div");
  821. container.className = "edui-chart-container";
  822. tableNode.parentNode.replaceChild(container, tableNode);
  823. return container;
  824. }
  825. //根据config解析出正确的类别和图表数据信息
  826. function analysisConfig(config) {
  827. var series = [],
  828. //数据类别
  829. categories = [],
  830. result = [],
  831. data = config.data,
  832. meta = config.meta;
  833. //数据对齐方式为相反的方式, 需要反转数据
  834. if (meta.dataFormat != "1") {
  835. for (var i = 0, len = data.length; i < len; i++) {
  836. for (var j = 0, jlen = data[i].length; j < jlen; j++) {
  837. if (!result[j]) {
  838. result[j] = [];
  839. }
  840. result[j][i] = data[i][j];
  841. }
  842. }
  843. data = result;
  844. }
  845. result = {};
  846. //普通图表
  847. if (meta.chartType != typeConfig.length - 1) {
  848. categories = data[0].slice(1);
  849. for (var i = 1, curData; (curData = data[i]); i++) {
  850. series.push({
  851. name: curData[0],
  852. data: curData.slice(1)
  853. });
  854. }
  855. result.series = series;
  856. result.categories = categories;
  857. result.title = meta.title;
  858. result.subTitle = meta.subTitle;
  859. result.xTitle = meta.xTitle;
  860. result.yTitle = meta.yTitle;
  861. result.suffix = meta.suffix;
  862. } else {
  863. var curData = [];
  864. for (var i = 1, len = data[0].length; i < len; i++) {
  865. curData.push([data[0][i], data[1][i] | 0]);
  866. }
  867. //饼图
  868. series[0] = {
  869. type: "pie",
  870. name: meta.tip,
  871. data: curData
  872. };
  873. result.series = series;
  874. result.title = meta.title;
  875. result.suffix = meta.suffix;
  876. }
  877. return result;
  878. }
  879. });
  880. UE.parse.register("background", function(utils) {
  881. var me = this,
  882. root = me.root,
  883. p = root.getElementsByTagName("p"),
  884. styles;
  885. for (var i = 0, ci; (ci = p[i++]); ) {
  886. styles = ci.getAttribute("data-background");
  887. if (styles) {
  888. ci.parentNode.removeChild(ci);
  889. }
  890. }
  891. //追加默认的表格样式
  892. styles &&
  893. utils.cssRule(
  894. "ueditor_background",
  895. me.selector + "{" + styles + "}",
  896. document
  897. );
  898. });
  899. UE.parse.register("list", function(utils) {
  900. var customCss = [],
  901. customStyle = {
  902. cn: "cn-1-",
  903. cn1: "cn-2-",
  904. cn2: "cn-3-",
  905. num: "num-1-",
  906. num1: "num-2-",
  907. num2: "num-3-",
  908. dash: "dash",
  909. dot: "dot"
  910. };
  911. utils.extend(this, {
  912. liiconpath : utils.removeLastbs(this.rootPath) + '/themes/ueditor-list/',
  913. listDefaultPaddingLeft: "20"
  914. },true);
  915. var root = this.root,
  916. ols = root.getElementsByTagName("ol"),
  917. uls = root.getElementsByTagName("ul"),
  918. selector = this.selector;
  919. if (ols.length) {
  920. applyStyle.call(this, ols);
  921. }
  922. if (uls.length) {
  923. applyStyle.call(this, uls);
  924. }
  925. if (ols.length || uls.length) {
  926. customCss.push(selector + " .list-paddingleft-1{padding-left:0}");
  927. customCss.push(
  928. selector +
  929. " .list-paddingleft-2{padding-left:" +
  930. this.listDefaultPaddingLeft +
  931. "px}"
  932. );
  933. customCss.push(
  934. selector +
  935. " .list-paddingleft-3{padding-left:" +
  936. this.listDefaultPaddingLeft * 2 +
  937. "px}"
  938. );
  939. utils.cssRule(
  940. "list",
  941. selector +
  942. " ol," +
  943. selector +
  944. " ul{margin:0;padding:0;}\n" +
  945. selector +
  946. " li{clear:both;}\n" +
  947. customCss.join("\n"),
  948. document
  949. );
  950. }
  951. function applyStyle(nodes) {
  952. var T = this;
  953. utils.each(nodes, function(list) {
  954. if (list.className && /custom_/i.test(list.className)) {
  955. var listStyle = list.className.match(/custom_(\w+)/)[1];
  956. if (listStyle == "dash" || listStyle == "dot") {
  957. utils.pushItem(
  958. customCss,
  959. selector +
  960. " li.list-" +
  961. customStyle[listStyle] +
  962. "{background-image:url(" +
  963. T.liiconpath +
  964. customStyle[listStyle] +
  965. ".gif)}"
  966. );
  967. utils.pushItem(
  968. customCss,
  969. selector +
  970. " ul.custom_" +
  971. listStyle +
  972. "{list-style:none;} " +
  973. selector +
  974. " ul.custom_" +
  975. listStyle +
  976. " li{background-position:0 3px;background-repeat:no-repeat}"
  977. );
  978. } else {
  979. var index = 1;
  980. utils.each(list.childNodes, function(li) {
  981. if (li.tagName == "LI") {
  982. utils.pushItem(
  983. customCss,
  984. selector +
  985. " li.list-" +
  986. customStyle[listStyle] +
  987. index +
  988. "{background-image:url(" +
  989. T.liiconpath +
  990. "list-" +
  991. customStyle[listStyle] +
  992. index +
  993. ".gif)}"
  994. );
  995. index++;
  996. }
  997. });
  998. utils.pushItem(
  999. customCss,
  1000. selector +
  1001. " ol.custom_" +
  1002. listStyle +
  1003. "{list-style:none;}" +
  1004. selector +
  1005. " ol.custom_" +
  1006. listStyle +
  1007. " li{background-position:0 3px;background-repeat:no-repeat}"
  1008. );
  1009. }
  1010. switch (listStyle) {
  1011. case "cn":
  1012. utils.pushItem(
  1013. customCss,
  1014. selector +
  1015. " li.list-" +
  1016. listStyle +
  1017. "-paddingleft-1{padding-left:25px}"
  1018. );
  1019. utils.pushItem(
  1020. customCss,
  1021. selector +
  1022. " li.list-" +
  1023. listStyle +
  1024. "-paddingleft-2{padding-left:40px}"
  1025. );
  1026. utils.pushItem(
  1027. customCss,
  1028. selector +
  1029. " li.list-" +
  1030. listStyle +
  1031. "-paddingleft-3{padding-left:55px}"
  1032. );
  1033. break;
  1034. case "cn1":
  1035. utils.pushItem(
  1036. customCss,
  1037. selector +
  1038. " li.list-" +
  1039. listStyle +
  1040. "-paddingleft-1{padding-left:30px}"
  1041. );
  1042. utils.pushItem(
  1043. customCss,
  1044. selector +
  1045. " li.list-" +
  1046. listStyle +
  1047. "-paddingleft-2{padding-left:40px}"
  1048. );
  1049. utils.pushItem(
  1050. customCss,
  1051. selector +
  1052. " li.list-" +
  1053. listStyle +
  1054. "-paddingleft-3{padding-left:55px}"
  1055. );
  1056. break;
  1057. case "cn2":
  1058. utils.pushItem(
  1059. customCss,
  1060. selector +
  1061. " li.list-" +
  1062. listStyle +
  1063. "-paddingleft-1{padding-left:40px}"
  1064. );
  1065. utils.pushItem(
  1066. customCss,
  1067. selector +
  1068. " li.list-" +
  1069. listStyle +
  1070. "-paddingleft-2{padding-left:55px}"
  1071. );
  1072. utils.pushItem(
  1073. customCss,
  1074. selector +
  1075. " li.list-" +
  1076. listStyle +
  1077. "-paddingleft-3{padding-left:68px}"
  1078. );
  1079. break;
  1080. case "num":
  1081. case "num1":
  1082. utils.pushItem(
  1083. customCss,
  1084. selector +
  1085. " li.list-" +
  1086. listStyle +
  1087. "-paddingleft-1{padding-left:25px}"
  1088. );
  1089. break;
  1090. case "num2":
  1091. utils.pushItem(
  1092. customCss,
  1093. selector +
  1094. " li.list-" +
  1095. listStyle +
  1096. "-paddingleft-1{padding-left:35px}"
  1097. );
  1098. utils.pushItem(
  1099. customCss,
  1100. selector +
  1101. " li.list-" +
  1102. listStyle +
  1103. "-paddingleft-2{padding-left:40px}"
  1104. );
  1105. break;
  1106. case "dash":
  1107. utils.pushItem(
  1108. customCss,
  1109. selector +
  1110. " li.list-" +
  1111. listStyle +
  1112. "-paddingleft{padding-left:35px}"
  1113. );
  1114. break;
  1115. case "dot":
  1116. utils.pushItem(
  1117. customCss,
  1118. selector +
  1119. " li.list-" +
  1120. listStyle +
  1121. "-paddingleft{padding-left:20px}"
  1122. );
  1123. }
  1124. }
  1125. });
  1126. }
  1127. });
  1128. UE.parse.register("vedio", function(utils) {
  1129. var video = this.root.getElementsByTagName("video"),
  1130. audio = this.root.getElementsByTagName("audio");
  1131. document.createElement("video");
  1132. document.createElement("audio");
  1133. if (video.length || audio.length) {
  1134. var sourcePath = utils.removeLastbs(this.rootPath),
  1135. jsurl = sourcePath + "/third-party/video-js/video.js",
  1136. cssurl = sourcePath + "/third-party/video-js/video-js.min.css",
  1137. swfUrl = sourcePath + "/third-party/video-js/video-js.swf";
  1138. if (window.videojs) {
  1139. videojs.autoSetup();
  1140. } else {
  1141. utils.loadFile(document, {
  1142. id: "video_css",
  1143. tag: "link",
  1144. rel: "stylesheet",
  1145. type: "text/css",
  1146. href: cssurl
  1147. });
  1148. utils.loadFile(
  1149. document,
  1150. {
  1151. id: "video_js",
  1152. src: jsurl,
  1153. tag: "script",
  1154. type: "text/javascript"
  1155. },
  1156. function() {
  1157. videojs.options.flash.swf = swfUrl;
  1158. videojs.autoSetup();
  1159. }
  1160. );
  1161. }
  1162. }
  1163. });
  1164. })();