X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=app%2Fjs%2Fdirectives.js;h=ac273fe5909f09ae46ba46a316b2cc163f099fda;hb=3b3aab3a072bc2ad0dc4bc18f951948d02045cde;hp=fb7b81e3f4df15a2642ca0e7821cec960e0ab7bd;hpb=5273e22cbd006b0b6658e69b4984b619c6657926;p=angular-drzb
diff --git a/app/js/directives.js b/app/js/directives.js
index fb7b81e..ac273fe 100644
--- a/app/js/directives.js
+++ b/app/js/directives.js
@@ -14,13 +14,115 @@ angular.module('myApp.directives', []).
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() );
+ });
+ }
+ });
+
+ }
+ };
+}])
+;