ueditor.parse.js 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. /*!
  2. * UEditor
  3. * version: ueditor
  4. * build: Wed Dec 26 2018 17:24:52 GMT+0800 (CST)
  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('', (index = doc.styleSheets.length))
  45. indexList[key] = index
  46. } else {
  47. sheetStyle = doc.styleSheets[indexList[key]]
  48. }
  49. if (style === undefined) {
  50. return sheetStyle.cssText
  51. }
  52. sheetStyle.cssText = sheetStyle.cssText + '\n' + (style || '')
  53. }
  54. : function (key, style, doc) {
  55. doc = doc || document
  56. var head = doc.getElementsByTagName('head')[0],
  57. node
  58. if (!(node = doc.getElementById(key))) {
  59. if (style === undefined) {
  60. return ''
  61. }
  62. node = doc.createElement('style')
  63. node.id = key
  64. head.appendChild(node)
  65. }
  66. if (style === undefined) {
  67. return node.innerHTML
  68. }
  69. if (style !== '') {
  70. node.innerHTML = node.innerHTML + '\n' + style
  71. } else {
  72. head.removeChild(node)
  73. }
  74. },
  75. domReady: function (onready) {
  76. var doc = window.document
  77. if (doc.readyState === 'complete') {
  78. onready()
  79. } else {
  80. if (isIE) {
  81. ;(function () {
  82. if (doc.isReady) return
  83. try {
  84. doc.documentElement.doScroll('left')
  85. } catch (error) {
  86. setTimeout(arguments.callee, 0)
  87. return
  88. }
  89. onready()
  90. })()
  91. window.attachEvent('onload', function () {
  92. onready()
  93. })
  94. } else {
  95. doc.addEventListener(
  96. 'DOMContentLoaded',
  97. function () {
  98. doc.removeEventListener('DOMContentLoaded', arguments.callee, false)
  99. onready()
  100. },
  101. false
  102. )
  103. window.addEventListener(
  104. 'load',
  105. function () {
  106. onready()
  107. },
  108. false
  109. )
  110. }
  111. }
  112. },
  113. each: function (obj, iterator, context) {
  114. if (obj == null) return
  115. if (obj.length === +obj.length) {
  116. for (var i = 0, l = obj.length; i < l; i++) {
  117. if (iterator.call(context, obj[i], i, obj) === false) return false
  118. }
  119. } else {
  120. for (var key in obj) {
  121. if (obj.hasOwnProperty(key)) {
  122. if (iterator.call(context, obj[key], key, obj) === false) return false
  123. }
  124. }
  125. }
  126. },
  127. inArray: function (arr, item) {
  128. var index = -1
  129. this.each(arr, function (v, i) {
  130. if (v === item) {
  131. index = i
  132. return false
  133. }
  134. })
  135. return index
  136. },
  137. pushItem: function (arr, item) {
  138. if (this.inArray(arr, item) == -1) {
  139. arr.push(item)
  140. }
  141. },
  142. trim: function (str) {
  143. return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, '')
  144. },
  145. indexOf: function (array, item, start) {
  146. var index = -1
  147. start = this.isNumber(start) ? start : 0
  148. this.each(array, function (v, i) {
  149. if (i >= start && v === item) {
  150. index = i
  151. return false
  152. }
  153. })
  154. return index
  155. },
  156. hasClass: function (element, className) {
  157. className = className
  158. .replace(/(^[ ]+)|([ ]+$)/g, '')
  159. .replace(/[ ]{2,}/g, ' ')
  160. .split(' ')
  161. for (var i = 0, ci, cls = element.className; (ci = className[i++]); ) {
  162. if (!new RegExp('\\b' + ci + '\\b', 'i').test(cls)) {
  163. return false
  164. }
  165. }
  166. return i - 1 == className.length
  167. },
  168. addClass: function (elm, classNames) {
  169. if (!elm) return
  170. classNames = this.trim(classNames)
  171. .replace(/[ ]{2,}/g, ' ')
  172. .split(' ')
  173. for (var i = 0, ci, cls = elm.className; (ci = classNames[i++]); ) {
  174. if (!new RegExp('\\b' + ci + '\\b').test(cls)) {
  175. cls += ' ' + ci
  176. }
  177. }
  178. elm.className = utils.trim(cls)
  179. },
  180. removeClass: function (elm, classNames) {
  181. classNames = this.isArray(classNames)
  182. ? classNames
  183. : this.trim(classNames)
  184. .replace(/[ ]{2,}/g, ' ')
  185. .split(' ')
  186. for (var i = 0, ci, cls = elm.className; (ci = classNames[i++]); ) {
  187. cls = cls.replace(new RegExp('\\b' + ci + '\\b'), '')
  188. }
  189. cls = this.trim(cls).replace(/[ ]{2,}/g, ' ')
  190. elm.className = cls
  191. !cls && elm.removeAttribute('className')
  192. },
  193. on: function (element, type, handler) {
  194. var types = this.isArray(type) ? type : type.split(/\s+/),
  195. k = types.length
  196. if (k)
  197. while (k--) {
  198. type = types[k]
  199. if (element.addEventListener) {
  200. element.addEventListener(type, handler, false)
  201. } else {
  202. if (!handler._d) {
  203. handler._d = {
  204. els: []
  205. }
  206. }
  207. var key = type + handler.toString(),
  208. index = utils.indexOf(handler._d.els, element)
  209. if (!handler._d[key] || index == -1) {
  210. if (index == -1) {
  211. handler._d.els.push(element)
  212. }
  213. if (!handler._d[key]) {
  214. handler._d[key] = function (evt) {
  215. return handler.call(evt.srcElement, evt || window.event)
  216. }
  217. }
  218. element.attachEvent('on' + type, handler._d[key])
  219. }
  220. }
  221. }
  222. element = null
  223. },
  224. off: function (element, type, handler) {
  225. var types = this.isArray(type) ? type : type.split(/\s+/),
  226. k = types.length
  227. if (k)
  228. while (k--) {
  229. type = types[k]
  230. if (element && element.removeEventListener) {
  231. element.removeEventListener(type, handler, false)
  232. } else {
  233. var key = type + handler.toString()
  234. try {
  235. element.detachEvent('on' + type, handler._d ? handler._d[key] : handler)
  236. } catch (e) {}
  237. if (handler._d && handler._d[key]) {
  238. var index = utils.indexOf(handler._d.els, element)
  239. if (index != -1) {
  240. handler._d.els.splice(index, 1)
  241. }
  242. handler._d.els.length == 0 && delete handler._d[key]
  243. }
  244. }
  245. }
  246. },
  247. loadFile: (function () {
  248. var tmpList = []
  249. function getItem(doc, obj) {
  250. try {
  251. for (var i = 0, ci; (ci = tmpList[i++]); ) {
  252. if (ci.doc === doc && ci.url == (obj.src || obj.href)) {
  253. return ci
  254. }
  255. }
  256. } catch (e) {
  257. return null
  258. }
  259. }
  260. return function (doc, obj, fn) {
  261. var item = getItem(doc, obj)
  262. if (item) {
  263. if (item.ready) {
  264. fn && fn()
  265. } else {
  266. item.funs.push(fn)
  267. }
  268. return
  269. }
  270. tmpList.push({
  271. doc: doc,
  272. url: obj.src || obj.href,
  273. funs: [fn]
  274. })
  275. if (!doc.body) {
  276. var html = []
  277. for (var p in obj) {
  278. if (p == 'tag') continue
  279. html.push(p + '="' + obj[p] + '"')
  280. }
  281. doc.write('<' + obj.tag + ' ' + html.join(' ') + ' ></' + obj.tag + '>')
  282. return
  283. }
  284. if (obj.id && doc.getElementById(obj.id)) {
  285. return
  286. }
  287. var element = doc.createElement(obj.tag)
  288. delete obj.tag
  289. for (var p in obj) {
  290. element.setAttribute(p, obj[p])
  291. }
  292. element.onload = element.onreadystatechange = function () {
  293. if (!this.readyState || /loaded|complete/.test(this.readyState)) {
  294. item = getItem(doc, obj)
  295. if (item.funs.length > 0) {
  296. item.ready = 1
  297. for (var fi; (fi = item.funs.pop()); ) {
  298. fi()
  299. }
  300. }
  301. element.onload = element.onreadystatechange = null
  302. }
  303. }
  304. element.onerror = function () {
  305. throw Error('The load ' + (obj.href || obj.src) + ' fails,check the url')
  306. }
  307. doc.getElementsByTagName('head')[0].appendChild(element)
  308. }
  309. })()
  310. }
  311. utils.each(
  312. ['String', 'Function', 'Array', 'Number', 'RegExp', 'Object', 'Boolean'],
  313. function (v) {
  314. utils['is' + v] = function (obj) {
  315. return Object.prototype.toString.apply(obj) == '[object ' + v + ']'
  316. }
  317. }
  318. )
  319. var parselist = {}
  320. UE.parse = {
  321. register: function (parseName, fn) {
  322. parselist[parseName] = fn
  323. },
  324. load: function (opt) {
  325. utils.each(parselist, function (v) {
  326. v.call(opt, utils)
  327. })
  328. }
  329. }
  330. uParse = function (selector, opt) {
  331. utils.domReady(function () {
  332. var contents
  333. if (document.querySelectorAll) {
  334. contents = document.querySelectorAll(selector)
  335. } else {
  336. if (/^#/.test(selector)) {
  337. contents = [document.getElementById(selector.replace(/^#/, ''))]
  338. } else if (/^\./.test(selector)) {
  339. var contents = []
  340. utils.each(document.getElementsByTagName('*'), function (node) {
  341. if (
  342. node.className &&
  343. new RegExp('\\b' + selector.replace(/^\./, '') + '\\b', 'i').test(node.className)
  344. ) {
  345. contents.push(node)
  346. }
  347. })
  348. } else {
  349. contents = document.getElementsByTagName(selector)
  350. }
  351. }
  352. utils.each(contents, function (v) {
  353. UE.parse.load(utils.extend({ root: v, selector: selector }, opt))
  354. })
  355. })
  356. }
  357. })()
  358. UE.parse.register('insertcode', function (utils) {
  359. var pres = this.root.getElementsByTagName('pre')
  360. if (pres.length) {
  361. if (typeof XRegExp == 'undefined') {
  362. var jsurl, cssurl
  363. if (this.rootPath !== undefined) {
  364. jsurl = utils.removeLastbs(this.rootPath) + '/third-party/SyntaxHighlighter/shCore.js'
  365. cssurl =
  366. utils.removeLastbs(this.rootPath) + '/third-party/SyntaxHighlighter/shCoreDefault.css'
  367. } else {
  368. jsurl = this.highlightJsUrl
  369. cssurl = this.highlightCssUrl
  370. }
  371. utils.loadFile(document, {
  372. id: 'syntaxhighlighter_css',
  373. tag: 'link',
  374. rel: 'stylesheet',
  375. type: 'text/css',
  376. href: cssurl
  377. })
  378. utils.loadFile(
  379. document,
  380. {
  381. id: 'syntaxhighlighter_js',
  382. src: jsurl,
  383. tag: 'script',
  384. type: 'text/javascript',
  385. defer: 'defer'
  386. },
  387. function () {
  388. utils.each(pres, function (pi) {
  389. if (pi && /brush/i.test(pi.className)) {
  390. SyntaxHighlighter.highlight(pi)
  391. }
  392. })
  393. }
  394. )
  395. } else {
  396. utils.each(pres, function (pi) {
  397. if (pi && /brush/i.test(pi.className)) {
  398. SyntaxHighlighter.highlight(pi)
  399. }
  400. })
  401. }
  402. }
  403. })
  404. UE.parse.register('table', function (utils) {
  405. var me = this,
  406. root = this.root,
  407. tables = root.getElementsByTagName('table')
  408. if (tables.length) {
  409. var selector = this.selector
  410. //追加默认的表格样式
  411. utils.cssRule(
  412. 'table',
  413. selector +
  414. ' table.noBorderTable td,' +
  415. selector +
  416. ' table.noBorderTable th,' +
  417. selector +
  418. ' table.noBorderTable caption{border:1px dashed #ddd !important}' +
  419. selector +
  420. ' table.sortEnabled tr.firstRow th,' +
  421. selector +
  422. ' table.sortEnabled tr.firstRow td{padding-right:20px; background-repeat: no-repeat;' +
  423. 'background-position: center right; background-image:url(' +
  424. this.rootPath +
  425. 'themes/default/images/sortable.png);}' +
  426. selector +
  427. ' table.sortEnabled tr.firstRow th:hover,' +
  428. selector +
  429. ' table.sortEnabled tr.firstRow td:hover{background-color: #EEE;}' +
  430. selector +
  431. ' table{margin-bottom:10px;border-collapse:collapse;display:table;}' +
  432. selector +
  433. ' td,' +
  434. selector +
  435. ' th{ background:white; padding: 5px 10px;border: 1px solid #DDD;}' +
  436. selector +
  437. ' caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' +
  438. selector +
  439. ' th{border-top:1px solid #BBB;background:#F7F7F7;}' +
  440. selector +
  441. ' table tr.firstRow th{border-top:2px solid #BBB;background:#F7F7F7;}' +
  442. selector +
  443. ' tr.ue-table-interlace-color-single td{ background: #fcfcfc; }' +
  444. selector +
  445. ' tr.ue-table-interlace-color-double td{ background: #f7faff; }' +
  446. selector +
  447. ' td p{margin:0;padding:0;}',
  448. document
  449. )
  450. //填充空的单元格
  451. utils.each('td th caption'.split(' '), function (tag) {
  452. var cells = root.getElementsByTagName(tag)
  453. cells.length &&
  454. utils.each(cells, function (node) {
  455. if (!node.firstChild) {
  456. node.innerHTML = '&nbsp;'
  457. }
  458. })
  459. })
  460. //表格可排序
  461. var tables = root.getElementsByTagName('table')
  462. utils.each(tables, function (table) {
  463. if (/\bsortEnabled\b/.test(table.className)) {
  464. utils.on(table, 'click', function (e) {
  465. var target = e.target || e.srcElement,
  466. cell = findParentByTagName(target, ['td', 'th'])
  467. var table = findParentByTagName(target, 'table'),
  468. colIndex = utils.indexOf(table.rows[0].cells, cell),
  469. sortType = table.getAttribute('data-sort-type')
  470. if (colIndex != -1) {
  471. sortTable(table, colIndex, me.tableSortCompareFn || sortType)
  472. updateTable(table)
  473. }
  474. })
  475. }
  476. })
  477. //按照标签名查找父节点
  478. function findParentByTagName(target, tagNames) {
  479. var i,
  480. current = target
  481. tagNames = utils.isArray(tagNames) ? tagNames : [tagNames]
  482. while (current) {
  483. for (i = 0; i < tagNames.length; i++) {
  484. if (current.tagName == tagNames[i].toUpperCase()) return current
  485. }
  486. current = current.parentNode
  487. }
  488. return null
  489. }
  490. //表格排序
  491. function sortTable(table, sortByCellIndex, compareFn) {
  492. var rows = table.rows,
  493. trArray = [],
  494. flag = rows[0].cells[0].tagName === 'TH',
  495. lastRowIndex = 0
  496. for (var i = 0, len = rows.length; i < len; i++) {
  497. trArray[i] = rows[i]
  498. }
  499. var Fn = {
  500. reversecurrent: function (td1, td2) {
  501. return 1
  502. },
  503. orderbyasc: function (td1, td2) {
  504. var value1 = td1.innerText || td1.textContent,
  505. value2 = td2.innerText || td2.textContent
  506. return value1.localeCompare(value2)
  507. },
  508. reversebyasc: function (td1, td2) {
  509. var value1 = td1.innerHTML,
  510. value2 = td2.innerHTML
  511. return value2.localeCompare(value1)
  512. },
  513. orderbynum: function (td1, td2) {
  514. var value1 = td1[utils.isIE ? 'innerText' : 'textContent'].match(/\d+/),
  515. value2 = td2[utils.isIE ? 'innerText' : 'textContent'].match(/\d+/)
  516. if (value1) value1 = +value1[0]
  517. if (value2) value2 = +value2[0]
  518. return (value1 || 0) - (value2 || 0)
  519. },
  520. reversebynum: function (td1, td2) {
  521. var value1 = td1[utils.isIE ? 'innerText' : 'textContent'].match(/\d+/),
  522. value2 = td2[utils.isIE ? 'innerText' : 'textContent'].match(/\d+/)
  523. if (value1) value1 = +value1[0]
  524. if (value2) value2 = +value2[0]
  525. return (value2 || 0) - (value1 || 0)
  526. }
  527. }
  528. //对表格设置排序的标记data-sort-type
  529. table.setAttribute(
  530. 'data-sort-type',
  531. compareFn && typeof compareFn === 'string' && Fn[compareFn] ? compareFn : ''
  532. )
  533. //th不参与排序
  534. flag && trArray.splice(0, 1)
  535. trArray = sort(trArray, function (tr1, tr2) {
  536. var result
  537. if (compareFn && typeof compareFn === 'function') {
  538. result = compareFn.call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex])
  539. } else if (compareFn && typeof compareFn === 'number') {
  540. result = 1
  541. } else if (compareFn && typeof compareFn === 'string' && Fn[compareFn]) {
  542. result = Fn[compareFn].call(
  543. this,
  544. tr1.cells[sortByCellIndex],
  545. tr2.cells[sortByCellIndex]
  546. )
  547. } else {
  548. result = Fn['orderbyasc'].call(
  549. this,
  550. tr1.cells[sortByCellIndex],
  551. tr2.cells[sortByCellIndex]
  552. )
  553. }
  554. return result
  555. })
  556. var fragment = table.ownerDocument.createDocumentFragment()
  557. for (var j = 0, len = trArray.length; j < len; j++) {
  558. fragment.appendChild(trArray[j])
  559. }
  560. var tbody = table.getElementsByTagName('tbody')[0]
  561. if (!lastRowIndex) {
  562. tbody.appendChild(fragment)
  563. } else {
  564. tbody.insertBefore(
  565. fragment,
  566. rows[lastRowIndex - range.endRowIndex + range.beginRowIndex - 1]
  567. )
  568. }
  569. }
  570. //冒泡排序
  571. function sort(array, compareFn) {
  572. compareFn =
  573. compareFn ||
  574. function (item1, item2) {
  575. return item1.localeCompare(item2)
  576. }
  577. for (var i = 0, len = array.length; i < len; i++) {
  578. for (var j = i, length = array.length; j < length; j++) {
  579. if (compareFn(array[i], array[j]) > 0) {
  580. var t = array[i]
  581. array[i] = array[j]
  582. array[j] = t
  583. }
  584. }
  585. }
  586. return array
  587. }
  588. //更新表格
  589. function updateTable(table) {
  590. //给第一行设置firstRow的样式名称,在排序图标的样式上使用到
  591. if (!utils.hasClass(table.rows[0], 'firstRow')) {
  592. for (var i = 1; i < table.rows.length; i++) {
  593. utils.removeClass(table.rows[i], 'firstRow')
  594. }
  595. utils.addClass(table.rows[0], 'firstRow')
  596. }
  597. }
  598. }
  599. })
  600. UE.parse.register('charts', function (utils) {
  601. utils.cssRule(
  602. 'chartsContainerHeight',
  603. '.edui-chart-container { height:' + (this.chartContainerHeight || 300) + 'px}'
  604. )
  605. var resourceRoot = this.rootPath,
  606. containers = this.root,
  607. sources = null
  608. //不存在指定的根路径, 则直接退出
  609. if (!resourceRoot) {
  610. return
  611. }
  612. if ((sources = parseSources())) {
  613. loadResources()
  614. }
  615. function parseSources() {
  616. if (!containers) {
  617. return null
  618. }
  619. return extractChartData(containers)
  620. }
  621. /**
  622. * 提取数据
  623. */
  624. function extractChartData(rootNode) {
  625. var data = [],
  626. tables = rootNode.getElementsByTagName('table')
  627. for (var i = 0, tableNode; (tableNode = tables[i]); i++) {
  628. if (tableNode.getAttribute('data-chart') !== null) {
  629. data.push(formatData(tableNode))
  630. }
  631. }
  632. return data.length ? data : null
  633. }
  634. function formatData(tableNode) {
  635. var meta = tableNode.getAttribute('data-chart'),
  636. metaConfig = {},
  637. data = []
  638. //提取table数据
  639. for (var i = 0, row; (row = tableNode.rows[i]); i++) {
  640. var rowData = []
  641. for (var j = 0, cell; (cell = row.cells[j]); j++) {
  642. var value = cell.innerText || cell.textContent || ''
  643. rowData.push(cell.tagName == 'TH' ? value : value | 0)
  644. }
  645. data.push(rowData)
  646. }
  647. //解析元信息
  648. meta = meta.split(';')
  649. for (var i = 0, metaData; (metaData = meta[i]); i++) {
  650. metaData = metaData.split(':')
  651. metaConfig[metaData[0]] = metaData[1]
  652. }
  653. return {
  654. table: tableNode,
  655. meta: metaConfig,
  656. data: data
  657. }
  658. }
  659. //加载资源
  660. function loadResources() {
  661. loadJQuery()
  662. }
  663. function loadJQuery() {
  664. //不存在jquery, 则加载jquery
  665. if (!window.jQuery) {
  666. utils.loadFile(
  667. document,
  668. {
  669. src: resourceRoot + '/third-party/jquery-1.10.2.min.js',
  670. tag: 'script',
  671. type: 'text/javascript',
  672. defer: 'defer'
  673. },
  674. function () {
  675. loadHighcharts()
  676. }
  677. )
  678. } else {
  679. loadHighcharts()
  680. }
  681. }
  682. function loadHighcharts() {
  683. //不存在Highcharts, 则加载Highcharts
  684. if (!window.Highcharts) {
  685. utils.loadFile(
  686. document,
  687. {
  688. src: resourceRoot + '/third-party/highcharts/highcharts.js',
  689. tag: 'script',
  690. type: 'text/javascript',
  691. defer: 'defer'
  692. },
  693. function () {
  694. loadTypeConfig()
  695. }
  696. )
  697. } else {
  698. loadTypeConfig()
  699. }
  700. }
  701. //加载图表差异化配置文件
  702. function loadTypeConfig() {
  703. utils.loadFile(
  704. document,
  705. {
  706. src: resourceRoot + '/dialogs/charts/chart.config.js',
  707. tag: 'script',
  708. type: 'text/javascript',
  709. defer: 'defer'
  710. },
  711. function () {
  712. render()
  713. }
  714. )
  715. }
  716. //渲染图表
  717. function render() {
  718. var config = null,
  719. chartConfig = null,
  720. container = null
  721. for (var i = 0, len = sources.length; i < len; i++) {
  722. config = sources[i]
  723. chartConfig = analysisConfig(config)
  724. container = createContainer(config.table)
  725. renderChart(container, typeConfig[config.meta.chartType], chartConfig)
  726. }
  727. }
  728. /**
  729. * 渲染图表
  730. * @param container 图表容器节点对象
  731. * @param typeConfig 图表类型配置
  732. * @param config 图表通用配置
  733. * */
  734. function renderChart(container, typeConfig, config) {
  735. $(container).highcharts(
  736. $.extend({}, typeConfig, {
  737. credits: {
  738. enabled: false
  739. },
  740. exporting: {
  741. enabled: false
  742. },
  743. title: {
  744. text: config.title,
  745. x: -20 //center
  746. },
  747. subtitle: {
  748. text: config.subTitle,
  749. x: -20
  750. },
  751. xAxis: {
  752. title: {
  753. text: config.xTitle
  754. },
  755. categories: config.categories
  756. },
  757. yAxis: {
  758. title: {
  759. text: config.yTitle
  760. },
  761. plotLines: [
  762. {
  763. value: 0,
  764. width: 1,
  765. color: '#808080'
  766. }
  767. ]
  768. },
  769. tooltip: {
  770. enabled: true,
  771. valueSuffix: config.suffix
  772. },
  773. legend: {
  774. layout: 'vertical',
  775. align: 'right',
  776. verticalAlign: 'middle',
  777. borderWidth: 1
  778. },
  779. series: config.series
  780. })
  781. )
  782. }
  783. /**
  784. * 创建图表的容器
  785. * 新创建的容器会替换掉对应的table对象
  786. * */
  787. function createContainer(tableNode) {
  788. var container = document.createElement('div')
  789. container.className = 'edui-chart-container'
  790. tableNode.parentNode.replaceChild(container, tableNode)
  791. return container
  792. }
  793. //根据config解析出正确的类别和图表数据信息
  794. function analysisConfig(config) {
  795. var series = [],
  796. //数据类别
  797. categories = [],
  798. result = [],
  799. data = config.data,
  800. meta = config.meta
  801. //数据对齐方式为相反的方式, 需要反转数据
  802. if (meta.dataFormat != '1') {
  803. for (var i = 0, len = data.length; i < len; i++) {
  804. for (var j = 0, jlen = data[i].length; j < jlen; j++) {
  805. if (!result[j]) {
  806. result[j] = []
  807. }
  808. result[j][i] = data[i][j]
  809. }
  810. }
  811. data = result
  812. }
  813. result = {}
  814. //普通图表
  815. if (meta.chartType != typeConfig.length - 1) {
  816. categories = data[0].slice(1)
  817. for (var i = 1, curData; (curData = data[i]); i++) {
  818. series.push({
  819. name: curData[0],
  820. data: curData.slice(1)
  821. })
  822. }
  823. result.series = series
  824. result.categories = categories
  825. result.title = meta.title
  826. result.subTitle = meta.subTitle
  827. result.xTitle = meta.xTitle
  828. result.yTitle = meta.yTitle
  829. result.suffix = meta.suffix
  830. } else {
  831. var curData = []
  832. for (var i = 1, len = data[0].length; i < len; i++) {
  833. curData.push([data[0][i], data[1][i] | 0])
  834. }
  835. //饼图
  836. series[0] = {
  837. type: 'pie',
  838. name: meta.tip,
  839. data: curData
  840. }
  841. result.series = series
  842. result.title = meta.title
  843. result.suffix = meta.suffix
  844. }
  845. return result
  846. }
  847. })
  848. UE.parse.register('background', function (utils) {
  849. var me = this,
  850. root = me.root,
  851. p = root.getElementsByTagName('p'),
  852. styles
  853. for (var i = 0, ci; (ci = p[i++]); ) {
  854. styles = ci.getAttribute('data-background')
  855. if (styles) {
  856. ci.parentNode.removeChild(ci)
  857. }
  858. }
  859. //追加默认的表格样式
  860. styles && utils.cssRule('ueditor_background', me.selector + '{' + styles + '}', document)
  861. })
  862. UE.parse.register('list', function (utils) {
  863. var customCss = [],
  864. customStyle = {
  865. cn: 'cn-1-',
  866. cn1: 'cn-2-',
  867. cn2: 'cn-3-',
  868. num: 'num-1-',
  869. num1: 'num-2-',
  870. num2: 'num-3-',
  871. dash: 'dash',
  872. dot: 'dot'
  873. }
  874. utils.extend(this, {
  875. liiconpath: 'http://bs.baidu.com/listicon/',
  876. listDefaultPaddingLeft: '20'
  877. })
  878. var root = this.root,
  879. ols = root.getElementsByTagName('ol'),
  880. uls = root.getElementsByTagName('ul'),
  881. selector = this.selector
  882. if (ols.length) {
  883. applyStyle.call(this, ols)
  884. }
  885. if (uls.length) {
  886. applyStyle.call(this, uls)
  887. }
  888. if (ols.length || uls.length) {
  889. customCss.push(selector + ' .list-paddingleft-1{padding-left:0}')
  890. customCss.push(
  891. selector + ' .list-paddingleft-2{padding-left:' + this.listDefaultPaddingLeft + 'px}'
  892. )
  893. customCss.push(
  894. selector + ' .list-paddingleft-3{padding-left:' + this.listDefaultPaddingLeft * 2 + 'px}'
  895. )
  896. utils.cssRule(
  897. 'list',
  898. selector +
  899. ' ol,' +
  900. selector +
  901. ' ul{margin:0;padding:0;}li{clear:both;}' +
  902. customCss.join('\n'),
  903. document
  904. )
  905. }
  906. function applyStyle(nodes) {
  907. var T = this
  908. utils.each(nodes, function (list) {
  909. if (list.className && /custom_/i.test(list.className)) {
  910. var listStyle = list.className.match(/custom_(\w+)/)[1]
  911. if (listStyle == 'dash' || listStyle == 'dot') {
  912. utils.pushItem(
  913. customCss,
  914. selector +
  915. ' li.list-' +
  916. customStyle[listStyle] +
  917. '{background-image:url(' +
  918. T.liiconpath +
  919. customStyle[listStyle] +
  920. '.gif)}'
  921. )
  922. utils.pushItem(
  923. customCss,
  924. selector +
  925. ' ul.custom_' +
  926. listStyle +
  927. '{list-style:none;} ' +
  928. selector +
  929. ' ul.custom_' +
  930. listStyle +
  931. ' li{background-position:0 3px;background-repeat:no-repeat}'
  932. )
  933. } else {
  934. var index = 1
  935. utils.each(list.childNodes, function (li) {
  936. if (li.tagName == 'LI') {
  937. utils.pushItem(
  938. customCss,
  939. selector +
  940. ' li.list-' +
  941. customStyle[listStyle] +
  942. index +
  943. '{background-image:url(' +
  944. T.liiconpath +
  945. 'list-' +
  946. customStyle[listStyle] +
  947. index +
  948. '.gif)}'
  949. )
  950. index++
  951. }
  952. })
  953. utils.pushItem(
  954. customCss,
  955. selector +
  956. ' ol.custom_' +
  957. listStyle +
  958. '{list-style:none;}' +
  959. selector +
  960. ' ol.custom_' +
  961. listStyle +
  962. ' li{background-position:0 3px;background-repeat:no-repeat}'
  963. )
  964. }
  965. switch (listStyle) {
  966. case 'cn':
  967. utils.pushItem(
  968. customCss,
  969. selector + ' li.list-' + listStyle + '-paddingleft-1{padding-left:25px}'
  970. )
  971. utils.pushItem(
  972. customCss,
  973. selector + ' li.list-' + listStyle + '-paddingleft-2{padding-left:40px}'
  974. )
  975. utils.pushItem(
  976. customCss,
  977. selector + ' li.list-' + listStyle + '-paddingleft-3{padding-left:55px}'
  978. )
  979. break
  980. case 'cn1':
  981. utils.pushItem(
  982. customCss,
  983. selector + ' li.list-' + listStyle + '-paddingleft-1{padding-left:30px}'
  984. )
  985. utils.pushItem(
  986. customCss,
  987. selector + ' li.list-' + listStyle + '-paddingleft-2{padding-left:40px}'
  988. )
  989. utils.pushItem(
  990. customCss,
  991. selector + ' li.list-' + listStyle + '-paddingleft-3{padding-left:55px}'
  992. )
  993. break
  994. case 'cn2':
  995. utils.pushItem(
  996. customCss,
  997. selector + ' li.list-' + listStyle + '-paddingleft-1{padding-left:40px}'
  998. )
  999. utils.pushItem(
  1000. customCss,
  1001. selector + ' li.list-' + listStyle + '-paddingleft-2{padding-left:55px}'
  1002. )
  1003. utils.pushItem(
  1004. customCss,
  1005. selector + ' li.list-' + listStyle + '-paddingleft-3{padding-left:68px}'
  1006. )
  1007. break
  1008. case 'num':
  1009. case 'num1':
  1010. utils.pushItem(
  1011. customCss,
  1012. selector + ' li.list-' + listStyle + '-paddingleft-1{padding-left:25px}'
  1013. )
  1014. break
  1015. case 'num2':
  1016. utils.pushItem(
  1017. customCss,
  1018. selector + ' li.list-' + listStyle + '-paddingleft-1{padding-left:35px}'
  1019. )
  1020. utils.pushItem(
  1021. customCss,
  1022. selector + ' li.list-' + listStyle + '-paddingleft-2{padding-left:40px}'
  1023. )
  1024. break
  1025. case 'dash':
  1026. utils.pushItem(
  1027. customCss,
  1028. selector + ' li.list-' + listStyle + '-paddingleft{padding-left:35px}'
  1029. )
  1030. break
  1031. case 'dot':
  1032. utils.pushItem(
  1033. customCss,
  1034. selector + ' li.list-' + listStyle + '-paddingleft{padding-left:20px}'
  1035. )
  1036. }
  1037. }
  1038. })
  1039. }
  1040. })
  1041. UE.parse.register('vedio', function (utils) {
  1042. var video = this.root.getElementsByTagName('video'),
  1043. audio = this.root.getElementsByTagName('audio')
  1044. document.createElement('video')
  1045. document.createElement('audio')
  1046. if (video.length || audio.length) {
  1047. var sourcePath = utils.removeLastbs(this.rootPath),
  1048. jsurl = sourcePath + '/third-party/video-js/video.js',
  1049. cssurl = sourcePath + '/third-party/video-js/video-js.min.css',
  1050. swfUrl = sourcePath + '/third-party/video-js/video-js.swf'
  1051. if (window.videojs) {
  1052. videojs.autoSetup()
  1053. } else {
  1054. utils.loadFile(document, {
  1055. id: 'video_css',
  1056. tag: 'link',
  1057. rel: 'stylesheet',
  1058. type: 'text/css',
  1059. href: cssurl
  1060. })
  1061. utils.loadFile(
  1062. document,
  1063. {
  1064. id: 'video_js',
  1065. src: jsurl,
  1066. tag: 'script',
  1067. type: 'text/javascript'
  1068. },
  1069. function () {
  1070. videojs.options.flash.swf = swfUrl
  1071. videojs.autoSetup()
  1072. }
  1073. )
  1074. }
  1075. }
  1076. })
  1077. })()