Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
151 - 1
/**
2
 * breakpoints-js v1.0.6
3
 * https://github.com/amazingSurge/breakpoints-js
4
 *
5
 * Copyright (c) amazingSurge
6
 * Released under the LGPL-3.0 license
7
 */
8
(function(global, factory) {
9
  if (typeof define === 'function' && define.amd) {
10
    define(['exports'], factory);
11
  } else if (typeof exports !== 'undefined') {
12
    factory(exports);
13
  } else {
14
    var mod = {
15
      exports: {}
16
    };
17
    factory(mod.exports);
18
    global.breakpointsEs = mod.exports;
19
  }
20
})(this, function(exports) {
21
  'use strict';
22
 
23
  Object.defineProperty(exports, '__esModule', {
24
    value: true
25
  });
26
 
27
  function _possibleConstructorReturn(self, call) {
28
    if (!self) {
29
      throw new ReferenceError(
30
        "this hasn't been initialised - super() hasn't been called"
31
      );
32
    }
33
 
34
    return call && (typeof call === 'object' || typeof call === 'function')
35
      ? call
36
      : self;
37
  }
38
 
39
  function _inherits(subClass, superClass) {
40
    if (typeof superClass !== 'function' && superClass !== null) {
41
      throw new TypeError(
42
        'Super expression must either be null or a function, not ' +
43
          typeof superClass
44
      );
45
    }
46
 
47
    subClass.prototype = Object.create(superClass && superClass.prototype, {
48
      constructor: {
49
        value: subClass,
50
        enumerable: false,
51
        writable: true,
52
        configurable: true
53
      }
54
    });
55
    if (superClass)
56
      Object.setPrototypeOf
57
        ? Object.setPrototypeOf(subClass, superClass)
58
        : (subClass.__proto__ = superClass);
59
  }
60
 
61
  function _classCallCheck(instance, Constructor) {
62
    if (!(instance instanceof Constructor)) {
63
      throw new TypeError('Cannot call a class as a function');
64
    }
65
  }
66
 
67
  var _createClass = (function() {
68
    function defineProperties(target, props) {
69
      for (var i = 0; i < props.length; i++) {
70
        var descriptor = props[i];
71
        descriptor.enumerable = descriptor.enumerable || false;
72
        descriptor.configurable = true;
73
        if ('value' in descriptor) descriptor.writable = true;
74
        Object.defineProperty(target, descriptor.key, descriptor);
75
      }
76
    }
77
 
78
    return function(Constructor, protoProps, staticProps) {
79
      if (protoProps) defineProperties(Constructor.prototype, protoProps);
80
      if (staticProps) defineProperties(Constructor, staticProps);
81
      return Constructor;
82
    };
83
  })();
84
 
85
  var _typeof =
86
    typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
87
      ? function(obj) {
88
          return typeof obj;
89
        }
90
      : function(obj) {
91
          return obj &&
92
            typeof Symbol === 'function' &&
93
            obj.constructor === Symbol &&
94
            obj !== Symbol.prototype
95
            ? 'symbol'
96
            : typeof obj;
97
        };
98
 
99
  /**
100
   * breakpoints-js v1.0.6
101
   * https://github.com/amazingSurge/breakpoints-js
102
   *
103
   * Copyright (c) amazingSurge
104
   * Released under the LGPL-3.0 license
105
   */
106
  var defaults = {
107
    // Extra small devices (phones)
108
    xs: {
109
      min: 0,
110
      max: 767
111
    },
112
    // Small devices (tablets)
113
    sm: {
114
      min: 768,
115
      max: 991
116
    },
117
    // Medium devices (desktops)
118
    md: {
119
      min: 992,
120
      max: 1199
121
    },
122
    // Large devices (large desktops)
123
    lg: {
124
      min: 1200,
125
      max: Infinity
126
    }
127
  };
128
 
129
  var util = {
130
    each: function each(obj, fn) {
131
      var continues = void 0;
132
 
133
      for (var i in obj) {
134
        if (
135
          (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !==
136
            'object' ||
137
          obj.hasOwnProperty(i)
138
        ) {
139
          continues = fn(i, obj[i]);
140
          if (continues === false) {
141
            break; //allow early exit
142
          }
143
        }
144
      }
145
    },
146
 
147
    isFunction: function isFunction(obj) {
148
      return typeof obj === 'function' || false;
149
    },
150
 
151
    extend: function extend(obj, source) {
152
      for (var property in source) {
153
        obj[property] = source[property];
154
      }
155
      return obj;
156
    }
157
  };
158
 
159
  var Callbacks = (function() {
160
    function Callbacks() {
161
      _classCallCheck(this, Callbacks);
162
 
163
      this.length = 0;
164
      this.list = [];
165
    }
166
 
167
    _createClass(Callbacks, [
168
      {
169
        key: 'add',
170
        value: function add(fn, data) {
171
          var one =
172
            arguments.length > 2 && arguments[2] !== undefined
173
              ? arguments[2]
174
              : false;
175
 
176
          this.list.push({
177
            fn: fn,
178
            data: data,
179
            one: one
180
          });
181
 
182
          this.length++;
183
        }
184
      },
185
      {
186
        key: 'remove',
187
        value: function remove(fn) {
188
          for (var i = 0; i < this.list.length; i++) {
189
            if (this.list[i].fn === fn) {
190
              this.list.splice(i, 1);
191
              this.length--;
192
              i--;
193
            }
194
          }
195
        }
196
      },
197
      {
198
        key: 'empty',
199
        value: function empty() {
200
          this.list = [];
201
          this.length = 0;
202
        }
203
      },
204
      {
205
        key: 'call',
206
        value: function call(caller, i) {
207
          var fn =
208
            arguments.length > 2 && arguments[2] !== undefined
209
              ? arguments[2]
210
              : null;
211
 
212
          if (!i) {
213
            i = this.length - 1;
214
          }
215
          var callback = this.list[i];
216
 
217
          if (util.isFunction(fn)) {
218
            fn.call(this, caller, callback, i);
219
          } else if (util.isFunction(callback.fn)) {
220
            callback.fn.call(caller || window, callback.data);
221
          }
222
 
223
          if (callback.one) {
224
            delete this.list[i];
225
            this.length--;
226
          }
227
        }
228
      },
229
      {
230
        key: 'fire',
231
        value: function fire(caller) {
232
          var fn =
233
            arguments.length > 1 && arguments[1] !== undefined
234
              ? arguments[1]
235
              : null;
236
 
237
          for (var i in this.list) {
238
            if (this.list.hasOwnProperty(i)) {
239
              this.call(caller, i, fn);
240
            }
241
          }
242
        }
243
      }
244
    ]);
245
 
246
    return Callbacks;
247
  })();
248
 
249
  var ChangeEvent = {
250
    current: null,
251
    callbacks: new Callbacks(),
252
    trigger: function trigger(size) {
253
      var previous = this.current;
254
      this.current = size;
255
      this.callbacks.fire(size, function(caller, callback) {
256
        if (util.isFunction(callback.fn)) {
257
          callback.fn.call(
258
            {
259
              current: size,
260
              previous: previous
261
            },
262
            callback.data
263
          );
264
        }
265
      });
266
    },
267
    one: function one(data, fn) {
268
      return this.on(data, fn, true);
269
    },
270
    on: function on(data, fn) {
271
      var one =
272
        arguments.length > 2 && arguments[2] !== undefined
273
          ? arguments[2]
274
          : false;
275
 
276
      if (typeof fn === 'undefined' && util.isFunction(data)) {
277
        fn = data;
278
        data = undefined;
279
      }
280
      if (util.isFunction(fn)) {
281
        this.callbacks.add(fn, data, one);
282
      }
283
    },
284
    off: function off(fn) {
285
      if (typeof fn === 'undefined') {
286
        this.callbacks.empty();
287
      }
288
    }
289
  };
290
 
291
  var MediaQuery = (function() {
292
    function MediaQuery(name, media) {
293
      _classCallCheck(this, MediaQuery);
294
 
295
      this.name = name;
296
      this.media = media;
297
 
298
      this.initialize();
299
    }
300
 
301
    _createClass(MediaQuery, [
302
      {
303
        key: 'initialize',
304
        value: function initialize() {
305
          this.callbacks = {
306
            enter: new Callbacks(),
307
            leave: new Callbacks()
308
          };
309
 
310
          this.mql = (window.matchMedia && window.matchMedia(this.media)) || {
311
            matches: false,
312
            media: this.media,
313
            addListener: function addListener() {
314
              // do nothing
315
            },
316
            removeListener: function removeListener() {
317
              // do nothing
318
            }
319
          };
320
 
321
          var that = this;
322
          this.mqlListener = function(mql) {
323
            var type = (mql.matches && 'enter') || 'leave';
324
 
325
            that.callbacks[type].fire(that);
326
          };
327
          this.mql.addListener(this.mqlListener);
328
        }
329
      },
330
      {
331
        key: 'on',
332
        value: function on(types, data, fn) {
333
          var one =
334
            arguments.length > 3 && arguments[3] !== undefined
335
              ? arguments[3]
336
              : false;
337
 
338
          if (
339
            (typeof types === 'undefined' ? 'undefined' : _typeof(types)) ===
340
            'object'
341
          ) {
342
            for (var type in types) {
343
              if (types.hasOwnProperty(type)) {
344
                this.on(type, data, types[type], one);
345
              }
346
            }
347
            return this;
348
          }
349
 
350
          if (typeof fn === 'undefined' && util.isFunction(data)) {
351
            fn = data;
352
            data = undefined;
353
          }
354
 
355
          if (!util.isFunction(fn)) {
356
            return this;
357
          }
358
 
359
          if (typeof this.callbacks[types] !== 'undefined') {
360
            this.callbacks[types].add(fn, data, one);
361
 
362
            if (types === 'enter' && this.isMatched()) {
363
              this.callbacks[types].call(this);
364
            }
365
          }
366
 
367
          return this;
368
        }
369
      },
370
      {
371
        key: 'one',
372
        value: function one(types, data, fn) {
373
          return this.on(types, data, fn, true);
374
        }
375
      },
376
      {
377
        key: 'off',
378
        value: function off(types, fn) {
379
          var type = void 0;
380
 
381
          if (
382
            (typeof types === 'undefined' ? 'undefined' : _typeof(types)) ===
383
            'object'
384
          ) {
385
            for (type in types) {
386
              if (types.hasOwnProperty(type)) {
387
                this.off(type, types[type]);
388
              }
389
            }
390
            return this;
391
          }
392
 
393
          if (typeof types === 'undefined') {
394
            this.callbacks.enter.empty();
395
            this.callbacks.leave.empty();
396
          } else if (types in this.callbacks) {
397
            if (fn) {
398
              this.callbacks[types].remove(fn);
399
            } else {
400
              this.callbacks[types].empty();
401
            }
402
          }
403
 
404
          return this;
405
        }
406
      },
407
      {
408
        key: 'isMatched',
409
        value: function isMatched() {
410
          return this.mql.matches;
411
        }
412
      },
413
      {
414
        key: 'destroy',
415
        value: function destroy() {
416
          this.off();
417
        }
418
      }
419
    ]);
420
 
421
    return MediaQuery;
422
  })();
423
 
424
  var MediaBuilder = {
425
    min: function min(_min) {
426
      var unit =
427
        arguments.length > 1 && arguments[1] !== undefined
428
          ? arguments[1]
429
          : 'px';
430
 
431
      return '(min-width: ' + _min + unit + ')';
432
    },
433
    max: function max(_max) {
434
      var unit =
435
        arguments.length > 1 && arguments[1] !== undefined
436
          ? arguments[1]
437
          : 'px';
438
 
439
      return '(max-width: ' + _max + unit + ')';
440
    },
441
    between: function between(min, max) {
442
      var unit =
443
        arguments.length > 2 && arguments[2] !== undefined
444
          ? arguments[2]
445
          : 'px';
446
 
447
      return (
448
        '(min-width: ' + min + unit + ') and (max-width: ' + max + unit + ')'
449
      );
450
    },
451
    get: function get(min, max) {
452
      var unit =
453
        arguments.length > 2 && arguments[2] !== undefined
454
          ? arguments[2]
455
          : 'px';
456
 
457
      if (min === 0) {
458
        return this.max(max, unit);
459
      }
460
      if (max === Infinity) {
461
        return this.min(min, unit);
462
      }
463
      return this.between(min, max, unit);
464
    }
465
  };
466
 
467
  var Size = (function(_MediaQuery) {
468
    _inherits(Size, _MediaQuery);
469
 
470
    function Size(name) {
471
      var min =
472
        arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
473
      var max =
474
        arguments.length > 2 && arguments[2] !== undefined
475
          ? arguments[2]
476
          : Infinity;
477
      var unit =
478
        arguments.length > 3 && arguments[3] !== undefined
479
          ? arguments[3]
480
          : 'px';
481
 
482
      _classCallCheck(this, Size);
483
 
484
      var media = MediaBuilder.get(min, max, unit);
485
 
486
      var _this = _possibleConstructorReturn(
487
        this,
488
        (Size.__proto__ || Object.getPrototypeOf(Size)).call(this, name, media)
489
      );
490
 
491
      _this.min = min;
492
      _this.max = max;
493
      _this.unit = unit;
494
 
495
      var that = _this;
496
      _this.changeListener = function() {
497
        if (that.isMatched()) {
498
          ChangeEvent.trigger(that);
499
        }
500
      };
501
      if (_this.isMatched()) {
502
        ChangeEvent.current = _this;
503
      }
504
 
505
      _this.mql.addListener(_this.changeListener);
506
      return _this;
507
    }
508
 
509
    _createClass(Size, [
510
      {
511
        key: 'destroy',
512
        value: function destroy() {
513
          this.off();
514
          this.mql.removeListener(this.changeListener);
515
        }
516
      }
517
    ]);
518
 
519
    return Size;
520
  })(MediaQuery);
521
 
522
  var UnionSize = (function(_MediaQuery2) {
523
    _inherits(UnionSize, _MediaQuery2);
524
 
525
    function UnionSize(names) {
526
      _classCallCheck(this, UnionSize);
527
 
528
      var sizes = [];
529
      var media = [];
530
 
531
      util.each(names.split(' '), function(i, name) {
532
        var size = Breakpoints$1.get(name);
533
        if (size) {
534
          sizes.push(size);
535
          media.push(size.media);
536
        }
537
      });
538
 
539
      return _possibleConstructorReturn(
540
        this,
541
        (UnionSize.__proto__ || Object.getPrototypeOf(UnionSize)).call(
542
          this,
543
          names,
544
          media.join(',')
545
        )
546
      );
547
    }
548
 
549
    return UnionSize;
550
  })(MediaQuery);
551
 
552
  var info = {
553
    version: '1.0.6'
554
  };
555
 
556
  var sizes = {};
557
  var unionSizes = {};
558
 
559
  var Breakpoints = (window.Breakpoints = function() {
560
    for (
561
      var _len = arguments.length, args = Array(_len), _key = 0;
562
      _key < _len;
563
      _key++
564
    ) {
565
      args[_key] = arguments[_key];
566
    }
567
 
568
    Breakpoints.define.apply(Breakpoints, args);
569
  });
570
 
571
  Breakpoints.defaults = defaults;
572
 
573
  Breakpoints = util.extend(Breakpoints, {
574
    version: info.version,
575
    defined: false,
576
    define: function define(values) {
577
      var options =
578
        arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
579
 
580
      if (this.defined) {
581
        this.destroy();
582
      }
583
 
584
      if (!values) {
585
        values = Breakpoints.defaults;
586
      }
587
 
588
      this.options = util.extend(options, {
589
        unit: 'px'
590
      });
591
 
592
      for (var size in values) {
593
        if (values.hasOwnProperty(size)) {
594
          this.set(size, values[size].min, values[size].max, this.options.unit);
595
        }
596
      }
597
 
598
      this.defined = true;
599
    },
600
    destroy: function destroy() {
601
      util.each(sizes, function(name, size) {
602
        size.destroy();
603
      });
604
      sizes = {};
605
      ChangeEvent.current = null;
606
    },
607
    is: function is(size) {
608
      var breakpoint = this.get(size);
609
      if (!breakpoint) {
610
        return null;
611
      }
612
 
613
      return breakpoint.isMatched();
614
    },
615
    all: function all() {
616
      var names = [];
617
      util.each(sizes, function(name) {
618
        names.push(name);
619
      });
620
      return names;
621
    },
622
 
623
    set: function set(name) {
624
      var min =
625
        arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
626
      var max =
627
        arguments.length > 2 && arguments[2] !== undefined
628
          ? arguments[2]
629
          : Infinity;
630
      var unit =
631
        arguments.length > 3 && arguments[3] !== undefined
632
          ? arguments[3]
633
          : 'px';
634
 
635
      var size = this.get(name);
636
      if (size) {
637
        size.destroy();
638
      }
639
 
640
      sizes[name] = new Size(name, min, max, unit);
641
      return sizes[name];
642
    },
643
 
644
    get: function get(size) {
645
      if (sizes.hasOwnProperty(size)) {
646
        return sizes[size];
647
      }
648
 
649
      return null;
650
    },
651
 
652
    getUnion: function getUnion(sizes) {
653
      if (unionSizes.hasOwnProperty(sizes)) {
654
        return unionSizes[sizes];
655
      }
656
 
657
      unionSizes[sizes] = new UnionSize(sizes);
658
 
659
      return unionSizes[sizes];
660
    },
661
    getMin: function getMin(size) {
662
      var obj = this.get(size);
663
      if (obj) {
664
        return obj.min;
665
      }
666
      return null;
667
    },
668
    getMax: function getMax(size) {
669
      var obj = this.get(size);
670
      if (obj) {
671
        return obj.max;
672
      }
673
      return null;
674
    },
675
    current: function current() {
676
      return ChangeEvent.current;
677
    },
678
    getMedia: function getMedia(size) {
679
      var obj = this.get(size);
680
      if (obj) {
681
        return obj.media;
682
      }
683
      return null;
684
    },
685
    on: function on(sizes, types, data, fn) {
686
      var one =
687
        arguments.length > 4 && arguments[4] !== undefined
688
          ? arguments[4]
689
          : false;
690
 
691
      sizes = sizes.trim();
692
 
693
      if (sizes === 'change') {
694
        fn = data;
695
        data = types;
696
        return ChangeEvent.on(data, fn, one);
697
      }
698
      if (sizes.includes(' ')) {
699
        var union = this.getUnion(sizes);
700
 
701
        if (union) {
702
          union.on(types, data, fn, one);
703
        }
704
      } else {
705
        var size = this.get(sizes);
706
 
707
        if (size) {
708
          size.on(types, data, fn, one);
709
        }
710
      }
711
 
712
      return this;
713
    },
714
    one: function one(sizes, types, data, fn) {
715
      return this.on(sizes, types, data, fn, true);
716
    },
717
    off: function off(sizes, types, fn) {
718
      sizes = sizes.trim();
719
 
720
      if (sizes === 'change') {
721
        return ChangeEvent.off(types);
722
      }
723
 
724
      if (sizes.includes(' ')) {
725
        var union = this.getUnion(sizes);
726
 
727
        if (union) {
728
          union.off(types, fn);
729
        }
730
      } else {
731
        var size = this.get(sizes);
732
 
733
        if (size) {
734
          size.off(types, fn);
735
        }
736
      }
737
 
738
      return this;
739
    }
740
  });
741
 
742
  var Breakpoints$1 = Breakpoints;
743
 
744
  exports.default = Breakpoints$1;
745
});