ui-shift.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. angular.module('app')
  2. .directive('uiShift', ['$timeout', function($timeout) {
  3. return {
  4. restrict: 'A',
  5. link: function(scope, el, attr) {
  6. // get the $prev or $parent of this el
  7. var _el = $(el),
  8. _window = $(window),
  9. prev = _el.prev(),
  10. parent,
  11. width = _window.width()
  12. ;
  13. !prev.length && (parent = _el.parent());
  14. function sm(){
  15. $timeout(function () {
  16. var method = attr.uiShift;
  17. var target = attr.target;
  18. _el.hasClass('in') || _el[method](target).addClass('in');
  19. });
  20. }
  21. function md(){
  22. parent && parent['prepend'](el);
  23. !parent && _el['insertAfter'](prev);
  24. _el.removeClass('in');
  25. }
  26. (width < 768 && sm()) || md();
  27. _window.resize(function() {
  28. if(width !== _window.width()){
  29. $timeout(function(){
  30. (_window.width() < 768 && sm()) || md();
  31. width = _window.width();
  32. });
  33. }
  34. });
  35. }
  36. };
  37. }]);