Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function ($) {
- var jelm = $('.js-full-page-view');
- var methods = {
- init: function () {
- jelm.each(function () {
- var id = $(this).attr('id'),
- title = ($(this).data('caFullPageTitle')) ? $(this).data('caFullPageTitle') : '',
- content = (!$(this).data('caSingle')) ? $(this).html() : '',
- action_container = ($(this).data('caActionContainer')) ? $(this).data('caActionContainer') : '',
- indented_content = ($(this).data('caNoIndentedContent')) ? '' : 'full-page-view--indented-content',
- bottom_action_container = '';
- if ($(this).data('caBottomActionContainer')) {
- bottom_action_container = '<div class="full-page-view--footer-bar">' + $(this).data('caBottomActionContainer') + '</div>';
- }
- $('body').append(
- '<div class="full-page-view js-full-page-view" id="fp_' + id
- + '"><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
- + '</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
- + '</div>' + bottom_action_container + '</div>');
- });
- methods.bind();
- },
- bind: function () {
- $('.js-full-page-view-open').on('click', function () {
- var open_elm = ($(this).data('caTarget')) ? $("#" + $(this).data('caTarget')) : $(this).closest('.js-full-page-view');
- if (methods.responsive_check(open_elm)) {
- methods.open('#fp_' + open_elm.attr('id'));
- }
- });
- $('.js-full-page-view-close').on('click', function () {
- var close_elm = ($(this).data('caTarget')) ? $(this).data('caTarget') : $(this).closest('.js-full-page-view');
- methods.close('#' + close_elm.attr('id'));
- });
- },
- close: function (selector) {
- $(selector).removeClass('active').ceScrollLock('body', 'rm');
- if (methods.single_check('#' + selector.substring(4))) {
- var focus = $(selector + ' .full-page-view--content');
- var content = $(focus).html();
- $('#' + selector.substring(4) + ' .full-page-view--content-placeholder').append(content);
- focus.empty();
- }
- },
- open: function (selector) {
- $(selector).addClass('active');
- setTimeout(function() {$(selector).ceScrollLock('body', 'add');}, 200);
- if (methods.single_check('#' + selector.substring(4))) {
- var focus = $('#' + selector.substring(4) + ' .full-page-view--content-placeholder');
- var content = $(focus).html();
- $(selector + ' .full-page-view--content').append(content);
- focus.empty();
- }
- },
- responsive_check: function (selector) {
- return $.fn.getRealWidth() <= $(selector).data('caResponsiveMax');
- },
- responsive_resize: function () {
- $('.js-full-page-view.active').each(function() {
- if (!methods.responsive_check('#' + $(this).attr('id').substring(3))) {
- methods.close('#' + $(this).attr('id'));
- }
- });
- },
- single_check: function (elem) {
- return !!$(elem).data('caSingle');
- }
- };
- $.fn.ceFullPageView = function (method) {
- return $(this).each(function (i, elm) {
- var errors = {};
- if (methods[method]) {
- return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
- } else if (typeof method === 'object' || !method) {
- return methods.init.apply(this, arguments);
- } else {
- $.error('fullpageview: method ' + method + ' does not exist');
- }
- });
- };
- if ($(document).ready()) {
- $('.js-full-page-view').ceFullPageView();
- $('.js-full-page-view-open').on('click', function () {
- $(this).ceFullPageView('bind');
- });
- $('.js-full-page-view-close').on('click', function () {
- $(this).ceFullPageView('bind');
- });
- $(window).resize(function () {
- $(this).ceFullPageView('responsive_resize');
- });
- }
- })(jQuery);
Add Comment
Please, Sign In to add comment