Created
June 8, 2014 12:43
-
-
Save MarZab/30271307aa639b3468ce 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
/* | |
* 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