ueditor.parse.js 36KB

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