From 5970181e830a3723d99e6893f5c97b8d290cf27a Mon Sep 17 00:00:00 2001 From: Maiz Date: Wed, 29 Jun 2016 17:41:00 +0800 Subject: [PATCH 1/6] export `tool` and `$` to public --- dist/vconsole.min.js | 4 ++-- src/core/core.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/vconsole.min.js b/dist/vconsole.min.js index 39bde160..8d62fc1b 100644 --- a/dist/vconsole.min.js +++ b/dist/vconsole.min.js @@ -3,5 +3,5 @@ * Copyright 2016, WechatFE Team * MIT license */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.vConsole=t():e.vConsole=t()}(this,function(){return function(e){function t(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return e[n].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var r=o(1),i=n(r),l=o(13),c=n(l),a=o(14),s=n(a),d=o(21),u=n(d),f=o(23),v=n(f),p=new i["default"];p.addPlugin(s["default"]),p.addPlugin(u["default"]),p.addPlugin(v["default"]),p.VConsolePlugin=c["default"],t["default"]=p,e.exports=t["default"]},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t["default"]=e,t}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var l=function(){function e(e,t){for(var o=0;o0){var n=o.touches[0].pageX-e.switchPos.startX,r=o.touches[0].pageY-e.switchPos.startY,i=e.switchPos.x-n,l=e.switchPos.y-r;0>i&&(i=0),0>l&&(l=0),i+t.offsetWidth>document.body.offsetWidth&&(i=document.body.offsetWidth-t.offsetWidth),l+t.offsetHeight>document.body.offsetHeight&&(l=document.body.offsetHeight-t.offsetHeight),t.style.right=i+"px",t.style.bottom=l+"px",e.switchPos.endX=i,e.switchPos.endY=l,o.preventDefault()}}),d["default"].bind(d["default"].one(".vc-switch",e.$dom),"click",function(){e.show()}),d["default"].bind(d["default"].one(".vc-hide",e.$dom),"click",function(){e.hide()}),d["default"].bind(d["default"].one(".vc-mask",e.$dom),"click",function(t){return t.target!=d["default"].one(".vc-mask")?!1:void e.hide()}),d["default"].delegate(d["default"].one(".vc-tabbar",e.$dom),"click",".vc-tab",function(t){var o=this.dataset.tab;o!=e.activedTab&&e.showTab(o)})}},{key:"_autoRun",value:function(){this.isReady=!0;for(var e in this.pluginList)this._initPlugin(this.pluginList[e]);this.showTab(this.tabList[0])}},{key:"_initPlugin",value:function(e){var t=this;e.trigger("init"),e.trigger("renderTab",function(o){t.tabList.push(e.id);var n=d["default"].render(p["default"],{id:e.id,name:e.name});d["default"].one(".vc-tabbar",t.$dom).appendChild(n);var r=d["default"].render(g["default"],{id:e.id});o&&(a.isString(o)?r.innerHTML+=o:a.isFunction(o.appendTo)?o.appendTo(r):a.isElement(o)&&r.appendChild(o)),d["default"].one(".vc-content",t.$dom).appendChild(r)}),e.trigger("addTool",function(t){if(t)for(var o=d["default"].one(".vc-tool-last"),n=0;n0?new Date(e):new Date,o=t.getDate()<10?"0"+t.getDate():t.getDate(),n=t.getMonth()<9?"0"+(t.getMonth()+1):t.getMonth()+1,r=t.getFullYear(),i=t.getHours()<10?"0"+t.getHours():t.getHours(),l=t.getMinutes()<10?"0"+t.getMinutes():t.getMinutes(),c=t.getSeconds()<10?"0"+t.getSeconds():t.getSeconds(),a=t.getMilliseconds()<10?"0"+t.getMilliseconds():t.getMilliseconds();return 100>a&&(a="0"+a),{time:+t,year:r,month:n,day:o,hour:i,minute:l,second:c,millisecond:a}}function n(e){return"[object Number]"==Object.prototype.toString.call(e)}function r(e){return"[object String]"==Object.prototype.toString.call(e)}function i(e){return"[object Array]"==Object.prototype.toString.call(e)}function l(e){return"[object Boolean]"==Object.prototype.toString.call(e)}function c(e){return"[object Undefined]"==Object.prototype.toString.call(e)}function a(e){return"[object Null]"==Object.prototype.toString.call(e)}function s(e){return"[object Symbol]"==Object.prototype.toString.call(e)}function d(e){return!("[object Object]"!=Object.prototype.toString.call(e)&&(n(e)||r(e)||l(e)||i(e)||a(e)||u(e)||c(e)||s(e)))}function u(e){return"[object Function]"==Object.prototype.toString.call(e)}function f(e){return"object"===("undefined"==typeof HTMLElement?"undefined":h(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":h(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName}function v(e){return document.createElement("a").appendChild(document.createTextNode(e)).parentNode.innerHTML}function p(e){function t(e){for(var t=p.length-1;t>=0;t--)if(p[t].child==e)return!0;return!1}function o(e){if(d(e)){if(t(e))return void(f+="CircularObject");p.push({parent:parent,child:e});var b=Object.keys(e);f+="{",v++;for(var g=0;g0&&(n=Array.prototype.slice.call(o)),n},c.addClass=function(e,t){if(e){(0,r.isArray)(e)||(e=[e]);for(var o=0;o=0&&m.splice(t,1)}function c(e){var t=document.createElement("style");return t.type="text/css",i(e,t),t}function a(e){var t=document.createElement("link");return t.rel="stylesheet",i(e,t),t}function s(e,t){var o,n,r;if(t.singleton){var i=y++;o=h||(h=c(t)),n=d.bind(null,o,i,!1),r=d.bind(null,o,i,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(o=a(t),n=f.bind(null,o),r=function(){l(o),o.href&&URL.revokeObjectURL(o.href)}):(o=c(t),n=u.bind(null,o),r=function(){l(o)});return n(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;n(e=t)}else r()}}function d(e,t,o,n){var r=o?"":n.css;if(e.styleSheet)e.styleSheet.cssText=_(t,r);else{var i=document.createTextNode(r),l=e.childNodes;l[t]&&e.removeChild(l[t]),l.length?e.insertBefore(i,l[t]):e.appendChild(i)}}function u(e,t){var o=t.css,n=t.media;if(n&&e.setAttribute("media",n),e.styleSheet)e.styleSheet.cssText=o;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(o))}}function f(e,t){var o=t.css,n=t.sourceMap;n&&(o+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(n))))+" */");var r=new Blob([o],{type:"text/css"}),i=e.href;e.href=URL.createObjectURL(r),i&&URL.revokeObjectURL(i)}var v={},p=function(e){var t;return function(){return"undefined"==typeof t&&(t=e.apply(this,arguments)),t}},b=p(function(){return/msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase())}),g=p(function(){return document.head||document.getElementsByTagName("head")[0]}),h=null,y=0,m=[];e.exports=function(e,t){t=t||{},"undefined"==typeof t.singleton&&(t.singleton=b()),"undefined"==typeof t.insertAt&&(t.insertAt="bottom");var o=r(e);return n(o,t),function(e){for(var i=[],l=0;l
vConsole
'},function(e,t){e.exports="{{name}}"},function(e,t){e.exports="
"},function(e,t){e.exports='{{name}}'},function(e,t){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var o=0;on;n++)o[n]=arguments[n];var r=_possibleConstructorReturn(this,(e=Object.getPrototypeOf(VConsoleDefaultTab)).call.apply(e,[this].concat(o)));return r.tplTabbox=_tabbox_default2["default"],r.windowOnError=null,r}return _inherits(VConsoleDefaultTab,_VConsoleLogTab),_createClass(VConsoleDefaultTab,[{key:"onReady",value:function(){var e=this;_get(Object.getPrototypeOf(VConsoleDefaultTab.prototype),"onReady",this).call(this),_query2["default"].bind(_query2["default"].one(".vc-cmd",this.$tabbox),"submit",function(t){t.preventDefault();var o=_query2["default"].one(".vc-cmd-input",t.target),n=o.value;o.value="",""!==n&&e.evalCommand(n)})}},{key:"mockConsole",value:function(){_get(Object.getPrototypeOf(VConsoleDefaultTab.prototype),"mockConsole",this).call(this);var e=this;tool.isFunction(window.onerror)&&(this.windowOnError=window.onerror),window.onerror=function(t,o,n,r,i){var l=t;o&&(l+="\n"+o.replace(location.origin,"")),(n||r)&&(l+=":"+n+":"+r),e.printLog({logType:"error",logs:[l],noOrigin:!0}),tool.isFunction(e.windowOnError)&&e.windowOnError.apply(window,t,o,n,r,i)}}},{key:"evalCommand",value:function evalCommand(cmd){var date=tool.getDate(+new Date);this.renderLog({logType:"log",meta:date.hour+":"+date.minute+":"+date.second,content:_query2["default"].render(_item_code2["default"],{content:cmd,type:"input"},!0),style:""});var result=eval(cmd),content="";content=tool.isArray(result)||tool.isObject(result)?this.getFoldedLine(result):_query2["default"].render(_item_code2["default"],{content:result,type:"output"},!0),this.renderLog({logType:"log",meta:"",content:content,style:"vc-item-nometa"})}}]),VConsoleDefaultTab}(_log2["default"]),tab=new VConsoleDefaultTab("default","Log");exports["default"]=tab,module.exports=exports["default"]},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t["default"]=e,t}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},s=function(){function e(e,t){for(var o=0;or;r++)n[r]=arguments[r];var c=l(this,(e=Object.getPrototypeOf(t)).call.apply(e,[this].concat(n)));return c.tplTabbox="",c.allowUnformattedLog=!0,c.isReady=!1,c.$tabbox=null,c.console={},c.logList=[],c.mockConsole(),c}return c(t,e),s(t,[{key:"onInit",value:function(){this.isReady=!0,this.$tabbox=v["default"].render(this.tplTabbox,{});for(var e=0;e0&&(r=i[1].toLowerCase())}if(r?o=r==this.id:0==this.allowUnformattedLog&&(o=!1),!o)return void(e.noOrigin||this.printOriginLog(e));if(e.date||(e.date=+new Date),!this.isReady)return void this.logList.push(e);u.isString(t[0])&&(t[0]=t[0].replace(n,""),""===t[0]&&t.shift());for(var l="",c=0;c")}catch(s){l+=" ["+a(t[c])+"]"}var d=u.getDate(e.date);this.renderLog({logType:e.logType,content:l,meta:d.hour+":"+d.minute+":"+d.second,style:""}),e.noOrigin||this.printOriginLog(e); -}}},{key:"renderLog",value:function(e){var t=v["default"].render(h["default"],e);v["default"].one(".vc-log",this.$tabbox).appendChild(t),v["default"].one(".vc-content").scrollTop=v["default"].one(".vc-content").scrollHeight}},{key:"getFoldedLine",value:function(e){function t(e){for(var t=s.length-1;t>=0;t--)if(s[t].child==e)return!0;return!1}function o(e,n){if(u.isObject(e)){if(t(e))return void(i+="{Circular Object}");s.push({parent:n,child:e});var r=Object.keys(e);i+="{\n",c++;for(var l=0;l26&&(l+="..."),r=Object.prototype.toString.call(e).replace("[object ","").replace("]",""),r+=" "+l;var s=[];o(e,null);var d=v["default"].render(m["default"],{outer:r,inner:i},!0);return d}}]),t}(b["default"]);t["default"]=x,e.exports=t["default"]},function(e,t){e.exports='
{{meta}}
{{content}}
'},function(e,t){e.exports='
{{outer}}
{{inner}}
'},function(e,t){e.exports="{{code}}"},function(e,t){e.exports="
"},function(e,t){e.exports='
{{content}}
'},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t["default"]=e,t}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(e,t){for(var o=0;or;r++)n[r]=arguments[r];var c=l(this,(e=Object.getPrototypeOf(t)).call.apply(e,[this].concat(n)));return c.tplTabbox=b["default"],c.allowUnformattedLog=!1,c}return c(t,e),a(t,[{key:"onInit",value:function(){s(Object.getPrototypeOf(t.prototype),"onInit",this).call(this),this.printSystemInfo()}},{key:"printSystemInfo",value:function(){var e=navigator.userAgent,t="",o=u.getDate();console.info("[system]","Now:",o.year+"-"+o.month+"-"+o.day+" "+o.hour+":"+o.minute+":"+o.second+"."+o.millisecond),t="Unknown";var n=e.match(/(ipod).*\s([\d_]+)/i),r=e.match(/(ipad).*\s([\d_]+)/i),i=e.match(/(iphone)\sos\s([\d_]+)/i),l=e.match(/(android)\s([\d\.]+)/i);l?t="Android "+l[2]:i?t="iPhone, iOS "+i[2].replace(/_/g,"."):r?t="iPad, iOS "+r[2].replace(/_/g,"."):n&&(t="iPod, iOS "+n[2].replace(/_/g,".")),console.info("[system]","System:",t);var c=e.match(/MicroMessenger\/([\d\.]+)/i);t="Unknown",c&&c[1]&&(t=c[1],console.info("[system]","WeChat:",t));var a=e.toLowerCase().match(/ nettype\/([^ ]+)/g);t="Unknown",a&&a[0]&&(a=a[0].split("/"),t=a[1],console.info("[system]","Network:",t)),t="Unknown",t="https:"==location.protocol?"HTTPS":"http:"==location.protocol?"HTTP":location.protocol.replace(":",""),console.info("[system]","Protocol:",t);var s=window.performance||window.msPerformance||window.webkitPerformance;if(s&&s.timing){var d=s.timing,f=d.navigationStart;console.info("[system]","connectEndTime:",d.connectEnd-f+"ms"),console.info("[system]","responseEndTime:",d.responseEnd-f+"ms"),d.secureConnectionStart>0&&console.info("[system]","SSL Cost:",d.connectEnd-d.secureConnectionStart+"ms"),console.info("[system]","DomRenderCost:",d.domComplete-d.domLoading+"ms")}console.info("[system]","UA:",e)}}]),t}(v["default"]),h=new g("system","System");t["default"]=h,e.exports=t["default"]},function(e,t){e.exports="
"},function(e,t,o){"use strict";function n(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t["default"]=e,t}function r(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(e,t){for(var o=0;or;r++)n[r]=arguments[r];var c=l(this,(e=Object.getPrototypeOf(t)).call.apply(e,[this].concat(n)));return c.$tabbox=d["default"].render(g["default"],{}),c.$header=null,c.reqList={},c.domList={},c.mockAjax(),c}return c(t,e),a(t,[{key:"onRenderTab",value:function(e){e(this.$tabbox)}},{key:"onAddTool",value:function(e){var t=this,o=[{name:"Clear",global:!1,onClick:function(e){t.clearLog()}}];e(o)}},{key:"onReady",value:function(){this.renderHeader(),d["default"].delegate(d["default"].one(".vc-log",this.$tabbox),"click",".vc-group-preview",function(e){var t=this.parentNode;d["default"].hasClass(t,"vc-actived")?d["default"].removeClass(t,"vc-actived"):d["default"].addClass(t,"vc-actived"),e.preventDefault()})}},{key:"clearLog",value:function(){this.reqList={};for(var e in this.domList)this.domList[e].remove(),this.domList[e]=void 0;this.domList={},this.renderHeader()}},{key:"renderHeader",value:function(){var e=Object.keys(this.reqList).length,t=d["default"].render(y["default"],{count:e}),o=d["default"].one(".vc-log",this.$tabbox);this.$header?this.$header.parentNode.replaceChild(t,this.$header):o.parentNode.insertBefore(t,o),this.$header=t}},{key:"updateRequest",value:function(e,t){var o=Object.keys(this.reqList).length,n=this.reqList[e]||{};for(var r in t)n[r]=t[r];this.reqList[e]=n;var i={url:n.url,status:n.status||"-",type:"-",costTime:n.costTime>0?n.costTime+"ms":"-",header:n.header,response:f.htmlEncode(n.response)};n.readyState<=1?i.status="Pending":n.readyState<4&&(i.status="Loading");var l=d["default"].render(_["default"],i),c=this.domList[e];n.status>=400&&d["default"].addClass(d["default"].one(".vc-group-preview",l),"vc-table-row-error"),c?c.parentNode.replaceChild(l,c):d["default"].one(".vc-log",this.$tabbox).appendChild(l),this.domList[e]=l;var a=Object.keys(this.reqList).length;a!=o&&this.renderHeader()}},{key:"mockAjax",value:function(){var e=window.XMLHttpRequest;if(e){var t=this,o=window.XMLHttpRequest.prototype.open;window.XMLHttpRequest.prototype.send;window.XMLHttpRequest.prototype.open=function(){var e=this,n=[].slice.call(arguments),r=n[1],i=t.getUniqueID();e._requestID=i;var l=e.onreadystatechange||function(){};return e.onreadystatechange=function(){var o=t.reqList[i]||{};if(o.url=r,o.readyState=e.readyState,0==e.readyState)o.startTime=+new Date;else if(1==e.readyState)o.startTime=+new Date;else if(2==e.readyState){o.header={};for(var n=e.getAllResponseHeaders()||"",c=n.split("\n"),a=0;a
"},function(e,t){e.exports='
Name {{if (count > 0)}}({{count}}){{/if}}
Status
Time
'},function(e,t){e.exports='
{{url}}
{{status}}
{{costTime}}
Headers
{{for (var key in header)}}
{{key}}
{{header[key]}}
{{/for}}
Response
{{response}}
'}])}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.vConsole=t():e.vConsole=t()}(this,function(){return function(e){function t(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return e[n].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var r=o(1),i=n(r),l=o(13),c=n(l),a=o(14),s=n(a),d=o(21),u=n(d),f=o(23),v=n(f),p=new i["default"];p.addPlugin(s["default"]),p.addPlugin(u["default"]),p.addPlugin(v["default"]),p.VConsolePlugin=c["default"],t["default"]=p,e.exports=t["default"]},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t["default"]=e,t}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var l=function(){function e(e,t){for(var o=0;o0){var n=o.touches[0].pageX-e.switchPos.startX,r=o.touches[0].pageY-e.switchPos.startY,i=e.switchPos.x-n,l=e.switchPos.y-r;0>i&&(i=0),0>l&&(l=0),i+t.offsetWidth>document.body.offsetWidth&&(i=document.body.offsetWidth-t.offsetWidth),l+t.offsetHeight>document.body.offsetHeight&&(l=document.body.offsetHeight-t.offsetHeight),t.style.right=i+"px",t.style.bottom=l+"px",e.switchPos.endX=i,e.switchPos.endY=l,o.preventDefault()}}),d["default"].bind(d["default"].one(".vc-switch",e.$dom),"click",function(){e.show()}),d["default"].bind(d["default"].one(".vc-hide",e.$dom),"click",function(){e.hide()}),d["default"].bind(d["default"].one(".vc-mask",e.$dom),"click",function(t){return t.target!=d["default"].one(".vc-mask")?!1:void e.hide()}),d["default"].delegate(d["default"].one(".vc-tabbar",e.$dom),"click",".vc-tab",function(t){var o=this.dataset.tab;o!=e.activedTab&&e.showTab(o)})}},{key:"_autoRun",value:function(){this.isReady=!0;for(var e in this.pluginList)this._initPlugin(this.pluginList[e]);this.showTab(this.tabList[0])}},{key:"_initPlugin",value:function(e){var t=this;e.trigger("init"),e.trigger("renderTab",function(o){t.tabList.push(e.id);var n=d["default"].render(p["default"],{id:e.id,name:e.name});d["default"].one(".vc-tabbar",t.$dom).appendChild(n);var r=d["default"].render(g["default"],{id:e.id});o&&(a.isString(o)?r.innerHTML+=o:a.isFunction(o.appendTo)?o.appendTo(r):a.isElement(o)&&r.appendChild(o)),d["default"].one(".vc-content",t.$dom).appendChild(r)}),e.trigger("addTool",function(t){if(t)for(var o=d["default"].one(".vc-tool-last"),n=0;n0?new Date(e):new Date,o=t.getDate()<10?"0"+t.getDate():t.getDate(),n=t.getMonth()<9?"0"+(t.getMonth()+1):t.getMonth()+1,r=t.getFullYear(),i=t.getHours()<10?"0"+t.getHours():t.getHours(),l=t.getMinutes()<10?"0"+t.getMinutes():t.getMinutes(),c=t.getSeconds()<10?"0"+t.getSeconds():t.getSeconds(),a=t.getMilliseconds()<10?"0"+t.getMilliseconds():t.getMilliseconds();return 100>a&&(a="0"+a),{time:+t,year:r,month:n,day:o,hour:i,minute:l,second:c,millisecond:a}}function n(e){return"[object Number]"==Object.prototype.toString.call(e)}function r(e){return"[object String]"==Object.prototype.toString.call(e)}function i(e){return"[object Array]"==Object.prototype.toString.call(e)}function l(e){return"[object Boolean]"==Object.prototype.toString.call(e)}function c(e){return"[object Undefined]"==Object.prototype.toString.call(e)}function a(e){return"[object Null]"==Object.prototype.toString.call(e)}function s(e){return"[object Symbol]"==Object.prototype.toString.call(e)}function d(e){return!("[object Object]"!=Object.prototype.toString.call(e)&&(n(e)||r(e)||l(e)||i(e)||a(e)||u(e)||c(e)||s(e)))}function u(e){return"[object Function]"==Object.prototype.toString.call(e)}function f(e){return"object"===("undefined"==typeof HTMLElement?"undefined":h(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":h(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName}function v(e){return document.createElement("a").appendChild(document.createTextNode(e)).parentNode.innerHTML}function p(e){function t(e){for(var t=p.length-1;t>=0;t--)if(p[t].child==e)return!0;return!1}function o(e){if(d(e)){if(t(e))return void(f+="CircularObject");p.push({parent:parent,child:e});var b=Object.keys(e);f+="{",v++;for(var g=0;g0&&(n=Array.prototype.slice.call(o)),n},c.addClass=function(e,t){if(e){(0,r.isArray)(e)||(e=[e]);for(var o=0;o=0&&m.splice(t,1)}function c(e){var t=document.createElement("style");return t.type="text/css",i(e,t),t}function a(e){var t=document.createElement("link");return t.rel="stylesheet",i(e,t),t}function s(e,t){var o,n,r;if(t.singleton){var i=y++;o=h||(h=c(t)),n=d.bind(null,o,i,!1),r=d.bind(null,o,i,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(o=a(t),n=f.bind(null,o),r=function(){l(o),o.href&&URL.revokeObjectURL(o.href)}):(o=c(t),n=u.bind(null,o),r=function(){l(o)});return n(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;n(e=t)}else r()}}function d(e,t,o,n){var r=o?"":n.css;if(e.styleSheet)e.styleSheet.cssText=_(t,r);else{var i=document.createTextNode(r),l=e.childNodes;l[t]&&e.removeChild(l[t]),l.length?e.insertBefore(i,l[t]):e.appendChild(i)}}function u(e,t){var o=t.css,n=t.media;if(n&&e.setAttribute("media",n),e.styleSheet)e.styleSheet.cssText=o;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(o))}}function f(e,t){var o=t.css,n=t.sourceMap;n&&(o+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(n))))+" */");var r=new Blob([o],{type:"text/css"}),i=e.href;e.href=URL.createObjectURL(r),i&&URL.revokeObjectURL(i)}var v={},p=function(e){var t;return function(){return"undefined"==typeof t&&(t=e.apply(this,arguments)),t}},b=p(function(){return/msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase())}),g=p(function(){return document.head||document.getElementsByTagName("head")[0]}),h=null,y=0,m=[];e.exports=function(e,t){t=t||{},"undefined"==typeof t.singleton&&(t.singleton=b()),"undefined"==typeof t.insertAt&&(t.insertAt="bottom");var o=r(e);return n(o,t),function(e){for(var i=[],l=0;l
vConsole
'},function(e,t){e.exports="{{name}}"},function(e,t){e.exports="
"},function(e,t){e.exports='{{name}}'},function(e,t){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var o=0;on;n++)o[n]=arguments[n];var r=_possibleConstructorReturn(this,(e=Object.getPrototypeOf(VConsoleDefaultTab)).call.apply(e,[this].concat(o)));return r.tplTabbox=_tabbox_default2["default"],r.windowOnError=null,r}return _inherits(VConsoleDefaultTab,_VConsoleLogTab),_createClass(VConsoleDefaultTab,[{key:"onReady",value:function(){var e=this;_get(Object.getPrototypeOf(VConsoleDefaultTab.prototype),"onReady",this).call(this),_query2["default"].bind(_query2["default"].one(".vc-cmd",this.$tabbox),"submit",function(t){t.preventDefault();var o=_query2["default"].one(".vc-cmd-input",t.target),n=o.value;o.value="",""!==n&&e.evalCommand(n)})}},{key:"mockConsole",value:function(){_get(Object.getPrototypeOf(VConsoleDefaultTab.prototype),"mockConsole",this).call(this);var e=this;tool.isFunction(window.onerror)&&(this.windowOnError=window.onerror),window.onerror=function(t,o,n,r,i){var l=t;o&&(l+="\n"+o.replace(location.origin,"")),(n||r)&&(l+=":"+n+":"+r),e.printLog({logType:"error",logs:[l],noOrigin:!0}),tool.isFunction(e.windowOnError)&&e.windowOnError.apply(window,t,o,n,r,i)}}},{key:"evalCommand",value:function evalCommand(cmd){var date=tool.getDate(+new Date);this.renderLog({logType:"log",meta:date.hour+":"+date.minute+":"+date.second,content:_query2["default"].render(_item_code2["default"],{content:cmd,type:"input"},!0),style:""});var result=eval(cmd),content="";content=tool.isArray(result)||tool.isObject(result)?this.getFoldedLine(result):_query2["default"].render(_item_code2["default"],{content:result,type:"output"},!0),this.renderLog({logType:"log",meta:"",content:content,style:"vc-item-nometa"})}}]),VConsoleDefaultTab}(_log2["default"]),tab=new VConsoleDefaultTab("default","Log");exports["default"]=tab,module.exports=exports["default"]},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t["default"]=e,t}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},s=function(){function e(e,t){for(var o=0;or;r++)n[r]=arguments[r];var c=l(this,(e=Object.getPrototypeOf(t)).call.apply(e,[this].concat(n)));return c.tplTabbox="",c.allowUnformattedLog=!0,c.isReady=!1,c.$tabbox=null,c.console={},c.logList=[],c.mockConsole(),c}return c(t,e),s(t,[{key:"onInit",value:function(){this.isReady=!0,this.$tabbox=v["default"].render(this.tplTabbox,{});for(var e=0;e0&&(r=i[1].toLowerCase())}if(r?o=r==this.id:0==this.allowUnformattedLog&&(o=!1),!o)return void(e.noOrigin||this.printOriginLog(e));if(e.date||(e.date=+new Date),!this.isReady)return void this.logList.push(e);u.isString(t[0])&&(t[0]=t[0].replace(n,""),""===t[0]&&t.shift());for(var l="",c=0;c")}catch(s){l+=" ["+a(t[c])+"]"}var d=u.getDate(e.date);this.renderLog({logType:e.logType,content:l,meta:d.hour+":"+d.minute+":"+d.second,style:"" +}),e.noOrigin||this.printOriginLog(e)}}},{key:"renderLog",value:function(e){var t=v["default"].render(h["default"],e);v["default"].one(".vc-log",this.$tabbox).appendChild(t),v["default"].one(".vc-content").scrollTop=v["default"].one(".vc-content").scrollHeight}},{key:"getFoldedLine",value:function(e){function t(e){for(var t=s.length-1;t>=0;t--)if(s[t].child==e)return!0;return!1}function o(e,n){if(u.isObject(e)){if(t(e))return void(i+="{Circular Object}");s.push({parent:n,child:e});var r=Object.keys(e);i+="{\n",c++;for(var l=0;l26&&(l+="..."),r=Object.prototype.toString.call(e).replace("[object ","").replace("]",""),r+=" "+l;var s=[];o(e,null);var d=v["default"].render(m["default"],{outer:r,inner:i},!0);return d}}]),t}(b["default"]);t["default"]=x,e.exports=t["default"]},function(e,t){e.exports='
{{meta}}
{{content}}
'},function(e,t){e.exports='
{{outer}}
{{inner}}
'},function(e,t){e.exports="{{code}}"},function(e,t){e.exports="
"},function(e,t){e.exports='
{{content}}
'},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t["default"]=e,t}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(e,t){for(var o=0;or;r++)n[r]=arguments[r];var c=l(this,(e=Object.getPrototypeOf(t)).call.apply(e,[this].concat(n)));return c.tplTabbox=b["default"],c.allowUnformattedLog=!1,c}return c(t,e),a(t,[{key:"onInit",value:function(){s(Object.getPrototypeOf(t.prototype),"onInit",this).call(this),this.printSystemInfo()}},{key:"printSystemInfo",value:function(){var e=navigator.userAgent,t="",o=u.getDate();console.info("[system]","Now:",o.year+"-"+o.month+"-"+o.day+" "+o.hour+":"+o.minute+":"+o.second+"."+o.millisecond),t="Unknown";var n=e.match(/(ipod).*\s([\d_]+)/i),r=e.match(/(ipad).*\s([\d_]+)/i),i=e.match(/(iphone)\sos\s([\d_]+)/i),l=e.match(/(android)\s([\d\.]+)/i);l?t="Android "+l[2]:i?t="iPhone, iOS "+i[2].replace(/_/g,"."):r?t="iPad, iOS "+r[2].replace(/_/g,"."):n&&(t="iPod, iOS "+n[2].replace(/_/g,".")),console.info("[system]","System:",t);var c=e.match(/MicroMessenger\/([\d\.]+)/i);t="Unknown",c&&c[1]&&(t=c[1],console.info("[system]","WeChat:",t));var a=e.toLowerCase().match(/ nettype\/([^ ]+)/g);t="Unknown",a&&a[0]&&(a=a[0].split("/"),t=a[1],console.info("[system]","Network:",t)),t="Unknown",t="https:"==location.protocol?"HTTPS":"http:"==location.protocol?"HTTP":location.protocol.replace(":",""),console.info("[system]","Protocol:",t);var s=window.performance||window.msPerformance||window.webkitPerformance;if(s&&s.timing){var d=s.timing,f=d.navigationStart;console.info("[system]","connectEndTime:",d.connectEnd-f+"ms"),console.info("[system]","responseEndTime:",d.responseEnd-f+"ms"),d.secureConnectionStart>0&&console.info("[system]","SSL Cost:",d.connectEnd-d.secureConnectionStart+"ms"),console.info("[system]","DomRenderCost:",d.domComplete-d.domLoading+"ms")}console.info("[system]","UA:",e)}}]),t}(v["default"]),h=new g("system","System");t["default"]=h,e.exports=t["default"]},function(e,t){e.exports="
"},function(e,t,o){"use strict";function n(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t["default"]=e,t}function r(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(e,t){for(var o=0;or;r++)n[r]=arguments[r];var c=l(this,(e=Object.getPrototypeOf(t)).call.apply(e,[this].concat(n)));return c.$tabbox=d["default"].render(g["default"],{}),c.$header=null,c.reqList={},c.domList={},c.mockAjax(),c}return c(t,e),a(t,[{key:"onRenderTab",value:function(e){e(this.$tabbox)}},{key:"onAddTool",value:function(e){var t=this,o=[{name:"Clear",global:!1,onClick:function(e){t.clearLog()}}];e(o)}},{key:"onReady",value:function(){this.renderHeader(),d["default"].delegate(d["default"].one(".vc-log",this.$tabbox),"click",".vc-group-preview",function(e){var t=this.parentNode;d["default"].hasClass(t,"vc-actived")?d["default"].removeClass(t,"vc-actived"):d["default"].addClass(t,"vc-actived"),e.preventDefault()})}},{key:"clearLog",value:function(){this.reqList={};for(var e in this.domList)this.domList[e].remove(),this.domList[e]=void 0;this.domList={},this.renderHeader()}},{key:"renderHeader",value:function(){var e=Object.keys(this.reqList).length,t=d["default"].render(y["default"],{count:e}),o=d["default"].one(".vc-log",this.$tabbox);this.$header?this.$header.parentNode.replaceChild(t,this.$header):o.parentNode.insertBefore(t,o),this.$header=t}},{key:"updateRequest",value:function(e,t){var o=Object.keys(this.reqList).length,n=this.reqList[e]||{};for(var r in t)n[r]=t[r];this.reqList[e]=n;var i={url:n.url,status:n.status||"-",type:"-",costTime:n.costTime>0?n.costTime+"ms":"-",header:n.header,response:f.htmlEncode(n.response)};n.readyState<=1?i.status="Pending":n.readyState<4&&(i.status="Loading");var l=d["default"].render(_["default"],i),c=this.domList[e];n.status>=400&&d["default"].addClass(d["default"].one(".vc-group-preview",l),"vc-table-row-error"),c?c.parentNode.replaceChild(l,c):d["default"].one(".vc-log",this.$tabbox).appendChild(l),this.domList[e]=l;var a=Object.keys(this.reqList).length;a!=o&&this.renderHeader()}},{key:"mockAjax",value:function(){var e=window.XMLHttpRequest;if(e){var t=this,o=window.XMLHttpRequest.prototype.open;window.XMLHttpRequest.prototype.send;window.XMLHttpRequest.prototype.open=function(){var e=this,n=[].slice.call(arguments),r=n[1],i=t.getUniqueID();e._requestID=i;var l=e.onreadystatechange||function(){};return e.onreadystatechange=function(){var o=t.reqList[i]||{};if(o.url=r,o.readyState=e.readyState,0==e.readyState)o.startTime=+new Date;else if(1==e.readyState)o.startTime=+new Date;else if(2==e.readyState){o.header={};for(var n=e.getAllResponseHeaders()||"",c=n.split("\n"),a=0;a
"},function(e,t){e.exports='
Name {{if (count > 0)}}({{count}}){{/if}}
Status
Time
'},function(e,t){e.exports='
{{url}}
{{status}}
{{costTime}}
Headers
{{for (var key in header)}}
{{key}}
{{header[key]}}
{{/for}}
Response
{{response}}
'}])}); \ No newline at end of file diff --git a/src/core/core.js b/src/core/core.js index 0917f19b..f460ab0a 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -35,6 +35,10 @@ class VConsole { }; this.bodyOverflowCSS = ''; + // export helper functions to public + this.tool = tool; + this.$ = $; + var _onload = function() { that._render(); that._bindEvent(); From 115b26fc0d1897ac9c42fb388e525635f89893bf Mon Sep 17 00:00:00 2001 From: Maiz Date: Wed, 29 Jun 2016 19:07:47 +0800 Subject: [PATCH 2/6] add new docs --- doc/a_doc_index.md | 2 + doc/a_doc_index_CN.md | 2 + doc/helper_functions.md | 304 +++++++++++++++++++++++++++ doc/helper_functions_CN.md | 305 ++++++++++++++++++++++++++++ doc/public_properties_methods.md | 120 +++++++++++ doc/public_properties_methods_CN.md | 120 +++++++++++ 6 files changed, 853 insertions(+) create mode 100644 doc/helper_functions.md create mode 100644 doc/helper_functions_CN.md create mode 100644 doc/public_properties_methods.md create mode 100644 doc/public_properties_methods_CN.md diff --git a/doc/a_doc_index.md b/doc/a_doc_index.md index 10f4362b..41ccc650 100644 --- a/doc/a_doc_index.md +++ b/doc/a_doc_index.md @@ -7,6 +7,8 @@ Documentation Index ## vConsole - [Tutorial](./tutorial.md) + - [Public Properties & Methods](./public_properties_methods.md) + - [Helper Functions](./helper_functions.md) ## Plugin diff --git a/doc/a_doc_index_CN.md b/doc/a_doc_index_CN.md index 063078ee..7ab25c8f 100644 --- a/doc/a_doc_index_CN.md +++ b/doc/a_doc_index_CN.md @@ -7,6 +7,8 @@ ## vConsole 本体 - [使用教程](./tutorial_CN.md) + - [公共属性及方法](./public_properties_methods_CN.md) + - [辅助函数](./helper_functions_CN.md) ## Plugin 插件 diff --git a/doc/helper_functions.md b/doc/helper_functions.md new file mode 100644 index 00000000..4400a04d --- /dev/null +++ b/doc/helper_functions.md @@ -0,0 +1,304 @@ +Helper Functions +============================== + +vConsole provides some useful helper functions for efficient plugin development. + +Helper functions are mounted in different vConsole properties according to their usage: + +- `vConsole.tool`: Helper functions. +- `vConsole.$`: DOM-related functions. + + +## vConsole.tool + +### vConsole.tool.isString(value) +### vConsole.tool.isArray(value) +### vConsole.tool.isBoolean(value) +### vConsole.tool.isElement(value) +### vConsole.tool.isFunction(value) +### vConsole.tool.isNull(value) +### vConsole.tool.isNumber(value) +### vConsole.tool.isObject(value) +### vConsole.tool.isSymbol(value) +### vConsole.tool.isUndefined(value) + +Check whether a value is a certain type. + +##### Return: +- Boolean + + + +### vConsole.tool.htmlEncode(text) + +Encode a text into a HTML non-sensitive string. + +##### Parameters: +- (required) text: A string to be encoded. + +##### Return: +- String + + + +### vConsole.tool.setStorage(key, value) + +Set data to `localStorage`. A prefix `vConsole_` will be added to `key` automatically. + +Note that some devices may not have `localStorage` and then `value` would not be saved under this situation, so DO NOT use this method to save permanent data. + +##### Parameters: +- (required) key: A string, the name of data. +- (required) value: A string, the value of data. + +##### Return: +- None + +##### Example: + +```javascript +vConsole.tool.setStorage('count', 1); +``` + + + +### vConsole.tool.getStorage(key) + +Get data from `localStorage`. A prefix `vConsole_` will be added to `key` automatically. + +##### Parameters: +- (required) key: A string, the name of data. + +##### Return: +- String, the value of data. + +##### Example: + +```javascript +var num = vConsole.tool.setStorage('count'); // => 1 +``` + + + +## vConsole.$ + +### vConsole.$.one(selectors, baseElement) + +Returns the first element within the document or baseElement that matches the specified group of selectors. + +##### Parameters: +- (required) selectors: A string containing one or more CSS selectors separated by commas. +- (optional) baseElement: An element object, default to be `document`. + +##### Return: +- Element object + +##### Example: + +```javascript +var $page = vConsole.$.one('#my_page'); +var $item = vConsole.$.one('.item', $page); +``` + + +### vConsole.$.all(selectors, baseElement) + +Returns a list of elements within the document or baseElement that matches the specified group of selectors. + +##### Parameters: +- (required) selectors: A string containing one or more CSS selectors separated by commas. +- (optional) baseElement: An element object, default to be `document`. + +##### Return: +- Element object + +##### Example: + +```javascript +var $page = vConsole.$.one('#my_page'); +var $items = vConsole.$.all('.item', $page); +``` + + +### vConsole.$.addClass(elements, className) + +Add the specified class(es) to element(s). + +##### Parameters: +- (required) elements: A single or a list of element object(s). +- (required) className: A string of one or more space-separated classes. + +##### Return: +- None + +##### Example: + +```javascript +var $items = vConsole.$.all('.item'); +vConsole.$.addClass($items, 'selected'); +``` + + +### vConsole.$.removeClass(elements, className) + +Remove the specified class(es) of element(s). + +##### Parameters: +- (required) elements: A single or a list of element object(s). +- (required) className: A string of one or more space-separated classes. + +##### Return: +- None + +##### Example: + +```javascript +var $items = vConsole.$.all('.item'); +vConsole.$.removeClass($items, 'selected'); +``` + + +### vConsole.$.hasClass(element, className) + +Check whether an element is assigned the given class. + +##### Parameters: +- (required) element: An element object. +- (required) className: A string. + +##### Return: +- Boolean + +##### Example: + +```javascript +var $page = vConsole.$.one('#my_page'); +if (vConsole.$.hasClass($page, 'actived')) { + // do something +} +``` + + +### vConsole.$.bind(elements, eventType, fn, useCapture) + +Bind an event to element(s). + +##### Parameters: +- (required) elements: A single or a list of element object(s). +- (required) eventType: A string of event's type. +- (required) fn: A function to execute when the event is triggered. +- (optional) useCapture: A boolean that indicates the event uses capturing or bubbling, default to be `false`. + +##### Return: +- None + +##### Example: + +```javascript +var $btn = vConsole.$.one('#submit'); +vConsole.$.bind($btn, 'click', function(event) { + event.preventDefault(); + alert('submit!'); +}); +``` + + +### vConsole.$.delegate(element, eventType, selectors, fn) + +Bind an event to an element, and only this element's descendants which match the selectors can trigger the event. + +##### Parameters: +- (required) element: An element object. +- (required) eventType: A string of event's type. +- (required) selectors: A string containing one or more CSS selectors separated by commas. +- (required) fn: A function to execute when the event is triggered. + +##### Return: +- None + +##### Example: + +```javascript +var $page = vConsole.$.one('#my_page'); +vConsole.$.delegate($page, 'click', '.item', function(event) { + vConsole.$.addClass(this, 'selected'); // this => '.item' +}); +``` + + +### vConsole.$.render(tpl, data, toString) + +Compile a template into an element object or a HTML string with given data. + +##### Parameters: +- (required) tpl: A template string. +- (required) data: A key-value data which is used to render the template. +- (optional) toString: A boolean that indicates whether returns an element object or a HTML string, default to be `false`. + +##### Return: +- Element object or HTML string + +##### Syntax: + +If: +```html +{{if}} + ... +{{else}} + ... +{{/if}} +``` + +For: +```html +{{for (var i=0; i<10; i++)}} + ... + {{continue}} + {{break}} +{{/for}} +``` + +Switch: +```html +{{switch (flag)}} + {{case 1}} + ... + {{break}} + {{default}} + ... +{{/switch}} +``` + +Print: +```html +{{flag}} +``` + +###### Example: + +```javascript +var tpl = '
    ' + + '{{for (var i = 0; i < list.length; i++)}}' + + '
  • ' + '{{list[i]}}' + '
  • ' + + '{{/for}}' + +'
'; +var data = { + list: ['Red', 'Blue', 'Yellow'] +}; + +var html = vConsole.&.render(tpl, data, true); +document.body.innerHTML += html; +``` + +Output: + +```html +
    +
  • Red
  • +
  • Blue
  • +
  • Yellow
  • +
+``` + + +[Back to Index](./a_doc_index.md) \ No newline at end of file diff --git a/doc/helper_functions_CN.md b/doc/helper_functions_CN.md new file mode 100644 index 00000000..27f86e4c --- /dev/null +++ b/doc/helper_functions_CN.md @@ -0,0 +1,305 @@ +辅助函数 +============================== + +vConsole 提供一些辅助函数以便开发插件。 + +辅助函数会按照类型,挂载到 vConsole 的不同属性中: + +- `vConsole.tool`:辅助函数。 +- `vConsole.$`:DOM 操作相关函数。 + + +## vConsole.tool + +### vConsole.tool.isString(value) +### vConsole.tool.isArray(value) +### vConsole.tool.isBoolean(value) +### vConsole.tool.isElement(value) +### vConsole.tool.isFunction(value) +### vConsole.tool.isNull(value) +### vConsole.tool.isNumber(value) +### vConsole.tool.isObject(value) +### vConsole.tool.isSymbol(value) +### vConsole.tool.isUndefined(value) + +判断变量是否为指定的类型。 + +##### 返回: +- Boolean + + + +### vConsole.tool.htmlEncode(text) + +将文本转为 HTML 安全的字符串。 + +##### 参数: +- (required) text: 字符串。 + +##### 返回: +- String + + + +### vConsole.tool.setStorage(key, value) + +将数据写入 `localStorage`。前缀 `vConsole_` 会自动加到 `key` 之前。 + +在一些设备中,`localStorage` 可能不存在,因此 `value` 将无法正常存储。所以不要使用此方法来保存持久性数据。 + +##### 参数: +- (required) key: 字符串,数据的键名。 +- (required) value: 字符串,数据的键值。 + +##### 返回: +- 无 + +##### 例子: + +```javascript +vConsole.tool.setStorage('count', 1); +``` + + + +### vConsole.tool.getStorage(key) + +获取 `localStorage` 的数据。前缀 `vConsole_` 会自动加到 `key` 之前。 + +##### 参数: +- (required) key: A string, the name of data. + +##### 返回: +- String + +##### 例子: + +```javascript +var num = vConsole.tool.setStorage('count'); // => 1 +``` + + + +## vConsole.$ + +### vConsole.$.one(selectors, baseElement) + +获取在 `document` 或 `baseElement` 中匹配 `selectors` 的首个 element 元素。 + +##### 参数: +- (required) selectors: CSS 选择器字符串,多个选择器以空格隔开。 +- (optional) baseElement: Element 对象,默认为 `document`. + +##### 返回: +- Element object + +##### 例子: + +```javascript +var $page = vConsole.$.one('#my_page'); +var $item = vConsole.$.one('.item', $page); +``` + + +### vConsole.$.all(selectors, baseElement) + +获取在 `document` 或 `baseElement` 中匹配 `selectors` 的所有 element 元素。 + +##### 参数: +- (required) selectors: CSS 选择器字符串,多个选择器以空格隔开。 +- (optional) baseElement: Element 对象,默认为 `document`. + +##### 返回: +- Element object + +##### 例子: + +```javascript +var $page = vConsole.$.one('#my_page'); +var $items = vConsole.$.all('.item', $page); +``` + + +### vConsole.$.addClass(elements, className) + +为一个或一组 element 添加 class 样式名。 + +##### 参数: +- (required) elements: 单个或一个数组的 element 对象。 +- (required) className: 字符串,多个样式名以空格隔开。 + +##### 返回: +- 无 + +##### 例子: + +```javascript +var $items = vConsole.$.all('.item'); +vConsole.$.addClass($items, 'selected'); +``` + + +### vConsole.$.removeClass(elements, className) + +为一个或一组 element 删除 class 样式名。 + +##### 参数: +- (required) elements: 单个或一个数组的 element 对象。 +- (required) className: 字符串,多个样式名以空格隔开。 + +##### 返回: +- 无 + +##### 例子: + +```javascript +var $items = vConsole.$.all('.item'); +vConsole.$.removeClass($items, 'selected'); +``` + + +### vConsole.$.hasClass(element, className) + +判断一个 element 对象是否有指定的样式名。 + +##### 参数: +- (required) element: Element 对象。 +- (required) className: 字符串。 + +##### 返回: +- Boolean + +##### 例子: + +```javascript +var $page = vConsole.$.one('#my_page'); +if (vConsole.$.hasClass($page, 'actived')) { + // do something +} +``` + + +### vConsole.$.bind(elements, eventType, fn, useCapture) + +绑定一个事件到一个或一组 element。 + +##### 参数: +- (required) elements: 单个或一个数组的 element 对象。 +- (required) eventType: 字符串,事件类型。 +- (required) fn: 事件回调函数。 +- (optional) useCapture: 布尔值,用于设定是使用 capturing 还是 bubbling。默认为 `false`. + +##### 返回: +- 无 + +##### 例子: + +```javascript +var $btn = vConsole.$.one('#submit'); +vConsole.$.bind($btn, 'click', function(event) { + event.preventDefault(); + alert('submit!'); +}); +``` + + +### vConsole.$.delegate(element, eventType, selectors, fn) + +绑定一个事件到一个 element 中,只有匹配 selecors 的子元素才会触发事件。 + +##### 参数: +- (required) element: Element 对象。 +- (required) eventType: 字符串,事件类型。 +- (required) selectors: CSS 选择器字符串,多个选择器以空格隔开。 +- (required) fn: 事件回调函数。 + +##### 返回: +- 无 + +##### 例子: + +```javascript +var $page = vConsole.$.one('#my_page'); +vConsole.$.delegate($page, 'click', '.item', function(event) { + vConsole.$.addClass(this, 'selected'); // this => '.item' +}); +``` + + +### vConsole.$.render(tpl, data, toString) + +Compile a template into an element object or a HTML string with given data. +使用指定数据将模板文本编译成 element 对象或者 HTML 字符串。 + +##### 参数: +- (required) tpl: 模板字符串。 +- (required) data: 一组 key-value 形式的数据源。 +- (optional) toString: 布尔值,用于设定返回值为 element 对象还是 HTML 字符串,默认为 `false`。 + +##### 返回: +- Element 对象或者 HTML 字符串 + +##### 模板语法: + +If: +```html +{{if}} + ... +{{else}} + ... +{{/if}} +``` + +For: +```html +{{for (var i=0; i<10; i++)}} + ... + {{continue}} + {{break}} +{{/for}} +``` + +Switch: +```html +{{switch (flag)}} + {{case 1}} + ... + {{break}} + {{default}} + ... +{{/switch}} +``` + +Print: +```html +{{flag}} +``` + +###### 例子: + +```javascript +var tpl = '
    ' + + '{{for (var i = 0; i < list.length; i++)}}' + + '
  • ' + '{{list[i]}}' + '
  • ' + + '{{/for}}' + +'
'; +var data = { + list: ['Red', 'Blue', 'Yellow'] +}; + +var html = vConsole.&.render(tpl, data, true); +document.body.innerHTML += html; +``` + +输出: + +```html +
    +
  • Red
  • +
  • Blue
  • +
  • Yellow
  • +
+``` + + +[返回索引](./a_doc_index_CN.md) \ No newline at end of file diff --git a/doc/public_properties_methods.md b/doc/public_properties_methods.md new file mode 100644 index 00000000..4bf8722d --- /dev/null +++ b/doc/public_properties_methods.md @@ -0,0 +1,120 @@ +Public Properties & Methods +============================== + +Some useful vConsole properties and methods are available for plugin development. + +## Properties + + +### vConsole.activedTab + +The actived tab's plugin id. + +- Readonly +- Type: string +- Default: "default" + +Example: + +```javascript +vConsole.activedTab // => "system" +``` + + +### vConsole.tabList + +A list of installed tabs' plugin id. + +- Readonly +- Type: array(string) + +Example: + +```javascript +vConsole.tabList // => ["default", "system"] +``` + + +### vConsole.$dom + +vConsole's HTML element. + +- Type: HTMLDivElement + + + +## Methods + + +### vConsole.addPlugin(plugin) + +Add a new plugin to vConsole. Duplicate plugin will be ignored. + +##### Parameters: +- (required) plugin: An VConsolePlugin object. + +##### Return: +- Boolean: `true` for success, `false` for failure. + +##### Example: + +```javascript +var myPlugin = new VConsolePlugin('my_plugin', 'My Plugin'); +vConsole.addPlugin(myPlugin); +``` + + +### vConsole.showTab(pluginID) + +Activating a tab according to its plugin id. + +Plugin event `hide` will be triggered for previous actived tab, and `show` for current actived tab. + +##### Parameters: +- (required) pluginID: A string, tab's plugin id. + +##### Return: +- None + +##### Example: + +```javascript +vConsole.showTab("system"); // show System tab +``` + + +### vConsole.show() + +Show vConsole panel. This method will trigger plugin event `showConsole`. + +##### Parameters: +- None + +##### Return: +- None + +##### Example: + +```javascript +vConsole.show(); +``` + + +### vConsole.hide() + +Hide vConsole panel. This method will trigger plugin event `hideConsole`. + +##### Parameters: +- None + +##### Return: +- None + +##### Example: + +```javascript +vConsole.hide(); +``` + + +[Back to Index](./a_doc_index.md) \ No newline at end of file diff --git a/doc/public_properties_methods_CN.md b/doc/public_properties_methods_CN.md new file mode 100644 index 00000000..2df82066 --- /dev/null +++ b/doc/public_properties_methods_CN.md @@ -0,0 +1,120 @@ +公共属性及方法 +============================== + +vConsole 提供一些公共属性字段、函数方法,以便开发插件。 + +## 属性 + + +### vConsole.activedTab + +当前激活的 tab 的 plugin id。 + +- 只读 +- 类型:string +- 默认值:"default" + +例子: + +```javascript +vConsole.activedTab // => "system" +``` + + +### vConsole.tabList + +已安装的 tab 的 plugin id 列表。 + +- 只读 +- 类型:array(string) + +例子: + +```javascript +vConsole.tabList // => ["default", "system"] +``` + + +### vConsole.$dom + +vConsole 的 HTML element。 + +- 类型:HTMLDivElement + + + +## 方法 + + +### vConsole.addPlugin(plugin) + +添加一个新插件。重名的插件会被忽略。 + +##### 参数: +- (required) plugin: 一个 VConsolePlugin 对象。 + +##### 返回: +- Boolean: 成功为 `true`,失败为 `false`。 + +##### 例子: + +```javascript +var myPlugin = new VConsolePlugin('my_plugin', 'My Plugin'); +vConsole.addPlugin(myPlugin); +``` + + +### vConsole.showTab(pluginID) + +根据 plugin id 激活显示一个 tab。 + +此方法会触发先前激活态 tab 的 `hide` 事件,并触发当前激活态 tab 的 `show` 事件。 + +##### 参数: +- (required) pluginID: 字符串,tab 的 plugin id。 + +##### 返回: +- 无 + +##### 例子: + +```javascript +vConsole.showTab("system"); // 显示 System tab +``` + + +### vConsole.show() + +显示 vConsole 主面板。这个方法会触发插件事件 `showConsole`。 + +##### 参数 +- 无 + +##### 返回: +- 无 + +##### 例子: + +```javascript +vConsole.show(); +``` + + +### vConsole.hide() + +隐藏 vConsole 主面板。这个方法会触发插件事件 `hideConsole`。 + +##### 参数 +- 无 + +##### 返回: +- 无 + +##### 例子: + +```javascript +vConsole.hide(); +``` + + +[返回索引](./a_doc_index_CN.md) \ No newline at end of file From 5fca1327eeab9e2edd110c6701b8f3a4dcdc9569 Mon Sep 17 00:00:00 2001 From: Maiz Date: Wed, 29 Jun 2016 19:09:54 +0800 Subject: [PATCH 3/6] add new docs --- README.md | 7 +++++++ README_CN.md | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 9b1f4669..5b3d7dee 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,14 @@ See [Tutorial](./doc/tutorial.md) for more details. ## Documentation +vConsole: + - [Tutorial](./doc/tutorial.md) + - [Public Properties & Methods](./public_properties_methods.md) + - [Helper Functions](./helper_functions.md) + +Plugin: + - [Plugin: Getting Started](./doc/plugin_getting_started.md) - [Plugin: Building a Plugin](./doc/plugin_building_a_plugin.md) - [Plugin: Event List](./doc/plugin_event_list.md) diff --git a/README_CN.md b/README_CN.md index a286100e..a4fb4fb4 100644 --- a/README_CN.md +++ b/README_CN.md @@ -50,7 +50,15 @@ console.log('Hello world'); ## 文档 + +vConsole 本体: + - [使用教程](./doc/tutorial_CN.md) + - [公共属性及方法](./public_properties_methods_CN.md) + - [辅助函数](./helper_functions_CN.md) + +插件: + - [插件:入门](./doc/plugin_getting_started_CN.md) - [插件:编写插件](./doc/plugin_building_a_plugin_CN.md) - [插件:Event 事件列表](./doc/plugin_event_list_CN.md) From 7968eda6ff04a83b9cf743b563eb4f11b0b54bd7 Mon Sep 17 00:00:00 2001 From: Maiz Date: Wed, 29 Jun 2016 19:12:10 +0800 Subject: [PATCH 4/6] add new docs --- README.md | 4 ++-- README_CN.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5b3d7dee..28207cf5 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ See [Tutorial](./doc/tutorial.md) for more details. vConsole: - [Tutorial](./doc/tutorial.md) - - [Public Properties & Methods](./public_properties_methods.md) - - [Helper Functions](./helper_functions.md) + - [Public Properties & Methods](./doc/public_properties_methods.md) + - [Helper Functions](./doc/helper_functions.md) Plugin: diff --git a/README_CN.md b/README_CN.md index a4fb4fb4..d78f0ac2 100644 --- a/README_CN.md +++ b/README_CN.md @@ -54,8 +54,8 @@ console.log('Hello world'); vConsole 本体: - [使用教程](./doc/tutorial_CN.md) - - [公共属性及方法](./public_properties_methods_CN.md) - - [辅助函数](./helper_functions_CN.md) + - [公共属性及方法](./doc/public_properties_methods_CN.md) + - [辅助函数](./doc/helper_functions_CN.md) 插件: From 85adbc3dc7d9b2797257555836ccf6546d0919ab Mon Sep 17 00:00:00 2001 From: Maiz Date: Wed, 29 Jun 2016 19:25:06 +0800 Subject: [PATCH 5/6] v2.1.0 released --- CHANGELOG.md | 7 +++++++ CHANGELOG_CN.md | 8 ++++++++ dist/vconsole.min.js | 2 +- package.json | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54836003..375185d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ English | [简体中文](./CHANGELOG_CN.md) +#### V2.1.0 (2016-06-29) + +- [FEATURE] Add `vConsole.tool` & `vConsole.$` helper functions, see [Helper Functions](./doc/helper_functions.md). +- [FEATURE] Public properties & methods of vConsole are available, see [Public Properties & Methods](./doc/public_properties_methods.md). +- [FIX] Fix issue that `error` in `window.onerror()` may be undefined. +- [FIX] Fix error that `xhr.status` may be unavailable when `xhr.readyState < 4`. + #### v2.0.1 (2016-06-16) diff --git a/CHANGELOG_CN.md b/CHANGELOG_CN.md index 2e867c42..6b032622 100644 --- a/CHANGELOG_CN.md +++ b/CHANGELOG_CN.md @@ -1,6 +1,14 @@ [English](./CHANGELOG.md) | 简体中文 +#### v2.1.0 (2016-06-29) + +- 【特性】新增 `vConsole.tool` 及 `vConsole.$` 辅助函数,请查阅[辅助函数](./doc/helper_functions_CN.md)。 +- 【特性】公开部分 vConsole 的属性及方法,请查阅[公共属性及方法](./doc/public_properties_methods_CN.md)。 +- 【修复】修复 `window.onerror()` 中 `error` 可能为空而导致堆栈读取错误的问题。 +- 【修复】修复当 `xhr.readyState < 4` 时读取 `xhr.status` 可能导致错误的问题。 + + #### v2.0.1 (2016-06-16) - 【修复】修复 vConsole 可能无法运行在 X5 内核浏览器的问题 diff --git a/dist/vconsole.min.js b/dist/vconsole.min.js index 8d62fc1b..9f73a72b 100644 --- a/dist/vconsole.min.js +++ b/dist/vconsole.min.js @@ -1,5 +1,5 @@ /*! - * vconsole v2.0.2-pre (https://github.com/WechatFE/vConsole) + * vconsole v2.1.0 (https://github.com/WechatFE/vConsole) * Copyright 2016, WechatFE Team * MIT license */ diff --git a/package.json b/package.json index 1172855b..0da0d8a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vconsole", - "version": "2.0.2-pre", + "version": "2.1.0", "description": "A lightweight, extendable front-end developer tool for mobile web page.", "homepage": "https://github.com/WechatFE/vConsole", "main": "dist/vconsole.min.js", From 0208721f64955b98970a8b390a5ea57f1fc66c61 Mon Sep 17 00:00:00 2001 From: Maiz Date: Wed, 29 Jun 2016 19:27:08 +0800 Subject: [PATCH 6/6] fix typo --- CHANGELOG_CN.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG_CN.md b/CHANGELOG_CN.md index 6b032622..a82dff8c 100644 --- a/CHANGELOG_CN.md +++ b/CHANGELOG_CN.md @@ -1,6 +1,5 @@ [English](./CHANGELOG.md) | 简体中文 - #### v2.1.0 (2016-06-29) - 【特性】新增 `vConsole.tool` 及 `vConsole.$` 辅助函数,请查阅[辅助函数](./doc/helper_functions_CN.md)。