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: {
src: [
// Base
'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/headerBarView.js',
'js/views/sideMenuView.js',
'js/views/tabBarView.js',
'js/views/toggleView.js',
'js/controllers/**/*.js',
'js/tapPolyfill.js'
// Controllers
'js/controllers/**/*.js'
],
dest: 'dist/<%= pkg.name %>.js'

305
dist/ionic.js vendored
View File

@ -4,67 +4,50 @@ window.ionic = {
controllers: {},
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 = {
detect: function() {
var platforms = [];
element.classList.remove('leave');
element.classList.remove('leave-active');
this._checkPlatforms(platforms);
for(var i = 0; i < platforms.length; i++) {
document.body.classList.add('platform-' + platforms[i]);
}
element.removeEventListener('webkitTransitionEnd', endFunc);
element.removeEventListener('transitionEnd', endFunc);
};
element.addEventListener('webkitTransitionEnd', endFunc);
element.addEventListener('transitionEnd', endFunc);
element.classList.add('leave');
element.classList.add('leave-active');
return this;
},
_checkPlatforms: function(platforms) {
if(this.isCordova()) {
platforms.push('cordova');
}
if(this.isIOS7()) {
platforms.push('ios7');
}
},
enter: function() {
var endFunc = function() {
console.log('Animation finished for element', element);
// 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;
}
}
element.classList.remove('enter');
element.classList.remove('enter-active');
ionic.Platform.detect();
})(window.ionic);
;(function(ionic) {
element.removeEventListener('webkitTransitionEnd', endFunc);
element.removeEventListener('transitionEnd', endFunc);
};
element.addEventListener('webkitTransitionEnd', endFunc);
element.addEventListener('transitionEnd', endFunc);
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;
element.classList.add('enter');
element.classList.add('enter-active');
return this;
}
dest[key] = src[key];
};
}
return dest;
},
}
})(window.ionic);
};
})(ionic);
;/**
* ion-events.js
*
@ -1612,61 +1595,121 @@ window.ionic = {
};
})(window.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');
element.classList.remove('leave-active');
ionic.Platform = {
detect: function() {
var platforms = [];
element.removeEventListener('webkitTransitionEnd', endFunc);
element.removeEventListener('transitionEnd', endFunc);
};
element.addEventListener('webkitTransitionEnd', endFunc);
element.addEventListener('transitionEnd', endFunc);
this._checkPlatforms(platforms);
for(var i = 0; i < platforms.length; i++) {
document.body.classList.add('platform-' + platforms[i]);
}
element.classList.add('leave');
element.classList.add('leave-active');
return this;
},
enter: function() {
var endFunc = function() {
console.log('Animation finished for element', element);
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;
_checkPlatforms: function(platforms) {
if(this.isCordova()) {
platforms.push('cordova');
}
};
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);
;(function(ionic) {
ionic.ViewController = function(options) {
this.init();
};
;(function(window, document, ionic) {
ionic.ViewController.prototype = {
// Initialize this view controller
init: function() {
},
// Destroy this view controller, including all child views
destroy: function() {
// polyfill use to simulate native "tap"
function inputTapPolyfill(ele, e) {
if(ele.type === "radio" || ele.type === "checkbox") {
ele.checked = !ele.checked;
} else if(ele.type === "submit" || ele.type === "button") {
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);
;
(function(ionic) {
@ -2575,59 +2618,17 @@ ionic.controllers.TabBarController.prototype = {
}
})(ionic = window.ionic || {});
;(function(window, document, ionic) {
;(function(ionic) {
ionic.ViewController = function(options) {
this.init();
};
// polyfill use to simulate native "tap"
function inputTapPolyfill(ele, e) {
if(ele.type === "radio" || ele.type === "checkbox") {
ele.checked = !ele.checked;
} else if(ele.type === "submit" || ele.type === "button") {
ele.click();
} else {
ele.focus();
ionic.ViewController.prototype = {
// Initialize this view controller
init: function() {
},
// Destroy this view controller, including all child views
destroy: function() {
}
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);
};
})(window.ionic);

View File

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