@egjs/flicking 4.12.0-beta.2 → 4.12.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/flicking.js CHANGED
@@ -4,7 +4,7 @@ name: @egjs/flicking
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-flicking
7
- version: 4.12.0-beta.2
7
+ version: 4.12.0-beta.3
8
8
  */
9
9
  (function (global, factory) {
10
10
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@egjs/component'), require('@egjs/axes'), require('@egjs/imready')) :
@@ -753,6 +753,26 @@ version: 4.12.0-beta.2
753
753
  obj.__proto__ = proto;
754
754
  return obj;
755
755
  };
756
+ var camelize = function (str) {
757
+ return str.replace(/[\s-_]([a-z])/g, function (all, letter) {
758
+ return letter.toUpperCase();
759
+ });
760
+ };
761
+ var getDataAttributes = function (element, attributePrefix) {
762
+ var dataAttributes = {};
763
+ var attributes = element.attributes;
764
+ var length = attributes.length;
765
+ for (var i = 0; i < length; ++i) {
766
+ var attribute = attributes[i];
767
+ var name_1 = attribute.name,
768
+ value = attribute.value;
769
+ if (name_1.indexOf(attributePrefix) === -1) {
770
+ continue;
771
+ }
772
+ dataAttributes[camelize(name_1.replace(attributePrefix, ""))] = value;
773
+ }
774
+ return dataAttributes;
775
+ };
756
776
 
757
777
  var Utils = {
758
778
  __proto__: null,
@@ -784,7 +804,9 @@ version: 4.12.0-beta.2
784
804
  circulateIndex: circulateIndex,
785
805
  range: range,
786
806
  getElementSize: getElementSize,
787
- setPrototypeOf: setPrototypeOf
807
+ setPrototypeOf: setPrototypeOf,
808
+ camelize: camelize,
809
+ getDataAttributes: getDataAttributes
788
810
  };
789
811
 
790
812
  /*
@@ -7969,7 +7991,7 @@ version: 4.12.0-beta.2
7969
7991
  * Flicking.VERSION; // ex) 4.0.0
7970
7992
  * ```
7971
7993
  */
7972
- Flicking.VERSION = "4.12.0-beta.2";
7994
+ Flicking.VERSION = "4.12.0-beta.3";
7973
7995
  return Flicking;
7974
7996
  }(Component);
7975
7997
 
@@ -8057,15 +8079,14 @@ version: 4.12.0-beta.2
8057
8079
  _this._syncToCategory(e.index, _this.index);
8058
8080
  }
8059
8081
  };
8060
- var horizontalPanels = toArray(getElement(root).children[0].children);
8061
8082
  // Internal states
8062
- _this._verticalState = _this._createVerticalState(horizontalPanels);
8083
+ _this._verticalState = _this._createVerticalState();
8063
8084
  _this._moveDirection = null;
8064
8085
  _this._nextIndex = 0;
8065
8086
  // Bind options
8066
8087
  _this._verticalOptions = verticalOptions;
8067
8088
  // Create core components
8068
- _this._verticalFlicking = _this._createVerticalFlicking(horizontalPanels);
8089
+ _this._verticalFlicking = _this._createVerticalFlicking();
8069
8090
  return _this;
8070
8091
  }
8071
8092
  var __proto = CrossFlicking.prototype;
@@ -8147,36 +8168,82 @@ version: 4.12.0-beta.2
8147
8168
  flicking.on(EVENTS.CHANGED, _this._onVerticalChanged);
8148
8169
  });
8149
8170
  };
8150
- __proto._createVerticalState = function (panels) {
8171
+ __proto._createVerticalState = function () {
8172
+ var _this = this;
8151
8173
  // data-index로 분류하기 전에 임시로 모든 children에 대해 vertical flicking으로 해보자.
8152
8174
  // panels에 data-attributes가 붙어있을 때와 안 붙어있을 때를 다르게 처리
8153
8175
  // 붙어있다면 가상의 viewport들을 index 갯수만큼 만들어줘야 한다
8176
+ var cameraEl = this.camera.element;
8177
+ var panels = toArray(cameraEl.children);
8178
+ var verticalState;
8154
8179
  var verticalPanels = "";
8155
- var verticalState = panels.reduce(function (state, panel) {
8156
- var start = state.length ? +state[state.length - 1].end + 1 : 0;
8157
- verticalPanels += panel.innerHTML;
8158
- return __spread(state, [{
8159
- start: start,
8160
- end: start + panel.children.length - 1,
8161
- element: panel
8162
- }]);
8163
- }, []);
8180
+ // check data attribute exists
8181
+ var groupKeys = [];
8182
+ var groupPanels = {};
8164
8183
  var verticalCamera = document.createElement("div");
8165
8184
  verticalCamera.classList.add(CLASS.CAMERA);
8166
- verticalCamera.innerHTML = verticalPanels;
8167
8185
  panels.forEach(function (panel) {
8168
- [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
8169
- if (!panel.classList.contains(className)) {
8170
- panel.classList.add(className);
8171
- }
8172
- });
8173
- panel.innerHTML = verticalCamera.outerHTML;
8186
+ var groupKey = getDataAttributes(panel, "data-flicking-").groupkey;
8187
+ if (groupKey && !includes(groupKeys, groupKey)) {
8188
+ groupKeys.push(groupKey);
8189
+ groupPanels[groupKey] = [panel];
8190
+ } else if (groupKey) {
8191
+ groupPanels[groupKey].push(panel);
8192
+ }
8193
+ return groupKey;
8174
8194
  });
8195
+ if (groupKeys.length) {
8196
+ panels.forEach(function () {
8197
+ return _this.remove(0);
8198
+ });
8199
+ verticalState = groupKeys.reduce(function (state, key) {
8200
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
8201
+ var element = groupPanels[key].reduce(function (el, panel) {
8202
+ verticalPanels += panel.outerHTML;
8203
+ el.appendChild(panel);
8204
+ return el;
8205
+ }, document.createElement("div"));
8206
+ return __spread(state, [{
8207
+ key: key,
8208
+ start: start,
8209
+ end: start + groupPanels[key].length - 1,
8210
+ element: element
8211
+ }]);
8212
+ }, []);
8213
+ verticalCamera.innerHTML = verticalPanels;
8214
+ cameraEl.innerHTML = "";
8215
+ groupKeys.forEach(function () {
8216
+ var panel = document.createElement("div");
8217
+ panel.classList.add(CLASS.VIEWPORT, CLASS.VERTICAL);
8218
+ panel.innerHTML = verticalCamera.outerHTML;
8219
+ _this.append(panel);
8220
+ });
8221
+ } else {
8222
+ verticalState = panels.reduce(function (state, panel, i) {
8223
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
8224
+ verticalPanels += panel.innerHTML;
8225
+ return __spread(state, [{
8226
+ key: i.toString(),
8227
+ start: start,
8228
+ end: start + panel.children.length - 1,
8229
+ element: panel
8230
+ }]);
8231
+ }, []);
8232
+ verticalCamera.innerHTML = verticalPanels;
8233
+ panels.forEach(function (panel) {
8234
+ [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
8235
+ if (!panel.classList.contains(className)) {
8236
+ panel.classList.add(className);
8237
+ }
8238
+ });
8239
+ panel.innerHTML = verticalCamera.outerHTML;
8240
+ });
8241
+ }
8175
8242
  return verticalState;
8176
8243
  };
8177
- __proto._createVerticalFlicking = function (panels) {
8244
+ __proto._createVerticalFlicking = function () {
8178
8245
  var _this = this;
8179
- return panels.map(function (panel, i) {
8246
+ return this.camera.children.map(function (panel, i) {
8180
8247
  return new Flicking(panel, __assign(__assign({}, _this.verticalOptions), {
8181
8248
  horizontal: false,
8182
8249
  panelsPerView: 1,