Skip to content

Commit 223b87d

Browse files
author
Marcelo Tosco @capynet
committed
Fix demo page path.
1 parent dd866b7 commit 223b87d

2 files changed

Lines changed: 154 additions & 1 deletion

File tree

sample/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ <h2>Resize the browser, "Logo" & "Search box" will be repositioned.</h2>
111111
</script>
112112

113113
<script src="js/mediaQueryEvents.jquery.js"></script>
114-
<script src="../dist/DOMElementRelocation.js"></script>
114+
<script src="./js/DOMElementRelocation.js"></script>
115115
<script src="./js/sample.js"></script>
116116
<script>hljs.initHighlightingOnLoad();</script>
117117
</body>

sample/js/DOMElementRelocation.js

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2+
'use strict';
3+
4+
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
5+
6+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
7+
8+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9+
10+
var DOMElementRelocation = function () {
11+
function DOMElementRelocation(conf) {
12+
_classCallCheck(this, DOMElementRelocation);
13+
14+
var self = this;
15+
16+
self.$win = $(window);
17+
18+
// Some defaults.
19+
self.opts = Object.assign({
20+
breakpoints: {
21+
desk: '(min-width: 1230px)',
22+
tab: '(min-width: 768px) and (max-width: 1229px)',
23+
mob: '(min-width: 0px) and (max-width: 767px)'
24+
},
25+
elements: []
26+
}, conf);
27+
28+
self._registerElements();
29+
self._registerBreakpoints();
30+
}
31+
32+
/**
33+
* Register elements to mediaQueryEvents event.
34+
*
35+
* @private
36+
*/
37+
38+
39+
_createClass(DOMElementRelocation, [{
40+
key: '_registerElements',
41+
value: function () {
42+
function _registerElements() {
43+
var self = this;
44+
45+
// Loop al defined breakpoints. Each time browser reaches one of them,
46+
// mediaQueryEvents will act and execute the new position of the
47+
// elements assigned to this breakpoint.
48+
Object.entries(this.opts.breakpoints).map(function (_ref) {
49+
var _ref2 = _slicedToArray(_ref, 2),
50+
k = _ref2[0],
51+
v = _ref2[1];
52+
53+
self.$win.on('mq.' + k, function (e) {
54+
self._bulkRelocate(k);
55+
});
56+
});
57+
}
58+
59+
return _registerElements;
60+
}()
61+
62+
/**
63+
* Register breakpoints to mediaQueryEvents.
64+
*
65+
* @private
66+
*/
67+
68+
}, {
69+
key: '_registerBreakpoints',
70+
value: function () {
71+
function _registerBreakpoints() {
72+
var self = this;
73+
74+
self.$win.mediaQueryEvents({
75+
breakpoints: self.opts.breakpoints
76+
});
77+
}
78+
79+
return _registerBreakpoints;
80+
}()
81+
82+
/**
83+
* Relocates a group of elements.
84+
* @param breakpoint
85+
* @param pos
86+
*
87+
* @private
88+
*/
89+
90+
}, {
91+
key: '_bulkRelocate',
92+
value: function () {
93+
function _bulkRelocate(breakpoint) {
94+
var pos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "top";
95+
96+
var self = this;
97+
98+
self.opts.elements.forEach(function (el) {
99+
self._relocate(el.element, el[breakpoint], pos);
100+
});
101+
}
102+
103+
return _bulkRelocate;
104+
}()
105+
106+
/**
107+
* Moves a DOM element to a new location.
108+
*
109+
* @param el
110+
* @param $target
111+
* @param position
112+
*
113+
* @private
114+
*/
115+
116+
}, {
117+
key: '_relocate',
118+
value: function () {
119+
function _relocate(el, $target, position) {
120+
var $el = $(el);
121+
122+
// First time we memorize the original position.
123+
if ($el.data('original-position') === undefined) {
124+
var $originalPosHolder = $('<div class="original-position-holder" />');
125+
$el.data('original-position', $originalPosHolder);
126+
$originalPosHolder.insertAfter($el);
127+
}
128+
129+
if ($target === false) {
130+
var $orig = $el.data('original-position');
131+
$el.insertAfter($orig);
132+
}
133+
134+
if (position === 'top') {
135+
$el.prependTo($target);
136+
} else {
137+
$el.appendTo($target);
138+
}
139+
}
140+
141+
return _relocate;
142+
}()
143+
}]);
144+
145+
return DOMElementRelocation;
146+
}();
147+
148+
// Expose the class to window.
149+
150+
151+
window.DOMElementRelocation = DOMElementRelocation;
152+
153+
},{}]},{},[1])//# sourceMappingURL=DOMElementRelocation.js.map

0 commit comments

Comments
 (0)