Rift.IO OSM R1 Initial Submission
[osm/UI.git] / skyquake / plugins / composer / src / src / actions / PanelResizeAction.js
1
2 /*
3 *
4 * Copyright 2016 RIFT.IO Inc
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19 /**
20 * Created by onvelocity on 8/11/15.
21 */
22 import alt from '../alt';
23 import changeCase from 'change-case'
24
25 /*
26 This class manages Composer Layout State
27 */
28
29 const cleanNameRegExp = /(-is-tray-open|panel-)/i;
30
31 class PanelResizeAction {
32
33 resize(e) {
34
35 /* we expect two types of resize events:
36 * window resize - invoked by window
37 * resize-manager resize - invoked by ResizeManager
38 *
39 * normalize the data needed by the Composer Layout or ignore invalid ones
40 *
41 * */
42
43 if (!e) {
44 return false;
45 }
46
47 if (e.detail && e.detail.side) {
48 // a ResizeManager event
49 this.dispatch(PanelResizeAction.buildResizeManagerInfo(e))
50 } else {
51 // a window event
52 this.dispatch(PanelResizeAction.buildWindowResizeInfo(e));
53 }
54
55 }
56
57 static buildWindowResizeInfo(e) {
58 return e;
59 }
60
61 static buildResizeManagerInfo(e) {
62 const info = Object.assign({originalEvent: e}, e.detail);
63 const name = changeCase.paramCase(info.target.className.replace(cleanNameRegExp, ''));
64 info.type = 'resize-manager.resize.' + name;
65 return info;
66 }
67
68 }
69
70 export default alt.createActions(PanelResizeAction);