├── README.md ├── demo ├── dialog.html ├── prompt.html └── toaste.html ├── gulpfile.js ├── js ├── animate-rippler.js ├── animate.js ├── effects.js └── refresh.js ├── lib ├── ajax.js ├── data.js ├── event.js ├── os.js ├── raf.js ├── touch.js └── zepto.js ├── package.json └── styles └── prompt.css /README.md: -------------------------------------------------------------------------------- 1 | MaterialUI 2 | ========== 3 | 4 | Google Material Design UI. 5 | 6 | Depend on Zepto.js. 7 | 8 | Make your webapp more like native app. 9 | 10 | Mobile Only! 11 | 12 | Lightweight! 13 | 14 | High Performance! 15 | 16 | ## Some Implementation 17 | 18 | * [material-refresh](https://github.com/lightningtgc/material-refresh) 19 | -------------------------------------------------------------------------------- /demo/dialog.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningtgc/MaterialUI/00141d8eb4f3ac9afe5c124b6d4b0809348e779f/demo/dialog.html -------------------------------------------------------------------------------- /demo/prompt.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningtgc/MaterialUI/00141d8eb4f3ac9afe5c124b6d4b0809348e779f/demo/prompt.html -------------------------------------------------------------------------------- /demo/toaste.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningtgc/MaterialUI/00141d8eb4f3ac9afe5c124b6d4b0809348e779f/demo/toaste.html -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var browserify = require('browserify'); 2 | var gulp = require('gulp'); 3 | var source = require('vinyl-source-stream'); 4 | 5 | gulp.task('browserify', function() { 6 | return browserify('./src/javascript/app.js').bundle() 7 | // vinyl-source-stream makes the bundle compatible with gulp 8 | .pipe(source('bundle.js')) // Desired filename 9 | // Output the file 10 | .pipe(gulp.dest('./build/')); 11 | }); 12 | 13 | -------------------------------------------------------------------------------- /js/animate-rippler.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningtgc/MaterialUI/00141d8eb4f3ac9afe5c124b6d4b0809348e779f/js/animate-rippler.js -------------------------------------------------------------------------------- /js/animate.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | var $ripple = require("./animate-rippler.js"); 3 | var $raf = require("../lib/raf.js"); 4 | 5 | function MaterialEffects($ripple, $raf){ 6 | 7 | return { 8 | inkRipple: animateInkRipple 9 | }; 10 | 11 | /** 12 | * Use the canvas animator to render the ripple effect(s). 13 | */ 14 | function animateInkRipple (canvas, options) { 15 | return new $ripple(canvas, options); 16 | } 17 | 18 | }; 19 | 20 | function MaterialRippleDirective(){ 21 | return { 22 | compile: compileWithCanvas 23 | }; 24 | /** 25 | * Use Javascript and Canvas to render ripple effects 26 | * 27 | * Note: attribute start="" has two (2) options: `center` || `pointer`; which 28 | * defines the start of the ripple center. 29 | * 30 | * @param element 31 | * @returns {Function} 32 | */ 33 | function compileWithCanvas( element, attrs ) { 34 | var RIGHT_BUTTON = 2; 35 | var options = calculateOptions(element, attrs); 36 | var tag = 37 | '' + 40 | ''; 41 | 42 | element.replaceWith( 43 | angular.element( $interpolate(tag)(options) ) 44 | ); 45 | 46 | return function linkCanvas( scope, element ){ 47 | 48 | var ripple, watchMouse, 49 | parent = element.parent(), 50 | makeRipple = $throttle({ 51 | start : function() { 52 | ripple = ripple || MaterialEffects.inkRipple( element[0], options ); 53 | watchMouse = watchMouse || buildMouseWatcher(parent, makeRipple); 54 | 55 | // Ripples start with left mouseDowns (or taps) 56 | parent.on('mousedown', makeRipple); 57 | }, 58 | throttle : function(e, done) { 59 | if ( effectAllowed() ) 60 | { 61 | switch(e.type) 62 | { 63 | case 'mousedown' : 64 | // If not right- or ctrl-click... 65 | if (!e.ctrlKey && (e.button !== RIGHT_BUTTON)) 66 | { 67 | watchMouse(true); 68 | ripple.createAt( options.forceToCenter ? null : localToCanvas(e) ); 69 | } 70 | break; 71 | 72 | default: 73 | watchMouse(false); 74 | 75 | // Draw of each wave/ripple in the ink only occurs 76 | // on mouseup/mouseleave 77 | 78 | ripple.draw( done ); 79 | break; 80 | } 81 | } else { 82 | done(); 83 | } 84 | }, 85 | end : function() { 86 | watchMouse(false); 87 | } 88 | })(); 89 | 90 | 91 | 92 | }; 93 | 94 | }); 95 | -------------------------------------------------------------------------------- /js/effects.js: -------------------------------------------------------------------------------- 1 | angular.module('material.animations', ['ngAnimateStylers', 'ngAnimateSequence', 'ngAnimate', 'material.services']) 2 | .service('materialEffects', [ '$animateSequence', '$ripple', '$rootElement', '$position', '$$rAF', MaterialEffects]) 3 | .directive('materialRipple', ['materialEffects', '$interpolate', '$throttle', MaterialRippleDirective]); 4 | 5 | /** 6 | * This service provides animation features for various Material Design effects: 7 | * 8 | * 1) ink stretchBars, 9 | * 2) ink ripples, 10 | * 3) popIn animations 11 | * 4) popOuts animations 12 | * 13 | * @constructor 14 | */ 15 | function MaterialEffects($animateSequence, $ripple, $rootElement, $position, $$rAF) { 16 | 17 | var styler = angular.isDefined( $rootElement[0].animate ) ? 'webAnimations' : 18 | angular.isDefined( window['TweenMax'] || window['TweenLite'] ) ? 'gsap' : 19 | angular.isDefined( window['jQuery'] ) ? 'jQuery' : 'default'; 20 | 21 | // Publish API for effects... 22 | 23 | return { 24 | inkRipple: animateInkRipple, 25 | inkBar: animateInkBar, 26 | popIn: popIn, 27 | popOut: popOut 28 | }; 29 | 30 | // ********************************************************** 31 | // API Methods 32 | // ********************************************************** 33 | 34 | /** 35 | * Use the canvas animator to render the ripple effect(s). 36 | */ 37 | function animateInkRipple( canvas, options ) 38 | { 39 | return new $ripple(canvas, options); 40 | } 41 | 42 | 43 | /** 44 | * Make instance of a reusable sequence and 45 | * auto-run the sequence on the element (if defined) 46 | */ 47 | function animateInkBar(element, styles, duration ) { 48 | var animate = $animateSequence({ styler: styler }).animate, 49 | sequence = animate( {}, styles, safeDuration(duration || 350) ); 50 | 51 | return angular.isDefined(element) ? sequence.run(element) : sequence; 52 | } 53 | 54 | 55 | /** 56 | * 57 | */ 58 | function popIn(element, parentElement, clickElement) { 59 | var startPos; 60 | var endPos = $position.positionElements(parentElement, element, 'center'); 61 | if (clickElement) { 62 | var dialogPos = $position.position(element); 63 | var clickPos = $position.offset(clickElement); 64 | startPos = { 65 | left: clickPos.left - dialogPos.width / 2, 66 | top: clickPos.top - dialogPos.height / 2 67 | }; 68 | } else { 69 | startPos = endPos; 70 | } 71 | 72 | // TODO once ngAnimateSequence bugs are fixed, this can be switched to use that 73 | element.css({ 74 | '-webkit-transform': translateString(startPos.left, startPos.top, 0) + ' scale(0.2)', 75 | opacity: 0 76 | }); 77 | $$rAF(function() { 78 | element.addClass('dialog-changing'); 79 | $$rAF(function() { 80 | element.css({ 81 | '-webkit-transform': translateString(endPos.left, endPos.top, 0) + ' scale(1.0)', 82 | opacity: 1 83 | }); 84 | }); 85 | }); 86 | } 87 | 88 | /** 89 | * 90 | * 91 | */ 92 | function popOut(element, parentElement) { 93 | var endPos = $position.positionElements(parentElement, element, 'bottom-center'); 94 | 95 | endPos.top -= element.prop('offsetHeight') / 2; 96 | 97 | var runner = $animateSequence({ styler: styler }) 98 | .addClass('dialog-changing') 99 | .then(function() { 100 | element.css({ 101 | '-webkit-transform': translateString(endPos.left, endPos.top, 0) + ' scale(0.5)', 102 | opacity: 0 103 | }); 104 | }); 105 | 106 | return runner.run(element); 107 | } 108 | 109 | 110 | // ********************************************************** 111 | // Utility Methods 112 | // ********************************************************** 113 | 114 | 115 | function translateString(x, y, z) { 116 | return 'translate3d(' + x + 'px,' + y + 'px,' + z + 'px)'; 117 | } 118 | 119 | 120 | /** 121 | * Support values such as 0.65 secs or 650 msecs 122 | */ 123 | function safeDuration(value) { 124 | var duration = isNaN(value) ? 0 : Number(value); 125 | return (duration < 1.0) ? (duration * 1000) : duration; 126 | } 127 | 128 | /** 129 | * Convert all values to decimal; 130 | * eg 150 msecs -> 0.15sec 131 | */ 132 | function safeVelocity(value) { 133 | var duration = isNaN(value) ? 0 : Number(value); 134 | return (duration > 100) ? (duration / 1000) : 135 | (duration > 10 ) ? (duration / 100) : 136 | (duration > 1 ) ? (duration / 10) : duration; 137 | } 138 | 139 | } 140 | 141 | /** 142 | * Directive 143 | */ 144 | function MaterialRippleDirective(materialEffects, $interpolate, $throttle) { 145 | return { 146 | restrict: 'E', 147 | compile: compileWithCanvas 148 | }; 149 | 150 | /** 151 | * Use Javascript and Canvas to render ripple effects 152 | * 153 | * Note: attribute start="" has two (2) options: `center` || `pointer`; which 154 | * defines the start of the ripple center. 155 | * 156 | * @param element 157 | * @returns {Function} 158 | */ 159 | function compileWithCanvas( element, attrs ) { 160 | var RIGHT_BUTTON = 2; 161 | var options = calculateOptions(element, attrs); 162 | var tag = 163 | '' + 166 | ''; 167 | 168 | element.replaceWith( 169 | angular.element( $interpolate(tag)(options) ) 170 | ); 171 | 172 | return function linkCanvas( scope, element ){ 173 | 174 | var ripple, watchMouse, 175 | parent = element.parent(), 176 | makeRipple = $throttle({ 177 | start : function() { 178 | ripple = ripple || materialEffects.inkRipple( element[0], options ); 179 | watchMouse = watchMouse || buildMouseWatcher(parent, makeRipple); 180 | 181 | // Ripples start with left mouseDowns (or taps) 182 | parent.on('mousedown', makeRipple); 183 | }, 184 | throttle : function(e, done) { 185 | if ( effectAllowed() ) 186 | { 187 | switch(e.type) 188 | { 189 | case 'mousedown' : 190 | // If not right- or ctrl-click... 191 | if (!e.ctrlKey && (e.button !== RIGHT_BUTTON)) 192 | { 193 | watchMouse(true); 194 | ripple.createAt( options.forceToCenter ? null : localToCanvas(e) ); 195 | } 196 | break; 197 | 198 | default: 199 | watchMouse(false); 200 | 201 | // Draw of each wave/ripple in the ink only occurs 202 | // on mouseup/mouseleave 203 | 204 | ripple.draw( done ); 205 | break; 206 | } 207 | } else { 208 | done(); 209 | } 210 | }, 211 | end : function() { 212 | watchMouse(false); 213 | } 214 | })(); 215 | 216 | 217 | // ********************************************************** 218 | // Utility Methods 219 | // ********************************************************** 220 | 221 | /** 222 | * If the ripple canvas been removed from the DOM, then 223 | * remove the `mousedown` listener 224 | * 225 | * @returns {*|boolean} 226 | */ 227 | function effectAllowed() { 228 | var allowed = isInkEnabled( element.scope() ) && angular.isDefined( element.parent()[0] ); 229 | if ( !allowed ) { 230 | parent.off('mousedown', makeRipple); 231 | } 232 | return allowed; 233 | 234 | 235 | /** 236 | * Check scope chain for `inkEnabled` or `disabled` flags... 237 | */ 238 | function isInkEnabled(scope) { 239 | return angular.isUndefined(scope) ? true : 240 | angular.isDefined(scope.disabled) ? !scope.disabled : 241 | angular.isDefined(scope.inkEnabled) ? scope.inkEnabled : true; 242 | } 243 | 244 | } 245 | 246 | /** 247 | * Build mouse event listeners for the specified element 248 | * @param element Angular element that will listen for bubbling mouseEvents 249 | * @param handlerFn Function to be invoked with the mouse event 250 | * @returns {Function} 251 | */ 252 | function buildMouseWatcher(element, handlerFn) { 253 | // Return function to easily toggle on/off listeners 254 | return function watchMouse(active) { 255 | angular.forEach("mouseup,mouseleave".split(","), function(eventType) { 256 | var fn = active ? element.on : element.off; 257 | fn.apply(element, [eventType, handlerFn]); 258 | }); 259 | } 260 | } 261 | /** 262 | * Convert the mouse down coordinates from `parent` relative 263 | * to `canvas` relative; needed since the event listener is on 264 | * the parent [e.g. tab element] 265 | */ 266 | function localToCanvas(e) 267 | { 268 | var canvas = element[0].getBoundingClientRect(); 269 | 270 | return { 271 | x : e.clientX - canvas.left, 272 | y : e.clientY - canvas.top 273 | }; 274 | } 275 | 276 | } 277 | 278 | function calculateOptions(element, attrs) 279 | { 280 | return angular.extend( getBounds(element), { 281 | classList : (attrs.class || ""), 282 | forceToCenter : (attrs.start == "center"), 283 | initialOpacity : getFloatValue( attrs, "initialOpacity" ), 284 | opacityDecayVelocity : getFloatValue( attrs, "opacityDecayVelocity" ) 285 | }); 286 | 287 | function getBounds(element) { 288 | var node = element[0]; 289 | var styles = node.ownerDocument.defaultView.getComputedStyle( node, null ) || { }; 290 | 291 | return { 292 | left : (styles.left == "auto" || !styles.left) ? "0px" : styles.left, 293 | top : (styles.top == "auto" || !styles.top) ? "0px" : styles.top, 294 | width : getValue( styles, "width" ), 295 | height : getValue( styles, "height" ) 296 | }; 297 | } 298 | 299 | function getFloatValue( map, key, defaultVal ) 300 | { 301 | return angular.isDefined( map[key] ) ? +map[key] : defaultVal; 302 | } 303 | 304 | function getValue( map, key, defaultVal ) 305 | { 306 | var val = map[key]; 307 | return (angular.isDefined( val ) && (val !== "")) ? map[key] : defaultVal; 308 | } 309 | } 310 | 311 | } 312 | 313 | 314 | 315 | } 316 | -------------------------------------------------------------------------------- /js/refresh.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/ajax.js: -------------------------------------------------------------------------------- 1 | define(['./zepto'], function(){ 2 | // Zepto.js 3 | // (c) 2010-2014 Thomas Fuchs 4 | // Zepto.js may be freely distributed under the MIT license. 5 | 6 | ;(function($){ 7 | var jsonpID = 0, 8 | document = window.document, 9 | key, 10 | name, 11 | rscript = /)<[^<]*)*<\/script>/gi, 12 | scriptTypeRE = /^(?:text|application)\/javascript/i, 13 | xmlTypeRE = /^(?:text|application)\/xml/i, 14 | jsonType = 'application/json', 15 | htmlType = 'text/html', 16 | blankRE = /^\s*$/ 17 | 18 | // trigger a custom event and return false if it was cancelled 19 | function triggerAndReturn(context, eventName, data) { 20 | var event = $.Event(eventName) 21 | $(context).trigger(event, data) 22 | return !event.isDefaultPrevented() 23 | } 24 | 25 | // trigger an Ajax "global" event 26 | function triggerGlobal(settings, context, eventName, data) { 27 | if (settings.global) return triggerAndReturn(context || document, eventName, data) 28 | } 29 | 30 | // Number of active Ajax requests 31 | $.active = 0 32 | 33 | function ajaxStart(settings) { 34 | if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart') 35 | } 36 | function ajaxStop(settings) { 37 | if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop') 38 | } 39 | 40 | // triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable 41 | function ajaxBeforeSend(xhr, settings) { 42 | var context = settings.context 43 | if (settings.beforeSend.call(context, xhr, settings) === false || 44 | triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false) 45 | return false 46 | 47 | triggerGlobal(settings, context, 'ajaxSend', [xhr, settings]) 48 | } 49 | function ajaxSuccess(data, xhr, settings, deferred) { 50 | var context = settings.context, status = 'success' 51 | settings.success.call(context, data, status, xhr) 52 | if (deferred) deferred.resolveWith(context, [data, status, xhr]) 53 | triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data]) 54 | ajaxComplete(status, xhr, settings) 55 | } 56 | // type: "timeout", "error", "abort", "parsererror" 57 | function ajaxError(error, type, xhr, settings, deferred) { 58 | var context = settings.context 59 | settings.error.call(context, xhr, type, error) 60 | if (deferred) deferred.rejectWith(context, [xhr, type, error]) 61 | triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error || type]) 62 | ajaxComplete(type, xhr, settings) 63 | } 64 | // status: "success", "notmodified", "error", "timeout", "abort", "parsererror" 65 | function ajaxComplete(status, xhr, settings) { 66 | var context = settings.context 67 | settings.complete.call(context, xhr, status) 68 | triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings]) 69 | ajaxStop(settings) 70 | } 71 | 72 | // Empty function, used as default callback 73 | function empty() {} 74 | 75 | $.ajaxJSONP = function(options, deferred){ 76 | if (!('type' in options)) return $.ajax(options) 77 | 78 | var _callbackName = options.jsonpCallback, 79 | callbackName = ($.isFunction(_callbackName) ? 80 | _callbackName() : _callbackName) || ('jsonp' + (++jsonpID)), 81 | script = document.createElement('script'), 82 | originalCallback = window[callbackName], 83 | responseData, 84 | abort = function(errorType) { 85 | $(script).triggerHandler('error', errorType || 'abort') 86 | }, 87 | xhr = { abort: abort }, abortTimeout 88 | 89 | if (deferred) deferred.promise(xhr) 90 | 91 | $(script).on('load error', function(e, errorType){ 92 | clearTimeout(abortTimeout) 93 | $(script).off().remove() 94 | 95 | if (e.type == 'error' || !responseData) { 96 | ajaxError(null, errorType || 'error', xhr, options, deferred) 97 | } else { 98 | ajaxSuccess(responseData[0], xhr, options, deferred) 99 | } 100 | 101 | window[callbackName] = originalCallback 102 | if (responseData && $.isFunction(originalCallback)) 103 | originalCallback(responseData[0]) 104 | 105 | originalCallback = responseData = undefined 106 | }) 107 | 108 | if (ajaxBeforeSend(xhr, options) === false) { 109 | abort('abort') 110 | return xhr 111 | } 112 | 113 | window[callbackName] = function(){ 114 | responseData = arguments 115 | } 116 | 117 | script.src = options.url.replace(/\?(.+)=\?/, '?$1=' + callbackName) 118 | document.head.appendChild(script) 119 | 120 | if (options.timeout > 0) abortTimeout = setTimeout(function(){ 121 | abort('timeout') 122 | }, options.timeout) 123 | 124 | return xhr 125 | } 126 | 127 | $.ajaxSettings = { 128 | // Default type of request 129 | type: 'GET', 130 | // Callback that is executed before request 131 | beforeSend: empty, 132 | // Callback that is executed if the request succeeds 133 | success: empty, 134 | // Callback that is executed the the server drops error 135 | error: empty, 136 | // Callback that is executed on request complete (both: error and success) 137 | complete: empty, 138 | // The context for the callbacks 139 | context: null, 140 | // Whether to trigger "global" Ajax events 141 | global: true, 142 | // Transport 143 | xhr: function () { 144 | return new window.XMLHttpRequest() 145 | }, 146 | // MIME types mapping 147 | // IIS returns Javascript as "application/x-javascript" 148 | accepts: { 149 | script: 'text/javascript, application/javascript, application/x-javascript', 150 | json: jsonType, 151 | xml: 'application/xml, text/xml', 152 | html: htmlType, 153 | text: 'text/plain' 154 | }, 155 | // Whether the request is to another domain 156 | crossDomain: false, 157 | // Default timeout 158 | timeout: 0, 159 | // Whether data should be serialized to string 160 | processData: true, 161 | // Whether the browser should be allowed to cache GET responses 162 | cache: true 163 | } 164 | 165 | function mimeToDataType(mime) { 166 | if (mime) mime = mime.split(';', 2)[0] 167 | return mime && ( mime == htmlType ? 'html' : 168 | mime == jsonType ? 'json' : 169 | scriptTypeRE.test(mime) ? 'script' : 170 | xmlTypeRE.test(mime) && 'xml' ) || 'text' 171 | } 172 | 173 | function appendQuery(url, query) { 174 | if (query == '') return url 175 | return (url + '&' + query).replace(/[&?]{1,2}/, '?') 176 | } 177 | 178 | // serialize payload and append it to the URL for GET requests 179 | function serializeData(options) { 180 | if (options.processData && options.data && $.type(options.data) != "string") 181 | options.data = $.param(options.data, options.traditional) 182 | if (options.data && (!options.type || options.type.toUpperCase() == 'GET')) 183 | options.url = appendQuery(options.url, options.data), options.data = undefined 184 | } 185 | 186 | $.ajax = function(options){ 187 | var settings = $.extend({}, options || {}), 188 | deferred = $.Deferred && $.Deferred() 189 | for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key] 190 | 191 | ajaxStart(settings) 192 | 193 | if (!settings.crossDomain) settings.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(settings.url) && 194 | RegExp.$2 != window.location.host 195 | 196 | if (!settings.url) settings.url = window.location.toString() 197 | serializeData(settings) 198 | if (settings.cache === false) settings.url = appendQuery(settings.url, '_=' + Date.now()) 199 | 200 | var dataType = settings.dataType, hasPlaceholder = /\?.+=\?/.test(settings.url) 201 | if (dataType == 'jsonp' || hasPlaceholder) { 202 | if (!hasPlaceholder) 203 | settings.url = appendQuery(settings.url, 204 | settings.jsonp ? (settings.jsonp + '=?') : settings.jsonp === false ? '' : 'callback=?') 205 | return $.ajaxJSONP(settings, deferred) 206 | } 207 | 208 | var mime = settings.accepts[dataType], 209 | headers = { }, 210 | setHeader = function(name, value) { headers[name.toLowerCase()] = [name, value] }, 211 | protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol, 212 | xhr = settings.xhr(), 213 | nativeSetHeader = xhr.setRequestHeader, 214 | abortTimeout 215 | 216 | if (deferred) deferred.promise(xhr) 217 | 218 | if (!settings.crossDomain) setHeader('X-Requested-With', 'XMLHttpRequest') 219 | setHeader('Accept', mime || '*/*') 220 | if (mime = settings.mimeType || mime) { 221 | if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0] 222 | xhr.overrideMimeType && xhr.overrideMimeType(mime) 223 | } 224 | if (settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() != 'GET')) 225 | setHeader('Content-Type', settings.contentType || 'application/x-www-form-urlencoded') 226 | 227 | if (settings.headers) for (name in settings.headers) setHeader(name, settings.headers[name]) 228 | xhr.setRequestHeader = setHeader 229 | 230 | xhr.onreadystatechange = function(){ 231 | if (xhr.readyState == 4) { 232 | xhr.onreadystatechange = empty 233 | clearTimeout(abortTimeout) 234 | var result, error = false 235 | if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) { 236 | dataType = dataType || mimeToDataType(settings.mimeType || xhr.getResponseHeader('content-type')) 237 | result = xhr.responseText 238 | 239 | try { 240 | // http://perfectionkills.com/global-eval-what-are-the-options/ 241 | if (dataType == 'script') (1,eval)(result) 242 | else if (dataType == 'xml') result = xhr.responseXML 243 | else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result) 244 | } catch (e) { error = e } 245 | 246 | if (error) ajaxError(error, 'parsererror', xhr, settings, deferred) 247 | else ajaxSuccess(result, xhr, settings, deferred) 248 | } else { 249 | ajaxError(xhr.statusText || null, xhr.status ? 'error' : 'abort', xhr, settings, deferred) 250 | } 251 | } 252 | } 253 | 254 | if (ajaxBeforeSend(xhr, settings) === false) { 255 | xhr.abort() 256 | ajaxError(null, 'abort', xhr, settings, deferred) 257 | return xhr 258 | } 259 | 260 | if (settings.xhrFields) for (name in settings.xhrFields) xhr[name] = settings.xhrFields[name] 261 | 262 | var async = 'async' in settings ? settings.async : true 263 | xhr.open(settings.type, settings.url, async, settings.username, settings.password) 264 | 265 | for (name in headers) nativeSetHeader.apply(xhr, headers[name]) 266 | 267 | if (settings.timeout > 0) abortTimeout = setTimeout(function(){ 268 | xhr.onreadystatechange = empty 269 | xhr.abort() 270 | ajaxError(null, 'timeout', xhr, settings, deferred) 271 | }, settings.timeout) 272 | 273 | // avoid sending empty string (#319) 274 | xhr.send(settings.data ? settings.data : null) 275 | return xhr 276 | } 277 | 278 | // handle optional data/success arguments 279 | function parseArguments(url, data, success, dataType) { 280 | if ($.isFunction(data)) dataType = success, success = data, data = undefined 281 | if (!$.isFunction(success)) dataType = success, success = undefined 282 | return { 283 | url: url 284 | , data: data 285 | , success: success 286 | , dataType: dataType 287 | } 288 | } 289 | 290 | $.get = function(/* url, data, success, dataType */){ 291 | return $.ajax(parseArguments.apply(null, arguments)) 292 | } 293 | 294 | $.post = function(/* url, data, success, dataType */){ 295 | var options = parseArguments.apply(null, arguments) 296 | options.type = 'POST' 297 | return $.ajax(options) 298 | } 299 | 300 | $.getJSON = function(/* url, data, success */){ 301 | var options = parseArguments.apply(null, arguments) 302 | options.dataType = 'json' 303 | return $.ajax(options) 304 | } 305 | 306 | $.fn.load = function(url, data, success){ 307 | if (!this.length) return this 308 | var self = this, parts = url.split(/\s/), selector, 309 | options = parseArguments(url, data, success), 310 | callback = options.success 311 | if (parts.length > 1) options.url = parts[0], selector = parts[1] 312 | options.success = function(response){ 313 | self.html(selector ? 314 | $('
').html(response.replace(rscript, "")).find(selector) 315 | : response) 316 | callback && callback.apply(self, arguments) 317 | } 318 | $.ajax(options) 319 | return this 320 | } 321 | 322 | var escape = encodeURIComponent 323 | 324 | function serialize(params, obj, traditional, scope){ 325 | var type, array = $.isArray(obj), hash = $.isPlainObject(obj) 326 | $.each(obj, function(key, value) { 327 | type = $.type(value) 328 | if (scope) key = traditional ? scope : 329 | scope + '[' + (hash || type == 'object' || type == 'array' ? key : '') + ']' 330 | // handle data in serializeArray() format 331 | if (!scope && array) params.add(value.name, value.value) 332 | // recurse into nested objects 333 | else if (type == "array" || (!traditional && type == "object")) 334 | serialize(params, value, traditional, key) 335 | else params.add(key, value) 336 | }) 337 | } 338 | 339 | $.param = function(obj, traditional){ 340 | var params = [] 341 | params.add = function(k, v){ this.push(escape(k) + '=' + escape(v)) } 342 | serialize(params, obj, traditional) 343 | return params.join('&').replace(/%20/g, '+') 344 | } 345 | })(Zepto) 346 | 347 | }); 348 | -------------------------------------------------------------------------------- /lib/data.js: -------------------------------------------------------------------------------- 1 | define(['./zepto'], function(){ 2 | // Zepto.js 3 | // (c) 2010-2014 Thomas Fuchs 4 | // Zepto.js may be freely distributed under the MIT license. 5 | 6 | // The following code is heavily inspired by jQuery's $.fn.data() 7 | 8 | ;(function($){ 9 | var data = {}, dataAttr = $.fn.data, camelize = $.camelCase, 10 | exp = $.expando = 'Zepto' + (+new Date()), emptyArray = [] 11 | 12 | // Get value from node: 13 | // 1. first try key as given, 14 | // 2. then try camelized key, 15 | // 3. fall back to reading "data-*" attribute. 16 | function getData(node, name) { 17 | var id = node[exp], store = id && data[id] 18 | if (name === undefined) return store || setData(node) 19 | else { 20 | if (store) { 21 | if (name in store) return store[name] 22 | var camelName = camelize(name) 23 | if (camelName in store) return store[camelName] 24 | } 25 | return dataAttr.call($(node), name) 26 | } 27 | } 28 | 29 | // Store value under camelized key on node 30 | function setData(node, name, value) { 31 | var id = node[exp] || (node[exp] = ++$.uuid), 32 | store = data[id] || (data[id] = attributeData(node)) 33 | if (name !== undefined) store[camelize(name)] = value 34 | return store 35 | } 36 | 37 | // Read all "data-*" attributes from a node 38 | function attributeData(node) { 39 | var store = {} 40 | $.each(node.attributes || emptyArray, function(i, attr){ 41 | if (attr.name.indexOf('data-') == 0) 42 | store[camelize(attr.name.replace('data-', ''))] = 43 | $.zepto.deserializeValue(attr.value) 44 | }) 45 | return store 46 | } 47 | 48 | $.fn.data = function(name, value) { 49 | return value === undefined ? 50 | // set multiple values via object 51 | $.isPlainObject(name) ? 52 | this.each(function(i, node){ 53 | $.each(name, function(key, value){ setData(node, key, value) }) 54 | }) : 55 | // get value from first element 56 | this.length == 0 ? undefined : getData(this[0], name) : 57 | // set value on all elements 58 | this.each(function(){ setData(this, name, value) }) 59 | } 60 | 61 | $.fn.removeData = function(names) { 62 | if (typeof names == 'string') names = names.split(/\s+/) 63 | return this.each(function(){ 64 | var id = this[exp], store = id && data[id] 65 | if (store) $.each(names || store, function(key){ 66 | delete store[names ? camelize(this) : key] 67 | }) 68 | }) 69 | } 70 | 71 | // Generate extended `remove` and `empty` functions 72 | ;['remove', 'empty'].forEach(function(methodName){ 73 | var origFn = $.fn[methodName] 74 | $.fn[methodName] = function() { 75 | var elements = this.find('*') 76 | if (methodName === 'remove') elements = elements.add(this) 77 | elements.removeData() 78 | return origFn.call(this) 79 | } 80 | }) 81 | })(Zepto) 82 | 83 | }); 84 | -------------------------------------------------------------------------------- /lib/event.js: -------------------------------------------------------------------------------- 1 | define(['./zepto'], function(){ 2 | // Zepto.js 3 | // (c) 2010-2014 Thomas Fuchs 4 | // Zepto.js may be freely distributed under the MIT license. 5 | 6 | ;(function($){ 7 | var _zid = 1, undefined, 8 | slice = Array.prototype.slice, 9 | isFunction = $.isFunction, 10 | isString = function(obj){ return typeof obj == 'string' }, 11 | handlers = {}, 12 | specialEvents={}, 13 | focusinSupported = 'onfocusin' in window, 14 | focus = { focus: 'focusin', blur: 'focusout' }, 15 | hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' } 16 | 17 | specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents' 18 | 19 | function zid(element) { 20 | return element._zid || (element._zid = _zid++) 21 | } 22 | function findHandlers(element, event, fn, selector) { 23 | event = parse(event) 24 | if (event.ns) var matcher = matcherFor(event.ns) 25 | return (handlers[zid(element)] || []).filter(function(handler) { 26 | return handler 27 | && (!event.e || handler.e == event.e) 28 | && (!event.ns || matcher.test(handler.ns)) 29 | && (!fn || zid(handler.fn) === zid(fn)) 30 | && (!selector || handler.sel == selector) 31 | }) 32 | } 33 | function parse(event) { 34 | var parts = ('' + event).split('.') 35 | return {e: parts[0], ns: parts.slice(1).sort().join(' ')} 36 | } 37 | function matcherFor(ns) { 38 | return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)') 39 | } 40 | 41 | function eventCapture(handler, captureSetting) { 42 | return handler.del && 43 | (!focusinSupported && (handler.e in focus)) || 44 | !!captureSetting 45 | } 46 | 47 | function realEvent(type) { 48 | return hover[type] || (focusinSupported && focus[type]) || type 49 | } 50 | 51 | function add(element, events, fn, data, selector, delegator, capture){ 52 | var id = zid(element), set = (handlers[id] || (handlers[id] = [])) 53 | events.split(/\s/).forEach(function(event){ 54 | if (event == 'ready') return $(document).ready(fn) 55 | var handler = parse(event) 56 | handler.fn = fn 57 | handler.sel = selector 58 | // emulate mouseenter, mouseleave 59 | if (handler.e in hover) fn = function(e){ 60 | var related = e.relatedTarget 61 | if (!related || (related !== this && !$.contains(this, related))) 62 | return handler.fn.apply(this, arguments) 63 | } 64 | handler.del = delegator 65 | var callback = delegator || fn 66 | handler.proxy = function(e){ 67 | e = compatible(e) 68 | if (e.isImmediatePropagationStopped()) return 69 | e.data = data 70 | var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args)) 71 | if (result === false) e.preventDefault(), e.stopPropagation() 72 | return result 73 | } 74 | handler.i = set.length 75 | set.push(handler) 76 | if ('addEventListener' in element) 77 | element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) 78 | }) 79 | } 80 | function remove(element, events, fn, selector, capture){ 81 | var id = zid(element) 82 | ;(events || '').split(/\s/).forEach(function(event){ 83 | findHandlers(element, event, fn, selector).forEach(function(handler){ 84 | delete handlers[id][handler.i] 85 | if ('removeEventListener' in element) 86 | element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) 87 | }) 88 | }) 89 | } 90 | 91 | $.event = { add: add, remove: remove } 92 | 93 | $.proxy = function(fn, context) { 94 | if (isFunction(fn)) { 95 | var proxyFn = function(){ return fn.apply(context, arguments) } 96 | proxyFn._zid = zid(fn) 97 | return proxyFn 98 | } else if (isString(context)) { 99 | return $.proxy(fn[context], fn) 100 | } else { 101 | throw new TypeError("expected function") 102 | } 103 | } 104 | 105 | $.fn.bind = function(event, data, callback){ 106 | return this.on(event, data, callback) 107 | } 108 | $.fn.unbind = function(event, callback){ 109 | return this.off(event, callback) 110 | } 111 | $.fn.one = function(event, selector, data, callback){ 112 | return this.on(event, selector, data, callback, 1) 113 | } 114 | 115 | var returnTrue = function(){return true}, 116 | returnFalse = function(){return false}, 117 | ignoreProperties = /^([A-Z]|returnValue$|layer[XY]$)/, 118 | eventMethods = { 119 | preventDefault: 'isDefaultPrevented', 120 | stopImmediatePropagation: 'isImmediatePropagationStopped', 121 | stopPropagation: 'isPropagationStopped' 122 | } 123 | 124 | function compatible(event, source) { 125 | if (source || !event.isDefaultPrevented) { 126 | source || (source = event) 127 | 128 | $.each(eventMethods, function(name, predicate) { 129 | var sourceMethod = source[name] 130 | event[name] = function(){ 131 | this[predicate] = returnTrue 132 | return sourceMethod && sourceMethod.apply(source, arguments) 133 | } 134 | event[predicate] = returnFalse 135 | }) 136 | 137 | if (source.defaultPrevented !== undefined ? source.defaultPrevented : 138 | 'returnValue' in source ? source.returnValue === false : 139 | source.getPreventDefault && source.getPreventDefault()) 140 | event.isDefaultPrevented = returnTrue 141 | } 142 | return event 143 | } 144 | 145 | function createProxy(event) { 146 | var key, proxy = { originalEvent: event } 147 | for (key in event) 148 | if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key] 149 | 150 | return compatible(proxy, event) 151 | } 152 | 153 | $.fn.delegate = function(selector, event, callback){ 154 | return this.on(event, selector, callback) 155 | } 156 | $.fn.undelegate = function(selector, event, callback){ 157 | return this.off(event, selector, callback) 158 | } 159 | 160 | $.fn.live = function(event, callback){ 161 | $(document.body).delegate(this.selector, event, callback) 162 | return this 163 | } 164 | $.fn.die = function(event, callback){ 165 | $(document.body).undelegate(this.selector, event, callback) 166 | return this 167 | } 168 | 169 | $.fn.on = function(event, selector, data, callback, one){ 170 | var autoRemove, delegator, $this = this 171 | if (event && !isString(event)) { 172 | $.each(event, function(type, fn){ 173 | $this.on(type, selector, data, fn, one) 174 | }) 175 | return $this 176 | } 177 | 178 | if (!isString(selector) && !isFunction(callback) && callback !== false) 179 | callback = data, data = selector, selector = undefined 180 | if (isFunction(data) || data === false) 181 | callback = data, data = undefined 182 | 183 | if (callback === false) callback = returnFalse 184 | 185 | return $this.each(function(_, element){ 186 | if (one) autoRemove = function(e){ 187 | remove(element, e.type, callback) 188 | return callback.apply(this, arguments) 189 | } 190 | 191 | if (selector) delegator = function(e){ 192 | var evt, match = $(e.target).closest(selector, element).get(0) 193 | if (match && match !== element) { 194 | evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element}) 195 | return (autoRemove || callback).apply(match, [evt].concat(slice.call(arguments, 1))) 196 | } 197 | } 198 | 199 | add(element, event, callback, data, selector, delegator || autoRemove) 200 | }) 201 | } 202 | $.fn.off = function(event, selector, callback){ 203 | var $this = this 204 | if (event && !isString(event)) { 205 | $.each(event, function(type, fn){ 206 | $this.off(type, selector, fn) 207 | }) 208 | return $this 209 | } 210 | 211 | if (!isString(selector) && !isFunction(callback) && callback !== false) 212 | callback = selector, selector = undefined 213 | 214 | if (callback === false) callback = returnFalse 215 | 216 | return $this.each(function(){ 217 | remove(this, event, callback, selector) 218 | }) 219 | } 220 | 221 | $.fn.trigger = function(event, args){ 222 | event = (isString(event) || $.isPlainObject(event)) ? $.Event(event) : compatible(event) 223 | event._args = args 224 | return this.each(function(){ 225 | // items in the collection might not be DOM elements 226 | if('dispatchEvent' in this) this.dispatchEvent(event) 227 | else $(this).triggerHandler(event, args) 228 | }) 229 | } 230 | 231 | // triggers event handlers on current element just as if an event occurred, 232 | // doesn't trigger an actual event, doesn't bubble 233 | $.fn.triggerHandler = function(event, args){ 234 | var e, result 235 | this.each(function(i, element){ 236 | e = createProxy(isString(event) ? $.Event(event) : event) 237 | e._args = args 238 | e.target = element 239 | $.each(findHandlers(element, event.type || event), function(i, handler){ 240 | result = handler.proxy(e) 241 | if (e.isImmediatePropagationStopped()) return false 242 | }) 243 | }) 244 | return result 245 | } 246 | 247 | // shortcut methods for `.bind(event, fn)` for each event type 248 | ;('focusin focusout load resize scroll unload click dblclick '+ 249 | 'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+ 250 | 'change select keydown keypress keyup error').split(' ').forEach(function(event) { 251 | $.fn[event] = function(callback) { 252 | return callback ? 253 | this.bind(event, callback) : 254 | this.trigger(event) 255 | } 256 | }) 257 | 258 | ;['focus', 'blur'].forEach(function(name) { 259 | $.fn[name] = function(callback) { 260 | if (callback) this.bind(name, callback) 261 | else this.each(function(){ 262 | try { this[name]() } 263 | catch(e) {} 264 | }) 265 | return this 266 | } 267 | }) 268 | 269 | $.Event = function(type, props) { 270 | if (!isString(type)) props = type, type = props.type 271 | var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true 272 | if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]) 273 | event.initEvent(type, bubbles, true) 274 | return compatible(event) 275 | } 276 | 277 | })(Zepto) 278 | 279 | }); 280 | -------------------------------------------------------------------------------- /lib/os.js: -------------------------------------------------------------------------------- 1 | define(['./zepto'], function(){ 2 | var ua = navigator.userAgent.toLowerCase(); 3 | function platform (os){ 4 | var ver = ('' + (new RegExp(os + '(\\d+((\\.|_)\\d+)*)').exec(ua) || [,0])[1]).replace(/_/g, '.'); 5 | // undefined < 3 === false, but null < 3 === true 6 | return parseFloat(ver) || undefined; 7 | } 8 | 9 | $.os = { 10 | // iPad UA contains 'cpu os', and iPod/iPhone UA contains 'iphone os' 11 | ios: platform('os '), 12 | // WTF? ZTE UserAgent: ZTEU880E_TD/1.0 Linux/2.6.35 Android/2.3 Release/12.15.2011 Browser/AppleWebKit533.1 FlyFlow/2.4 baidubrowser/042_1.8.4.2_dio 13 | android: platform('android[/ ]') 14 | }; 15 | }); 16 | -------------------------------------------------------------------------------- /lib/raf.js: -------------------------------------------------------------------------------- 1 | // requestAnimationFrame polyfill 2 | (function() { 3 | 4 | var lastTime = 0, 5 | frame = window.webkitRequestAnimationFrame || 6 | window.mozRequestAnimationFrame || 7 | function(callback){ 8 | 9 | // make a timeStamp to callback,otherwise the arguments(now) will be undefined in ios4,5 10 | var currTime = new Date().getTime(), 11 | timeToCall = Math.max(0, 16 - (currTime - lastTime)), 12 | timeOutId = setTimeout(function() { 13 | callback(currTime + timeToCall); 14 | }, timeToCall); 15 | 16 | lastTime = currTime + timeToCall; 17 | return timeOutId; 18 | }; 19 | 20 | window.requestAnimationFrame = window.requestAnimationFrame || frame; 21 | 22 | window.cancelAnimationFrame = window.cancelAnimationFrame || 23 | function(id) { 24 | clearTimeout(id); 25 | }; 26 | 27 | 28 | // exports 29 | module.exports = function(callback){ 30 | return window.requestAnimationFrame(callback); 31 | } 32 | }()); 33 | -------------------------------------------------------------------------------- /lib/touch.js: -------------------------------------------------------------------------------- 1 | define(['./zepto'], function(){ 2 | // Zepto.js 3 | // (c) 2010-2014 Thomas Fuchs 4 | // Zepto.js may be freely distributed under the MIT license. 5 | 6 | ;(function($){ 7 | var touch = {}, 8 | touchTimeout, tapTimeout, swipeTimeout, longTapTimeout, 9 | longTapDelay = 750, 10 | gesture 11 | 12 | function swipeDirection(x1, x2, y1, y2) { 13 | return Math.abs(x1 - x2) >= 14 | Math.abs(y1 - y2) ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down') 15 | } 16 | 17 | function longTap() { 18 | longTapTimeout = null 19 | if (touch.last) { 20 | touch.el.trigger('longTap') 21 | touch = {} 22 | } 23 | } 24 | 25 | function cancelLongTap() { 26 | if (longTapTimeout) clearTimeout(longTapTimeout) 27 | longTapTimeout = null 28 | } 29 | 30 | function cancelAll() { 31 | if (touchTimeout) clearTimeout(touchTimeout) 32 | if (tapTimeout) clearTimeout(tapTimeout) 33 | if (swipeTimeout) clearTimeout(swipeTimeout) 34 | if (longTapTimeout) clearTimeout(longTapTimeout) 35 | touchTimeout = tapTimeout = swipeTimeout = longTapTimeout = null 36 | touch = {} 37 | } 38 | 39 | function isPrimaryTouch(event){ 40 | return (event.pointerType == 'touch' || 41 | event.pointerType == event.MSPOINTER_TYPE_TOUCH) 42 | && event.isPrimary 43 | } 44 | 45 | function isPointerEventType(e, type){ 46 | return (e.type == 'pointer'+type || 47 | e.type.toLowerCase() == 'mspointer'+type) 48 | } 49 | 50 | $(document).ready(function(){ 51 | var now, delta, deltaX = 0, deltaY = 0, firstTouch, _isPointerType 52 | 53 | if ('MSGesture' in window) { 54 | gesture = new MSGesture() 55 | gesture.target = document.body 56 | } 57 | 58 | $(document) 59 | .bind('MSGestureEnd', function(e){ 60 | var swipeDirectionFromVelocity = 61 | e.velocityX > 1 ? 'Right' : e.velocityX < -1 ? 'Left' : e.velocityY > 1 ? 'Down' : e.velocityY < -1 ? 'Up' : null; 62 | if (swipeDirectionFromVelocity) { 63 | touch.el.trigger('swipe') 64 | touch.el.trigger('swipe'+ swipeDirectionFromVelocity) 65 | } 66 | }) 67 | .on('touchstart MSPointerDown pointerdown', function(e){ 68 | if((_isPointerType = isPointerEventType(e, 'down')) && 69 | !isPrimaryTouch(e)) return 70 | firstTouch = _isPointerType ? e : e.touches[0] 71 | if (e.touches && e.touches.length === 1 && touch.x2) { 72 | // Clear out touch movement data if we have it sticking around 73 | // This can occur if touchcancel doesn't fire due to preventDefault, etc. 74 | touch.x2 = undefined 75 | touch.y2 = undefined 76 | } 77 | now = Date.now() 78 | delta = now - (touch.last || now) 79 | touch.el = $('tagName' in firstTouch.target ? 80 | firstTouch.target : firstTouch.target.parentNode) 81 | touchTimeout && clearTimeout(touchTimeout) 82 | touch.x1 = firstTouch.pageX 83 | touch.y1 = firstTouch.pageY 84 | if (delta > 0 && delta <= 250) touch.isDoubleTap = true 85 | touch.last = now 86 | longTapTimeout = setTimeout(longTap, longTapDelay) 87 | // adds the current touch contact for IE gesture recognition 88 | if (gesture && _isPointerType) gesture.addPointer(e.pointerId); 89 | }) 90 | .on('touchmove MSPointerMove pointermove', function(e){ 91 | if((_isPointerType = isPointerEventType(e, 'move')) && 92 | !isPrimaryTouch(e)) return 93 | firstTouch = _isPointerType ? e : e.touches[0] 94 | cancelLongTap() 95 | touch.x2 = firstTouch.pageX 96 | touch.y2 = firstTouch.pageY 97 | 98 | deltaX += Math.abs(touch.x1 - touch.x2) 99 | deltaY += Math.abs(touch.y1 - touch.y2) 100 | }) 101 | .on('touchend MSPointerUp pointerup', function(e){ 102 | if((_isPointerType = isPointerEventType(e, 'up')) && 103 | !isPrimaryTouch(e)) return 104 | cancelLongTap() 105 | 106 | // swipe 107 | if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) || 108 | (touch.y2 && Math.abs(touch.y1 - touch.y2) > 30)) 109 | 110 | swipeTimeout = setTimeout(function() { 111 | touch.el.trigger('swipe') 112 | touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2))) 113 | touch = {} 114 | }, 0) 115 | 116 | // normal tap 117 | else if ('last' in touch) 118 | // don't fire tap when delta position changed by more than 30 pixels, 119 | // for instance when moving to a point and back to origin 120 | if (deltaX < 30 && deltaY < 30) { 121 | // delay by one tick so we can cancel the 'tap' event if 'scroll' fires 122 | // ('tap' fires before 'scroll') 123 | tapTimeout = setTimeout(function() { 124 | 125 | // trigger universal 'tap' with the option to cancelTouch() 126 | // (cancelTouch cancels processing of single vs double taps for faster 'tap' response) 127 | var event = $.Event('tap') 128 | event.cancelTouch = cancelAll 129 | touch.el.trigger(event) 130 | 131 | // trigger double tap immediately 132 | if (touch.isDoubleTap) { 133 | if (touch.el) touch.el.trigger('doubleTap') 134 | touch = {} 135 | } 136 | 137 | // trigger single tap after 250ms of inactivity 138 | else { 139 | touchTimeout = setTimeout(function(){ 140 | touchTimeout = null 141 | if (touch.el) touch.el.trigger('singleTap') 142 | touch = {} 143 | }, 250) 144 | } 145 | }, 0) 146 | } else { 147 | touch = {} 148 | } 149 | deltaX = deltaY = 0 150 | 151 | }) 152 | // when the browser window loses focus, 153 | // for example when a modal dialog is shown, 154 | // cancel all ongoing events 155 | .on('touchcancel MSPointerCancel pointercancel', cancelAll) 156 | 157 | // scrolling the window indicates intention of the user 158 | // to scroll, not tap or swipe, so cancel all ongoing events 159 | $(window).on('scroll', cancelAll) 160 | }) 161 | 162 | ;['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 163 | 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(eventName){ 164 | $.fn[eventName] = function(callback){ return this.on(eventName, callback) } 165 | }) 166 | })(Zepto) 167 | 168 | }); 169 | -------------------------------------------------------------------------------- /lib/zepto.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | // Zepto.js 3 | // (c) 2010-2014 Thomas Fuchs 4 | // Zepto.js may be freely distributed under the MIT license. 5 | 6 | var Zepto = (function() { 7 | var undefined, key, $, classList, emptyArray = [], slice = emptyArray.slice, filter = emptyArray.filter, 8 | document = window.document, 9 | elementDisplay = {}, classCache = {}, 10 | cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 }, 11 | fragmentRE = /^\s*<(\w+|!)[^>]*>/, 12 | singleTagRE = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, 13 | tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, 14 | rootNodeRE = /^(?:body|html)$/i, 15 | capitalRE = /([A-Z])/g, 16 | 17 | // special attributes that should be get/set via method calls 18 | methodAttributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'], 19 | 20 | adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ], 21 | table = document.createElement('table'), 22 | tableRow = document.createElement('tr'), 23 | containers = { 24 | 'tr': document.createElement('tbody'), 25 | 'tbody': table, 'thead': table, 'tfoot': table, 26 | 'td': tableRow, 'th': tableRow, 27 | '*': document.createElement('div') 28 | }, 29 | readyRE = /complete|loaded|interactive/, 30 | simpleSelectorRE = /^[\w-]*$/, 31 | class2type = {}, 32 | toString = class2type.toString, 33 | zepto = {}, 34 | camelize, uniq, 35 | tempParent = document.createElement('div'), 36 | propMap = { 37 | 'tabindex': 'tabIndex', 38 | 'readonly': 'readOnly', 39 | 'for': 'htmlFor', 40 | 'class': 'className', 41 | 'maxlength': 'maxLength', 42 | 'cellspacing': 'cellSpacing', 43 | 'cellpadding': 'cellPadding', 44 | 'rowspan': 'rowSpan', 45 | 'colspan': 'colSpan', 46 | 'usemap': 'useMap', 47 | 'frameborder': 'frameBorder', 48 | 'contenteditable': 'contentEditable' 49 | }, 50 | isArray = Array.isArray || 51 | function(object){ return object instanceof Array } 52 | 53 | zepto.matches = function(element, selector) { 54 | if (!selector || !element || element.nodeType !== 1) return false 55 | var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector || 56 | element.oMatchesSelector || element.matchesSelector 57 | if (matchesSelector) return matchesSelector.call(element, selector) 58 | // fall back to performing a selector: 59 | var match, parent = element.parentNode, temp = !parent 60 | if (temp) (parent = tempParent).appendChild(element) 61 | match = ~zepto.qsa(parent, selector).indexOf(element) 62 | temp && tempParent.removeChild(element) 63 | return match 64 | } 65 | 66 | function type(obj) { 67 | return obj == null ? String(obj) : 68 | class2type[toString.call(obj)] || "object" 69 | } 70 | 71 | function isFunction(value) { return type(value) == "function" } 72 | function isWindow(obj) { return obj != null && obj == obj.window } 73 | function isDocument(obj) { return obj != null && obj.nodeType == obj.DOCUMENT_NODE } 74 | function isObject(obj) { return type(obj) == "object" } 75 | function isPlainObject(obj) { 76 | return isObject(obj) && !isWindow(obj) && Object.getPrototypeOf(obj) == Object.prototype 77 | } 78 | function likeArray(obj) { return typeof obj.length == 'number' } 79 | 80 | function compact(array) { return filter.call(array, function(item){ return item != null }) } 81 | function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array } 82 | camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) } 83 | function dasherize(str) { 84 | return str.replace(/::/g, '/') 85 | .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') 86 | .replace(/([a-z\d])([A-Z])/g, '$1_$2') 87 | .replace(/_/g, '-') 88 | .toLowerCase() 89 | } 90 | uniq = function(array){ return filter.call(array, function(item, idx){ return array.indexOf(item) == idx }) } 91 | 92 | function classRE(name) { 93 | return name in classCache ? 94 | classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)')) 95 | } 96 | 97 | function maybeAddPx(name, value) { 98 | return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value 99 | } 100 | 101 | function defaultDisplay(nodeName) { 102 | var element, display 103 | if (!elementDisplay[nodeName]) { 104 | element = document.createElement(nodeName) 105 | document.body.appendChild(element) 106 | display = getComputedStyle(element, '').getPropertyValue("display") 107 | element.parentNode.removeChild(element) 108 | display == "none" && (display = "block") 109 | elementDisplay[nodeName] = display 110 | } 111 | return elementDisplay[nodeName] 112 | } 113 | 114 | function children(element) { 115 | return 'children' in element ? 116 | slice.call(element.children) : 117 | $.map(element.childNodes, function(node){ if (node.nodeType == 1) return node }) 118 | } 119 | 120 | // `$.zepto.fragment` takes a html string and an optional tag name 121 | // to generate DOM nodes nodes from the given html string. 122 | // The generated DOM nodes are returned as an array. 123 | // This function can be overriden in plugins for example to make 124 | // it compatible with browsers that don't support the DOM fully. 125 | zepto.fragment = function(html, name, properties) { 126 | var dom, nodes, container 127 | 128 | // A special case optimization for a single tag 129 | if (singleTagRE.test(html)) dom = $(document.createElement(RegExp.$1)) 130 | 131 | if (!dom) { 132 | if (html.replace) html = html.replace(tagExpanderRE, "<$1>") 133 | if (name === undefined) name = fragmentRE.test(html) && RegExp.$1 134 | if (!(name in containers)) name = '*' 135 | 136 | container = containers[name] 137 | container.innerHTML = '' + html 138 | dom = $.each(slice.call(container.childNodes), function(){ 139 | container.removeChild(this) 140 | }) 141 | } 142 | 143 | if (isPlainObject(properties)) { 144 | nodes = $(dom) 145 | $.each(properties, function(key, value) { 146 | if (methodAttributes.indexOf(key) > -1) nodes[key](value) 147 | else nodes.attr(key, value) 148 | }) 149 | } 150 | 151 | return dom 152 | } 153 | 154 | // `$.zepto.Z` swaps out the prototype of the given `dom` array 155 | // of nodes with `$.fn` and thus supplying all the Zepto functions 156 | // to the array. Note that `__proto__` is not supported on Internet 157 | // Explorer. This method can be overriden in plugins. 158 | zepto.Z = function(dom, selector) { 159 | dom = dom || [] 160 | dom.__proto__ = $.fn 161 | dom.selector = selector || '' 162 | return dom 163 | } 164 | 165 | // `$.zepto.isZ` should return `true` if the given object is a Zepto 166 | // collection. This method can be overriden in plugins. 167 | zepto.isZ = function(object) { 168 | return object instanceof zepto.Z 169 | } 170 | 171 | // `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and 172 | // takes a CSS selector and an optional context (and handles various 173 | // special cases). 174 | // This method can be overriden in plugins. 175 | zepto.init = function(selector, context) { 176 | var dom 177 | // If nothing given, return an empty Zepto collection 178 | if (!selector) return zepto.Z() 179 | // Optimize for string selectors 180 | else if (typeof selector == 'string') { 181 | selector = selector.trim() 182 | // If it's a html fragment, create nodes from it 183 | // Note: In both Chrome 21 and Firefox 15, DOM error 12 184 | // is thrown if the fragment doesn't begin with < 185 | if (selector[0] == '<' && fragmentRE.test(selector)) 186 | dom = zepto.fragment(selector, RegExp.$1, context), selector = null 187 | // If there's a context, create a collection on that context first, and select 188 | // nodes from there 189 | else if (context !== undefined) return $(context).find(selector) 190 | // If it's a CSS selector, use it to select nodes. 191 | else dom = zepto.qsa(document, selector) 192 | } 193 | // If a function is given, call it when the DOM is ready 194 | else if (isFunction(selector)) return $(document).ready(selector) 195 | // If a Zepto collection is given, just return it 196 | else if (zepto.isZ(selector)) return selector 197 | else { 198 | // normalize array if an array of nodes is given 199 | if (isArray(selector)) dom = compact(selector) 200 | // Wrap DOM nodes. 201 | else if (isObject(selector)) 202 | dom = [selector], selector = null 203 | // If it's a html fragment, create nodes from it 204 | else if (fragmentRE.test(selector)) 205 | dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null 206 | // If there's a context, create a collection on that context first, and select 207 | // nodes from there 208 | else if (context !== undefined) return $(context).find(selector) 209 | // And last but no least, if it's a CSS selector, use it to select nodes. 210 | else dom = zepto.qsa(document, selector) 211 | } 212 | // create a new Zepto collection from the nodes found 213 | return zepto.Z(dom, selector) 214 | } 215 | 216 | // `$` will be the base `Zepto` object. When calling this 217 | // function just call `$.zepto.init, which makes the implementation 218 | // details of selecting nodes and creating Zepto collections 219 | // patchable in plugins. 220 | $ = function(selector, context){ 221 | return zepto.init(selector, context) 222 | } 223 | 224 | function extend(target, source, deep) { 225 | for (key in source) 226 | if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { 227 | if (isPlainObject(source[key]) && !isPlainObject(target[key])) 228 | target[key] = {} 229 | if (isArray(source[key]) && !isArray(target[key])) 230 | target[key] = [] 231 | extend(target[key], source[key], deep) 232 | } 233 | else if (source[key] !== undefined) target[key] = source[key] 234 | } 235 | 236 | // Copy all but undefined properties from one or more 237 | // objects to the `target` object. 238 | $.extend = function(target){ 239 | var deep, args = slice.call(arguments, 1) 240 | if (typeof target == 'boolean') { 241 | deep = target 242 | target = args.shift() 243 | } 244 | args.forEach(function(arg){ extend(target, arg, deep) }) 245 | return target 246 | } 247 | 248 | // `$.zepto.qsa` is Zepto's CSS selector implementation which 249 | // uses `document.querySelectorAll` and optimizes for some special cases, like `#id`. 250 | // This method can be overriden in plugins. 251 | zepto.qsa = function(element, selector){ 252 | var found, 253 | maybeID = selector[0] == '#', 254 | maybeClass = !maybeID && selector[0] == '.', 255 | nameOnly = maybeID || maybeClass ? selector.slice(1) : selector, // Ensure that a 1 char tag name still gets checked 256 | isSimple = simpleSelectorRE.test(nameOnly) 257 | return (isDocument(element) && isSimple && maybeID) ? 258 | ( (found = element.getElementById(nameOnly)) ? [found] : [] ) : 259 | (element.nodeType !== 1 && element.nodeType !== 9) ? [] : 260 | slice.call( 261 | isSimple && !maybeID ? 262 | maybeClass ? element.getElementsByClassName(nameOnly) : // If it's simple, it could be a class 263 | element.getElementsByTagName(selector) : // Or a tag 264 | element.querySelectorAll(selector) // Or it's not simple, and we need to query all 265 | ) 266 | } 267 | 268 | function filtered(nodes, selector) { 269 | return selector == null ? $(nodes) : $(nodes).filter(selector) 270 | } 271 | 272 | $.contains = function(parent, node) { 273 | return parent !== node && parent.contains(node) 274 | } 275 | 276 | function funcArg(context, arg, idx, payload) { 277 | return isFunction(arg) ? arg.call(context, idx, payload) : arg 278 | } 279 | 280 | function setAttribute(node, name, value) { 281 | value == null ? node.removeAttribute(name) : node.setAttribute(name, value) 282 | } 283 | 284 | // access className property while respecting SVGAnimatedString 285 | function className(node, value){ 286 | var klass = node.className, 287 | svg = klass && klass.baseVal !== undefined 288 | 289 | if (value === undefined) return svg ? klass.baseVal : klass 290 | svg ? (klass.baseVal = value) : (node.className = value) 291 | } 292 | 293 | // "true" => true 294 | // "false" => false 295 | // "null" => null 296 | // "42" => 42 297 | // "42.5" => 42.5 298 | // "08" => "08" 299 | // JSON => parse if valid 300 | // String => self 301 | function deserializeValue(value) { 302 | var num 303 | try { 304 | return value ? 305 | value == "true" || 306 | ( value == "false" ? false : 307 | value == "null" ? null : 308 | !/^0/.test(value) && !isNaN(num = Number(value)) ? num : 309 | /^[\[\{]/.test(value) ? $.parseJSON(value) : 310 | value ) 311 | : value 312 | } catch(e) { 313 | return value 314 | } 315 | } 316 | 317 | $.type = type 318 | $.isFunction = isFunction 319 | $.isWindow = isWindow 320 | $.isArray = isArray 321 | $.isPlainObject = isPlainObject 322 | 323 | $.isEmptyObject = function(obj) { 324 | var name 325 | for (name in obj) return false 326 | return true 327 | } 328 | 329 | $.inArray = function(elem, array, i){ 330 | return emptyArray.indexOf.call(array, elem, i) 331 | } 332 | 333 | $.camelCase = camelize 334 | $.trim = function(str) { 335 | return str == null ? "" : String.prototype.trim.call(str) 336 | } 337 | 338 | // plugin compatibility 339 | $.uuid = 0 340 | $.support = { } 341 | $.expr = { } 342 | 343 | $.map = function(elements, callback){ 344 | var value, values = [], i, key 345 | if (likeArray(elements)) 346 | for (i = 0; i < elements.length; i++) { 347 | value = callback(elements[i], i) 348 | if (value != null) values.push(value) 349 | } 350 | else 351 | for (key in elements) { 352 | value = callback(elements[key], key) 353 | if (value != null) values.push(value) 354 | } 355 | return flatten(values) 356 | } 357 | 358 | $.each = function(elements, callback){ 359 | var i, key 360 | if (likeArray(elements)) { 361 | for (i = 0; i < elements.length; i++) 362 | if (callback.call(elements[i], i, elements[i]) === false) return elements 363 | } else { 364 | for (key in elements) 365 | if (callback.call(elements[key], key, elements[key]) === false) return elements 366 | } 367 | 368 | return elements 369 | } 370 | 371 | $.grep = function(elements, callback){ 372 | return filter.call(elements, callback) 373 | } 374 | 375 | if (window.JSON) $.parseJSON = JSON.parse 376 | 377 | // Populate the class2type map 378 | $.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { 379 | class2type[ "[object " + name + "]" ] = name.toLowerCase() 380 | }) 381 | 382 | // Define methods that will be available on all 383 | // Zepto collections 384 | $.fn = { 385 | // Because a collection acts like an array 386 | // copy over these useful array functions. 387 | forEach: emptyArray.forEach, 388 | reduce: emptyArray.reduce, 389 | push: emptyArray.push, 390 | sort: emptyArray.sort, 391 | indexOf: emptyArray.indexOf, 392 | concat: emptyArray.concat, 393 | 394 | // `map` and `slice` in the jQuery API work differently 395 | // from their array counterparts 396 | map: function(fn){ 397 | return $($.map(this, function(el, i){ return fn.call(el, i, el) })) 398 | }, 399 | slice: function(){ 400 | return $(slice.apply(this, arguments)) 401 | }, 402 | 403 | ready: function(callback){ 404 | // need to check if document.body exists for IE as that browser reports 405 | // document ready when it hasn't yet created the body element 406 | if (readyRE.test(document.readyState) && document.body) callback($) 407 | else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false) 408 | return this 409 | }, 410 | get: function(idx){ 411 | return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length] 412 | }, 413 | toArray: function(){ return this.get() }, 414 | size: function(){ 415 | return this.length 416 | }, 417 | remove: function(){ 418 | return this.each(function(){ 419 | if (this.parentNode != null) 420 | this.parentNode.removeChild(this) 421 | }) 422 | }, 423 | each: function(callback){ 424 | emptyArray.every.call(this, function(el, idx){ 425 | return callback.call(el, idx, el) !== false 426 | }) 427 | return this 428 | }, 429 | filter: function(selector){ 430 | if (isFunction(selector)) return this.not(this.not(selector)) 431 | return $(filter.call(this, function(element){ 432 | return zepto.matches(element, selector) 433 | })) 434 | }, 435 | add: function(selector,context){ 436 | return $(uniq(this.concat($(selector,context)))) 437 | }, 438 | is: function(selector){ 439 | return this.length > 0 && zepto.matches(this[0], selector) 440 | }, 441 | not: function(selector){ 442 | var nodes=[] 443 | if (isFunction(selector) && selector.call !== undefined) 444 | this.each(function(idx){ 445 | if (!selector.call(this,idx)) nodes.push(this) 446 | }) 447 | else { 448 | var excludes = typeof selector == 'string' ? this.filter(selector) : 449 | (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector) 450 | this.forEach(function(el){ 451 | if (excludes.indexOf(el) < 0) nodes.push(el) 452 | }) 453 | } 454 | return $(nodes) 455 | }, 456 | has: function(selector){ 457 | return this.filter(function(){ 458 | return isObject(selector) ? 459 | $.contains(this, selector) : 460 | $(this).find(selector).size() 461 | }) 462 | }, 463 | eq: function(idx){ 464 | return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1) 465 | }, 466 | first: function(){ 467 | var el = this[0] 468 | return el && !isObject(el) ? el : $(el) 469 | }, 470 | last: function(){ 471 | var el = this[this.length - 1] 472 | return el && !isObject(el) ? el : $(el) 473 | }, 474 | find: function(selector){ 475 | var result, $this = this 476 | if (typeof selector == 'object') 477 | result = $(selector).filter(function(){ 478 | var node = this 479 | return emptyArray.some.call($this, function(parent){ 480 | return $.contains(parent, node) 481 | }) 482 | }) 483 | else if (this.length == 1) result = $(zepto.qsa(this[0], selector)) 484 | else result = this.map(function(){ return zepto.qsa(this, selector) }) 485 | return result 486 | }, 487 | closest: function(selector, context){ 488 | var node = this[0], collection = false 489 | if (typeof selector == 'object') collection = $(selector) 490 | while (node && !(collection ? collection.indexOf(node) >= 0 : zepto.matches(node, selector))) 491 | node = node !== context && !isDocument(node) && node.parentNode 492 | return $(node) 493 | }, 494 | parents: function(selector){ 495 | var ancestors = [], nodes = this 496 | while (nodes.length > 0) 497 | nodes = $.map(nodes, function(node){ 498 | if ((node = node.parentNode) && !isDocument(node) && ancestors.indexOf(node) < 0) { 499 | ancestors.push(node) 500 | return node 501 | } 502 | }) 503 | return filtered(ancestors, selector) 504 | }, 505 | parent: function(selector){ 506 | return filtered(uniq(this.pluck('parentNode')), selector) 507 | }, 508 | children: function(selector){ 509 | return filtered(this.map(function(){ return children(this) }), selector) 510 | }, 511 | contents: function() { 512 | return this.map(function() { return slice.call(this.childNodes) }) 513 | }, 514 | siblings: function(selector){ 515 | return filtered(this.map(function(i, el){ 516 | return filter.call(children(el.parentNode), function(child){ return child!==el }) 517 | }), selector) 518 | }, 519 | empty: function(){ 520 | return this.each(function(){ this.innerHTML = '' }) 521 | }, 522 | // `pluck` is borrowed from Prototype.js 523 | pluck: function(property){ 524 | return $.map(this, function(el){ return el[property] }) 525 | }, 526 | show: function(){ 527 | return this.each(function(){ 528 | this.style.display == "none" && (this.style.display = '') 529 | if (getComputedStyle(this, '').getPropertyValue("display") == "none") 530 | this.style.display = defaultDisplay(this.nodeName) 531 | }) 532 | }, 533 | replaceWith: function(newContent){ 534 | return this.before(newContent).remove() 535 | }, 536 | wrap: function(structure){ 537 | var func = isFunction(structure) 538 | if (this[0] && !func) 539 | var dom = $(structure).get(0), 540 | clone = dom.parentNode || this.length > 1 541 | 542 | return this.each(function(index){ 543 | $(this).wrapAll( 544 | func ? structure.call(this, index) : 545 | clone ? dom.cloneNode(true) : dom 546 | ) 547 | }) 548 | }, 549 | wrapAll: function(structure){ 550 | if (this[0]) { 551 | $(this[0]).before(structure = $(structure)) 552 | var children 553 | // drill down to the inmost element 554 | while ((children = structure.children()).length) structure = children.first() 555 | $(structure).append(this) 556 | } 557 | return this 558 | }, 559 | wrapInner: function(structure){ 560 | var func = isFunction(structure) 561 | return this.each(function(index){ 562 | var self = $(this), contents = self.contents(), 563 | dom = func ? structure.call(this, index) : structure 564 | contents.length ? contents.wrapAll(dom) : self.append(dom) 565 | }) 566 | }, 567 | unwrap: function(){ 568 | this.parent().each(function(){ 569 | $(this).replaceWith($(this).children()) 570 | }) 571 | return this 572 | }, 573 | clone: function(){ 574 | return this.map(function(){ return this.cloneNode(true) }) 575 | }, 576 | hide: function(){ 577 | return this.css("display", "none") 578 | }, 579 | toggle: function(setting){ 580 | return this.each(function(){ 581 | var el = $(this) 582 | ;(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide() 583 | }) 584 | }, 585 | prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') }, 586 | next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') }, 587 | html: function(html){ 588 | return arguments.length === 0 ? 589 | (this.length > 0 ? this[0].innerHTML : null) : 590 | this.each(function(idx){ 591 | var originHtml = this.innerHTML 592 | $(this).empty().append( funcArg(this, html, idx, originHtml) ) 593 | }) 594 | }, 595 | text: function(text){ 596 | return arguments.length === 0 ? 597 | (this.length > 0 ? this[0].textContent : null) : 598 | this.each(function(){ this.textContent = (text === undefined) ? '' : ''+text }) 599 | }, 600 | attr: function(name, value){ 601 | var result 602 | return (typeof name == 'string' && value === undefined) ? 603 | (this.length == 0 || this[0].nodeType !== 1 ? undefined : 604 | (name == 'value' && this[0].nodeName == 'INPUT') ? this.val() : 605 | (!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result 606 | ) : 607 | this.each(function(idx){ 608 | if (this.nodeType !== 1) return 609 | if (isObject(name)) for (key in name) setAttribute(this, key, name[key]) 610 | else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name))) 611 | }) 612 | }, 613 | removeAttr: function(name){ 614 | return this.each(function(){ this.nodeType === 1 && setAttribute(this, name) }) 615 | }, 616 | prop: function(name, value){ 617 | name = propMap[name] || name 618 | return (value === undefined) ? 619 | (this[0] && this[0][name]) : 620 | this.each(function(idx){ 621 | this[name] = funcArg(this, value, idx, this[name]) 622 | }) 623 | }, 624 | data: function(name, value){ 625 | var data = this.attr('data-' + name.replace(capitalRE, '-$1').toLowerCase(), value) 626 | return data !== null ? deserializeValue(data) : undefined 627 | }, 628 | val: function(value){ 629 | return arguments.length === 0 ? 630 | (this[0] && (this[0].multiple ? 631 | $(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') : 632 | this[0].value) 633 | ) : 634 | this.each(function(idx){ 635 | this.value = funcArg(this, value, idx, this.value) 636 | }) 637 | }, 638 | offset: function(coordinates){ 639 | if (coordinates) return this.each(function(index){ 640 | var $this = $(this), 641 | coords = funcArg(this, coordinates, index, $this.offset()), 642 | parentOffset = $this.offsetParent().offset(), 643 | props = { 644 | top: coords.top - parentOffset.top, 645 | left: coords.left - parentOffset.left 646 | } 647 | 648 | if ($this.css('position') == 'static') props['position'] = 'relative' 649 | $this.css(props) 650 | }) 651 | if (this.length==0) return null 652 | var obj = this[0].getBoundingClientRect() 653 | return { 654 | left: obj.left + window.pageXOffset, 655 | top: obj.top + window.pageYOffset, 656 | width: Math.round(obj.width), 657 | height: Math.round(obj.height) 658 | } 659 | }, 660 | css: function(property, value){ 661 | if (arguments.length < 2) { 662 | var element = this[0], computedStyle = getComputedStyle(element, '') 663 | if(!element) return 664 | if (typeof property == 'string') 665 | return element.style[camelize(property)] || computedStyle.getPropertyValue(property) 666 | else if (isArray(property)) { 667 | var props = {} 668 | $.each(isArray(property) ? property: [property], function(_, prop){ 669 | props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop)) 670 | }) 671 | return props 672 | } 673 | } 674 | 675 | var css = '' 676 | if (type(property) == 'string') { 677 | if (!value && value !== 0) 678 | this.each(function(){ this.style.removeProperty(dasherize(property)) }) 679 | else 680 | css = dasherize(property) + ":" + maybeAddPx(property, value) 681 | } else { 682 | for (key in property) 683 | if (!property[key] && property[key] !== 0) 684 | this.each(function(){ this.style.removeProperty(dasherize(key)) }) 685 | else 686 | css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';' 687 | } 688 | 689 | return this.each(function(){ this.style.cssText += ';' + css }) 690 | }, 691 | index: function(element){ 692 | return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0]) 693 | }, 694 | hasClass: function(name){ 695 | if (!name) return false 696 | return emptyArray.some.call(this, function(el){ 697 | return this.test(className(el)) 698 | }, classRE(name)) 699 | }, 700 | addClass: function(name){ 701 | if (!name) return this 702 | return this.each(function(idx){ 703 | classList = [] 704 | var cls = className(this), newName = funcArg(this, name, idx, cls) 705 | newName.split(/\s+/g).forEach(function(klass){ 706 | if (!$(this).hasClass(klass)) classList.push(klass) 707 | }, this) 708 | classList.length && className(this, cls + (cls ? " " : "") + classList.join(" ")) 709 | }) 710 | }, 711 | removeClass: function(name){ 712 | return this.each(function(idx){ 713 | if (name === undefined) return className(this, '') 714 | classList = className(this) 715 | funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){ 716 | classList = classList.replace(classRE(klass), " ") 717 | }) 718 | className(this, classList.trim()) 719 | }) 720 | }, 721 | toggleClass: function(name, when){ 722 | if (!name) return this 723 | return this.each(function(idx){ 724 | var $this = $(this), names = funcArg(this, name, idx, className(this)) 725 | names.split(/\s+/g).forEach(function(klass){ 726 | (when === undefined ? !$this.hasClass(klass) : when) ? 727 | $this.addClass(klass) : $this.removeClass(klass) 728 | }) 729 | }) 730 | }, 731 | scrollTop: function(value){ 732 | if (!this.length) return 733 | var hasScrollTop = 'scrollTop' in this[0] 734 | if (value === undefined) return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset 735 | return this.each(hasScrollTop ? 736 | function(){ this.scrollTop = value } : 737 | function(){ this.scrollTo(this.scrollX, value) }) 738 | }, 739 | scrollLeft: function(value){ 740 | if (!this.length) return 741 | var hasScrollLeft = 'scrollLeft' in this[0] 742 | if (value === undefined) return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset 743 | return this.each(hasScrollLeft ? 744 | function(){ this.scrollLeft = value } : 745 | function(){ this.scrollTo(value, this.scrollY) }) 746 | }, 747 | position: function() { 748 | if (!this.length) return 749 | 750 | var elem = this[0], 751 | // Get *real* offsetParent 752 | offsetParent = this.offsetParent(), 753 | // Get correct offsets 754 | offset = this.offset(), 755 | parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset() 756 | 757 | // Subtract element margins 758 | // note: when an element has margin: auto the offsetLeft and marginLeft 759 | // are the same in Safari causing offset.left to incorrectly be 0 760 | offset.top -= parseFloat( $(elem).css('margin-top') ) || 0 761 | offset.left -= parseFloat( $(elem).css('margin-left') ) || 0 762 | 763 | // Add offsetParent borders 764 | parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0 765 | parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0 766 | 767 | // Subtract the two offsets 768 | return { 769 | top: offset.top - parentOffset.top, 770 | left: offset.left - parentOffset.left 771 | } 772 | }, 773 | offsetParent: function() { 774 | return this.map(function(){ 775 | var parent = this.offsetParent || document.body 776 | while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static") 777 | parent = parent.offsetParent 778 | return parent 779 | }) 780 | } 781 | } 782 | 783 | // for now 784 | $.fn.detach = $.fn.remove 785 | 786 | // Generate the `width` and `height` functions 787 | ;['width', 'height'].forEach(function(dimension){ 788 | var dimensionProperty = 789 | dimension.replace(/./, function(m){ return m[0].toUpperCase() }) 790 | 791 | $.fn[dimension] = function(value){ 792 | var offset, el = this[0] 793 | if (value === undefined) return isWindow(el) ? el['inner' + dimensionProperty] : 794 | isDocument(el) ? el.documentElement['scroll' + dimensionProperty] : 795 | (offset = this.offset()) && offset[dimension] 796 | else return this.each(function(idx){ 797 | el = $(this) 798 | el.css(dimension, funcArg(this, value, idx, el[dimension]())) 799 | }) 800 | } 801 | }) 802 | 803 | function traverseNode(node, fun) { 804 | fun(node) 805 | for (var key in node.childNodes) traverseNode(node.childNodes[key], fun) 806 | } 807 | 808 | // Generate the `after`, `prepend`, `before`, `append`, 809 | // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods. 810 | adjacencyOperators.forEach(function(operator, operatorIndex) { 811 | var inside = operatorIndex % 2 //=> prepend, append 812 | 813 | $.fn[operator] = function(){ 814 | // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings 815 | var argType, nodes = $.map(arguments, function(arg) { 816 | argType = type(arg) 817 | return argType == "object" || argType == "array" || arg == null ? 818 | arg : zepto.fragment(arg) 819 | }), 820 | parent, copyByClone = this.length > 1 821 | if (nodes.length < 1) return this 822 | 823 | return this.each(function(_, target){ 824 | parent = inside ? target : target.parentNode 825 | 826 | // convert all methods to a "before" operation 827 | target = operatorIndex == 0 ? target.nextSibling : 828 | operatorIndex == 1 ? target.firstChild : 829 | operatorIndex == 2 ? target : 830 | null 831 | 832 | nodes.forEach(function(node){ 833 | if (copyByClone) node = node.cloneNode(true) 834 | else if (!parent) return $(node).remove() 835 | 836 | traverseNode(parent.insertBefore(node, target), function(el){ 837 | if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' && 838 | (!el.type || el.type === 'text/javascript') && !el.src) 839 | window['eval'].call(window, el.innerHTML) 840 | }) 841 | }) 842 | }) 843 | } 844 | 845 | // after => insertAfter 846 | // prepend => prependTo 847 | // before => insertBefore 848 | // append => appendTo 849 | $.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){ 850 | $(html)[operator](this) 851 | return this 852 | } 853 | }) 854 | 855 | zepto.Z.prototype = $.fn 856 | 857 | // Export internal API functions in the `$.zepto` namespace 858 | zepto.uniq = uniq 859 | zepto.deserializeValue = deserializeValue 860 | $.zepto = zepto 861 | 862 | return $ 863 | })() 864 | 865 | // If `$` is not yet defined, point it to `Zepto` 866 | window.Zepto = Zepto 867 | window.$ === undefined && (window.$ = Zepto) 868 | 869 | }); 870 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /styles/prompt.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningtgc/MaterialUI/00141d8eb4f3ac9afe5c124b6d4b0809348e779f/styles/prompt.css --------------------------------------------------------------------------------