-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery-jvectormap-2.0.4.min.js
3375 lines (2966 loc) · 104 KB
/
jquery-jvectormap-2.0.4.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* jVectorMap version 2.0.4
*
* Copyright 2011-2014, Kirill Lebedev
*
*/
(function( $ ){
var apiParams = {
set: {
colors: 1,
values: 1,
backgroundColor: 1,
scaleColors: 1,
normalizeFunction: 1,
focus: 1
},
get: {
selectedRegions: 1,
selectedMarkers: 1,
mapObject: 1,
regionName: 1
}
};
$.fn.vectorMap = function(options) {
var map,
methodName,
map = this.children('.jvectormap-container').data('mapObject');
if (options === 'addMap') {
jvm.Map.maps[arguments[1]] = arguments[2];
} else if ((options === 'set' || options === 'get') && apiParams[options][arguments[1]]) {
methodName = arguments[1].charAt(0).toUpperCase()+arguments[1].substr(1);
return map[options+methodName].apply(map, Array.prototype.slice.call(arguments, 2));
} else {
options = options || {};
options.container = this;
map = new jvm.Map(options);
}
return this;
};
})( jQuery );
/*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh)
* Licensed under the MIT License (LICENSE.txt).
*
* Version: 3.1.9
*
* Requires: jQuery 1.2.2+
*/
(function (factory) {
if ( typeof define === 'function' && define.amd ) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS style for Browserify
module.exports = factory;
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],
toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
slice = Array.prototype.slice,
nullLowestDeltaTimeout, lowestDelta;
if ( $.event.fixHooks ) {
for ( var i = toFix.length; i; ) {
$.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
}
}
var special = $.event.special.mousewheel = {
version: '3.1.9',
setup: function() {
if ( this.addEventListener ) {
for ( var i = toBind.length; i; ) {
this.addEventListener( toBind[--i], handler, false );
}
} else {
this.onmousewheel = handler;
}
// Store the line height and page height for this particular element
$.data(this, 'mousewheel-line-height', special.getLineHeight(this));
$.data(this, 'mousewheel-page-height', special.getPageHeight(this));
},
teardown: function() {
if ( this.removeEventListener ) {
for ( var i = toBind.length; i; ) {
this.removeEventListener( toBind[--i], handler, false );
}
} else {
this.onmousewheel = null;
}
},
getLineHeight: function(elem) {
return parseInt($(elem)['offsetParent' in $.fn ? 'offsetParent' : 'parent']().css('fontSize'), 10);
},
getPageHeight: function(elem) {
return $(elem).height();
},
settings: {
adjustOldDeltas: true
}
};
$.fn.extend({
mousewheel: function(fn) {
return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');
},
unmousewheel: function(fn) {
return this.unbind('mousewheel', fn);
}
});
function handler(event) {
var orgEvent = event || window.event,
args = slice.call(arguments, 1),
delta = 0,
deltaX = 0,
deltaY = 0,
absDelta = 0;
event = $.event.fix(orgEvent);
event.type = 'mousewheel';
// Old school scrollwheel delta
if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }
if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }
if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
// Firefox < 17 horizontal scrolling related to DOMMouseScroll event
if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
deltaX = deltaY * -1;
deltaY = 0;
}
// Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
delta = deltaY === 0 ? deltaX : deltaY;
// New school wheel delta (wheel event)
if ( 'deltaY' in orgEvent ) {
deltaY = orgEvent.deltaY * -1;
delta = deltaY;
}
if ( 'deltaX' in orgEvent ) {
deltaX = orgEvent.deltaX;
if ( deltaY === 0 ) { delta = deltaX * -1; }
}
// No change actually happened, no reason to go any further
if ( deltaY === 0 && deltaX === 0 ) { return; }
// Need to convert lines and pages to pixels if we aren't already in pixels
// There are three delta modes:
// * deltaMode 0 is by pixels, nothing to do
// * deltaMode 1 is by lines
// * deltaMode 2 is by pages
if ( orgEvent.deltaMode === 1 ) {
var lineHeight = $.data(this, 'mousewheel-line-height');
delta *= lineHeight;
deltaY *= lineHeight;
deltaX *= lineHeight;
} else if ( orgEvent.deltaMode === 2 ) {
var pageHeight = $.data(this, 'mousewheel-page-height');
delta *= pageHeight;
deltaY *= pageHeight;
deltaX *= pageHeight;
}
// Store lowest absolute delta to normalize the delta values
absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
if ( !lowestDelta || absDelta < lowestDelta ) {
lowestDelta = absDelta;
// Adjust older deltas if necessary
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
lowestDelta /= 40;
}
}
// Adjust older deltas if necessary
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
// Divide all the things by 40!
delta /= 40;
deltaX /= 40;
deltaY /= 40;
}
// Get a whole, normalized value for the deltas
delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
// Add information to the event object
event.deltaX = deltaX;
event.deltaY = deltaY;
event.deltaFactor = lowestDelta;
// Go ahead and set deltaMode to 0 since we converted to pixels
// Although this is a little odd since we overwrite the deltaX/Y
// properties with normalized deltas.
event.deltaMode = 0;
// Add event and delta to the front of the arguments
args.unshift(event, delta, deltaX, deltaY);
// Clearout lowestDelta after sometime to better
// handle multiple device types that give different
// a different lowestDelta
// Ex: trackpad = 3 and mouse wheel = 120
if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
return ($.event.dispatch || $.event.handle).apply(this, args);
}
function nullLowestDelta() {
lowestDelta = null;
}
function shouldAdjustOldDeltas(orgEvent, absDelta) {
// If this is an older event and the delta is divisable by 120,
// then we are assuming that the browser is treating this as an
// older mouse wheel event and that we should divide the deltas
// by 40 to try and get a more usable deltaFactor.
// Side note, this actually impacts the reported scroll distance
// in older browsers and can cause scrolling to be slower than native.
// Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
}
}));/**
* @namespace jvm Holds core methods and classes used by jVectorMap.
*/
var jvm = {
/**
* Inherits child's prototype from the parent's one.
* @param {Function} child
* @param {Function} parent
*/
inherits: function(child, parent) {
function temp() {}
temp.prototype = parent.prototype;
child.prototype = new temp();
child.prototype.constructor = child;
child.parentClass = parent;
},
/**
* Mixes in methods from the source constructor to the target one.
* @param {Function} target
* @param {Function} source
*/
mixin: function(target, source){
var prop;
for (prop in source.prototype) {
if (source.prototype.hasOwnProperty(prop)) {
target.prototype[prop] = source.prototype[prop];
}
}
},
min: function(values){
var min = Number.MAX_VALUE,
i;
if (values instanceof Array) {
for (i = 0; i < values.length; i++) {
if (values[i] < min) {
min = values[i];
}
}
} else {
for (i in values) {
if (values[i] < min) {
min = values[i];
}
}
}
return min;
},
max: function(values){
var max = Number.MIN_VALUE,
i;
if (values instanceof Array) {
for (i = 0; i < values.length; i++) {
if (values[i] > max) {
max = values[i];
}
}
} else {
for (i in values) {
if (values[i] > max) {
max = values[i];
}
}
}
return max;
},
keys: function(object){
var keys = [],
key;
for (key in object) {
keys.push(key);
}
return keys;
},
values: function(object){
var values = [],
key,
i;
for (i = 0; i < arguments.length; i++) {
object = arguments[i];
for (key in object) {
values.push(object[key]);
}
}
return values;
},
whenImageLoaded: function(url){
var deferred = new jvm.$.Deferred(),
img = jvm.$('<img/>');
img.error(function(){
deferred.reject();
}).load(function(){
deferred.resolve(img);
});
img.attr('src', url);
return deferred;
},
isImageUrl: function(s){
return /\.\w{3,4}$/.test(s);
}
};
jvm.$ = jQuery;
/**
* indexOf polyfill for IE < 9
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
*/
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
var k;
// 1. Let O be the result of calling ToObject passing
// the this value as the argument.
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var O = Object(this);
// 2. Let lenValue be the result of calling the Get
// internal method of O with the argument "length".
// 3. Let len be ToUint32(lenValue).
var len = O.length >>> 0;
// 4. If len is 0, return -1.
if (len === 0) {
return -1;
}
// 5. If argument fromIndex was passed let n be
// ToInteger(fromIndex); else let n be 0.
var n = +fromIndex || 0;
if (Math.abs(n) === Infinity) {
n = 0;
}
// 6. If n >= len, return -1.
if (n >= len) {
return -1;
}
// 7. If n >= 0, then Let k be n.
// 8. Else, n<0, Let k be len - abs(n).
// If k is less than 0, then let k be 0.
k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
// 9. Repeat, while k < len
while (k < len) {
// a. Let Pk be ToString(k).
// This is implicit for LHS operands of the in operator
// b. Let kPresent be the result of calling the
// HasProperty internal method of O with argument Pk.
// This step can be combined with c
// c. If kPresent is true, then
// i. Let elementK be the result of calling the Get
// internal method of O with the argument ToString(k).
// ii. Let same be the result of applying the
// Strict Equality Comparison Algorithm to
// searchElement and elementK.
// iii. If same is true, return k.
if (k in O && O[k] === searchElement) {
return k;
}
k++;
}
return -1;
};
}/**
* Basic wrapper for DOM element.
* @constructor
* @param {String} name Tag name of the element
* @param {Object} config Set of parameters to initialize element with
*/
jvm.AbstractElement = function(name, config){
/**
* Underlying DOM element
* @type {DOMElement}
* @private
*/
this.node = this.createElement(name);
/**
* Name of underlying element
* @type {String}
* @private
*/
this.name = name;
/**
* Internal store of attributes
* @type {Object}
* @private
*/
this.properties = {};
if (config) {
this.set(config);
}
};
/**
* Set attribute of the underlying DOM element.
* @param {String} name Name of attribute
* @param {Number|String} config Set of parameters to initialize element with
*/
jvm.AbstractElement.prototype.set = function(property, value){
var key;
if (typeof property === 'object') {
for (key in property) {
this.properties[key] = property[key];
this.applyAttr(key, property[key]);
}
} else {
this.properties[property] = value;
this.applyAttr(property, value);
}
};
/**
* Returns value of attribute.
* @param {String} name Name of attribute
*/
jvm.AbstractElement.prototype.get = function(property){
return this.properties[property];
};
/**
* Applies attribute value to the underlying DOM element.
* @param {String} name Name of attribute
* @param {Number|String} config Value of attribute to apply
* @private
*/
jvm.AbstractElement.prototype.applyAttr = function(property, value){
this.node.setAttribute(property, value);
};
jvm.AbstractElement.prototype.remove = function(){
jvm.$(this.node).remove();
};/**
* Implements abstract vector canvas.
* @constructor
* @param {HTMLElement} container Container to put element to.
* @param {Number} width Width of canvas.
* @param {Number} height Height of canvas.
*/
jvm.AbstractCanvasElement = function(container, width, height){
this.container = container;
this.setSize(width, height);
this.rootElement = new jvm[this.classPrefix+'GroupElement']();
this.node.appendChild( this.rootElement.node );
this.container.appendChild(this.node);
}
/**
* Add element to the certain group inside of the canvas.
* @param {HTMLElement} element Element to add to canvas.
* @param {HTMLElement} group Group to add element into or into root group if not provided.
*/
jvm.AbstractCanvasElement.prototype.add = function(element, group){
group = group || this.rootElement;
group.add(element);
element.canvas = this;
}
/**
* Create path and add it to the canvas.
* @param {Object} config Parameters of path to create.
* @param {Object} style Styles of the path to create.
* @param {HTMLElement} group Group to add path into.
*/
jvm.AbstractCanvasElement.prototype.addPath = function(config, style, group){
var el = new jvm[this.classPrefix+'PathElement'](config, style);
this.add(el, group);
return el;
};
/**
* Create circle and add it to the canvas.
* @param {Object} config Parameters of path to create.
* @param {Object} style Styles of the path to create.
* @param {HTMLElement} group Group to add circle into.
*/
jvm.AbstractCanvasElement.prototype.addCircle = function(config, style, group){
var el = new jvm[this.classPrefix+'CircleElement'](config, style);
this.add(el, group);
return el;
};
/**
* Create circle and add it to the canvas.
* @param {Object} config Parameters of path to create.
* @param {Object} style Styles of the path to create.
* @param {HTMLElement} group Group to add circle into.
*/
jvm.AbstractCanvasElement.prototype.addImage = function(config, style, group){
var el = new jvm[this.classPrefix+'ImageElement'](config, style);
this.add(el, group);
return el;
};
/**
* Create text and add it to the canvas.
* @param {Object} config Parameters of path to create.
* @param {Object} style Styles of the path to create.
* @param {HTMLElement} group Group to add circle into.
*/
jvm.AbstractCanvasElement.prototype.addText = function(config, style, group){
var el = new jvm[this.classPrefix+'TextElement'](config, style);
this.add(el, group);
return el;
};
/**
* Add group to the another group inside of the canvas.
* @param {HTMLElement} group Group to add circle into or root group if not provided.
*/
jvm.AbstractCanvasElement.prototype.addGroup = function(parentGroup){
var el = new jvm[this.classPrefix+'GroupElement']();
if (parentGroup) {
parentGroup.node.appendChild(el.node);
} else {
this.node.appendChild(el.node);
}
el.canvas = this;
return el;
};/**
* Abstract shape element. Shape element represents some visual vector or raster object.
* @constructor
* @param {String} name Tag name of the element.
* @param {Object} config Set of parameters to initialize element with.
* @param {Object} style Object with styles to set on element initialization.
*/
jvm.AbstractShapeElement = function(name, config, style){
this.style = style || {};
this.style.current = this.style.current || {};
this.isHovered = false;
this.isSelected = false;
this.updateStyle();
};
/**
* Set element's style.
* @param {Object|String} property Could be string to set only one property or object to set several style properties at once.
* @param {String} value Value to set in case only one property should be set.
*/
jvm.AbstractShapeElement.prototype.setStyle = function(property, value){
var styles = {};
if (typeof property === 'object') {
styles = property;
} else {
styles[property] = value;
}
jvm.$.extend(this.style.current, styles);
this.updateStyle();
};
jvm.AbstractShapeElement.prototype.updateStyle = function(){
var attrs = {};
jvm.AbstractShapeElement.mergeStyles(attrs, this.style.initial);
jvm.AbstractShapeElement.mergeStyles(attrs, this.style.current);
if (this.isHovered) {
jvm.AbstractShapeElement.mergeStyles(attrs, this.style.hover);
}
if (this.isSelected) {
jvm.AbstractShapeElement.mergeStyles(attrs, this.style.selected);
if (this.isHovered) {
jvm.AbstractShapeElement.mergeStyles(attrs, this.style.selectedHover);
}
}
this.set(attrs);
};
jvm.AbstractShapeElement.mergeStyles = function(styles, newStyles){
var key;
newStyles = newStyles || {};
for (key in newStyles) {
if (newStyles[key] === null) {
delete styles[key];
} else {
styles[key] = newStyles[key];
}
}
}/**
* Wrapper for SVG element.
* @constructor
* @extends jvm.AbstractElement
* @param {String} name Tag name of the element
* @param {Object} config Set of parameters to initialize element with
*/
jvm.SVGElement = function(name, config){
jvm.SVGElement.parentClass.apply(this, arguments);
}
jvm.inherits(jvm.SVGElement, jvm.AbstractElement);
jvm.SVGElement.svgns = "http://www.w3.org/2000/svg";
/**
* Creates DOM element.
* @param {String} tagName Name of element
* @private
* @returns DOMElement
*/
jvm.SVGElement.prototype.createElement = function( tagName ){
return document.createElementNS( jvm.SVGElement.svgns, tagName );
};
/**
* Adds CSS class for underlying DOM element.
* @param {String} className Name of CSS class name
*/
jvm.SVGElement.prototype.addClass = function( className ){
this.node.setAttribute('class', className);
};
/**
* Returns constructor for element by name prefixed with 'VML'.
* @param {String} ctr Name of basic constructor to return
* proper implementation for.
* @returns Function
* @private
*/
jvm.SVGElement.prototype.getElementCtr = function( ctr ){
return jvm['SVG'+ctr];
};
jvm.SVGElement.prototype.getBBox = function(){
return this.node.getBBox();
};jvm.SVGGroupElement = function(){
jvm.SVGGroupElement.parentClass.call(this, 'g');
}
jvm.inherits(jvm.SVGGroupElement, jvm.SVGElement);
jvm.SVGGroupElement.prototype.add = function(element){
this.node.appendChild( element.node );
};jvm.SVGCanvasElement = function(container, width, height){
this.classPrefix = 'SVG';
jvm.SVGCanvasElement.parentClass.call(this, 'svg');
this.defsElement = new jvm.SVGElement('defs');
this.node.appendChild( this.defsElement.node );
jvm.AbstractCanvasElement.apply(this, arguments);
}
jvm.inherits(jvm.SVGCanvasElement, jvm.SVGElement);
jvm.mixin(jvm.SVGCanvasElement, jvm.AbstractCanvasElement);
jvm.SVGCanvasElement.prototype.setSize = function(width, height){
this.width = width;
this.height = height;
this.node.setAttribute('width', width);
this.node.setAttribute('height', height);
};
jvm.SVGCanvasElement.prototype.applyTransformParams = function(scale, transX, transY) {
this.scale = scale;
this.transX = transX;
this.transY = transY;
this.rootElement.node.setAttribute('transform', 'scale('+scale+') translate('+transX+', '+transY+')');
};jvm.SVGShapeElement = function(name, config, style){
jvm.SVGShapeElement.parentClass.call(this, name, config);
jvm.AbstractShapeElement.apply(this, arguments);
};
jvm.inherits(jvm.SVGShapeElement, jvm.SVGElement);
jvm.mixin(jvm.SVGShapeElement, jvm.AbstractShapeElement);
jvm.SVGShapeElement.prototype.applyAttr = function(attr, value){
var patternEl,
imageEl,
that = this;
if (attr === 'fill' && jvm.isImageUrl(value)) {
if (!jvm.SVGShapeElement.images[value]) {
jvm.whenImageLoaded(value).then(function(img){
imageEl = new jvm.SVGElement('image');
imageEl.node.setAttributeNS('http://www.w3.org/1999/xlink', 'href', value);
imageEl.applyAttr('x', '0');
imageEl.applyAttr('y', '0');
imageEl.applyAttr('width', img[0].width);
imageEl.applyAttr('height', img[0].height);
patternEl = new jvm.SVGElement('pattern');
patternEl.applyAttr('id', 'image'+jvm.SVGShapeElement.imageCounter);
patternEl.applyAttr('x', 0);
patternEl.applyAttr('y', 0);
patternEl.applyAttr('width', img[0].width / 2);
patternEl.applyAttr('height', img[0].height / 2);
patternEl.applyAttr('viewBox', '0 0 '+img[0].width+' '+img[0].height);
patternEl.applyAttr('patternUnits', 'userSpaceOnUse');
patternEl.node.appendChild( imageEl.node );
that.canvas.defsElement.node.appendChild( patternEl.node );
jvm.SVGShapeElement.images[value] = jvm.SVGShapeElement.imageCounter++;
that.applyAttr('fill', 'url(#image'+jvm.SVGShapeElement.images[value]+')');
});
} else {
this.applyAttr('fill', 'url(#image'+jvm.SVGShapeElement.images[value]+')');
}
} else {
jvm.SVGShapeElement.parentClass.prototype.applyAttr.apply(this, arguments);
}
};
jvm.SVGShapeElement.imageCounter = 1;
jvm.SVGShapeElement.images = {};jvm.SVGPathElement = function(config, style){
jvm.SVGPathElement.parentClass.call(this, 'path', config, style);
this.node.setAttribute('fill-rule', 'evenodd');
}
jvm.inherits(jvm.SVGPathElement, jvm.SVGShapeElement);jvm.SVGCircleElement = function(config, style){
jvm.SVGCircleElement.parentClass.call(this, 'circle', config, style);
};
jvm.inherits(jvm.SVGCircleElement, jvm.SVGShapeElement);jvm.SVGImageElement = function(config, style){
jvm.SVGImageElement.parentClass.call(this, 'image', config, style);
};
jvm.inherits(jvm.SVGImageElement, jvm.SVGShapeElement);
jvm.SVGImageElement.prototype.applyAttr = function(attr, value){
var that = this;
if (attr == 'image') {
jvm.whenImageLoaded(value).then(function(img){
that.node.setAttributeNS('http://www.w3.org/1999/xlink', 'href', value);
that.width = img[0].width;
that.height = img[0].height;
that.applyAttr('width', that.width);
that.applyAttr('height', that.height);
that.applyAttr('x', that.cx - that.width / 2);
that.applyAttr('y', that.cy - that.height / 2);
jvm.$(that.node).trigger('imageloaded', [img]);
});
} else if(attr == 'cx') {
this.cx = value;
if (this.width) {
this.applyAttr('x', value - this.width / 2);
}
} else if(attr == 'cy') {
this.cy = value;
if (this.height) {
this.applyAttr('y', value - this.height / 2);
}
} else {
jvm.SVGImageElement.parentClass.prototype.applyAttr.apply(this, arguments);
}
};jvm.SVGTextElement = function(config, style){
jvm.SVGTextElement.parentClass.call(this, 'text', config, style);
}
jvm.inherits(jvm.SVGTextElement, jvm.SVGShapeElement);
jvm.SVGTextElement.prototype.applyAttr = function(attr, value){
if (attr === 'text') {
this.node.textContent = value;
} else {
jvm.SVGTextElement.parentClass.prototype.applyAttr.apply(this, arguments);
}
};/**
* Wrapper for VML element.
* @constructor
* @extends jvm.AbstractElement
* @param {String} name Tag name of the element
* @param {Object} config Set of parameters to initialize element with
*/
jvm.VMLElement = function(name, config){
if (!jvm.VMLElement.VMLInitialized) {
jvm.VMLElement.initializeVML();
}
jvm.VMLElement.parentClass.apply(this, arguments);
};
jvm.inherits(jvm.VMLElement, jvm.AbstractElement);
/**
* Shows if VML was already initialized for the current document or not.
* @static
* @private
* @type {Boolean}
*/
jvm.VMLElement.VMLInitialized = false;
/**
* Initializes VML handling before creating the first element
* (adds CSS class and creates namespace). Adds one of two forms
* of createElement method depending of support by browser.
* @static
* @private
*/
// The following method of VML handling is borrowed from the
// Raphael library by Dmitry Baranovsky.
jvm.VMLElement.initializeVML = function(){
try {
if (!document.namespaces.rvml) {
document.namespaces.add("rvml","urn:schemas-microsoft-com:vml");
}
/**
* Creates DOM element.
* @param {String} tagName Name of element
* @private
* @returns DOMElement
*/
jvm.VMLElement.prototype.createElement = function (tagName) {
return document.createElement('<rvml:' + tagName + ' class="rvml">');
};
} catch (e) {
/**
* @private
*/
jvm.VMLElement.prototype.createElement = function (tagName) {
return document.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
};
}
document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
jvm.VMLElement.VMLInitialized = true;
};
/**
* Returns constructor for element by name prefixed with 'VML'.
* @param {String} ctr Name of basic constructor to return
* proper implementation for.
* @returns Function
* @private
*/
jvm.VMLElement.prototype.getElementCtr = function( ctr ){
return jvm['VML'+ctr];
};
/**
* Adds CSS class for underlying DOM element.
* @param {String} className Name of CSS class name
*/
jvm.VMLElement.prototype.addClass = function( className ){
jvm.$(this.node).addClass(className);
};
/**
* Applies attribute value to the underlying DOM element.
* @param {String} name Name of attribute
* @param {Number|String} config Value of attribute to apply
* @private
*/
jvm.VMLElement.prototype.applyAttr = function( attr, value ){
this.node[attr] = value;
};
/**
* Returns boundary box for the element.
* @returns {Object} Boundary box with numeric fields: x, y, width, height
* @override
*/
jvm.VMLElement.prototype.getBBox = function(){
var node = jvm.$(this.node);
return {
x: node.position().left / this.canvas.scale,
y: node.position().top / this.canvas.scale,
width: node.width() / this.canvas.scale,
height: node.height() / this.canvas.scale
};
};jvm.VMLGroupElement = function(){
jvm.VMLGroupElement.parentClass.call(this, 'group');
this.node.style.left = '0px';
this.node.style.top = '0px';
this.node.coordorigin = "0 0";
};
jvm.inherits(jvm.VMLGroupElement, jvm.VMLElement);
jvm.VMLGroupElement.prototype.add = function(element){
this.node.appendChild( element.node );
};jvm.VMLCanvasElement = function(container, width, height){
this.classPrefix = 'VML';
jvm.VMLCanvasElement.parentClass.call(this, 'group');
jvm.AbstractCanvasElement.apply(this, arguments);
this.node.style.position = 'absolute';
};
jvm.inherits(jvm.VMLCanvasElement, jvm.VMLElement);
jvm.mixin(jvm.VMLCanvasElement, jvm.AbstractCanvasElement);
jvm.VMLCanvasElement.prototype.setSize = function(width, height){
var paths,
groups,
i,
l;
this.width = width;
this.height = height;
this.node.style.width = width + "px";
this.node.style.height = height + "px";
this.node.coordsize = width+' '+height;
this.node.coordorigin = "0 0";
if (this.rootElement) {
paths = this.rootElement.node.getElementsByTagName('shape');
for(i = 0, l = paths.length; i < l; i++) {
paths[i].coordsize = width+' '+height;
paths[i].style.width = width+'px';
paths[i].style.height = height+'px';
}
groups = this.node.getElementsByTagName('group');
for(i = 0, l = groups.length; i < l; i++) {
groups[i].coordsize = width+' '+height;
groups[i].style.width = width+'px';
groups[i].style.height = height+'px';
}
}
};
jvm.VMLCanvasElement.prototype.applyTransformParams = function(scale, transX, transY) {
this.scale = scale;
this.transX = transX;
this.transY = transY;
this.rootElement.node.coordorigin = (this.width-transX-this.width/100)+','+(this.height-transY-this.height/100);
this.rootElement.node.coordsize = this.width/scale+','+this.height/scale;
};jvm.VMLShapeElement = function(name, config){