Guest User

Untitled

a guest
Aug 28th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. (function ($) {
  2. var jelm = $('.js-full-page-view');
  3.  
  4. var methods = {
  5. init: function () {
  6. jelm.each(function () {
  7. var id = $(this).attr('id'),
  8. title = ($(this).data('caFullPageTitle')) ? $(this).data('caFullPageTitle') : '',
  9. content = (!$(this).data('caSingle')) ? $(this).html() : '',
  10. action_container = ($(this).data('caActionContainer')) ? $(this).data('caActionContainer') : '',
  11. indented_content = ($(this).data('caNoIndentedContent')) ? '' : 'full-page-view--indented-content',
  12. bottom_action_container = '';
  13.  
  14. if ($(this).data('caBottomActionContainer')) {
  15. bottom_action_container = '<div class="full-page-view--footer-bar">' + $(this).data('caBottomActionContainer') + '</div>';
  16. }
  17.  
  18. $('body').append(
  19. '<div class="full-page-view js-full-page-view" id="fp_' + id
  20. + '"><div class="full-page-view--main-bar"><div class="full-page-view--action-container"><button class="full-page-view--action js-full-page-view-close"><svg class="icon-svg alt-flip"><use xlink:href="#icon-arrow"></use></svg></button></div><div class="full-page-view--title">' + title
  21. + '</div><div class="full-page-view--action-container">' + action_container + '</div></div><div class="full-page-view--scroll-pane full-page-view--content ' + indented_content + '">' + content
  22. + '</div>' + bottom_action_container + '</div>');
  23. });
  24. methods.bind();
  25. },
  26. bind: function () {
  27. $('.js-full-page-view-open').on('click', function () {
  28. var open_elm = ($(this).data('caTarget')) ? $("#" + $(this).data('caTarget')) : $(this).closest('.js-full-page-view');
  29. if (methods.responsive_check(open_elm)) {
  30. methods.open('#fp_' + open_elm.attr('id'));
  31. }
  32. });
  33.  
  34. $('.js-full-page-view-close').on('click', function () {
  35. var close_elm = ($(this).data('caTarget')) ? $(this).data('caTarget') : $(this).closest('.js-full-page-view');
  36. methods.close('#' + close_elm.attr('id'));
  37. });
  38. },
  39. close: function (selector) {
  40. $(selector).removeClass('active').ceScrollLock('body', 'rm');
  41. if (methods.single_check('#' + selector.substring(4))) {
  42. var focus = $(selector + ' .full-page-view--content');
  43. var content = $(focus).html();
  44. $('#' + selector.substring(4) + ' .full-page-view--content-placeholder').append(content);
  45. focus.empty();
  46. }
  47. },
  48. open: function (selector) {
  49. $(selector).addClass('active');
  50. setTimeout(function() {$(selector).ceScrollLock('body', 'add');}, 200);
  51. if (methods.single_check('#' + selector.substring(4))) {
  52. var focus = $('#' + selector.substring(4) + ' .full-page-view--content-placeholder');
  53. var content = $(focus).html();
  54. $(selector + ' .full-page-view--content').append(content);
  55. focus.empty();
  56. }
  57. },
  58. responsive_check: function (selector) {
  59. return $.fn.getRealWidth() <= $(selector).data('caResponsiveMax');
  60. },
  61. responsive_resize: function () {
  62. $('.js-full-page-view.active').each(function() {
  63. if (!methods.responsive_check('#' + $(this).attr('id').substring(3))) {
  64. methods.close('#' + $(this).attr('id'));
  65. }
  66. });
  67. },
  68. single_check: function (elem) {
  69. return !!$(elem).data('caSingle');
  70. }
  71. };
  72.  
  73. $.fn.ceFullPageView = function (method) {
  74. return $(this).each(function (i, elm) {
  75. var errors = {};
  76.  
  77. if (methods[method]) {
  78. return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
  79. } else if (typeof method === 'object' || !method) {
  80. return methods.init.apply(this, arguments);
  81. } else {
  82. $.error('fullpageview: method ' + method + ' does not exist');
  83. }
  84. });
  85. };
  86.  
  87. if ($(document).ready()) {
  88. $('.js-full-page-view').ceFullPageView();
  89.  
  90. $('.js-full-page-view-open').on('click', function () {
  91. $(this).ceFullPageView('bind');
  92. });
  93. $('.js-full-page-view-close').on('click', function () {
  94. $(this).ceFullPageView('bind');
  95. });
  96.  
  97. $(window).resize(function () {
  98. $(this).ceFullPageView('responsive_resize');
  99. });
  100. }
  101. })(jQuery);
Add Comment
Please, Sign In to add comment