mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-09-21 17:27:44 +02:00
1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
!function(e){"use strict";e.fn.xpanda=function(t){var n=this,a=e.extend(!0,{breakpoints:{xs:{minWidth:0,itemsPerRow:2},sm:{minWidth:576,itemsPerRow:4},md:{minWidth:768,itemsPerRow:6},lg:{minWidth:992,itemsPerRow:8},xl:{minWidth:1200,itemsPerRow:10},xx:{minWidth:1400,itemsPerRow:12}},element:{selector:".x-item",equalThumbSizes:!0,wrapperClass:"x-item-wrap",toClone:".x-content",spaceBetweenItems:10,spaceBetweenRows:10},placeholder:{class:"x-placeholder",marginSides:10,desktopScrollTo:!0,scrollSpeed:400,scrollTopOffset:0,slideAnimation:!0,slideSpeed:400,showControls:!0},spacer:{class:"x-spacer-inside"},independent:!0,history:!1},t);return n.each(function(){var t={};t.GO={globalVar:function(){t.GO.win=e(window),t.GO.doc=e(document),t.GO.html=e("html"),t.GO.userAgent=navigator.userAgent,t.GO.container=n,t.GO.spacer=e(".x-spacer-outside"),t.GO.item=t.GO.container.find(String(a.element.selector)),t.GO.itemLength=t.GO.item.length,t.GO.winWidth=t.GO.win.width(),t.GO.winHeight=t.GO.win.height(),t.GO.winTop=t.GO.win.scrollTop(),t.GO.containerWidth=t.GO.container.width(),t.GO.containerWidthCached=t.GO.container.width(),t.GO.columnCount=0,t.GO.updatedColumnCount=0,t.GO.placeholderCount=1,t.GO.throttleResizeFunc=_.throttle(t.GO.updateResizeThrottle,1),t.GO.throttleScrollFunc=_.throttle(t.GO.updateScrollThrottle,10)},initialLoad:function(){var n=t.GO.userAgent.toLowerCase();t.GO.isMobileDevice=!!n.match(/ipad|iphone|android|iemobile/g),e('.xpanda[data-instance="1"]').addClass("x-keyboard-active"),e(".xpanda").on("click",function(){e(this).addClass("x-keyboard-active").siblings(".xpanda").removeClass("x-keyboard-active")}),t.GO.fixWidth=!!t.GO.container.hasClass("x-fix-width"),t.GO.container.addClass("x-initiated"),t.GO.spacer.addClass("x-initiated"),t.GO.jqueryVersion=e.fn.jquery.split(".")[0]},destroyPreloader:function(){t.GO.container.each(function(){var n=e(this);n.hasClass("x-preloader")&&n.removeClass("x-preloader").promise().then(function(){setTimeout(function(){t.GO.lazyLoadThumb()},10)})})},getColumns:function(){t.GO.containerWidth>a.breakpoints.xx.minWidth?t.GO.columnCount=a.breakpoints.xx.itemsPerRow:t.GO.containerWidth<=a.breakpoints.xx.minWidth&&t.GO.containerWidth>a.breakpoints.xl.minWidth?t.GO.columnCount=a.breakpoints.xl.itemsPerRow:t.GO.containerWidth<=a.breakpoints.xl.minWidth&&t.GO.containerWidth>a.breakpoints.lg.minWidth?t.GO.columnCount=a.breakpoints.lg.itemsPerRow:t.GO.containerWidth<=a.breakpoints.lg.minWidth&&t.GO.containerWidth>a.breakpoints.md.minWidth?t.GO.columnCount=a.breakpoints.md.itemsPerRow:t.GO.containerWidth<=a.breakpoints.md.minWidth&&t.GO.containerWidth>a.breakpoints.sm.minWidth?t.GO.columnCount=a.breakpoints.sm.itemsPerRow:t.GO.containerWidth<=a.breakpoints.sm.minWidth&&t.GO.containerWidth>a.breakpoints.xs.minWidth?t.GO.columnCount=a.breakpoints.xs.itemsPerRow:console.log("error with breakpoints")},createPlaceholders:function(){t.GO.container.each(function(){var n=e(this),i=n.find(a.element.selector),o=i.length;t.GO.updatedColumnCount=t.GO.columnCount,t.GO.placeholderCount=1,i.each(function(){var s=e(this),d=i.index(s),l=d%t.GO.updatedColumnCount,r=t.GO.updatedColumnCount*t.GO.placeholderCount,c=e('<div class="'+a.placeholder.class+'" data-until="'+r+'">').prepend('<div class="x-indicator"></div>').append('<div class="'+a.placeholder.class+'-inner" style="top: '+a.element.spaceBetweenRows+'px;"></div>'),p=t.GO.fixWidth?0:a.element.spaceBetweenItems/2;s.attr("data-index",d+1).attr("data-group",r),l!==t.GO.updatedColumnCount-1&&d!==o-1||(s.after(c),n.find(a.element.selector+'[data-group="'+r+'"]').wrapAll('<div data-columns="'+t.GO.updatedColumnCount+'" class="'+a.element.wrapperClass+'" style="margin: 0 '+p+'px"></div>'),t.GO.placeholderCount=t.GO.placeholderCount+1)}),t.GO.createButtons(!1),t.GO.onArrowClick(),t.GO.onCloseClick()})},destroyPlaceholders:function(){t.GO.container.each(function(){var t=e(this);t.find(a.element.selector).unwrap(),t.find("."+a.placeholder.class).remove().removeAttr("style")})},styleItems:function(){t.GO.item.each(function(){var n=e(this),i=n.attr("data-index"),o=n.find("img"),s=o.width()/o.height(),d=a.element.spaceBetweenItems/2+"px",l=t.GO.fixWidth?0:d,r=a.element.spaceBetweenRows+"px";1===t.GO.updatedColumnCount||!0===a.element.equalThumbSizes?n.css({"flex-grow":1}):n.css({"flex-grow":s}),n.css({"flex-shrink":1,"flex-basis":"0%","margin-top":r,"margin-bottom":0}),i%t.GO.updatedColumnCount==0?n.css({"margin-right":l,"margin-left":d}):i%t.GO.updatedColumnCount-1==0?n.css({"margin-right":d,"margin-left":l}):n.css({"margin-right":d,"margin-left":d})}).promise().then(function(){t.GO.createSpacer()}),t.GO.container.css("margin-bottom",a.element.spaceBetweenRows)},createSpacer:function(){t.GO.container.each(function(){var n=e(this),i=n.attr("data-instance"),o=e('.x-spacer-outside[data-instance="'+i+'"]'),s=e("."+a.spacer.class+'[data-instance="'+i+'"]'),d=n.find(a.element.selector),l=d.length;o.hide(),s.remove(),d.each(function(){var s=d.index(this),r=n.find("."+a.placeholder.class).last().attr("data-until"),c=n.find(a.element.selector+'[data-group="'+r+'"]').length,p=t.GO.columnCount-c,h=(p-1)*a.element.spaceBetweenItems/2,m=n.find("."+a.element.wrapperClass).last(),u=t.GO.fixWidth?0:a.element.spaceBetweenItems/2,f=t.GO.fixWidth?t.GO.containerWidth:t.GO.containerWidth-2*a.element.spaceBetweenItems,O=t.GO.fixWidth?0:a.element.spaceBetweenItems,x=e("<div/>",{class:a.spacer.class}).css({"flex-grow":p,"flex-shrink":1,"flex-basis":"0%","margin-top":a.element.spaceBetweenRows+"px","margin-left":a.element.spaceBetweenItems/2,"margin-right":u,"padding-left":h,"padding-right":h}).attr("data-instance",i);s===l-1&&(c<t.GO.columnCount?x.appendTo(m):o.show().css({width:f+"px","margin-left":O+"px","margin-right":O+"px","margin-bottom":a.element.spaceBetweenRows+"px"}))})}).promise().then(function(){t.GO.addSpacerContent()})},addSpacerContent:function(){t.GO.container.each(function(){var t,n=e(this),i=n.attr("data-instance"),o=e('.x-spacer-outside[data-instance="'+i+'"]'),s=o.html();t=o,e.trim(t.html())?n.find("."+a.spacer.class).html(s):n.find("."+a.spacer.class).addClass("x-spacer-empty")}).promise().then(function(){t.GO.destroyPreloader(),t.GO.lazyLoadThumb()})},updateResizeThrottle:function(){t.GO.containerWidth=t.GO.container.width(),t.GO.container.each(function(){var n=e(this),i=n.find(".x-is-active"),o=i.attr("data-index"),s=n.find("."+a.placeholder.class+"-inner"),d=n.find("."+a.placeholder.class);s.css({display:""}),t.GO.updatedColumnCount!==t.GO.columnCount?(t.GO.destroyPlaceholders(),t.GO.createPlaceholders(),t.GO.styleItems()):(d.hasClass("x-is-expanded")&&n.find(".x-is-expanded > .x-placeholder-inner").css("height","auto"),t.GO.createSpacer()),i.length>0&&(t.GO.containerWidth!==t.GO.containerWidthCached&&(t.GO.containerWidthCached=t.GO.container.width(),n.find(".x-is-expanded > .x-placeholder-inner").find(".x-asset, .x-info, .x-updated-content").remove(),t.GO.openXpanda(i,o,!1,!1,!1)),t.GO.styleActivePlaceholder()),t.GO.getColumns()})},updateScrollThrottle:function(){t.GO.winHeight=t.GO.win.height(),t.GO.winTop=t.GO.win.scrollTop(),t.GO.lazyLoadThumb()},onItemClick:function(){t.GO.item.on("click",function(n){n.preventDefault();var i=a.placeholder.slideAnimation,o=a.placeholder.desktopScrollTo,s=a.independent,d=e(this),l=d.attr("data-path"),r=d.closest(".xpanda").find(a.element.selector),c=e(".xpanda").find(a.element.selector),p=d.closest(".xpanda").find(".x-is-active"),h=e(".xpanda").find(".x-is-active"),m=d.attr("data-index"),u=p.attr("data-index"),f=h.attr("data-index"),O=d.attr("data-group"),x=p.attr("data-group");function G(){var e=window.location.href.toString();if(window.location.search.toString().includes("?xpnd="))var t=e.split("?xpnd=")[0];else t=e.split("&xpnd=")[0];history.replaceState(null,null,t)}if(d.hasClass("x-is-active"))!1===s?c.removeClass("x-is-not-active"):r.removeClass("x-is-not-active"),d.removeClass("x-is-active"),!0===i?t.GO.closeXpanda(d,m,!0):t.GO.closeXpanda(d,m,!1),a.history&&G();else if(!1===s?c.removeClass("x-is-active").addClass("x-is-not-active"):r.removeClass("x-is-active").addClass("x-is-not-active"),d.removeClass("x-is-not-active").addClass("x-is-active"),p.length>0||h.length>0?O===x?!0===i?t.GO.adjustXpanda(d,p,m,!0):t.GO.adjustXpanda(d,p,m,!1):!0===i?!0===o&&!1===t.GO.isMobileDevice?(!1===s?t.GO.closeXpanda(h,f,!0):t.GO.closeXpanda(p,u,!0),setTimeout(function(){t.GO.openXpanda(d,m,!0,!0)},a.placeholder.slideSpeed+50)):(!1===s?t.GO.closeXpanda(h,f,!0):t.GO.closeXpanda(p,u,!0),setTimeout(function(){t.GO.openXpanda(d,m,!0,!1,!0)},a.placeholder.slideSpeed+50)):(!1===s?t.GO.closeXpanda(h,f,!1):t.GO.closeXpanda(p,u,!1),!0===o&&!1===t.GO.isMobileDevice?t.GO.openXpanda(d,m,!1,!0,!0):t.GO.openXpanda(d,m,!1,!1,!0)):!0===i?!0===o&&!1===t.GO.isMobileDevice?t.GO.openXpanda(d,m,!0,!0,!1):t.GO.openXpanda(d,m,!0,!1,!1):!0===o&&!1===t.GO.isMobileDevice?t.GO.openXpanda(d,m,!1,!0,!1):t.GO.openXpanda(d,m,!1,!1,!1),a.history){G();var w=-1===window.location.href.indexOf("?")?"?xpnd=":"&xpnd=";history.pushState(null,null,window.location.href+w+l)}})},openXpanda:function(n,i,o,s,d){var l=n.find(a.element.toClone).html(),r=n.closest(".xpanda"),c=Math.ceil(i/t.GO.updatedColumnCount)*t.GO.updatedColumnCount,p=r.find("."+a.placeholder.class+'[data-until="'+c+'"]'),h=p.find("."+a.placeholder.class+"-inner"),m=a.element.spaceBetweenRows,u=a.placeholder.scrollTopOffset;p.addClass("x-is-expanded"),h.prepend(l).promise().then(function(){t.GO.jqueryVersion<3&&t.GO.styleActivePlaceholder(),h.css({height:"auto",top:m}).promise().then(function(){var i=h.outerHeight();!0===d?!0===o?(h.animate({height:i}),p.animate({height:i+a.element.spaceBetweenRows},a.placeholder.slideSpeed,"linear").promise().then(function(){h.animate({opacity:1}).promise().then(function(){!0===s?(e("html, body").animate({scrollTop:n.parent(".x-item-wrap").offset().top-u},a.placeholder.scrollSpeed,"linear"),t.GO.showIndicator(n,100)):t.GO.showIndicator(n,0)})})):(p.css({height:i+a.element.spaceBetweenRows}),h.css({height:i,opacity:1}).promise().then(function(){!0===s?(e("html, body").animate({scrollTop:n.parent(".x-item-wrap").offset().top-u},a.placeholder.scrollSpeed,"linear"),t.GO.showIndicator(n,400)):t.GO.showIndicator(n,200)})):!0===o?(h.animate({height:i}),p.animate({height:i+a.element.spaceBetweenRows},a.placeholder.slideSpeed,"linear").promise().then(function(){h.animate({opacity:1}).promise().then(function(){!0===s?(e("html, body").animate({scrollTop:n.parent(".x-item-wrap").offset().top-u},a.placeholder.scrollSpeed,"linear"),t.GO.showIndicator(n,0)):t.GO.showIndicator(n,0)})})):(p.css({height:i+a.element.spaceBetweenRows}),h.css({height:i,opacity:1}).promise().then(function(){!0===s?(e("html, body").animate({scrollTop:n.parent(".x-item-wrap").offset().top-u},a.placeholder.scrollSpeed,"linear"),t.GO.showIndicator(n,400)):t.GO.showIndicator(n,200)}))}),t.GO.jqueryVersion>=3&&t.GO.styleActivePlaceholder(),t.GO.lazyLoadAsset(i),t.GO.updateButtons(i,c)})},closeXpanda:function(e,n,i){var o=e.closest(".xpanda"),s=(Math.ceil(n/t.GO.updatedColumnCount),t.GO.updatedColumnCount,o.find("."+a.placeholder.class+".x-is-expanded")),d=s.find("."+a.placeholder.class+"-inner");t.GO.hideIndicator(),!0===i?(s.animate({height:0},a.placeholder.slideSpeed,"linear").promise().then(function(){s.removeClass("x-is-expanded").removeAttr("style")}),d.animate({height:0,opacity:0},a.placeholder.slideSpeed,"linear").promise().then(function(){d.removeAttr("style").find(".x-asset, .x-info, .x-updated-content").remove()})):(s.removeClass("x-is-expanded").removeAttr("style"),d.removeAttr("style").css({opacity:0}).find(".x-asset, .x-info, .x-updated-content").remove()),t.GO.lazyLoadThumb()},adjustXpanda:function(e,n,i,o){var s,d,l=e.find(a.element.toClone).html(),r=n.closest(".xpanda"),c=Math.ceil(i/t.GO.updatedColumnCount)*t.GO.updatedColumnCount,p=r.find("."+a.placeholder.class+'[data-until="'+c+'"]'),h=p.find("."+a.placeholder.class+"-inner");t.GO.hideIndicator(),!0===o?(s=a.placeholder.slideSpeed,d=0):(s=0,d=200),h.find(".x-info, .x-asset, .x-updated-content").animate({opacity:0},s,"linear").promise().then(function(){t.GO.updateButtons(i,c),h.find(".x-asset, .x-info, .x-updated-content").remove(),h.prepend('<div class="x-updated-content" style="opacity: 0;">'+l+"</div>").promise().then(function(){h.css({display:"block"});var n=h.find(".x-updated-content").outerHeight();p.animate({height:n+a.element.spaceBetweenRows},s,"linear"),h.animate({height:n},s,"linear").promise().then(function(){h.find(".x-info, .x-asset, .x-updated-content").animate({opacity:1},s,"linear").promise().then(function(){t.GO.showIndicator(e,d),t.GO.styleActivePlaceholder(),t.GO.lazyLoadAsset(i)})})})}),t.GO.lazyLoadThumb()},showIndicator:function(e,t){var n=e.position(),i=e.width(),o=n.left+i/2,s=e.parent(".x-item-wrap").next("."+a.placeholder.class).find(".x-indicator"),d=s.width(),l=s.height();s.css({left:o-d/2,top:a.element.spaceBetweenRows}).promise().then(function(){s.css({opacity:1}).promise().then(function(){setTimeout(function(){s.animate({top:-(l-a.element.spaceBetweenRows)},200)},t)})})},hideIndicator:function(){var t=e(".x-indicator");t.css({opacity:0}).promise().then(function(){t.css({left:0,top:0})})},lazyLoadAsset:function(n){if(t.GO.container.hasClass("x-lazyload-asset")){var i=e(".x-is-expanded").find(".x-asset"),o=i.find("img"),s=o.attr("data-src"),d=e(a.element.selector+'[data-index="'+n+'"]').find(".x-asset");o.attr("data-src")&&null!==o.attr("data-src")&&(o.attr("src",s),o.one("load",function(){d.hasClass("x-was-loaded")||i.addClass("x-is-loaded");var e=d.find("img"),t=e.attr("data-src");e.attr("src",t).promise().then(function(){d.addClass("x-was-loaded")})}).each(function(){this.complete&&e(this).trigger("load")}))}},lazyLoadThumb:function(){if(t.GO.container.hasClass("x-lazyload-thumbnail")){var n=e("."+a.placeholder.class),i=t.GO.winTop+t.GO.winHeight;n.each(function(){var n=e(this),o=n.offset().top,s=o-100,d=n.attr("data-until"),l=e(a.element.selector+'[data-group="'+d+'"]');s<=i&&o>=t.GO.winTop&&l.each(function(){var t=e(this).find("> a > img"),n=t.attr("data-src");t.attr("src",n).promise().then(function(){l.addClass("x-is-loaded")})})})}},createButtons:function(n){t.GO.container.each(function(){var t=e(this),i=e('<div class="x-arrow x-prev"></div>'),o=e('<div class="x-arrow x-next"></div>'),s=e('<div class="x-close"></div>');!0===a.placeholder.showControls&&(!0===n?t.find("."+a.placeholder.class).find(".x-updated-content").append(i).append(o).append(s):t.find("."+a.placeholder.class).find("."+a.placeholder.class+"-inner").append(i).append(o).append(s))})},updateButtons:function(n,i){t.GO.container.each(function(){var o=e(this);!0===a.placeholder.showControls&&("1"===n?o.find("."+a.placeholder.class+'[data-until="'+i+'"]').find(".x-arrow.x-prev").addClass("x-arrow-disabled"):n===t.GO.itemLength.toString()?o.find("."+a.placeholder.class+'[data-until="'+i+'"]').find(".x-arrow.x-next").addClass("x-arrow-disabled"):o.find("."+a.placeholder.class).find(".x-arrow.x-prev, .x-arrow.x-next").removeClass("x-arrow-disabled"))}),t.GO.onArrowClick(),t.GO.onKeyboardClick()},styleActivePlaceholder:function(){t.GO.container.each(function(){var n=e(this).find(".x-is-expanded"),i=t.GO.fixWidth?0:a.placeholder.marginSides;n.css({"margin-right":i,"margin-left":i,width:"100%"}).css("width","-="+2*i)})},onArrowClick:function(){e(".x-arrow").off("click").one("click",function(){var t,n=e(this),i=n.closest(".xpanda").find(".x-is-active").attr("data-index");t=n.hasClass("x-prev")?parseInt(i,10)-1:parseInt(i,10)+1,n.closest(".xpanda").find(a.element.selector+'[data-index="'+t+'"]').trigger("click")})},onCloseClick:function(){e(".x-close").on("click",function(){e(this).closest(".xpanda").find(".x-is-active").trigger("click")})},onKeyboardClick:function(){t.GO.doc.off("keydown").one("keydown",function(t){t.stopImmediatePropagation();var n,i=e(".x-keyboard-active"),o=i.find(".x-is-active"),s=o.attr("data-index"),d=parseInt(i.find(".x-item-wrap").attr("data-columns"),10);o.length>0&&(27===t.which&&o.trigger("click"),37===t.which&&(n=parseInt(s,10)-1,i.find(a.element.selector+'[data-index="'+n+'"]').trigger("click")),38===t.which&&(n=parseInt(s,10)-d,i.find(a.element.selector+'[data-index="'+n+'"]').trigger("click")),39===t.which&&(n=parseInt(s,10)+1,i.find(a.element.selector+'[data-index="'+n+'"]').trigger("click")),40===t.which&&(n=parseInt(s,10)+d,i.find(a.element.selector+'[data-index="'+n+'"]').trigger("click")))})},historyLoad:function(){if(a.history){var e=window.location.href,n=e.substring(e.lastIndexOf("xpnd="),e.length).slice(5);t.GO.container.find(String(a.element.selector)+'[data-path="'+n+'"]').trigger("click")}}},t.GO.globalVar(),t.GO.win.on("load",function(){t.GO.initialLoad(),t.GO.getColumns(),t.GO.createPlaceholders(),t.GO.styleItems(),t.GO.historyLoad()}),t.GO.win.on("resize",function(){t.GO.throttleResizeFunc()}),t.GO.win.on("orientationchange",function(){window.location.reload(!1)}),t.GO.win.on("scroll",function(){t.GO.throttleScrollFunc()}),t.GO.win.on("popstate",function(){t.GO.historyLoad()}),t.GO.onItemClick(),t.GO.onKeyboardClick()})}}(jQuery); |