├── README.md ├── auto ├── index.js ├── node_modules │ ├── .bin │ │ └── casperjs │ └── colors │ │ ├── LICENSE │ │ ├── ReadMe.md │ │ ├── examples │ │ ├── normal-usage.js │ │ └── safe-string.js │ │ ├── lib │ │ ├── colors.js │ │ ├── custom │ │ │ ├── trap.js │ │ │ └── zalgo.js │ │ ├── extendStringPrototype.js │ │ ├── index.js │ │ ├── maps │ │ │ ├── america.js │ │ │ ├── rainbow.js │ │ │ ├── random.js │ │ │ └── zebra.js │ │ ├── styles.js │ │ └── system │ │ │ └── supports-colors.js │ │ ├── package.json │ │ ├── safe.js │ │ └── themes │ │ └── generic-logging.js └── task │ ├── captcha.txt │ └── yunpan.js ├── countDown └── mcountdown.js ├── getFlashVersion └── getFlashVersion.js ├── imgCompress ├── imgCompress.js └── index.html ├── jQuery.CusScrollBar ├── index.html └── jQuery.cusScrollBar.js ├── less&sass mixins ├── mixins.less └── mixins.scss ├── mResize └── mresize.js └── mframe ├── index.html └── src ├── index ├── data.js ├── logic.js └── ui.js ├── main.js ├── mframe ├── mframe.base.js └── utils.js └── zepto ├── zepto.116.js ├── zepto.callback.js └── zepto.deferred.js /README.md: -------------------------------------------------------------------------------- 1 | #CodeSnippet 2 | 3 | ####less&sass mixins 4 | source url : https://github.com/mytcer/xmixins 5 | 6 | sass mixin 新增单位自动转换方法。 7 | 定义设计稿的尺寸后,只需要按照px切图即可。 8 | 9 | ```css 10 | .logo{ 11 | width : px2rem(300); 12 | height : px2rem(300); 13 | } 14 | //这里的300直接是设计图上量出来的 15 | ``` 16 | 17 | ####jQuery.cusScrollBar 18 | create by : https://github.com/huzunjie 19 | 20 | 21 | ####getFlashVersion 22 | 可以用此方法来检测当前环境是否支持flash。 23 | ```javascript 24 | @return {number} //返回-1表示没有检测到flash版本 25 | ``` 26 | 27 | ####imgCompres 28 | 前端图片压缩,一般用于移动端上传前对图片进行简单处理 29 | 30 | 31 | ####mResize 32 | 根据页面大小,自动调整根字体的大小,以便更好的使用rem,多用于移动端。 33 | 部分小米机型不能重新计算,需要在页面ready之后手动触发一下 window 的 resize事件 34 | 35 | ####mframe 36 | 解决UI和数据分离的问题,demo下载后可修改 src/index/data.js 中得请求地址及参数测试效果。 37 | -------------------------------------------------------------------------------- /auto/index.js: -------------------------------------------------------------------------------- 1 | var colors = require('colors'), 2 | 3 | config = { 4 | yunpan : { 5 | url : 'http://yunpan.360.cn/', 6 | user : '你的账号', 7 | pass : '你的密码' 8 | } 9 | }, 10 | 11 | sign = 'yunpan', 12 | 13 | spawn = require('child_process').spawn, 14 | 15 | casper = spawn('casperjs',[ 'task/'+ sign + '.js', JSON.stringify(config[sign])]); 16 | 17 | 18 | casper.stdout.on('data',function( data ){ 19 | console.log( colors.green(data) ); 20 | }); 21 | 22 | casper.stderr.on('data',function(data){ 23 | console.log( colors.red( data ) ); 24 | }); -------------------------------------------------------------------------------- /auto/node_modules/.bin/casperjs: -------------------------------------------------------------------------------- 1 | ../casperjs/bin/casperjs -------------------------------------------------------------------------------- /auto/node_modules/colors/LICENSE: -------------------------------------------------------------------------------- 1 | Original Library 2 | - Copyright (c) Marak Squires 3 | 4 | Additional Functionality 5 | - Copyright (c) Sindre Sorhus (sindresorhus.com) 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. -------------------------------------------------------------------------------- /auto/node_modules/colors/ReadMe.md: -------------------------------------------------------------------------------- 1 | # colors.js [![Build Status](https://travis-ci.org/Marak/colors.js.svg?branch=master)](https://travis-ci.org/Marak/colors.js) 2 | 3 | ## get color and style in your node.js console 4 | 5 | ![Demo](https://raw.githubusercontent.com/Marak/colors.js/master/screenshots/colors.png) 6 | 7 | ## Installation 8 | 9 | npm install colors 10 | 11 | ## colors and styles! 12 | 13 | ### text colors 14 | 15 | - black 16 | - red 17 | - green 18 | - yellow 19 | - blue 20 | - magenta 21 | - cyan 22 | - white 23 | - gray 24 | - grey 25 | 26 | ### background colors 27 | 28 | - bgBlack 29 | - bgRed 30 | - bgGreen 31 | - bgYellow 32 | - bgBlue 33 | - bgMagenta 34 | - bgCyan 35 | - bgWhite 36 | 37 | ### styles 38 | 39 | - reset 40 | - bold 41 | - dim 42 | - italic 43 | - underline 44 | - inverse 45 | - hidden 46 | - strikethrough 47 | 48 | ### extras 49 | 50 | - rainbow 51 | - zebra 52 | - america 53 | - trap 54 | - random 55 | 56 | 57 | ## Usage 58 | 59 | By popular demand, `colors` now ships with two types of usages! 60 | 61 | The super nifty way 62 | 63 | ```js 64 | var colors = require('colors'); 65 | 66 | console.log('hello'.green); // outputs green text 67 | console.log('i like cake and pies'.underline.red) // outputs red underlined text 68 | console.log('inverse the color'.inverse); // inverses the color 69 | console.log('OMG Rainbows!'.rainbow); // rainbow 70 | console.log('Run the trap'.trap); // Drops the bass 71 | 72 | ``` 73 | 74 | or a slightly less nifty way which doesn't extend `String.prototype` 75 | 76 | ```js 77 | var colors = require('colors/safe'); 78 | 79 | console.log(colors.green('hello')); // outputs green text 80 | console.log(colors.red.underline('i like cake and pies')) // outputs red underlined text 81 | console.log(colors.inverse('inverse the color')); // inverses the color 82 | console.log(colors.rainbow('OMG Rainbows!')); // rainbow 83 | console.log(colors.trap('Run the trap')); // Drops the bass 84 | 85 | ``` 86 | 87 | I prefer the first way. Some people seem to be afraid of extending `String.prototype` and prefer the second way. 88 | 89 | If you are writing good code you will never have an issue with the first approach. If you really don't want to touch `String.prototype`, the second usage will not touch `String` native object. 90 | 91 | ## Disabling Colors 92 | 93 | To disable colors you can pass the following arguments in the command line to your application: 94 | 95 | ```bash 96 | node myapp.js --no-color 97 | ``` 98 | 99 | ## Console.log [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data) 100 | 101 | ```js 102 | var name = 'Marak'; 103 | console.log(colors.green('Hello %s'), name); 104 | // outputs -> 'Hello Marak' 105 | ``` 106 | 107 | ## Custom themes 108 | 109 | ### Using standard API 110 | 111 | ```js 112 | 113 | var colors = require('colors'); 114 | 115 | colors.setTheme({ 116 | silly: 'rainbow', 117 | input: 'grey', 118 | verbose: 'cyan', 119 | prompt: 'grey', 120 | info: 'green', 121 | data: 'grey', 122 | help: 'cyan', 123 | warn: 'yellow', 124 | debug: 'blue', 125 | error: 'red' 126 | }); 127 | 128 | // outputs red text 129 | console.log("this is an error".error); 130 | 131 | // outputs yellow text 132 | console.log("this is a warning".warn); 133 | ``` 134 | 135 | ### Using string safe API 136 | 137 | ```js 138 | var colors = require('colors/safe'); 139 | 140 | // set single property 141 | var error = colors.red; 142 | error('this is red'); 143 | 144 | // set theme 145 | colors.setTheme({ 146 | silly: 'rainbow', 147 | input: 'grey', 148 | verbose: 'cyan', 149 | prompt: 'grey', 150 | info: 'green', 151 | data: 'grey', 152 | help: 'cyan', 153 | warn: 'yellow', 154 | debug: 'blue', 155 | error: 'red' 156 | }); 157 | 158 | // outputs red text 159 | console.log(colors.error("this is an error")); 160 | 161 | // outputs yellow text 162 | console.log(colors.warn("this is a warning")); 163 | 164 | ``` 165 | 166 | You can also combine them: 167 | 168 | ```javascript 169 | var colors = require('colors'); 170 | 171 | colors.setTheme({ 172 | custom: ['red', 'underline'] 173 | }); 174 | 175 | console.log('test'.custom); 176 | ``` 177 | 178 | *Protip: There is a secret undocumented style in `colors`. If you find the style you can summon him.* 179 | -------------------------------------------------------------------------------- /auto/node_modules/colors/examples/normal-usage.js: -------------------------------------------------------------------------------- 1 | var colors = require('../lib/index'); 2 | 3 | console.log("First some yellow text".yellow); 4 | 5 | console.log("Underline that text".yellow.underline); 6 | 7 | console.log("Make it bold and red".red.bold); 8 | 9 | console.log(("Double Raindows All Day Long").rainbow) 10 | 11 | console.log("Drop the bass".trap) 12 | 13 | console.log("DROP THE RAINBOW BASS".trap.rainbow) 14 | 15 | 16 | console.log('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported 17 | 18 | console.log('So '.green + 'are'.underline + ' ' + 'inverse'.inverse + ' styles! '.yellow.bold); // styles not widely supported 19 | console.log("Zebras are so fun!".zebra); 20 | 21 | // 22 | // Remark: .strikethrough may not work with Mac OS Terminal App 23 | // 24 | console.log("This is " + "not".strikethrough + " fun."); 25 | 26 | console.log('Background color attack!'.black.bgWhite) 27 | console.log('Use random styles on everything!'.random) 28 | console.log('America, Heck Yeah!'.america) 29 | 30 | 31 | console.log('Setting themes is useful') 32 | 33 | // 34 | // Custom themes 35 | // 36 | console.log('Generic logging theme as JSON'.green.bold.underline); 37 | // Load theme with JSON literal 38 | colors.setTheme({ 39 | silly: 'rainbow', 40 | input: 'grey', 41 | verbose: 'cyan', 42 | prompt: 'grey', 43 | info: 'green', 44 | data: 'grey', 45 | help: 'cyan', 46 | warn: 'yellow', 47 | debug: 'blue', 48 | error: 'red' 49 | }); 50 | 51 | // outputs red text 52 | console.log("this is an error".error); 53 | 54 | // outputs yellow text 55 | console.log("this is a warning".warn); 56 | 57 | // outputs grey text 58 | console.log("this is an input".input); 59 | 60 | console.log('Generic logging theme as file'.green.bold.underline); 61 | 62 | // Load a theme from file 63 | colors.setTheme(__dirname + '/../themes/generic-logging.js'); 64 | 65 | // outputs red text 66 | console.log("this is an error".error); 67 | 68 | // outputs yellow text 69 | console.log("this is a warning".warn); 70 | 71 | // outputs grey text 72 | console.log("this is an input".input); 73 | 74 | //console.log("Don't summon".zalgo) -------------------------------------------------------------------------------- /auto/node_modules/colors/examples/safe-string.js: -------------------------------------------------------------------------------- 1 | var colors = require('../safe'); 2 | 3 | console.log(colors.yellow("First some yellow text")); 4 | 5 | console.log(colors.yellow.underline("Underline that text")); 6 | 7 | console.log(colors.red.bold("Make it bold and red")); 8 | 9 | console.log(colors.rainbow("Double Raindows All Day Long")) 10 | 11 | console.log(colors.trap("Drop the bass")) 12 | 13 | console.log(colors.rainbow(colors.trap("DROP THE RAINBOW BASS"))); 14 | 15 | console.log(colors.bold.italic.underline.red('Chains are also cool.')); // styles not widely supported 16 | 17 | 18 | console.log(colors.green('So ') + colors.underline('are') + ' ' + colors.inverse('inverse') + colors.yellow.bold(' styles! ')); // styles not widely supported 19 | 20 | console.log(colors.zebra("Zebras are so fun!")); 21 | 22 | console.log("This is " + colors.strikethrough("not") + " fun."); 23 | 24 | 25 | console.log(colors.black.bgWhite('Background color attack!')); 26 | console.log(colors.random('Use random styles on everything!')) 27 | console.log(colors.america('America, Heck Yeah!')); 28 | 29 | console.log('Setting themes is useful') 30 | 31 | // 32 | // Custom themes 33 | // 34 | //console.log('Generic logging theme as JSON'.green.bold.underline); 35 | // Load theme with JSON literal 36 | colors.setTheme({ 37 | silly: 'rainbow', 38 | input: 'grey', 39 | verbose: 'cyan', 40 | prompt: 'grey', 41 | info: 'green', 42 | data: 'grey', 43 | help: 'cyan', 44 | warn: 'yellow', 45 | debug: 'blue', 46 | error: 'red' 47 | }); 48 | 49 | // outputs red text 50 | console.log(colors.error("this is an error")); 51 | 52 | // outputs yellow text 53 | console.log(colors.warn("this is a warning")); 54 | 55 | // outputs grey text 56 | console.log(colors.input("this is an input")); 57 | 58 | 59 | // console.log('Generic logging theme as file'.green.bold.underline); 60 | 61 | // Load a theme from file 62 | colors.setTheme(__dirname + '/../themes/generic-logging.js'); 63 | 64 | // outputs red text 65 | console.log(colors.error("this is an error")); 66 | 67 | // outputs yellow text 68 | console.log(colors.warn("this is a warning")); 69 | 70 | // outputs grey text 71 | console.log(colors.input("this is an input")); 72 | 73 | // console.log(colors.zalgo("Don't summon him")) 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /auto/node_modules/colors/lib/colors.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Original Library 6 | - Copyright (c) Marak Squires 7 | 8 | Additional functionality 9 | - Copyright (c) Sindre Sorhus (sindresorhus.com) 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | 29 | */ 30 | 31 | var colors = {}; 32 | module['exports'] = colors; 33 | 34 | colors.themes = {}; 35 | 36 | var ansiStyles = colors.styles = require('./styles'); 37 | var defineProps = Object.defineProperties; 38 | 39 | colors.supportsColor = require('./system/supports-colors'); 40 | 41 | if (typeof colors.enabled === "undefined") { 42 | colors.enabled = colors.supportsColor; 43 | } 44 | 45 | colors.stripColors = colors.strip = function(str){ 46 | return ("" + str).replace(/\x1B\[\d+m/g, ''); 47 | }; 48 | 49 | 50 | var stylize = colors.stylize = function stylize (str, style) { 51 | if (!colors.enabled) { 52 | return str+''; 53 | } 54 | 55 | return ansiStyles[style].open + str + ansiStyles[style].close; 56 | } 57 | 58 | var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g; 59 | var escapeStringRegexp = function (str) { 60 | if (typeof str !== 'string') { 61 | throw new TypeError('Expected a string'); 62 | } 63 | return str.replace(matchOperatorsRe, '\\$&'); 64 | } 65 | 66 | function build(_styles) { 67 | var builder = function builder() { 68 | return applyStyle.apply(builder, arguments); 69 | }; 70 | builder._styles = _styles; 71 | // __proto__ is used because we must return a function, but there is 72 | // no way to create a function with a different prototype. 73 | builder.__proto__ = proto; 74 | return builder; 75 | } 76 | 77 | var styles = (function () { 78 | var ret = {}; 79 | ansiStyles.grey = ansiStyles.gray; 80 | Object.keys(ansiStyles).forEach(function (key) { 81 | ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g'); 82 | ret[key] = { 83 | get: function () { 84 | return build(this._styles.concat(key)); 85 | } 86 | }; 87 | }); 88 | return ret; 89 | })(); 90 | 91 | var proto = defineProps(function colors() {}, styles); 92 | 93 | function applyStyle() { 94 | var args = arguments; 95 | var argsLen = args.length; 96 | var str = argsLen !== 0 && String(arguments[0]); 97 | if (argsLen > 1) { 98 | for (var a = 1; a < argsLen; a++) { 99 | str += ' ' + args[a]; 100 | } 101 | } 102 | 103 | if (!colors.enabled || !str) { 104 | return str; 105 | } 106 | 107 | var nestedStyles = this._styles; 108 | 109 | var i = nestedStyles.length; 110 | while (i--) { 111 | var code = ansiStyles[nestedStyles[i]]; 112 | str = code.open + str.replace(code.closeRe, code.open) + code.close; 113 | } 114 | 115 | return str; 116 | } 117 | 118 | function applyTheme (theme) { 119 | for (var style in theme) { 120 | (function(style){ 121 | colors[style] = function(str){ 122 | if (typeof theme[style] === 'object'){ 123 | var out = str; 124 | for (var i in theme[style]){ 125 | out = colors[theme[style][i]](out); 126 | } 127 | return out; 128 | } 129 | return colors[theme[style]](str); 130 | }; 131 | })(style) 132 | } 133 | } 134 | 135 | colors.setTheme = function (theme) { 136 | if (typeof theme === 'string') { 137 | try { 138 | colors.themes[theme] = require(theme); 139 | applyTheme(colors.themes[theme]); 140 | return colors.themes[theme]; 141 | } catch (err) { 142 | console.log(err); 143 | return err; 144 | } 145 | } else { 146 | applyTheme(theme); 147 | } 148 | }; 149 | 150 | function init() { 151 | var ret = {}; 152 | Object.keys(styles).forEach(function (name) { 153 | ret[name] = { 154 | get: function () { 155 | return build([name]); 156 | } 157 | }; 158 | }); 159 | return ret; 160 | } 161 | 162 | var sequencer = function sequencer (map, str) { 163 | var exploded = str.split(""), i = 0; 164 | exploded = exploded.map(map); 165 | return exploded.join(""); 166 | }; 167 | 168 | // custom formatter methods 169 | colors.trap = require('./custom/trap'); 170 | colors.zalgo = require('./custom/zalgo'); 171 | 172 | // maps 173 | colors.maps = {}; 174 | colors.maps.america = require('./maps/america'); 175 | colors.maps.zebra = require('./maps/zebra'); 176 | colors.maps.rainbow = require('./maps/rainbow'); 177 | colors.maps.random = require('./maps/random') 178 | 179 | for (var map in colors.maps) { 180 | (function(map){ 181 | colors[map] = function (str) { 182 | return sequencer(colors.maps[map], str); 183 | } 184 | })(map) 185 | } 186 | 187 | defineProps(colors, init()); -------------------------------------------------------------------------------- /auto/node_modules/colors/lib/custom/trap.js: -------------------------------------------------------------------------------- 1 | module['exports'] = function runTheTrap (text, options) { 2 | var result = ""; 3 | text = text || "Run the trap, drop the bass"; 4 | text = text.split(''); 5 | var trap = { 6 | a: ["\u0040", "\u0104", "\u023a", "\u0245", "\u0394", "\u039b", "\u0414"], 7 | b: ["\u00df", "\u0181", "\u0243", "\u026e", "\u03b2", "\u0e3f"], 8 | c: ["\u00a9", "\u023b", "\u03fe"], 9 | d: ["\u00d0", "\u018a", "\u0500" , "\u0501" ,"\u0502", "\u0503"], 10 | e: ["\u00cb", "\u0115", "\u018e", "\u0258", "\u03a3", "\u03be", "\u04bc", "\u0a6c"], 11 | f: ["\u04fa"], 12 | g: ["\u0262"], 13 | h: ["\u0126", "\u0195", "\u04a2", "\u04ba", "\u04c7", "\u050a"], 14 | i: ["\u0f0f"], 15 | j: ["\u0134"], 16 | k: ["\u0138", "\u04a0", "\u04c3", "\u051e"], 17 | l: ["\u0139"], 18 | m: ["\u028d", "\u04cd", "\u04ce", "\u0520", "\u0521", "\u0d69"], 19 | n: ["\u00d1", "\u014b", "\u019d", "\u0376", "\u03a0", "\u048a"], 20 | o: ["\u00d8", "\u00f5", "\u00f8", "\u01fe", "\u0298", "\u047a", "\u05dd", "\u06dd", "\u0e4f"], 21 | p: ["\u01f7", "\u048e"], 22 | q: ["\u09cd"], 23 | r: ["\u00ae", "\u01a6", "\u0210", "\u024c", "\u0280", "\u042f"], 24 | s: ["\u00a7", "\u03de", "\u03df", "\u03e8"], 25 | t: ["\u0141", "\u0166", "\u0373"], 26 | u: ["\u01b1", "\u054d"], 27 | v: ["\u05d8"], 28 | w: ["\u0428", "\u0460", "\u047c", "\u0d70"], 29 | x: ["\u04b2", "\u04fe", "\u04fc", "\u04fd"], 30 | y: ["\u00a5", "\u04b0", "\u04cb"], 31 | z: ["\u01b5", "\u0240"] 32 | } 33 | text.forEach(function(c){ 34 | c = c.toLowerCase(); 35 | var chars = trap[c] || [" "]; 36 | var rand = Math.floor(Math.random() * chars.length); 37 | if (typeof trap[c] !== "undefined") { 38 | result += trap[c][rand]; 39 | } else { 40 | result += c; 41 | } 42 | }); 43 | return result; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /auto/node_modules/colors/lib/custom/zalgo.js: -------------------------------------------------------------------------------- 1 | // please no 2 | module['exports'] = function zalgo(text, options) { 3 | text = text || " he is here "; 4 | var soul = { 5 | "up" : [ 6 | '̍', '̎', '̄', '̅', 7 | '̿', '̑', '̆', '̐', 8 | '͒', '͗', '͑', '̇', 9 | '̈', '̊', '͂', '̓', 10 | '̈', '͊', '͋', '͌', 11 | '̃', '̂', '̌', '͐', 12 | '̀', '́', '̋', '̏', 13 | '̒', '̓', '̔', '̽', 14 | '̉', 'ͣ', 'ͤ', 'ͥ', 15 | 'ͦ', 'ͧ', 'ͨ', 'ͩ', 16 | 'ͪ', 'ͫ', 'ͬ', 'ͭ', 17 | 'ͮ', 'ͯ', '̾', '͛', 18 | '͆', '̚' 19 | ], 20 | "down" : [ 21 | '̖', '̗', '̘', '̙', 22 | '̜', '̝', '̞', '̟', 23 | '̠', '̤', '̥', '̦', 24 | '̩', '̪', '̫', '̬', 25 | '̭', '̮', '̯', '̰', 26 | '̱', '̲', '̳', '̹', 27 | '̺', '̻', '̼', 'ͅ', 28 | '͇', '͈', '͉', '͍', 29 | '͎', '͓', '͔', '͕', 30 | '͖', '͙', '͚', '̣' 31 | ], 32 | "mid" : [ 33 | '̕', '̛', '̀', '́', 34 | '͘', '̡', '̢', '̧', 35 | '̨', '̴', '̵', '̶', 36 | '͜', '͝', '͞', 37 | '͟', '͠', '͢', '̸', 38 | '̷', '͡', ' ҉' 39 | ] 40 | }, 41 | all = [].concat(soul.up, soul.down, soul.mid), 42 | zalgo = {}; 43 | 44 | function randomNumber(range) { 45 | var r = Math.floor(Math.random() * range); 46 | return r; 47 | } 48 | 49 | function is_char(character) { 50 | var bool = false; 51 | all.filter(function (i) { 52 | bool = (i === character); 53 | }); 54 | return bool; 55 | } 56 | 57 | 58 | function heComes(text, options) { 59 | var result = '', counts, l; 60 | options = options || {}; 61 | options["up"] = typeof options["up"] !== 'undefined' ? options["up"] : true; 62 | options["mid"] = typeof options["mid"] !== 'undefined' ? options["mid"] : true; 63 | options["down"] = typeof options["down"] !== 'undefined' ? options["down"] : true; 64 | options["size"] = typeof options["size"] !== 'undefined' ? options["size"] : "maxi"; 65 | text = text.split(''); 66 | for (l in text) { 67 | if (is_char(l)) { 68 | continue; 69 | } 70 | result = result + text[l]; 71 | counts = {"up" : 0, "down" : 0, "mid" : 0}; 72 | switch (options.size) { 73 | case 'mini': 74 | counts.up = randomNumber(8); 75 | counts.mid = randomNumber(2); 76 | counts.down = randomNumber(8); 77 | break; 78 | case 'maxi': 79 | counts.up = randomNumber(16) + 3; 80 | counts.mid = randomNumber(4) + 1; 81 | counts.down = randomNumber(64) + 3; 82 | break; 83 | default: 84 | counts.up = randomNumber(8) + 1; 85 | counts.mid = randomNumber(6) / 2; 86 | counts.down = randomNumber(8) + 1; 87 | break; 88 | } 89 | 90 | var arr = ["up", "mid", "down"]; 91 | for (var d in arr) { 92 | var index = arr[d]; 93 | for (var i = 0 ; i <= counts[index]; i++) { 94 | if (options[index]) { 95 | result = result + soul[index][randomNumber(soul[index].length)]; 96 | } 97 | } 98 | } 99 | } 100 | return result; 101 | } 102 | // don't summon him 103 | return heComes(text, options); 104 | } 105 | -------------------------------------------------------------------------------- /auto/node_modules/colors/lib/extendStringPrototype.js: -------------------------------------------------------------------------------- 1 | var colors = require('./colors'); 2 | 3 | module['exports'] = function () { 4 | 5 | // 6 | // Extends prototype of native string object to allow for "foo".red syntax 7 | // 8 | var addProperty = function (color, func) { 9 | String.prototype.__defineGetter__(color, func); 10 | }; 11 | 12 | var sequencer = function sequencer (map, str) { 13 | return function () { 14 | var exploded = this.split(""), i = 0; 15 | exploded = exploded.map(map); 16 | return exploded.join(""); 17 | } 18 | }; 19 | 20 | addProperty('strip', function () { 21 | return colors.strip(this); 22 | }); 23 | 24 | addProperty('stripColors', function () { 25 | return colors.strip(this); 26 | }); 27 | 28 | addProperty("trap", function(){ 29 | return colors.trap(this); 30 | }); 31 | 32 | addProperty("zalgo", function(){ 33 | return colors.zalgo(this); 34 | }); 35 | 36 | addProperty("zebra", function(){ 37 | return colors.zebra(this); 38 | }); 39 | 40 | addProperty("rainbow", function(){ 41 | return colors.rainbow(this); 42 | }); 43 | 44 | addProperty("random", function(){ 45 | return colors.random(this); 46 | }); 47 | 48 | addProperty("america", function(){ 49 | return colors.america(this); 50 | }); 51 | 52 | // 53 | // Iterate through all default styles and colors 54 | // 55 | var x = Object.keys(colors.styles); 56 | x.forEach(function (style) { 57 | addProperty(style, function () { 58 | return colors.stylize(this, style); 59 | }); 60 | }); 61 | 62 | function applyTheme(theme) { 63 | // 64 | // Remark: This is a list of methods that exist 65 | // on String that you should not overwrite. 66 | // 67 | var stringPrototypeBlacklist = [ 68 | '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor', 69 | 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt', 70 | 'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring', 71 | 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight' 72 | ]; 73 | 74 | Object.keys(theme).forEach(function (prop) { 75 | if (stringPrototypeBlacklist.indexOf(prop) !== -1) { 76 | console.log('warn: '.red + ('String.prototype' + prop).magenta + ' is probably something you don\'t want to override. Ignoring style name'); 77 | } 78 | else { 79 | if (typeof(theme[prop]) === 'string') { 80 | colors[prop] = colors[theme[prop]]; 81 | addProperty(prop, function () { 82 | return colors[theme[prop]](this); 83 | }); 84 | } 85 | else { 86 | addProperty(prop, function () { 87 | var ret = this; 88 | for (var t = 0; t < theme[prop].length; t++) { 89 | ret = colors[theme[prop][t]](ret); 90 | } 91 | return ret; 92 | }); 93 | } 94 | } 95 | }); 96 | } 97 | 98 | colors.setTheme = function (theme) { 99 | if (typeof theme === 'string') { 100 | try { 101 | colors.themes[theme] = require(theme); 102 | applyTheme(colors.themes[theme]); 103 | return colors.themes[theme]; 104 | } catch (err) { 105 | console.log(err); 106 | return err; 107 | } 108 | } else { 109 | applyTheme(theme); 110 | } 111 | }; 112 | 113 | }; -------------------------------------------------------------------------------- /auto/node_modules/colors/lib/index.js: -------------------------------------------------------------------------------- 1 | var colors = require('./colors'); 2 | module['exports'] = colors; 3 | 4 | // Remark: By default, colors will add style properties to String.prototype 5 | // 6 | // If you don't wish to extend String.prototype you can do this instead and native String will not be touched 7 | // 8 | // var colors = require('colors/safe); 9 | // colors.red("foo") 10 | // 11 | // 12 | require('./extendStringPrototype')(); -------------------------------------------------------------------------------- /auto/node_modules/colors/lib/maps/america.js: -------------------------------------------------------------------------------- 1 | var colors = require('../colors'); 2 | 3 | module['exports'] = (function() { 4 | return function (letter, i, exploded) { 5 | if(letter === " ") return letter; 6 | switch(i%3) { 7 | case 0: return colors.red(letter); 8 | case 1: return colors.white(letter) 9 | case 2: return colors.blue(letter) 10 | } 11 | } 12 | })(); -------------------------------------------------------------------------------- /auto/node_modules/colors/lib/maps/rainbow.js: -------------------------------------------------------------------------------- 1 | var colors = require('../colors'); 2 | 3 | module['exports'] = (function () { 4 | var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta']; //RoY G BiV 5 | return function (letter, i, exploded) { 6 | if (letter === " ") { 7 | return letter; 8 | } else { 9 | return colors[rainbowColors[i++ % rainbowColors.length]](letter); 10 | } 11 | }; 12 | })(); 13 | 14 | -------------------------------------------------------------------------------- /auto/node_modules/colors/lib/maps/random.js: -------------------------------------------------------------------------------- 1 | var colors = require('../colors'); 2 | 3 | module['exports'] = (function () { 4 | var available = ['underline', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta']; 5 | return function(letter, i, exploded) { 6 | return letter === " " ? letter : colors[available[Math.round(Math.random() * (available.length - 1))]](letter); 7 | }; 8 | })(); -------------------------------------------------------------------------------- /auto/node_modules/colors/lib/maps/zebra.js: -------------------------------------------------------------------------------- 1 | var colors = require('../colors'); 2 | 3 | module['exports'] = function (letter, i, exploded) { 4 | return i % 2 === 0 ? letter : colors.inverse(letter); 5 | }; -------------------------------------------------------------------------------- /auto/node_modules/colors/lib/styles.js: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) Sindre Sorhus (sindresorhus.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | */ 25 | 26 | var styles = {}; 27 | module['exports'] = styles; 28 | 29 | var codes = { 30 | reset: [0, 0], 31 | 32 | bold: [1, 22], 33 | dim: [2, 22], 34 | italic: [3, 23], 35 | underline: [4, 24], 36 | inverse: [7, 27], 37 | hidden: [8, 28], 38 | strikethrough: [9, 29], 39 | 40 | black: [30, 39], 41 | red: [31, 39], 42 | green: [32, 39], 43 | yellow: [33, 39], 44 | blue: [34, 39], 45 | magenta: [35, 39], 46 | cyan: [36, 39], 47 | white: [37, 39], 48 | gray: [90, 39], 49 | grey: [90, 39], 50 | 51 | bgBlack: [40, 49], 52 | bgRed: [41, 49], 53 | bgGreen: [42, 49], 54 | bgYellow: [43, 49], 55 | bgBlue: [44, 49], 56 | bgMagenta: [45, 49], 57 | bgCyan: [46, 49], 58 | bgWhite: [47, 49], 59 | 60 | // legacy styles for colors pre v1.0.0 61 | blackBG: [40, 49], 62 | redBG: [41, 49], 63 | greenBG: [42, 49], 64 | yellowBG: [43, 49], 65 | blueBG: [44, 49], 66 | magentaBG: [45, 49], 67 | cyanBG: [46, 49], 68 | whiteBG: [47, 49] 69 | 70 | }; 71 | 72 | Object.keys(codes).forEach(function (key) { 73 | var val = codes[key]; 74 | var style = styles[key] = []; 75 | style.open = '\u001b[' + val[0] + 'm'; 76 | style.close = '\u001b[' + val[1] + 'm'; 77 | }); -------------------------------------------------------------------------------- /auto/node_modules/colors/lib/system/supports-colors.js: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) Sindre Sorhus (sindresorhus.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | */ 25 | 26 | var argv = process.argv; 27 | 28 | module.exports = (function () { 29 | if (argv.indexOf('--no-color') !== -1 || 30 | argv.indexOf('--color=false') !== -1) { 31 | return false; 32 | } 33 | 34 | if (argv.indexOf('--color') !== -1 || 35 | argv.indexOf('--color=true') !== -1 || 36 | argv.indexOf('--color=always') !== -1) { 37 | return true; 38 | } 39 | 40 | if (process.stdout && !process.stdout.isTTY) { 41 | return false; 42 | } 43 | 44 | if (process.platform === 'win32') { 45 | return true; 46 | } 47 | 48 | if ('COLORTERM' in process.env) { 49 | return true; 50 | } 51 | 52 | if (process.env.TERM === 'dumb') { 53 | return false; 54 | } 55 | 56 | if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) { 57 | return true; 58 | } 59 | 60 | return false; 61 | })(); -------------------------------------------------------------------------------- /auto/node_modules/colors/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "colors", 3 | "description": "get colors in your node.js console", 4 | "version": "1.1.2", 5 | "author": { 6 | "name": "Marak Squires" 7 | }, 8 | "homepage": "https://github.com/Marak/colors.js", 9 | "bugs": { 10 | "url": "https://github.com/Marak/colors.js/issues" 11 | }, 12 | "keywords": [ 13 | "ansi", 14 | "terminal", 15 | "colors" 16 | ], 17 | "repository": { 18 | "type": "git", 19 | "url": "git+ssh://git@github.com/Marak/colors.js.git" 20 | }, 21 | "license": "MIT", 22 | "scripts": { 23 | "test": "node tests/basic-test.js && node tests/safe-test.js" 24 | }, 25 | "engines": { 26 | "node": ">=0.1.90" 27 | }, 28 | "main": "lib", 29 | "files": [ 30 | "examples", 31 | "lib", 32 | "LICENSE", 33 | "safe.js", 34 | "themes" 35 | ], 36 | "gitHead": "8bf2ad9fa695dcb30b7e9fd83691b139fd6655c4", 37 | "_id": "colors@1.1.2", 38 | "_shasum": "168a4701756b6a7f51a12ce0c97bfa28c084ed63", 39 | "_from": "colors@*", 40 | "_npmVersion": "2.1.8", 41 | "_nodeVersion": "0.11.13", 42 | "_npmUser": { 43 | "name": "marak", 44 | "email": "marak.squires@gmail.com" 45 | }, 46 | "maintainers": [ 47 | { 48 | "name": "marak", 49 | "email": "marak.squires@gmail.com" 50 | } 51 | ], 52 | "dist": { 53 | "shasum": "168a4701756b6a7f51a12ce0c97bfa28c084ed63", 54 | "size": 8212, 55 | "noattachment": false, 56 | "tarball": "http://registry.npm.taobao.org/colors/download/colors-1.1.2.tgz" 57 | }, 58 | "directories": {}, 59 | "publish_time": 1434546180583, 60 | "_cnpm_publish_time": 1434546180583, 61 | "_resolved": "https://registry.npm.taobao.org/colors/download/colors-1.1.2.tgz", 62 | "readme": "ERROR: No README data found!" 63 | } 64 | -------------------------------------------------------------------------------- /auto/node_modules/colors/safe.js: -------------------------------------------------------------------------------- 1 | // 2 | // Remark: Requiring this file will use the "safe" colors API which will not touch String.prototype 3 | // 4 | // var colors = require('colors/safe); 5 | // colors.red("foo") 6 | // 7 | // 8 | var colors = require('./lib/colors'); 9 | module['exports'] = colors; -------------------------------------------------------------------------------- /auto/node_modules/colors/themes/generic-logging.js: -------------------------------------------------------------------------------- 1 | module['exports'] = { 2 | silly: 'rainbow', 3 | input: 'grey', 4 | verbose: 'cyan', 5 | prompt: 'grey', 6 | info: 'green', 7 | data: 'grey', 8 | help: 'cyan', 9 | warn: 'yellow', 10 | debug: 'blue', 11 | error: 'red' 12 | }; -------------------------------------------------------------------------------- /auto/task/captcha.txt: -------------------------------------------------------------------------------- 1 | rwpkr#1446172349674 -------------------------------------------------------------------------------- /auto/task/yunpan.js: -------------------------------------------------------------------------------- 1 | var casper = require('casper').create({ 2 | pageSettings : { 3 | loadImages : true 4 | }, 5 | viewportSize : { 6 | width : 1200, 7 | height : 600 8 | }, 9 | timeout : 1000000 10 | }); 11 | var info = JSON.parse( casper.cli.get(0) ); 12 | 13 | var fs = require('fs'); 14 | 15 | casper.waitForCaptcha = function(captchaFile, parsedFile){ 16 | casper.then(function(){ 17 | this.captureSelector(captchaFile, ".quc-captcha-img"); 18 | }); 19 | var key = +new Date(); 20 | console.log('key is ' + key ); 21 | casper.waitFor(function check(){ 22 | 23 | var content = fs.read( parsedFile ); 24 | 25 | if( content.indexOf(key) < 0 ){ 26 | return false; 27 | }else{ 28 | return true; 29 | } 30 | 31 | }, function then(){ 32 | var content = fs.read( parsedFile ); 33 | casper.then(function(){ 34 | this.fillSelectors('form.quc-form',{ 35 | 'input[name="account"]' : info.user, 36 | 'input[name="password"]' : info.pass, 37 | 'input[name="phrase"]' : content.split('#')[0] 38 | }, true); 39 | console.log('用户名密码自动填充中...'); 40 | }); 41 | 42 | }, function onTimeout(){ 43 | 44 | }, 60000); 45 | return this; 46 | }; 47 | 48 | casper.start( info.url , function(){ 49 | console.log('----------------------------'); 50 | console.log('云盘抽奖任务开始运行'); 51 | }); 52 | 53 | casper.waitForSelector('#login',function(){ 54 | casper.waitForCaptcha( 'task/captcha.png', 'task/captcha.txt'); 55 | }); 56 | 57 | casper.then(function(){ 58 | this.click('input[type="submit"]'); 59 | this.capture('task/1.png'); 60 | console.log('开始尝试登录'); 61 | }); 62 | 63 | casper.waitForSelector('#lottery-everyday',function(){ 64 | console.log('登陆成功'); 65 | this.click('#lottery-everyday'); 66 | }); 67 | 68 | casper.then(function(){ 69 | this.click('#lottery-everyday'); 70 | }); 71 | 72 | casper.waitFor( function check(){ 73 | return this.evaluate(function(){ 74 | return document.querySelector('#BasePanel1').style.display === 'none' ? false : true; 75 | }) 76 | },function then(){ 77 | var m = this.evaluate(function(){ 78 | return document.querySelector('#BasePanel1 .content0 h2').innerHTML; 79 | }); 80 | var text = this.evaluate(function(){ 81 | return document.querySelector('#BasePanel1 .content2').innerText; 82 | }); 83 | 84 | console.log(m); 85 | 86 | if( m.indexOf('MB') < 0 ){ 87 | console.log('今天已经抽过了。') 88 | }else{ 89 | console.log( '抽奖成功 : ' + m ); 90 | } 91 | 92 | }); 93 | 94 | casper.run(); -------------------------------------------------------------------------------- /countDown/mcountdown.js: -------------------------------------------------------------------------------- 1 | (function( root , factory ){ 2 | 3 | if( typeof define === 'function' && define.amd ){ 4 | //AMD 5 | define(factory); 6 | }else if( typeof exports === 'object' ){ 7 | //Node , CommonJS之类 8 | module.exports = factory(); 9 | }else{ 10 | //直接暴露全局变量 11 | root.mcountdown = factory(); 12 | } 13 | 14 | })( window , function(){ 15 | 16 | 'use strict'; 17 | 18 | return function( leftSeconds , ingcallback , overcallback ){ 19 | 20 | var start = +new Date(), //获取当前时间戳 21 | 22 | timeleft = leftSeconds*1000, //剩余秒数转化为毫秒 23 | 24 | end = start + timeleft; //计算得到结束时间戳 25 | 26 | 27 | function second2JSON( timeleft ){ 28 | 29 | var days = parseInt( timeleft/86400 ), 30 | 31 | hours = parseInt( (timeleft%86400)/3600 ), 32 | 33 | minutes = parseInt( ((timeleft%86400)%3600)/60 ), 34 | 35 | seconds = parseInt( ((timeleft%86400)%3600)%60 ); 36 | 37 | return { 38 | days : days, 39 | hours : hours < 10 ? '0' + hours : hours, 40 | minutes : minutes < 10 ? '0' + minutes : minutes, 41 | seconds : seconds < 10 ? '0' + seconds : seconds 42 | }; 43 | 44 | } 45 | 46 | function runner(){ 47 | //使用时间戳做对比,保证倒计时的精确性。 48 | var now = +new Date(); //得到运行状态中得时间戳 49 | 50 | if( now >= end ){ //如果倒计时已经结束,则中断 51 | 52 | if( overcallback ){ 53 | overcallback(); //执行倒计时结束的回调函数 54 | } 55 | 56 | return false; 57 | } 58 | 59 | if( ingcallback ){ 60 | ingcallback.call( second2JSON((end - now)/1000) ); 61 | } 62 | 63 | setTimeout(function(){ 64 | runner(); 65 | },333); 66 | } 67 | 68 | runner(); 69 | 70 | }; 71 | 72 | }); -------------------------------------------------------------------------------- /getFlashVersion/getFlashVersion.js: -------------------------------------------------------------------------------- 1 | /** 2 | * [isSupportFlash description] 3 | * @return {number} [ -1(不支持flash) | flash版本号] 4 | */ 5 | function getFlashVersion() { 6 | var version = -1; 7 | if( window.ActiveXObject ) { 8 | try{ 9 | var swf = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); 10 | version = parseInt( swf.GetVariable("$version").split(" ")[1].split(",")[0]); 11 | } 12 | catch(e){} 13 | } 14 | else{ 15 | if( navigator.plugins && navigator.plugins["Shockwave Flash"] ) { 16 | var arr = navigator.plugins['Shockwave Flash'].description.split(' '); 17 | var i = 0; 18 | var length = arr.length; 19 | if ( arr ) { 20 | for ( ; i < length ; i++) { 21 | if (!isNaN( Number(arr[i]) )) { 22 | version = Number(arr[i]); 23 | break; 24 | } 25 | } 26 | } 27 | } 28 | } 29 | return version; 30 | } -------------------------------------------------------------------------------- /imgCompress/imgCompress.js: -------------------------------------------------------------------------------- 1 | 2 | (function( window){ 3 | 4 | var imgCompress = function( option , callback ){ 5 | 6 | var option = option || {}, 7 | canvas = document.createElement('canvas'), 8 | context = canvas.getContext('2d'), 9 | img = new Image(), 10 | 11 | maxwidth = option.maxwidth, 12 | maxheight = option.height, 13 | 14 | scale = option.scale || .8; 15 | 16 | img.onload = function(){ 17 | 18 | var _width = img.width, 19 | _height = img.height, 20 | 21 | 22 | _percent = _width/_height, 23 | 24 | real_width = _width, 25 | real_height = _height; 26 | 27 | 28 | 29 | if( typeof maxwidth === undefined ) { maxwidth = _width } 30 | if( typeof maxheight === undefined ) { maxheight = _height } 31 | 32 | 33 | 34 | if( _percent > maxwidth/maxheight && _width > maxwidth ){ 35 | real_width = maxwidth; 36 | real_height = _height*maxwidth/_width; 37 | } 38 | 39 | if( _percent <= maxwidth/maxheight && _height > maxheight ){ 40 | real_width = _width*maxheight/_height; 41 | real_height = maxheight; 42 | } 43 | 44 | canvas.width = real_width; 45 | canvas.height = real_height; 46 | 47 | context.drawImage( img ,0,0 , _width , _height , 0, 0, real_width , real_height ); 48 | 49 | var res = canvas.toDataURL('image/jpeg',scale); 50 | 51 | callback&&callback( res ); 52 | 53 | 54 | } 55 | 56 | img.src = option.src; 57 | 58 | } 59 | 60 | window.imgCompress = window.imgCompress ? window.imgCompress : imgCompress; 61 | 62 | })( window ) 63 | 64 | -------------------------------------------------------------------------------- /imgCompress/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | canvas图片压缩 6 | 7 | 8 | 9 |
10 | 11 | 12 | 46 | -------------------------------------------------------------------------------- /jQuery.CusScrollBar/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery.cusScrollBar 6 | 7 | 8 | 50 | 51 | 52 |
53 |
54 | 55 |
56 |
57 |
58 |
59 |
60 |
61 | 77 | 78 | -------------------------------------------------------------------------------- /jQuery.CusScrollBar/jQuery.cusScrollBar.js: -------------------------------------------------------------------------------- 1 | (function(window, document, $) { 2 | 3 | /** 4 | * @class CusScrollBar 自定义滚动条 使用示例:http://pyzy.net/Demo/cus_scroll_bar.html 5 | * @param options 配置表 6 | * { 7 | * scrollDir:"y", //滚动条方向 ['x'||'y',默认'y' 纵向滚动] 8 | * contSelector:"", //内容容器元素选择器 [必填项] 9 | * scrollBarSelector:"", //滚动条模拟元素选择器[非必填项,如果为空则自动取sliderSelector的父容器] 10 | * sliderSelector:"", //滚动条滑块 [非必填项,不需要滑块可忽略该配置(比如只需要按钮控制滚动时)] 11 | * addBtnSelector:"", //滚动条坐标增加按钮(横向的向右,纵向的向下按钮) [非必填项,不需要滚动条位移增加按钮,则忽略该配置] 12 | * subBtnSelector:"", //滚动条坐标减少按钮(横向的向左,纵向的向上按钮) [非必填项,不需要滚动条位移减少按钮,则忽略该配置] 13 | * btnClkStepSize:60, //按钮控制时,单次操作滚动的幅度(匀速动画形式完成滚动,滚动速度依赖scrollAnimTime、scrollStepTime配置) 14 | * sliderMinHeight:10, //滑块最小高度(若滑块按比例计算后小于当前值,则以当前值显示) 15 | * sliderAlwaysShow:false, //滑块是否保持显示(false则按照内容多少,自动判断显示、隐藏) 16 | * scrollAnimTime:80, //scrollToAnim单词动画总时长(结合scrollStepTime计算帧数) 17 | * scrollStepTime:10, //scrollToAnim动画执行中每帧时长 18 | * scrollAnimAwait:false, //滚动条动画是否等待上一帧完毕才执行交互响应 19 | * wheelStepSize:80, //滚轮控制滚动时,每次滚动触发的位移距离 20 | * wheelBindSelector:'', //滚轮事件要绑定到的DOM元素选择器(比如可以直接将内容容器的滚动交互绑到document上以实现局部fixed等) 21 | * autoInitUiEvent:true, //是否自动初始化UI事件绑定(使用者设为false则禁用自动初始化,此时可以手动调配一些隐含的配置后,再手动初始化) 22 | * animEasing:function(p){ return p } //动画算子,改变则控制动画方式 23 | * } 24 | * @events <自定义事件> 通过实例cs.on(type,handler)绑定、通过cs.un(type,handler)解绑、通过cs.fire(type)触发 25 | * { 26 | * scroll //滚动条变化 27 | * resizeSlider //滑块尺寸变更 、内容容器改变 28 | * sliderMove //滑块坐标变更 29 | * sliderShow //滑块由隐藏变为显示 30 | * sliderHide //滑块由显示变为隐藏 31 | * contChange //变更了绑定的内容容器 32 | * mouseEnter //hoverDoms hover触发(含滑块、滚动条容器、按钮、内容容器) 33 | * mouseLeave //hoverDoms hover触发(含滑块、滚动条容器、按钮、内容容器) 34 | * scrollToAnimSta //滚动动画开始 35 | * scrollToAnimEnd //滚动动画结束 36 | * scrollToAniming //滚动动画播放中每一帧触发一次... 37 | * } 38 | */ 39 | function CusScrollBar(options) { 40 | 41 | this._init.call(this, options); 42 | 43 | }; 44 | 45 | 46 | var topLeft = { 47 | y: "Top", 48 | x: "Left" 49 | }, 50 | widthHeight = { 51 | y: "Height", 52 | x: "Width" 53 | }, 54 | /* hover交互中各关联DOM及将追加的className */ 55 | hoverCls = { 56 | scrollBar: "scroll-bar-hover", 57 | slider: "slider-hover", 58 | addBtn: "add-btn-hover", 59 | subBtn: "sub-btn-hover" 60 | }, 61 | /* 设定要绑定hover交互的元素们 */ 62 | hoverDoms = $.extend({ 63 | cont: '' 64 | }, hoverCls), 65 | sliderActiveCls = "slider-active", 66 | /* 开关拖选功能 */ 67 | preventDefaultHandler = function(e) { 68 | e.preventDefault() 69 | }, 70 | selectEventType = "onselectstart" in document.createElement("div") ? "selectstart" : "mousedown"; 71 | 72 | $.extend(CusScrollBar.prototype, { 73 | 74 | /** 75 | * 统一初始化入口 76 | * @method _init 77 | * @param {Object} options JSON格式配置参数 78 | * @returns {CusScrollBar} 79 | */ 80 | _init: function(options) { 81 | var _t = this; 82 | 83 | options = options || {}; 84 | 85 | /* 合并配置参数 */ 86 | _t.options = $.extend(true, { 87 | scrollDir: "y", 88 | contSelector: "", 89 | scrollBarSelector: "", 90 | sliderSelector: "", 91 | addBtnSelector: "", 92 | subBtnSelector: "", 93 | btnClkStepSize: 60, 94 | sliderMinHeight: 10, 95 | sliderAlwaysShow: false, 96 | scrollAnimTime: 80, 97 | scrollStepTime: 10, 98 | scrollAnimAwait: false, 99 | wheelStepSize: 80, 100 | wheelBindSelector: '', 101 | autoInitUiEvent: true, 102 | animEasing: function(p) { 103 | return p 104 | } 105 | //animEasing:function(p){ return -1/2 * (Math.cos(Math.PI*p) - 1) } 106 | /*animEasing:function (p) { 107 | if (p < (1 / 2.75)) { 108 | return (7.5625 * p * p); 109 | } else if (p < (2 / 2.75)) { 110 | return (7.5625 * (p -= (1.5 / 2.75)) * p + 0.75); 111 | } else if (p < (2.5 / 2.75)) { 112 | return (7.5625 * (p -= (2.25 / 2.75)) * p + 0.9375); 113 | } 114 | return (7.5625 * (p -= (2.625 / 2.75)) * p + 0.984375); 115 | }*/ 116 | }, options); 117 | 118 | /* 根据设定坐标方向得到要用于计算的属性(使用简写,不建议外部使用)*/ 119 | var _dir = options.scrollDir == 'x' ? 'x' : 'y', 120 | scr = "scroll", 121 | _tl = topLeft[_dir], 122 | _wh = widthHeight[_dir]; 123 | $.extend(true, _t, { 124 | _dir: _dir, //'x' || 'y' 125 | _tl: _tl, //'Top' || 'Left' 126 | _tl_: _tl.toLowerCase(), //'top' || 'left' 127 | _stl: scr + _tl, //'scrollTop' || 'scrollLeft' 128 | _wh: _wh, //'Width' || 'Height' 129 | _wh_: _wh.toLowerCase(), //'width' || 'height' 130 | _swh: scr + _wh //'scrollWidth' || 'scrollHeight' 131 | }); 132 | 133 | //初始化自定义事件相关功能 134 | _t._initCustEvent()._initDomEvent(); 135 | 136 | return _t; 137 | }, 138 | 139 | /** 140 | * 初始化自定义事件(让当前对象支持 on%un\fire方法) 141 | * @method _initCustEvent 142 | * @returns {CusScrollBar} 143 | */ 144 | _initCustEvent: function() { 145 | var _t = this, 146 | _event = $(_t); 147 | $.each({ 148 | on: "on", 149 | /*绑定*/ 150 | un: "unbind", 151 | /*解绑*/ 152 | fire: "triggerHandler" /*触发*/ 153 | }, function(key, val) { 154 | _t[key] = function() { 155 | _event[val].apply(_event, arguments); 156 | return _t; 157 | }; 158 | }); 159 | return _t; 160 | }, 161 | 162 | /** 163 | * 初始化DOM引用、基础参数 164 | * @method _initDom 165 | * @returns {CusScrollBar} 166 | */ 167 | _initDomEvent: function() { 168 | 169 | var _t = this, 170 | opts = _t.options, 171 | _sliderW = _t._sliderW = opts.sliderSelector && $(opts.sliderSelector); 172 | 173 | //内容容器 174 | _t._contW = $(opts.contSelector); 175 | //滚轮事件要绑定到的DOM元素 176 | _t._wheelBindW = opts.wheelBindSelector ? $(opts.wheelBindSelector) : _t._contW; 177 | //滚动条 178 | _t._scrollBarW = opts.scrollBarSelector ? $(opts.scrollBarSelector) : _sliderW && _sliderW.parent(); 179 | 180 | //文档对象 181 | _t._docW = $(document); 182 | 183 | if (opts.autoInitUiEvent) { 184 | 185 | //初始化滚动条控制按钮(add、sub分别对应滚动条坐标增加、减少控制按钮) 186 | _t._initButton("add") 187 | ._initButton("sub") 188 | /*初始化滑块拖动功能*/ 189 | ._initSliderDragEvent() 190 | /*初始化滚动条点击重新定位功能*/ 191 | ._initScrollBarEvent() 192 | /*重算滑块尺寸*/ 193 | .resizeSlider() 194 | /*重算滑块坐标*/ 195 | .removeSlider() 196 | /*绑定滚轮操作*/ 197 | .bindMousewheel() 198 | /*绑定内容滚动交互,同步滑块坐标*/ 199 | .bindContScroll() 200 | /*绑定hover交互*/ 201 | .bindHover(); 202 | 203 | } 204 | }, 205 | 206 | /** 207 | * 初始化控制按钮引用及交互事件,并将对应DOM引用赋值给_t._addBtnW||_t._subBtnW(前提需要有设置addBtnSelector||subBtnSelector) 208 | * @method _initButton 209 | * @param {String} btnType ["add"||"sub"] add、sub分别对应滚动条坐标增加、减少控制按钮 210 | * @returns {CusScrollBar} 211 | */ 212 | _initButton: function(btnType) { 213 | var _t = this, 214 | opts = _t.options, 215 | btnSelector = opts[btnType + 'BtnSelector']; 216 | /* 没设定对应DOM元素选择器,则不执行后续初始化 */ 217 | if (btnSelector) { 218 | var btnW = _t["_" + btnType + "BtnW"] = $(btnSelector), 219 | basicNum = btnType == "add" ? 1 : -1, 220 | docW = _t._docW; 221 | 222 | /* 按设定按钮点击对应滚动步长执行滚动动画 */ 223 | function btnAnim() { 224 | //console.log('btnAnim',_t.getScrollPosition(),_t.options.btnClkStepSize); 225 | _t.scrollToAnim(_t.getScrollPosition() + _t.options.btnClkStepSize * basicNum); 226 | }; 227 | 228 | /* 释放按钮 */ 229 | function btnMouseUpHandler(e) { 230 | e.preventDefault(); 231 | _t.un("scrollToAnimEnd", btnAnim); 232 | docW.unbind("mouseup", btnMouseUpHandler); 233 | }; 234 | 235 | /* 按下按钮 */ 236 | btnW.on("mousedown", function(e) { 237 | e.preventDefault(); 238 | docW.on("mouseup", btnMouseUpHandler); 239 | _t.on("scrollToAnimEnd", btnAnim); 240 | btnAnim(); 241 | }); 242 | } 243 | return _t; 244 | }, 245 | 246 | //改变滚动条插件绑定到的容器为另一个contEl 247 | replaceCont: function(contSelector) { 248 | var _t = this, 249 | autoInitEvt = _t.options.autoInitUiEvent; 250 | //解除已绑定的DOM事件 251 | autoInitEvt && _t.unbindMousewheel().unbindContScroll().unbindHover(); 252 | //替换掉内容容器 253 | _t._contW = $(contSelector); 254 | //重新初始化滑块尺寸、坐标、各DOM元素事件绑定 255 | autoInitEvt && _t.resizeSlider().removeSlider().bindMousewheel().bindContScroll().bindHover(); 256 | _t.fire("contChange"); 257 | return _t; 258 | }, 259 | 260 | /** 261 | * 绑定滚轮控制事件到设定元素 262 | * @method bindMousewheel 263 | * @returns {CusScrollBar} 264 | */ 265 | bindMousewheel: function() { 266 | var _t = this; 267 | _t._wheelBindW.on("mousewheel", _t._mousewheelHandler || (_t._mousewheelHandler = function(e) { 268 | e.preventDefault(); 269 | var oE = e.originalEvent, 270 | wheelDelta = oE.detail || -(oE.wheelDelta || 0); 271 | _t.scrollToAnim(_t.getScrollPosition() + wheelDelta / Math.abs(wheelDelta) * _t.options.wheelStepSize); 272 | })); 273 | return _t; 274 | }, 275 | 276 | /** 277 | * 解绑滚轮控制(为内容容器可通过replaceCont进行更换提供解绑处理) 278 | * @method unbindMousewheel 279 | * @returns {CusScrollBar} 280 | */ 281 | unbindMousewheel: function() { 282 | var _t = this, 283 | _mousewheelHandler = _t._mousewheelHandler; 284 | _mousewheelHandler && _t._wheelBindW.unbind("mousewheel", _mousewheelHandler); 285 | return _t; 286 | }, 287 | 288 | /** 289 | * 绑定内容容器的滚动事件(同步滑块坐标) 290 | * @method bindContScroll 291 | * @returns {CusScrollBar} 292 | */ 293 | bindContScroll: function() { 294 | var _t = this; 295 | _t._contW.on("scroll", _t._contScrollHandler || (_t._contScrollHandler = function() { 296 | //console.log(this,'_contW scroll'); 297 | _t.removeSlider(); 298 | })); 299 | return _t; 300 | }, 301 | 302 | /** 303 | * 解除内容容器的滚动事件(为内容容器可通过replaceCont进行更换提供解绑处理) 304 | * @method unbindContScroll 305 | * @returns {CusScrollBar} 306 | */ 307 | unbindContScroll: function() { 308 | var _t = this, 309 | _contScrollHandler = _t._contScrollHandler; 310 | _contScrollHandler && _t._contW.unbind("scroll", _contScrollHandler); 311 | return _t; 312 | }, 313 | 314 | /** 315 | * 为操作按钮或滑块绑定hover交互(追加或移除滑块、滚动条、操作按钮hover交互的className,内容容器hover时同样触发hover) 316 | * @method bindHover 317 | * @returns {CusScrollBar} 318 | */ 319 | bindHover: function() { 320 | var _t = this, 321 | _mouseEnterHandler = _t._mouseEnterHandler || (_t._mouseEnterHandler = function() { 322 | $.each(hoverCls, function(key, cls) { 323 | var elW = _t["_" + key + "W"]; 324 | elW && elW.addClass(cls); 325 | if (!_t._hoverStatus) { 326 | _t._hoverStatus = true; 327 | _t.fire("mouseEnter"); 328 | } 329 | }); 330 | }), 331 | _mouseLeaveHandler = _t._mouseLeaveHandler || (_t._mouseLeaveHandler = function() { 332 | $.each(hoverCls, function(key, cls) { 333 | var elW = _t["_" + key + "W"]; 334 | elW && elW.removeClass(cls); 335 | if (_t._hoverStatus) { 336 | _t._hoverStatus = false; 337 | _t.fire("mouseLeave"); 338 | } 339 | }); 340 | }); 341 | 342 | $.each(hoverDoms, function(key, cls) { 343 | var elW = _t["_" + key + "W"]; 344 | elW && elW.on("mouseenter", _mouseEnterHandler).on("mouseleave", _mouseLeaveHandler); 345 | }); 346 | 347 | return _t; 348 | }, 349 | /** 350 | * 为操作按钮或滑块解绑hover交互(为内容容器可通过replaceCont进行更换提供解绑处理) 351 | * @method unbindHover 352 | * @returns {CusScrollBar} 353 | */ 354 | unbindHover: function() { 355 | var _t = this; 356 | $.each(hoverDoms, function(key, cls) { 357 | var elW = _t["_" + key + "W"]; 358 | if (elW) { 359 | _t._mouseEnterHandler && elW.unbind("mouseleave", _t._mouseEnterHandler); 360 | _t._mouseLeaveHandler && elW.unbind("mouseleave", _t._mouseLeaveHandler); 361 | } 362 | }); 363 | return _t; 364 | }, 365 | 366 | /** 367 | * 初始化滑块拖动DOM事件 368 | * @method _initSliderDragEvent 369 | * @returns {CusScrollBar} 370 | */ 371 | _initSliderDragEvent: function() { 372 | var _t = this, 373 | sliderW = _t._sliderW, 374 | sliderEl = sliderW && sliderW[0]; 375 | if (sliderEl) { 376 | var docW = _t._docW, 377 | dragStaPagePos, dragStaScrollBarRate, dragStaScrollPos; 378 | 379 | /* document的museup事件释放拖动(除了鼠标释放,自动加载下一屏的需求中也需要自动释放拖动,所以后面通过releaseDrag将该方法暴露出去) */ 380 | function docMouseupHandler(e) { 381 | dragStaPagePos = null; 382 | e && e.preventDefault(); 383 | sliderEl.releaseCapture && sliderEl.releaseCapture(); //for ie6 解除绑定滑块事件监听 384 | sliderW.removeClass(sliderActiveCls); 385 | docW.unbind(selectEventType, preventDefaultHandler); //重启拖选 386 | //console.log('docMouseupHandler'); 387 | docW.unbind("mouseup contextmenu", docMouseupHandler).unbind("mousemove", docMousemoveHandler); 388 | }; 389 | 390 | /* 暴露主动释放拖拽的功能接口 */ 391 | _t.releaseDrag = docMouseupHandler; 392 | 393 | /* 拖拽 */ 394 | function docMousemoveHandler(e) { 395 | if (dragStaPagePos == null) return; 396 | //起始坐标点 + (鼠标位移距离*滚动条最大坐标值/滚动条容器尺寸) 397 | _t.scrollTo(dragStaScrollPos + (_t.getPageXY(e) - dragStaPagePos) * dragStaScrollBarRate); 398 | }; 399 | 400 | /* 滑块被按下时启动拖拽 */ 401 | sliderW.on("mousedown", function(e) { 402 | e.stopPropagation(); 403 | e.preventDefault(); 404 | dragStaPagePos = _t.getPageXY(e); //鼠标按下时页面中的所在坐标 405 | dragStaScrollBarRate = _t.getScrollSize() / _t.getScrollBarSize(); //鼠标按下时计算滚动条最大值与滚动条容器的比率(用于将鼠标位移距离转换为滚动条位移距离) 406 | dragStaScrollPos = _t.getScrollPosition(); //鼠标按下时滚动条所在的坐标点 407 | sliderEl.setCapture && sliderEl.setCapture(); //for ie6 绑定事件监听到滑块 408 | sliderW.addClass(sliderActiveCls); 409 | docW.on(selectEventType, preventDefaultHandler) //关闭拖选 410 | .on("mouseup contextmenu", docMouseupHandler) 411 | .on("mousemove", docMousemoveHandler); 412 | }); 413 | } 414 | return _t; 415 | }, 416 | 417 | 418 | /** 419 | * 点击滚动条容器触发滚动并重新定位滑块 420 | * @method _initScrollBarEvent 421 | * @returns {CusScrollBar} 422 | */ 423 | _initScrollBarEvent: function() { 424 | var _t = this, 425 | scrollBarW = _t._scrollBarW; 426 | scrollBarW && scrollBarW.on("mousedown", function(e) { 427 | _t.scrollToByPagePos(e); 428 | }); 429 | return _t; 430 | }, 431 | 432 | /** 433 | * 为用于模拟的元素绑定原生DOM事件 434 | * @method onDomEvent 435 | * @param {String} type 事件名称 436 | * @param {Function} handler 监听方法 437 | * @param {String} elName 取值范围为对象hoverDoms的key或选择器(为空则默认为滑块) 438 | * @returns {CusScrollBar} 439 | */ 440 | onDomEvent: function(type, handler, elName) { 441 | elName = elName || "slider"; //slider || cont || scrollBar 442 | var _t = this, 443 | elW = _t['_' + elName + 'W'] || $(elName); 444 | elW && elW.on(type, handler); 445 | return _t; 446 | }, 447 | 448 | /** 449 | * 为用于模拟的元素解绑原生事件 450 | * @method unDomEvent 451 | * @param {String} type 事件名称 452 | * @param {Function} handler 监听方法 453 | * @param {String} elName 取值范围为对象hoverDoms的key或选择器(为空则默认为滑块) 454 | * @returns {CusScrollBar} 455 | */ 456 | unDomEvent: function(type, handler, elName) { 457 | elName = elName || "slider"; //slider || cont || scrollBar 458 | var _t = this, 459 | elW = _t['_' + elName + 'W'] || $(elName); 460 | elW && elW.unbind(type, handler); 461 | return _t; 462 | }, 463 | 464 | _animTimer: null, 465 | _animProgress: null, 466 | /** 467 | * 动画渐进式执行scrollTo 468 | * @method scrollToAnim 469 | * @param {Number} toVal 要滚动到的目标坐标值 470 | * @param {Number} stepTime 动画单帧时长(毫秒) 471 | * @param {Number} animTime 动画总时长(毫秒) 472 | * @param {Boolean} isAwait 是否强制等待前一动画执行完毕(忽略则默认为 options.scrollAnimAwait) 473 | * @param {Function} animEasing 动画算子(不传入则使用options.animEasing) 474 | * @returns {CusScrollBar} 475 | */ 476 | scrollToAnim: function(toVal, stepTime, animTime, isAwait, animEasing) { 477 | var _t = this, 478 | opts = _t.options, 479 | easing = opts.animEasing; 480 | if (_t._animTimer) { 481 | if (isAwait == null ? opts.scrollAnimAwait : isAwait) return; 482 | _t.scrollToAnimStop(); 483 | } 484 | stepTime = stepTime || opts.scrollStepTime; 485 | animTime = animTime || opts.scrollAnimTime; 486 | 487 | var formVal = _t.getScrollPosition(), 488 | currVal = formVal, 489 | distance = toVal - formVal, 490 | frameCount = Math.ceil(animTime / stepTime), 491 | frameProgress = 0, 492 | progress = 0; 493 | 494 | _t.fire('scrollToAnimSta'); 495 | //开始动画 496 | (function() { 497 | frameProgress++; 498 | progress = frameProgress / frameCount; 499 | currVal = formVal + distance * easing(progress); 500 | //console.log('scrollToAniming',currVal); 501 | _t.scrollTo(currVal); 502 | _t._animProgress = { 503 | progress: progress, 504 | currVal: currVal, 505 | formVal: formVal, 506 | toVal: toVal, 507 | distance: distance 508 | }; 509 | _t.fire('scrollToAniming', _t._animProgress); 510 | if (frameProgress == frameCount) { 511 | _t.scrollToAnimStop(); 512 | } else { 513 | _t._animTimer = setTimeout(arguments.callee, stepTime); 514 | } 515 | })(); 516 | return _t; 517 | }, 518 | 519 | /* 终止动画 */ 520 | scrollToAnimStop: function() { 521 | var _t = this; 522 | clearTimeout(_t._animTimer); 523 | _t._animTimer = null; 524 | _t.fire('scrollToAnimEnd', _t._animProgress); 525 | }, 526 | 527 | /* 根据event对象及dir ["x"||"y"]得到鼠标坐标 */ 528 | getPageXY: function(event, dir) { 529 | return event["page" + ((dir || this._dir).toUpperCase())]; 530 | }, 531 | 532 | //按照pageXY定位滚动条坐标 scrollPosDiff是滑块操作时候的初始差值 533 | //如果不传scrollPosDiff则以当前pageXY作为滑块中心点,否则以scrollPosDiff与当前pageXY的差值作为滚动条新坐标 534 | scrollToByPagePos: function(e, scrollPosDiff) { 535 | var _t = this; 536 | _t.scrollTo(_t.getScrollSize() * (_t.getPageXY(e) - _t.getScrollBarPosition() - _t.getSliderSize() * .5) / (_t.getScrollBarSize() || 1)); 537 | return _t; 538 | }, 539 | //按差值调整滚动条所在位置 540 | scrollAdd: function(diffVal) { 541 | var _t = this; 542 | _t.scrollTo(_t.getScrollPosition() + (diffVal || 0)); 543 | return _t; 544 | }, 545 | //改变滚动条所在位置到positionVal 546 | scrollTo: function(positionVal) { 547 | var _t = this; 548 | //console.log('scrollTo:',_t._stl,positionVal); 549 | _t._contW[_t._stl](positionVal); 550 | _t.fire('scroll'); 551 | return _t; 552 | }, 553 | //取得滚动条所在位置坐标值 554 | getScrollPosition: function() { 555 | return this._contW[0][this._stl] || 0; 556 | }, 557 | //取得滚动条最大可滚动到的坐标值 558 | getMaxScrollPosition: function() { 559 | return this.getScrollSize() - this.getContSize(); 560 | }, 561 | 562 | //内容容器高度 563 | getContSize: function() { 564 | return this._contW[this._wh_](); 565 | }, 566 | 567 | //可滚动内容尺寸 568 | getScrollSize: function() { 569 | var _t = this; 570 | return Math.max(_t.getContSize(), this._contW[0][_t._swh] || 0); 571 | }, 572 | 573 | //滚动条模拟元素尺寸 574 | getScrollBarSize: function() { 575 | return this._scrollBarW[this._wh_](); 576 | }, 577 | 578 | //滚动条模拟元素坐标 579 | getScrollBarPosition: function() { 580 | return this._scrollBarW.offset()[this._tl_]; 581 | }, 582 | 583 | //滑块当前应在尺寸 584 | getSliderSize: function() { 585 | var _t = this; 586 | return Math.max(_t.getScrollBarSize() * _t.getContSize() / (_t.getScrollSize() || 1), _t.options.sliderMinHeight); 587 | }, 588 | 589 | //滑块最大坐标 590 | getMaxSliderPosition: function() { 591 | return this.getScrollBarSize() - this._sliderW[this._wh_](); 592 | }, 593 | 594 | //滑块当前应在坐标 595 | getSliderPosition: function() { 596 | var _t = this, 597 | maxSliderPos = _t.getMaxSliderPosition(); 598 | return Math.min(maxSliderPos * _t.getScrollPosition() / (_t.getMaxScrollPosition() || 1), maxSliderPos); 599 | }, 600 | 601 | /** 602 | * 重新计算并设置滑块尺寸 603 | * @method scrollToAnim 604 | * @param {Number} sizeVal 要调整到的长度尺寸,不传则默认为this.getSliderSize() 605 | * @returns {CusScrollBar} 606 | */ 607 | resizeSlider: function(sizeVal) { 608 | var _t = this, 609 | sliderEl = _t._sliderW && _t._sliderW[0]; 610 | if (sliderEl) { 611 | sizeVal = isNaN(sizeVal) ? _t.getSliderSize() : sizeVal; 612 | var sliderDisplay = _t.options.sliderAlwaysShow || sizeVal < _t.getScrollBarSize() ? "" : "none", 613 | originDisplay = sliderEl.style.display; 614 | if (sliderDisplay != originDisplay) { 615 | sliderEl.style.display = sliderDisplay; 616 | _t.fire(sliderDisplay == "none" ? "sliderHide" : "sliderShow"); 617 | } 618 | sliderEl.style[_t._wh_] = sizeVal + 'px'; 619 | _t.fire('resizeSlider'); 620 | } 621 | return _t; 622 | }, 623 | 624 | /** 625 | * 重新计算并设置滑块位置 626 | * @method scrollToAnim 627 | * @param {Number} positionVal 要调整到的坐标值,不传则默认为this.getSliderPosition() 628 | * @returns {CusScrollBar} 629 | */ 630 | removeSlider: function(positionVal) { 631 | var _t = this, 632 | sliderEl = _t._sliderW && _t._sliderW[0]; 633 | if (sliderEl) { 634 | sliderEl.style[_t._tl_] = (isNaN(positionVal) ? _t.getSliderPosition() : positionVal) + 'px'; 635 | _t.fire('sliderMove'); 636 | } 637 | return _t; 638 | } 639 | }); 640 | 641 | window.CusScrollBar = CusScrollBar; 642 | 643 | })(window, document, jQuery); 644 | /* 自定义滚动条功能模块 end */ -------------------------------------------------------------------------------- /less&sass mixins/mixins.less: -------------------------------------------------------------------------------- 1 | .animation(@value) { 2 | -webkit-animation: @value; 3 | -moz-animation: @value; 4 | -o-animation: @value; 5 | animation: @value; 6 | } 7 | .appearance(@value) { 8 | -webkit-appearance: @value; 9 | -moz-appearance: @value; 10 | appearance: @value; 11 | } 12 | .backface-visibility(@value:visible) { 13 | -webkit-backface-visibility: @value;; 14 | -moz-backface-visibility: @value;; 15 | -ms-backface-visibility: @value;; 16 | backface-visibility: @value; 17 | } 18 | .background-clip(@mode: border-box) { 19 | 20 | .if-simulater () when (@mode = border-box) { 21 | -moz-background-clip: border; 22 | -webkit-background-clip: border; 23 | } 24 | 25 | .if-simulater () when (@mode = padding-box) { 26 | -moz-background-clip: padding; 27 | -webkit-background-clip: padding; 28 | } 29 | 30 | .if-simulater () when (@mode = content-box) { 31 | -moz-background-clip: content; 32 | -webkit-background-clip: content; 33 | } 34 | 35 | .if-simulater(); 36 | 37 | background-clip: @mode; 38 | } 39 | .background-origin(@mode: border-box) { 40 | 41 | .if-simulater () when (@mode = border-box) { 42 | -moz-background-origin: border; 43 | -webkit-background-origin: border; 44 | } 45 | 46 | .if-simulater () when (@mode = padding-box) { 47 | -moz-background-origin: padding; 48 | -webkit-background-origin: padding; 49 | } 50 | 51 | .if-simulater () when (@mode = content-box) { 52 | -moz-background-origin: content; 53 | -webkit-background-origin: content; 54 | } 55 | 56 | .if-simulater(); 57 | 58 | background-origin: @mode; 59 | } 60 | .background-retina(@img_1x, @img_2x, @width_1x, @height_1x) { 61 | background-image: url(@img_1x); 62 | 63 | @media only screen and (-webkit-min-device-pixel-ratio: 2), 64 | only screen and (min--moz-device-pixel-ratio: 2), 65 | only screen and (-o-min-device-pixel-ratio: 2/1), 66 | only screen and (min-device-pixel-ratio: 2), 67 | only screen and (min-resolution: 192dpi), 68 | only screen and (min-resolution: 2dppx) { 69 | background-image: url(@img_2x); 70 | .background-size(@width_1x @height_1x); 71 | } 72 | } 73 | .background-size(@size) { 74 | -webkit-background-size: @size; 75 | -moz-background-size: @size; 76 | -o-background-size: @size; 77 | background-size: @size; 78 | } 79 | .border-radius(@radius, @direction:all) { 80 | .if-simulater () when (@direction = all) { 81 | -moz-border-radius: @radius; 82 | -webkit-border-radius: @radius; 83 | border-radius: @radius; 84 | } 85 | 86 | .if-simulater () when (@direction = top) { 87 | -moz-border-radius: @radius @radius 0 0; 88 | -webkit-border-radius: @radius @radius 0 0; 89 | border-radius: @radius @radius 0 0; 90 | } 91 | 92 | .if-simulater () when (@direction = right) { 93 | -moz-border-radius: 0 @radius @radius 0; 94 | -webkit-border-radius: 0 @radius @radius 0; 95 | border-radius: 0 @radius @radius 0; 96 | } 97 | 98 | .if-simulater () when (@direction = bottom) { 99 | -moz-border-radius: 0 0 @radius @radius; 100 | -webkit-border-radius: 0 0 @radius @radius; 101 | border-radius: 0 0 @radius @radius; 102 | } 103 | 104 | .if-simulater () when (@direction = left) { 105 | -moz-border-radius: @radius 0 0 @radius; 106 | -webkit-border-radius: @radius 0 0 @radius; 107 | border-radius: @radius 0 0 @radius; 108 | } 109 | 110 | .if-simulater(); 111 | } 112 | 113 | .border-triangle(@borderWidth, @borderColor, @direction) { 114 | @default-border-style: solid; 115 | 116 | width: 0; 117 | height: 0; 118 | overflow: hidden; 119 | border-width: @borderWidth; 120 | border-style: @default-border-style; 121 | _border-style: dashed; 122 | border-color: transparent; 123 | 124 | .if-simulater () when (@direction = top) { 125 | border-bottom-color: @borderColor; 126 | _border-bottom-style: @default-border-style; 127 | } 128 | 129 | .if-simulater () when (@direction = right) { 130 | border-left-color: @borderColor; 131 | _border-left-style: @default-border-style; 132 | } 133 | 134 | .if-simulater () when (@direction = bottom) { 135 | border-top-color: @borderColor; 136 | _border-top-style: @default-border-style; 137 | } 138 | 139 | .if-simulater () when (@direction = left) { 140 | border-right-color: @borderColor; 141 | _border-right-style: @default-border-style; 142 | } 143 | 144 | .if-simulater () when (@direction = topleft) { 145 | border-top-color: @borderColor; 146 | border-left-color: @borderColor; 147 | _border-top-style: @default-border-style; 148 | _border-left-style: @default-border-style; 149 | } 150 | 151 | .if-simulater () when (@direction = topright) { 152 | border-top-color: @borderColor; 153 | border-right-color: @borderColor; 154 | _border-top-style: @default-border-style; 155 | _border-right-style: @default-border-style; 156 | } 157 | 158 | .if-simulater () when (@direction = bottomleft) { 159 | border-bottom-color: @borderColor; 160 | border-left-color: @borderColor; 161 | _border-bottom-style: @default-border-style; 162 | _border-left-style: @default-border-style; 163 | } 164 | 165 | .if-simulater () when (@direction = bottomright) { 166 | border-bottom-color: @borderColor; 167 | border-right-color: @borderColor; 168 | _border-bottom-style: @default-border-style; 169 | _border-right-style: @default-border-style; 170 | } 171 | 172 | .if-simulater(); 173 | } 174 | .box-shadow(@params) { 175 | -moz-box-shadow: @params; 176 | -webkit-box-shadow: @params; 177 | box-shadow: @params; 178 | } 179 | .box-sizing(@model) { 180 | -webkit-box-sizing: @model; 181 | -moz-box-sizing: @model; 182 | box-sizing: @model; 183 | } 184 | .clearfix() { 185 | &:before, 186 | &:after { 187 | content: " "; 188 | display: table; 189 | } 190 | &:after { 191 | clear: both; 192 | } 193 | *zoom: 1; 194 | } 195 | .font-face(@fontName, @noSuffixFontUrl) { 196 | @font-face { 197 | font-family: "@{fontName}"; 198 | src: url("@{noSuffixFontUrl}.eot"); 199 | src: url("@{noSuffixFontUrl}.eot?#iefix") format("embedded-opentype"), 200 | url("@{noSuffixFontUrl}.woff") format("woff"), 201 | url("@{noSuffixFontUrl}.ttf") format("truetype"), 202 | url("@{noSuffixFontUrl}.svg#svgFontName") format("svg"); 203 | } 204 | } 205 | .grayscale() { 206 | /* for Chrome, Safari, Opera */ 207 | -webkit-filter: grayscale(100%); 208 | /* CSS3 standard usage */ 209 | filter: grayscale(100%); 210 | /* for FF, data-uri generate from gray.svg */ 211 | filter: url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8ZmlsdGVyIGlkPSJncmF5c2NhbGUiPgogICAgICAgIDxmZUNvbG9yTWF0cml4IHR5cGU9Im1hdHJpeCIgdmFsdWVzPSIwLjMzMzMgMC4zMzMzIDAuMzMzMyAwIDAgMC4zMzMzIDAuMzMzMyAwLjMzMzMgMCAwIDAuMzMzMyAwLjMzMzMgMC4zMzMzIDAgMCAwIDAgMCAxIDAiLz4KICAgIDwvZmlsdGVyPgo8L3N2Zz4=#grayscale'); 212 | /* for IE6~9 */ 213 | filter: gray; 214 | } 215 | .hyphens(@mode:auto) { 216 | -ms-word-break: break-all; 217 | word-break: break-all; 218 | word-break: break-word; 219 | -webkit-hyphens: @mode; 220 | -moz-hyphens: @mode; 221 | -ms-hyphens: @mode; 222 | hyphens: @mode; 223 | } 224 | .inline-block() { 225 | display: inline-block; 226 | *display: inline; 227 | *zoom: 1; 228 | } 229 | .linear-gradient(...) { 230 | 231 | @params: ~`"@{arguments}".toString().replace(/[\[\]]/g, "")`; 232 | @webkitParams: ~`"@{arguments}".toString().replace(/[\[\]]/g, "") 233 | .replace(/to top|\b0deg\b/, "bottom") 234 | .replace(/to right|\b90deg\b/, "left") 235 | .replace(/to bottom|\b180deg\b/, "top") 236 | .replace(/to left|\b270deg\b/, "right")`; 237 | 238 | @len: length(@arguments); 239 | 240 | .if(@arguments) when(@len = 2) { 241 | @startColor: extract(extract(@arguments, 1), 1); 242 | @endColor: extract(extract(@arguments, 2), 1); 243 | filter: ~`"progid:DXImageTransform.Microsoft.gradient(startcolorstr=@{startColor},endcolorstr=@{endColor},gradientType=0)"`; 244 | } 245 | 246 | .if(@arguments) when(@len > 2) { 247 | @direction: extract(@arguments, 1); 248 | @startColor: extract(extract(@arguments, 2), 1); 249 | @endColor: extract(extract(@arguments, 3), 1); 250 | 251 | .subif(@startColor, @endColor) when("@{direction}" = "to top") { 252 | filter: ~`"progid:DXImageTransform.Microsoft.gradient(startcolorstr=@{endColor},endcolorstr=@{startColor},gradientType=0)"`; 253 | } 254 | .subif(@startColor, @endColor) when("@{direction}" = "to right") { 255 | filter: ~`"progid:DXImageTransform.Microsoft.gradient(startcolorstr=@{startColor},endcolorstr=@{endColor},gradientType=1)"`; 256 | } 257 | .subif(@startColor, @endColor) when("@{direction}" = "to bottom") { 258 | filter: ~`"progid:DXImageTransform.Microsoft.gradient(startcolorstr=@{startColor},endcolorstr=@{endColor},gradientType=0)"`; 259 | } 260 | .subif(@startColor, @endColor) when("@{direction}" = "to left") { 261 | filter: ~`"progid:DXImageTransform.Microsoft.gradient(startcolorstr=@{endColor},endcolorstr=@{startColor},gradientType=1)"`; 262 | } 263 | .subif(@startColor, @endColor) when(@direction = 0deg) { 264 | filter: ~`"progid:DXImageTransform.Microsoft.gradient(startcolorstr=@{endColor},endcolorstr=@{startColor},gradientType=0)"`; 265 | } 266 | .subif(@startColor, @endColor) when(@direction = 90deg) { 267 | filter: ~`"progid:DXImageTransform.Microsoft.gradient(startcolorstr=@{startColor},endcolorstr=@{endColor},gradientType=1)"`; 268 | } 269 | .subif(@startColor, @endColor) when(@direction = 180deg) { 270 | filter: ~`"progid:DXImageTransform.Microsoft.gradient(startcolorstr=@{startColor},endcolorstr=@{endColor},gradientType=0)"`; 271 | } 272 | .subif(@startColor, @endColor) when(@direction = 270deg) { 273 | filter: ~`"progid:DXImageTransform.Microsoft.gradient(startcolorstr=@{endColor},endcolorstr=@{startColor},gradientType=1)"`; 274 | } 275 | .subif(@startColor, @endColor); 276 | } 277 | 278 | .if(@arguments); 279 | 280 | background: -webkit-linear-gradient(@webkitParams); 281 | background: linear-gradient(@params); 282 | } 283 | .min-height(@height) { 284 | min-height: @height; 285 | _height: @height; 286 | } 287 | 288 | .opacity(@opacity) { 289 | @opacityIE: @opacity * 100; 290 | -ms-filter: ~"progid:DXImageTransform.Microsoft.Alpha(Opacity=@{opacityIE})"; // IE 8 & 9 291 | filter: ~"alpha(opacity=@{opacityIE})"; // IE 6 & 7 292 | opacity: @opacity; 293 | } 294 | .perspective-origin(@origin:50% 50%) { 295 | -webkit-perspective-origin: @origin; 296 | -moz-perspective-origin: @origin; 297 | perspective-origin: @origin; 298 | } 299 | .perspective(@value:none) { 300 | -webkit-perspective: @value; 301 | -moz-perspective: @value; 302 | perspective: @value; 303 | } 304 | .placeholder(@color) { 305 | &::-moz-placeholder { 306 | color: @color; 307 | opacity: 1; 308 | } 309 | &:-moz-placeholder { 310 | color: @color; 311 | } 312 | &:-ms-input-placeholder { 313 | color: @color; 314 | } 315 | &::-webkit-input-placeholder { 316 | color: @color; 317 | } 318 | } 319 | .radial-gradient(...) { 320 | @param: ~`"@{arguments}".toString().replace(/[\[\]]/g, "")`; 321 | background: -webkit-radial-gradient(@param); 322 | background: -moz-radial-gradient(@param); 323 | background: -ms-radial-gradient(@param); 324 | background: radial-gradient(@param); 325 | } 326 | .text-overflow(@cutway: clip) { 327 | overflow: hidden; 328 | text-overflow: @cutway; 329 | white-space: nowrap; 330 | } 331 | .transform-origin(@value: 50% 50% 0) { 332 | -webkit-transform-origin: @value; 333 | -moz-transform-origin: @value; 334 | -ms-transform-origin: @value; 335 | transform-origin: @value; 336 | } 337 | .transform-style(@value:flat) { 338 | -webkit-transform-style: @value; 339 | -moz-transform-style: @value; 340 | transform-style: @value; 341 | } 342 | .transform(@value) { 343 | -webkit-transform: @value; 344 | -moz-transform: @value; 345 | -ms-transform: @value; 346 | -o-transform: @value; 347 | transform: @value; 348 | } 349 | .transition(@value) { 350 | -webkit-transition: @value; 351 | -moz-transition: @value; 352 | -o-transition: @value; 353 | transition: @value; 354 | } 355 | .user-select(@mode:text) { 356 | -webkit-user-select: @mode; 357 | -moz-user-select: @mode; 358 | -ms-user-select: @mode; 359 | user-select: @mode; 360 | } -------------------------------------------------------------------------------- /less&sass mixins/mixins.scss: -------------------------------------------------------------------------------- 1 | //在这里定义设计图的宽度,单位是px。 2 | //然后以后的单位中,直接写设计图上得到的尺寸即可。 3 | //记得配合mresize使用 4 | // .logo{ 5 | // width : px2rem(300); //这里的300,是在设计图上量出来的,没做任何处理; 6 | // } 7 | 8 | $designWidth : 750; 9 | 10 | 11 | @function px2rem( $px ){ 12 | //320*50/750/20 13 | @return $px*320/$designWidth/20 + rem; 14 | } 15 | 16 | @mixin flexbox{ 17 | display: -webkit-box; //old 18 | display: -moz-box; //old 19 | display: -ms-flexbox; // ie 20 | display: -webkit-flex; //new 21 | display: flex; //new 22 | } 23 | 24 | @mixin flex( $value ){ 25 | -webkit-box-flex: $value; 26 | -moz-box-flex: $value; 27 | -ms-flex: $value; 28 | -webkit-flex: $value; 29 | flex: $value; 30 | } 31 | 32 | @mixin flex-order( $order ){ 33 | -webkit-box-ordinal-group: $order; // old 34 | -moz-box-ordinal-group: $order; // old 35 | -ms-flex-order: $order; // ie 36 | -webkit-order: $order; // new 37 | order: $order; // new 38 | } 39 | 40 | @mixin flex-direction($direction){ 41 | @if $direction == column{ 42 | -webkit-flex-direction:vertical; 43 | -moz-flex-direction:vertical; 44 | -ms-flex-direction:column; 45 | -webkit-flex-direction:column; 46 | flex-direction:column; 47 | }@else{ 48 | -webkit-flex-direction:horizontal; 49 | -moz-flex-direction:horizontal; 50 | -ms-flex-direction:row; 51 | -webkit-flex-direction:row; 52 | flex-direction:row; 53 | } 54 | } 55 | 56 | @mixin animation($value) { 57 | -webkit-animation: $value; 58 | -moz-animation: $value; 59 | -o-animation: $value; 60 | animation: $value; 61 | } 62 | @mixin appearance($value) { 63 | -webkit-appearance: $value; 64 | -moz-appearance: $value; 65 | appearance: $value; 66 | } 67 | @mixin backface-visibility($value:visible) { 68 | -webkit-backface-visibility: $value;; 69 | -moz-backface-visibility: $value;; 70 | -ms-backface-visibility: $value;; 71 | backface-visibility: $value; 72 | } 73 | @mixin background-clip($mode: border-box) { 74 | $xmode: null; 75 | 76 | @if ($mode == border-box) { 77 | $xmode: border; 78 | } 79 | 80 | @if ($mode == padding-box) { 81 | $xmode: padding; 82 | } 83 | 84 | @if ($mode == content-box) { 85 | $xmode: content; 86 | } 87 | 88 | -moz-background-clip: $xmode; 89 | -webkit-background-clip: $xmode; 90 | background-clip: $mode; 91 | } 92 | @mixin background-origin($mode: border-box) { 93 | $xmode: null; 94 | 95 | @if ($mode == border-box) { 96 | $xmode: border; 97 | } 98 | 99 | @if ($mode == padding-box) { 100 | $xmode: padding; 101 | } 102 | 103 | @if ($mode == content-box) { 104 | $xmode: content; 105 | } 106 | 107 | -moz-background-origin: $xmode; 108 | -webkit-background-origin: $xmode; 109 | background-origin: $mode; 110 | } 111 | @mixin background-retina($img_1x, $img_2x, $width_1x, $height_1x) { 112 | background-image: url($img_1x); 113 | 114 | @media only screen and (-webkit-min-device-pixel-ratio: 2), 115 | only screen and (min--moz-device-pixel-ratio: 2), 116 | only screen and (-o-min-device-pixel-ratio: 2/1), 117 | only screen and (min-device-pixel-ratio: 2), 118 | only screen and (min-resolution: 192dpi), 119 | only screen and (min-resolution: 2dppx) { 120 | background-image: url($img_2x); 121 | @include background-size($width_1x $height_1x); 122 | } 123 | } 124 | @mixin background-size($size) { 125 | -webkit-background-size: $size; 126 | -moz-background-size: $size; 127 | -o-background-size: $size; 128 | background-size: $size; 129 | } 130 | @mixin border-radius($radius, $direction:all) { 131 | @if ($direction == all) { 132 | -moz-border-radius: $radius; 133 | -webkit-border-radius: $radius; 134 | border-radius: $radius; 135 | } 136 | 137 | @if ($direction == top) { 138 | -moz-border-radius: $radius $radius 0 0; 139 | -webkit-border-radius: $radius $radius 0 0; 140 | border-radius: $radius $radius 0 0; 141 | } 142 | 143 | @if ($direction == right) { 144 | -moz-border-radius: 0 $radius $radius 0; 145 | -webkit-border-radius: 0 $radius $radius 0; 146 | border-radius: 0 $radius $radius 0; 147 | } 148 | 149 | @if ($direction == bottom) { 150 | -moz-border-radius: 0 0 $radius $radius; 151 | -webkit-border-radius: 0 0 $radius $radius; 152 | border-radius: 0 0 $radius $radius; 153 | } 154 | 155 | @if ($direction == left) { 156 | -moz-border-radius: $radius 0 0 $radius; 157 | -webkit-border-radius: $radius 0 0 $radius; 158 | border-radius: $radius 0 0 $radius; 159 | } 160 | } 161 | 162 | @mixin border-triangle($borderWidth, $borderColor, $direction) { 163 | $default-border-style: solid; 164 | 165 | width: 0; 166 | height: 0; 167 | overflow: hidden; 168 | border-width: $borderWidth; 169 | border-style: $default-border-style; 170 | _border-style: dashed; 171 | border-color: transparent; 172 | 173 | @if ($direction == top) { 174 | border-bottom-color: $borderColor; 175 | _border-bottom-style: $default-border-style; 176 | } 177 | 178 | @if ($direction == right) { 179 | border-left-color: $borderColor; 180 | _border-left-style: $default-border-style; 181 | } 182 | 183 | @if ($direction == bottom) { 184 | border-top-color: $borderColor; 185 | _border-top-style: $default-border-style; 186 | } 187 | 188 | @if ($direction == left) { 189 | border-right-color: $borderColor; 190 | _border-right-style: $default-border-style; 191 | } 192 | 193 | @if ($direction == topleft) { 194 | border-top-color: $borderColor; 195 | border-left-color: $borderColor; 196 | _border-top-style: $default-border-style; 197 | _border-left-style: $default-border-style; 198 | } 199 | 200 | @if ($direction == topright) { 201 | border-top-color: $borderColor; 202 | border-right-color: $borderColor; 203 | _border-top-style: $default-border-style; 204 | _border-right-style: $default-border-style; 205 | } 206 | 207 | @if ($direction == bottomleft) { 208 | border-bottom-color: $borderColor; 209 | border-left-color: $borderColor; 210 | _border-bottom-style: $default-border-style; 211 | _border-left-style: $default-border-style; 212 | } 213 | 214 | @if ($direction == bottomright) { 215 | border-bottom-color: $borderColor; 216 | border-right-color: $borderColor; 217 | _border-bottom-style: $default-border-style; 218 | _border-right-style: $default-border-style; 219 | } 220 | } 221 | @mixin box-shadow($param) { 222 | -moz-box-shadow: $param; 223 | -webkit-box-shadow: $param; 224 | box-shadow: $param; 225 | } 226 | @mixin box-sizing($model) { 227 | -webkit-box-sizing: $model; 228 | -moz-box-sizing: $model; 229 | box-sizing: $model; 230 | } 231 | @mixin clearfix() { 232 | &:before, 233 | &:after { 234 | content: " "; 235 | display: table; 236 | } 237 | &:after { 238 | clear: both; 239 | } 240 | *zoom: 1; 241 | } 242 | @mixin font-face($fontName, $noSuffixFontUrl) { 243 | @font-face { 244 | font-family: "#{$fontName}"; 245 | src: url("#{$noSuffixFontUrl}.eot"); 246 | src: url("#{$noSuffixFontUrl}.eot?#iefix") format("embedded-opentype"), 247 | url("#{$noSuffixFontUrl}.woff") format("woff"), 248 | url("#{$noSuffixFontUrl}.ttf") format("truetype"), 249 | url("#{$noSuffixFontUrl}.svg#svgFontName") format("svg"); 250 | } 251 | } 252 | @mixin grayscale() { 253 | /* for Chrome, Safari, Opera */ 254 | -webkit-filter: grayscale(100%); 255 | /* CSS3 standard usage */ 256 | filter: grayscale(100%); 257 | /* for FF, data-uri generate from gray.svg */ 258 | filter: url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8ZmlsdGVyIGlkPSJncmF5c2NhbGUiPgogICAgICAgIDxmZUNvbG9yTWF0cml4IHR5cGU9Im1hdHJpeCIgdmFsdWVzPSIwLjMzMzMgMC4zMzMzIDAuMzMzMyAwIDAgMC4zMzMzIDAuMzMzMyAwLjMzMzMgMCAwIDAuMzMzMyAwLjMzMzMgMC4zMzMzIDAgMCAwIDAgMCAxIDAiLz4KICAgIDwvZmlsdGVyPgo8L3N2Zz4=#grayscale'); 259 | /* for IE6~9 */ 260 | filter: gray; 261 | } 262 | @mixin hyphens($mode:auto) { 263 | -ms-word-break: break-all; 264 | word-break: break-all; 265 | word-break: break-word; 266 | -webkit-hyphens: $mode; 267 | -moz-hyphens: $mode; 268 | -ms-hyphens: $mode; 269 | hyphens: $mode; 270 | } 271 | @mixin inline-block() { 272 | display: inline-block; 273 | *display: inline; 274 | *zoom: 1; 275 | } 276 | @mixin linear-gradient($arguments...) { 277 | 278 | @if (length($arguments) == 2) { 279 | $arguments: join(unquote("to bottom"), $arguments, comma); 280 | } 281 | 282 | $map: ("to top": bottom, 283 | "to right": left, 284 | "to bottom": top, 285 | "to left": right, 286 | "0deg": bottom, 287 | "90deg": left, 288 | "180deg": top, 289 | "270deg": right); 290 | 291 | $iemap: ("to top": 0, 292 | "to right": 1, 293 | "to bottom": 0, 294 | "to left": 1, 295 | "0deg": 0, 296 | "90deg": 1, 297 | "180deg": 0, 298 | "270deg": 1); 299 | 300 | $direction: inspect(nth($arguments, 1)); 301 | $colorlist: str-slice(inspect($arguments), str-length($direction) + 2); 302 | $wkdirection: map-get($map, $direction); 303 | $iedirection: map-get($iemap, $direction); 304 | $startColor: null; 305 | $endColor: null; 306 | 307 | @if ($wkdirection == top) { 308 | $startColor: nth(nth($arguments, 2), 1); 309 | $endColor: nth(nth($arguments, 3), 1); 310 | } @else if ($wkdirection == left) { 311 | $startColor: nth(nth($arguments, 2), 1); 312 | $endColor: nth(nth($arguments, 3), 1); 313 | } @else if ($wkdirection == bottom) { 314 | $startColor: nth(nth($arguments, 3), 1); 315 | $endColor: nth(nth($arguments, 2), 1); 316 | } @else if ($wkdirection == right) { 317 | $startColor: nth(nth($arguments, 3), 1); 318 | $endColor: nth(nth($arguments, 2), 1); 319 | } 320 | 321 | background: -webkit-linear-gradient($wkdirection, $colorlist); 322 | background: linear-gradient($arguments); 323 | filter: unquote("progid:DXImageTransform.Microsoft.gradient(startcolorstr=#{$startColor},endcolorstr=#{$endColor},gradientType=#{$iedirection})"); 324 | } 325 | @mixin min-height($height) { 326 | min-height: $height; 327 | _height: $height; 328 | } 329 | @mixin opacity($opacity) { 330 | $opacityIE: $opacity * 100; 331 | -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=$opacityIE); // IE 8 & 9 332 | filter: alpha(opacity=$opacityIE); // IE 6 & 7 333 | opacity: $opacity; 334 | } 335 | @mixin perspective-origin($origin:50% 50%) { 336 | -webkit-perspective-origin: $origin; 337 | -moz-perspective-origin: $origin; 338 | perspective-origin: $origin; 339 | } 340 | @mixin perspective($value:none) { 341 | -webkit-perspective: $value; 342 | -moz-perspective: $value; 343 | perspective: $value; 344 | } 345 | @mixin placeholder($color) { 346 | &::-moz-placeholder { 347 | color: $color; 348 | opacity: 1; 349 | } 350 | &:-moz-placeholder { 351 | color: $color; 352 | } 353 | &:-ms-input-placeholder { 354 | color: $color; 355 | } 356 | &::-webkit-input-placeholder { 357 | color: $color; 358 | } 359 | } 360 | @mixin radial-gradient($arguments...) { 361 | background: -webkit-radial-gradient($arguments); 362 | background: -moz-radial-gradient($arguments); 363 | background: -ms-radial-gradient($arguments); 364 | background: radial-gradient($arguments); 365 | } 366 | @mixin text-overflow($cutway: clip) { 367 | overflow: hidden; 368 | text-overflow: $cutway; 369 | white-space: nowrap; 370 | } 371 | @mixin transform-origin($value: 50% 50% 0) { 372 | -webkit-transform-origin: $value; 373 | -moz-transform-origin: $value; 374 | -ms-transform-origin: $value; 375 | transform-origin: $value; 376 | } 377 | @mixin transform-style($value:flat) { 378 | -webkit-transform-style: $value; 379 | -moz-transform-style: $value; 380 | transform-style: $value; 381 | } 382 | @mixin transform($value) { 383 | -webkit-transform: $value; 384 | -moz-transform: $value; 385 | -ms-transform: $value; 386 | -o-transform: $value; 387 | transform: $value; 388 | } 389 | @mixin transition($value) { 390 | -webkit-transition: $value; 391 | -moz-transition: $value; 392 | -o-transition: $value; 393 | transition: $value; 394 | } 395 | @mixin user-select($mode:text) { 396 | -webkit-user-select: $mode; 397 | -moz-user-select: $mode; 398 | -ms-user-select: $mode; 399 | user-select: $mode; 400 | } -------------------------------------------------------------------------------- /mResize/mresize.js: -------------------------------------------------------------------------------- 1 | /** 2 | * name : mresize.js 3 | * 4 | * desc : 根据页面大小来调整 根字体的大小,以便使用rem单位。 5 | * 6 | * -------------------------------------------------- 7 | * 8 | * step1 : 将设计图转化为320的标准宽。 9 | * 10 | * step2 : 将尺寸大小转化为 w/20 rem。[推荐使用less] 11 | * 12 | * 已知bug : 部分小米机型需要在页面ready之后 触发一下 window 的resize事件 13 | */ 14 | ;(function( window , document ){ 15 | 16 | "use strict"; 17 | 18 | var mresize = function(){ 19 | 20 | var innerWidth = window.innerWidth; 21 | 22 | if( !innerWidth ){ return false;} 23 | 24 | document.documentElement.style.fontSize = ( innerWidth*20/320 ) + 'px'; 25 | 26 | }; 27 | 28 | mresize(); 29 | 30 | window.addEventListener( 'resize' , mresize , false ); 31 | 32 | window.addEventListener( 'load' , mresize , false ); 33 | 34 | 35 | })( window , document ); 36 | -------------------------------------------------------------------------------- /mframe/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | mframe 6 | 7 | 8 | 9 |
10 | 11 | 14 | -------------------------------------------------------------------------------- /mframe/src/index/data.js: -------------------------------------------------------------------------------- 1 | (function( M ){ 2 | 3 | "use strict"; 4 | 5 | var Sync = M.Sync; 6 | 7 | M.sync = { 8 | 9 | getSourceData: function() { 10 | 11 | var sync = new Sync({ 12 | param: 'your param' 13 | },{ 14 | dataType : 'jsonp' 15 | }); 16 | 17 | return sync.get('your url'); 18 | }, 19 | 20 | }; 21 | 22 | 23 | })( MFrame ); -------------------------------------------------------------------------------- /mframe/src/index/logic.js: -------------------------------------------------------------------------------- 1 | (function( M ){ 2 | 3 | "use strict"; 4 | 5 | var name = 'index', 6 | 7 | errmsg = '网络连接异常,请稍后尝试!', 8 | 9 | utils = M.utils; 10 | 11 | var logic = M.getLogic({ 12 | 13 | name: name, 14 | 15 | run: function( opts ){ 16 | this.init(); 17 | }, 18 | getData: function() { 19 | 20 | var deferred = $.Deferred(); 21 | 22 | M.sync.getSourceData().done(function( res ){ 23 | 24 | deferred.resolve( res ); 25 | 26 | }).fail(function(){ 27 | deferred.reject( errmsg ); 28 | }) 29 | return deferred.promise(); 30 | } 31 | }); 32 | 33 | M[name] = function(opts) { 34 | logic.run(opts); 35 | }; 36 | 37 | 38 | })( MFrame ) -------------------------------------------------------------------------------- /mframe/src/index/ui.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @Overview UI模块 3 | * 页面交互,通知状态 4 | */ 5 | (function(M){ 6 | 7 | 'use strict'; 8 | 9 | var name = 'index', 10 | 11 | $ = M.$; 12 | 13 | var ui = { 14 | 15 | init : function( model ) { 16 | 17 | this.model = model; 18 | 19 | this.testEvent(); 20 | }, 21 | testEvent : function(){ 22 | 23 | var $content = $('#content'); 24 | 25 | this.model.getData().done(function( res ){ 26 | 27 | $content.html( JSON.stringify(res) ); 28 | 29 | }).fail(function( errmsg ){ 30 | alert( errmsg ); 31 | }); 32 | 33 | } 34 | 35 | }; 36 | 37 | M.ui.index = { 38 | init : function() { 39 | ui.init.apply(ui, arguments); 40 | } 41 | }; 42 | })( MFrame ); -------------------------------------------------------------------------------- /mframe/src/main.js: -------------------------------------------------------------------------------- 1 | 2 | document.write(""); 3 | document.write(""); 4 | document.write(""); 5 | 6 | 7 | /** 8 | document.write(""); 9 | **/ 10 | 11 | 12 | document.write(""); 13 | document.write(""); 14 | 15 | 16 | document.write(""); 17 | document.write(""); 18 | document.write(""); -------------------------------------------------------------------------------- /mframe/src/mframe/mframe.base.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) skycamp 2013 4 | * 5 | * last-modifiy : 2015.08.27 6 | * 7 | * author: mochen 8 | * 9 | * ---------------------------------------------- 10 | * 11 | * Tips : 使用Zepto需引入 callback 、 deferred 模块 12 | * 13 | */ 14 | 15 | (function( window ){ 16 | 17 | "use strict"; 18 | 19 | var $ = window.jQuery ? jQuery : Zepto, 20 | 21 | 22 | /** 23 | * [MFrame 核心命名空间] 24 | */ 25 | MFrame = window.MFrame = { 26 | 27 | $ : $, //框架 28 | 29 | utils : {}, //通用工具模块 30 | 31 | ui : {}, //UI操作模块 32 | 33 | data : {}, //数据处理模块 34 | 35 | events : {} //事件模块 36 | 37 | }, 38 | 39 | 40 | $ = MFrame.$, 41 | 42 | $events = $( MFrame.events ), 43 | 44 | 45 | guid = parseInt(new Date().getTime().toString().substr(4), 10), 46 | 47 | getUid = function(){ 48 | return guid++; 49 | }, 50 | 51 | Logic = function(props) { 52 | 53 | this.name = 'func_' + getUid(); 54 | this.extend(props); 55 | 56 | this._initFlag = false; 57 | this._data = {}; 58 | 59 | }; 60 | 61 | $.extend( Logic.prototype , { 62 | /** 63 | * 初始化函数 64 | */ 65 | init : function() { 66 | var self = this; 67 | if (!self._initFlag) { 68 | self._initFlag = true; 69 | MFrame.ui[self.name].init(self); 70 | } 71 | return self; 72 | }, 73 | /** 74 | * 获取是否已经初始化的标记 75 | * @returns {boolean} 76 | */ 77 | isInit: function() { 78 | return this._initFlag; 79 | }, 80 | /** 81 | * 获取数据 82 | * @param {String} key 83 | * @param {*} defaultValue 84 | * @returns {*} 85 | */ 86 | get : function(key, defaultValue) { 87 | var value = this._data[key]; 88 | return value !== undefined ? value : defaultValue; 89 | }, 90 | /** 91 | * 设置数据 92 | * @param {String|Object} key 93 | * @param {*} value 94 | */ 95 | set : function(key, value) { 96 | if ( $.isPlainObject(key) ) { 97 | $.extend( this._data , key ); 98 | } else { 99 | this._data[key] = value; 100 | } 101 | return this; 102 | }, 103 | /** 104 | * 清理数据 105 | */ 106 | clear : function() { 107 | this._data = {}; 108 | return this; 109 | }, 110 | 111 | /** 112 | * 扩展实例方法 113 | */ 114 | extend : function() { 115 | var args = [].slice.apply(arguments); 116 | args.unshift(this); 117 | $.extend.apply(null, args); 118 | } 119 | }); 120 | 121 | $.each(['on', 'off', 'one', 'trigger'], function(i, type) { 122 | Logic.prototype[type] = function() { 123 | $.fn[type].apply($events, arguments); 124 | return this; 125 | }; 126 | }); 127 | 128 | MFrame.getLogic = function(props) { 129 | return new Logic(props); 130 | }; 131 | 132 | 133 | var Sync = function(param, ajaxOpt) { 134 | if(!param) { 135 | return; 136 | } 137 | var protocol = this.protocol = 'http'; 138 | 139 | var ajaxOptDefault = { 140 | url: protocol + '://'+location.host, 141 | type: 'GET', 142 | dataType: 'jsonp', 143 | timeout: 20000 144 | }; 145 | 146 | this.protocol = protocol; 147 | this.param = $.extend({}, param); 148 | this.ajaxOpt = $.extend({data: this.param}, ajaxOptDefault, ajaxOpt); 149 | this.HOST = protocol + '://'+location.host; 150 | }; 151 | 152 | 153 | $.extend( Sync.prototype , { 154 | /** 155 | * 通过get方式(jsonp)提交 156 | * @param {String} [url] 请求链接 157 | * @return {Object} promise对象 158 | */ 159 | get: function(url) { 160 | var self = this; 161 | var send = $.ajax( $.extend( this.ajaxOpt ,{ url : url}) ); 162 | return send.then( this.done, function( status ) { 163 | return self.fail( status ); 164 | }); 165 | }, 166 | /** 167 | * 收到响应时默认回调 168 | * @param {Object} data 数据 169 | * @return {Object} 170 | */ 171 | done: function (data) { 172 | var deferred = $.Deferred(); 173 | deferred.resolve(data); 174 | return deferred.promise(); 175 | }, 176 | /** 177 | * 未收到响应时默认回调 178 | * @param {Object} error 错误信息 179 | * @return {Object} 180 | */ 181 | fail: function(error) { 182 | var deferred = $.Deferred(); 183 | deferred.reject({ 184 | errno: 999999, 185 | errmsg: '网络连接超时,请稍后尝试!' 186 | }); 187 | return deferred.promise(); 188 | } 189 | }); 190 | 191 | MFrame.Sync = Sync; 192 | 193 | })( window ); 194 | -------------------------------------------------------------------------------- /mframe/src/mframe/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @Overview 工具方法 3 | * 4 | * ---- 5 | * 6 | * 非必须,如需要全局方法可在此定义 7 | */ 8 | (function( M ){ 9 | 10 | 11 | "use strict"; 12 | 13 | var utils = M.utils; 14 | 15 | utils = {}; 16 | 17 | 18 | })( MFrame ); -------------------------------------------------------------------------------- /mframe/src/zepto/zepto.116.js: -------------------------------------------------------------------------------- 1 | 2 | /* Zepto v1.1.6 - zepto event ajax form ie - zeptojs.com/license */ 3 | 4 | var Zepto = (function() { 5 | var undefined, key, $, classList, emptyArray = [], slice = emptyArray.slice, filter = emptyArray.filter, 6 | document = window.document, 7 | elementDisplay = {}, classCache = {}, 8 | cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 }, 9 | fragmentRE = /^\s*<(\w+|!)[^>]*>/, 10 | singleTagRE = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, 11 | tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, 12 | rootNodeRE = /^(?:body|html)$/i, 13 | capitalRE = /([A-Z])/g, 14 | 15 | // special attributes that should be get/set via method calls 16 | methodAttributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'], 17 | 18 | adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ], 19 | table = document.createElement('table'), 20 | tableRow = document.createElement('tr'), 21 | containers = { 22 | 'tr': document.createElement('tbody'), 23 | 'tbody': table, 'thead': table, 'tfoot': table, 24 | 'td': tableRow, 'th': tableRow, 25 | '*': document.createElement('div') 26 | }, 27 | readyRE = /complete|loaded|interactive/, 28 | simpleSelectorRE = /^[\w-]*$/, 29 | class2type = {}, 30 | toString = class2type.toString, 31 | zepto = {}, 32 | camelize, uniq, 33 | tempParent = document.createElement('div'), 34 | propMap = { 35 | 'tabindex': 'tabIndex', 36 | 'readonly': 'readOnly', 37 | 'for': 'htmlFor', 38 | 'class': 'className', 39 | 'maxlength': 'maxLength', 40 | 'cellspacing': 'cellSpacing', 41 | 'cellpadding': 'cellPadding', 42 | 'rowspan': 'rowSpan', 43 | 'colspan': 'colSpan', 44 | 'usemap': 'useMap', 45 | 'frameborder': 'frameBorder', 46 | 'contenteditable': 'contentEditable' 47 | }, 48 | isArray = Array.isArray || 49 | function(object){ return object instanceof Array } 50 | 51 | zepto.matches = function(element, selector) { 52 | if (!selector || !element || element.nodeType !== 1) return false 53 | var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector || 54 | element.oMatchesSelector || element.matchesSelector 55 | if (matchesSelector) return matchesSelector.call(element, selector) 56 | // fall back to performing a selector: 57 | var match, parent = element.parentNode, temp = !parent 58 | if (temp) (parent = tempParent).appendChild(element) 59 | match = ~zepto.qsa(parent, selector).indexOf(element) 60 | temp && tempParent.removeChild(element) 61 | return match 62 | } 63 | 64 | function type(obj) { 65 | return obj == null ? String(obj) : 66 | class2type[toString.call(obj)] || "object" 67 | } 68 | 69 | function isFunction(value) { return type(value) == "function" } 70 | function isWindow(obj) { return obj != null && obj == obj.window } 71 | function isDocument(obj) { return obj != null && obj.nodeType == obj.DOCUMENT_NODE } 72 | function isObject(obj) { return type(obj) == "object" } 73 | function isPlainObject(obj) { 74 | return isObject(obj) && !isWindow(obj) && Object.getPrototypeOf(obj) == Object.prototype 75 | } 76 | function likeArray(obj) { return typeof obj.length == 'number' } 77 | 78 | function compact(array) { return filter.call(array, function(item){ return item != null }) } 79 | function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array } 80 | camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) } 81 | function dasherize(str) { 82 | return str.replace(/::/g, '/') 83 | .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') 84 | .replace(/([a-z\d])([A-Z])/g, '$1_$2') 85 | .replace(/_/g, '-') 86 | .toLowerCase() 87 | } 88 | uniq = function(array){ return filter.call(array, function(item, idx){ return array.indexOf(item) == idx }) } 89 | 90 | function classRE(name) { 91 | return name in classCache ? 92 | classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)')) 93 | } 94 | 95 | function maybeAddPx(name, value) { 96 | return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value 97 | } 98 | 99 | function defaultDisplay(nodeName) { 100 | var element, display 101 | if (!elementDisplay[nodeName]) { 102 | element = document.createElement(nodeName) 103 | document.body.appendChild(element) 104 | display = getComputedStyle(element, '').getPropertyValue("display") 105 | element.parentNode.removeChild(element) 106 | display == "none" && (display = "block") 107 | elementDisplay[nodeName] = display 108 | } 109 | return elementDisplay[nodeName] 110 | } 111 | 112 | function children(element) { 113 | return 'children' in element ? 114 | slice.call(element.children) : 115 | $.map(element.childNodes, function(node){ if (node.nodeType == 1) return node }) 116 | } 117 | 118 | // `$.zepto.fragment` takes a html string and an optional tag name 119 | // to generate DOM nodes nodes from the given html string. 120 | // The generated DOM nodes are returned as an array. 121 | // This function can be overriden in plugins for example to make 122 | // it compatible with browsers that don't support the DOM fully. 123 | zepto.fragment = function(html, name, properties) { 124 | var dom, nodes, container 125 | 126 | // A special case optimization for a single tag 127 | if (singleTagRE.test(html)) dom = $(document.createElement(RegExp.$1)) 128 | 129 | if (!dom) { 130 | if (html.replace) html = html.replace(tagExpanderRE, "<$1>") 131 | if (name === undefined) name = fragmentRE.test(html) && RegExp.$1 132 | if (!(name in containers)) name = '*' 133 | 134 | container = containers[name] 135 | container.innerHTML = '' + html 136 | dom = $.each(slice.call(container.childNodes), function(){ 137 | container.removeChild(this) 138 | }) 139 | } 140 | 141 | if (isPlainObject(properties)) { 142 | nodes = $(dom) 143 | $.each(properties, function(key, value) { 144 | if (methodAttributes.indexOf(key) > -1) nodes[key](value) 145 | else nodes.attr(key, value) 146 | }) 147 | } 148 | 149 | return dom 150 | } 151 | 152 | // `$.zepto.Z` swaps out the prototype of the given `dom` array 153 | // of nodes with `$.fn` and thus supplying all the Zepto functions 154 | // to the array. Note that `__proto__` is not supported on Internet 155 | // Explorer. This method can be overriden in plugins. 156 | zepto.Z = function(dom, selector) { 157 | dom = dom || [] 158 | dom.__proto__ = $.fn 159 | dom.selector = selector || '' 160 | return dom 161 | } 162 | 163 | // `$.zepto.isZ` should return `true` if the given object is a Zepto 164 | // collection. This method can be overriden in plugins. 165 | zepto.isZ = function(object) { 166 | return object instanceof zepto.Z 167 | } 168 | 169 | // `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and 170 | // takes a CSS selector and an optional context (and handles various 171 | // special cases). 172 | // This method can be overriden in plugins. 173 | zepto.init = function(selector, context) { 174 | var dom 175 | // If nothing given, return an empty Zepto collection 176 | if (!selector) return zepto.Z() 177 | // Optimize for string selectors 178 | else if (typeof selector == 'string') { 179 | selector = selector.trim() 180 | // If it's a html fragment, create nodes from it 181 | // Note: In both Chrome 21 and Firefox 15, DOM error 12 182 | // is thrown if the fragment doesn't begin with < 183 | if (selector[0] == '<' && fragmentRE.test(selector)) 184 | dom = zepto.fragment(selector, RegExp.$1, context), selector = null 185 | // If there's a context, create a collection on that context first, and select 186 | // nodes from there 187 | else if (context !== undefined) return $(context).find(selector) 188 | // If it's a CSS selector, use it to select nodes. 189 | else dom = zepto.qsa(document, selector) 190 | } 191 | // If a function is given, call it when the DOM is ready 192 | else if (isFunction(selector)) return $(document).ready(selector) 193 | // If a Zepto collection is given, just return it 194 | else if (zepto.isZ(selector)) return selector 195 | else { 196 | // normalize array if an array of nodes is given 197 | if (isArray(selector)) dom = compact(selector) 198 | // Wrap DOM nodes. 199 | else if (isObject(selector)) 200 | dom = [selector], selector = null 201 | // If it's a html fragment, create nodes from it 202 | else if (fragmentRE.test(selector)) 203 | dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null 204 | // If there's a context, create a collection on that context first, and select 205 | // nodes from there 206 | else if (context !== undefined) return $(context).find(selector) 207 | // And last but no least, if it's a CSS selector, use it to select nodes. 208 | else dom = zepto.qsa(document, selector) 209 | } 210 | // create a new Zepto collection from the nodes found 211 | return zepto.Z(dom, selector) 212 | } 213 | 214 | // `$` will be the base `Zepto` object. When calling this 215 | // function just call `$.zepto.init, which makes the implementation 216 | // details of selecting nodes and creating Zepto collections 217 | // patchable in plugins. 218 | $ = function(selector, context){ 219 | return zepto.init(selector, context) 220 | } 221 | 222 | function extend(target, source, deep) { 223 | for (key in source) 224 | if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { 225 | if (isPlainObject(source[key]) && !isPlainObject(target[key])) 226 | target[key] = {} 227 | if (isArray(source[key]) && !isArray(target[key])) 228 | target[key] = [] 229 | extend(target[key], source[key], deep) 230 | } 231 | else if (source[key] !== undefined) target[key] = source[key] 232 | } 233 | 234 | // Copy all but undefined properties from one or more 235 | // objects to the `target` object. 236 | $.extend = function(target){ 237 | var deep, args = slice.call(arguments, 1) 238 | if (typeof target == 'boolean') { 239 | deep = target 240 | target = args.shift() 241 | } 242 | args.forEach(function(arg){ extend(target, arg, deep) }) 243 | return target 244 | } 245 | 246 | // `$.zepto.qsa` is Zepto's CSS selector implementation which 247 | // uses `document.querySelectorAll` and optimizes for some special cases, like `#id`. 248 | // This method can be overriden in plugins. 249 | zepto.qsa = function(element, selector){ 250 | var found, 251 | maybeID = selector[0] == '#', 252 | maybeClass = !maybeID && selector[0] == '.', 253 | nameOnly = maybeID || maybeClass ? selector.slice(1) : selector, // Ensure that a 1 char tag name still gets checked 254 | isSimple = simpleSelectorRE.test(nameOnly) 255 | return (isDocument(element) && isSimple && maybeID) ? 256 | ( (found = element.getElementById(nameOnly)) ? [found] : [] ) : 257 | (element.nodeType !== 1 && element.nodeType !== 9) ? [] : 258 | slice.call( 259 | isSimple && !maybeID ? 260 | maybeClass ? element.getElementsByClassName(nameOnly) : // If it's simple, it could be a class 261 | element.getElementsByTagName(selector) : // Or a tag 262 | element.querySelectorAll(selector) // Or it's not simple, and we need to query all 263 | ) 264 | } 265 | 266 | function filtered(nodes, selector) { 267 | return selector == null ? $(nodes) : $(nodes).filter(selector) 268 | } 269 | 270 | $.contains = document.documentElement.contains ? 271 | function(parent, node) { 272 | return parent !== node && parent.contains(node) 273 | } : 274 | function(parent, node) { 275 | while (node && (node = node.parentNode)) 276 | if (node === parent) return true 277 | return false 278 | } 279 | 280 | function funcArg(context, arg, idx, payload) { 281 | return isFunction(arg) ? arg.call(context, idx, payload) : arg 282 | } 283 | 284 | function setAttribute(node, name, value) { 285 | value == null ? node.removeAttribute(name) : node.setAttribute(name, value) 286 | } 287 | 288 | // access className property while respecting SVGAnimatedString 289 | function className(node, value){ 290 | var klass = node.className || '', 291 | svg = klass && klass.baseVal !== undefined 292 | 293 | if (value === undefined) return svg ? klass.baseVal : klass 294 | svg ? (klass.baseVal = value) : (node.className = value) 295 | } 296 | 297 | // "true" => true 298 | // "false" => false 299 | // "null" => null 300 | // "42" => 42 301 | // "42.5" => 42.5 302 | // "08" => "08" 303 | // JSON => parse if valid 304 | // String => self 305 | function deserializeValue(value) { 306 | try { 307 | return value ? 308 | value == "true" || 309 | ( value == "false" ? false : 310 | value == "null" ? null : 311 | +value + "" == value ? +value : 312 | /^[\[\{]/.test(value) ? $.parseJSON(value) : 313 | value ) 314 | : value 315 | } catch(e) { 316 | return value 317 | } 318 | } 319 | 320 | $.type = type 321 | $.isFunction = isFunction 322 | $.isWindow = isWindow 323 | $.isArray = isArray 324 | $.isPlainObject = isPlainObject 325 | 326 | $.isEmptyObject = function(obj) { 327 | var name 328 | for (name in obj) return false 329 | return true 330 | } 331 | 332 | $.inArray = function(elem, array, i){ 333 | return emptyArray.indexOf.call(array, elem, i) 334 | } 335 | 336 | $.camelCase = camelize 337 | $.trim = function(str) { 338 | return str == null ? "" : String.prototype.trim.call(str) 339 | } 340 | 341 | // plugin compatibility 342 | $.uuid = 0 343 | $.support = { } 344 | $.expr = { } 345 | 346 | $.map = function(elements, callback){ 347 | var value, values = [], i, key 348 | if (likeArray(elements)) 349 | for (i = 0; i < elements.length; i++) { 350 | value = callback(elements[i], i) 351 | if (value != null) values.push(value) 352 | } 353 | else 354 | for (key in elements) { 355 | value = callback(elements[key], key) 356 | if (value != null) values.push(value) 357 | } 358 | return flatten(values) 359 | } 360 | 361 | $.each = function(elements, callback){ 362 | var i, key 363 | if (likeArray(elements)) { 364 | for (i = 0; i < elements.length; i++) 365 | if (callback.call(elements[i], i, elements[i]) === false) return elements 366 | } else { 367 | for (key in elements) 368 | if (callback.call(elements[key], key, elements[key]) === false) return elements 369 | } 370 | 371 | return elements 372 | } 373 | 374 | $.grep = function(elements, callback){ 375 | return filter.call(elements, callback) 376 | } 377 | 378 | if (window.JSON) $.parseJSON = JSON.parse 379 | 380 | // Populate the class2type map 381 | $.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { 382 | class2type[ "[object " + name + "]" ] = name.toLowerCase() 383 | }) 384 | 385 | // Define methods that will be available on all 386 | // Zepto collections 387 | $.fn = { 388 | // Because a collection acts like an array 389 | // copy over these useful array functions. 390 | forEach: emptyArray.forEach, 391 | reduce: emptyArray.reduce, 392 | push: emptyArray.push, 393 | sort: emptyArray.sort, 394 | indexOf: emptyArray.indexOf, 395 | concat: emptyArray.concat, 396 | 397 | // `map` and `slice` in the jQuery API work differently 398 | // from their array counterparts 399 | map: function(fn){ 400 | return $($.map(this, function(el, i){ return fn.call(el, i, el) })) 401 | }, 402 | slice: function(){ 403 | return $(slice.apply(this, arguments)) 404 | }, 405 | 406 | ready: function(callback){ 407 | // need to check if document.body exists for IE as that browser reports 408 | // document ready when it hasn't yet created the body element 409 | if (readyRE.test(document.readyState) && document.body) callback($) 410 | else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false) 411 | return this 412 | }, 413 | get: function(idx){ 414 | return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length] 415 | }, 416 | toArray: function(){ return this.get() }, 417 | size: function(){ 418 | return this.length 419 | }, 420 | remove: function(){ 421 | return this.each(function(){ 422 | if (this.parentNode != null) 423 | this.parentNode.removeChild(this) 424 | }) 425 | }, 426 | each: function(callback){ 427 | emptyArray.every.call(this, function(el, idx){ 428 | return callback.call(el, idx, el) !== false 429 | }) 430 | return this 431 | }, 432 | filter: function(selector){ 433 | if (isFunction(selector)) return this.not(this.not(selector)) 434 | return $(filter.call(this, function(element){ 435 | return zepto.matches(element, selector) 436 | })) 437 | }, 438 | add: function(selector,context){ 439 | return $(uniq(this.concat($(selector,context)))) 440 | }, 441 | is: function(selector){ 442 | return this.length > 0 && zepto.matches(this[0], selector) 443 | }, 444 | not: function(selector){ 445 | var nodes=[] 446 | if (isFunction(selector) && selector.call !== undefined) 447 | this.each(function(idx){ 448 | if (!selector.call(this,idx)) nodes.push(this) 449 | }) 450 | else { 451 | var excludes = typeof selector == 'string' ? this.filter(selector) : 452 | (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector) 453 | this.forEach(function(el){ 454 | if (excludes.indexOf(el) < 0) nodes.push(el) 455 | }) 456 | } 457 | return $(nodes) 458 | }, 459 | has: function(selector){ 460 | return this.filter(function(){ 461 | return isObject(selector) ? 462 | $.contains(this, selector) : 463 | $(this).find(selector).size() 464 | }) 465 | }, 466 | eq: function(idx){ 467 | return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1) 468 | }, 469 | first: function(){ 470 | var el = this[0] 471 | return el && !isObject(el) ? el : $(el) 472 | }, 473 | last: function(){ 474 | var el = this[this.length - 1] 475 | return el && !isObject(el) ? el : $(el) 476 | }, 477 | find: function(selector){ 478 | var result, $this = this 479 | if (!selector) result = $() 480 | else if (typeof selector == 'object') 481 | result = $(selector).filter(function(){ 482 | var node = this 483 | return emptyArray.some.call($this, function(parent){ 484 | return $.contains(parent, node) 485 | }) 486 | }) 487 | else if (this.length == 1) result = $(zepto.qsa(this[0], selector)) 488 | else result = this.map(function(){ return zepto.qsa(this, selector) }) 489 | return result 490 | }, 491 | closest: function(selector, context){ 492 | var node = this[0], collection = false 493 | if (typeof selector == 'object') collection = $(selector) 494 | while (node && !(collection ? collection.indexOf(node) >= 0 : zepto.matches(node, selector))) 495 | node = node !== context && !isDocument(node) && node.parentNode 496 | return $(node) 497 | }, 498 | parents: function(selector){ 499 | var ancestors = [], nodes = this 500 | while (nodes.length > 0) 501 | nodes = $.map(nodes, function(node){ 502 | if ((node = node.parentNode) && !isDocument(node) && ancestors.indexOf(node) < 0) { 503 | ancestors.push(node) 504 | return node 505 | } 506 | }) 507 | return filtered(ancestors, selector) 508 | }, 509 | parent: function(selector){ 510 | return filtered(uniq(this.pluck('parentNode')), selector) 511 | }, 512 | children: function(selector){ 513 | return filtered(this.map(function(){ return children(this) }), selector) 514 | }, 515 | contents: function() { 516 | return this.map(function() { return slice.call(this.childNodes) }) 517 | }, 518 | siblings: function(selector){ 519 | return filtered(this.map(function(i, el){ 520 | return filter.call(children(el.parentNode), function(child){ return child!==el }) 521 | }), selector) 522 | }, 523 | empty: function(){ 524 | return this.each(function(){ this.innerHTML = '' }) 525 | }, 526 | // `pluck` is borrowed from Prototype.js 527 | pluck: function(property){ 528 | return $.map(this, function(el){ return el[property] }) 529 | }, 530 | show: function(){ 531 | return this.each(function(){ 532 | this.style.display == "none" && (this.style.display = '') 533 | if (getComputedStyle(this, '').getPropertyValue("display") == "none") 534 | this.style.display = defaultDisplay(this.nodeName) 535 | }) 536 | }, 537 | replaceWith: function(newContent){ 538 | return this.before(newContent).remove() 539 | }, 540 | wrap: function(structure){ 541 | var func = isFunction(structure) 542 | if (this[0] && !func) 543 | var dom = $(structure).get(0), 544 | clone = dom.parentNode || this.length > 1 545 | 546 | return this.each(function(index){ 547 | $(this).wrapAll( 548 | func ? structure.call(this, index) : 549 | clone ? dom.cloneNode(true) : dom 550 | ) 551 | }) 552 | }, 553 | wrapAll: function(structure){ 554 | if (this[0]) { 555 | $(this[0]).before(structure = $(structure)) 556 | var children 557 | // drill down to the inmost element 558 | while ((children = structure.children()).length) structure = children.first() 559 | $(structure).append(this) 560 | } 561 | return this 562 | }, 563 | wrapInner: function(structure){ 564 | var func = isFunction(structure) 565 | return this.each(function(index){ 566 | var self = $(this), contents = self.contents(), 567 | dom = func ? structure.call(this, index) : structure 568 | contents.length ? contents.wrapAll(dom) : self.append(dom) 569 | }) 570 | }, 571 | unwrap: function(){ 572 | this.parent().each(function(){ 573 | $(this).replaceWith($(this).children()) 574 | }) 575 | return this 576 | }, 577 | clone: function(){ 578 | return this.map(function(){ return this.cloneNode(true) }) 579 | }, 580 | hide: function(){ 581 | return this.css("display", "none") 582 | }, 583 | toggle: function(setting){ 584 | return this.each(function(){ 585 | var el = $(this) 586 | ;(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide() 587 | }) 588 | }, 589 | prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') }, 590 | next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') }, 591 | html: function(html){ 592 | return 0 in arguments ? 593 | this.each(function(idx){ 594 | var originHtml = this.innerHTML 595 | $(this).empty().append( funcArg(this, html, idx, originHtml) ) 596 | }) : 597 | (0 in this ? this[0].innerHTML : null) 598 | }, 599 | text: function(text){ 600 | return 0 in arguments ? 601 | this.each(function(idx){ 602 | var newText = funcArg(this, text, idx, this.textContent) 603 | this.textContent = newText == null ? '' : ''+newText 604 | }) : 605 | (0 in this ? this[0].textContent : null) 606 | }, 607 | attr: function(name, value){ 608 | var result 609 | return (typeof name == 'string' && !(1 in arguments)) ? 610 | (!this.length || this[0].nodeType !== 1 ? undefined : 611 | (!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result 612 | ) : 613 | this.each(function(idx){ 614 | if (this.nodeType !== 1) return 615 | if (isObject(name)) for (key in name) setAttribute(this, key, name[key]) 616 | else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name))) 617 | }) 618 | }, 619 | removeAttr: function(name){ 620 | return this.each(function(){ this.nodeType === 1 && name.split(' ').forEach(function(attribute){ 621 | setAttribute(this, attribute) 622 | }, this)}) 623 | }, 624 | prop: function(name, value){ 625 | name = propMap[name] || name 626 | return (1 in arguments) ? 627 | this.each(function(idx){ 628 | this[name] = funcArg(this, value, idx, this[name]) 629 | }) : 630 | (this[0] && this[0][name]) 631 | }, 632 | data: function(name, value){ 633 | var attrName = 'data-' + name.replace(capitalRE, '-$1').toLowerCase() 634 | 635 | var data = (1 in arguments) ? 636 | this.attr(attrName, value) : 637 | this.attr(attrName) 638 | 639 | return data !== null ? deserializeValue(data) : undefined 640 | }, 641 | val: function(value){ 642 | return 0 in arguments ? 643 | this.each(function(idx){ 644 | this.value = funcArg(this, value, idx, this.value) 645 | }) : 646 | (this[0] && (this[0].multiple ? 647 | $(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') : 648 | this[0].value) 649 | ) 650 | }, 651 | offset: function(coordinates){ 652 | if (coordinates) return this.each(function(index){ 653 | var $this = $(this), 654 | coords = funcArg(this, coordinates, index, $this.offset()), 655 | parentOffset = $this.offsetParent().offset(), 656 | props = { 657 | top: coords.top - parentOffset.top, 658 | left: coords.left - parentOffset.left 659 | } 660 | 661 | if ($this.css('position') == 'static') props['position'] = 'relative' 662 | $this.css(props) 663 | }) 664 | if (!this.length) return null 665 | var obj = this[0].getBoundingClientRect() 666 | return { 667 | left: obj.left + window.pageXOffset, 668 | top: obj.top + window.pageYOffset, 669 | width: Math.round(obj.width), 670 | height: Math.round(obj.height) 671 | } 672 | }, 673 | css: function(property, value){ 674 | if (arguments.length < 2) { 675 | var computedStyle, element = this[0] 676 | if(!element) return 677 | computedStyle = getComputedStyle(element, '') 678 | if (typeof property == 'string') 679 | return element.style[camelize(property)] || computedStyle.getPropertyValue(property) 680 | else if (isArray(property)) { 681 | var props = {} 682 | $.each(property, function(_, prop){ 683 | props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop)) 684 | }) 685 | return props 686 | } 687 | } 688 | 689 | var css = '' 690 | if (type(property) == 'string') { 691 | if (!value && value !== 0) 692 | this.each(function(){ this.style.removeProperty(dasherize(property)) }) 693 | else 694 | css = dasherize(property) + ":" + maybeAddPx(property, value) 695 | } else { 696 | for (key in property) 697 | if (!property[key] && property[key] !== 0) 698 | this.each(function(){ this.style.removeProperty(dasherize(key)) }) 699 | else 700 | css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';' 701 | } 702 | 703 | return this.each(function(){ this.style.cssText += ';' + css }) 704 | }, 705 | index: function(element){ 706 | return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0]) 707 | }, 708 | hasClass: function(name){ 709 | if (!name) return false 710 | return emptyArray.some.call(this, function(el){ 711 | return this.test(className(el)) 712 | }, classRE(name)) 713 | }, 714 | addClass: function(name){ 715 | if (!name) return this 716 | return this.each(function(idx){ 717 | if (!('className' in this)) return 718 | classList = [] 719 | var cls = className(this), newName = funcArg(this, name, idx, cls) 720 | newName.split(/\s+/g).forEach(function(klass){ 721 | if (!$(this).hasClass(klass)) classList.push(klass) 722 | }, this) 723 | classList.length && className(this, cls + (cls ? " " : "") + classList.join(" ")) 724 | }) 725 | }, 726 | removeClass: function(name){ 727 | return this.each(function(idx){ 728 | if (!('className' in this)) return 729 | if (name === undefined) return className(this, '') 730 | classList = className(this) 731 | funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){ 732 | classList = classList.replace(classRE(klass), " ") 733 | }) 734 | className(this, classList.trim()) 735 | }) 736 | }, 737 | toggleClass: function(name, when){ 738 | if (!name) return this 739 | return this.each(function(idx){ 740 | var $this = $(this), names = funcArg(this, name, idx, className(this)) 741 | names.split(/\s+/g).forEach(function(klass){ 742 | (when === undefined ? !$this.hasClass(klass) : when) ? 743 | $this.addClass(klass) : $this.removeClass(klass) 744 | }) 745 | }) 746 | }, 747 | scrollTop: function(value){ 748 | if (!this.length) return 749 | var hasScrollTop = 'scrollTop' in this[0] 750 | if (value === undefined) return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset 751 | return this.each(hasScrollTop ? 752 | function(){ this.scrollTop = value } : 753 | function(){ this.scrollTo(this.scrollX, value) }) 754 | }, 755 | scrollLeft: function(value){ 756 | if (!this.length) return 757 | var hasScrollLeft = 'scrollLeft' in this[0] 758 | if (value === undefined) return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset 759 | return this.each(hasScrollLeft ? 760 | function(){ this.scrollLeft = value } : 761 | function(){ this.scrollTo(value, this.scrollY) }) 762 | }, 763 | position: function() { 764 | if (!this.length) return 765 | 766 | var elem = this[0], 767 | // Get *real* offsetParent 768 | offsetParent = this.offsetParent(), 769 | // Get correct offsets 770 | offset = this.offset(), 771 | parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset() 772 | 773 | // Subtract element margins 774 | // note: when an element has margin: auto the offsetLeft and marginLeft 775 | // are the same in Safari causing offset.left to incorrectly be 0 776 | offset.top -= parseFloat( $(elem).css('margin-top') ) || 0 777 | offset.left -= parseFloat( $(elem).css('margin-left') ) || 0 778 | 779 | // Add offsetParent borders 780 | parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0 781 | parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0 782 | 783 | // Subtract the two offsets 784 | return { 785 | top: offset.top - parentOffset.top, 786 | left: offset.left - parentOffset.left 787 | } 788 | }, 789 | offsetParent: function() { 790 | return this.map(function(){ 791 | var parent = this.offsetParent || document.body 792 | while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static") 793 | parent = parent.offsetParent 794 | return parent 795 | }) 796 | } 797 | } 798 | 799 | // for now 800 | $.fn.detach = $.fn.remove 801 | 802 | // Generate the `width` and `height` functions 803 | ;['width', 'height'].forEach(function(dimension){ 804 | var dimensionProperty = 805 | dimension.replace(/./, function(m){ return m[0].toUpperCase() }) 806 | 807 | $.fn[dimension] = function(value){ 808 | var offset, el = this[0] 809 | if (value === undefined) return isWindow(el) ? el['inner' + dimensionProperty] : 810 | isDocument(el) ? el.documentElement['scroll' + dimensionProperty] : 811 | (offset = this.offset()) && offset[dimension] 812 | else return this.each(function(idx){ 813 | el = $(this) 814 | el.css(dimension, funcArg(this, value, idx, el[dimension]())) 815 | }) 816 | } 817 | }) 818 | 819 | function traverseNode(node, fun) { 820 | fun(node) 821 | for (var i = 0, len = node.childNodes.length; i < len; i++) 822 | traverseNode(node.childNodes[i], fun) 823 | } 824 | 825 | // Generate the `after`, `prepend`, `before`, `append`, 826 | // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods. 827 | adjacencyOperators.forEach(function(operator, operatorIndex) { 828 | var inside = operatorIndex % 2 //=> prepend, append 829 | 830 | $.fn[operator] = function(){ 831 | // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings 832 | var argType, nodes = $.map(arguments, function(arg) { 833 | argType = type(arg) 834 | return argType == "object" || argType == "array" || arg == null ? 835 | arg : zepto.fragment(arg) 836 | }), 837 | parent, copyByClone = this.length > 1 838 | if (nodes.length < 1) return this 839 | 840 | return this.each(function(_, target){ 841 | parent = inside ? target : target.parentNode 842 | 843 | // convert all methods to a "before" operation 844 | target = operatorIndex == 0 ? target.nextSibling : 845 | operatorIndex == 1 ? target.firstChild : 846 | operatorIndex == 2 ? target : 847 | null 848 | 849 | var parentInDocument = $.contains(document.documentElement, parent) 850 | 851 | nodes.forEach(function(node){ 852 | if (copyByClone) node = node.cloneNode(true) 853 | else if (!parent) return $(node).remove() 854 | 855 | parent.insertBefore(node, target) 856 | if (parentInDocument) traverseNode(node, function(el){ 857 | if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' && 858 | (!el.type || el.type === 'text/javascript') && !el.src) 859 | window['eval'].call(window, el.innerHTML) 860 | }) 861 | }) 862 | }) 863 | } 864 | 865 | // after => insertAfter 866 | // prepend => prependTo 867 | // before => insertBefore 868 | // append => appendTo 869 | $.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){ 870 | $(html)[operator](this) 871 | return this 872 | } 873 | }) 874 | 875 | zepto.Z.prototype = $.fn 876 | 877 | // Export internal API functions in the `$.zepto` namespace 878 | zepto.uniq = uniq 879 | zepto.deserializeValue = deserializeValue 880 | $.zepto = zepto 881 | 882 | return $ 883 | })() 884 | 885 | window.Zepto = Zepto 886 | window.$ === undefined && (window.$ = Zepto) 887 | 888 | ;(function($){ 889 | var _zid = 1, undefined, 890 | slice = Array.prototype.slice, 891 | isFunction = $.isFunction, 892 | isString = function(obj){ return typeof obj == 'string' }, 893 | handlers = {}, 894 | specialEvents={}, 895 | focusinSupported = 'onfocusin' in window, 896 | focus = { focus: 'focusin', blur: 'focusout' }, 897 | hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' } 898 | 899 | specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents' 900 | 901 | function zid(element) { 902 | return element._zid || (element._zid = _zid++) 903 | } 904 | function findHandlers(element, event, fn, selector) { 905 | event = parse(event) 906 | if (event.ns) var matcher = matcherFor(event.ns) 907 | return (handlers[zid(element)] || []).filter(function(handler) { 908 | return handler 909 | && (!event.e || handler.e == event.e) 910 | && (!event.ns || matcher.test(handler.ns)) 911 | && (!fn || zid(handler.fn) === zid(fn)) 912 | && (!selector || handler.sel == selector) 913 | }) 914 | } 915 | function parse(event) { 916 | var parts = ('' + event).split('.') 917 | return {e: parts[0], ns: parts.slice(1).sort().join(' ')} 918 | } 919 | function matcherFor(ns) { 920 | return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)') 921 | } 922 | 923 | function eventCapture(handler, captureSetting) { 924 | return handler.del && 925 | (!focusinSupported && (handler.e in focus)) || 926 | !!captureSetting 927 | } 928 | 929 | function realEvent(type) { 930 | return hover[type] || (focusinSupported && focus[type]) || type 931 | } 932 | 933 | function add(element, events, fn, data, selector, delegator, capture){ 934 | var id = zid(element), set = (handlers[id] || (handlers[id] = [])) 935 | events.split(/\s/).forEach(function(event){ 936 | if (event == 'ready') return $(document).ready(fn) 937 | var handler = parse(event) 938 | handler.fn = fn 939 | handler.sel = selector 940 | // emulate mouseenter, mouseleave 941 | if (handler.e in hover) fn = function(e){ 942 | var related = e.relatedTarget 943 | if (!related || (related !== this && !$.contains(this, related))) 944 | return handler.fn.apply(this, arguments) 945 | } 946 | handler.del = delegator 947 | var callback = delegator || fn 948 | handler.proxy = function(e){ 949 | e = compatible(e) 950 | if (e.isImmediatePropagationStopped()) return 951 | e.data = data 952 | var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args)) 953 | if (result === false) e.preventDefault(), e.stopPropagation() 954 | return result 955 | } 956 | handler.i = set.length 957 | set.push(handler) 958 | if ('addEventListener' in element) 959 | element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) 960 | }) 961 | } 962 | function remove(element, events, fn, selector, capture){ 963 | var id = zid(element) 964 | ;(events || '').split(/\s/).forEach(function(event){ 965 | findHandlers(element, event, fn, selector).forEach(function(handler){ 966 | delete handlers[id][handler.i] 967 | if ('removeEventListener' in element) 968 | element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) 969 | }) 970 | }) 971 | } 972 | 973 | $.event = { add: add, remove: remove } 974 | 975 | $.proxy = function(fn, context) { 976 | var args = (2 in arguments) && slice.call(arguments, 2) 977 | if (isFunction(fn)) { 978 | var proxyFn = function(){ return fn.apply(context, args ? args.concat(slice.call(arguments)) : arguments) } 979 | proxyFn._zid = zid(fn) 980 | return proxyFn 981 | } else if (isString(context)) { 982 | if (args) { 983 | args.unshift(fn[context], fn) 984 | return $.proxy.apply(null, args) 985 | } else { 986 | return $.proxy(fn[context], fn) 987 | } 988 | } else { 989 | throw new TypeError("expected function") 990 | } 991 | } 992 | 993 | $.fn.bind = function(event, data, callback){ 994 | return this.on(event, data, callback) 995 | } 996 | $.fn.unbind = function(event, callback){ 997 | return this.off(event, callback) 998 | } 999 | $.fn.one = function(event, selector, data, callback){ 1000 | return this.on(event, selector, data, callback, 1) 1001 | } 1002 | 1003 | var returnTrue = function(){return true}, 1004 | returnFalse = function(){return false}, 1005 | ignoreProperties = /^([A-Z]|returnValue$|layer[XY]$)/, 1006 | eventMethods = { 1007 | preventDefault: 'isDefaultPrevented', 1008 | stopImmediatePropagation: 'isImmediatePropagationStopped', 1009 | stopPropagation: 'isPropagationStopped' 1010 | } 1011 | 1012 | function compatible(event, source) { 1013 | if (source || !event.isDefaultPrevented) { 1014 | source || (source = event) 1015 | 1016 | $.each(eventMethods, function(name, predicate) { 1017 | var sourceMethod = source[name] 1018 | event[name] = function(){ 1019 | this[predicate] = returnTrue 1020 | return sourceMethod && sourceMethod.apply(source, arguments) 1021 | } 1022 | event[predicate] = returnFalse 1023 | }) 1024 | 1025 | if (source.defaultPrevented !== undefined ? source.defaultPrevented : 1026 | 'returnValue' in source ? source.returnValue === false : 1027 | source.getPreventDefault && source.getPreventDefault()) 1028 | event.isDefaultPrevented = returnTrue 1029 | } 1030 | return event 1031 | } 1032 | 1033 | function createProxy(event) { 1034 | var key, proxy = { originalEvent: event } 1035 | for (key in event) 1036 | if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key] 1037 | 1038 | return compatible(proxy, event) 1039 | } 1040 | 1041 | $.fn.delegate = function(selector, event, callback){ 1042 | return this.on(event, selector, callback) 1043 | } 1044 | $.fn.undelegate = function(selector, event, callback){ 1045 | return this.off(event, selector, callback) 1046 | } 1047 | 1048 | $.fn.live = function(event, callback){ 1049 | $(document.body).delegate(this.selector, event, callback) 1050 | return this 1051 | } 1052 | $.fn.die = function(event, callback){ 1053 | $(document.body).undelegate(this.selector, event, callback) 1054 | return this 1055 | } 1056 | 1057 | $.fn.on = function(event, selector, data, callback, one){ 1058 | var autoRemove, delegator, $this = this 1059 | if (event && !isString(event)) { 1060 | $.each(event, function(type, fn){ 1061 | $this.on(type, selector, data, fn, one) 1062 | }) 1063 | return $this 1064 | } 1065 | 1066 | if (!isString(selector) && !isFunction(callback) && callback !== false) 1067 | callback = data, data = selector, selector = undefined 1068 | if (isFunction(data) || data === false) 1069 | callback = data, data = undefined 1070 | 1071 | if (callback === false) callback = returnFalse 1072 | 1073 | return $this.each(function(_, element){ 1074 | if (one) autoRemove = function(e){ 1075 | remove(element, e.type, callback) 1076 | return callback.apply(this, arguments) 1077 | } 1078 | 1079 | if (selector) delegator = function(e){ 1080 | var evt, match = $(e.target).closest(selector, element).get(0) 1081 | if (match && match !== element) { 1082 | evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element}) 1083 | return (autoRemove || callback).apply(match, [evt].concat(slice.call(arguments, 1))) 1084 | } 1085 | } 1086 | 1087 | add(element, event, callback, data, selector, delegator || autoRemove) 1088 | }) 1089 | } 1090 | $.fn.off = function(event, selector, callback){ 1091 | var $this = this 1092 | if (event && !isString(event)) { 1093 | $.each(event, function(type, fn){ 1094 | $this.off(type, selector, fn) 1095 | }) 1096 | return $this 1097 | } 1098 | 1099 | if (!isString(selector) && !isFunction(callback) && callback !== false) 1100 | callback = selector, selector = undefined 1101 | 1102 | if (callback === false) callback = returnFalse 1103 | 1104 | return $this.each(function(){ 1105 | remove(this, event, callback, selector) 1106 | }) 1107 | } 1108 | 1109 | $.fn.trigger = function(event, args){ 1110 | event = (isString(event) || $.isPlainObject(event)) ? $.Event(event) : compatible(event) 1111 | event._args = args 1112 | return this.each(function(){ 1113 | // handle focus(), blur() by calling them directly 1114 | if (event.type in focus && typeof this[event.type] == "function") this[event.type]() 1115 | // items in the collection might not be DOM elements 1116 | else if ('dispatchEvent' in this) this.dispatchEvent(event) 1117 | else $(this).triggerHandler(event, args) 1118 | }) 1119 | } 1120 | 1121 | // triggers event handlers on current element just as if an event occurred, 1122 | // doesn't trigger an actual event, doesn't bubble 1123 | $.fn.triggerHandler = function(event, args){ 1124 | var e, result 1125 | this.each(function(i, element){ 1126 | e = createProxy(isString(event) ? $.Event(event) : event) 1127 | e._args = args 1128 | e.target = element 1129 | $.each(findHandlers(element, event.type || event), function(i, handler){ 1130 | result = handler.proxy(e) 1131 | if (e.isImmediatePropagationStopped()) return false 1132 | }) 1133 | }) 1134 | return result 1135 | } 1136 | 1137 | // shortcut methods for `.bind(event, fn)` for each event type 1138 | ;('focusin focusout focus blur load resize scroll unload click dblclick '+ 1139 | 'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+ 1140 | 'change select keydown keypress keyup error').split(' ').forEach(function(event) { 1141 | $.fn[event] = function(callback) { 1142 | return (0 in arguments) ? 1143 | this.bind(event, callback) : 1144 | this.trigger(event) 1145 | } 1146 | }) 1147 | 1148 | $.Event = function(type, props) { 1149 | if (!isString(type)) props = type, type = props.type 1150 | var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true 1151 | if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]) 1152 | event.initEvent(type, bubbles, true) 1153 | return compatible(event) 1154 | } 1155 | 1156 | })(Zepto) 1157 | 1158 | ;(function($){ 1159 | var jsonpID = 0, 1160 | document = window.document, 1161 | key, 1162 | name, 1163 | rscript = /)<[^<]*)*<\/script>/gi, 1164 | scriptTypeRE = /^(?:text|application)\/javascript/i, 1165 | xmlTypeRE = /^(?:text|application)\/xml/i, 1166 | jsonType = 'application/json', 1167 | htmlType = 'text/html', 1168 | blankRE = /^\s*$/, 1169 | originAnchor = document.createElement('a') 1170 | 1171 | originAnchor.href = window.location.href 1172 | 1173 | // trigger a custom event and return false if it was cancelled 1174 | function triggerAndReturn(context, eventName, data) { 1175 | var event = $.Event(eventName) 1176 | $(context).trigger(event, data) 1177 | return !event.isDefaultPrevented() 1178 | } 1179 | 1180 | // trigger an Ajax "global" event 1181 | function triggerGlobal(settings, context, eventName, data) { 1182 | if (settings.global) return triggerAndReturn(context || document, eventName, data) 1183 | } 1184 | 1185 | // Number of active Ajax requests 1186 | $.active = 0 1187 | 1188 | function ajaxStart(settings) { 1189 | if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart') 1190 | } 1191 | function ajaxStop(settings) { 1192 | if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop') 1193 | } 1194 | 1195 | // triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable 1196 | function ajaxBeforeSend(xhr, settings) { 1197 | var context = settings.context 1198 | if (settings.beforeSend.call(context, xhr, settings) === false || 1199 | triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false) 1200 | return false 1201 | 1202 | triggerGlobal(settings, context, 'ajaxSend', [xhr, settings]) 1203 | } 1204 | function ajaxSuccess(data, xhr, settings, deferred) { 1205 | var context = settings.context, status = 'success' 1206 | settings.success.call(context, data, status, xhr) 1207 | if (deferred) deferred.resolveWith(context, [data, status, xhr]) 1208 | triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data]) 1209 | ajaxComplete(status, xhr, settings) 1210 | } 1211 | // type: "timeout", "error", "abort", "parsererror" 1212 | function ajaxError(error, type, xhr, settings, deferred) { 1213 | var context = settings.context 1214 | settings.error.call(context, xhr, type, error) 1215 | if (deferred) deferred.rejectWith(context, [xhr, type, error]) 1216 | triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error || type]) 1217 | ajaxComplete(type, xhr, settings) 1218 | } 1219 | // status: "success", "notmodified", "error", "timeout", "abort", "parsererror" 1220 | function ajaxComplete(status, xhr, settings) { 1221 | var context = settings.context 1222 | settings.complete.call(context, xhr, status) 1223 | triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings]) 1224 | ajaxStop(settings) 1225 | } 1226 | 1227 | // Empty function, used as default callback 1228 | function empty() {} 1229 | 1230 | $.ajaxJSONP = function(options, deferred){ 1231 | if (!('type' in options)) return $.ajax(options) 1232 | 1233 | var _callbackName = options.jsonpCallback, 1234 | callbackName = ($.isFunction(_callbackName) ? 1235 | _callbackName() : _callbackName) || ('jsonp' + (++jsonpID)), 1236 | script = document.createElement('script'), 1237 | originalCallback = window[callbackName], 1238 | responseData, 1239 | abort = function(errorType) { 1240 | $(script).triggerHandler('error', errorType || 'abort') 1241 | }, 1242 | xhr = { abort: abort }, abortTimeout 1243 | 1244 | if (deferred) deferred.promise(xhr) 1245 | 1246 | $(script).on('load error', function(e, errorType){ 1247 | clearTimeout(abortTimeout) 1248 | $(script).off().remove() 1249 | 1250 | if (e.type == 'error' || !responseData) { 1251 | ajaxError(null, errorType || 'error', xhr, options, deferred) 1252 | } else { 1253 | ajaxSuccess(responseData[0], xhr, options, deferred) 1254 | } 1255 | 1256 | window[callbackName] = originalCallback 1257 | if (responseData && $.isFunction(originalCallback)) 1258 | originalCallback(responseData[0]) 1259 | 1260 | originalCallback = responseData = undefined 1261 | }) 1262 | 1263 | if (ajaxBeforeSend(xhr, options) === false) { 1264 | abort('abort') 1265 | return xhr 1266 | } 1267 | 1268 | window[callbackName] = function(){ 1269 | responseData = arguments 1270 | } 1271 | 1272 | script.src = options.url.replace(/\?(.+)=\?/, '?$1=' + callbackName) 1273 | document.head.appendChild(script) 1274 | 1275 | if (options.timeout > 0) abortTimeout = setTimeout(function(){ 1276 | abort('timeout') 1277 | }, options.timeout) 1278 | 1279 | return xhr 1280 | } 1281 | 1282 | $.ajaxSettings = { 1283 | // Default type of request 1284 | type: 'GET', 1285 | // Callback that is executed before request 1286 | beforeSend: empty, 1287 | // Callback that is executed if the request succeeds 1288 | success: empty, 1289 | // Callback that is executed the the server drops error 1290 | error: empty, 1291 | // Callback that is executed on request complete (both: error and success) 1292 | complete: empty, 1293 | // The context for the callbacks 1294 | context: null, 1295 | // Whether to trigger "global" Ajax events 1296 | global: true, 1297 | // Transport 1298 | xhr: function () { 1299 | return new window.XMLHttpRequest() 1300 | }, 1301 | // MIME types mapping 1302 | // IIS returns Javascript as "application/x-javascript" 1303 | accepts: { 1304 | script: 'text/javascript, application/javascript, application/x-javascript', 1305 | json: jsonType, 1306 | xml: 'application/xml, text/xml', 1307 | html: htmlType, 1308 | text: 'text/plain' 1309 | }, 1310 | // Whether the request is to another domain 1311 | crossDomain: false, 1312 | // Default timeout 1313 | timeout: 0, 1314 | // Whether data should be serialized to string 1315 | processData: true, 1316 | // Whether the browser should be allowed to cache GET responses 1317 | cache: true 1318 | } 1319 | 1320 | function mimeToDataType(mime) { 1321 | if (mime) mime = mime.split(';', 2)[0] 1322 | return mime && ( mime == htmlType ? 'html' : 1323 | mime == jsonType ? 'json' : 1324 | scriptTypeRE.test(mime) ? 'script' : 1325 | xmlTypeRE.test(mime) && 'xml' ) || 'text' 1326 | } 1327 | 1328 | function appendQuery(url, query) { 1329 | if (query == '') return url 1330 | return (url + '&' + query).replace(/[&?]{1,2}/, '?') 1331 | } 1332 | 1333 | // serialize payload and append it to the URL for GET requests 1334 | function serializeData(options) { 1335 | if (options.processData && options.data && $.type(options.data) != "string") 1336 | options.data = $.param(options.data, options.traditional) 1337 | if (options.data && (!options.type || options.type.toUpperCase() == 'GET')) 1338 | options.url = appendQuery(options.url, options.data), options.data = undefined 1339 | } 1340 | 1341 | $.ajax = function(options){ 1342 | var settings = $.extend({}, options || {}), 1343 | deferred = $.Deferred && $.Deferred(), 1344 | urlAnchor 1345 | for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key] 1346 | 1347 | ajaxStart(settings) 1348 | 1349 | if (!settings.crossDomain) { 1350 | urlAnchor = document.createElement('a') 1351 | urlAnchor.href = settings.url 1352 | urlAnchor.href = urlAnchor.href 1353 | settings.crossDomain = (originAnchor.protocol + '//' + originAnchor.host) !== (urlAnchor.protocol + '//' + urlAnchor.host) 1354 | } 1355 | 1356 | if (!settings.url) settings.url = window.location.toString() 1357 | serializeData(settings) 1358 | 1359 | var dataType = settings.dataType, hasPlaceholder = /\?.+=\?/.test(settings.url) 1360 | if (hasPlaceholder) dataType = 'jsonp' 1361 | 1362 | if (settings.cache === false || ( 1363 | (!options || options.cache !== true) && 1364 | ('script' == dataType || 'jsonp' == dataType) 1365 | )) 1366 | settings.url = appendQuery(settings.url, '_=' + Date.now()) 1367 | 1368 | if ('jsonp' == dataType) { 1369 | if (!hasPlaceholder) 1370 | settings.url = appendQuery(settings.url, 1371 | settings.jsonp ? (settings.jsonp + '=?') : settings.jsonp === false ? '' : 'callback=?') 1372 | return $.ajaxJSONP(settings, deferred) 1373 | } 1374 | 1375 | var mime = settings.accepts[dataType], 1376 | headers = { }, 1377 | setHeader = function(name, value) { headers[name.toLowerCase()] = [name, value] }, 1378 | protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol, 1379 | xhr = settings.xhr(), 1380 | nativeSetHeader = xhr.setRequestHeader, 1381 | abortTimeout 1382 | 1383 | if (deferred) deferred.promise(xhr) 1384 | 1385 | if (!settings.crossDomain) setHeader('X-Requested-With', 'XMLHttpRequest') 1386 | setHeader('Accept', mime || '*/*') 1387 | if (mime = settings.mimeType || mime) { 1388 | if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0] 1389 | xhr.overrideMimeType && xhr.overrideMimeType(mime) 1390 | } 1391 | if (settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() != 'GET')) 1392 | setHeader('Content-Type', settings.contentType || 'application/x-www-form-urlencoded') 1393 | 1394 | if (settings.headers) for (name in settings.headers) setHeader(name, settings.headers[name]) 1395 | xhr.setRequestHeader = setHeader 1396 | 1397 | xhr.onreadystatechange = function(){ 1398 | if (xhr.readyState == 4) { 1399 | xhr.onreadystatechange = empty 1400 | clearTimeout(abortTimeout) 1401 | var result, error = false 1402 | if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) { 1403 | dataType = dataType || mimeToDataType(settings.mimeType || xhr.getResponseHeader('content-type')) 1404 | result = xhr.responseText 1405 | 1406 | try { 1407 | // http://perfectionkills.com/global-eval-what-are-the-options/ 1408 | if (dataType == 'script') (1,eval)(result) 1409 | else if (dataType == 'xml') result = xhr.responseXML 1410 | else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result) 1411 | } catch (e) { error = e } 1412 | 1413 | if (error) ajaxError(error, 'parsererror', xhr, settings, deferred) 1414 | else ajaxSuccess(result, xhr, settings, deferred) 1415 | } else { 1416 | ajaxError(xhr.statusText || null, xhr.status ? 'error' : 'abort', xhr, settings, deferred) 1417 | } 1418 | } 1419 | } 1420 | 1421 | if (ajaxBeforeSend(xhr, settings) === false) { 1422 | xhr.abort() 1423 | ajaxError(null, 'abort', xhr, settings, deferred) 1424 | return xhr 1425 | } 1426 | 1427 | if (settings.xhrFields) for (name in settings.xhrFields) xhr[name] = settings.xhrFields[name] 1428 | 1429 | var async = 'async' in settings ? settings.async : true 1430 | xhr.open(settings.type, settings.url, async, settings.username, settings.password) 1431 | 1432 | for (name in headers) nativeSetHeader.apply(xhr, headers[name]) 1433 | 1434 | if (settings.timeout > 0) abortTimeout = setTimeout(function(){ 1435 | xhr.onreadystatechange = empty 1436 | xhr.abort() 1437 | ajaxError(null, 'timeout', xhr, settings, deferred) 1438 | }, settings.timeout) 1439 | 1440 | // avoid sending empty string (#319) 1441 | xhr.send(settings.data ? settings.data : null) 1442 | return xhr 1443 | } 1444 | 1445 | // handle optional data/success arguments 1446 | function parseArguments(url, data, success, dataType) { 1447 | if ($.isFunction(data)) dataType = success, success = data, data = undefined 1448 | if (!$.isFunction(success)) dataType = success, success = undefined 1449 | return { 1450 | url: url 1451 | , data: data 1452 | , success: success 1453 | , dataType: dataType 1454 | } 1455 | } 1456 | 1457 | $.get = function(/* url, data, success, dataType */){ 1458 | return $.ajax(parseArguments.apply(null, arguments)) 1459 | } 1460 | 1461 | $.post = function(/* url, data, success, dataType */){ 1462 | var options = parseArguments.apply(null, arguments) 1463 | options.type = 'POST' 1464 | return $.ajax(options) 1465 | } 1466 | 1467 | $.getJSON = function(/* url, data, success */){ 1468 | var options = parseArguments.apply(null, arguments) 1469 | options.dataType = 'json' 1470 | return $.ajax(options) 1471 | } 1472 | 1473 | $.fn.load = function(url, data, success){ 1474 | if (!this.length) return this 1475 | var self = this, parts = url.split(/\s/), selector, 1476 | options = parseArguments(url, data, success), 1477 | callback = options.success 1478 | if (parts.length > 1) options.url = parts[0], selector = parts[1] 1479 | options.success = function(response){ 1480 | self.html(selector ? 1481 | $('
').html(response.replace(rscript, "")).find(selector) 1482 | : response) 1483 | callback && callback.apply(self, arguments) 1484 | } 1485 | $.ajax(options) 1486 | return this 1487 | } 1488 | 1489 | var escape = encodeURIComponent 1490 | 1491 | function serialize(params, obj, traditional, scope){ 1492 | var type, array = $.isArray(obj), hash = $.isPlainObject(obj) 1493 | $.each(obj, function(key, value) { 1494 | type = $.type(value) 1495 | if (scope) key = traditional ? scope : 1496 | scope + '[' + (hash || type == 'object' || type == 'array' ? key : '') + ']' 1497 | // handle data in serializeArray() format 1498 | if (!scope && array) params.add(value.name, value.value) 1499 | // recurse into nested objects 1500 | else if (type == "array" || (!traditional && type == "object")) 1501 | serialize(params, value, traditional, key) 1502 | else params.add(key, value) 1503 | }) 1504 | } 1505 | 1506 | $.param = function(obj, traditional){ 1507 | var params = [] 1508 | params.add = function(key, value) { 1509 | if ($.isFunction(value)) value = value() 1510 | if (value == null) value = "" 1511 | this.push(escape(key) + '=' + escape(value)) 1512 | } 1513 | serialize(params, obj, traditional) 1514 | return params.join('&').replace(/%20/g, '+') 1515 | } 1516 | })(Zepto) 1517 | 1518 | ;(function($){ 1519 | $.fn.serializeArray = function() { 1520 | var name, type, result = [], 1521 | add = function(value) { 1522 | if (value.forEach) return value.forEach(add) 1523 | result.push({ name: name, value: value }) 1524 | } 1525 | if (this[0]) $.each(this[0].elements, function(_, field){ 1526 | type = field.type, name = field.name 1527 | if (name && field.nodeName.toLowerCase() != 'fieldset' && 1528 | !field.disabled && type != 'submit' && type != 'reset' && type != 'button' && type != 'file' && 1529 | ((type != 'radio' && type != 'checkbox') || field.checked)) 1530 | add($(field).val()) 1531 | }) 1532 | return result 1533 | } 1534 | 1535 | $.fn.serialize = function(){ 1536 | var result = [] 1537 | this.serializeArray().forEach(function(elm){ 1538 | result.push(encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value)) 1539 | }) 1540 | return result.join('&') 1541 | } 1542 | 1543 | $.fn.submit = function(callback) { 1544 | if (0 in arguments) this.bind('submit', callback) 1545 | else if (this.length) { 1546 | var event = $.Event('submit') 1547 | this.eq(0).trigger(event) 1548 | if (!event.isDefaultPrevented()) this.get(0).submit() 1549 | } 1550 | return this 1551 | } 1552 | 1553 | })(Zepto) 1554 | 1555 | ;(function($){ 1556 | // __proto__ doesn't exist on IE<11, so redefine 1557 | // the Z function to use object extension instead 1558 | if (!('__proto__' in {})) { 1559 | $.extend($.zepto, { 1560 | Z: function(dom, selector){ 1561 | dom = dom || [] 1562 | $.extend(dom, $.fn) 1563 | dom.selector = selector || '' 1564 | dom.__Z = true 1565 | return dom 1566 | }, 1567 | // this is a kludge but works 1568 | isZ: function(object){ 1569 | return $.type(object) === 'array' && '__Z' in object 1570 | } 1571 | }) 1572 | } 1573 | 1574 | // getComputedStyle shouldn't freak out when called 1575 | // without a valid element as argument 1576 | try { 1577 | getComputedStyle(undefined) 1578 | } catch(e) { 1579 | var nativeGetComputedStyle = getComputedStyle; 1580 | window.getComputedStyle = function(element){ 1581 | try { 1582 | return nativeGetComputedStyle(element) 1583 | } catch(e) { 1584 | return null 1585 | } 1586 | } 1587 | } 1588 | })(Zepto) 1589 | -------------------------------------------------------------------------------- /mframe/src/zepto/zepto.callback.js: -------------------------------------------------------------------------------- 1 | // Zepto.js 2 | // (c) 2010-2015 Thomas Fuchs 3 | // Zepto.js may be freely distributed under the MIT license. 4 | 5 | ;(function($){ 6 | // Create a collection of callbacks to be fired in a sequence, with configurable behaviour 7 | // Option flags: 8 | // - once: Callbacks fired at most one time. 9 | // - memory: Remember the most recent context and arguments 10 | // - stopOnFalse: Cease iterating over callback list 11 | // - unique: Permit adding at most one instance of the same callback 12 | $.Callbacks = function(options) { 13 | options = $.extend({}, options) 14 | 15 | var memory, // Last fire value (for non-forgettable lists) 16 | fired, // Flag to know if list was already fired 17 | firing, // Flag to know if list is currently firing 18 | firingStart, // First callback to fire (used internally by add and fireWith) 19 | firingLength, // End of the loop when firing 20 | firingIndex, // Index of currently firing callback (modified by remove if needed) 21 | list = [], // Actual callback list 22 | stack = !options.once && [], // Stack of fire calls for repeatable lists 23 | fire = function(data) { 24 | memory = options.memory && data 25 | fired = true 26 | firingIndex = firingStart || 0 27 | firingStart = 0 28 | firingLength = list.length 29 | firing = true 30 | for ( ; list && firingIndex < firingLength ; ++firingIndex ) { 31 | if (list[firingIndex].apply(data[0], data[1]) === false && options.stopOnFalse) { 32 | memory = false 33 | break 34 | } 35 | } 36 | firing = false 37 | if (list) { 38 | if (stack) stack.length && fire(stack.shift()) 39 | else if (memory) list.length = 0 40 | else Callbacks.disable() 41 | } 42 | }, 43 | 44 | Callbacks = { 45 | add: function() { 46 | if (list) { 47 | var start = list.length, 48 | add = function(args) { 49 | $.each(args, function(_, arg){ 50 | if (typeof arg === "function") { 51 | if (!options.unique || !Callbacks.has(arg)) list.push(arg) 52 | } 53 | else if (arg && arg.length && typeof arg !== 'string') add(arg) 54 | }) 55 | } 56 | add(arguments) 57 | if (firing) firingLength = list.length 58 | else if (memory) { 59 | firingStart = start 60 | fire(memory) 61 | } 62 | } 63 | return this 64 | }, 65 | remove: function() { 66 | if (list) { 67 | $.each(arguments, function(_, arg){ 68 | var index 69 | while ((index = $.inArray(arg, list, index)) > -1) { 70 | list.splice(index, 1) 71 | // Handle firing indexes 72 | if (firing) { 73 | if (index <= firingLength) --firingLength 74 | if (index <= firingIndex) --firingIndex 75 | } 76 | } 77 | }) 78 | } 79 | return this 80 | }, 81 | has: function(fn) { 82 | return !!(list && (fn ? $.inArray(fn, list) > -1 : list.length)) 83 | }, 84 | empty: function() { 85 | firingLength = list.length = 0 86 | return this 87 | }, 88 | disable: function() { 89 | list = stack = memory = undefined 90 | return this 91 | }, 92 | disabled: function() { 93 | return !list 94 | }, 95 | lock: function() { 96 | stack = undefined; 97 | if (!memory) Callbacks.disable() 98 | return this 99 | }, 100 | locked: function() { 101 | return !stack 102 | }, 103 | fireWith: function(context, args) { 104 | if (list && (!fired || stack)) { 105 | args = args || [] 106 | args = [context, args.slice ? args.slice() : args] 107 | if (firing) stack.push(args) 108 | else fire(args) 109 | } 110 | return this 111 | }, 112 | fire: function() { 113 | return Callbacks.fireWith(this, arguments) 114 | }, 115 | fired: function() { 116 | return !!fired 117 | } 118 | } 119 | 120 | return Callbacks 121 | } 122 | })(Zepto); -------------------------------------------------------------------------------- /mframe/src/zepto/zepto.deferred.js: -------------------------------------------------------------------------------- 1 | // Zepto.js 2 | // (c) 2010-2015 Thomas Fuchs 3 | // Zepto.js may be freely distributed under the MIT license. 4 | // 5 | // Some code (c) 2005, 2013 jQuery Foundation, Inc. and other contributors 6 | 7 | ;(function($){ 8 | var slice = Array.prototype.slice 9 | 10 | function Deferred(func) { 11 | var tuples = [ 12 | // action, add listener, listener list, final state 13 | [ "resolve", "done", $.Callbacks({once:1, memory:1}), "resolved" ], 14 | [ "reject", "fail", $.Callbacks({once:1, memory:1}), "rejected" ], 15 | [ "notify", "progress", $.Callbacks({memory:1}) ] 16 | ], 17 | state = "pending", 18 | promise = { 19 | state: function() { 20 | return state 21 | }, 22 | always: function() { 23 | deferred.done(arguments).fail(arguments) 24 | return this 25 | }, 26 | then: function(/* fnDone [, fnFailed [, fnProgress]] */) { 27 | var fns = arguments 28 | return Deferred(function(defer){ 29 | $.each(tuples, function(i, tuple){ 30 | var fn = $.isFunction(fns[i]) && fns[i] 31 | deferred[tuple[1]](function(){ 32 | var returned = fn && fn.apply(this, arguments) 33 | if (returned && $.isFunction(returned.promise)) { 34 | returned.promise() 35 | .done(defer.resolve) 36 | .fail(defer.reject) 37 | .progress(defer.notify) 38 | } else { 39 | var context = this === promise ? defer.promise() : this, 40 | values = fn ? [returned] : arguments 41 | defer[tuple[0] + "With"](context, values) 42 | } 43 | }) 44 | }) 45 | fns = null 46 | }).promise() 47 | }, 48 | 49 | promise: function(obj) { 50 | return obj != null ? $.extend( obj, promise ) : promise 51 | } 52 | }, 53 | deferred = {} 54 | 55 | $.each(tuples, function(i, tuple){ 56 | var list = tuple[2], 57 | stateString = tuple[3] 58 | 59 | promise[tuple[1]] = list.add 60 | 61 | if (stateString) { 62 | list.add(function(){ 63 | state = stateString 64 | }, tuples[i^1][2].disable, tuples[2][2].lock) 65 | } 66 | 67 | deferred[tuple[0]] = function(){ 68 | deferred[tuple[0] + "With"](this === deferred ? promise : this, arguments) 69 | return this 70 | } 71 | deferred[tuple[0] + "With"] = list.fireWith 72 | }) 73 | 74 | promise.promise(deferred) 75 | if (func) func.call(deferred, deferred) 76 | return deferred 77 | } 78 | 79 | $.when = function(sub) { 80 | var resolveValues = slice.call(arguments), 81 | len = resolveValues.length, 82 | i = 0, 83 | remain = len !== 1 || (sub && $.isFunction(sub.promise)) ? len : 0, 84 | deferred = remain === 1 ? sub : Deferred(), 85 | progressValues, progressContexts, resolveContexts, 86 | updateFn = function(i, ctx, val){ 87 | return function(value){ 88 | ctx[i] = this 89 | val[i] = arguments.length > 1 ? slice.call(arguments) : value 90 | if (val === progressValues) { 91 | deferred.notifyWith(ctx, val) 92 | } else if (!(--remain)) { 93 | deferred.resolveWith(ctx, val) 94 | } 95 | } 96 | } 97 | 98 | if (len > 1) { 99 | progressValues = new Array(len) 100 | progressContexts = new Array(len) 101 | resolveContexts = new Array(len) 102 | for ( ; i < len; ++i ) { 103 | if (resolveValues[i] && $.isFunction(resolveValues[i].promise)) { 104 | resolveValues[i].promise() 105 | .done(updateFn(i, resolveContexts, resolveValues)) 106 | .fail(deferred.reject) 107 | .progress(updateFn(i, progressContexts, progressValues)) 108 | } else { 109 | --remain 110 | } 111 | } 112 | } 113 | if (!remain) deferred.resolveWith(resolveContexts, resolveValues) 114 | return deferred.promise() 115 | } 116 | 117 | $.Deferred = Deferred 118 | })(Zepto) --------------------------------------------------------------------------------