Created
January 31, 2014 19:14
-
-
Save kvofreelance/8740990 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a module | |
angular.module('inFoodApp', ['ngTouch', 'ui.router.compat', 'angular-gestures', 'infinite-scroll', 'angular-carousel', | |
'ui.bootstrap']); /*, 'siyfion.sfTypeahead'*/ | |
//This configures the routes and associates each route with a view and a controller | |
angular.module('inFoodApp').config([ | |
"$stateProvider", | |
"$urlRouterProvider", | |
function ($stateProvider, $urlRouterProvider) { | |
var apiVersion = 1; | |
// | |
// For any unmatched url, send to /route1 | |
$urlRouterProvider.otherwise( "/listresult" ); | |
// | |
// Now set up the states | |
$stateProvider | |
.state("layout", { | |
abstract: true, | |
template: "<ui-view/>", | |
views: { | |
"layout" : { | |
templateUrl: "layout.html" | |
}, | |
"header": { | |
templateUrl: "header.html", | |
controller: "headerController" | |
}, | |
"footer": { | |
templateUrl: "footer.html", | |
controller: "footerController" | |
} | |
} | |
}) | |
.state('layout.information', { | |
url: "/information/:barcode", | |
views: { | |
"content" : { | |
templateUrl: "information.html", | |
controller: "informationController", | |
resolve: { | |
isProduct: function(srvLibrary) { | |
return srvLibrary.getIsProduct(); | |
} | |
} | |
} | |
} | |
}) | |
.state('layout.detail', { | |
url: "/detail/:barcode", | |
views: { | |
"content" : { | |
templateUrl: "detail.html", | |
controller: "detailController" | |
} | |
} | |
}) | |
.state('layout.photo', { | |
url: "/photo/:barcode", | |
views: { | |
"content" : { | |
templateUrl: "photo.html", | |
controller: "pleasePhotoController" | |
} | |
} | |
}) | |
.state('layout.statistic', { | |
url: "/statistic", | |
views: { | |
"content" : { | |
templateUrl: "statistic.html", | |
controller: "statisticController" | |
} | |
} | |
}) | |
.state('layout.history', { | |
url: "/history/:barcode", | |
views: { | |
"content" : { | |
templateUrl: "history.html", | |
controller: "historyController" | |
} | |
} | |
}) | |
.state('layout.listresult', { | |
url: "/listresult", | |
views: { | |
"content" : { | |
templateUrl: "listresult.html", | |
controller: "listresultController" | |
} | |
} | |
}) | |
.state("layout.listresult.ingridients", { | |
url: "/ingridients", | |
views: { | |
"listresultDetailed": { | |
templateUrl: "ingridients.html", | |
controller: "ingridientsController" | |
} | |
} | |
}) | |
.state("layout.listresult.products", { | |
url: "/products", | |
views: { | |
"listresultDetailed": { | |
templateUrl: "products.html", | |
controller: "productsController" | |
} | |
} | |
}) | |
.state('layout.ingridientsDetail', { | |
url: "/ingridientsDetail", | |
views: { | |
"content" : { | |
templateUrl: "ingridientsDetail.html", | |
controller: "ingridientsDetailController" | |
} | |
} | |
}) | |
.state('layout.productsDetail', { | |
url: "/productsDetail", | |
views: { | |
"content" : { | |
templateUrl: "productsDetail.html", | |
controller: "productsDetailController" | |
} | |
} | |
}); | |
} | |
]) | |
.directive('onScroll', function () { | |
return function (scope, element, attrs) { | |
console.log("onScroll"); | |
return $(element).hammer({ | |
prevent_default: false, | |
drag_vertical: false | |
}) | |
.bind("drag", function (ev) { | |
console.log("MOVE"); | |
console.log(element.offset()); | |
var offset = element.offset(); | |
var displayWidth = $(window).width(); | |
var imagesSize = 4; | |
var widthElement = displayWidth/2; | |
var fullWidth = widthElement*imagesSize; | |
var current = (fullWidth + offset.left)/widthElement; | |
var intValue = Math.floor( current ); | |
console.log('********'); | |
console.log(current); | |
console.log(offset.left); | |
/* console.log(fullWidth); | |
console.log(widthElement); | |
console.log(imagesSize);*/ | |
console.log('********'); | |
if(current - intValue < 0.5) { | |
// $scope.$apply(function(){ | |
if(current < 2.2) { | |
// $scope.activeId = $scope.imagesSize-1; | |
scope.$apply(scope.activeId = imagesSize-1); | |
console.log("Active id"); | |
console.log(imagesSize-1); | |
} else { | |
scope.activeId = imagesSize-intValue; | |
//$scope.activeId = $scope.imagesSize - intValue; | |
scope.$apply(scope.activeId = scope.imagesSize - intValue); | |
console.log("Active id"); | |
console.log(imagesSize - intValue); | |
console.log(imagesSize - intValue); | |
//alert(imagesSize - intValue); | |
} | |
} | |
return scope.$apply(attrs['onTap']); | |
}); | |
}; | |
}); | |
angular.module('inFoodApp').run([ | |
"$rootScope", | |
"$templateCache", | |
"$http", | |
function($rootScope, $templateCache, $http){ | |
$rootScope.loadingListView = false; | |
$rootScope.$on('$stateChangeStart', function(e, curr, prev) { | |
if (curr.$$route && curr.$$route.resolve) { | |
// Show a loading message until promises are not resolved | |
console.log("STATE CHANGE to true"); | |
$rootScope.loadingView = true; | |
} | |
}); | |
$rootScope.$on('$stateChangeSuccess', function(e, curr, prev) { | |
console.log("STATE CHANGE to false"); | |
// Hide loading message | |
$rootScope.loadingView = false; | |
}); | |
$http.get('partials/detail.html') | |
.success(function(html) { | |
$templateCache.put('detail.html', html); | |
}); | |
$http.get('partials/footer.html') | |
.success(function(html) { | |
$templateCache.put('footer.html', html); | |
}); | |
$http.get('partials/header.html') | |
.success(function(html) { | |
$templateCache.put('header.html', html); | |
}); | |
$http.get('partials/history.html') | |
.success(function(html) { | |
$templateCache.put('history.html', html); | |
}); | |
$http.get('partials/information.html') | |
.success(function(html) { | |
console.log(html); | |
$templateCache.put('information.html', html); | |
}); | |
$http.get('partials/ingridients.html') | |
.success(function(html) { | |
$templateCache.put('ingridients.html', html); | |
}); | |
$http.get('partials/ingridientsDetail.html') | |
.success(function(html) { | |
$templateCache.put('ingridientsDetail.html', html); | |
}); | |
$http.get('partials/layout.html') | |
.success(function(html) { | |
$templateCache.put('layout.html', html); | |
}); | |
$http.get('partials/listresult.html') | |
.success(function(html) { | |
$templateCache.put('listresult.html', html); | |
}); | |
$http.get('partials/photo.html') | |
.success(function(html) { | |
$templateCache.put('photo.html', html); | |
}); | |
$http.get('partials/products.html') | |
.success(function(html) { | |
$templateCache.put('products.html', html); | |
}); | |
$http.get('partials/productsDetail.html') | |
.success(function(html) { | |
$templateCache.put('productsDetail.html', html); | |
}); | |
$http.get('partials/statistic.html') | |
.success(function(html) { | |
$templateCache.put('statistic.html', html); | |
}); | |
} | |
]); | |
function onLoad() { | |
document.addEventListener("deviceready", onDeviceReady, false); | |
onDeviceReady(); | |
} | |
var isHidden = true; | |
function showKeyboard() { | |
//alert('Show keyboard'); | |
$('#navbarElement').hide(); | |
$('#centralbtnElement').hide(); | |
$('#footer').hide(); | |
$('.infood-header').css({position:'absolute'}); | |
$('#main_header').css({position:'absolute'}); | |
} | |
function hideKeyboard() { | |
window.scrollBy(0,5); | |
$('#footer').css({position:'fixed'}); | |
$('#navbarElement').show(); | |
$('#centralbtnElement').show(); | |
$('#footer').show(); | |
$('.infood-header').css({position:'fixed'}); | |
$('#main_header').css({position:'fixed'}); | |
} | |
function onDeviceReady() { | |
angular.bootstrap(document, ["fakeServer"]); | |
navigator.splashscreen.hide(); | |
console.log('Hide splashscreen'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment