├── .gitignore ├── LICENSE ├── README.md ├── gquery.js └── gquery.min.js /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-present, JU Chengren (Ganxiaozhe) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gQuery 2 | The brand new JavaScript function library, and killed IE 3 | - Only 10.0kB minified and gzipped. Can also be included as an AMD module 4 | - Supports CSS3 selectors to find elements as well as in style property manipulation 5 | - Use native animation API. Support all major browsers 6 | 7 | 8 | # Why gQuery 9 | 众所周知 jQuery 是一个非常健壮的 JavaScript 库,它提供的 API 易于使用且兼容众多浏览器(例如令开发者头痛的 Internet Explorer)。 10 | 11 | 毫无疑问它曾改变了前端代码书写的模式,并且延续至今。 12 | 13 | 不过随着现代浏览器不断迭代的 API,在家庭电脑中几乎已无法见到 IE 的影子,而 Windows 默认浏览器也早已换成 Edge(并已放弃 EDGEHTML 而使用 Chromium)。 14 | 15 | 如今现代浏览器中,jQuery 难免显得有些臃肿,且绝大多数开发者并未完全使用其函数。各大平台(Github ...)和框架(Bootstrap 5 ...)也都和 jQuery 逐渐告别。 16 | 17 | 在这一境况下,我决定在新项目中也不再引入 jQuery 库,而转头重写了 gQuery 这更为精小的函数库。在继承 jQuery 中的常用函数同时,拓展了许多我平时常用的操作函数。其代码大小在压缩后仅有 14kB,并完全在 MIT 下开源。 18 | 19 | 另外,大多数 jQuery 插件仅需小量修改即可适用于 gQuery。 20 | 21 | 如果不考虑兼容 IE,同时喜欢极简自由的开发,强烈建议使用 gQuery 以获得更好的体验。 22 | 23 | gQuery 及 GQUI 良好兼容 Electron 及 NW.js,并已开发过成熟商业软件。 24 | 25 | 26 | # Docs 27 | https://gquery.cn/docs/ 28 | 29 | 30 | 31 | # Let's try gQuery 32 | gQuery: 取值操作 33 | ```JavaScript 34 | let val = $('#exGetValues').text(); 35 | $('#exPutValues li:nth-child(1)').text( val ); 36 | 37 | // .text([]) 将返回有序数组 38 | val = $('#exGetValues li').text([]); 39 | $('#exPutValues li:nth-child(2)').text( val.join(',')+'。' ); 40 | 41 | $('#exPutValues li:nth-child(3)').html('—— 张爱玲'); 42 | ``` 43 | 44 | gQuery: 事件委派 45 | ```JavaScript 46 | $('#todoList').on('click', 'li', function(){ 47 | $(this).remove(); 48 | }); 49 | 50 | $('#todoList').on({ 51 | mousedown: function(e){ 52 | console.log(this, e); 53 | }, 54 | mouseup: function(e){ 55 | console.log(this, e); 56 | } 57 | }, 'li'); 58 | ``` 59 | 60 | gQuery: fade 操作 61 | ```JavaScript 62 | $('.exFadeShow').html("It's").append(''); 63 | 64 | // wait 实现更优雅的 setTimeout 65 | $('.exFadeShow').wait(500).fadeToggle(800,function(){ 66 | $(this).html('gQuery').fadeIn(800); 67 | }); 68 | ``` 69 | 70 | gQuery: slide 操作 71 | ```JavaScript 72 | $('.exSlideShow > .header > .bullets > .bg-red,.exSlideShow > .header > .bullets > .bg-green').off('click').on('click',function(){ 73 | let body = $(this).parent().parent().next(); 74 | if( $(this).hasClass('bg-red') ){ 75 | body.slideUp(300); 76 | } else { 77 | body.slideDown(300); 78 | } 79 | }); 80 | ``` 81 | 82 | ### gQuery: array{} 83 | ```JavaScript 84 | let CHAT_RECORD = [ 85 | {id:0,name:'甘大蔗',msg:'为什么会有人把大花被穿身上啊?'}, 86 | {id:1,name:'甘小蔗',msg:'小燕子穿花衣'}, 87 | {id:2,name:'甘小蔗',msg:'年年春天来这里'}, 88 | {id:3,name:'甘小蔗',msg:'我问燕子你为啥来'}, 89 | {id:4,name:'甘大蔗',msg:'呃呃'}, 90 | {id:5,name:'甘小蔗',msg:'燕子说'}, 91 | {id:6,name:'甘小蔗',msg:'“先他妈管好你自己”'}, 92 | {id:7,name:'甘大蔗',msg:'乌鱼子'}, 93 | ]; 94 | 95 | let newArr = $.array.finder(CHAT_RECORD, {name:'甘大蔗'}, {limit:2}); 96 | 97 | $('#ex-array-finder').text( JSON.stringify(newArr) ); 98 | ``` 99 | 100 | ### gQuery: cookie{} 101 | ``` 102 | $.cookie.get(key:String [, json:Boolean]) 103 | $.cookie.set(key:String, value:Mixed [, options:Object]) 104 | $.cookie.remove(key:String) 105 | ``` 106 | 107 | ### gQuery: storage{} 108 | ```JavaScript 109 | var storageEx = []; 110 | $.storage.remove('exampleData'); 111 | storageEx.push( JSON.stringify( $.storage.local() ) ); 112 | 113 | $.storage.set('exampleData',storageEx); 114 | storageEx.push( $.storage.get('exampleData') ); 115 | 116 | $.storage.set('exampleData','gQuery'); 117 | storageEx.push( $.storage.get('exampleData') ); 118 | 119 | $.storage.push('exampleData','is'); 120 | $.storage.push('exampleData','a'); 121 | $.storage.push('exampleData','Smaller and faster modern JavaScript function library'); 122 | storageEx.push( $.storage.get('exampleData') ); 123 | 124 | storageEx.push( $.storage.get('exampleData','array').join(' ') ); 125 | 126 | $('#exStorageData').html( storageEx.join('\n\n') ); 127 | ``` 128 | Result: storageEx 129 | ```javascript 130 | {"theme":"light","indexInit":"1"} 131 | 132 | ["{\"theme\":\"light\",\"indexInit\":\"1\"}"] 133 | 134 | gQuery 135 | 136 | ["gQuery","is","a","Smaller and faster modern JavaScript function library"] 137 | 138 | gQuery is a Smaller and faster modern JavaScript function library 139 | ``` 140 | 141 | ### gQuery: get{} 142 | ```javascript 143 | $.get.queryParam(name:String) 144 | $.get.browserSpec() 145 | $.get.json(url:String, data:Object) 146 | ``` 147 | 148 | ### gQuery: fetch 操作 149 | `$.fetch(url:String:Object [, data:Object, bodyMethod:String])` 150 | ```javascript 151 | $.fetch('/lib/js/gquery.ui.js', 'text').then(data => { 152 | console.log(data); 153 | }); 154 | 155 | $.fetch('/lib/json/enneagram.json', 'json').then(data=>{ 156 | console.log(data); 157 | }) 158 | 159 | $.fetch('/lib/php/user/info.php', { 160 | id: 168, 161 | token: 'a6440a91c528dadfc7d5323dc626686a' 162 | }, 'json').then(data => { 163 | console.log(data); 164 | }); 165 | ``` 166 | 167 | ### gQuery: Date 操作 168 | ```javascript 169 | let $date = $('#exDate > li'); 170 | 171 | $date.eq(0).text( $.date().format() ); 172 | 173 | $date.eq(1).text( $.date(1630862585909).format('本世纪第yy年的m月d日 hh:ii:ss') ); 174 | 175 | $date.eq(2).text( $.date('2002-2-14 2:30:00').format() ); 176 | 177 | $date.eq(3).text( $.date('-3d').calc('+4 hours').calc('-2h').format() ); 178 | 179 | $date.eq(4).text( $.date().diff('-3d').ago() ); 180 | 181 | // console.log( $.date() ) 182 | ``` 183 | 184 | ...... 185 | -------------------------------------------------------------------------------- /gquery.js: -------------------------------------------------------------------------------- 1 | // ================================================= 2 | // 3 | // gQuery.js v1.5.6 4 | // (c) 2020-present, JU Chengren (Ganxiaozhe) 5 | // Contact: hi@gxzv.com 6 | // Released under the MIT License. 7 | // gquery.cn/license 8 | // 9 | // [fn] 10 | // init,push,each,find,is,exist,eq,parent,next 11 | // text,html,ohtml,val,width,height,css,offset 12 | // remove,empty,prepend,append,before,after 13 | // attr,removeAttr,data,removeData 14 | // hasClass,addClass,removeClass,toggleClass 15 | // show,hide,animate,fadeIn,fadeOut,fadeToggle 16 | // slideUp,slideDown,slideToggle,on,one,off,trigger 17 | // click,select,load,wait 18 | // 19 | // [extend fn] 20 | // isPlainObject,isWindow,isNode 21 | // each,copy,fetch 22 | // [extend array] 23 | // unique,finder,has 24 | // [extend event] 25 | // add,remove 26 | // [extend get] 27 | // browserSpec,queryParam,json 28 | // [extend parse] 29 | // html,json 30 | // [extend cookie] 31 | // set,get,remove 32 | // [extend storage] 33 | // local,set,get,remove,clear,push 34 | // [extend sessionStorage] 35 | // local,set,get,remove,clear,push 36 | // [extend chain] 37 | // chain 38 | // [extend date] 39 | // parse,calc 40 | // [extend date prototype] 41 | // init,calc,initDate,format,diff,ago 42 | // 43 | // ================================================= 44 | ;(function(global, factory){ 45 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 46 | typeof define === 'function' && define.amd ? define(factory) : 47 | (global = window || self, global.gQuery = global.$ = factory()); 48 | 49 | if(!!window.ActiveXObject || "ActiveXObject" in window){ 50 | window.location.href = 'https://gquery.cn/kill-ie?back='+(window.location.href); 51 | } 52 | 53 | console.log('%c gQuery 1.5.6 %c gquery.cn \n','color: #fff; background: #030307; padding:5px 0; margin-top: 1em;','background: #efefef; color: #333; padding:5px 0;'); 54 | }(window, function(){ 55 | 'use strict'; 56 | let gQuery = function(selector, context){ 57 | return new gQuery.fn.init(selector, context); 58 | }; 59 | 60 | /* ------------------------------------- 61 | * gQuery - prototype chain 62 | * ------------------------------------- */ 63 | gQuery.fn = gQuery.prototype = { 64 | constructor: gQuery, 65 | gquery: '1.5.6', 66 | init: function(sel, opts){ 67 | let to = typeof sel, elems = []; 68 | switch(to){ 69 | case 'function': 70 | if (document.readyState != 'loading'){sel();} else { 71 | document.addEventListener('DOMContentLoaded', sel); 72 | } 73 | return; 74 | case 'object': 75 | if(gQuery.isWindow(sel)){elems = [window];break;} 76 | if(sel.gquery!==undefined){elems = sel;break;} 77 | 78 | if(Array.isArray(sel)){ 79 | sel.map((val)=>{ 80 | $.isNode(val) && elems.push(val); 81 | }); 82 | } else {elems.push(sel);} 83 | break; 84 | case 'string': 85 | try{elems = document.querySelectorAll(sel);} catch(err){ 86 | elems = $.parse.html(sel); 87 | }; 88 | break; 89 | } 90 | 91 | switch(opts){ 92 | case 'push': 93 | let oi = this.length; 94 | for(let i = elems.length-1; i >= 0; i--){ 95 | let rp = true; 96 | for(let ii = this.length-1; ii>=0; ii--){ 97 | this[ii]===elems[i] && (rp=false); 98 | } 99 | rp && (this.length+=1, this[oi+i] = elems[i]); 100 | } 101 | break; 102 | default: 103 | this.length = elems.length; 104 | for (let i = elems.length - 1; i >= 0; i--) {this[i] = elems[i];} 105 | } 106 | 107 | return this; 108 | }, 109 | push: function(sel){ 110 | return this.init(sel, 'push'); 111 | }, 112 | each: function(arr, callback){ 113 | callback || (callback = arr, arr = this); 114 | for(let i = 0,len = arr.length; i < len; i++){ 115 | if(callback.call(arr[i], i, arr[i-1]) == false){break;} 116 | } 117 | return this; 118 | }, 119 | /** 120 | * sel CSS3 选择器 121 | * selfContain 查询是否包含自身 122 | * onlyChildren 只查询子元素 123 | */ 124 | find: function(sel, selfContain, onlyChildren){ 125 | let finder = Object.create(this), fArr = [], i; 126 | this.each(function(idx){ 127 | if(!$.isNode(this)){return;} 128 | selfContain && $(this).is(sel) && fArr.push(this); 129 | 130 | let elems = onlyChildren ? this.children : this.querySelectorAll(sel); 131 | for (i = 0; i < elems.length; i++) { 132 | if(onlyChildren && !$(elems[i]).is(sel)){ 133 | continue; 134 | } 135 | fArr.push(elems[i]); 136 | } 137 | }); 138 | 139 | fArr = $.array.unique(fArr); 140 | finder.length = fArr.length; 141 | for (i = fArr.length - 1; i >= 0; i--) {finder[i] = fArr[i];} 142 | return finder; 143 | }, 144 | is: function(sel){ 145 | let r = false; 146 | this.each(function(idx){ 147 | let _mat = ( 148 | this.matches || this.matchesSelector || 149 | this.msMatchesSelector || this.mozMatchesSelector || 150 | this.webkitMatchesSelector || this.oMatchesSelector 151 | ); 152 | if(typeof _mat==='function' && _mat.call(this, sel)){r = true;return false;} 153 | }); 154 | return r; 155 | }, 156 | exist: function(){ 157 | let r = false; 158 | this.each(function(idx){ 159 | if(document.body.contains(this)){r = true;return false;} 160 | }); 161 | return r; 162 | }, 163 | eq: function(idx){return $(this[idx]);}, 164 | parent: function(sel, force){ 165 | let finder = Object.create(this), fArr = [], i; 166 | this.each(function(idx){ 167 | let node = this.parentNode; 168 | while(sel && node && !$(node).is(sel)){ 169 | if(!force){ 170 | node = undefined;break; 171 | } 172 | node = node.parentNode; 173 | } 174 | node&&fArr.push(node); 175 | }); 176 | 177 | fArr = $.array.unique(fArr); 178 | finder.length = fArr.length; 179 | for (i = fArr.length - 1; i >= 0; i--) {finder[i] = fArr[i];} 180 | return finder; 181 | }, 182 | next: function(sel){ 183 | let finder = Object.create(this), fArr = [], elem, i; 184 | this.each(function(idx){ 185 | elem = this.nextElementSibling; 186 | if( elem!==null && (!sel || elem.matches(sel)) ){ 187 | fArr.push(elem); 188 | } 189 | delete finder[idx]; 190 | }); 191 | 192 | fArr = $.array.unique(fArr); 193 | finder.length = fArr.length; 194 | for (i = fArr.length - 1; i >= 0; i--) {finder[i] = fArr[i];} 195 | return finder; 196 | }, 197 | remove: function(sel, onlyChildren){ 198 | onlyChildren===undefined && (onlyChildren=false); 199 | let rthis = ( sel === undefined ? this : this.find(sel, false, onlyChildren) ); 200 | rthis.each(function(){ 201 | if(this.parentNode===null){return true;} 202 | this.parentNode.removeChild(this); 203 | }); 204 | return this; 205 | }, 206 | empty: function(sel){ 207 | let rthis = ( sel === undefined ? this : this.find(sel) ); 208 | return rthis.each(function(){ 209 | while(this.firstChild){this.removeChild(this.firstChild);} 210 | }); 211 | }, 212 | text: function(val){ 213 | return gqHandle.thvEach.call(this,'innerText',val); 214 | }, 215 | html: function(val){ 216 | return gqHandle.thvEach.call(this,'innerHTML',val); 217 | }, 218 | val: function(val){ 219 | return gqHandle.thvEach.call(this,'value',val); 220 | }, 221 | ohtml: function(val){ 222 | return gqHandle.thvEach.call(this,'outerHTML',val); 223 | }, 224 | width: function(val){ 225 | if(val!==undefined){ 226 | isNaN(val) || (val += 'px'); 227 | return this.each(function(){this.style.width = val;}); 228 | } 229 | 230 | let totalWidth = [], iw; 231 | this.each(function(){ 232 | iw = this.offsetWidth; 233 | if(iw===undefined){ 234 | iw = typeof this.getBoundingClientRect==='function' ? this.getBoundingClientRect().width.toFixed(2) : 0; 235 | } 236 | totalWidth.push(parseFloat(iw)); 237 | }); 238 | return (totalWidth.length>1 ? totalWidth : totalWidth[0]); 239 | }, 240 | height: function(val){ 241 | if(val!==undefined){ 242 | isNaN(val) || (val += 'px'); 243 | return this.each(function(){this.style.height = val;}); 244 | } 245 | 246 | let totalHeight = [], ih; 247 | this.each(function(){ 248 | ih = this.offsetHeight; 249 | if(ih===undefined){ 250 | ih = typeof this.getBoundingClientRect==='function' ? this.getBoundingClientRect().height.toFixed(2) : 0; 251 | } 252 | totalHeight.push(parseFloat(ih)); 253 | }); 254 | return (totalHeight.length>1 ? totalHeight : totalHeight[0]); 255 | }, 256 | offset: function(opts){ 257 | if(typeof opts === 'object'){ 258 | return this.each(function(){ 259 | for(let key in opts){ 260 | isNaN(opts[key]) || (opts[key]+='px'); 261 | this.style[key] = opts[key]; 262 | } 263 | }); 264 | } 265 | 266 | let rect = this[0].getBoundingClientRect(), spos = { 267 | top: document.body.scrollTop==0?document.documentElement.scrollTop:document.body.scrollTop, 268 | left: document.body.scrollLeft==0?document.documentElement.scrollLeft:document.body.scrollLeft 269 | }; 270 | // true 271 | opts && (spos.top=0, spos.left=0); 272 | 273 | let $this = $(this[0]); 274 | let data = { 275 | top: rect.top + spos.top, 276 | left: rect.left + spos.left, 277 | height: $this.height(), 278 | width: $this.width(), 279 | }; 280 | let wrapH = opts ? window.innerHeight : document.body.offsetHeight, 281 | wrapW = opts ? window.innerWidth : document.body.offsetWidth; 282 | data.bottom = wrapH - data.top - data.height; 283 | data.right = wrapW - data.left - data.width; 284 | 285 | return data; 286 | }, 287 | append: function(elem){ 288 | return gqHandle.pend.call(this, 'appendChild', elem); 289 | }, 290 | prepend: function(elem){ 291 | return gqHandle.pend.call(this, 'insertBefore', elem); 292 | }, 293 | insertBefore: function(elem){ 294 | return gqHandle.pend.call($(elem), 'before', this); 295 | }, 296 | before: function(elem){ 297 | return gqHandle.pend.call(this, 'before', elem); 298 | }, 299 | after: function(elem){ 300 | return gqHandle.pend.call(this, 'after', elem); 301 | }, 302 | attr: function(attrs, val){ 303 | if(val === undefined && typeof attrs === 'string') { 304 | let resArr = [], attr;this.each(function(){ 305 | attr = this.getAttribute(attrs);attr===null&&(attr=undefined); 306 | resArr.push( attr ); 307 | }); 308 | return (resArr.length>1 ? resArr : resArr[0]); 309 | } 310 | 311 | if(typeof attrs === 'object'){ 312 | return this.each(function(){ 313 | for(let idx in attrs){ 314 | this.setAttribute&&this.setAttribute(idx, attrs[idx]); 315 | } 316 | }); 317 | } 318 | return this.each(function(){ 319 | this.setAttribute&&this.setAttribute(attrs, val); 320 | }); 321 | }, 322 | removeAttr: function(attr){ 323 | attr = attr.split(' '); 324 | return this.each(function(){ 325 | attr.map(v=>this.removeAttribute(v)); 326 | }); 327 | }, 328 | data: function(keys, val){ 329 | if(typeof keys !== 'object' && val === undefined) { 330 | let resArr = [];this.each(function(){ 331 | this.gQueryData===undefined&&(this.gQueryData={}); 332 | typeof keys === 'string' ? resArr.push( this.gQueryData[keys] ) : resArr.push( this.gQueryData ); 333 | }); 334 | return (resArr.length>1 ? resArr : resArr[0]); 335 | } 336 | 337 | return this.each(function(){ 338 | this.gQueryData===undefined&&(this.gQueryData={}); 339 | if(typeof keys === 'object'){ 340 | for(let idx in keys){this.gQueryData[idx] = keys[idx];} 341 | } else {this.gQueryData[keys] = val;} 342 | }); 343 | }, 344 | removeData: function(key){ 345 | return this.each(function(){ 346 | this.gQueryData===undefined&&(this.gQueryData={}); 347 | delete this.gQueryData[key]; 348 | }); 349 | }, 350 | hasClass: function(cls){ 351 | cls = cls.split(' '); 352 | let res = true; 353 | this.each(function(){ 354 | cls.map(v=>{ 355 | this.classList.contains(v) || (res = false); 356 | }); 357 | }); 358 | return res; 359 | }, 360 | addClass: function(cls){ 361 | cls = cls.split(' '); 362 | return this.each(function(){ 363 | cls.map(v=>this.classList.add(v)); 364 | }); 365 | }, 366 | removeClass: function(cls){ 367 | cls = cls.split(' '); 368 | return this.each(function(){ 369 | cls.map(v=>this.classList.remove(v)); 370 | }); 371 | }, 372 | toggleClass: function(cls){ 373 | cls = cls.split(' '); 374 | return this.each(function(){ 375 | cls.map(v=>this.classList.toggle(v)); 376 | }); 377 | }, 378 | css: function(styles, val){ 379 | if(val !== undefined){ 380 | return this.each(function(){ 381 | setProperty(this, styles, val); 382 | }); 383 | } 384 | 385 | if(typeof styles === 'string'){ 386 | let _css, resArr=[]; 387 | this.each(function(){ 388 | resArr.push( getComputedStyle(this)[styles] ); 389 | }); 390 | return (resArr.length>1 ? resArr : resArr[0]); 391 | } 392 | 393 | return this.each(function(){ 394 | for(let style in styles){ 395 | setProperty(this, style, styles[style]); 396 | } 397 | }); 398 | 399 | function setProperty(obj, prop, val){ 400 | let re = /!important\s?$/, thr = ''; 401 | re.test(val) && (thr = 'important', val = val.replace(re, '')); 402 | obj.style.setProperty(prop, val, thr); 403 | } 404 | }, 405 | show: function(disp){ 406 | return this.each(function(){ 407 | this.style.display = ''; 408 | if(getComputedStyle(this)['display'] == 'none'){ 409 | this.style.display = disp||'block'; 410 | } 411 | }); 412 | }, 413 | hide: function(){ 414 | return this.each(function(){this.style.display='none'}); 415 | }, 416 | 417 | animate: function(props, opts, callback){ 418 | typeof opts === undefined && (opts = 500); 419 | if(typeof opts!=='object'){ 420 | opts = {duration:parseInt(opts)}; 421 | } 422 | opts.duration || (opts.duration = 500); 423 | opts.timing || (opts.timing = 'linear'); 424 | opts.delay || (opts.delay = 0); 425 | 426 | return this.each(function(){ 427 | let ani = { 428 | elem:this, 429 | callback:callback, 430 | 431 | props:props, 432 | calc:$.animation.preCalc(props, this), 433 | 434 | opts:opts, 435 | start:null 436 | }; 437 | 438 | function add(){ 439 | $.animation.array.push(ani); 440 | $.animation.start(); 441 | }; 442 | opts.delay>0 ? setTimeout(add, opts.delay) : add(); 443 | }); 444 | }, 445 | stop: function(){ 446 | return this.each(function(){ 447 | this.__gQueryStop = true; 448 | }); 449 | }, 450 | 451 | fadeIn: function(dur, callback){ 452 | dur || (dur=500); 453 | 454 | return this.each(function(){ 455 | $(this).show().stop().animate({opacity:1}, dur, function(){ 456 | callback && callback.call(this); 457 | }); 458 | }); 459 | }, 460 | fadeOut: function(dur, callback){ 461 | dur || (dur=500); 462 | 463 | return this.each(function(){ 464 | $(this).stop().animate({opacity:0}, dur, function(){ 465 | this.style.display = 'none'; 466 | callback && callback.call(this); 467 | }); 468 | }); 469 | }, 470 | fadeToggle: function(dur, callback){ 471 | dur || (dur=500); 472 | typeof callback === 'function' || (callback=function(){}); 473 | 474 | return this.each(function(){ 475 | this.style.display=='none' ? $(this).fadeIn(dur, callback) : $(this).fadeOut(dur, callback); 476 | }); 477 | }, 478 | slideUp: function(dur, callback){ 479 | dur || (dur=500); 480 | 481 | return this.each(function(){ 482 | $(this).stop().animate({height:'0px'}, dur, function(){ 483 | this.style.display = 'none'; 484 | callback && callback.call(this); 485 | }); 486 | }); 487 | }, 488 | slideDown: function(dur, callback){ 489 | dur || (dur=500); 490 | 491 | return this.each(function(){ 492 | let orgHeight = $(this).css('height'); 493 | let $that = $(this).css({display:'', height:''}); 494 | let newHeight = this.offsetHeight; 495 | this.style.height = orgHeight; 496 | $that.stop().animate({height:newHeight+'px'}, dur, function(){ 497 | callback && callback.call(this); 498 | }); 499 | }); 500 | }, 501 | slideToggle: function(dur, callback){ 502 | dur || (dur=500);typeof callback === 'function' || (callback=function(){}); 503 | 504 | return this.each(function(){ 505 | this.style.display=='none' ? $(this).slideDown(dur, callback) : $(this).slideUp(dur, callback); 506 | }); 507 | }, 508 | on: function(evtName, selector, fn, opts){ 509 | [evtName, selector, fn, opts] = gqHandle.onArgs(arguments); 510 | 511 | // 处理事件委托 512 | if(selector){ 513 | opts.capture===undefined&&(opts.capture=true); 514 | } 515 | let appoint = function(inFn, name){ 516 | let isMouse = $.array.finder([ 517 | // 不包括 mousedown\mouseup\touchstart\touchend 518 | 'mouseenter','mouseleave', 519 | 'mousemove','mouseover','mouseout' 520 | ], name); 521 | 522 | return selector ? function(e){ 523 | let nodes = this.querySelectorAll(selector), 524 | tgtNode = false, i; 525 | 526 | for (i = nodes.length - 1; i >= 0; i--) { 527 | if(tgtNode!==false){break;} 528 | if(isMouse){ 529 | nodes[i]===e.target && (tgtNode = nodes[i]); 530 | } else { 531 | nodes[i].contains(e.target) && (tgtNode = nodes[i]); 532 | } 533 | } 534 | tgtNode && ( inFn.call(tgtNode, e) ); 535 | } : inFn; 536 | }, cfn; 537 | 538 | if(typeof fn === 'function'){ 539 | cfn = appoint(fn, evtName); 540 | return this.each(function(){ 541 | $.event.add(this, evtName, cfn, opts); 542 | }); 543 | } 544 | 545 | return this.each(function(){ 546 | for(let evt in evtName){ 547 | cfn = appoint(evtName[evt], evt); 548 | $.event.add(this, evt, cfn, opts); 549 | } 550 | }); 551 | }, 552 | one: function(evtName, selector, fn, opts){ 553 | [evtName, selector, fn, opts] = gqHandle.onArgs(arguments); 554 | opts.once = true; 555 | return this.on(evtName, selector, fn, opts); 556 | }, 557 | off: function(evts, opts){ 558 | opts===undefined && (opts = false); 559 | evts || (evts='*'); 560 | evts = evts.split(' '); 561 | 562 | return this.each(function(){ 563 | evts.map(evt=>$.event.remove(this, evt, opts)); 564 | }); 565 | }, 566 | trigger: function(evts, params){ 567 | params || (params={}); 568 | evts = evts.split(' '); 569 | let ctmEvts = evts.map(name=>new CustomEvent(name, {detail: params})); 570 | 571 | return this.each(function(){ 572 | ctmEvts.map(evt=>this.dispatchEvent(evt)); 573 | }); 574 | }, 575 | click: function(fn){ 576 | if(typeof fn === 'function'){ 577 | return this.each(function(){$.event.add(this,'click',fn);}); 578 | } else { 579 | return this.trigger('click'); 580 | } 581 | }, 582 | select: function(){ 583 | switch( this[0].tagName.toLowerCase() ){ 584 | case 'input':case 'textarea': 585 | this[0].select();break; 586 | default:window.getSelection().selectAllChildren(this[0]); 587 | } 588 | return this; 589 | }, 590 | /** 591 | * load('https://gquery.cn #hero') 592 | */ 593 | load: function(url, data, func){ 594 | let _this = this, up = url.trim().split(' '); 595 | typeof data === 'function' && (func=data, data=false); 596 | 597 | $.fetch(up[0], data, 'text').then(function(resp){ 598 | if(up.length>1){ 599 | up.splice(0, 1); 600 | _this.html( $(resp).find(up.join(' '), true).html() ); 601 | } else { 602 | _this.html( resp ); 603 | } 604 | typeof func === 'function' && func.call( _this ); 605 | }); 606 | }, 607 | extend: function(obj){ 608 | for(let idx in obj){ 609 | typeof obj[idx] === "object" ? 610 | this[idx] = $.extend(true, this[idx], obj[idx]) : 611 | this[idx] = obj[idx]; 612 | } 613 | return this; 614 | } 615 | }; 616 | gQuery.fn.init.prototype = gQuery.fn; 617 | 618 | 619 | let gqHandle = { 620 | thvEach: function(prop, val){ 621 | let isArr = Array.isArray(val); 622 | 623 | if(val === undefined || (isArr && val.length==0) ) { 624 | let resArr = []; 625 | this.each(function(){ 626 | resArr.push(this[prop]); 627 | }); 628 | return (isArr ? resArr : resArr.join('')); 629 | } 630 | 631 | return isArr ? this.each(function(idx){ 632 | this[prop] = val[idx]; 633 | }) : this.each(function(){this[prop] = val;}); 634 | }, 635 | pend: function(prop, elem){ 636 | let elems = typeof elem === 'string' ? $.parse.html(elem) : ( 637 | elem.gquery ? elem : [elem] 638 | ); 639 | 640 | return this.each(function(){ 641 | let elen = elems.length, i, el; 642 | 643 | for(i = 0; i < elen; i++){ 644 | el = elems[i].cloneNode(true); 645 | prop=='insertBefore' ? this[prop](el, this.firstChild) : this[prop](el); 646 | } 647 | }); 648 | }, 649 | 650 | onArgs: function(args){ 651 | let evtName = args[0], selector = args[1], fn = args[2], opts = args[3]; 652 | 653 | (args.length==3 && typeof fn !== 'function') && (opts = fn,fn = selector,selector = false); 654 | if(args.length==2){ 655 | if(typeof selector === 'function'){ 656 | fn = selector, selector = false; 657 | } else if(typeof selector === 'object'){opts = selector, selector = false;} 658 | } 659 | typeof opts === 'object' || (opts={}); 660 | 661 | return [evtName, selector, fn, opts]; 662 | } 663 | }; 664 | 665 | 666 | 667 | /** 668 | * gQuery wait 669 | * @author Matthew Lee matt@madleedesign.com 670 | * @author Ganxiaozhe hi@gxzv.com 671 | */ 672 | function gQueryDummy($real, delay, _fncQueue){ 673 | let dummy = this; 674 | this._fncQueue = (typeof _fncQueue === 'undefined') ? [] : _fncQueue; 675 | this._delayCompleted = false; 676 | this._$real = $real; 677 | 678 | // 1: $(sel).fn().wait(ms).fn(); 679 | // 2: $(sel).fn().wait(promise).fn(); 680 | // 3: $(sel).fn().wait(event).fn(); 681 | if (typeof delay === 'number' && delay >= 0 && delay < Infinity){ 682 | this.timeoutKey = window.setTimeout(function(){ 683 | dummy._performDummyQueueActions(); 684 | }, delay); 685 | } else if (delay !== null && typeof delay === 'object' && typeof delay.promise === 'function'){ 686 | delay.then(function(){ 687 | dummy._performDummyQueueActions(); 688 | }); 689 | } else if (typeof delay === 'string'){ 690 | $real.one(delay, function(){ 691 | dummy._performDummyQueueActions(); 692 | }); 693 | } else return $real; 694 | } 695 | 696 | gQueryDummy.prototype._addToQueue = function(fnc, arg){ 697 | // 当影子函数被调用时,将函数名称及参数放入队列以便稍后执行 698 | this._fncQueue.unshift({fnc: fnc, arg: arg}); 699 | 700 | if (this._delayCompleted){ 701 | return this._performDummyQueueActions(); 702 | } else {return this;} 703 | }; 704 | 705 | gQueryDummy.prototype._performDummyQueueActions = function(){ 706 | // 列队操作 707 | // 若遇到另一个 “wait”,则将剩余堆栈传递给新的 gQueryDummy 708 | this._delayCompleted = true; 709 | 710 | let next; 711 | while (this._fncQueue.length > 0){ 712 | next = this._fncQueue.pop(); 713 | 714 | if (next.fnc === 'wait') { 715 | next.arg.push(this._fncQueue); 716 | return this._$real = this._$real[next.fnc].apply(this._$real, next.arg); 717 | } 718 | 719 | this._$real = this._$real[next.fnc].apply(this._$real, next.arg); 720 | } 721 | 722 | return this; 723 | }; 724 | 725 | 726 | gQuery.fn.wait = function(delay, _queue){ 727 | return new gQueryDummy(this, delay, _queue); 728 | }; 729 | gQuery.waitUpdate = function(){ 730 | // 为 gQueryDummy 添加 gQuery 的所有的方法 731 | // 跳过非函数方法和 Object.prototype 732 | for (let fnc in gQuery.fn){ 733 | if (typeof gQuery.fn[fnc] !== 'function' || !gQuery.fn.hasOwnProperty(fnc)){ 734 | continue; 735 | } 736 | 737 | gQueryDummy.prototype[fnc] = (function(fnc){ 738 | return function(){ 739 | let arg = Array.prototype.slice.call(arguments); 740 | return this._addToQueue(fnc, arg); 741 | }; 742 | })(fnc); 743 | }; 744 | }; 745 | gQuery.waitUpdate(); 746 | 747 | 748 | 749 | 750 | gQuery.debugger = false; 751 | /* ------------------------------------- 752 | * gQuery - extend 753 | * ------------------------------------- */ 754 | gQuery.extend = function(obj){ 755 | if(arguments.length==1){ 756 | for(let idx in obj){ 757 | typeof obj[idx] === "object" ? 758 | this[idx] = $.extend(true, this[idx], obj[idx]) : 759 | this[idx] = obj[idx]; 760 | } 761 | gQuery.waitUpdate(); 762 | return this; 763 | } 764 | 765 | let deep = false, length = arguments.length, i = 1, 766 | name, options, src, copy, clone, copyIsArray, 767 | target = arguments[0] || {}; 768 | if (typeof target == 'boolean') { 769 | deep = target;target = arguments[i] || {};i++; 770 | } 771 | if (typeof target !== "object") {target = {};} 772 | 773 | for (; i < length; i++) { 774 | options = arguments[i]; 775 | if(options == null){continue;} 776 | 777 | for (name in options) { 778 | src = target[name]; 779 | copy = options[name]; 780 | 781 | // 解决循环引用 782 | if (target === copy) {continue;} 783 | // 要递归的对象必须是 plainObject 或者数组 784 | if ( deep && copy && (gQuery.isPlainObject(copy) || (copyIsArray = Array.isArray(copy))) ) { 785 | // 要复制的对象属性值类型需要与目标属性值相同 786 | if (copyIsArray) { 787 | copyIsArray = false; 788 | clone = src && Array.isArray(src) ? src : []; 789 | } else { 790 | clone = src && gQuery.isPlainObject(src) ? src : {}; 791 | } 792 | target[name] = gQuery.extend(deep, clone, copy); 793 | } else if (copy !== undefined) { 794 | target[name] = copy; 795 | } 796 | } 797 | } 798 | return target; 799 | }; 800 | 801 | 802 | gQuery.each = function(object, callback){ 803 | if(typeof object === 'object'){ 804 | for(let i in object){ 805 | if(callback.call(object[i], i, object[i]) === false){ 806 | break; 807 | } 808 | } 809 | return true; 810 | } 811 | 812 | [].every.call(object, function(v, i){ 813 | return callback.call(v, i, v) === false ? false : true; 814 | }); 815 | }; 816 | gQuery.copy = function(str){ 817 | if(typeof str==='object'){str = $(str).text();} 818 | 819 | $('body').append(""); 820 | $('#gQuery-copyTemp').select();document.execCommand("Copy"); 821 | $('#gQuery-copyTemp').remove(); 822 | }; 823 | 824 | /** 825 | * Fetch 826 | * @url 传入请求地址:String或请求实例:Object 827 | * @data 传入 String 或 Object 828 | * @bodyMH 对 Response 的解析方法:String 829 | */ 830 | gQuery.fetch = function(url, data, bodyMH){ 831 | let _mh = {method: 'GET'}; 832 | typeof url === 'object' && (_mh = $.extend(_mh, url), url = url.url); 833 | 834 | if(typeof data === 'object'){ 835 | _mh.method = 'POST'; 836 | if(Object.prototype.toString.call(data)=='[object FormData]'){ 837 | _mh.body = data; 838 | } else { 839 | _mh.body = new FormData(); 840 | for(let nm in data){_mh.body.append(nm, data[nm]);} 841 | } 842 | } else if(typeof data === 'string'){ 843 | typeof bodyMH === 'string' ? (_mh.method = 'POST', _mh.body = data) : (bodyMH = data); 844 | } 845 | 846 | if(!bodyMH){return fetch(url, _mh);} 847 | let copyRes; 848 | return fetch(url, _mh).then(res => { 849 | if(!res.ok){throw new Error('Network response was not ok.');} 850 | gQuery.debugger && (copyRes = res.clone()); 851 | return res[bodyMH](); 852 | }).catch(err => { 853 | if(copyRes && copyRes.ok){ 854 | copyRes.text().then(rsp=>{ 855 | console.error(rsp); 856 | }); 857 | } 858 | throw new Error(err); 859 | }); 860 | }; 861 | gQuery.global = (typeof window !== 'undefined' ? window : global); 862 | gQuery.isWindow = function(obj){ 863 | return Object.prototype.toString.call(obj)==='[object Window]'; 864 | }; 865 | gQuery.isNode = function(obj){ 866 | let str = Object.prototype.toString.call(obj); 867 | return (str.indexOf('HTML')>-1 && str.indexOf('Element')>-1) ? true : false; 868 | }; 869 | gQuery.isPlainObject = function(obj){ 870 | let prototype; 871 | 872 | return Object.prototype.toString.call(obj) === '[object Object]' 873 | && (prototype = Object.getPrototypeOf(obj), prototype === null || 874 | prototype == Object.getPrototypeOf({})); 875 | }; 876 | gQuery.ui = "Missing gQuery UI components."; 877 | 878 | 879 | /** ------------------------------------- 880 | * Array 881 | * ------------------------------------- */ 882 | gQuery.array = { 883 | unique: function(arr, typ){ 884 | let j = {}; 885 | if( typ=='node' || $.isNode(arr[0]) ){ 886 | return arr.filter(function(item, index, arr) { 887 | return arr.indexOf(item, 0) === index; 888 | }); 889 | } 890 | 891 | arr.forEach(function(v){ 892 | let vtyp = typeof v, vv=v; 893 | if(vtyp==='object'){v = JSON.stringify(v);} 894 | j[v + '::' + vtyp] = vv; 895 | }); 896 | return Object.keys(j).map(function(v){return j[v];}); 897 | }, 898 | finder: function(arr, finder, opts){ 899 | typeof opts === 'object' || (opts = {}); 900 | opts.limit === undefined && (opts.limit=1); 901 | 902 | let isObj = (typeof finder === 'object'), resame, resArr = []; 903 | for (let i = 0; i < arr.length; i++) { 904 | if(isObj){ 905 | resame = true; 906 | for(let obj in finder){ 907 | arr[i][obj]==finder[obj] || (resame = false); 908 | } 909 | resame && resArr.push( {index:i, array:arr[i]} ); 910 | 911 | if(opts.limit>0 && resArr.length>=opts.limit){break;} 912 | } else { 913 | arr[i]==finder && resArr.push( {index:i,array:arr[i]} ); 914 | if(opts.limit>0 && resArr.length>=opts.limit){break;} 915 | } 916 | } 917 | 918 | if(opts.array){return resArr;} 919 | return resArr.length>1 ? resArr : resArr[0]; 920 | }, 921 | has: function(arr, finder){ 922 | let fdr = this.finder(arr, finder); 923 | return fdr!==undefined; 924 | } 925 | }; 926 | 927 | gQuery.event = { 928 | add: function(obj, name, fn, opts){ 929 | typeof opts === 'object' || (opts={}); 930 | opts.capture === undefined && (opts.capture=false); 931 | 932 | let flag = name.split('.'); 933 | let evtName = flag.splice(0,1); 934 | flag.length>0 && (opts.__flag = {}); 935 | flag.map(f=>{opts.__flag[f]=true;}); 936 | 937 | let fnDummy = function(e){ 938 | if(opts.once===true){ 939 | $.event.remove(obj, name, opts); 940 | } 941 | return fn.call(obj, e); 942 | }; 943 | 944 | let events = obj.gQueryEvents, evtObj = {fn:fnDummy, opts:opts}; 945 | if(events===undefined){ 946 | events = {[evtName]:[ evtObj ]}; 947 | } else { 948 | if(typeof events[evtName] !== 'object'){ 949 | events[evtName] = [evtObj]; 950 | } else { 951 | events[evtName].push(evtObj); 952 | } 953 | } 954 | 955 | obj.gQueryEvents = events; 956 | let event = events[evtName][ events[evtName].length-1 ]; 957 | obj.addEventListener(evtName, event.fn, event.opts); 958 | }, 959 | remove: function(obj, evtName, opts){ 960 | let events = obj.gQueryEvents, flag = evtName.split('.'), i; 961 | evtName = flag.splice(0, 1); 962 | if(events===undefined){return;} 963 | if(evtName=='*'){ 964 | Object.keys(events).map(evt=>revent(evt, true));return; 965 | } 966 | 967 | if(typeof events[evtName]!=='object'){return;} 968 | revent(evtName); 969 | 970 | function revent(evt, forceFilter){ 971 | let fns = events[evt]; 972 | for (i = fns.length - 1; i >= 0; i--) { 973 | /* 974 | * 默认过滤状态; 975 | * 传入 flag 时,过滤无 flag 的对象,留下有 flag 的对象; 976 | * 未传入 flag 时,过滤有 flag 的对象,留下无 flag 的对象。 977 | */ 978 | if(!forceFilter){ 979 | let filter=1, flagO=fns[i].opts.__flag || {}; 980 | if(flag.length<1 && Object.keys(flagO).length<1){filter=0;} 981 | flag.map(f=>{flagO[f] && (filter=0);}); 982 | if(filter){continue;} 983 | } 984 | 985 | obj.removeEventListener(evt, fns[i].fn, fns[i].opts); 986 | events[evt].splice(i, 1); 987 | events[evt].length<1 && (delete events[evt]); 988 | } 989 | } 990 | } 991 | }; 992 | 993 | /** ------------------------------------- 994 | * Get 995 | * ------------------------------------- */ 996 | gQuery.get = { 997 | browserSpec: function(){ 998 | let ua = navigator.userAgent, tem, 999 | M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; 1000 | 1001 | if(/trident/i.test(M[1])){ 1002 | tem = /\brv[ :]+(\d+)/g.exec(ua) || []; 1003 | return {name:'IE',version:(tem[1] || '')}; 1004 | } 1005 | if(M[1]=== 'Chrome'){ 1006 | tem = ua.match(/\b(OPR|Edge)\/(\d+)/); 1007 | if(tem != null) return {name:tem[1].replace('OPR', 'Opera'),version:tem[2]}; 1008 | } 1009 | M = M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?']; 1010 | 1011 | if((tem = ua.match(/version\/(\d+)/i))!= null){M.splice(1, 1, tem[1]);} 1012 | return { 1013 | name: M[0], version: M[1], 1014 | isMobile: /Mobi/i.test(ua), 1015 | touchPoints: (navigator.maxTouchPoints || 'ontouchstart' in document.documentElement || 0) 1016 | }; 1017 | }, 1018 | queryParam: function(href, name){ 1019 | name===undefined && (name = href, href=window.location.href); 1020 | if(href.indexOf('?')<0){return null;} 1021 | 1022 | let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'), 1023 | res = href.replace(/.*?\?/g, '').match(reg); 1024 | if(res != null){return decodeURI(res[2]);} 1025 | return null; 1026 | }, 1027 | json: function(url, data){ 1028 | return $.fetch(url, data, 'text').then(data => { 1029 | return $.parse.json(data); 1030 | }); 1031 | } 1032 | }; 1033 | 1034 | /** ------------------------------------- 1035 | * Parse 1036 | * ------------------------------------- */ 1037 | gQuery.parse = { 1038 | html: function(html){ 1039 | if(typeof html === 'string'){ 1040 | let template = document.createElement('template'); 1041 | template.innerHTML = html; 1042 | return template.content.childNodes; 1043 | } 1044 | return html; 1045 | }, 1046 | json: function(str){ 1047 | if(typeof str === 'object'){return str;} 1048 | if(str===''){return {};} 1049 | 1050 | let json; 1051 | try{json = JSON.parse(str);} catch(err){} 1052 | try{ 1053 | if(!json){json = Function('"use strict";return (' + str + ')')();} 1054 | } catch(err){throw new Error(err);} 1055 | 1056 | return json; 1057 | }, 1058 | number: function(str){ 1059 | return ( 1060 | typeof str === 'string' ? parseInt( str.replace(/[^\d]/g,'') ) : str 1061 | ); 1062 | } 1063 | }; 1064 | 1065 | /** ------------------------------------- 1066 | * Cookie 1067 | * ------------------------------------- */ 1068 | gQuery.cookie = { 1069 | get: function(key, json){ 1070 | let jar = {}, i = 0, 1071 | cookies = document.cookie ? document.cookie.split('; ') : []; 1072 | function decode(s){return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);} 1073 | 1074 | for (; i < cookies.length; i++) { 1075 | let parts = cookies[i].split('='); 1076 | let cookie = parts.slice(1).join('='); 1077 | if (!json && cookie.charAt(0) === '"') {cookie = cookie.slice(1, -1);} 1078 | 1079 | try { 1080 | let name = decode(parts[0]);cookie = decode(cookie); 1081 | 1082 | if(json){try {cookie = JSON.parse(cookie);} catch(e){}} 1083 | jar[name] = cookie; 1084 | 1085 | if(key === name){break;} 1086 | } catch (e) {} 1087 | } 1088 | 1089 | return key ? jar[key] : jar; 1090 | }, 1091 | set: function(key, value, attrs){ 1092 | attrs = $.extend({path: '/'}, attrs); 1093 | if (typeof attrs.expires === 'number') { 1094 | attrs.expires = new Date(new Date() * 1 + attrs.expires * 864e+5); 1095 | } 1096 | attrs.expires = attrs.expires ? attrs.expires.toUTCString() : ''; 1097 | 1098 | let stringifiedAttrs = ''; 1099 | for (let attrName in attrs) { 1100 | if (!attrs[attrName]) {continue;} 1101 | stringifiedAttrs += '; ' + attrName; 1102 | 1103 | if (attrs[attrName] === true) {continue;} 1104 | stringifiedAttrs += '=' + String(attrs[attrName]).split(';')[0]; 1105 | } 1106 | 1107 | typeof value==='object' && (value = JSON.stringify(value)); 1108 | return (document.cookie = key + '=' + value + stringifiedAttrs); 1109 | }, 1110 | remove: function(key, attrs){ 1111 | $.cookie.set(key, '', $.extend(attrs, {expires: -1})); 1112 | } 1113 | }; 1114 | 1115 | /** ------------------------------------- 1116 | * Storage 1117 | * ------------------------------------- */ 1118 | gQuery.storage = { 1119 | IKEY: '$$GQ$EXP$$', 1120 | local: function(){return $.global.localStorage}, 1121 | set: function(key, data, expires){ 1122 | (typeof data=='object') && (data = JSON.stringify(data)); 1123 | 1124 | if(expires!==undefined){ 1125 | let ts = $.date.parse(expires).getTime(); 1126 | data = ts+this.IKEY+data; 1127 | } 1128 | 1129 | this.local().setItem(key, data); 1130 | }, 1131 | get: function(key, typ){ 1132 | let data = this.local().getItem(key); 1133 | if(data===null){return null;} 1134 | 1135 | // expire 1136 | let index = data.indexOf(this.IKEY); 1137 | if(index>-1){ 1138 | let ts = parseInt( data.substr(0, index) ); 1139 | // 对比数据是否过期 1140 | if(ts{ 1196 | let valTo = this.toCalc(_k); 1197 | if(valTo===false){return true;} 1198 | let suffix = this.getPrefix(_k); 1199 | 1200 | // 确定该元素有相应 prop 1201 | let prop = elem.style[_i]; 1202 | if(prop===undefined){return true;} 1203 | if(prop===''){prop = getComputedStyle(elem)[_i];} 1204 | let valFrom = this.toCalc(prop); 1205 | 1206 | /** 1207 | * 后缀转换 1208 | * 原属性:200px 1209 | * 目标:80vw 1210 | * 转换:设置为100vw,获取t_px,得200px/t_px(vw) 1211 | */ 1212 | let ogPrefix = this.getPrefix(prop); 1213 | if(suffix!=ogPrefix){ 1214 | elem.style[_i] = '100'+suffix; 1215 | let t_prop = getComputedStyle(elem)[_i]; 1216 | // TODO: em/rem 等非百分比值的测试 1217 | valFrom = valFrom/this.toCalc(t_prop)*100; 1218 | elem.style[_i] = prop; 1219 | } 1220 | 1221 | _props[_i] = { 1222 | from:valFrom, to:valTo, 1223 | suffix:suffix 1224 | }; 1225 | }); 1226 | return _props; 1227 | }, 1228 | toCalc:function(_k){ 1229 | if(_k===''){return false;} 1230 | if(isNaN(_k)){ 1231 | if(!/^[-\d]/.test(_k) || _k.lastIndexOf('-')>0){return false;} 1232 | _k = _k.replace(/[^-.\d]/g,''); 1233 | if(_k.replace(/[^\.]/g,'').length>1){return false;} 1234 | } 1235 | 1236 | return parseFloat(_k); 1237 | }, 1238 | getPrefix:function(val){ 1239 | return String(val).replace(/[-.\d]/g, ''); 1240 | }, 1241 | 1242 | start:function(){ 1243 | if(this.running){return;} 1244 | this.running = true; 1245 | this.tick(); 1246 | }, 1247 | tick:function(){ 1248 | let that = $.animation; 1249 | if(!that.running){return;} 1250 | 1251 | if(document.hidden === false && window.requestAnimationFrame){ 1252 | window.requestAnimationFrame(that.tick); 1253 | } else { 1254 | window.setTimeout(that.tick, 13); 1255 | } 1256 | that.process(); 1257 | } 1258 | }; 1259 | 1260 | /** 1261 | * 如果一个 300px -> 700px 1262 | * 开始于 0ms,结束于 500ms 1263 | * 在 300ms 时:px = 300+300/500*400 1264 | * from+perc*diff 1265 | * 1266 | * 如果一个 600px -> 100px 1267 | * 开始于 0ms,结束于 500ms 1268 | * 在 200ms 时:px = 600-200/500*500 1269 | */ 1270 | gQuery.animation.process = function(){ 1271 | let aniArray = this.array, _ts = Date.now(); 1272 | 1273 | $.each(aniArray, function(_i, _k){ 1274 | if(typeof _k.opts!=='object'){return true;} 1275 | 1276 | let dura = _k.opts.duration; 1277 | if(_k.start==null){ 1278 | _k.start = _ts; 1279 | _k.end = _ts + dura; 1280 | _k.elem.__gQueryStop = false; 1281 | } else { 1282 | if(_k.elem.__gQueryStop){ 1283 | aniArray.splice(_i, 1);return true; 1284 | } 1285 | } 1286 | _k.curr = dura - (_k.end - _ts); 1287 | 1288 | $.each(_k.calc, function(_pi, _pk){ 1289 | if(!_pk.curr){ 1290 | _pk.curr = _pk.from; 1291 | _pk.diff = Math.abs(_pk.to - _pk.from); 1292 | _pk.re = _pk.from>_pk.to; 1293 | } 1294 | 1295 | _pk.curr = _k.curr/dura*_pk.diff; 1296 | if(_pk.re){ 1297 | _pk.curr = Math.max(_pk.from-_pk.curr, _pk.to); 1298 | } else { 1299 | _pk.curr = Math.min(_pk.from+_pk.curr, _pk.to); 1300 | } 1301 | _k.elem.style[_pi] = _pk.curr+_pk.suffix; 1302 | 1303 | if(_pk.from===_pk.to){ 1304 | delete _k.calc[_pi]; 1305 | } 1306 | }); 1307 | 1308 | if(_ts>=_k.end){ 1309 | typeof _k.callback==='function' && _k.callback.call(_k.elem); 1310 | aniArray.splice(_i, 1); 1311 | } 1312 | }); 1313 | 1314 | if(aniArray.length<1){ 1315 | this.running = false; 1316 | } 1317 | } 1318 | 1319 | 1320 | /** ------------------------------------- 1321 | * Prototype Chain Generator 1322 | * @HTU chain({ 1323 | * init: function([args]){...}, 1324 | * todo: function([args]){...} 1325 | * }) 1326 | * @tip 局部变量请在 init 函数中赋值 1327 | * ------------------------------------- */ 1328 | gQuery.chain = function(_ch){ 1329 | function chain(){ 1330 | return new chain.prototype.init(...arguments); 1331 | } 1332 | chain.fn = chain.prototype = _ch; 1333 | chain.fn.init.prototype = chain.prototype; 1334 | return chain; 1335 | }; 1336 | 1337 | /** ------------------------------------- 1338 | * Date 1339 | * ------------------------------------- */ 1340 | gQuery.date = new gQuery.chain({ 1341 | gquery: true, 1342 | init: function(){ 1343 | let arg = arguments[0], isArg = false; 1344 | this.date = $.date.parse(arg); 1345 | 1346 | return this.initDate(); 1347 | }, 1348 | calc: function(arg){ 1349 | // 以免在计算过程中对初始日期产生影响 1350 | let __dt = Object.create(this); 1351 | __dt.date = $.date.calc(__dt.date, arg); 1352 | 1353 | return this.initDate(__dt); 1354 | }, 1355 | initDate: function(__dt){ 1356 | if(typeof __dt!=='object'){ 1357 | __dt = this; 1358 | } 1359 | __dt.timestamp = __dt.date.getTime(); 1360 | 1361 | let dt = __dt.date; 1362 | __dt._y = dt.getFullYear(); 1363 | __dt._m = dt.getMonth() + 1; 1364 | __dt._d = dt.getDate(); 1365 | __dt._h = dt.getHours(); 1366 | __dt._i = dt.getMinutes(); 1367 | __dt._s = dt.getSeconds(); 1368 | 1369 | return __dt; 1370 | }, 1371 | 1372 | /** 1373 | * @e.g. format() 1374 | * @e.g. format('yyyy-mm-dd') 1375 | * @e.g. format('本世纪第yy年的m月') 1376 | */ 1377 | format: function(fmt){ 1378 | let _t = $.extend({}, this); 1379 | _t._m<10 && (_t._m='0'+_t._m); 1380 | _t._d<10 && (_t._d='0'+_t._d); 1381 | _t._h<10 && (_t._h='0'+_t._h); 1382 | _t._i<10 && (_t._i='0'+_t._i); 1383 | _t._s<10 && (_t._s='0'+_t._s); 1384 | _t._dt = _t._y+'-'+_t._m+'-'+_t._d+' '+_t._h+':'+_t._i+':'+_t._s; 1385 | // 未自定义直接返回默认格式 1386 | if(typeof fmt!=='string'){return _t._dt;} 1387 | 1388 | rp('yyyy', _t._y);rp('yy', String(_t._y).substr(-2)); 1389 | rp('mm', _t._m);rp('m', this._m); 1390 | rp('dd', _t._d);rp('d', this._d); 1391 | 1392 | rp('hh', _t._h);rp('h', this._h); 1393 | rp('ii', _t._i);rp('i', this._i); 1394 | rp('ss', _t._s);rp('s', this._s); 1395 | 1396 | function rp(regStr, repStr){ 1397 | fmt = fmt.replace(new RegExp(regStr, 'g'), repStr); 1398 | }; 1399 | return fmt; 1400 | }, 1401 | /** 1402 | * $.date().diff('-3d') => 差距+3天(1_结束时间,2_开始时间) 1403 | */ 1404 | diff: function(_dt){ 1405 | _dt = $.date.parse(_dt); 1406 | let df = {}, _t = {}, 1407 | ms_start = this.date.getTime(), ms_end = _dt.getTime(); 1408 | function fl(val){return Math.floor(val);} 1409 | 1410 | df._ms = ms_start - ms_end; 1411 | df._s = fl(df._ms/1000); 1412 | df._i = fl(df._s/60); 1413 | df._h = fl(df._i/60); 1414 | df._d = fl(df._h/24); 1415 | 1416 | // 防止开始时间>结束时间导致的计算出错 1417 | _t._ms = Math.abs(df._ms); 1418 | 1419 | df.d = fl( _t._ms / (24*60*60*1000) ); 1420 | _t.df_h = _t._ms % (24*60*60*1000); 1421 | df.h = fl( _t.df_h / (60*60*1000) ); 1422 | _t.df_i = _t.df_h % (60*60*1000); 1423 | df.i = fl( _t.df_i / (60*1000) ); 1424 | _t.df_s = _t.df_i % (60*1000); 1425 | df.s = fl( _t.df_s / (1000) ); 1426 | df.ms = _t.df_s % (1000); 1427 | 1428 | this._df = df; 1429 | return this; 1430 | }, 1431 | ago: function(split){ 1432 | split || (split = ''); 1433 | 1434 | let df = this._df; 1435 | if(typeof df!=='object'){return '现在';} 1436 | if(df._ms<0){return '未来';} 1437 | 1438 | if(df.d>0){ 1439 | if(df.d>=30){ 1440 | df.mon = Math.floor(df.d/30); 1441 | if(df.mon>=12){ 1442 | df.year = Math.floor(df.mon/12); 1443 | return df.year+split+"年前"; 1444 | } 1445 | 1446 | return df.mon+split+"个月前"; 1447 | } 1448 | 1449 | if(df.d==1){return "昨天";} 1450 | if(df.d==2){return "前天";} 1451 | return df.d+split+"天前"; 1452 | } 1453 | if(df.h>0){return df.h+split+"小时前";} 1454 | if(df.i>0){return df.i+split+"分钟前";} 1455 | if(df.s>0){return df.s+split+"秒前";} 1456 | if(df.ms>0){return "刚刚";} 1457 | if(df.ms===0){return "现在";} 1458 | 1459 | return '未知'; 1460 | } 1461 | }); 1462 | /** 1463 | * @e.g. parse('2002-2-14 12:00:00') 1464 | * @e.g. parse(timestamp) 1465 | * @e.g. parse(Date, '+5 day -2months +1y') 1466 | * @e.g. parse('+5 day') 1467 | */ 1468 | gQuery.date.parse = function(arg1, arg2){ 1469 | let typ1 = typeof arg1, typ2 = typeof arg2, date, _t = {}; 1470 | 1471 | // 如果传入 gqData 对象 1472 | if(arg1 instanceof gQuery.date){arg1 = arg1.date;} 1473 | if(arg1 && arg1 instanceof Date){ 1474 | if(typ2!=='string'){return arg1;} 1475 | return this.calc(arg1, arg2); 1476 | } 1477 | if(typ1==='string' && /^[+-]/.test(arg1)){ 1478 | return this.calc(new Date(), arg1); 1479 | } 1480 | 1481 | if(typ1==='string'){ 1482 | date = new Date(arg1); 1483 | // Safari 处理 1484 | if( isNaN(date.getTime()) ){ 1485 | date = new Date(arg1.replace(/-/g, '/')); 1486 | } 1487 | return date; 1488 | } 1489 | 1490 | if(typ1==='number'){ 1491 | // 处理错误数值 1492 | _t.len = 13 - String(arg1).length; 1493 | if(_t.len!=0){ 1494 | arg1 = _t.len<0 ? arg1/(10**Math.abs(_t.len)) : arg1*(10**_t.len); 1495 | } 1496 | return new Date(Math.round(arg1)); 1497 | } 1498 | 1499 | return new Date(); 1500 | }; 1501 | /** 1502 | * @e.g. calc(Date, '+5 day -2months +1y') 1503 | * @return Date 1504 | */ 1505 | gQuery.date.calc = function(arg1, arg2, force){ 1506 | if(!force){ 1507 | // 默认传入时,将对 arg2 序列化 1508 | arg2 = arg2.replace(/\s/g, '').replace(/([\+\-])/g,' $1').split(' '); 1509 | for (let i = 0; i < arg2.length; i++) { 1510 | if(!arg2[i]){continue;} 1511 | arg1 = $.date.calc(arg1, arg2[i], true); 1512 | } 1513 | return arg1; 1514 | }; 1515 | 1516 | let ts = arg1.getTime(), isAdd = !/^-/.test(arg2); 1517 | let dt = {}; 1518 | 1519 | arg2 = arg2.replace(/[\+\- ]/g, ''); 1520 | // 分割数值和类型 1521 | dt.num = arg2.replace(/[^\d]/g, ''); 1522 | dt.typ = arg2.replace(dt.num, ''); 1523 | 1524 | dt.num = parseInt(dt.num); 1525 | isAdd && (dt.num*=-1); 1526 | 1527 | switch(dt.typ){ 1528 | case 'y':case 'year':case 'years': 1529 | arg1.setYear(arg1.getFullYear() - dt.num); 1530 | ts = arg1.getTime(); 1531 | break; 1532 | case 'm':case 'mon':case 'month':case 'months': 1533 | arg1.setMonth(arg1.getMonth() - dt.num); 1534 | ts = arg1.getTime(); 1535 | break; 1536 | 1537 | case 'd':case 'day':case 'days': 1538 | ts -= dt.num*(24*60*60*1000); 1539 | break; 1540 | case 'h':case 'hour':case 'hours': 1541 | ts -= dt.num*(60*60*1000); 1542 | break; 1543 | case 'i':case 'min':case 'minute':case 'minutes': 1544 | ts -= dt.num*(60*1000); 1545 | break; 1546 | case 's':case 'sec':case 'second':case 'seconds': 1547 | ts -= dt.num*1000; 1548 | break; 1549 | case 'ms':case 'millisecond':case 'milliseconds': 1550 | ts -= dt.num; 1551 | break; 1552 | } 1553 | return new Date(ts); 1554 | } 1555 | 1556 | return gQuery; 1557 | })); -------------------------------------------------------------------------------- /gquery.min.js: -------------------------------------------------------------------------------- 1 | /* gQuery v1.5.6 | (c) 2020-present, JU Chengren (Ganxiaozhe) | hi@gxzv.com | gquery.cn/license */ 2 | "use strict";function _defineProperty(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var _slicedToArray=function(){function t(t,e){var n=[],i=!0,r=!1,o=void 0;try{for(var a,s=t[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!e||n.length!==e);i=!0);}catch(t){r=!0,o=t}finally{try{!i&&s.return&&s.return()}finally{if(r)throw o}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(t,e){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=window||self,t.gQuery=t.$=e()),(window.ActiveXObject||"ActiveXObject"in window)&&(window.location.href="https://gquery.cn/kill-ie?back="+window.location.href),console.log("%c gQuery 1.5.6 %c gquery.cn \n","color: #fff; background: #030307; padding:5px 0; margin-top: 1em;","background: #efefef; color: #333; padding:5px 0;")}(window,function(){function t(t,e,n){var i=this;if(this._fncQueue=void 0===n?[]:n,this._delayCompleted=!1,this._$real=t,"number"==typeof e&&e>=0&&e<1/0)this.timeoutKey=window.setTimeout(function(){i._performDummyQueueActions()},e);else if(null!==e&&"object"===(void 0===e?"undefined":_typeof(e))&&"function"==typeof e.promise)e.then(function(){i._performDummyQueueActions()});else{if("string"!=typeof e)return t;t.one(e,function(){i._performDummyQueueActions()})}}var e=function t(e,n){return new t.fn.init(e,n)};e.fn=e.prototype={constructor:e,gquery:"1.5.6",init:function(t,n){var i=void 0===t?"undefined":_typeof(t),r=[];switch(i){case"function":return void("loading"!=document.readyState?t():document.addEventListener("DOMContentLoaded",t));case"object":if(e.isWindow(t)){r=[window];break}if(void 0!==t.gquery){r=t;break}Array.isArray(t)?t.map(function(t){$.isNode(t)&&r.push(t)}):r.push(t);break;case"string":try{r=document.querySelectorAll(t)}catch(e){r=$.parse.html(t)}}switch(n){case"push":for(var o=this.length,a=r.length-1;a>=0;a--){for(var s=!0,c=this.length-1;c>=0;c--)this[c]===r[a]&&(s=!1);s&&(this.length+=1,this[o+a]=r[a])}break;default:this.length=r.length;for(var u=r.length-1;u>=0;u--)this[u]=r[u]}return this},push:function(t){return this.init(t,"push")},each:function(t,e){e||(e=t,t=this);for(var n=0,i=t.length;n=0;o--)i[o]=r[o];return i},is:function(t){var e=!1;return this.each(function(n){var i=this.matches||this.matchesSelector||this.msMatchesSelector||this.mozMatchesSelector||this.webkitMatchesSelector||this.oMatchesSelector;if("function"==typeof i&&i.call(this,t))return e=!0,!1}),e},exist:function(){var t=!1;return this.each(function(e){if(document.body.contains(this))return t=!0,!1}),t},eq:function(t){return $(this[t])},parent:function(t,e){var n=Object.create(this),i=[],r=void 0;for(this.each(function(n){for(var r=this.parentNode;t&&r&&!$(r).is(t);){if(!e){r=void 0;break}r=r.parentNode}r&&i.push(r)}),i=$.array.unique(i),n.length=i.length,r=i.length-1;r>=0;r--)n[r]=i[r];return n},next:function(t){var e=Object.create(this),n=[],i=void 0,r=void 0;for(this.each(function(r){i=this.nextElementSibling,null===i||t&&!i.matches(t)||n.push(i),delete e[r]}),n=$.array.unique(n),e.length=n.length,r=n.length-1;r>=0;r--)e[r]=n[r];return e},remove:function(t,e){return void 0===e&&(e=!1),(void 0===t?this:this.find(t,!1,e)).each(function(){if(null===this.parentNode)return!0;this.parentNode.removeChild(this)}),this},empty:function(t){return(void 0===t?this:this.find(t)).each(function(){for(;this.firstChild;)this.removeChild(this.firstChild)})},text:function(t){return n.thvEach.call(this,"innerText",t)},html:function(t){return n.thvEach.call(this,"innerHTML",t)},val:function(t){return n.thvEach.call(this,"value",t)},ohtml:function(t){return n.thvEach.call(this,"outerHTML",t)},width:function(t){if(void 0!==t)return isNaN(t)||(t+="px"),this.each(function(){this.style.width=t});var e=[],n=void 0;return this.each(function(){n=this.offsetWidth,void 0===n&&(n="function"==typeof this.getBoundingClientRect?this.getBoundingClientRect().width.toFixed(2):0),e.push(parseFloat(n))}),e.length>1?e:e[0]},height:function(t){if(void 0!==t)return isNaN(t)||(t+="px"),this.each(function(){this.style.height=t});var e=[],n=void 0;return this.each(function(){n=this.offsetHeight,void 0===n&&(n="function"==typeof this.getBoundingClientRect?this.getBoundingClientRect().height.toFixed(2):0),e.push(parseFloat(n))}),e.length>1?e:e[0]},offset:function(t){if("object"===(void 0===t?"undefined":_typeof(t)))return this.each(function(){for(var e in t)isNaN(t[e])||(t[e]+="px"),this.style[e]=t[e]});var e=this[0].getBoundingClientRect(),n={top:0==document.body.scrollTop?document.documentElement.scrollTop:document.body.scrollTop,left:0==document.body.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft};t&&(n.top=0,n.left=0);var i=$(this[0]),r={top:e.top+n.top,left:e.left+n.left,height:i.height(),width:i.width()},o=t?window.innerHeight:document.body.offsetHeight,a=t?window.innerWidth:document.body.offsetWidth;return r.bottom=o-r.top-r.height,r.right=a-r.left-r.width,r},append:function(t){return n.pend.call(this,"appendChild",t)},prepend:function(t){return n.pend.call(this,"insertBefore",t)},insertBefore:function(t){return n.pend.call($(t),"before",this)},before:function(t){return n.pend.call(this,"before",t)},after:function(t){return n.pend.call(this,"after",t)},attr:function(t,e){if(void 0===e&&"string"==typeof t){var n=[],i=void 0;return this.each(function(){i=this.getAttribute(t),null===i&&(i=void 0),n.push(i)}),n.length>1?n:n[0]}return"object"===(void 0===t?"undefined":_typeof(t))?this.each(function(){for(var e in t)this.setAttribute&&this.setAttribute(e,t[e])}):this.each(function(){this.setAttribute&&this.setAttribute(t,e)})},removeAttr:function(t){return t=t.split(" "),this.each(function(){var e=this;t.map(function(t){return e.removeAttribute(t)})})},data:function(t,e){if("object"!==(void 0===t?"undefined":_typeof(t))&&void 0===e){var n=[];return this.each(function(){void 0===this.gQueryData&&(this.gQueryData={}),"string"==typeof t?n.push(this.gQueryData[t]):n.push(this.gQueryData)}),n.length>1?n:n[0]}return this.each(function(){if(void 0===this.gQueryData&&(this.gQueryData={}),"object"===(void 0===t?"undefined":_typeof(t)))for(var n in t)this.gQueryData[n]=t[n];else this.gQueryData[t]=e})},removeData:function(t){return this.each(function(){void 0===this.gQueryData&&(this.gQueryData={}),delete this.gQueryData[t]})},hasClass:function(t){t=t.split(" ");var e=!0;return this.each(function(){var n=this;t.map(function(t){n.classList.contains(t)||(e=!1)})}),e},addClass:function(t){return t=t.split(" "),this.each(function(){var e=this;t.map(function(t){return e.classList.add(t)})})},removeClass:function(t){return t=t.split(" "),this.each(function(){var e=this;t.map(function(t){return e.classList.remove(t)})})},toggleClass:function(t){return t=t.split(" "),this.each(function(){var e=this;t.map(function(t){return e.classList.toggle(t)})})},css:function(t,e){function n(t,e,n){var i=/!important\s?$/,r="";i.test(n)&&(r="important",n=n.replace(i,"")),t.style.setProperty(e,n,r)}if(void 0!==e)return this.each(function(){n(this,t,e)});if("string"==typeof t){var i=[];return this.each(function(){i.push(getComputedStyle(this)[t])}),i.length>1?i:i[0]}return this.each(function(){for(var e in t)n(this,e,t[e])})},show:function(t){return this.each(function(){this.style.display="","none"==getComputedStyle(this).display&&(this.style.display=t||"block")})},hide:function(){return this.each(function(){this.style.display="none"})},animate:function(t,e,n){return void 0===(void 0===e?"undefined":_typeof(e))&&(e=500),"object"!==(void 0===e?"undefined":_typeof(e))&&(e={duration:parseInt(e)}),e.duration||(e.duration=500),e.timing||(e.timing="linear"),e.delay||(e.delay=0),this.each(function(){function i(){$.animation.array.push(r),$.animation.start()}var r={elem:this,callback:n,props:t,calc:$.animation.preCalc(t,this),opts:e,start:null};e.delay>0?setTimeout(i,e.delay):i()})},stop:function(){return this.each(function(){this.__gQueryStop=!0})},fadeIn:function(t,e){return t||(t=500),this.each(function(){$(this).show().stop().animate({opacity:1},t,function(){e&&e.call(this)})})},fadeOut:function(t,e){return t||(t=500),this.each(function(){$(this).stop().animate({opacity:0},t,function(){this.style.display="none",e&&e.call(this)})})},fadeToggle:function(t,e){return t||(t=500),"function"==typeof e||(e=function(){}),this.each(function(){"none"==this.style.display?$(this).fadeIn(t,e):$(this).fadeOut(t,e)})},slideUp:function(t,e){return t||(t=500),this.each(function(){$(this).stop().animate({height:"0px"},t,function(){this.style.display="none",e&&e.call(this)})})},slideDown:function(t,e){return t||(t=500),this.each(function(){var n=$(this).css("height"),i=$(this).css({display:"",height:""}),r=this.offsetHeight;this.style.height=n,i.stop().animate({height:r+"px"},t,function(){e&&e.call(this)})})},slideToggle:function(t,e){return t||(t=500),"function"==typeof e||(e=function(){}),this.each(function(){"none"==this.style.display?$(this).slideDown(t,e):$(this).slideUp(t,e)})},on:function(t,e,i,r){var o=n.onArgs(arguments),a=_slicedToArray(o,4);t=a[0],e=a[1],i=a[2],r=a[3],e&&void 0===r.capture&&(r.capture=!0);var s=function(t,n){var i=$.array.finder(["mouseenter","mouseleave","mousemove","mouseover","mouseout"],n);return e?function(n){var r=this.querySelectorAll(e),o=!1,a=void 0;for(a=r.length-1;a>=0&&!1===o;a--)i?r[a]===n.target&&(o=r[a]):r[a].contains(n.target)&&(o=r[a]);o&&t.call(o,n)}:t},c=void 0;return"function"==typeof i?(c=s(i,t),this.each(function(){$.event.add(this,t,c,r)})):this.each(function(){for(var e in t)c=s(t[e],e),$.event.add(this,e,c,r)})},one:function(t,e,i,r){var o=n.onArgs(arguments),a=_slicedToArray(o,4);return t=a[0],e=a[1],i=a[2],r=a[3],r.once=!0,this.on(t,e,i,r)},off:function(t,e){return void 0===e&&(e=!1),t||(t="*"),t=t.split(" "),this.each(function(){var n=this;t.map(function(t){return $.event.remove(n,t,e)})})},trigger:function(t,e){e||(e={}),t=t.split(" ");var n=t.map(function(t){return new CustomEvent(t,{detail:e})});return this.each(function(){var t=this;n.map(function(e){return t.dispatchEvent(e)})})},click:function(t){return"function"==typeof t?this.each(function(){$.event.add(this,"click",t)}):this.trigger("click")},select:function(){switch(this[0].tagName.toLowerCase()){case"input":case"textarea":this[0].select();break;default:window.getSelection().selectAllChildren(this[0])}return this},load:function(t,e,n){var i=this,r=t.trim().split(" ");"function"==typeof e&&(n=e,e=!1),$.fetch(r[0],e,"text").then(function(t){r.length>1?(r.splice(0,1),i.html($(t).find(r.join(" "),!0).html())):i.html(t),"function"==typeof n&&n.call(i)})},extend:function(t){for(var e in t)"object"===_typeof(t[e])?this[e]=$.extend(!0,this[e],t[e]):this[e]=t[e];return this}},e.fn.init.prototype=e.fn;var n={thvEach:function(t,e){var n=Array.isArray(e);if(void 0===e||n&&0==e.length){var i=[];return this.each(function(){i.push(this[t])}),n?i:i.join("")}return n?this.each(function(n){this[t]=e[n]}):this.each(function(){this[t]=e})},pend:function(t,e){var n="string"==typeof e?$.parse.html(e):e.gquery?e:[e];return this.each(function(){var e=n.length,i=void 0,r=void 0;for(i=0;i0;){if(t=this._fncQueue.pop(),"wait"===t.fnc)return t.arg.push(this._fncQueue),this._$real=this._$real[t.fnc].apply(this._$real,t.arg);this._$real=this._$real[t.fnc].apply(this._$real,t.arg)}return this},e.fn.wait=function(e,n){return new t(this,e,n)},e.waitUpdate=function(){for(var n in e.fn)"function"==typeof e.fn[n]&&e.fn.hasOwnProperty(n)&&(t.prototype[n]=function(t){return function(){var e=Array.prototype.slice.call(arguments);return this._addToQueue(t,e)}}(n))},e.waitUpdate(),e.debugger=!1,e.extend=function(t){if(1==arguments.length){for(var n in t)"object"===_typeof(t[n])?this[n]=$.extend(!0,this[n],t[n]):this[n]=t[n];return e.waitUpdate(),this}var i=!1,r=arguments.length,o=1,a=void 0,s=void 0,c=void 0,u=void 0,f=void 0,h=void 0,l=arguments[0]||{};for("boolean"==typeof l&&(i=l,l=arguments[o]||{},o++),"object"!==(void 0===l?"undefined":_typeof(l))&&(l={});o"+t+""),$("#gQuery-copyTemp").select(),document.execCommand("Copy"),$("#gQuery-copyTemp").remove()},e.fetch=function(t,n,i){var r={method:"GET"};if("object"===(void 0===t?"undefined":_typeof(t))&&(r=$.extend(r,t),t=t.url),"object"===(void 0===n?"undefined":_typeof(n)))if(r.method="POST","[object FormData]"==Object.prototype.toString.call(n))r.body=n;else{r.body=new FormData;for(var o in n)r.body.append(o,n[o])}else"string"==typeof n&&("string"==typeof i?(r.method="POST",r.body=n):i=n);if(!i)return fetch(t,r);var a=void 0;return fetch(t,r).then(function(t){if(!t.ok)throw new Error("Network response was not ok.");return e.debugger&&(a=t.clone()),t[i]()}).catch(function(t){throw a&&a.ok&&a.text().then(function(t){console.error(t)}),new Error(t)})},e.global="undefined"!=typeof window?window:global,e.isWindow=function(t){return"[object Window]"===Object.prototype.toString.call(t)},e.isNode=function(t){var e=Object.prototype.toString.call(t);return e.indexOf("HTML")>-1&&e.indexOf("Element")>-1},e.isPlainObject=function(t){var e=void 0;return"[object Object]"===Object.prototype.toString.call(t)&&(null===(e=Object.getPrototypeOf(t))||e==Object.getPrototypeOf({}))},e.ui="Missing gQuery UI components.",e.array={unique:function(t,e){var n={};return"node"==e||$.isNode(t[0])?t.filter(function(t,e,n){return n.indexOf(t,0)===e}):(t.forEach(function(t){var e=void 0===t?"undefined":_typeof(t),i=t;"object"===e&&(t=JSON.stringify(t)),n[t+"::"+e]=i}),Object.keys(n).map(function(t){return n[t]}))},finder:function(t,e,n){"object"===(void 0===n?"undefined":_typeof(n))||(n={}),void 0===n.limit&&(n.limit=1);for(var i="object"===(void 0===e?"undefined":_typeof(e)),r=void 0,o=[],a=0;a0&&o.length>=n.limit)break}else if(t[a]==e&&o.push({index:a,array:t[a]}),n.limit>0&&o.length>=n.limit)break;return n.array?o:o.length>1?o:o[0]},has:function(t,e){return void 0!==this.finder(t,e)}},e.event={add:function(t,e,n,i){"object"===(void 0===i?"undefined":_typeof(i))||(i={}),void 0===i.capture&&(i.capture=!1);var r=e.split("."),o=r.splice(0,1);r.length>0&&(i.__flag={}),r.map(function(t){i.__flag[t]=!0});var a=function(r){return!0===i.once&&$.event.remove(t,e,i),n.call(t,r)},s=t.gQueryEvents,c={fn:a,opts:i};void 0===s?s=_defineProperty({},o,[c]):"object"!==_typeof(s[o])?s[o]=[c]:s[o].push(c),t.gQueryEvents=s;var u=s[o][s[o].length-1];t.addEventListener(o,u.fn,u.opts)},remove:function(t,e,n){function i(e,n){var i=r[e];for(a=i.length-1;a>=0;a--){if(!n){if("continue"===function(){var t=1,e=i[a].opts.__flag||{};if(o.length<1&&Object.keys(e).length<1&&(t=0),o.map(function(n){e[n]&&(t=0)}),t)return"continue"}())continue}t.removeEventListener(e,i[a].fn,i[a].opts),r[e].splice(a,1),r[e].length<1&&delete r[e]}}var r=t.gQueryEvents,o=e.split("."),a=void 0;if(e=o.splice(0,1),void 0!==r)return"*"==e?void Object.keys(r).map(function(t){return i(t,!0)}):void("object"===_typeof(r[e])&&i(e))}},e.get={browserSpec:function(){var t=navigator.userAgent,e=void 0,n=t.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];return/trident/i.test(n[1])?(e=/\brv[ :]+(\d+)/g.exec(t)||[],{name:"IE",version:e[1]||""}):"Chrome"===n[1]&&null!=(e=t.match(/\b(OPR|Edge)\/(\d+)/))?{name:e[1].replace("OPR","Opera"),version:e[2]}:(n=n[2]?[n[1],n[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(e=t.match(/version\/(\d+)/i))&&n.splice(1,1,e[1]),{name:n[0],version:n[1],isMobile:/Mobi/i.test(t),touchPoints:navigator.maxTouchPoints||"ontouchstart"in document.documentElement||0})},queryParam:function(t,e){if(void 0===e&&(e=t,t=window.location.href),t.indexOf("?")<0)return null;var n=new RegExp("(^|&)"+e+"=([^&]*)(&|$)","i"),i=t.replace(/.*?\?/g,"").match(n);return null!=i?decodeURI(i[2]):null},json:function(t,e){return $.fetch(t,e,"text").then(function(t){return $.parse.json(t)})}},e.parse={html:function(t){if("string"==typeof t){var e=document.createElement("template");return e.innerHTML=t,e.content.childNodes}return t},json:function(t){if("object"===(void 0===t?"undefined":_typeof(t)))return t;if(""===t)return{};var e=void 0;try{e=JSON.parse(t)}catch(t){}try{e||(e=Function('"use strict";return ('+t+")")())}catch(t){throw new Error(t)}return e},number:function(t){return"string"==typeof t?parseInt(t.replace(/[^\d]/g,"")):t}},e.cookie={get:function(t,e){function n(t){return t.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}for(var i={},r=0,o=document.cookie?document.cookie.split("; "):[];r-1){if(parseInt(n.substr(0,i))<(new Date).getTime())return this.remove(t),null;n=n.substr(i+this.IKEY.length)}if("array"==e||"object"==e)try{n=$.parse.json(n)}catch(t){throw new Error("Parsing!")}return n},remove:function(t){this.local().removeItem(t)},clear:function(){this.local().clear()},push:function(t,e,n){var i=this.get(t);if(i){try{var r=JSON.parse(i);Array.isArray(r)?(r.push(e),i=r):(i=JSON.parse("["+i+"]"),i.push(e))}catch(t){i="["+JSON.stringify(i)+"]",i=JSON.parse(i),i.push(e)}return"unique"==n&&(i=$.array.unique(i)),this.set(t,JSON.stringify(i)),this.get(t,"array")}return e="["+JSON.stringify(e)+"]",this.set(t,e),this.get(t)}},e.sessionStorage=e.extend({},e.storage),e.sessionStorage.local=function(){return $.global.sessionStorage},e.animation={array:[],running:!1,preCalc:function(t,e){var n=this,i={};return $.each(t,function(t,r){var o=n.toCalc(r);if(!1===o)return!0;var a=n.getPrefix(r),s=e.style[t];if(void 0===s)return!0;""===s&&(s=getComputedStyle(e)[t]);var c=n.toCalc(s);if(a!=n.getPrefix(s)){e.style[t]="100"+a;var u=getComputedStyle(e)[t];c=c/n.toCalc(u)*100,e.style[t]=s}i[t]={from:c,to:o,suffix:a}}),i},toCalc:function(t){if(""===t)return!1;if(isNaN(t)){if(!/^[-\d]/.test(t)||t.lastIndexOf("-")>0)return!1;if(t=t.replace(/[^-.\d]/g,""),t.replace(/[^\.]/g,"").length>1)return!1}return parseFloat(t)},getPrefix:function(t){return String(t).replace(/[-.\d]/g,"")},start:function(){this.running||(this.running=!0,this.tick())},tick:function(){var t=$.animation;t.running&&(!1===document.hidden&&window.requestAnimationFrame?window.requestAnimationFrame(t.tick):window.setTimeout(t.tick,13),t.process())}},e.animation.process=function(){var t=this.array,e=Date.now();$.each(t,function(n,i){if("object"!==_typeof(i.opts))return!0;var r=i.opts.duration;if(null==i.start)i.start=e,i.end=e+r,i.elem.__gQueryStop=!1;else if(i.elem.__gQueryStop)return t.splice(n,1),!0;i.curr=r-(i.end-e),$.each(i.calc,function(t,e){e.curr||(e.curr=e.from,e.diff=Math.abs(e.to-e.from),e.re=e.from>e.to),e.curr=i.curr/r*e.diff,e.re?e.curr=Math.max(e.from-e.curr,e.to):e.curr=Math.min(e.from+e.curr,e.to),i.elem.style[t]=e.curr+e.suffix,e.from===e.to&&delete i.calc[t]}),e>=i.end&&("function"==typeof i.callback&&i.callback.call(i.elem),t.splice(n,1))}),t.length<1&&(this.running=!1)},e.chain=function(t){function e(){return new(Function.prototype.bind.apply(e.prototype.init,[null].concat(Array.prototype.slice.call(arguments))))}return e.fn=e.prototype=t,e.fn.init.prototype=e.prototype,e},e.date=new e.chain({gquery:!0,init:function(){var t=arguments[0];return this.date=$.date.parse(t),this.initDate()},calc:function(t){var e=Object.create(this);return e.date=$.date.calc(e.date,t),this.initDate(e)},initDate:function(t){"object"!==(void 0===t?"undefined":_typeof(t))&&(t=this),t.timestamp=t.date.getTime();var e=t.date;return t._y=e.getFullYear(),t._m=e.getMonth()+1,t._d=e.getDate(),t._h=e.getHours(),t._i=e.getMinutes(),t._s=e.getSeconds(),t},format:function(t){function e(e,n){t=t.replace(new RegExp(e,"g"),n)}var n=$.extend({},this);return n._m<10&&(n._m="0"+n._m),n._d<10&&(n._d="0"+n._d),n._h<10&&(n._h="0"+n._h),n._i<10&&(n._i="0"+n._i),n._s<10&&(n._s="0"+n._s),n._dt=n._y+"-"+n._m+"-"+n._d+" "+n._h+":"+n._i+":"+n._s,"string"!=typeof t?n._dt:(e("yyyy",n._y),e("yy",String(n._y).substr(-2)),e("mm",n._m),e("m",this._m),e("dd",n._d),e("d",this._d),e("hh",n._h),e("h",this._h),e("ii",n._i),e("i",this._i),e("ss",n._s),e("s",this._s),t)},diff:function(t){function e(t){return Math.floor(t)}t=$.date.parse(t);var n={},i={},r=this.date.getTime(),o=t.getTime();return n._ms=r-o,n._s=e(n._ms/1e3),n._i=e(n._s/60),n._h=e(n._i/60),n._d=e(n._h/24),i._ms=Math.abs(n._ms),n.d=e(i._ms/864e5),i.df_h=i._ms%864e5,n.h=e(i.df_h/36e5),i.df_i=i.df_h%36e5,n.i=e(i.df_i/6e4),i.df_s=i.df_i%6e4,n.s=e(i.df_s/1e3),n.ms=i.df_s%1e3,this._df=n,this},ago:function(t){t||(t="");var e=this._df;return"object"!==(void 0===e?"undefined":_typeof(e))?"现在":e._ms<0?"未来":e.d>0?e.d>=30?(e.mon=Math.floor(e.d/30),e.mon>=12?(e.year=Math.floor(e.mon/12),e.year+t+"年前"):e.mon+t+"个月前"):1==e.d?"昨天":2==e.d?"前天":e.d+t+"天前":e.h>0?e.h+t+"小时前":e.i>0?e.i+t+"分钟前":e.s>0?e.s+t+"秒前":e.ms>0?"刚刚":0===e.ms?"现在":"未知"}}),e.date.parse=function(t,n){var i=void 0===t?"undefined":_typeof(t),r=void 0===n?"undefined":_typeof(n),o=void 0,a={};return t instanceof e.date&&(t=t.date),t&&t instanceof Date?"string"!==r?t:this.calc(t,n):"string"===i&&/^[+-]/.test(t)?this.calc(new Date,t):"string"===i?(o=new Date(t),isNaN(o.getTime())&&(o=new Date(t.replace(/-/g,"/"))),o):"number"===i?(a.len=13-String(t).length,0!=a.len&&(t=a.len<0?t/Math.pow(10,Math.abs(a.len)):t*Math.pow(10,a.len)),new Date(Math.round(t))):new Date},e.date.calc=function(t,e,n){if(!n){e=e.replace(/\s/g,"").replace(/([\+\-])/g," $1").split(" ");for(var i=0;i