b8ee871fb25683636107e5c3c70ccc7147a3f06c.svn-base 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. /*!
  2. * UEditor
  3. * version: ueditor
  4. * build: Wed Aug 10 2016 11:06:03 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. })();