Guest User

Untitled

a guest
Feb 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. <template>
  2.  
  3. <div class="Modal mfp-hide" ref="modal">
  4. <div class="Modal__inner">
  5. <slot></slot>
  6. </div>
  7. </div>
  8.  
  9. </template>
  10.  
  11.  
  12. <script>
  13. import _ from 'underscore'
  14. import $ from 'jquery'
  15. import 'magnific-popup'
  16.  
  17. export default {
  18. name: 'magnific-popup-modal',
  19.  
  20. props: {
  21. show: {
  22. type: Boolean,
  23. default: false
  24. },
  25. config: {
  26. type: Object,
  27. default: function () {
  28. return {
  29. // magnific defaults
  30. disableOn: null,
  31. mainClass: '',
  32. preloader: true,
  33. focus: '',
  34. closeOnContentClick: false,
  35. closeOnBgClick: false,
  36. closeBtnInside: true,
  37. showCloseBtn: true,
  38. enableEscapeKey: true,
  39. modal: false,
  40. alignTop: false,
  41. index: null,
  42. fixedContentPos: 'auto',
  43. fixedBgPos: 'auto',
  44. overflowY: 'auto',
  45. removalDelay: 0,
  46. // closeMarkup: '',
  47. // prependTo: document.body,
  48. autoFocusLast: true
  49. }
  50. }
  51. }
  52. },
  53.  
  54. data () {
  55. return {
  56. visible: this.show
  57. }
  58. },
  59.  
  60. mounted () {
  61. this[this.visible ? 'open' : 'close']()
  62. },
  63.  
  64. methods: {
  65.  
  66. /**
  67. * Opens the modal
  68. * @param {object} options Last chance to define options on this call to Magnific Popup's open() method
  69. */
  70. open: function (options) {
  71. if (!!$.magnificPopup.instance.isOpen && this.visible) {
  72. return
  73. }
  74.  
  75. let root = this
  76.  
  77. let config = _.extend(
  78. this.config,
  79. {
  80. items: {
  81. src: $(this.$refs.modal),
  82. type: 'inline'
  83. },
  84. callbacks: {
  85. open: function () {
  86. root.visible = true
  87. root.$emit('open')
  88. },
  89. close: root.close
  90. }
  91. },
  92. options || {})
  93.  
  94. $.magnificPopup.open(config)
  95. },
  96.  
  97. /**
  98. * Closes the modal
  99. */
  100. close: function () {
  101. if (!$.magnificPopup.instance.isOpen && !this.visible) {
  102. return
  103. }
  104.  
  105. this.visible = false
  106. $.magnificPopup.close()
  107. this.$emit('close')
  108. },
  109.  
  110. /**
  111. * Toggles modal open/closed
  112. */
  113. toggle: function () {
  114. this[this.visible ? 'close' : 'open']()
  115. }
  116. }
  117. }
  118.  
  119. </script>
  120.  
  121.  
  122. <style lang="scss">
  123.  
  124. @import '../../node_modules/magnific-popup/src/css/main.scss';
  125.  
  126. .mfp-content {
  127. text-align: center;
  128. }
  129.  
  130. $module: '.Modal';
  131. #{$module} {
  132. display: inline-block;
  133. position: relative;
  134.  
  135. &__inner {
  136. display: inline-block;
  137. text-align: left;
  138. }
  139.  
  140. .mfp-close {
  141. width: auto;
  142. height: auto;
  143. font-size: 2em;
  144. line-height: 1;
  145. position: absolute;
  146. top: auto;
  147. right: auto;
  148. bottom: 100%;
  149. left: 100%;
  150. color: #fff;
  151. opacity: 1;
  152. }
  153. }
  154.  
  155. </style>
Add Comment
Please, Sign In to add comment