editor-parse.js 36 KB

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