From d7c2ab66b218cea6894838f3e863f45922cdd15d Mon Sep 17 00:00:00 2001 From: surunzi Date: Sun, 13 Mar 2016 23:11:40 +0800 Subject: [PATCH] Dev: Features, resources, info tools --- dist/eruda.js | 552 ++++++++++++++++++++++++++++------- eustia/loadJs.js | 10 +- eustia/orientation.js | 14 + src/Console/Log.es6 | 12 +- src/Console/Log.scss | 4 +- src/Console/cmdList.json | 1 + src/Console/libraries.json | 3 +- src/DevTools/DevTools.scss | 2 +- src/DevTools/HomeBtn.es6 | 10 +- src/DevTools/NavBar.scss | 2 +- src/Features/Features.hbs | 9 +- src/Features/Features.scss | 44 ++- src/Info/Info.scss | 12 +- src/Resources/Resources.es6 | 153 +++++++++- src/Resources/Resources.hbs | 75 ++++- src/Resources/Resources.scss | 66 ++++- src/color.scss | 5 +- src/index.es6 | 2 +- src/util.js | 151 +++++++++- test/index.html | 8 +- test/style.css | 3 + 21 files changed, 976 insertions(+), 162 deletions(-) create mode 100644 eustia/orientation.js create mode 100644 test/style.css diff --git a/dist/eruda.js b/dist/eruda.js index 29b94df..fe8e6f6 100644 --- a/dist/eruda.js +++ b/dist/eruda.js @@ -63,31 +63,31 @@ var eruda = var _Console2 = _interopRequireDefault(_Console); - var _Network = __webpack_require__(50); + var _Network = __webpack_require__(51); var _Network2 = _interopRequireDefault(_Network); - var _Elements = __webpack_require__(51); + var _Elements = __webpack_require__(52); var _Elements2 = _interopRequireDefault(_Elements); - var _Sinppets = __webpack_require__(52); + var _Sinppets = __webpack_require__(53); var _Sinppets2 = _interopRequireDefault(_Sinppets); - var _Resources = __webpack_require__(53); + var _Resources = __webpack_require__(54); var _Resources2 = _interopRequireDefault(_Resources); - var _Info = __webpack_require__(57); + var _Info = __webpack_require__(58); var _Info2 = _interopRequireDefault(_Info); - var _Features = __webpack_require__(62); + var _Features = __webpack_require__(63); var _Features2 = _interopRequireDefault(_Features); - var _Settings = __webpack_require__(68); + var _Settings = __webpack_require__(69); var _Settings2 = _interopRequireDefault(_Settings); @@ -97,7 +97,7 @@ var eruda = function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - __webpack_require__(69); + __webpack_require__(70); var $container; @@ -114,7 +114,7 @@ var eruda = return devTools.toggle(); }); - devTools.add(new _Console2.default()).add(new _Network2.default()).add(new _Elements2.default()).add(new _Sinppets2.default()).add(new _Resources2.default()).add(new _Info2.default()).add(new _Features2.default()).add(new _Settings2.default()).showTool('console').show(); + devTools.add(new _Console2.default()).add(new _Network2.default()).add(new _Elements2.default()).add(new _Sinppets2.default()).add(new _Resources2.default()).add(new _Info2.default()).add(new _Features2.default()).add(new _Settings2.default()).showTool('resources').show(); } function appendContainer() { @@ -197,11 +197,9 @@ var eruda = return _this.emit('click'); }); - window.addEventListener('orientationchange', function () { - setTimeout(function () { - _this._setPos(); - }, 150); - }, false); + _util2.default.orientation.on('change', function () { + return _this._setPos(); + }); } }, { key: '_makeDraggable', @@ -616,6 +614,96 @@ var eruda = return isNum; })(); + /* ------------------------------ cookie ------------------------------ */ + + var cookie; + + _.cookie = (function () + { + // TODO + + /* module + * cookie: Simple api for handling browser cookies. + */ + + var defOpts = { path: '/' }; + + function setCookie(key, val, options) + { + if (arguments.length > 1) + { + options = extend(defOpts, options); + + if (isNum(options.expires)) + { + var expires = new Date(); + expires.setMilliseconds(expires.getMilliseconds() + options.expires * 864e+5); + options.expires = expires; + } + + val = encodeURIComponent(String(val)); + key = encodeURIComponent(key); + + document.cookie = [ + key, '=', val, + options.expires && '; expires=' + options.expires.toUTCString(), + options.path && '; path=' + options.path, + options.domain && '; domain=' + options.domain, + options.secure ? '; secure' : '' + ].join(''); + + return cookie; + } + + var cookies = document.cookie ? document.cookie.split('; ') : [], + result = key ? undefined : {}; + + for (var i = 0, len = cookies.length; i < len; i++) + { + var c = cookies[i], + parts = c.split('='), + name = decodeURIComponent(parts.shift()); + + c = parts.join('='); + c = decodeURIComponent(c); + + if (key === name) + { + result = c; + break; + } + + if (!key) result[name] = c; + } + + return result; + } + + cookie = { + /* member + * cookie.get: Read cookie. + * key(string): The cookie name. + * return(string): Returns cookie value if exists, eles undefined. + */ + get: setCookie, + /* member + * cookie.set: Set cookie. + * key(string): The cookie name. + * val(string): The cookie value. + * options(Object): Options. + */ + set: setCookie, + remove: function (key, options) + { + options = options || {}; + options.expires = -1; + return setCookie(key, '', options); + } + }; + + return cookie; + })(); + /* ------------------------------ isArrLike ------------------------------ */ var isArrLike; @@ -823,10 +911,18 @@ var eruda = _.loadJs = (function () { - loadJs = function (url) + loadJs = function (url, cb) { var script = document.createElement('script'); script.src = url; + script.onload = function () + { + var isNotLoaded = script.readyState && + script.readyState != "complete" && + script.readyState != "loaded"; + + cb && cb(!isNotLoaded); + }; document.body.appendChild(script); }; @@ -2020,6 +2116,28 @@ var eruda = return $; })(); + /* ------------------------------ orientation ------------------------------ */ + + var orientation; + + _.orientation = (function () + { + + orientation = {}; + + Emitter.mixin(orientation); + + window.addEventListener('orientationchange', function () + { + setTimeout(function () + { + orientation.emit('change'); + }, 150); + }, false); + + return orientation; + })(); + /* ------------------------------ rtrim ------------------------------ */ var rtrim; @@ -2102,6 +2220,35 @@ var eruda = return trim; })(); + /* ------------------------------ unique ------------------------------ */ + + var unique; + + _.unique = (function () + { + + function isEqual(a, b) { return a === b } + + unique = function (arr, compare) + { + compare = compare || isEqual; + + return filter(arr, function (item, idx, arr) + { + var len = arr.length; + + while (++idx < len) + { + if (compare(item, arr[idx])) return false; + } + + return true; + }); + }; + + return unique; + })(); + return _; })(); @@ -5281,7 +5428,7 @@ var eruda = // module - exports.push([module.id, "#eruda .dev-tools .nav-bar {\n height: 50px;\n overflow-y: scroll;\n position: absolute;\n width: 100%;\n left: 0;\n top: 0;\n z-index: 100;\n background: #76a2ee; }\n #eruda .dev-tools .nav-bar ul {\n font-size: 0; }\n #eruda .dev-tools .nav-bar ul li {\n display: inline-block;\n height: 50px;\n line-height: 50px;\n width: 69px;\n color: #f2f2f2;\n font-size: 12px;\n text-align: center;\n opacity: 0.5;\n text-transform: capitalize; }\n #eruda .dev-tools .nav-bar ul li.active {\n color: #fff;\n opacity: 1;\n border-bottom: 3px solid #fff; }\n", ""]); + exports.push([module.id, "#eruda .dev-tools .nav-bar {\n height: 50px;\n overflow-y: auto;\n position: absolute;\n width: 100%;\n left: 0;\n top: 0;\n z-index: 100;\n background: #76a2ee; }\n #eruda .dev-tools .nav-bar ul {\n font-size: 0; }\n #eruda .dev-tools .nav-bar ul li {\n display: inline-block;\n height: 50px;\n line-height: 50px;\n width: 69px;\n color: #f2f2f2;\n font-size: 12px;\n text-align: center;\n opacity: 0.5;\n text-transform: capitalize; }\n #eruda .dev-tools .nav-bar ul li.active {\n color: #fff;\n opacity: 1;\n border-bottom: 3px solid #fff; }\n", ""]); // exports @@ -5321,7 +5468,7 @@ var eruda = // module - exports.push([module.id, "#eruda .dev-tools {\n position: absolute;\n width: 100%;\n height: 100%;\n padding-top: 50px;\n background: #fff;\n z-index: 500;\n display: none; }\n #eruda .dev-tools.show {\n display: block;\n -webkit-animation: show-menu .3s linear both;\n animation: show-menu .3s linear both; }\n #eruda .dev-tools.hide {\n display: block;\n -webkit-animation: hide-menu .3s linear both;\n animation: hide-menu .3s linear both; }\n #eruda .dev-tools .tools {\n height: 100%;\n width: 100%;\n position: relative;\n overflow: scroll; }\n #eruda .dev-tools .tools .tool {\n position: absolute;\n left: 0;\n top: 0;\n background: #f2f2f2;\n width: 100%;\n height: 100%; }\n\n@-webkit-keyframes show-menu {\n 0% {\n opacity: 0; }\n 100% {\n opacity: 1; } }\n\n@keyframes show-menu {\n 0% {\n opacity: 0; }\n 100% {\n opacity: 1; } }\n\n@-webkit-keyframes hide-menu {\n 0% {\n opacity: 1; }\n 100% {\n opacity: 0; } }\n\n@keyframes hide-menu {\n 0% {\n opacity: 1; }\n 100% {\n opacity: 0; } }\n", ""]); + exports.push([module.id, "#eruda .dev-tools {\n position: absolute;\n width: 100%;\n height: 100%;\n padding-top: 50px;\n background: #fff;\n z-index: 500;\n display: none; }\n #eruda .dev-tools.show {\n display: block;\n -webkit-animation: show-menu .3s linear both;\n animation: show-menu .3s linear both; }\n #eruda .dev-tools.hide {\n display: block;\n -webkit-animation: hide-menu .3s linear both;\n animation: hide-menu .3s linear both; }\n #eruda .dev-tools .tools {\n height: 100%;\n width: 100%;\n position: relative;\n overflow: auto; }\n #eruda .dev-tools .tools .tool {\n position: absolute;\n left: 0;\n top: 0;\n background: #f2f2f2;\n width: 100%;\n height: 100%; }\n\n@-webkit-keyframes show-menu {\n 0% {\n opacity: 0; }\n 100% {\n opacity: 1; } }\n\n@keyframes show-menu {\n 0% {\n opacity: 0; }\n 100% {\n opacity: 1; } }\n\n@-webkit-keyframes hide-menu {\n 0% {\n opacity: 1; }\n 100% {\n opacity: 0; } }\n\n@keyframes hide-menu {\n 0% {\n opacity: 1; }\n 100% {\n opacity: 0; } }\n", ""]); // exports @@ -5353,7 +5500,7 @@ var eruda = var _Log2 = _interopRequireDefault(_Log); - var _Tool2 = __webpack_require__(46); + var _Tool2 = __webpack_require__(47); var _Tool3 = _interopRequireDefault(_Tool2); @@ -5369,7 +5516,7 @@ var eruda = function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - __webpack_require__(47); + __webpack_require__(48); var Console = function (_Tool) { _inherits(Console, _Tool); @@ -5397,7 +5544,7 @@ var eruda = value: function _appendTpl() { var $el = this._$el; - $el.append(__webpack_require__(49)()); + $el.append(__webpack_require__(50)()); this._$logs = $el.find('.logs'); this._$jsInput = $el.find('.js-input'); } @@ -5461,7 +5608,7 @@ var eruda = commands: cmdList }); - var libraries = __webpack_require__(71); + var libraries = __webpack_require__(45); var regJsUrl = /https?:\/\/([0-9.\-A-Za-z]+)(?::(\d+))?\/[A-Za-z0-9/]*\.js/g; @@ -5502,7 +5649,7 @@ var eruda = this._$el = $el; this._logs = []; - this._tpl = __webpack_require__(45); + this._tpl = __webpack_require__(46); this._filter = 'all'; } @@ -5662,11 +5809,24 @@ var eruda = case 'h': return this.help(); case '$': - return _util2.default.loadJs(libraries['jQuery']); + return this._loadJs('jQuery'); + case '_': + return this._loadJs('underscore'); default: this.warn('Unknown command').help(); } } + }, { + key: '_loadJs', + value: function _loadJs(name) { + var _this = this; + + _util2.default.loadJs(libraries[name], function (result) { + if (result) return _this.log(name + ' is loaded'); + + _this.warn('Failed to load ' + name); + }); + } }, { key: '_render', value: function _render() { @@ -5742,7 +5902,7 @@ var eruda = // module - exports.push([module.id, "#eruda .dev-tools .tools .console .logs {\n height: 100%;\n overflow-x: hidden;\n overflow-y: scroll;\n font-size: 14px; }\n #eruda .dev-tools .tools .console .logs li {\n padding: 10px;\n overflow-x: scroll; }\n #eruda .dev-tools .tools .console .logs li.log, #eruda .dev-tools .tools .console .logs li.output {\n border-bottom: 1px solid #b4b4b4; }\n #eruda .dev-tools .tools .console .logs li.log table {\n width: 100%;\n background: #fff;\n border-collapse: collapse; }\n #eruda .dev-tools .tools .console .logs li.log table th {\n background: #76a2ee;\n color: #fff; }\n #eruda .dev-tools .tools .console .logs li.log table th, #eruda .dev-tools .tools .console .logs li.log table td {\n padding: 10px; }\n #eruda .dev-tools .tools .console .logs li.error {\n background: #fff0f0;\n color: #ff0000;\n border-top: 1px solid #ffd7d7;\n border-bottom: 1px solid #ffd7d7; }\n #eruda .dev-tools .tools .console .logs li.error .stack {\n color: #000;\n padding-left: 1.2em; }\n #eruda .dev-tools .tools .console .logs li.warn {\n background: #fffbe6;\n border-top: 1px solid #fff5c2;\n border-bottom: 1px solid #fff5c2; }\n", ""]); + exports.push([module.id, "#eruda .dev-tools .tools .console .logs {\n height: 100%;\n overflow-x: hidden;\n overflow-y: auto;\n font-size: 14px; }\n #eruda .dev-tools .tools .console .logs li {\n padding: 10px;\n overflow-x: auto; }\n #eruda .dev-tools .tools .console .logs li.log, #eruda .dev-tools .tools .console .logs li.output {\n border-bottom: 1px solid #b4b4b4; }\n #eruda .dev-tools .tools .console .logs li.log table {\n width: 100%;\n background: #fff;\n border-collapse: collapse; }\n #eruda .dev-tools .tools .console .logs li.log table th {\n background: #76a2ee;\n color: #fff; }\n #eruda .dev-tools .tools .console .logs li.log table th, #eruda .dev-tools .tools .console .logs li.log table td {\n padding: 10px; }\n #eruda .dev-tools .tools .console .logs li.error {\n background: #fff0f0;\n color: #ff0000;\n border-top: 1px solid #ffd7d7;\n border-bottom: 1px solid #ffd7d7; }\n #eruda .dev-tools .tools .console .logs li.error .stack {\n color: #000;\n padding-left: 1.2em; }\n #eruda .dev-tools .tools .console .logs li.warn {\n background: #fffbe6;\n border-top: 1px solid #fff5c2;\n border-bottom: 1px solid #fff5c2; }\n", ""]); // exports @@ -5759,6 +5919,7 @@ var eruda = ":l": "Show normal logs only", ":h": "Show help", ":$": "Load jQuery", + ":_": "Load underscore", "/regexp": "Show logs that match given regexp" }; @@ -5785,6 +5946,15 @@ var eruda = /***/ }, /* 45 */ +/***/ function(module, exports) { + + module.exports = { + "jQuery": "//cdn.bootcss.com/jquery/2.2.1/jquery.js", + "underscore": "//cdn.bootcss.com/underscore.js/1.8.3/underscore-min.js" + }; + +/***/ }, +/* 46 */ /***/ function(module, exports, __webpack_require__) { var Handlebars = __webpack_require__(13); @@ -5805,7 +5975,7 @@ var eruda = },"useData":true}); /***/ }, -/* 46 */ +/* 47 */ /***/ function(module, exports) { "use strict"; @@ -5846,13 +6016,13 @@ var eruda = exports.default = Tool; /***/ }, -/* 47 */ +/* 48 */ /***/ function(module, exports, __webpack_require__) { // style-loader: Adds some css to the DOM by adding a + + + \ No newline at end of file diff --git a/test/style.css b/test/style.css new file mode 100644 index 0000000..1e46d93 --- /dev/null +++ b/test/style.css @@ -0,0 +1,3 @@ +body { + background: #b4bad2; +} \ No newline at end of file