@mapgis/webclient-mapboxgl-plugin 10.3.4 → 17.0.0

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.
Files changed (91) hide show
  1. package/README.md +51 -124
  2. package/dist/es5/webclient-common.min.js +90 -0
  3. package/dist/es5/webclient-mapboxgl-plugin.min.js +1 -0
  4. package/dist/webclient-mapboxgl-plugin-es6.min.js +1 -0
  5. package/documention/EchartsLayer.html +379 -0
  6. package/documention/MapViewMapboxgl.html +3587 -0
  7. package/documention/Popup.html +1523 -0
  8. package/documention/Screenshot.html +1089 -0
  9. package/documention/SketchEditorMapboxgl.html +3383 -0
  10. package/documention/document_ArcGISVectorTileLayerView.js.html +265 -0
  11. package/documention/document_EchartsLayerView.js.html +246 -0
  12. package/documention/document_GraphicsLayerView.js.html +314 -0
  13. package/documention/document_IGSFeatureLayerView.js.html +218 -0
  14. package/documention/document_IGSMapImageLayerView.js.html +240 -0
  15. package/documention/document_IGSTileLayerView.js.html +236 -0
  16. package/documention/document_IGSVectorTileLayerView.js.html +264 -0
  17. package/documention/document_MapVLayerView.js.html +247 -0
  18. package/documention/document_WMSLayerView.js.html +240 -0
  19. package/documention/document_WMTSLayerView.js.html +234 -0
  20. package/documention/document_WebTileLayerView.js.html +240 -0
  21. package/documention/document_support_FeatureRenderView.js.html +682 -0
  22. package/documention/document_support_MapboxglGraphicsLayer.js.html +1184 -0
  23. package/documention/document_support_SourceMetaData.js.html +223 -0
  24. package/documention/document_support_Utils.js.html +624 -0
  25. package/documention/document_support_mapbox_mapboxCustomUtil.js.html +322 -0
  26. package/documention/global.html +252 -0
  27. package/documention/index.html +251 -0
  28. package/documention/module-%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%8F%AF%E8%A7%86%E5%8C%96.MapvLayer.html +445 -0
  29. package/documention/scripts/app.min.js +1 -0
  30. package/documention/scripts/linenumber.js +26 -0
  31. package/documention/scripts/search.js +45 -0
  32. package/documention/scripts/sideBar.js +11 -0
  33. package/documention/sketchEditor_SketchEditorMapboxgl.js.html +875 -0
  34. package/documention/styles/anchor.png +0 -0
  35. package/documention/styles/app.min.css +1 -0
  36. package/documention/styles/c.png +0 -0
  37. package/documention/styles/iframe.css +29 -0
  38. package/documention/styles/m.png +0 -0
  39. package/documention/styles/prettify-jsdoc.css +111 -0
  40. package/documention/styles/prettify-tomorrow.css +132 -0
  41. package/documention/styles/reset.css +44 -0
  42. package/documention/styles/up-arrow.png +0 -0
  43. package/documention/tutorial-1./345/277/253/351/200/237/345/205/245/351/227/250.html +165 -0
  44. package/documention/util_ConvertRendererToStyleLayerUtil.js.html +844 -0
  45. package/documention/util_MapboxglFeatureRender.js.html +225 -0
  46. package/documention/util_MapboxglPlugin.js.html +284 -0
  47. package/documention/view_MapViewMapboxgl.js.html +1882 -0
  48. package/documention/view_utils_ArcGISVectorTileLayerUtil.js.html +382 -0
  49. package/documention/view_utils_EchartsLayerUtil.js.html +194 -0
  50. package/documention/view_utils_IGSMapImageUtil.js.html +373 -0
  51. package/documention/view_utils_IGSTileLayerUtil.js.html +285 -0
  52. package/documention/view_utils_IGSVectorTileLayerUtil.js.html +379 -0
  53. package/documention/view_utils_MapVLayerUtil.js.html +197 -0
  54. package/documention/view_utils_Popup.js.html +525 -0
  55. package/documention/view_utils_Screenshot.js.html +320 -0
  56. package/documention/view_utils_WMSLayerUtil.js.html +337 -0
  57. package/documention/view_utils_WMTSLayerUtil.js.html +331 -0
  58. package/documention/view_utils_WebTileLayerUtil.js.html +284 -0
  59. package/documention/view_utils_echarts_EchartsLayerPlugin.js.html +419 -0
  60. package/documention/view_utils_mapV_MapVLayerPlugin.js.html +527 -0
  61. package/documention/view_utils_mapV_MapvBaseLayer.js.html +477 -0
  62. package/documention/view_utils_support_rasterLayerUtil.js.html +244 -0
  63. package/documention/view_utils_support_vectorLayerUtil.js.html +503 -0
  64. package/package.json +20 -20
  65. package/core/Base.js +0 -15
  66. package/core/index.js +0 -5
  67. package/index.js +0 -6
  68. package/overlay/D3Layer.js +0 -108
  69. package/overlay/EchartsLayer.js +0 -242
  70. package/overlay/ElsCubeLayer.js +0 -125
  71. package/overlay/MapvLayer.js +0 -296
  72. package/overlay/StreamLayer.js +0 -83
  73. package/overlay/TimeSpaceCubeLayer.js +0 -135
  74. package/overlay/dthree/mapbox-d3.css +0 -9
  75. package/overlay/echarts/MapCoordSys.js +0 -105
  76. package/overlay/echarts/MapModel.js +0 -0
  77. package/overlay/echarts/MapView.js +0 -0
  78. package/overlay/echarts/index.js +0 -4
  79. package/overlay/index.js +0 -31
  80. package/overlay/mapv/MapvBaseLayer.js +0 -299
  81. package/overlay/mapv/index.js +0 -5
  82. package/overlay/stream/GeojsonStreamLayer.js +0 -135
  83. package/overlay/stream/MapvStreamLayer.js +0 -79
  84. package/overlay/stream/index.js +0 -3
  85. package/overlay/stream/popup.css +0 -31
  86. package/service/index.js +0 -1
  87. package/service/socket/ISocketService.js +0 -121
  88. package/service/socket/SocketEvent.js +0 -50
  89. package/service/socket/SocketService.js +0 -90
  90. package/util/Evented.js +0 -295
  91. package/util/Util.js +0 -348
package/util/Evented.js DELETED
@@ -1,295 +0,0 @@
1
- import * as Util from "./Util";
2
-
3
- /*
4
- * @class Evented
5
- * @aka L.Evented
6
- * @inherits Class
7
- *
8
- * A set of methods shared between event-powered classes (like `Map` and `Marker`). Generally, Evented allow you to execute some function when something happens with an object (e.g. the user clicks on the map, causing the map to fire `'click'` event).
9
- *
10
- * @example
11
- *
12
- * ```js
13
- * map.on('click', function(e) {
14
- * alert(e.latlng);
15
- * } );
16
- * ```
17
- *
18
- * Leaflet deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function:
19
- *
20
- * ```js
21
- * function onClick(e) { ... }
22
- *
23
- * map.on('click', onClick);
24
- * map.off('click', onClick);
25
- * ```
26
- */
27
-
28
- export class Evented {
29
- /* @method on(type: String, fn: Function, context?: Object): this
30
- * Adds a listener function (`fn`) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. `'click dblclick'`).
31
- *
32
- * @alternative
33
- * @method on(eventMap: Object): this
34
- * Adds a set of type/listener pairs, e.g. `{click: onClick, mousemove: onMouseMove}`
35
- */
36
- on(types, fn, context) {
37
- // types can be a map of types/handlers
38
- if (typeof types === "object") {
39
- for (var type in types) {
40
- // we don't process space-separated Evented here for performance;
41
- // it's a hot path since Layer uses the on(obj) syntax
42
- this._on(type, types[type], fn);
43
- }
44
- } else {
45
- // types can be a string of space-separated words
46
- types = Util.splitWords(types);
47
-
48
- for (var i = 0, len = types.length; i < len; i++) {
49
- this._on(types[i], fn, context);
50
- }
51
- }
52
-
53
- return this;
54
- }
55
-
56
- /* @method off(type: String, fn?: Function, context?: Object): this
57
- * Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to `on`, you must pass the same context to `off` in order to remove the listener.
58
- *
59
- * @alternative
60
- * @method off(eventMap: Object): this
61
- * Removes a set of type/listener pairs.
62
- *
63
- * @alternative
64
- * @method off: this
65
- * Removes all listeners to all Evented on the object.
66
- */
67
- off(types, fn, context) {
68
- if (!types) {
69
- // clear all listeners if called without arguments
70
- delete this._Evented;
71
- } else if (typeof types === "object") {
72
- for (var type in types) {
73
- this._off(type, types[type], fn);
74
- }
75
- } else {
76
- types = Util.splitWords(types);
77
-
78
- for (var i = 0, len = types.length; i < len; i++) {
79
- this._off(types[i], fn, context);
80
- }
81
- }
82
-
83
- return this;
84
- }
85
-
86
- // attach listener (without syntactic sugar now)
87
- _on(type, fn, context) {
88
- this._Evented = this._Evented || {};
89
-
90
- /* get/init listeners for type */
91
- var typeListeners = this._Evented[type];
92
- if (!typeListeners) {
93
- typeListeners = [];
94
- this._Evented[type] = typeListeners;
95
- }
96
-
97
- if (context === this) {
98
- // Less memory footprint.
99
- context = undefined;
100
- }
101
- var newListener = { fn: fn, ctx: context },
102
- listeners = typeListeners;
103
-
104
- // check if fn already there
105
- for (var i = 0, len = listeners.length; i < len; i++) {
106
- if (listeners[i].fn === fn && listeners[i].ctx === context) {
107
- return;
108
- }
109
- }
110
-
111
- listeners.push(newListener);
112
- }
113
-
114
- _off(type, fn, context) {
115
- var listeners, i, len;
116
-
117
- if (!this._Evented) {
118
- return;
119
- }
120
-
121
- listeners = this._Evented[type];
122
-
123
- if (!listeners) {
124
- return;
125
- }
126
-
127
- if (!fn) {
128
- // Set all removed listeners to noop so they are not called if remove happens in fire
129
- for (i = 0, len = listeners.length; i < len; i++) {
130
- listeners[i].fn = Util.falseFn;
131
- }
132
- // clear all listeners for a type if function isn't specified
133
- delete this._Evented[type];
134
- return;
135
- }
136
-
137
- if (context === this) {
138
- context = undefined;
139
- }
140
-
141
- if (listeners) {
142
- // find fn and remove it
143
- for (i = 0, len = listeners.length; i < len; i++) {
144
- var l = listeners[i];
145
- if (l.ctx !== context) {
146
- continue;
147
- }
148
- if (l.fn === fn) {
149
- // set the removed listener to noop so that's not called if remove happens in fire
150
- l.fn = Util.falseFn;
151
-
152
- if (this._firingCount) {
153
- /* copy array in case Evented are being fired */
154
- this._Evented[type] = listeners = listeners.slice();
155
- }
156
- listeners.splice(i, 1);
157
-
158
- return;
159
- }
160
- }
161
- }
162
- }
163
-
164
-
165
- // @method fire(type: String, data?: Object, propagate?: Boolean): this
166
- // Fires an event of the specified type. You can optionally provide an data
167
- // object — the first argument of the listener function will contain its
168
- // properties. The event can optionally be propagated to event parents.
169
- fire(type, data, propagate) {
170
- if (!this.listens(type, propagate)) {
171
- return this;
172
- }
173
-
174
- var event = Util.extend({}, data, {
175
- type: type,
176
- target: this,
177
- sourceTarget: (data && data.sourceTarget) || this
178
- });
179
-
180
- if (this._Evented) {
181
- var listeners = this._Evented[type];
182
-
183
- if (listeners) {
184
- this._firingCount = this._firingCount + 1 || 1;
185
- for (var i = 0, len = listeners.length; i < len; i++) {
186
- var l = listeners[i];
187
- l.fn.call(l.ctx || this, event);
188
- }
189
-
190
- this._firingCount--;
191
- }
192
- }
193
-
194
- if (propagate) {
195
- // propagate the event to parents (set with addEventParent)
196
- this._propagateEvent(event);
197
- }
198
- return this;
199
- }
200
-
201
- // @method listens(type: String): Boolean
202
- // Returns `true` if a particular event type has any listeners attached to it.
203
- listens(type, propagate) {
204
- var listeners = this._Evented && this._Evented[type];
205
- if (listeners && listeners.length) {
206
- return true;
207
- }
208
-
209
- if (propagate) {
210
- // also check parents for listeners if event propagates
211
- for (var id in this._eventParents) {
212
- if (this._eventParents[id].listens(type, propagate)) {
213
- return true;
214
- }
215
- }
216
- }
217
- return false;
218
- }
219
-
220
- // @method once(…): this
221
- // Behaves as [`on(…)`](#evented-on), except the listener will only get fired once and then removed.
222
- once(types, fn, context) {
223
- if (typeof types === "object") {
224
- for (var type in types) {
225
- this.once(type, types[type], fn);
226
- }
227
- return this;
228
- }
229
-
230
- var handler = Util.bind(function() {
231
- this.off(types, fn, context).off(types, handler, context);
232
- }, this);
233
-
234
- // add a listener that's executed once and removed after that
235
- return this.on(types, fn, context).on(types, handler, context);
236
- }
237
-
238
- // @method addEventParent(obj: Evented): this
239
- // Adds an event parent - an `Evented` that will receive propagated Evented
240
- addEventParent(obj) {
241
- this._eventParents = this._eventParents || {};
242
- this._eventParents[Util.stamp(obj)] = obj;
243
- return this;
244
- }
245
-
246
- // @method removeEventParent(obj: Evented): this
247
- // Removes an event parent, so it will stop receiving propagated Evented
248
- removeEventParent(obj) {
249
- if (this._eventParents) {
250
- delete this._eventParents[Util.stamp(obj)];
251
- }
252
- return this;
253
- }
254
-
255
- _propagateEvent(e) {
256
- for (var id in this._eventParents) {
257
- this._eventParents[id].fire(
258
- e.type,
259
- Util.extend(
260
- {
261
- layer: e.target,
262
- propagatedFrom: e.target
263
- },
264
- e
265
- ),
266
- true
267
- );
268
- }
269
- }
270
- }
271
-
272
- // aliases; we should ditch those eventually
273
-
274
- // @method addEventListener(…): this
275
- // Alias to [`on(…)`](#evented-on)
276
- Evented.addEventListener = Evented.on;
277
-
278
- // @method removeEventListener(…): this
279
- // Alias to [`off(…)`](#evented-off)
280
-
281
- // @method clearAllEventListeners(…): this
282
- // Alias to [`off()`](#evented-off)
283
- Evented.removeEventListener = Evented.clearAllEventListeners = Evented.off;
284
-
285
- // @method addOneTimeEventListener(…): this
286
- // Alias to [`once(…)`](#evented-once)
287
- Evented.addOneTimeEventListener = Evented.once;
288
-
289
- // @method fireEvent(…): this
290
- // Alias to [`fire(…)`](#evented-fire)
291
- Evented.fireEvent = Evented.fire;
292
-
293
- // @method hasEventListeners(…): Boolean
294
- // Alias to [`listens(…)`](#evented-listens)
295
- Evented.hasEventListeners = Evented.listens;
package/util/Util.js DELETED
@@ -1,348 +0,0 @@
1
- import { Zondy } from '../core/Base'
2
-
3
- export var Util = (Zondy.Util = Zondy.Util || {})
4
-
5
- /**
6
- * @description 复制源对象的所有属性到目标对象上,源对象上的没有定义的属性在目标对象上也不会被设置。
7
- * @example
8
- * 要复制Zondy.Size对象的所有属性到自定义对象上,使用方法如下:
9
- * var size = new Zondy.Size(100, 100)
10
- * var obj = {};
11
- * Zondy.Util.extend(obj, size)
12
- * @param destination - {Object} 目标对象。
13
- * @param source - {Object} 源对象,其属性将被设置到目标对象上。
14
- * @return {Object} 目标对象。
15
- */
16
- export var extend = function(destination, source) {
17
- destination = destination || {}
18
- if (source) {
19
- for (var property in source) {
20
- var value = source[property]
21
- if (value !== undefined) {
22
- destination[property] = value
23
- }
24
- }
25
-
26
- /**
27
- * IE doesn't include the toString property when iterating over an object's
28
- * properties with the for(property in object) syntax. Explicitly check if
29
- * the source has its own toString property.
30
- */
31
-
32
- /*
33
- * FF/Windows < 2.0.0.13 reports 'Illegal operation on WrappedNative
34
- * prototype object' when calling hawOwnProperty if the source object
35
- * is an instance of window.Event.
36
- */
37
-
38
- var sourceIsEvt =
39
- typeof window.Event === 'function' && source instanceof window.Event
40
-
41
- if (
42
- !sourceIsEvt &&
43
- source.hasOwnProperty &&
44
- source.hasOwnProperty('toString')
45
- ) {
46
- destination.toString = source.toString
47
- }
48
- }
49
- return destination
50
- }
51
-
52
- /**
53
- * @description 给url追加参数。
54
- * @param url - {string} 待追加参数的url字符串。
55
- * @param paramStr - {string} 待追加的参数。
56
- * @return {string} The new url
57
- */
58
- export var appendUrl = function(url, paramStr) {
59
- var newUrl = url
60
- if (paramStr) {
61
- var parts = (url + ' ').split(/[?&]/)
62
- newUrl +=
63
- parts.pop() === ' ' //如果url是以?或者&结尾的直接追加参数
64
- ? paramStr
65
- : parts.length
66
- ? '&' + paramStr
67
- : '?' + paramStr
68
- //如果url不是以?或者&结尾的则根据是否有参数进行符号补充
69
- }
70
- return newUrl
71
- }
72
-
73
- /**
74
- * @description 复制源对象数组的所有属性到目标对象上,源对象数组的当前对象会重写前一个对象的值
75
- * @author 潘卓然ParnDeedlit 基础平台/创新中心
76
- * @param dest - {Object} 目标对象
77
- * @param sources -{Array} 源对象数据,每个对象都会给目的对象设置对应的属性值
78
- * @private
79
- */
80
- export var extendFromArray = function(dest, sources) {
81
- for (const src of sources) {
82
- for (const k in src) {
83
- dest[k] = src[k]
84
- }
85
- }
86
- return dest
87
- }
88
-
89
- /**
90
- * 判断字符串是否以特定后缀字符结束
91
- * @author 潘卓然ParnDeedlit 基础平台/创新中心
92
- * @description
93
- * @param string {String} 判断字符串
94
- * @param string {String} 尾部后缀
95
- * @private
96
- */
97
- export var endsWith = function(string, suffix) {
98
- return string.indexOf(suffix, string.length - suffix.length) !== -1
99
- }
100
-
101
- // @function create(proto: Object, properties?: Object): Object
102
- // Compatibility polyfill for [Object.create](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
103
- export var create =
104
- Object.create ||
105
- (function() {
106
- function F() {}
107
- return function(proto) {
108
- F.prototype = proto
109
- return new F()
110
- }
111
- })()
112
-
113
- // @function bind(fn: Function, …): Function
114
- // Returns a new function bound to the arguments passed, like [Function.prototype.bind](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
115
- // Has a `L.bind()` shortcut.
116
- export function bind(fn, obj) {
117
- var slice = Array.prototype.slice
118
-
119
- if (fn.bind) {
120
- return fn.bind.apply(fn, slice.call(arguments, 1))
121
- }
122
-
123
- var args = slice.call(arguments, 2)
124
-
125
- return function() {
126
- return fn.apply(
127
- obj,
128
- args.length ? args.concat(slice.call(arguments)) : arguments
129
- )
130
- }
131
- }
132
-
133
- // @property lastId: Number
134
- // Last unique ID used by [`stamp()`](#util-stamp)
135
- export var lastId = 0
136
-
137
- // @function stamp(obj: Object): Number
138
- // Returns the unique ID of an object, assigning it one if it doesn't have it.
139
- export function stamp(obj) {
140
- /*eslint-disable */
141
- obj._leaflet_id = obj._leaflet_id || ++lastId
142
- return obj._leaflet_id
143
- /* eslint-enable */
144
- }
145
-
146
- // @function throttle(fn: Function, time: Number, context: Object): Function
147
- // Returns a function which executes function `fn` with the given scope `context`
148
- // (so that the `this` keyword refers to `context` inside `fn`'s code). The function
149
- // `fn` will be called no more than one time per given amount of `time`. The arguments
150
- // received by the bound function will be any arguments passed when binding the
151
- // function, followed by any arguments passed when invoking the bound function.
152
- // Has an `L.throttle` shortcut.
153
- export function throttle(fn, time, context) {
154
- var lock, args, wrapperFn, later
155
-
156
- later = function() {
157
- // reset lock and call if queued
158
- lock = false
159
- if (args) {
160
- wrapperFn.apply(context, args)
161
- args = false
162
- }
163
- }
164
-
165
- wrapperFn = function() {
166
- if (lock) {
167
- // called too soon, queue to call later
168
- args = arguments
169
- } else {
170
- // call and lock until later
171
- fn.apply(context, arguments)
172
- setTimeout(later, time)
173
- lock = true
174
- }
175
- }
176
-
177
- return wrapperFn
178
- }
179
-
180
- // @function wrapNum(num: Number, range: Number[], includeMax?: Boolean): Number
181
- // Returns the number `num` modulo `range` in such a way so it lies within
182
- // `range[0]` and `range[1]`. The returned value will be always smaller than
183
- // `range[1]` unless `includeMax` is set to `true`.
184
- export function wrapNum(x, range, includeMax) {
185
- var max = range[1],
186
- min = range[0],
187
- d = max - min
188
- return x === max && includeMax ? x : ((((x - min) % d) + d) % d) + min
189
- }
190
-
191
- // @function falseFn(): Function
192
- // Returns a function which always returns `false`.
193
- export function falseFn() {
194
- return false
195
- }
196
-
197
- // @function formatNum(num: Number, digits?: Number): Number
198
- // Returns the number `num` rounded to `digits` decimals, or to 6 decimals by default.
199
- export function formatNum(num, digits) {
200
- var pow = Math.pow(10, digits === undefined ? 6 : digits)
201
- return Math.round(num * pow) / pow
202
- }
203
-
204
- // @function trim(str: String): String
205
- // Compatibility polyfill for [String.prototype.trim](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim)
206
- export function trim(str) {
207
- return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '')
208
- }
209
-
210
- // @function splitWords(str: String): String[]
211
- // Trims and splits the string on whitespace and returns the array of parts.
212
- export function splitWords(str) {
213
- return trim(str).split(/\s+/)
214
- }
215
-
216
- // @function setOptions(obj: Object, options: Object): Object
217
- // Merges the given properties to the `options` of the `obj` object, returning the resulting options. See `Class options`. Has an `L.setOptions` shortcut.
218
- export function setOptions(obj, options) {
219
- if (!obj.hasOwnProperty('options')) {
220
- obj.options = obj.options ? create(obj.options) : {}
221
- }
222
- for (var i in options) {
223
- obj.options[i] = options[i]
224
- }
225
- return obj.options
226
- }
227
-
228
- // @function getParamString(obj: Object, existingUrl?: String, uppercase?: Boolean): String
229
- // Converts an object into a parameter URL string, e.g. `{a: 'foo', b: 'bar'}`
230
- // translates to `'?a=foo&b=bar'`. If `existingUrl` is set, the parameters will
231
- // be appended at the end. If `uppercase` is `true`, the parameter names will
232
- // be uppercased (e.g. `'?A=foo&B=bar'`)
233
- export function getParamString(obj, existingUrl, uppercase) {
234
- var params = []
235
- for (var i in obj) {
236
- params.push(
237
- encodeURIComponent(uppercase ? i.toUpperCase() : i) +
238
- '=' +
239
- encodeURIComponent(obj[i])
240
- )
241
- }
242
- return (
243
- (!existingUrl || existingUrl.indexOf('?') === -1 ? '?' : '&') +
244
- params.join('&')
245
- )
246
- }
247
-
248
- var templateRe = /\{ *([\w_-]+) *\}/g
249
-
250
- // @function template(str: String, data: Object): String
251
- // Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`
252
- // and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string
253
- // `('Hello foo, bar')`. You can also specify functions instead of strings for
254
- // data values — they will be evaluated passing `data` as an argument.
255
- export function template(str, data) {
256
- return str.replace(templateRe, function(str, key) {
257
- var value = data[key]
258
-
259
- if (value === undefined) {
260
- throw new Error('No value provided for variable ' + str)
261
- } else if (typeof value === 'function') {
262
- value = value(data)
263
- }
264
- return value
265
- })
266
- }
267
-
268
- // @function isArray(obj): Boolean
269
- // Compatibility polyfill for [Array.isArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
270
- export var isArray =
271
- Array.isArray ||
272
- function(obj) {
273
- return Object.prototype.toString.call(obj) === '[object Array]'
274
- }
275
-
276
- // @function indexOf(array: Array, el: Object): Number
277
- // Compatibility polyfill for [Array.prototype.indexOf](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
278
- export function indexOf(array, el) {
279
- for (var i = 0; i < array.length; i++) {
280
- if (array[i] === el) {
281
- return i
282
- }
283
- }
284
- return -1
285
- }
286
-
287
- // @property emptyImageUrl: String
288
- // Data URI string containing a base64-encoded empty GIF image.
289
- // Used as a hack to free memory from unused images on WebKit-powered
290
- // mobile devices (by setting image `src` to this string).
291
- export var emptyImageUrl =
292
- 'data:image/gifbase64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='
293
-
294
- // inspired by http://paulirish.com/2011/requestanimationframe-for-smart-animating/
295
-
296
- function getPrefixed(name) {
297
- return window['webkit' + name] || window['moz' + name] || window['ms' + name]
298
- }
299
-
300
- var lastTime = 0
301
-
302
- // fallback for IE 7-8
303
- function timeoutDefer(fn) {
304
- var time = +new Date(),
305
- timeToCall = Math.max(0, 16 - (time - lastTime))
306
-
307
- lastTime = time + timeToCall
308
- return window.setTimeout(fn, timeToCall)
309
- }
310
-
311
- export var requestFn =
312
- window.requestAnimationFrame ||
313
- getPrefixed('RequestAnimationFrame') ||
314
- timeoutDefer
315
- export var cancelFn =
316
- window.cancelAnimationFrame ||
317
- getPrefixed('CancelAnimationFrame') ||
318
- getPrefixed('CancelRequestAnimationFrame') ||
319
- function(id) {
320
- window.clearTimeout(id)
321
- }
322
-
323
- // @function requestAnimFrame(fn: Function, context?: Object, immediate?: Boolean): Number
324
- // Schedules `fn` to be executed when the browser repaints. `fn` is bound to
325
- // `context` if given. When `immediate` is set, `fn` is called immediately if
326
- // the browser doesn't have native support for
327
- // [`window.requestAnimationFrame`](https://developer.mozilla.org/docs/Web/API/window/requestAnimationFrame),
328
- // otherwise it's delayed. Returns a request ID that can be used to cancel the request.
329
- export function requestAnimFrame(fn, context, immediate) {
330
- if (immediate && requestFn === timeoutDefer) {
331
- fn.call(context)
332
- } else {
333
- return requestFn.call(window, bind(fn, context))
334
- }
335
- }
336
-
337
- // @function cancelAnimFrame(id: Number): undefined
338
- // Cancels a previous `requestAnimFrame`. See also [window.cancelAnimationFrame](https://developer.mozilla.org/docs/Web/API/window/cancelAnimationFrame).
339
- export function cancelAnimFrame(id) {
340
- if (id) {
341
- cancelFn.call(window, id)
342
- }
343
- }
344
-
345
- Zondy.Util.extend = extend
346
- Zondy.Util.appendUrl = appendUrl
347
- Zondy.Util.endsWith = endsWith
348
- Zondy.Util.extendFromArray = extendFromArray