Skip to content

Instantly share code, notes, and snippets.

@MarZab
Created June 8, 2014 12:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarZab/30271307aa639b3468ce to your computer and use it in GitHub Desktop.
Save MarZab/30271307aa639b3468ce to your computer and use it in GitHub Desktop.
/*
* angular-ubilabs-geocomplete
* (c) 2014 Marko Zabreznik http://zabreznik.net
* License: MIT
*/
/*
* What is it: a simple factory that lazy loads google geo maps and ubilabs jquery.geocomplete.js
*
* You need: Angular, jQuery and Underscore
*
* Usage:
function (ulGeo) { // directive/controller
ulGeo().then(
function () {
// google maps and ubilabs geocomplete have loaded
},
function(m) {
// error
}
);
}
*/
angular.module('ub')
.factory("ulGeo", ['$window', '$q', function ($window, $q) {
var deferred = $q.defer();
// start socket
var load = _.once(function () {
$window.loadgeocomplete = function () {
$.getScript('/bower_components/ubilabs-geocomplete/jquery.geocomplete.min.js')
.done(function () { deferred.resolve(); })
.fail(function () { deferred.reject('could not load ubilabs geocomplete'); });
delete $window.loadgeocomplete;
};
// we need to wait for google maps to do its thing, it'll call loadgeocomplete when its done
$.getScript('http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&callback=loadgeocomplete')
.fail(function () { deferred.reject('could not load google maps'); });
});
return function () {
load();
return deferred.promise;
};
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment