Skip to content

Instantly share code, notes, and snippets.

@aldesantis
Created April 19, 2015 17:17
Show Gist options
  • Save aldesantis/4a9437c7859896b0074d to your computer and use it in GitHub Desktop.
Save aldesantis/4a9437c7859896b0074d to your computer and use it in GitHub Desktop.
var myApp = angular.module('myApp');
myApp.directive('selectPicker', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
$(element).selectpicker();
$(element).change(function() {
if ($(this).val() === '' || $(this).val() === null) {
$(this).selectpicker('setStyle', 'btn-success', 'remove');
} else {
$(this).selectpicker('setStyle', 'btn-success', 'add');
}
});
}
};
});
myApp.directive('datePicker', function() {
var updateDatePicker = function() {
var inputGroup = $(this).parents('.input-group');
if ($(this).val() === '' || $(this).val() === null) {
inputGroup.removeClass('input-group-success');
} else {
inputGroup.addClass('input-group-success');
}
};
return {
restrict: 'A',
link: function(scope, element, attrs) {
$(element).datepicker();
$(element)
.on('changeDate', updateDatePicker)
.change(updateDatePicker)
.blur(updateDatePicker);
}
};
});
myApp.directive('toggleHandle', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
$(element).click(function() {
$(attrs.handleTarget).toggle();
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment