move stuff to js/utils

This commit is contained in:
Adam Bradley
2013-10-01 10:45:20 -05:00
parent 7386f3f468
commit a0a720988d
9 changed files with 166 additions and 167 deletions

View File

@ -10,24 +10,21 @@ module.exports = function(grunt) {
dist: { dist: {
src: [ src: [
// Base
'js/ionic.js', 'js/ionic.js',
'js/platform.js',
'js/utils.js',
'js/events.js',
'js/gestures.js',
'js/animate.js',
'js/viewController.js', // Utils
'js/utils/**/*.js',
// Views
'js/views/navBarView.js', 'js/views/navBarView.js',
'js/views/headerBarView.js', 'js/views/headerBarView.js',
'js/views/sideMenuView.js', 'js/views/sideMenuView.js',
'js/views/tabBarView.js', 'js/views/tabBarView.js',
'js/views/toggleView.js', 'js/views/toggleView.js',
'js/controllers/**/*.js', // Controllers
'js/controllers/**/*.js'
'js/tapPolyfill.js'
], ],
dest: 'dist/<%= pkg.name %>.js' dest: 'dist/<%= pkg.name %>.js'

305
dist/ionic.js vendored
View File

@ -4,67 +4,50 @@ window.ionic = {
controllers: {}, controllers: {},
views: {} views: {}
}; };
;(function(ionic) { ;
(function(ionic) {
ionic.Animator = {
animate: function(element, className, fn) {
return {
leave: function() {
var endFunc = function() {
console.log('Animation finished for element', element);
ionic.Platform = { element.classList.remove('leave');
detect: function() { element.classList.remove('leave-active');
var platforms = [];
this._checkPlatforms(platforms); element.removeEventListener('webkitTransitionEnd', endFunc);
element.removeEventListener('transitionEnd', endFunc);
for(var i = 0; i < platforms.length; i++) { };
document.body.classList.add('platform-' + platforms[i]); element.addEventListener('webkitTransitionEnd', endFunc);
} element.addEventListener('transitionEnd', endFunc);
element.classList.add('leave');
element.classList.add('leave-active');
return this;
}, },
_checkPlatforms: function(platforms) { enter: function() {
if(this.isCordova()) { var endFunc = function() {
platforms.push('cordova'); console.log('Animation finished for element', element);
}
if(this.isIOS7()) {
platforms.push('ios7');
}
},
// Check if we are running in Cordova, which will have element.classList.remove('enter');
// window.device available. element.classList.remove('enter-active');
isCordova: function() {
return (window.cordova || window.PhoneGap || window.phonegap);
//&& /^file:\/{3}[^\/]/i.test(window.location.href)
//&& /ios|iphone|ipod|ipad|android/i.test(navigator.userAgent);
},
isIOS7: function() {
if(!window.device) {
return false;
}
return parseFloat(window.device.version) >= 7.0;
}
}
ionic.Platform.detect(); element.removeEventListener('webkitTransitionEnd', endFunc);
})(window.ionic); element.removeEventListener('transitionEnd', endFunc);
;(function(ionic) { };
element.addEventListener('webkitTransitionEnd', endFunc);
element.addEventListener('transitionEnd', endFunc);
ionic.Utils = { element.classList.add('enter');
/** element.classList.add('enter-active');
* extend method,
* also used for cloning when dest is an empty object return this;
* @param {Object} dest
* @param {Object} src
* @parm {Boolean} merge do a merge
* @returns {Object} dest
*/
extend: function extend(dest, src, merge) {
for (var key in src) {
if(dest[key] !== undefined && merge) {
continue;
} }
dest[key] = src[key]; };
} }
return dest; };
}, })(ionic);
}
})(window.ionic);
;/** ;/**
* ion-events.js * ion-events.js
* *
@ -1612,61 +1595,121 @@ window.ionic = {
}; };
})(window.ionic); })(window.ionic);
;(function(ionic) { ;(function(ionic) {
ionic.Animator = {
animate: function(element, className, fn) {
return {
leave: function() {
var endFunc = function() {
console.log('Animation finished for element', element);
element.classList.remove('leave'); ionic.Platform = {
element.classList.remove('leave-active'); detect: function() {
var platforms = [];
element.removeEventListener('webkitTransitionEnd', endFunc); this._checkPlatforms(platforms);
element.removeEventListener('transitionEnd', endFunc);
}; for(var i = 0; i < platforms.length; i++) {
element.addEventListener('webkitTransitionEnd', endFunc); document.body.classList.add('platform-' + platforms[i]);
element.addEventListener('transitionEnd', endFunc); }
element.classList.add('leave');
element.classList.add('leave-active');
return this;
}, },
enter: function() { _checkPlatforms: function(platforms) {
var endFunc = function() { if(this.isCordova()) {
console.log('Animation finished for element', element); platforms.push('cordova');
element.classList.remove('enter');
element.classList.remove('enter-active');
element.removeEventListener('webkitTransitionEnd', endFunc);
element.removeEventListener('transitionEnd', endFunc);
};
element.addEventListener('webkitTransitionEnd', endFunc);
element.addEventListener('transitionEnd', endFunc);
element.classList.add('enter');
element.classList.add('enter-active');
return this;
} }
}; if(this.isIOS7()) {
platforms.push('ios7');
} }
}; },
// Check if we are running in Cordova, which will have
// window.device available.
isCordova: function() {
return (window.cordova || window.PhoneGap || window.phonegap);
//&& /^file:\/{3}[^\/]/i.test(window.location.href)
//&& /ios|iphone|ipod|ipad|android/i.test(navigator.userAgent);
},
isIOS7: function() {
if(!window.device) {
return false;
}
return parseFloat(window.device.version) >= 7.0;
}
}
ionic.Platform.detect();
})(window.ionic); })(window.ionic);
;(function(ionic) { ;(function(window, document, ionic) {
ionic.ViewController = function(options) {
this.init();
};
ionic.ViewController.prototype = { // polyfill use to simulate native "tap"
// Initialize this view controller function inputTapPolyfill(ele, e) {
init: function() { if(ele.type === "radio" || ele.type === "checkbox") {
}, ele.checked = !ele.checked;
// Destroy this view controller, including all child views } else if(ele.type === "submit" || ele.type === "button") {
destroy: function() { ele.click();
} else {
ele.focus();
}
e.stopPropagation();
e.preventDefault();
return false;
}
function tapPolyfill(e) {
// if the source event wasn't from a touch event then don't use this polyfill
if(!e.gesture || e.gesture.pointerType !== "touch" || !e.gesture.srcEvent) return;
var
e = e.gesture.srcEvent, // evaluate the actual source event, not the created event by gestures.js
ele = e.target;
while(ele) {
if( ele.tagName === "INPUT" || ele.tagName === "TEXTAREA" || ele.tagName === "SELECT" ) {
return inputTapPolyfill(ele, e);
} else if( ele.tagName === "LABEL" ) {
if(ele.control) {
return inputTapPolyfill(ele.control, e);
}
} else if( ele.tagName === "A" || ele.tagName === "BUTTON" ) {
ele.click();
e.stopPropagation();
e.preventDefault();
return false;
}
ele = ele.parentElement;
}
// they didn't tap one of the above elements
// if the currently active element is an input, and they tapped outside
// of the current input, then unset its focus (blur) so the keyboard goes away
var activeElement = document.activeElement;
if(activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA" || activeElement.tagName === "SELECT")) {
activeElement.blur();
e.stopPropagation();
e.preventDefault();
return false;
}
}
// global tap event listener polyfill for HTML elements that were "tapped" by the user
ionic.on("tap", tapPolyfill, window);
})(this, document, ionic);
;(function(ionic) {
ionic.Utils = {
/**
* extend method,
* also used for cloning when dest is an empty object
* @param {Object} dest
* @param {Object} src
* @parm {Boolean} merge do a merge
* @returns {Object} dest
*/
extend: function extend(dest, src, merge) {
for (var key in src) {
if(dest[key] !== undefined && merge) {
continue;
}
dest[key] = src[key];
}
return dest;
},
} }
};
})(window.ionic); })(window.ionic);
; ;
(function(ionic) { (function(ionic) {
@ -2575,59 +2618,17 @@ ionic.controllers.TabBarController.prototype = {
} }
})(ionic = window.ionic || {}); })(ionic = window.ionic || {});
;(function(window, document, ionic) { ;(function(ionic) {
ionic.ViewController = function(options) {
this.init();
};
// polyfill use to simulate native "tap" ionic.ViewController.prototype = {
function inputTapPolyfill(ele, e) { // Initialize this view controller
if(ele.type === "radio" || ele.type === "checkbox") { init: function() {
ele.checked = !ele.checked; },
} else if(ele.type === "submit" || ele.type === "button") { // Destroy this view controller, including all child views
ele.click(); destroy: function() {
} else {
ele.focus();
} }
e.stopPropagation(); };
e.preventDefault(); })(window.ionic);
return false;
}
function tapPolyfill(e) {
// if the source event wasn't from a touch event then don't use this polyfill
if(!e.gesture || e.gesture.pointerType !== "touch" || !e.gesture.srcEvent) return;
var
e = e.gesture.srcEvent, // evaluate the actual source event, not the created event by gestures.js
ele = e.target;
while(ele) {
if( ele.tagName === "INPUT" || ele.tagName === "TEXTAREA" || ele.tagName === "SELECT" ) {
return inputTapPolyfill(ele, e);
} else if( ele.tagName === "LABEL" ) {
if(ele.control) {
return inputTapPolyfill(ele.control, e);
}
} else if( ele.tagName === "A" || ele.tagName === "BUTTON" ) {
ele.click();
e.stopPropagation();
e.preventDefault();
return false;
}
ele = ele.parentElement;
}
// they didn't tap one of the above elements
// if the currently active element is an input, and they tapped outside
// of the current input, then unset its focus (blur) so the keyboard goes away
var activeElement = document.activeElement;
if(activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA" || activeElement.tagName === "SELECT")) {
activeElement.blur();
e.stopPropagation();
e.preventDefault();
return false;
}
}
// global tap event listener polyfill for HTML elements that were "tapped" by the user
ionic.on("tap", tapPolyfill, window);
})(this, document, ionic);

View File

@ -1,3 +1,4 @@
(function(ionic) { (function(ionic) {
ionic.Animator = { ionic.Animator = {
animate: function(element, className, fn) { animate: function(element, className, fn) {
@ -40,4 +41,4 @@
}; };
} }
}; };
})(window.ionic); })(ionic);