learun-directive.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 
  2. /**
  3. * Created by cbb on 16/6/5.
  4. */
  5. angular.module('starter.directive', [])
  6. //标题组件
  7. .directive('lrComponentHeader', ['$rootScope', '$lrfnGuid', function ($rootScope, $lrfnGuid) {
  8. return {
  9. restrict: 'E',
  10. replace: true,
  11. template: '<h1 class="lr-component-heading lr-f ic-selected">标题</h1>',
  12. link: function (scope, element, attrs) {
  13. $(element).attr('data-value', $lrfnGuid());
  14. $rootScope.$on('componentScroll', function (event, data) {
  15. var $obj = $(element);
  16. var $selectBox = $('.ic-select-box');
  17. if ($selectBox.attr('data-value') == $obj.attr('data-value'))
  18. {
  19. $selectBox.offset($obj.offset());
  20. }
  21. });
  22. element.on('click', function () {
  23. var $obj = $(element);
  24. $('.ic-select-box')
  25. .attr('data-value', $obj.attr('data-value'))
  26. .width($obj.width())
  27. .height($obj.height())
  28. .offset($obj.offset());
  29. });
  30. window.onresize = function () {
  31. var $obj = $(element);
  32. var $selectBox = $('.ic-select-box');
  33. if ($selectBox.attr('data-value') == $obj.attr('data-value')) {
  34. $selectBox.width($obj.width());
  35. }
  36. }
  37. }
  38. };
  39. }])
  40. .directive('lrSelectBox', function () {
  41. return {
  42. restrict: "E",
  43. replace: true,
  44. template: '<div class="ic-select-box ic-select-box-can-delete" style="width: 300px; height: 43px;display:none;">' +
  45. '<div class="control-container">' +
  46. '<a class="select-duplicate" ><span class="fa fa-clone"></span></a>' +
  47. '<a class="select-remove" ><span class="fa fa-trash-o"></span></a>' +
  48. '</div>' +
  49. '</div>',
  50. link: function (scope, element, attr) {
  51. element.find('a').on('mouseover', function () {
  52. element.removeClass('duplicatebox');
  53. element.removeClass('removebox');
  54. if ($(this).is('.select-duplicate')) {
  55. element.addClass('duplicatebox');
  56. }
  57. else {
  58. element.addClass('removebox');
  59. }
  60. });
  61. element.find('a').on('mouseout', function () {
  62. element.removeClass('duplicatebox');
  63. element.removeClass('removebox');
  64. });
  65. //复制
  66. element.find('a').on('click', function () {
  67. var _id = $('.ic-select-box').attr("data-value");
  68. if ($(this).is('.select-duplicate')) {
  69. doBroadcast(appBroadcastCode.btnSelectBox, { "cmd": "duplicate", "id": _id });
  70. }
  71. else {
  72. doBroadcast(appBroadcastCode.btnSelectBox, {"cmd":"remove","id":_id});
  73. }
  74. });
  75. }
  76. }
  77. })
  78. ;