From 3702da6edec06e9f633d9e0ae58f3dc2a016410f Mon Sep 17 00:00:00 2001 From: Kris Zhang Date: Sat, 12 Dec 2015 14:57:23 +0800 Subject: [PATCH 01/10] Rewrite Tree plugin --- CNAME | 1 + build.sh | 6 - css/jquery.bootstrap.css | 30 +++++ home.html => index.html | 0 js/jquery.bootstrap.js | 128 ++++++++++-------- js/jquery.bootstrap.min.js | 2 +- src/jquery.datagrid.js | 265 ------------------------------------- src/jquery.dialog.js | 157 ---------------------- src/jquery.messager.js | 104 --------------- src/jquery.tree.js | 93 ------------- src/string.format.js | 16 --- 11 files changed, 102 insertions(+), 700 deletions(-) create mode 100644 CNAME create mode 100644 css/jquery.bootstrap.css rename home.html => index.html (100%) delete mode 100644 src/jquery.datagrid.js delete mode 100644 src/jquery.dialog.js delete mode 100644 src/jquery.messager.js delete mode 100644 src/jquery.tree.js delete mode 100644 src/string.format.js diff --git a/CNAME b/CNAME new file mode 100644 index 0000000..f550da1 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +bootstrap.ourjs.com \ No newline at end of file diff --git a/build.sh b/build.sh index d8d9589..856b8ed 100755 --- a/build.sh +++ b/build.sh @@ -3,12 +3,6 @@ #show commands set -x -#combine source files into one -cd src -cat copyright.js string.format.js jquery.dialog.js jquery.messager.js jquery.datagrid.js jquery.tree.js > ../js/jquery.bootstrap.js -cd .. - - #require uglify js: [sudo]npm install uglify-js -g node src/minifier js/jquery.bootstrap.js js/jquery.bootstrap.min.tmp.js cat src/copyright.js js/jquery.bootstrap.min.tmp.js > js/jquery.bootstrap.min.js diff --git a/css/jquery.bootstrap.css b/css/jquery.bootstrap.css new file mode 100644 index 0000000..ae6763b --- /dev/null +++ b/css/jquery.bootstrap.css @@ -0,0 +1,30 @@ +.tree-nav .nav { + display: none; +} + +.tree-nav .active > .nav { + display: block; +} + +.tree-folder, +.tree-indent, +.tree-item { + position: relative; + top: 1px; + display: inline-block; + height: 1em; + width: 1em; +} + +.tree-folder, +.tree-item { + margin-right: 6px; +} + +.tree-nav .active > a .tree-folder:before { + content: "\e118"; /*folder open*/ +} + +.tree-arrow .active > a .tree-folder:before { + content: "\e113"; /*arrow up*/ +} \ No newline at end of file diff --git a/home.html b/index.html similarity index 100% rename from home.html rename to index.html diff --git a/js/jquery.bootstrap.js b/js/jquery.bootstrap.js index c374ffd..169b974 100644 --- a/js/jquery.bootstrap.js +++ b/js/jquery.bootstrap.js @@ -250,10 +250,10 @@ $.messager = (function() { + '' ; - var $msgbox; + var $msgbox = $('.dialog.msg-popup') var popup = function(message) { - if (!$msgbox) { + if (!$msgbox.size()) { $msgbox = $(msghtml); $('body').append($msgbox); } @@ -263,7 +263,7 @@ $.messager = (function() { setTimeout(function() { $msgbox.modal('hide'); - }, 1500); + }, 2000); }; return { @@ -551,88 +551,100 @@ Dependence: string.js $.fn.tree = function(method, options) { - var self = this - , $this = $(self) - , pushFn = Array.prototype.push - , icon_node = "glyphicon-file" - , icon_open = "glyphicon-folder-open" - , icon_close = "glyphicon-folder-close" - ; + var self = this + , $this = $(self) + , pushFn = Array.prototype.push + , treeClass = 'nav' + , activeClass = 'active' + , folderIcon = 'glyphicon glyphicon-folder-close' + , itemIcon = 'glyphicon glyphicon-file' + , indentIcon = '' + - var build = function(data, root, parentState) { + var build = function(data, indent) { var tree = []; - !root && tree.push('') + + return tree + } var bind = function() { $("span.glyphicon-folder-open, span.glyphicon-folder-close", $this).click(function(e) { var $icon = $(this) - , $children = $icon.closest("li").children("ul"); + , $children = $icon.closest("li").children("ul") if ($icon.hasClass(icon_close)){ - $icon.removeClass(icon_close).addClass(icon_open); - $children.show(); + $icon.removeClass(icon_close).addClass(icon_open) + $children.show() } else { - $icon.removeClass(icon_open).addClass(icon_close); - $children.hide(); + $icon.removeClass(icon_open).addClass(icon_close) + $children.hide() } - }); - }; + }) + } if (method && method.constructor == Object) { - var data = method.data; + treeClass = method.treeClass || treeClass + activeClass = method.activeClass || activeClass + folderIcon = typeof method.folderIcon == 'undefined' ? folderIcon : method.folderIcon + itemIcon = typeof method.itemIcon == 'undefined' ? itemIcon : method.itemIcon + indentIcon = typeof method.indentIcon == 'undefined' ? indentIcon : method.indentIcon + + var data = method.data if (data && (data.constructor == Array)) { - var htmlArr = build(data, true); - $this.html(htmlArr.join('')); - $this.data("config", method); - bind(); + var htmlArr = build(data, '') + $this.html(htmlArr.join('')) + $this.data("config", method) + bind() } - var clickHandler = method.onClick; - if (clickHandler) { - $("li>a", $this).click(function() { - var $link = $(this); - attrs = $link.attr("data-attr"); - - clickHandler.call(self, { - id : $link.attr("data-id") - , attributes : attrs ? JSON.parse(attrs) : {} - , text : $link.text() - }, $link); - }); - } + var clickHandler = method.onClick + + $("li>a", $this).click(function() { + var $link = $(this) + , attrs = $link.attr("data-attr") + + $link.closest('li') + .toggleClass(activeClass) + + clickHandler && clickHandler.call(self, { + id : $link.attr("data-id") + , attributes : attrs ? JSON.parse(attrs) : {} + , text : $link.text() + }, $link) + }) } - return self; + return self }; })(jQuery); \ No newline at end of file diff --git a/js/jquery.bootstrap.min.js b/js/jquery.bootstrap.min.js index 3f348cc..5946a2f 100644 --- a/js/jquery.bootstrap.min.js +++ b/js/jquery.bootstrap.min.js @@ -3,4 +3,4 @@ Copyright (c) Kris Zhang License: MIT (https://github.com/newghost/bootstrap-jquery-plugin/blob/master/LICENSE) */ -String.prototype.format||(String.prototype.format=function(){var e=arguments;return this.replace(/{(\d+)}/g,function(t,n){return typeof e[n]!="undefined"?e[n]:t})}),function(e){e.fn.dialog=function(t){var n=this,r=e(n),i=e(document.body),s=r.closest(".dialog"),o="dialog-parent",u=arguments[1],a=arguments[2],f=function(){var t='';s=e(t),e(document.body).append(s),s.find(".modal-body").append(r)},l=function(r){var i=(r||t||{}).buttons||{},o=s.find(".modal-footer");o.empty();var u=i.constructor==Array;for(var a in i){var f=i[a],l="",c="",h="btn-default",p="";if(f.constructor==Object)l=f.id,c=f.text,h=f["class"]||f.classed||h,p=f.click;else{if(!!u||f.constructor!=Function)continue;c=a,p=f}$button=e('';s=e(t),e(document.body).append(s),s.find(".modal-body").append(r)},l=function(r){var i=(r||t||{}).buttons||{},o=s.find(".modal-footer");o.empty();var u=i.constructor==Array;for(var a in i){var f=i[a],l="",c="",h="btn-default",p="";if(f.constructor==Object)l=f.id,c=f.text,h=f["class"]||f.classed||h,p=f.click;else{if(!!u||f.constructor!=Function)continue;c=a,p=f}$button=e('' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - ; - - - $msgbox = $(msghtml); - $(document.body).append($msgbox); - $msgbox.find(".modal-body").append($this); - }; - - var createButton = function(_options) { - var buttons = (_options || options || {}).buttons || {} - , $btnrow = $msgbox.find(".modal-footer"); - - //clear old buttons - $btnrow.empty(); - - var isButtonArr = buttons.constructor == Array; - - for (var button in buttons) { - var btnObj = buttons[button] - , id = "" - , text = "" - , classed = "btn-default" - , click = ""; - - if (btnObj.constructor == Object) { - id = btnObj.id; - text = btnObj.text; - classed = btnObj['class'] || btnObj.classed || classed; - click = btnObj.click; - } - - //Buttons should be an object, etc: { 'close': function { } } - else if (!isButtonArr && btnObj.constructor == Function) { - text = button; - click = btnObj; - } - - else { - continue; - } - - // - $button = $('