From 84d616193e32b7cdea9f8f0e49aee4eb6055e276 Mon Sep 17 00:00:00 2001 From: cssmagic Date: Tue, 10 May 2016 15:14:37 +0800 Subject: [PATCH] Release first version of v0.6. --- .npmignore | 1 + dist/gearbox.js | 200 +++++++++++++++++++------------------------- dist/gearbox.min.js | 2 +- package.json | 2 +- 4 files changed, 87 insertions(+), 118 deletions(-) diff --git a/.npmignore b/.npmignore index 9885b31..85d1729 100644 --- a/.npmignore +++ b/.npmignore @@ -3,3 +3,4 @@ !package.json !README.md !dist/*.js +!src/plugin/*.js diff --git a/dist/gearbox.js b/dist/gearbox.js index a532101..4e5e6f8 100644 --- a/dist/gearbox.js +++ b/dist/gearbox.js @@ -1,6 +1,7 @@ /*! Gearbox | MIT | https://github.com/CMUI/gearbox */ !function (window, undefined) { - 'use strict' + // check conflict + if (window.gearbox) return false // shortcut var _ = window._ @@ -10,85 +11,54 @@ if (!_ || !$) return false //////////////////// START: source code //////////////////// +/* */ //////////////////// core //////////////////// // namespace -var _ext = {} +var gearbox = {} // shortcut var document = window.document -void function (window, _ext) { +void function (window, gearbox) { 'use strict' /** * bind a set of apis to a key of `_` as namespace - * @param key {string} + * @param moduleName {string} * @param apiSet {object} */ - _ext.exports = function (key, apiSet) { - if (!key || !_.isString(key) || !apiSet || !_.isObject(apiSet)) { - /* - console.error('[Gearbox] [exports] missing or wrong param.') - */ + gearbox.__defineModule = function (moduleName, apiSet) { + if (!moduleName || !_.isString(moduleName) || !apiSet || !_.isObject(apiSet)) return - return - } - - if (key === 'root') { - // {apiSet}.xxx => _.xxx + if (moduleName === 'root') { + // {apiSet}.xxx => gearbox.xxx _.each(apiSet, function (value, key) { - exportKey(key, value) + gearbox[key] = value }) } else { - // {apiSet}.xxx => _.{key}.xxx - exportKey(key, apiSet) + // {apiSet}.xxx => gearbox.{key}.xxx + gearbox[moduleName] = apiSet } - function exportKey(key, apiSet) { - if (checkKey(key)) { - _.extend(_[key], apiSet) - } else { - _[key] = apiSet - } - } - function checkKey(key) { - if (_[key]) { - /* - // warn if going to modify existed key unintentionally - var knownKeysToBeExtended = ['template', 'str'] - if (!_.include(knownKeysToBeExtended, key)) { - console.warn('[Gearbox] [exports] `_` already has key: ' + key) - } - */ - return true - } else { - return false - } - } } -}(window, _ext) - +}(window, gearbox) -//////////////////// str - alternative to underscore.string //////////////////// -// this file contains apis same as underscore.string's. -// heavily inspired by [underscore.string](https://github.com/epeli/underscore.string) -// if you has underscore.string in your project, -// just skip this file when building your own package. - -void function (window, _ext) { +//////////////////// str //////////////////// +void function (window, gearbox) { 'use strict' // namespace - var str = _.str || {} - // check underscore.string - quit if underscore.string existed - if (str.VERSION && typeof str.trim === 'function') return + var str = {} + //////////////////// START: alternative to underscore.string //////////////////// + // this section contains apis same as underscore.string's. + // heavily inspired by [underscore.string](https://github.com/epeli/underscore.string) // source: https://github.com/epeli/underscore.string/blob/master/lib/underscore.string.js + // util - var _s = str var nativeTrim = String.prototype.trim var nativeTrimRight = String.prototype.trimRight var nativeTrimLeft = String.prototype.trimLeft @@ -107,7 +77,7 @@ void function (window, _ext) { else if (characters.source) return characters.source else - return '[' + _s.escapeRegExp(characters) + ']' + return '[' + str.escapeRegExp(characters) + ']' } str.escapeRegExp = function (str) { if (str == null) return '' @@ -158,21 +128,12 @@ void function (window, _ext) { } // aliases - _s.contains = _s.include - - // exports - _ext.exports('str', str) + str.contains = str.include + str.includes = str.include -}(window, _ext) + //////////////////// END: alternative to underscore.string //////////////////// -//////////////////// str //////////////////// -void function (window, _ext) { - 'use strict' - - // namespace - var str = _.str || {} - // shortcuts for frequently-used characters str.CNY = str.RMB = '\xA5' // CNY(RMB) symbol str.FULL_WIDTH_CNY = str.FULL_WIDTH_RMB = '\uffe5' // full-width version of CNY(RMB) symbol @@ -184,13 +145,13 @@ void function (window, _ext) { // hash str.isHash = function (str) { - str = _.str.trim(str) - return _.str.startsWith(str, '#') + str = gearbox.str.trim(str) + return gearbox.str.startsWith(str, '#') } str.stripHash = function (str) { - str = _.str.trim(str) - str = _.str.ltrim(str, '#') - if (_.str.startsWith(str, '!')) str = str.slice(1) + str = gearbox.str.trim(str) + str = gearbox.str.ltrim(str, '#') + if (gearbox.str.startsWith(str, '!')) str = str.slice(1) return str } @@ -210,16 +171,16 @@ void function (window, _ext) { var n = parseFloat(str) return n < 0 ? Math.ceil(n) : Math.floor(n) } - str.toFixed = function (str, i) {return _.str.toFloat(_.str.toFloat(str).toFixed(i || 0))} + str.toFixed = function (str, i) {return gearbox.str.toFloat(gearbox.str.toFloat(str).toFixed(i || 0))} // exports - _ext.exports('str', str) + gearbox.__defineModule('str', str) -}(window, _ext) +}(window, gearbox) //////////////////// root //////////////////// -void function (window, _ext) { +void function (window, gearbox) { 'use strict' var root = { @@ -227,7 +188,7 @@ void function (window, _ext) { var result if (_.isElement(input)) { result = input.__$__ = input.__$__ || $(input) - } else if (_.dom.is$Element(input)) { + } else if (gearbox.dom.is$Element(input)) { result = input } else { result = $(input) @@ -237,13 +198,13 @@ void function (window, _ext) { isPlainObject: $.isPlainObject } - _ext.exports('root', root) + gearbox.__defineModule('root', root) -}(window, _ext) +}(window, gearbox) //////////////////// ua //////////////////// -void function (window, _ext) { +void function (window, gearbox) { 'use strict' // namespace @@ -262,8 +223,8 @@ void function (window, _ext) { var s = ua.str.toLowerCase() ua.isSafari = /\bapple\b/i.test(navigator.vendor) && /\bsafari\b/i.test(s) - ua.isChrome = _.str.include(s, 'chrome') || - _.str.include(s, 'crios') // both desktop and mobile version + ua.isChrome = gearbox.str.include(s, 'chrome') || + gearbox.str.include(s, 'crios') // both desktop and mobile version // platform version and device ua.osVersion = '' @@ -275,7 +236,7 @@ void function (window, _ext) { ua.osVersion = (/[\/; i]os[\/: _](\d+(?:[\._]\d+)?)[\._; ]/.exec(s) || [0, ''])[1] .replace('_', '.') } else { - var _includeAndroid = _.str.include(s, 'android') + var _includeAndroid = gearbox.str.include(s, 'android') var _includeAdr = /\badr\b/.test(s) && /\blinux;\s*u;/.test(s) var _isJUC = /juc\s*\(linux;\s*u;\s*\d+\.\d+/.test(s) ua.isAndroid = _includeAndroid || _includeAdr || _isJUC @@ -289,38 +250,38 @@ void function (window, _ext) { } } // fix - Windows Phone might pretend to be iOS or Android - if (_.str.include(s, 'windows phone')) { + if (gearbox.str.include(s, 'windows phone')) { ua.isIOS = ua.isAndroid = false ua.osVersion = '' } - if (ua.osVersion && !_.str.include(ua.osVersion, '.')) ua.osVersion += '.0' + if (ua.osVersion && !gearbox.str.include(ua.osVersion, '.')) ua.osVersion += '.0' // summery ua.isMobileDevice = !!(ua.isIOS || ua.isAndroid) // get browser info var browser = '' - if (_.str.include(s, 'micromessenger')) { + if (gearbox.str.include(s, 'micromessenger')) { browser = 'wechat' - } else if (_.str.include(s, 'ucbrowser') || _.str.include(s, 'ucweb') || _.str.include(s, ' uc applewebkit')) { + } else if (gearbox.str.include(s, 'ucbrowser') || gearbox.str.include(s, 'ucweb') || gearbox.str.include(s, ' uc applewebkit')) { browser = 'uc' - } else if (_.str.include(s, 'baiduhd') || _.str.include(s, 'baiduboxapp')) { + } else if (gearbox.str.include(s, 'baiduhd') || gearbox.str.include(s, 'baiduboxapp')) { browser = 'baidu-app' - } else if (_.str.include(s, 'baidubrowser')) { + } else if (gearbox.str.include(s, 'baidubrowser')) { browser = 'baidu-browser' - } else if (_.str.include(s, 'mqqbrowser')) { + } else if (gearbox.str.include(s, 'mqqbrowser')) { browser = 'm-qq-browser' - } else if (_.str.include(s, 'miuibrowser')) { + } else if (gearbox.str.include(s, 'miuibrowser')) { browser = 'miui' - } else if (_.str.include(s, '_weibo_') || _.str.include(s, ' weibo ')) { + } else if (gearbox.str.include(s, '_weibo_') || gearbox.str.include(s, ' weibo ')) { browser = 'weibo' - } else if (_.str.include(s, 'firefox')) { + } else if (gearbox.str.include(s, 'firefox')) { browser = 'firefox' - } else if (_.str.include(s, 'opera')) { + } else if (gearbox.str.include(s, 'opera')) { browser = 'opera' - } else if (_.str.include(s, ' edge/')) { + } else if (gearbox.str.include(s, ' edge/')) { browser = 'edge' - } else if (_.str.include(s, 'iemobile')) { + } else if (gearbox.str.include(s, 'iemobile')) { browser = 'ie-mobile' } // these two must be the last @@ -350,7 +311,7 @@ void function (window, _ext) { } } if (!engine) { - if (_.str.include(s, 'webkit')) { + if (gearbox.str.include(s, 'webkit')) { engine = 'webkit' } else if (ua.isIOS) { engine = 'webkit' @@ -358,7 +319,7 @@ void function (window, _ext) { engine = 'webkit' } if (browser === 'firefox' && !ua.isIOS) engine = 'gecko' - if (browser === 'opera' && !ua.isIOS && _.str.include(s, 'presto')) engine = 'presto' + if (browser === 'opera' && !ua.isIOS && gearbox.str.include(s, 'presto')) engine = 'presto' } // fix Windows Phone, IE Mobile and Edge if (browser === 'edge') { @@ -381,7 +342,7 @@ void function (window, _ext) { */ // util - // TODO: implement a stricter API: `_.str.formatVersion(ver, length)`, e.g. ('1.2', 3) -> '1.2.0' + // TODO: implement a stricter API: `gearbox.str.formatVersion(ver, length)`, e.g. ('1.2', 3) -> '1.2.0' function _trimVersion(ver, length) { var temp = ver.split('.') temp.length = length || 2 @@ -398,13 +359,13 @@ void function (window, _ext) { */ // exports - _ext.exports('ua', ua) + gearbox.__defineModule('ua', ua) -}(window, _ext) +}(window, gearbox) //////////////////// url //////////////////// -void function (window, _ext) { +void function (window, gearbox) { 'use strict' // namespace @@ -454,19 +415,19 @@ void function (window, _ext) { url.appendParam = function (url, param) { var s = '' url = _.isString(url) ? url : '' - url = _.url.removeHashFromUrl(url) - if (_.isPlainObject(param)) { + url = gearbox.url.removeHashFromUrl(url) + if (gearbox.isPlainObject(param)) { param = $.param(param) } else if (_.isString(param)) { // fix param string - if (_.str.startsWith(param, '&') || _.str.startsWith(param, '?')) { + if (gearbox.str.startsWith(param, '&') || gearbox.str.startsWith(param, '?')) { param = param.slice(1) } } else { param = null } // append - s = param ? url + (_.str.include(url, '?') ? '&' : '?') + param : s + s = param ? url + (gearbox.str.include(url, '?') ? '&' : '?') + param : s return s || false } @@ -481,17 +442,17 @@ void function (window, _ext) { } // aliases - url.isHash = _.str.isHash - url.stripHash = _.str.stripHash + url.isHash = gearbox.str.isHash + url.stripHash = gearbox.str.stripHash // exports - _ext.exports('url', url) + gearbox.__defineModule('url', url) -}(window, _ext) +}(window, gearbox) //////////////////// dom //////////////////// -void function (window, _ext) { +void function (window, gearbox) { 'use strict' // namespace @@ -516,18 +477,19 @@ void function (window, _ext) { } // exports - _ext.exports('dom', dom) + gearbox.__defineModule('dom', dom) -}(window, _ext) +}(window, gearbox) //////////////////// action //////////////////// // include and wrap external module: Action -void function (window, _ext) { +void function (window, gearbox) { 'use strict' /* ================= START: source code ================= */ +/* */ /** * Action - Easy and lazy solution for click-event-binding. * Released under the MIT license. @@ -650,19 +612,21 @@ var action = (function () { }()) +/* */ /* ================= END: source code ================= */ - _ext.exports('action', action) + gearbox.__defineModule('action', action) -}(window, _ext) +}(window, gearbox) //////////////////// template //////////////////// // include and wrap external module: Underscore-template -void function (window, _ext) { +void function (window, gearbox) { 'use strict' /* ================= START: source code ================= */ +/* */ /** * Underscore-template - More APIs for Underscore's template engine - template fetching, rendering and caching. * Released under the MIT license. @@ -833,11 +797,15 @@ var template = (function () { }()) +/* */ /* ================= END: source code ================= */ - _ext.exports('template', template) + gearbox.__defineModule('template', template) -}(window, _ext) +}(window, gearbox) +/* */ //////////////////// END: source code //////////////////// + window.gearbox = gearbox + }(window) \ No newline at end of file diff --git a/dist/gearbox.min.js b/dist/gearbox.min.js index ea2c1d7..9441831 100644 --- a/dist/gearbox.min.js +++ b/dist/gearbox.min.js @@ -1,2 +1,2 @@ /*! Gearbox | MIT | https://github.com/CMUI/gearbox */ -!function(t,e){"use strict";var r=t._,n=t.Zepto||t.jQuery||t.$;if(!r||!n)return!1;var i={},o=t.document;void function(t,e){e.exports=function(t,e){function n(t,e){i(t)?r.extend(r[t],e):r[t]=e}function i(t){return r[t]?!0:!1}t&&r.isString(t)&&e&&r.isObject(e)&&("root"===t?r.each(e,function(t,e){n(e,t)}):n(t,e))}}(t,i),void function(t,e){function n(t){return null==t?"":""+t}function i(t){return 0>t?0:+t||0}function o(t){return null==t?"\\s":t.source?t.source:"["+u.escapeRegExp(t)+"]"}var s=r.str||{};if(!s.VERSION||"function"!=typeof s.trim){var u=s,a=String.prototype.trim,c=String.prototype.trimRight,l=String.prototype.trimLeft;s.escapeRegExp=function(t){return null==t?"":n(t).replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")},s.trim=function(t,e){return null==t?"":!e&&a?a.call(t):(e=o(e),n(t).replace(new RegExp("^"+e+"+|"+e+"+$","g"),""))},s.ltrim=function(t,e){return null==t?"":!e&&l?l.call(t):(e=o(e),n(t).replace(new RegExp("^"+e+"+"),""))},s.rtrim=function(t,e){return null==t?"":!e&&c?c.call(t):(e=o(e),n(t).replace(new RegExp(e+"+$"),""))},s.include=function(t,e,r){return""===e?!0:(r=null==r?0:Math.min(i(r),t.length),-1!==n(t).slice(r).indexOf(e))},s.startsWith=function(t,e,r){return t=n(t),e=""+e,r=null==r?0:Math.min(i(r),t.length),t.lastIndexOf(e,r)===r},s.endsWith=function(t,e,r){return t=n(t),e=""+e,r="undefined"==typeof r?t.length-e.length:Math.min(i(r),t.length)-e.length,r>=0&&t.indexOf(e,r)===r},u.contains=u.include,e.exports("str",s)}}(t,i),void function(t,e){var n=r.str||{};n.CNY=n.RMB="¥",n.FULL_WIDTH_CNY=n.FULL_WIDTH_RMB="¥",n.RE_EMAIL=/^(?:[a-z\d]+[_\-\+\.]?)*[a-z\d]+@(?:([a-z\d]+\-?)*[a-z\d]+\.)+([a-z]{2,})+$/i,n.RE_MOBILE=/^1[34578]\d{9}$/,n.RE_POSTCODE=/^\d{6}$/,n.isHash=function(t){return t=r.str.trim(t),r.str.startsWith(t,"#")},n.stripHash=function(t){return t=r.str.trim(t),t=r.str.ltrim(t,"#"),r.str.startsWith(t,"!")&&(t=t.slice(1)),t},n.uniq=n.unique=function(t){if(!r.isArray(t))return!1;var e={};return r.each(t,function(t){e[String(t)]=null}),r.keys(e)},n.toFloat=function(t){return parseFloat(t)},n.toInt=function(t){var e=parseFloat(t);return 0>e?Math.ceil(e):Math.floor(e)},n.toFixed=function(t,e){return r.str.toFloat(r.str.toFloat(t).toFixed(e||0))},e.exports("str",n)}(t,i),void function(t,e){var i={$:function(t){var e;return e=r.isElement(t)?t.__$__=t.__$__||n(t):r.dom.is$Element(t)?t:n(t)},isPlainObject:n.isPlainObject};e.exports("root",i)}(t,i),void function(t,e){function n(t){var e=t.str.toLowerCase();if(t.isSafari=/\bapple\b/i.test(navigator.vendor)&&/\bsafari\b/i.test(e),t.isChrome=r.str.include(e,"chrome")||r.str.include(e,"crios"),t.osVersion="",t.isIOS=/\(i(?:phone|pod|pad)\b/.test(e)||/\bios \d+\./.test(e),t.isIOS)t.isIPad=/\(ipad\b/.test(e),t.isIPod=/\(ipod\b/.test(e),t.isIPhone=/\(iphone\b/.test(e),t.osVersion=(/[\/; i]os[\/: _](\d+(?:[\._]\d+)?)[\._; ]/.exec(e)||[0,""])[1].replace("_",".");else{var n=r.str.include(e,"android"),o=/\badr\b/.test(e)&&/\blinux;\s*u;/.test(e),s=/juc\s*\(linux;\s*u;\s*\d+\.\d+/.test(e);t.isAndroid=n||o||s,t.osVersion=o||s?(/\badr[\/: ]?(\d+\.\d)\d*\b/.exec(e)||/\blinux;\s*u;\s*(\d+\.\d)\d*\b/.exec(e)||[0,""])[1]:(/\bandroid(?:_os)?[\/: ]?(\d+\.\d)\d*\b/.exec(e)||[0,""])[1]}r.str.include(e,"windows phone")&&(t.isIOS=t.isAndroid=!1,t.osVersion=""),t.osVersion&&!r.str.include(t.osVersion,".")&&(t.osVersion+=".0"),t.isMobileDevice=!(!t.isIOS&&!t.isAndroid);var u="";r.str.include(e,"micromessenger")?u="wechat":r.str.include(e,"ucbrowser")||r.str.include(e,"ucweb")||r.str.include(e," uc applewebkit")?u="uc":r.str.include(e,"baiduhd")||r.str.include(e,"baiduboxapp")?u="baidu-app":r.str.include(e,"baidubrowser")?u="baidu-browser":r.str.include(e,"mqqbrowser")?u="m-qq-browser":r.str.include(e,"miuibrowser")?u="miui":r.str.include(e,"_weibo_")||r.str.include(e," weibo ")?u="weibo":r.str.include(e,"firefox")?u="firefox":r.str.include(e,"opera")?u="opera":r.str.include(e," edge/")?u="edge":r.str.include(e,"iemobile")?u="ie-mobile":t.isChrome?(u="chrome",t.isAndroid&&/\bwv\b/.test(e)&&(u="chrome-webview")):t.isSafari&&(u="safari"),"chrome"!==u&&(t.isChrome=!1),"safari"!==u&&(t.isSafari=!1);var a="",c="",l=/chrome[^\d]*([\.\d]*)[ ;\/]/.exec(e);if(l)a="chrome",c=i(l[1]);else{var d=/webkit[^\d]*([\.\d]*)\+*[ ;\/]/.exec(e);d&&(a="webkit",c=i(d[1]))}return a||(r.str.include(e,"webkit")?a="webkit":t.isIOS?a="webkit":t.isAndroid&&"m-qq-browser"===u&&(a="webkit"),"firefox"!==u||t.isIOS||(a="gecko"),"opera"===u&&!t.isIOS&&r.str.include(e,"presto")&&(a="presto")),"edge"===u?(a="edge",c=""):"ie-mobile"===u&&(a=c=""),t.browser=u,t.engine=a,t.engineVersion=c,t}function i(t,e){var n=t.split(".");return n.length=e||2,r.compact(n).join(".")}var o={};o.isTouchDevice="ontouchstart"in t&&"ontouchmove"in t&&"ontouchend"in t,o.str=navigator.userAgent,n(o),e.exports("ua",o)}(t,i),void function(t,e){function i(){return s.search.slice(1)}var o={},s=t.location;o.parseQuery=function(t){var e={};if(t&&r.isString(t)){var n,i,o,s=t.split("&");r.each(s,function(t){n=t.split("="),i=n[0],o=n[1]||"",i&&(e[decodeURIComponent(i).toLowerCase()]=decodeURIComponent(o))})}return e};var u,a=null;o.getParam=function(t){if(!t||!r.isString(t))return!1;if("undefined"==typeof u)u=i();else{var e=i();e!==u&&(a=null,u=e)}return a||(a=this.parseQuery(u)),a[t.toLowerCase()]},o.appendParam=function(t,e){var i="";return t=r.isString(t)?t:"",t=r.url.removeHashFromUrl(t),r.isPlainObject(e)?e=n.param(e):r.isString(e)?(r.str.startsWith(e,"&")||r.str.startsWith(e,"?"))&&(e=e.slice(1)):e=null,i=e?t+(r.str.include(t,"?")?"&":"?")+e:i,i||!1},o.removeHashFromUrl=function(t){return arguments.length?String(t).split("#")[0]:""},o.getHashFromUrl=function(t){var e=String(t).split("#");return e[0]="",e.join("#")},o.isHash=r.str.isHash,o.stripHash=r.str.stripHash,e.exports("url",o)}(t,i),void function(t,e){var i={};i.$win=n(t),i.$root=n(o.documentElement),i.$body=n(o.body),i.is$Element=function(t){if(!t||!r.isObject(t))return!1;var e=!1;if("__proto__"in t)e=t.__proto__===n.fn;else{var i=n.zepto&&n.zepto.Z||n;e=t instanceof i}return e},e.exports("dom",i)}(t,i),void function(t,e){var r=function(){function e(t){var e=t.attr("data-action")||"";if(!e){var i=n.trim(t.attr("href"));i&&0===i.indexOf("#")&&(e=i)}return r(e)}function r(t){return t?n.trim(String(t).replace(/^[#!\s]+/,"")):""}function i(){var t=n(o.body||o.documentElement);t.on("click",l,function(t){t.preventDefault();var r=n(this),i=e(r);s(i,this)})}function s(e,r){if(e){var i=d[e];return i&&n.isFunction(i)?i.call(r||t):void 0}}function u(t){n.isPlainObject(t)&&n.each(t,function(t,e){var i=r(t);i&&n.isFunction(e)&&(d[i]=e)})}function a(t,e){return s(r(t),e)}var c={},l="[data-action]",d={};return i(),c.add=u,c.trigger=a,c}();e.exports("action",r)}(t,i),void function(t,e){var n=function(){function t(t){return t.replace(/^\s+|\s+$/g,"")}function e(t,e){return t.length>e.length?0===t.indexOf(e):!1}function n(e){return e=e&&r.isString(e)?t(e).replace(/^[#!]+/,""):"",t(e).replace(l,"")}function i(n){return n=n&&r.isString(n)?t(n):"",e(n,l)?n:l+n}function s(e){if(!e)return!1;var r="",n=i(String(e)),s=o.getElementById(n);return s&&(r=t(s.innerHTML)),r}function u(t,e){var r=!1;if(arguments.length<2)return r;if(e){var i=n(t);f[i]&&(f[i]=null),d[i]=String(e),r=!0}return r}function a(t,e){var i="";if(arguments.length<2)return i;var o=n(t),u=f[o],a=d[o];return r.isFunction(u)?i=u(e):a?(u=r.template(a),f[o]=u,i=u(e),d[o]=null):(a=s(o),a&&(u=r.template(a),f[o]=u,i=u(e))),i||""}var c={},l="template-",d={},f={};return c.add=u,c.render=a,c}();e.exports("template",n)}(t,i)}(window); \ No newline at end of file +!function(e,t){if(e.gearbox)return!1;var n=e._,r=e.Zepto||e.jQuery||e.$;if(!n||!r)return!1;var i={},o=e.document;void function(e,t){"use strict";t.__defineModule=function(e,r){e&&n.isString(e)&&r&&n.isObject(r)&&("root"===e?n.each(r,function(e,n){t[n]=e}):t[e]=r)}}(e,i),void function(e,t){"use strict";function r(e){return null==e?"":""+e}function i(e){return 0>e?0:+e||0}function o(e){return null==e?"\\s":e.source?e.source:"["+s.escapeRegExp(e)+"]"}var s={},u=String.prototype.trim,a=String.prototype.trimRight,c=String.prototype.trimLeft;s.escapeRegExp=function(e){return null==e?"":r(e).replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")},s.trim=function(e,t){return null==e?"":!t&&u?u.call(e):(t=o(t),r(e).replace(new RegExp("^"+t+"+|"+t+"+$","g"),""))},s.ltrim=function(e,t){return null==e?"":!t&&c?c.call(e):(t=o(t),r(e).replace(new RegExp("^"+t+"+"),""))},s.rtrim=function(e,t){return null==e?"":!t&&a?a.call(e):(t=o(t),r(e).replace(new RegExp(t+"+$"),""))},s.include=function(e,t,n){return""===t?!0:(n=null==n?0:Math.min(i(n),e.length),-1!==r(e).slice(n).indexOf(t))},s.startsWith=function(e,t,n){return e=r(e),t=""+t,n=null==n?0:Math.min(i(n),e.length),e.lastIndexOf(t,n)===n},s.endsWith=function(e,t,n){return e=r(e),t=""+t,n="undefined"==typeof n?e.length-t.length:Math.min(i(n),e.length)-t.length,n>=0&&e.indexOf(t,n)===n},s.contains=s.include,s.includes=s.include,s.CNY=s.RMB="¥",s.FULL_WIDTH_CNY=s.FULL_WIDTH_RMB="¥",s.RE_EMAIL=/^(?:[a-z\d]+[_\-\+\.]?)*[a-z\d]+@(?:([a-z\d]+\-?)*[a-z\d]+\.)+([a-z]{2,})+$/i,s.RE_MOBILE=/^1[34578]\d{9}$/,s.RE_POSTCODE=/^\d{6}$/,s.isHash=function(e){return e=t.str.trim(e),t.str.startsWith(e,"#")},s.stripHash=function(e){return e=t.str.trim(e),e=t.str.ltrim(e,"#"),t.str.startsWith(e,"!")&&(e=e.slice(1)),e},s.uniq=s.unique=function(e){if(!n.isArray(e))return!1;var t={};return n.each(e,function(e){t[String(e)]=null}),n.keys(t)},s.toFloat=function(e){return parseFloat(e)},s.toInt=function(e){var t=parseFloat(e);return 0>t?Math.ceil(t):Math.floor(t)},s.toFixed=function(e,n){return t.str.toFloat(t.str.toFloat(e).toFixed(n||0))},t.__defineModule("str",s)}(e,i),void function(e,t){"use strict";var i={$:function(e){var i;return i=n.isElement(e)?e.__$__=e.__$__||r(e):t.dom.is$Element(e)?e:r(e)},isPlainObject:r.isPlainObject};t.__defineModule("root",i)}(e,i),void function(e,t){"use strict";function r(e){var n=e.str.toLowerCase();if(e.isSafari=/\bapple\b/i.test(navigator.vendor)&&/\bsafari\b/i.test(n),e.isChrome=t.str.include(n,"chrome")||t.str.include(n,"crios"),e.osVersion="",e.isIOS=/\(i(?:phone|pod|pad)\b/.test(n)||/\bios \d+\./.test(n),e.isIOS)e.isIPad=/\(ipad\b/.test(n),e.isIPod=/\(ipod\b/.test(n),e.isIPhone=/\(iphone\b/.test(n),e.osVersion=(/[\/; i]os[\/: _](\d+(?:[\._]\d+)?)[\._; ]/.exec(n)||[0,""])[1].replace("_",".");else{var r=t.str.include(n,"android"),o=/\badr\b/.test(n)&&/\blinux;\s*u;/.test(n),s=/juc\s*\(linux;\s*u;\s*\d+\.\d+/.test(n);e.isAndroid=r||o||s,e.osVersion=o||s?(/\badr[\/: ]?(\d+\.\d)\d*\b/.exec(n)||/\blinux;\s*u;\s*(\d+\.\d)\d*\b/.exec(n)||[0,""])[1]:(/\bandroid(?:_os)?[\/: ]?(\d+\.\d)\d*\b/.exec(n)||[0,""])[1]}t.str.include(n,"windows phone")&&(e.isIOS=e.isAndroid=!1,e.osVersion=""),e.osVersion&&!t.str.include(e.osVersion,".")&&(e.osVersion+=".0"),e.isMobileDevice=!(!e.isIOS&&!e.isAndroid);var u="";t.str.include(n,"micromessenger")?u="wechat":t.str.include(n,"ucbrowser")||t.str.include(n,"ucweb")||t.str.include(n," uc applewebkit")?u="uc":t.str.include(n,"baiduhd")||t.str.include(n,"baiduboxapp")?u="baidu-app":t.str.include(n,"baidubrowser")?u="baidu-browser":t.str.include(n,"mqqbrowser")?u="m-qq-browser":t.str.include(n,"miuibrowser")?u="miui":t.str.include(n,"_weibo_")||t.str.include(n," weibo ")?u="weibo":t.str.include(n,"firefox")?u="firefox":t.str.include(n,"opera")?u="opera":t.str.include(n," edge/")?u="edge":t.str.include(n,"iemobile")?u="ie-mobile":e.isChrome?(u="chrome",e.isAndroid&&/\bwv\b/.test(n)&&(u="chrome-webview")):e.isSafari&&(u="safari"),"chrome"!==u&&(e.isChrome=!1),"safari"!==u&&(e.isSafari=!1);var a="",c="",l=/chrome[^\d]*([\.\d]*)[ ;\/]/.exec(n);if(l)a="chrome",c=i(l[1]);else{var d=/webkit[^\d]*([\.\d]*)\+*[ ;\/]/.exec(n);d&&(a="webkit",c=i(d[1]))}return a||(t.str.include(n,"webkit")?a="webkit":e.isIOS?a="webkit":e.isAndroid&&"m-qq-browser"===u&&(a="webkit"),"firefox"!==u||e.isIOS||(a="gecko"),"opera"===u&&!e.isIOS&&t.str.include(n,"presto")&&(a="presto")),"edge"===u?(a="edge",c=""):"ie-mobile"===u&&(a=c=""),e.browser=u,e.engine=a,e.engineVersion=c,e}function i(e,t){var r=e.split(".");return r.length=t||2,n.compact(r).join(".")}var o={};o.isTouchDevice="ontouchstart"in e&&"ontouchmove"in e&&"ontouchend"in e,o.str=navigator.userAgent,r(o),t.__defineModule("ua",o)}(e,i),void function(e,t){"use strict";function i(){return s.search.slice(1)}var o={},s=e.location;o.parseQuery=function(e){var t={};if(e&&n.isString(e)){var r,i,o,s=e.split("&");n.each(s,function(e){r=e.split("="),i=r[0],o=r[1]||"",i&&(t[decodeURIComponent(i).toLowerCase()]=decodeURIComponent(o))})}return t};var u,a=null;o.getParam=function(e){if(!e||!n.isString(e))return!1;if("undefined"==typeof u)u=i();else{var t=i();t!==u&&(a=null,u=t)}return a||(a=this.parseQuery(u)),a[e.toLowerCase()]},o.appendParam=function(e,i){var o="";return e=n.isString(e)?e:"",e=t.url.removeHashFromUrl(e),t.isPlainObject(i)?i=r.param(i):n.isString(i)?(t.str.startsWith(i,"&")||t.str.startsWith(i,"?"))&&(i=i.slice(1)):i=null,o=i?e+(t.str.include(e,"?")?"&":"?")+i:o,o||!1},o.removeHashFromUrl=function(e){return arguments.length?String(e).split("#")[0]:""},o.getHashFromUrl=function(e){var t=String(e).split("#");return t[0]="",t.join("#")},o.isHash=t.str.isHash,o.stripHash=t.str.stripHash,t.__defineModule("url",o)}(e,i),void function(e,t){"use strict";var i={};i.$win=r(e),i.$root=r(o.documentElement),i.$body=r(o.body),i.is$Element=function(e){if(!e||!n.isObject(e))return!1;var t=!1;if("__proto__"in e)t=e.__proto__===r.fn;else{var i=r.zepto&&r.zepto.Z||r;t=e instanceof i}return t},t.__defineModule("dom",i)}(e,i),void function(e,t){"use strict";var n=function(){function t(e){var t=e.attr("data-action")||"";if(!t){var i=r.trim(e.attr("href"));i&&0===i.indexOf("#")&&(t=i)}return n(t)}function n(e){return e?r.trim(String(e).replace(/^[#!\s]+/,"")):""}function i(){var e=r(o.body||o.documentElement);e.on("click",l,function(e){e.preventDefault();var n=r(this),i=t(n);s(i,this)})}function s(t,n){if(t){var i=d[t];return i&&r.isFunction(i)?i.call(n||e):void 0}}function u(e){r.isPlainObject(e)&&r.each(e,function(e,t){var i=n(e);i&&r.isFunction(t)&&(d[i]=t)})}function a(e,t){return s(n(e),t)}var c={},l="[data-action]",d={};return i(),c.add=u,c.trigger=a,c}();t.__defineModule("action",n)}(e,i),void function(e,t){"use strict";var r=function(){function e(e){return e.replace(/^\s+|\s+$/g,"")}function t(e,t){return e.length>t.length?0===e.indexOf(t):!1}function r(t){return t=t&&n.isString(t)?e(t).replace(/^[#!]+/,""):"",e(t).replace(l,"")}function i(r){return r=r&&n.isString(r)?e(r):"",t(r,l)?r:l+r}function s(t){if(!t)return!1;var n="",r=i(String(t)),s=o.getElementById(r);return s&&(n=e(s.innerHTML)),n}function u(e,t){var n=!1;if(arguments.length<2)return n;if(t){var i=r(e);f[i]&&(f[i]=null),d[i]=String(t),n=!0}return n}function a(e,t){var i="";if(arguments.length<2)return i;var o=r(e),u=f[o],a=d[o];return n.isFunction(u)?i=u(t):a?(u=n.template(a),f[o]=u,i=u(t),d[o]=null):(a=s(o),a&&(u=n.template(a),f[o]=u,i=u(t))),i||""}var c={},l="template-",d={},f={};return c.add=u,c.render=a,c}();t.__defineModule("template",r)}(e,i),e.gearbox=i}(window); \ No newline at end of file diff --git a/package.json b/package.json index 49ac42a..50d877e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cmui-gearbox", - "version": "0.5.2", + "version": "0.6.0-rc.1", "homepage": "https://github.com/CMUI/gearbox", "author": "cssmagic ", "description": "Lightweight JavaScript utilities for web development.",