]> git.proxmox.com Git - extjs.git/blame - extjs/build/examples/classic/shared/options-toolbar.js
add extjs 6.0.1 sources
[extjs.git] / extjs / build / examples / classic / shared / options-toolbar.js
CommitLineData
6527f429
DM
1(function() {\r
2 function getQueryParam(name, queryString) {\r
3 var match = RegExp(name + '=([^&]*)').exec(queryString || location.search);\r
4 return match && decodeURIComponent(match[1]);\r
5 }\r
6\r
7 function hasOption(opt) {\r
8 var s = window.location.search;\r
9 var re = new RegExp('(?:^|[&?])' + opt + '(?:[=]([^&]*))?(?:$|[&])', 'i');\r
10 var m = re.exec(s);\r
11\r
12 return m ? (m[1] === undefined ? true : m[1]) : false;\r
13 }\r
14\r
15 var scriptTags = document.getElementsByTagName('script'),\r
16 defaultTheme = 'triton',\r
17 defaultRtl = false,\r
18 i = scriptTags.length,\r
19 requires = [\r
20 'Ext.window.MessageBox',\r
21 'Ext.toolbar.Toolbar',\r
22 'Ext.form.field.ComboBox',\r
23 'Ext.form.FieldContainer',\r
24 'Ext.form.field.Radio'\r
25\r
26 ],\r
27 comboWidth = {\r
28 classic: 160,\r
29 gray: 160,\r
30 neptune: 180,\r
31 triton: 180,\r
32 crisp: 180,\r
33 'neptune-touch': 220,\r
34 'crisp-touch': 220\r
35 },\r
36 labelWidth = {\r
37 classic: 40,\r
38 gray: 40,\r
39 neptune: 45,\r
40 triton: 45,\r
41 crisp: 45,\r
42 'neptune-touch': 55,\r
43 'crisp-touch': 55\r
44 },\r
45 defaultQueryString, src, theme, rtl, toolbar;\r
46\r
47 while (i--) {\r
48 src = scriptTags[i].src;\r
49 if (src.indexOf('include-ext.js') !== -1) {\r
50 defaultQueryString = src.split('?')[1];\r
51 if (defaultQueryString) {\r
52 defaultTheme = getQueryParam('theme', defaultQueryString) || defaultTheme;\r
53 defaultRtl = getQueryParam('rtl', defaultQueryString) || defaultRtl;\r
54 }\r
55 break;\r
56 }\r
57 }\r
58\r
59 Ext.themeName = theme = getQueryParam('theme') || defaultTheme;\r
60 \r
61 rtl = getQueryParam('rtl') || defaultRtl;\r
62\r
63 if (rtl.toString() === 'true') {\r
64 requires.unshift('Ext.rtl.*');\r
65 Ext.define('Ext.examples.RtlComponent', {\r
66 override: 'Ext.Component',\r
67 rtl: true\r
68 });\r
69 }\r
70\r
71 Ext.require(requires);\r
72\r
73 Ext.onReady(function() {\r
74 Ext.getBody().addCls(Ext.baseCSSPrefix + 'theme-' + Ext.themeName);\r
75\r
76 // prevent touchmove from panning the viewport in mobile safari\r
77 if (Ext.supports.TouchEvents) {\r
78 Ext.getDoc().on({\r
79 touchmove: function(e) {\r
80 // If within a scroller, don't let the document use it\r
81 if (Ext.scroll.Scroller.isTouching) {\r
82 e.preventDefault();\r
83 }\r
84 },\r
85 translate: false,\r
86 delegated: false\r
87 });\r
88 }\r
89\r
90 if (hasOption('nocss3')) {\r
91 Ext.supports.CSS3BorderRadius = false;\r
92 Ext.getBody().addCls('x-nbr x-nlg');\r
93 }\r
94\r
95 if (hasOption('nlg')) {\r
96 Ext.getBody().addCls('x-nlg');\r
97 }\r
98\r
99 function setParam(param) {\r
100 var queryString = Ext.Object.toQueryString(\r
101 Ext.apply(Ext.Object.fromQueryString(location.search), param)\r
102 );\r
103 location.search = queryString;\r
104 }\r
105\r
106 function removeParam(paramName) {\r
107 var params = Ext.Object.fromQueryString(location.search);\r
108\r
109 delete params[paramName];\r
110\r
111 location.search = Ext.Object.toQueryString(params);\r
112 }\r
113 \r
114 if (hasOption('no-toolbar') || /no-toolbar/.test(document.cookie)) {\r
115 return;\r
116 }\r
117\r
118 if (hasOption('no-toolbar') || /no-toolbar/.test(document.cookie)) {\r
119 return;\r
120 }\r
121\r
122 setTimeout(function() {\r
123 toolbar = Ext.widget({\r
124 xtype: 'toolbar',\r
125 border: true,\r
126 rtl: false,\r
127 id: 'options-toolbar',\r
128 floating: true,\r
129 fixed: true,\r
130 preventFocusOnActivate: true,\r
131 draggable: {\r
132 constrain: true\r
133 },\r
134 defaults : { rtl : false },\r
135 items: [{\r
136 xtype: 'combo',\r
137 width: comboWidth[Ext.themeName],\r
138 labelWidth: labelWidth[Ext.themeName],\r
139 fieldLabel: 'Theme',\r
140 displayField: 'name',\r
141 valueField: 'value',\r
142 labelStyle: 'cursor:move;',\r
143 margin: '0 5 0 0',\r
144 queryMode: 'local',\r
145 store: Ext.create('Ext.data.Store', {\r
146 fields: ['value', 'name'],\r
147 data : [\r
148 { value: 'triton', name: 'Triton' },\r
149 { value: 'neptune', name: 'Neptune' },\r
150 { value: 'neptune-touch', name: 'Neptune Touch' },\r
151 { value: 'crisp', name: 'Crisp' },\r
152 { value: 'crisp-touch', name: 'Crisp Touch' },\r
153 { value: 'classic', name: 'Classic' },\r
154 { value: 'gray', name: 'Gray' }\r
155 ]\r
156 }),\r
157 value: theme,\r
158 listeners: {\r
159 select: function(combo) {\r
160 var theme = combo.getValue();\r
161 if (theme !== defaultTheme) {\r
162 setParam({ theme: theme });\r
163 } else {\r
164 removeParam('theme');\r
165 }\r
166 }\r
167 }\r
168 }, {\r
169\r
170 /**\r
171 * Only visible in repoDevMode and on QA sites\r
172 */\r
173 xtype: 'button',\r
174 hidden: !(Ext.repoDevMode || location.href.indexOf('qa.sencha.com') !== -1),\r
175 enableToggle: true,\r
176 pressed: rtl,\r
177 text: 'RTL',\r
178 margin: '0 5 0 0',\r
179 listeners: {\r
180 toggle: function(btn, pressed) {\r
181 if (pressed) {\r
182 setParam({ rtl: true });\r
183 } else {\r
184 removeParam('rtl');\r
185 }\r
186 }\r
187 }\r
188 }, {\r
189 xtype: 'tool',\r
190 type: 'close',\r
191 handler: function() {\r
192 toolbar.destroy();\r
193 }\r
194 }],\r
195\r
196 // Extra constraint margins within default constrain region of parentNode\r
197 constraintInsets: '0 -' + (Ext.getScrollbarSize().width + 5) + ' 0 0'\r
198 });\r
199 toolbar.show();\r
200 toolbar.anchorTo(\r
201 document.body,\r
202 Ext.optionsToolbarAlign || 'tr-tr',\r
203 [-(Ext.getScrollbarSize().width + 5), 0], //adjust for scrollbar offsets\r
204 false, //anim\r
205 true //monitor scroll\r
206 );\r
207\r
208 }, 100);\r
209\r
210 });\r
211})();\r