X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=app%2Fjs%2Fdirectives.js;h=ac273fe5909f09ae46ba46a316b2cc163f099fda;hb=3b3aab3a072bc2ad0dc4bc18f951948d02045cde;hp=9fc16cc4cbc0ad7bf164726da5c3d9f267c92204;hpb=11e1695154127e28964687149bd24a8922bc38b6;p=angular-drzb
diff --git a/app/js/directives.js b/app/js/directives.js
index 9fc16cc..ac273fe 100644
--- a/app/js/directives.js
+++ b/app/js/directives.js
@@ -8,4 +8,121 @@ angular.module('myApp.directives', []).
return function(scope, elm, attrs) {
elm.text(version);
};
- }]);
+ }]).
+ directive('myInput', function() {
+ return {
+ restrict: 'C',
+ compile: function(element, attrs) {
+ var my_class = attrs['class'] || '';
+ my_class = my_class.replace(/ *my-input */,'');
+ var my_type = attrs['type'] || 'text';
+ var html = '
'
+ +''
+ +'
';
+ element.replaceWith(html);
+ }
+ };
+ }).
+
+directive('myLabelInput', function() {
+ return {
+ restrict: 'C',
+ compile: function(element, attrs) {
+ var my_class = attrs['class'] || '';
+ my_class = my_class.replace(/ *my-input */,'');
+ var my_type = attrs['type'] || 'text';
+ var m = attrs.ngModel;
+ var html =
+' '+
+'
'+
+'
'+
+' '+
+'
'+
+'
';
+
+ element.replaceWith(html);
+ }
+ };
+})
+
+.directive('myLabelSelect', function() {
+ return {
+ restrict: 'C',
+ compile: function(element, attrs) {
+ var my_class = attrs['class'] || '';
+ my_class = my_class.replace(/ *my-input */,'');
+ var m = attrs.ngModel;
+ var html =
+' '+
+'
'+
+'
'+
+' '+
+'
'+
+'
';
+
+ element.replaceWith(html);
+ }
+ };
+})
+
+.directive('bsTypeahead', ['$parse', function($parse) {
+ 'use strict';
+
+ return {
+ restrict: 'A',
+ require: '?ngModel',
+ link: function postLink(scope, element, attr, controller) {
+
+ var getter = $parse(attr.bsTypeahead),
+ setter = getter.assign,
+ value = getter(scope);
+
+ // Watch bsTypeahead for changes
+ scope.$watch(attr.bsTypeahead, function(newValue, oldValue) {
+ if(newValue !== oldValue) {
+ value = newValue;
+ }
+ });
+
+ element.attr('data-provide', 'typeahead');
+ element.typeahead({
+ source: function(query) { return value; },
+ items: attr.items,
+ updater: function(value) {
+ // If we have a controller (i.e. ngModelController) then wire it up
+ if(controller) {
+ scope.$apply(function () {
+ controller.$setViewValue(value);
+ });
+ }
+ return value;
+ }
+ });
+
+ // add entered element into typeahead array for other fields
+ element.bind('blur', function() {
+ var new_value = element.val();
+ if ( new_value.length > 1 && $.inArray( new_value, value ) === -1 ) { // IE doesn't have .indexOf
+ scope.$apply( function() {
+ value.unshift( element.val() );
+ });
+ }
+ });
+
+ }
+ };
+}])
+;