From af31dc666fde88b97d86c27652fd960225478989 Mon Sep 17 00:00:00 2001 From: Jinqn <459452372> Date: Fri, 25 Oct 2013 16:58:25 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[fix]by=20Jinqn=20=E4=BF=AE=E6=94=B9grunt,?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E8=A1=A8=E6=A0=BC=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E7=9A=84demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gruntfile.js | 36 +++++----- _examples/sortableDemo.html | 135 ++++++++++++++++++++---------------- parse/parse.js | 87 ++++++++++++++++++----- parse/table.js | 16 ++--- 4 files changed, 168 insertions(+), 106 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index b69921cb3..48a5b878a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -6,26 +6,20 @@ module.exports = function ( grunt ) { Util = { jsBasePath: '_src/', + parseBasePath: 'parse/', cssBasePath: 'themes/default/_css/', - fetchScripts: function () { - - var sources = fs.readFileSync( "_examples/editor_api.js" ); - - sources = /\[([^\]]+)\]/.exec( sources ); + fetchScripts: function ( readFile, basePath) { + var sources = fs.readFileSync( readFile ); + sources = /\[([^\]]+\.js'[^\]]+)\]/.exec( sources ); sources = sources[1].replace( /\/\/.*\n/g, '\n' ).replace( /'|"|\n|\t|\s/g, '' ); - sources = sources.split( "," ); - sources.forEach( function ( filepath, index ) { - - sources[ index ] = Util.jsBasePath + filepath; - + sources[ index ] = basePath + filepath; } ); return sources; - }, fetchStyles: function () { @@ -36,9 +30,7 @@ module.exports = function ( grunt ) { src = []; while ( filepath = pattern.exec( sources ) ) { - src.push( this.cssBasePath + filepath[ 1 ].replace( /'|"/g, "" ) ); - } return src; @@ -68,13 +60,21 @@ module.exports = function ( grunt ) { options: { banner: banner + '(function(){\n\n', footer: '\n\n})()', - process: function(src, filepath) { + process: function(src) { return src.replace('/_css/', '/css/'); } }, - src: Util.fetchScripts(), + src: Util.fetchScripts( "_examples/editor_api.js", Util.jsBasePath ), dest: disDir + '<%= pkg.name %>.all.js' }, + parse: { + options: { + banner: banner + '(function(){\n\n', + footer: '\n\n})()' + }, + src: Util.fetchScripts( "ueditor.parse.js", Util.parseBasePath ), + dest: disDir + '<%= pkg.name %>.parse.js' + }, css: { src: Util.fetchStyles(), dest: disDir + 'themes/default/css/ueditor.css' @@ -99,6 +99,10 @@ module.exports = function ( grunt ) { dest: { src: disDir + '<%= pkg.name %>.all.js', dest: disDir + '<%= pkg.name %>.all.min.js' + }, + dest1: { + src: disDir + '<%= pkg.name %>.parse.js', + dest: disDir + '<%= pkg.name %>.parse.min.js' } }, copy: { @@ -106,7 +110,7 @@ module.exports = function ( grunt ) { files: [ { - src: [ 'themes/iframe.css', 'themes/default/dialogbase.css', 'themes/default/images/**', 'dialogs/**', 'lang/**', 'third-party/**', 'ueditor.parse.js' ], + src: [ 'themes/iframe.css', 'themes/default/dialogbase.css', 'themes/default/images/**', 'dialogs/**', 'lang/**', 'third-party/**' ], dest: disDir } diff --git a/_examples/sortableDemo.html b/_examples/sortableDemo.html index 51898ca62..3bbb75b18 100644 --- a/_examples/sortableDemo.html +++ b/_examples/sortableDemo.html @@ -1,71 +1,84 @@ - + - UEditor表格排序示例 - - - - - - - - - - - + + + + -

UEditor表格排序示例

-
- -
-
- - 点击下面表格第一行的单元格进行排序 +

表格排序演示

+

+

+ 默认排序方法有五种:
+ reversecurrent : 逆序当前
+ orderbyasc : 按ASCII字符升序
+ reversebyasc : 按ASCII字符降序
+ orderbynum : 按数值大小升序
+ reversebynum : 按数值大小降序 +

+

+ 表格data-sort-type属性值为reversebynum,按照数值大小降序排序,点击第一行的单元格进行排序。 +

+
+ + + + + + + + +
343 352 323 234 379 782
341 163 422 234 725 833
221 456 335 423 445 793
112 277 563 423 932 425
587 175 159 734 582 458
-
-


-
- - + \ No newline at end of file diff --git a/parse/parse.js b/parse/parse.js index 8b1234131..7645ef24e 100644 --- a/parse/parse.js +++ b/parse/parse.js @@ -1,9 +1,6 @@ (function(){ UE = window.UE || {}; - var isIE = !!window.ActiveXObject, - trim = function (str) { - return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, ''); - }; + var isIE = !!window.ActiveXObject; //定义utils工具 var utils = { removeLastbs : function(url){ @@ -126,7 +123,20 @@ arr.push(item) } }, - trim:trim, + trim: function (str) { + return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, ''); + }, + indexOf: function (array, item, start) { + var index = -1; + start = this.isNumber(start) ? start : 0; + this.each(array, function (v, i) { + if (i >= start && v === item) { + index = i; + return false; + } + }); + return index; + }, hasClass: function (element, className) { className = className.replace(/(^[ ]+)|([ ]+$)/g, '').replace(/[ ]{2,}/g, ' ').split(' '); for (var i = 0, ci, cls = element.className; ci = className[i++];) { @@ -138,7 +148,7 @@ }, addClass:function (elm, classNames) { if(!elm)return; - classNames = trim(classNames).replace(/[ ]{2,}/g,' ').split(' '); + classNames = this.trim(classNames).replace(/[ ]{2,}/g,' ').split(' '); for(var i = 0,ci,cls = elm.className;ci=classNames[i++];){ if(!new RegExp('\\b' + ci + '\\b').test(cls)){ cls += ' ' + ci; @@ -147,27 +157,70 @@ elm.className = utils.trim(cls); }, removeClass:function (elm, classNames) { - classNames = utils.isArray(classNames) ? classNames : - trim(classNames).replace(/[ ]{2,}/g,' ').split(' '); + classNames = this.isArray(classNames) ? classNames : + this.trim(classNames).replace(/[ ]{2,}/g,' ').split(' '); for(var i = 0,ci,cls = elm.className;ci=classNames[i++];){ cls = cls.replace(new RegExp('\\b' + ci + '\\b'),'') } - cls = trim(cls).replace(/[ ]{2,}/g,' '); + cls = this.trim(cls).replace(/[ ]{2,}/g,' '); if(cls){ elm.className = cls; }else{ elm.removeAttribute('class'); } }, - on: isIE ? function (element, type, fn) { - element.attachEvent(type, fn); - } : function (element, type, fn) { - element.addEventListener(type, fn); + on: function (element, type, handler) { + var types = this.isArray(type) ? type : type.split(/\s+/), + k = types.length; + if (k) while (k--) { + type = types[k]; + if (element.addEventListener) { + element.addEventListener(type, handler, false); + } else { + if (!handler._d) { + handler._d = { + els : [] + }; + } + var key = type + handler.toString(),index = utils.indexOf(handler._d.els,element); + if (!handler._d[key] || index == -1) { + if(index == -1){ + handler._d.els.push(element); + } + if(!handler._d[key]){ + handler._d[key] = function (evt) { + return handler.call(evt.srcElement, evt || window.event); + }; + } + + + element.attachEvent('on' + type, handler._d[key]); + } + } + } + element = null; }, - un: isIE ? function (element, type, fn) { - element.detachEvent(type, fn); - } : function (element, type, fn) { - element.removeEventListener(type, fn); + off: function (element, type, handler) { + var types = this.isArray(type) ? type : type.split(/\s+/), + k = types.length; + if (k) while (k--) { + type = types[k]; + if (element.removeEventListener) { + element.removeEventListener(type, handler, false); + } else { + var key = type + handler.toString(); + try{ + element.detachEvent('on' + type, handler._d ? handler._d[key] : handler); + }catch(e){} + if (handler._d && handler._d[key]) { + var index = utils.indexOf(handler._d.els,element); + if(index!=-1){ + handler._d.els.splice(index,1); + } + handler._d.els.length == 0 && delete handler._d[key]; + } + } + } }, loadFile : function () { var tmpList = []; diff --git a/parse/table.js b/parse/table.js index 5a881994c..3c48f0432 100644 --- a/parse/table.js +++ b/parse/table.js @@ -1,5 +1,6 @@ UE.parse.register('table', function (utils) { - var root = this.root, + var me = this, + root = this.root, tables = root.getElementsByTagName('table'); if (tables.length) { var selector = this.selector; @@ -36,10 +37,10 @@ UE.parse.register('table', function (utils) { var target = e.target || e.srcElement, cell = findParentByTagName(target, ['td', 'th']); var table = findParentByTagName(target, 'table'), - colIndex = indexOf(table.rows[0].cells, cell), + colIndex = utils.indexOf(table.rows[0].cells, cell), sortType = table.getAttribute('data-sort-type'); if(colIndex != -1) { - sortTable(table, colIndex, sortType); + sortTable(table, colIndex, me.tableSortCompareFn || sortType); updateTable(table); } }); @@ -58,15 +59,6 @@ UE.parse.register('table', function (utils) { } return null; } - //查找项在数组中的索引 - function indexOf(arr, item) { - for (var i = 0; i < arr.length; i++) { - if(arr[i] === item) { - return i; - } - } - return -1; - } //表格排序 function sortTable(table, sortByCellIndex, compareFn) { var rows = table.rows, From 67379bb5dd6a3ea9f5674945bd7ce0f02e772f1d Mon Sep 17 00:00:00 2001 From: Jinqn <459452372> Date: Fri, 25 Oct 2013 17:09:34 +0800 Subject: [PATCH 2/3] [fix]by Jinqn --- {parse => _parse}/insertcode.js | 0 {parse => _parse}/list.js | 0 {parse => _parse}/parse.js | 0 {parse => _parse}/table.js | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {parse => _parse}/insertcode.js (100%) rename {parse => _parse}/list.js (100%) rename {parse => _parse}/parse.js (100%) rename {parse => _parse}/table.js (100%) diff --git a/parse/insertcode.js b/_parse/insertcode.js similarity index 100% rename from parse/insertcode.js rename to _parse/insertcode.js diff --git a/parse/list.js b/_parse/list.js similarity index 100% rename from parse/list.js rename to _parse/list.js diff --git a/parse/parse.js b/_parse/parse.js similarity index 100% rename from parse/parse.js rename to _parse/parse.js diff --git a/parse/table.js b/_parse/table.js similarity index 100% rename from parse/table.js rename to _parse/table.js From e272328cfdc83b542a19afe9f4aa5e868a4c379f Mon Sep 17 00:00:00 2001 From: Jinqn <459452372> Date: Fri, 25 Oct 2013 17:09:48 +0800 Subject: [PATCH 3/3] [fix]by Jinqn --- ueditor.parse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ueditor.parse.js b/ueditor.parse.js index d440c4259..d9a2cc7c5 100644 --- a/ueditor.parse.js +++ b/ueditor.parse.js @@ -375,7 +375,7 @@ 'insertcode.js', 'table.js' ], - baseURL = '../parse/'; + baseURL = '../_parse/'; for (var i=0,pi;pi = paths[i++];) { document.write(''); }