Skip to content

Instantly share code, notes, and snippets.

@anvaka
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anvaka/9848505 to your computer and use it in GitHub Desktop.
Save anvaka/9848505 to your computer and use it in GitHub Desktop.
requirebin sketch
document.onload = function () {
require('typeahead.an'); // we are going to use typeahead in this demo
require('an').controller(DemoCtrl);
var module = require('an').flush(); // flush and bootstrap angular app
angular.bootstrap(document.body, [module.name]);
function DemoCtrl($scope, $http) {
$scope.getLocation = function(val) {
return $http.get('http://maps.googleapis.com/maps/api/geocode/json', {
params: {
address: val,
sensor: false
}
}).then(function(res){
var addresses = [];
angular.forEach(res.data.results, function(item){
addresses.push(item.formatted_address);
});
return addresses;
});
};
}
}
require=function e(t,n,r){function i(a,c){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!c&&u)return u(a,!0);if(o)return o(a,!0);throw Error("Cannot find module '"+a+"'")}var f=n[a]={exports:{}};t[a][0].call(f.exports,function(e){var n=t[a][1][e];return i(n?n:e)},f,f.exports,e,t,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;r.length>a;a++)i(r[a]);return i}({1:[function(){},{}],XBG20T:[function(e,t){function n(t,n,r,i,o){var a=e("./lib/utils/position")(document,window),c=[9,13,27,38,40];return{require:"ngModel",link:function(u,f,s,l){var p,d=u.$eval(s.typeaheadMinLength)||1,h=u.$eval(s.typeaheadWaitMs)||0,m=u.$eval(s.typeaheadEditable)!==!1,v=n(s.typeaheadLoading).assign||angular.noop,g=n(s.typeaheadOnSelect),b=s.typeaheadInputFormatter?n(s.typeaheadInputFormatter):void 0,y=s.typeaheadAppendToBody?u.$eval(s.typeaheadAppendToBody):!1,x=n(s.ngModel).assign,w=e("./lib/parser")(n),$=w.parse(s.typeahead),E=angular.element("<div typeahead-popup></div>");E.attr({matches:"matches",active:"activeIdx",select:"select(activeIdx)",query:"query",position:"position"}),angular.isDefined(s.typeaheadTemplateUrl)&&E.attr("template-url",s.typeaheadTemplateUrl);var q=u.$new();u.$on("$destroy",function(){q.$destroy()});var N=function(){q.matches=[],q.activeIdx=-1},k=function(e){var t={$viewValue:e};v(u,!0),r.when($.source(u,t)).then(function(n){if(e===l.$viewValue&&p){if(n.length>0){q.activeIdx=0,q.matches.length=0;for(var r=0;n.length>r;r++)t[$.itemName]=n[r],q.matches.push({label:$.viewMapper(q,t),model:n[r]});q.query=e,q.position=y?a.offset(f):a.position(f),q.position.top=q.position.top+f.prop("offsetHeight")}else N();v(u,!1)}},function(){N(),v(u,!1)})};N(),q.query=void 0;var A;l.$parsers.unshift(function(e){return p=!0,e&&e.length>=d?h>0?(A&&i.cancel(A),A=i(function(){k(e)},h)):k(e):(v(u,!1),N()),m?e:e?(l.$setValidity("editable",!1),void 0):(l.$setValidity("editable",!0),e)}),l.$formatters.push(function(e){var t,n,r={};return b?(r.$model=e,b(u,r)):(r[$.itemName]=e,t=$.viewMapper(u,r),r[$.itemName]=void 0,n=$.viewMapper(u,r),t!==n?t:e)}),q.select=function(e){var t,n,r={};r[$.itemName]=n=q.matches[e].model,t=$.modelMapper(u,r),x(u,t),l.$setValidity("editable",!0),g(u,{$item:n,$model:t,$label:$.viewMapper(u,r)}),N(),f[0].focus()},f.bind("keydown",function(e){0!==q.matches.length&&-1!==c.indexOf(e.which)&&(e.preventDefault(),40===e.which?(q.activeIdx=(q.activeIdx+1)%q.matches.length,q.$digest()):38===e.which?(q.activeIdx=(q.activeIdx?q.activeIdx:q.matches.length)-1,q.$digest()):13===e.which||9===e.which?q.$apply(function(){q.select(q.activeIdx)}):27===e.which&&(e.stopPropagation(),N(),q.$digest()))}),f.bind("blur",function(){p=!1});var M=function(e){f[0]!==e.target&&(N(),q.$digest())};o.bind("click",M),u.$on("$destroy",function(){o.unbind("click",M)});var O=t(E)(q);y?o.find("body").append(O):f.after(O)}}}t.exports=n,e("./lib/popup"),e("an").directive(n)},{"./lib/parser":7,"./lib/popup":8,"./lib/utils/position":9,an:10}],"typeahead.an":[function(e,t){t.exports=e("XBG20T")},{}],4:[function(e,t){function n(){return function(e,t,n){t.addClass("ng-binding").data("$binding",n.bindHtmlUnsafe),e.$watch(n.bindHtmlUnsafe,function(e){t.html(e||"")})}}t.exports=n,e("an").directive(n)},{an:10}],5:[function(e,t){function n(){return function(e,t){return t?(""+e).replace(RegExp(r(t),"gi"),"<strong>$&</strong>"):e}}function r(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}t.exports=n,e("an").filter(n)},{an:10}],6:[function(e,t){function n(e,t,n,i){return{restrict:"EA",scope:{index:"=",match:"=",query:"="},link:function(o,a,c){function u(e){a.replaceWith(n(e.trim())(o))}var f=i(c.templateUrl)(o.$parent);f?e.get(f,{cache:t}).success(u):u(r)}}}t.exports=e("an").directive(n),e("./bindHtmlUnsafe"),e("fs");var r='<a tabindex="-1" bind-html-unsafe="match.label | highlightFilter:query"></a>\n'},{"./bindHtmlUnsafe":4,an:10,fs:1}],7:[function(e,t){t.exports=function(e){var t=/^\s*(.*?)(?:\s+as\s+(.*?))?\s+for\s+(?:([\$\w][\$\w\d]*))\s+in\s+(.*)$/;return{parse:function(n){var r=n.match(t);if(!r)throw Error('Expected typeahead specification in form of "_modelValue_ (as _label_)? for _item_ in _collection_" but got "'+n+'".');return{itemName:r[3],source:e(r[4]),viewMapper:e(r[2]||r[1]),modelMapper:e(r[1])}}}}},{}],8:[function(e,t){function n(){return{restrict:"EA",scope:{matches:"=",query:"=",active:"=",position:"=",select:"&"},replace:!0,template:'<ul class="dropdown-menu" ng-if="isOpen()" ng-style="{top: position.top+\'px\', left: position.left+\'px\'}" style="display: block;">\n <li ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)">\n <div typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>\n </li>\n</ul>\n',link:function(e,t,n){e.templateUrl=n.templateUrl,e.isOpen=function(){return e.matches.length>0},e.isActive=function(t){return e.active==t},e.selectActive=function(t){e.active=t},e.selectMatch=function(t){e.select({activeIdx:t})}}}}t.exports=n,e("./match"),e("./highlightFilter"),e("an").directive(n),e("fs")},{"./highlightFilter":5,"./match":6,an:10,fs:1}],9:[function(e,t){t.exports=function(e,t){function n(e,n){return e.currentStyle?e.currentStyle[n]:t.getComputedStyle?t.getComputedStyle(e)[n]:e.style[n]}function r(e){return"static"===(n(e,"position")||"static")}var i=function(t){for(var n=e,i=t.offsetParent||n;i&&i!==n&&r(i);)i=i.offsetParent;return i||n};return{position:function(t){var n=this.offset(t),r={top:0,left:0},o=i(t[0]);o!=e&&(r=this.offset(angular.element(o)),r.top+=o.clientTop-o.scrollTop,r.left+=o.clientLeft-o.scrollLeft);var a=t[0].getBoundingClientRect();return{width:a.width||t.prop("offsetWidth"),height:a.height||t.prop("offsetHeight"),top:n.top-r.top,left:n.left-r.left}},offset:function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e.documentElement.scrollTop),left:r.left+(t.pageXOffset||e.documentElement.scrollLeft)}},positionElements:function(e,t,n,r){var i,o,a,c,u=n.split("-"),f=u[0],s=u[1]||"center";i=r?this.offset(e):this.position(e),o=t.prop("offsetWidth"),a=t.prop("offsetHeight");var l={center:function(){return i.left+i.width/2-o/2},left:function(){return i.left},right:function(){return i.left+i.width}},p={center:function(){return i.top+i.height/2-a/2},top:function(){return i.top},bottom:function(){return i.top+i.height}};switch(f){case"right":c={top:p[s](),left:l[f]()};break;case"left":c={top:p[s](),left:i.left-o};break;case"bottom":c={top:p[f](),left:l[s]()};break;default:c={top:i.top-a,left:l[s]()}}return c}}}},{}],10:[function(e,t){function n(){return angular.module("anModule",[])}var r=e("./lib/directive"),i=e("./lib/controller"),o=e("./lib/filter");t.exports={directive:r.register,controller:i.register,filter:o.register,flush:function(e){return e||(e=n()),i.flush(e),r.flush(e),o.flush(e),e}}},{"./lib/controller":11,"./lib/directive":12,"./lib/filter":13}],11:[function(e,t,n){var r={};n.register=function(t,n){if(n=n||e("./functionName")(t),!n)throw Error("Anonymous functions cannot be registered as controllers. Please provide named function or pass second argument as controlelr name");return r[n]=t,t},n.flush=function(e){Object.keys(r).forEach(function(t){e.controller(t,r[t])})}},{"./functionName":14}],12:[function(e,t,n){var r={};n.register=function(t,n){if(n=n||e("./functionName")(t),!n)throw Error("Anonymous functions cannot be registered as directives. Please provide named function or pass second argument as directive name");return r[n]=t,t},n.flush=function(e){Object.keys(r).forEach(function(t){e.directive(t,r[t])})}},{"./functionName":14}],13:[function(e,t,n){var r={};n.register=function(t,n){if(n=n||e("./functionName")(t),!n)throw Error("Anonymous functions cannot be registered as filters. Please provide named function or pass second argument as filter name");return r[n]=t,t},n.flush=function(e){Object.keys(r).forEach(function(t){e.filter(t,r[t])})}},{"./functionName":14}],14:[function(e,t){t.exports=function(e){var t=""+e,n=t.match(/function\s+(\w+)/);return n&&n[1]}},{}]},{},[]),require=function e(t,n,r){function i(a,c){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!c&&u)return u(a,!0);if(o)return o(a,!0);throw Error("Cannot find module '"+a+"'")}var f=n[a]={exports:{}};t[a][0].call(f.exports,function(e){var n=t[a][1][e];return i(n?n:e)},f,f.exports,e,t,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;r.length>a;a++)i(r[a]);return i}({UilLsf:[function(e,t){function n(){return angular.module("anModule",[])}var r=e("./lib/directive"),i=e("./lib/controller"),o=e("./lib/filter");t.exports={directive:r.register,controller:i.register,filter:o.register,flush:function(e){return e||(e=n()),i.flush(e),r.flush(e),o.flush(e),e}}},{"./lib/controller":3,"./lib/directive":4,"./lib/filter":5}],an:[function(e,t){t.exports=e("UilLsf")},{}],3:[function(e,t,n){var r={};n.register=function(t,n){if(n=n||e("./functionName")(t),!n)throw Error("Anonymous functions cannot be registered as controllers. Please provide named function or pass second argument as controlelr name");return r[n]=t,t},n.flush=function(e){Object.keys(r).forEach(function(t){e.controller(t,r[t])})}},{"./functionName":6}],4:[function(e,t,n){var r={};n.register=function(t,n){if(n=n||e("./functionName")(t),!n)throw Error("Anonymous functions cannot be registered as directives. Please provide named function or pass second argument as directive name");return r[n]=t,t},n.flush=function(e){Object.keys(r).forEach(function(t){e.directive(t,r[t])})}},{"./functionName":6}],5:[function(e,t,n){var r={};n.register=function(t,n){if(n=n||e("./functionName")(t),!n)throw Error("Anonymous functions cannot be registered as filters. Please provide named function or pass second argument as filter name");return r[n]=t,t},n.flush=function(e){Object.keys(r).forEach(function(t){e.filter(t,r[t])})}},{"./functionName":6}],6:[function(e,t){t.exports=function(e){var t=""+e,n=t.match(/function\s+(\w+)/);return n&&n[1]}},{}]},{},[]),require=function e(t,n,r){function i(a,c){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!c&&u)return u(a,!0);if(o)return o(a,!0);throw Error("Cannot find module '"+a+"'")}var f=n[a]={exports:{}};t[a][0].call(f.exports,function(e){var n=t[a][1][e];return i(n?n:e)},f,f.exports,e,t,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;r.length>a;a++)i(r[a]);return i}({UilLsf:[function(e,t){function n(){return angular.module("anModule",[])}var r=e("./lib/directive"),i=e("./lib/controller"),o=e("./lib/filter");t.exports={directive:r.register,controller:i.register,filter:o.register,flush:function(e){return e||(e=n()),i.flush(e),r.flush(e),o.flush(e),e}}},{"./lib/controller":3,"./lib/directive":4,"./lib/filter":5}],an:[function(e,t){t.exports=e("UilLsf")},{}],3:[function(e,t,n){var r={};n.register=function(t,n){if(n=n||e("./functionName")(t),!n)throw Error("Anonymous functions cannot be registered as controllers. Please provide named function or pass second argument as controlelr name");return r[n]=t,t},n.flush=function(e){Object.keys(r).forEach(function(t){e.controller(t,r[t])})}},{"./functionName":6}],4:[function(e,t,n){var r={};n.register=function(t,n){if(n=n||e("./functionName")(t),!n)throw Error("Anonymous functions cannot be registered as directives. Please provide named function or pass second argument as directive name");return r[n]=t,t},n.flush=function(e){Object.keys(r).forEach(function(t){e.directive(t,r[t])})}},{"./functionName":6}],5:[function(e,t,n){var r={};n.register=function(t,n){if(n=n||e("./functionName")(t),!n)throw Error("Anonymous functions cannot be registered as filters. Please provide named function or pass second argument as filter name");return r[n]=t,t},n.flush=function(e){Object.keys(r).forEach(function(t){e.filter(t,r[t])})}},{"./functionName":6}],6:[function(e,t){t.exports=function(e){var t=""+e,n=t.match(/function\s+(\w+)/);return n&&n[1]}},{}]},{},[]),document.onload=function(){function e(e,t){e.getLocation=function(e){return t.get("http://maps.googleapis.com/maps/api/geocode/json",{params:{address:e,sensor:!1}}).then(function(e){var t=[];return angular.forEach(e.data.results,function(e){t.push(e.formatted_address)}),t})}}require("typeahead.an"),require("an").controller(e);var t=require("an").flush();angular.bootstrap(document.body,[t.name])};
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"typeahead.an": "0.0.4",
"an": "0.0.2"
}
}
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
<script>
console.log('hello');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment