Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: third_party/polymer/components-chromium/core-drawer-panel/core-drawer-panel-extracted.js

Issue 592593002: Inline scripts were extracted from Polymer elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/echo ""/echo/ Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1
2
3 Polymer('core-drawer-panel', {
4 /**
5 * Fired when the narrow layout changes.
6 *
7 * @event core-responsive-change
8 * @param {Object} detail
9 * @param {boolean} detail.narrow true if the panel is in narrow layout.
10 */
11
12 publish: {
13
14 /**
15 * Width of the drawer panel.
16 *
17 * @attribute drawerWidth
18 * @type string
19 * @default '256px'
20 */
21 drawerWidth: '256px',
22
23 /**
24 * Max-width when the panel changes to narrow layout.
25 *
26 * @attribute responsiveWidth
27 * @type string
28 * @default '640px'
29 */
30 responsiveWidth: '640px',
31
32 /**
33 * The panel that is being selected. `drawer` for the drawer panel and
34 * `main` for the main panel.
35 *
36 * @attribute selected
37 * @type string
38 * @default null
39 */
40 selected: {value: null, reflect: true},
41
42 /**
43 * The panel to be selected when `core-drawer-panel` changes to narrow
44 * layout.
45 *
46 * @attribute defaultSelected
47 * @type string
48 * @default 'main'
49 */
50 defaultSelected: 'main',
51
52 /**
53 * Returns true if the panel is in narrow layout. This is useful if you
54 * need to show/hide elements based on the layout.
55 *
56 * @attribute narrow
57 * @type boolean
58 * @default false
59 */
60 narrow: {value: false, reflect: true},
61
62 /**
63 * If true, position the drawer to the right.
64 *
65 * @attribute rightDrawer
66 * @type boolean
67 * @default false
68 */
69 rightDrawer: false,
70
71 /**
72 * If true, swipe to open/close the drawer is disabled.
73 *
74 * @attribute disableSwipe
75 * @type boolean
76 * @default false
77 */
78 disableSwipe: false
79 },
80
81 eventDelegates: {
82 trackstart: 'trackStart',
83 trackx: 'trackx',
84 trackend: 'trackEnd'
85 },
86
87 transition: false,
88
89 edgeSwipeSensitivity : 15,
90
91 dragging : false,
92
93 domReady: function() {
94 // to avoid transition at the beginning e.g. page loads
95 // NOTE: domReady is already raf delayed and delaying another frame
96 // ensures a layout has occurred.
97 this.async(function() {
98 this.transition = true;
99 });
100 },
101
102 /**
103 * Toggles the panel open and closed.
104 *
105 * @method togglePanel
106 */
107 togglePanel: function() {
108 this.selected = this.selected === 'main' ? 'drawer' : 'main';
109 },
110
111 /**
112 * Opens the drawer.
113 *
114 * @method openDrawer
115 */
116 openDrawer: function() {
117 this.selected = 'drawer';
118 },
119
120 /**
121 * Closes the drawer.
122 *
123 * @method closeDrawer
124 */
125 closeDrawer: function() {
126 this.selected = 'main';
127 },
128
129 queryMatchesChanged: function() {
130 if (this.queryMatches) {
131 this.selected = this.defaultSelected;
132 }
133 this.narrow = this.queryMatches;
134 this.setAttribute('touch-action',
135 this.narrow && !this.disableSwipe ? 'pan-y' : '');
136 this.fire('core-responsive-change', {narrow: this.narrow});
137 },
138
139 // swipe support for the drawer, inspired by
140 // https://github.com/Polymer/core-drawer-panel/pull/6
141 trackStart : function(e) {
142 if (this.narrow && !this.disableSwipe) {
143 this.dragging = true;
144
145 if (this.selected === 'main') {
146 this.dragging = this.rightDrawer ?
147 e.pageX >= this.offsetWidth - this.edgeSwipeSensitivity :
148 e.pageX <= this.edgeSwipeSensitivity;
149 }
150
151 if (this.dragging) {
152 this.width = this.$.drawer.offsetWidth;
153 this.transition = false;
154 e.preventTap();
155 }
156 }
157 },
158
159 trackx : function(e) {
160 if (this.dragging) {
161 var x;
162 if (this.rightDrawer) {
163 x = Math.max(0, (this.selected === 'main') ? this.width + e.dx : e.dx) ;
164 } else {
165 x = Math.min(0, (this.selected === 'main') ? e.dx - this.width : e.dx) ;
166 }
167 this.moveDrawer(x);
168 }
169 },
170
171 trackEnd : function(e) {
172 if (this.dragging) {
173 this.dragging = false;
174 this.transition = true;
175 this.moveDrawer(null);
176
177 if (this.rightDrawer) {
178 this.selected = e.xDirection > 0 ? 'main' : 'drawer';
179 } else {
180 this.selected = e.xDirection > 0 ? 'drawer' : 'main';
181 }
182 }
183 },
184
185 moveDrawer: function(translateX) {
186 var s = this.$.drawer.style;
187 s.webkitTransform = s.transform =
188 translateX === null ? '' : 'translate3d(' + translateX + 'px, 0, 0)';
189 }
190
191 });
192
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698