Skip to content

Commit

Permalink
fixes #84 jVectorMap should work in jQuery.noConflict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornd authored and bugwelle committed Feb 1, 2013
1 parent 30d7eb3 commit de7aea5
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 42 deletions.
5 changes: 3 additions & 2 deletions jquery-jvectormap.js
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/abstract-element.js
Expand Up @@ -69,5 +69,5 @@ jvm.AbstractElement.prototype.applyAttr = function(property, value){
};

jvm.AbstractElement.prototype.remove = function(){
$(this.node).remove();
jvm.$(this.node).remove();
};
14 changes: 7 additions & 7 deletions lib/abstract-shape-element.js
Expand Up @@ -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]);
}
};

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/data-series.js
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion lib/jvectormap.js
Expand Up @@ -94,4 +94,6 @@ var jvm = {
}
return values;
}
};
};

jvm.$ = jQuery;
4 changes: 2 additions & 2 deletions lib/vml-element.js
Expand Up @@ -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);
};

/**
Expand All @@ -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,
Expand Down
54 changes: 27 additions & 27 deletions lib/world-map.js
Expand Up @@ -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({
Expand All @@ -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]) {
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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) {
Expand All @@ -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];
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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] = {
Expand All @@ -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++) {
Expand All @@ -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]);
Expand Down Expand Up @@ -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);
}
};

Expand Down
5 changes: 4 additions & 1 deletion tests/index.html
Expand Up @@ -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');
});
Expand Down

0 comments on commit de7aea5

Please sign in to comment.