Permalink
Browse files

fixes #84 jVectorMap should work in jQuery.noConflict mode

  • Loading branch information...
1 parent 2175602 commit f5470d2606f76aa591ab056b4a2f58096f9e5b2f @bjornd committed Sep 4, 2012
Showing with 48 additions and 42 deletions.
  1. +3 −2 jquery-jvectormap.js
  2. +1 −1 lib/abstract-element.js
  3. +7 −7 lib/abstract-shape-element.js
  4. +1 −1 lib/data-series.js
  5. +3 −1 lib/jvectormap.js
  6. +2 −2 lib/vml-element.js
  7. +27 −27 lib/world-map.js
  8. +4 −1 tests/index.html
@@ -26,13 +26,14 @@
$.fn.vectorMap = function(options) {
var map,
methodName,
- event;
+ event,
+ map = this.children('.jvectormap-container').data('mapObject');
if (options === 'addMap') {
jvm.WorldMap.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 this.data('mapObject')[options+methodName].apply(this.data('mapObject'), Array.prototype.slice.call(arguments, 2));
+ return map[options+methodName].apply(map, Array.prototype.slice.call(arguments, 2));
} else {
options = options || {};
options.container = this;
@@ -69,5 +69,5 @@ jvm.AbstractElement.prototype.applyAttr = function(property, value){
};
jvm.AbstractElement.prototype.remove = function(){
- $(this.node).remove();
+ jvm.$(this.node).remove();
};
@@ -32,7 +32,7 @@ jvm.AbstractShapeElement.prototype.setSelected = function(isSelected){
if (this.isSelected !== isSelected) {
this.isSelected = isSelected;
this.updateStyle();
- $(this.node).trigger('selected', [isSelected]);
+ jvm.$(this.node).trigger('selected', [isSelected]);
}
};
@@ -49,23 +49,23 @@ jvm.AbstractShapeElement.prototype.setStyle = function(property, value){
} else {
styles[property] = value;
}
- $.extend(this.style.current, styles);
+ jvm.$.extend(this.style.current, styles);
this.updateStyle();
};
jvm.AbstractShapeElement.prototype.updateStyle = function(){
var attrs = {};
- $.extend(attrs, this.style.initial || {});
- $.extend(attrs, this.style.current || {});
+ jvm.$.extend(attrs, this.style.initial || {});
+ jvm.$.extend(attrs, this.style.current || {});
if (this.isHovered) {
- $.extend(attrs, this.style.hover || {});
+ jvm.$.extend(attrs, this.style.hover || {});
}
if (this.isSelected) {
- $.extend(attrs, this.style.selected || {});
+ jvm.$.extend(attrs, this.style.selected || {});
if (this.isHovered) {
- $.extend(attrs, this.style.selectedHover || {});
+ jvm.$.extend(attrs, this.style.selectedHover || {});
}
}
this.set(attrs);
View
@@ -23,7 +23,7 @@ jvm.DataSeries = function(params, elements) {
this.setAttributes(params.attributes);
}
- if (!$.isArray(params.scale)) {
+ if (!jvm.$.isArray(params.scale)) {
this.scale = new jvm.OrdinalScale(params.scale);
} else {
scaleConstructor = (params.attribute === 'fill' || params.attribute === 'stroke') ? jvm.ColorScale : jvm.NumericScale;
View
@@ -94,4 +94,6 @@ var jvm = {
}
return values;
}
-};
+};
+
+jvm.$ = jQuery;
View
@@ -77,7 +77,7 @@ jvm.VMLElement.prototype.getElementCtr = function( ctr ){
* @param {String} className Name of CSS class name
*/
jvm.VMLElement.prototype.addClass = function( className ){
- $(this.node).addClass(className);
+ jvm.$(this.node).addClass(className);
};
/**
@@ -96,7 +96,7 @@ jvm.VMLElement.prototype.applyAttr = function( attr, value ){
* @override
*/
jvm.VMLElement.prototype.getBBox = function(){
- var node = $(this.node);
+ var node = jvm.$(this.node);
return {
x: node.position().left / this.canvas.scale,
y: node.position().top / this.canvas.scale,
View
@@ -73,14 +73,14 @@ jvm.WorldMap = function(params) {
var map = this,
e;
- this.params = $.extend(true, {}, jvm.WorldMap.defaultParams, params);
+ this.params = jvm.$.extend(true, {}, jvm.WorldMap.defaultParams, params);
this.mapData = jvm.WorldMap.maps[this.params.map];
this.markers = {};
this.regions = {};
this.regionsColors = {};
this.regionsData = {};
- this.container = $('<div>').css({width: '100%', height: '100%'});
+ this.container = jvm.$('<div>').css({width: '100%', height: '100%'}).addClass('jvectormap-container');
this.params.container.append( this.container );
this.container.data('mapObject', this);
this.container.css({
@@ -96,7 +96,7 @@ jvm.WorldMap = function(params) {
this.onResize = function(){
map.setSize();
}
- $(window).resize(this.onResize);
+ jvm.$(window).resize(this.onResize);
for (e in jvm.WorldMap.apiEvents) {
if (this.params[e]) {
@@ -261,7 +261,7 @@ jvm.WorldMap.prototype = {
if (this.params.zoomOnScroll) {
this.container.mousewheel(function(event, delta, deltaX, deltaY) {
- var offset = $(map.container).offset(),
+ var offset = jvm.$(map.container).offset(),
centerX = event.pageX - offset.left,
centerY = event.pageY - offset.top,
zoomStep = Math.pow(1.3, deltaY);
@@ -284,13 +284,13 @@ jvm.WorldMap.prototype = {
centerTouchX,
centerTouchY;
- $(this.container).bind('gesturestart', function(e){
+ jvm.$(this.container).bind('gesturestart', function(e){
touchStartScale = map.scale;
touchStartTransX = map.transX;
touchStartTransY = map.transY;
return false;
});
- $(this.container).bind('gesturechange', function(e){
+ jvm.$(this.container).bind('gesturechange', function(e){
var zoomStep = e.originalEvent.scale;
map.setScale(
@@ -301,7 +301,7 @@ jvm.WorldMap.prototype = {
map.label.hide();
return false;
});
- $(this.container).bind('touchstart', function(e){
+ jvm.$(this.container).bind('touchstart', function(e){
var touches = e.originalEvent.touches;
if (touches.length == 2) {
if (touches[0].pageX > touches[1].pageX) {
@@ -318,7 +318,7 @@ jvm.WorldMap.prototype = {
touchX = e.originalEvent.touches[0].pageX;
touchY = e.originalEvent.touches[0].pageY;
});
- $(this.container).bind('touchmove', function(e){
+ jvm.$(this.container).bind('touchmove', function(e){
var touch;
if (e.originalEvent.touches.length == 1 && touchX && touchY) {
touch = e.originalEvent.touches[0];
@@ -350,12 +350,12 @@ jvm.WorldMap.prototype = {
this.container.delegate('.jvectormap-region, .jvectormap-marker', 'mouseover mouseout', function(e){
var path = this,
- type = $(this).attr('class').indexOf('jvectormap-region') === -1 ? 'marker' : 'region',
- code = type == 'region' ? $(this).attr('data-code') : $(this).attr('data-index'),
+ type = jvm.$(this).attr('class').indexOf('jvectormap-region') === -1 ? 'marker' : 'region',
+ code = type == 'region' ? jvm.$(this).attr('data-code') : jvm.$(this).attr('data-index'),
element = type == 'region' ? map.regions[code].element : map.markers[code].element,
labelText = type == 'region' ? map.mapData.paths[code].name : (map.markers[code].config.name || ''),
- labelShowEvent = $.Event(type+'LabelShow.jvectormap'),
- overEvent = $.Event(type+'Over.jvectormap');
+ labelShowEvent = jvm.$.Event(type+'LabelShow.jvectormap'),
+ overEvent = jvm.$.Event(type+'Over.jvectormap');
if (e.type == 'mouseover') {
map.container.trigger(overEvent, [code]);
@@ -383,9 +383,9 @@ jvm.WorldMap.prototype = {
this.container.delegate('.jvectormap-region, .jvectormap-marker', 'mouseup', function(e){
var path = this,
- type = $(this).attr('class').indexOf('jvectormap-region') === -1 ? 'marker' : 'region',
- code = type == 'region' ? $(this).attr('data-code') : $(this).attr('data-index'),
- clickEvent = $.Event(type+'Click.jvectormap'),
+ type = jvm.$(this).attr('class').indexOf('jvectormap-region') === -1 ? 'marker' : 'region',
+ code = type == 'region' ? jvm.$(this).attr('data-code') : jvm.$(this).attr('data-index'),
+ clickEvent = jvm.$.Event(type+'Click.jvectormap'),
element = type == 'region' ? map.regions[code].element : map.markers[code].element;
if (!mouseMoved) {
@@ -402,8 +402,8 @@ jvm.WorldMap.prototype = {
bindZoomButtons: function() {
var map = this;
- $('<div/>').addClass('jvectormap-zoomin').text('+').appendTo(this.container);
- $('<div/>').addClass('jvectormap-zoomout').html('&#x2212;').appendTo(this.container);
+ jvm.$('<div/>').addClass('jvectormap-zoomin').text('+').appendTo(this.container);
+ jvm.$('<div/>').addClass('jvectormap-zoomout').html('&#x2212;').appendTo(this.container);
this.container.find('.jvectormap-zoomin').click(function(){
map.setScale(map.scale * map.params.zoomStep, map.width / 2, map.height / 2);
@@ -416,7 +416,7 @@ jvm.WorldMap.prototype = {
createLabel: function(){
var map = this;
- this.label = $('<div/>').addClass('jvectormap-label').appendTo($('body'));
+ this.label = jvm.$('<div/>').addClass('jvectormap-label').appendTo(jvm.$('body'));
this.container.mousemove(function(e){
var left = e.pageX-15-map.labelWidth,
@@ -519,7 +519,7 @@ jvm.WorldMap.prototype = {
keys = [keys];
}
- if ($.isArray(keys)) {
+ if (jvm.$.isArray(keys)) {
for (i = 0; i < keys.length; i++) {
this[type][keys[i]].element.setSelected(true);
}
@@ -597,9 +597,9 @@ jvm.WorldMap.prototype = {
region = this.canvas.addPath({
d: this.mapData.paths[key].path,
"data-code": key
- }, $.extend({}, this.params.regionStyle));
- $(region.node).bind('selected', function(e, isSelected){
- map.container.trigger('regionSelected.jvectormap', [$(this).attr('data-code'), isSelected, map.getSelectedRegions()]);
+ }, jvm.$.extend({}, this.params.regionStyle));
+ jvm.$(region.node).bind('selected', function(e, isSelected){
+ map.container.trigger('regionSelected.jvectormap', [jvm.$(this).attr('data-code'), isSelected, map.getSelectedRegions()]);
});
region.addClass('jvectormap-region');
this.regions[key] = {
@@ -619,7 +619,7 @@ jvm.WorldMap.prototype = {
this.markersGroup = this.markersGroup || this.canvas.addGroup();
- if ($.isArray(markers)) {
+ if (jvm.$.isArray(markers)) {
markersArray = markers.slice();
markers = {};
for (i = 0; i < markersArray.length; i++) {
@@ -635,10 +635,10 @@ jvm.WorldMap.prototype = {
"data-index": i,
cx: point.x,
cy: point.y
- }, $.extend(true, {}, this.params.markerStyle, {initial: markerConfig.style || {}}), this.markersGroup);
+ }, jvm.$.extend(true, {}, this.params.markerStyle, {initial: markerConfig.style || {}}), this.markersGroup);
marker.addClass('jvectormap-marker');
- $(marker.node).bind('selected', function(e, isSelected){
- map.container.trigger('markerSelected.jvectormap', [$(this).attr('data-index'), isSelected, map.getSelectedMarkers()]);
+ jvm.$(marker.node).bind('selected', function(e, isSelected){
+ map.container.trigger('markerSelected.jvectormap', [jvm.$(this).attr('data-index'), isSelected, map.getSelectedMarkers()]);
});
if (this.markers[i]) {
this.removeMarkers([i]);
@@ -796,7 +796,7 @@ jvm.WorldMap.prototype = {
remove: function(){
this.label.remove();
this.container.remove();
- $(window).unbind('resize', this.onResize);
+ jvm.$(window).unbind('resize', this.onResize);
}
};
View
@@ -37,7 +37,10 @@
<script src="assets/jquery-jvectormap-world-mill-en.js"></script>
<script>
- $(function(){
+ jQuery.noConflict();
+ jQuery(function(){
+ var $ = jQuery;
+
$('#focus').click(function(){
$('#map1').vectorMap('set', 'focus', 'AU');
});

0 comments on commit f5470d2

Please sign in to comment.