kist-dochopper
Version:
Move elements on page depending on media query.
2 lines • 8.44 kB
JavaScript
/*! kist-dochopper 0.3.2 - Move elements on page depending on media query. | Author: Ivan Nikolić <niksy5@gmail.com> (http://ivannikolic.com/), 2015 | License: MIT */
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self);var c=b;c=c.jQuery||(c.jQuery={}),c=c.fn||(c.fn={}),c.dochopper=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){(function(c){function d(a){var b;return"function"==typeof a&&(a=a.call(this.element,this.$el)),"string"==typeof a&&(b="[data-"+this.options.hopFromDataProp+'="'+a+'"]'),a instanceof q&&(b=a),h(b)}function e(){var a=this.$el.data(this.options.hopConditionsDataProp);return a?j(a):[]}function f(){this.conditions=this.conditions||[],this.conditions=this.conditions.concat(e.call(this),j(this.options.conditions)),this.conditions=i(this.conditions,"media"),h.each(this.conditions,h.proxy(function(a,b){b.get={},b.get.media=window.matchMedia(b.media),b.get.into=d.call(this,b.into),b.get.listener=h.proxy(o,this,b.get.into,!1)},this))}function g(a,b){this.element=a,this.options=h.extend(!0,{},this.defaults,b),this.queueActive=[],this.queue=[],m.setup.call(this),k.setup.call(this),f.call(this),l.setupInitial.call(this),l.setupListeners.call(this)}var h="undefined"!=typeof window?window.$:"undefined"!=typeof c?c.$:null,i=a(10),j=a(12),k=a(2),l=a(3),m=a(6),n=a(7),o=a(4),p=a(8)(n.name),q=h;h.extend(g.prototype,{hop:function(a,b){this.$content.detach().appendTo(a),this.queue.length||p(this,"hop",[a,b])},destroy:function(){k.destroy.call(this),l.destroy.call(this),m.destroy.call(this)},rehop:function(){var a=[];h.each(this.conditions,h.proxy(function(b,c){if(c.get.media.matches){var e=d.call(this,c.into);c.get.into.is(e)||(c.get.into=e,c.get.media.removeListener(c.get.listener),c.get.listener=h.proxy(o,this,c.get.into,!1),c.get.media.addListener(c.get.listener),a.push([c.get.into,c.get.media]))}},this)),a.length&&this.hop.apply(this,a[a.length-1])},defaults:{conditions:[],hop:h.noop,hopFromDataProp:"hop-from",hopConditionsDataProp:"hop-conditions",classes:{item:n.ns.htmlClass+"-item",isReady:"is-ready"}}}),b.exports=g}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(a,b){(function(a){var c="undefined"!=typeof window?window.$:"undefined"!=typeof a?a.$:null;b.exports={setup:function(){this.$el=c(this.element),this.$content=this.$el.contents()},destroy:function(){var a=c();a=a.add(this.$el),c.each(this.conditions,function(b,c){a=a.add(c.get.into)}),a.removeClass([this.options.classes.item,this.options.classes.isReady].join(" "))}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],3:[function(a,b){(function(c){var d="undefined"!=typeof window?window.$:"undefined"!=typeof c?c.$:null,e=a(7),f=a(4),g=a(8)(e.name);b.exports={setupInitial:function(){this.$el.one("init"+this.ens,d.proxy(function(a,b){var c=d(),e=[],f=0;for(d.each(b,function(a,b){return d.isEmptyObject(b)?void f++:(c=c.add(b.into),void e.push(b.media))}),f!==b.length&&g(this,"hop",[c,e]);b.length>0;)b.pop()},this))},setupListeners:function(){d.each(this.conditions,d.proxy(function(a,b){b.get.media.addListener(b.get.listener),f.call(this,b.get.into,!0,b.get.media)},this)),this.$el.trigger("init"+this.ens,[this.queue])},destroy:function(){d.each(this.conditions,function(a,b){b.get.media.removeListener(b.get.listener)})}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(a,b){(function(a){{var c="undefined"!=typeof window?window.$:"undefined"!=typeof a?a.$:null;b.exports=function(a,b,d){var e={};d.matches?(e={media:d,into:a},this.queueActive.push(e)):b||(this.queueActive.pop(),e=0===this.queueActive.length?{media:{matches:!0,media:"root"},into:this.$el}:this.queueActive[this.queueActive.length-1]),b&&(this.queue.push(e),this.$el.add(a).addClass([this.options.classes.item,this.options.classes.isReady].join(" "))),!c.isEmptyObject(e)&&e.media.matches&&this.hop(e.into,e.media)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(a,b){(function(c){var d="undefined"!=typeof window?window.$:"undefined"!=typeof c?c.$:null,e=a(1),f=a(7),g=a(9)(f.publicMethods),h=b.exports=function(a){return a=a||{},this.each(function(){var b=d.data(this,f.name);g(a)&&b?b[a]():"object"!==d.type(a)||b||d.data(this,f.name,new e(this,a))})};h.defaults=e.prototype.defaults}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],6:[function(a,b){(function(c){var d="undefined"!=typeof window?window.$:"undefined"!=typeof c?c.$:null,e=a(7),f=0;b.exports={setup:function(){this.uid=f++,this.ens=e.ns.event+"."+this.uid},destroy:function(){d.removeData(this.element,e.name)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],7:[function(a,b){b.exports={name:"dochopper",ns:{htmlClass:"kist-Dochopper",event:".kist.dochopper"},publicMethods:["destroy","rehop"]}},{}],8:[function(a,b){(function(a){var c="undefined"!=typeof window?window.$:"undefined"!=typeof a?a.$:null;b.exports=function(a){return function(b,d,e,f){var g=b.dom&&b.dom.el||b.$el||c({});b.options[d]&&b.options[d].apply(1===g.length?g[0]:g.toArray(),e),(f||g).trigger(((a||"")+d).toLowerCase(),e)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],9:[function(a,b){(function(a){var c="undefined"!=typeof window?window.$:"undefined"!=typeof a?a.$:null;b.exports=function(a){return function(b){return"string"==typeof b&&-1!==c.inArray(b,a||[])}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],10:[function(a,b){function c(a,b,c){for(var d=!0,e=0,f=a.length;f>e;e++)if(typeof a[e]!==b||c&&!a[e].hasOwnProperty(c)){d=!1;break}return d}function d(a,b,d){return a&&a.length&&"string"!=typeof a?("object"!==b||d&&"string"==typeof d)&&c(a,b,d)?"all":"some":"none"}function e(a,b,c){for(var d=[],e={},f=0,g=a.length;g>f;f++)"string"===b?e=l({},{__media:a[f]}):(e=l({},a[f]),e.__media=a[f][c]),d.push(e);return d}function f(a){return function(b,c){var d=b.sortVal,e=c.sortVal,f=b.item.__media,g=c.item.__media;if(a="undefined"!=typeof a?a:!1,d===e){if(f.match(/print/))return 1;if(g.match(/print/))return-1}return a?e-d:d-e}}function g(){for(var a={},b=0,c=m.length;c>b;b++)a[m[b]]=[];return a}function h(a,b){for(var c=0,d=b.length;d>c;c++){var e=b[c],f=e.__media,g="blank",h=f.match(/\d+/g);f.match(/min-width/)?g="minWidth":f.match(/min-height/)?g="minHeight":f.match(/max-width/)?g="maxWidth":f.match(/max-height/)?g="maxHeight":f.match(/print/)?g="print":f.match(/all/)&&(g="all"),a[g].push({item:e,sortVal:h?h[0]:0})}return a}function i(a){var b;for(var c in a)a.hasOwnProperty(c)&&(b=f(!1),("maxWidth"===c||"maxHeight"===c)&&(b=f(!0)),a[c].sort(b));return a}function j(a,b){function c(a){for(var c,e=0,f=a.length;f>e;e++)"string"===b?c=a[e].item.__media:(c=a[e].item,delete c.__media),d.push(c)}for(var d=[],e=0,f=m.length;f>e;e++)c(a[m[e]]);return d}function k(a,b,c){switch(d(a,b,c)){case"none":return[];case"some":return a}var f=g();return a=e(a,b,c),h(f,a),i(f),j(f,b,c)}var l=a(11),m=["blank","all","minWidth","minHeight","maxWidth","maxHeight","print"];b.exports=function(a,b){return a?b?k(a,"object",b):k(a,"string"):[]}},{}],11:[function(a,b){function c(){for(var a={},b=0;b<arguments.length;b++){var c=arguments[b];for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d])}return a}b.exports=c},{}],12:[function(a,b){b.exports=function(a){return void 0===a?[]:"[object Array]"===Object.prototype.toString.call(a)?a:[a]}},{}]},{},[5])(5)});