I'm new to Javascript and have had some help, but still trying to wrap my head around the solution. I'm trying to apply the .mapplic-active class to all states listed on the map when active. An example can be seen here: http://test.guidehunts.com/concealed-weapons-permit-reciprocity-map/?location=nv. I'm trying to get a string from location.description, split the states, then apply the class through the results of an array, but running into issues. This is what I'm trying to edit.
function Tooltip() {
this.el = null;
this.shift = 6;
this.drop = 0;
this.location = null;
this.init = function() {
var s = this;
// Construct
this.el = $('<div></div>').addClass('mapplic-tooltip');
this.close = $('<a></a>').addClass('mapplic-tooltip-close').attr('href', '#').appendTo(this.el);
this.close.on('click touchend', function(e) {
e.preventDefault();
$('.mapplic-active', self.el).attr('class', 'mapplic-clickable');
if (self.deeplinking) self.deeplinking.clear();
if (!self.o.zoom) zoomTo(0.5, 0.5, 1, 600, 'easeInOutCubic');
s.hide();
});
this.image = $('<img>').addClass('mapplic-tooltip-image').hide().appendTo(this.el);
this.title = $('<h4></h4>').addClass('mapplic-tooltip-title').appendTo(this.el);
this.content = $('<div></div>').addClass('mapplic-tooltip-content').appendTo(this.el);
this.desc = $('<div></div>').addClass('mapplic-tooltip-description').appendTo(this.content);
this.link = $('<a>' + mapplic_localization.more_button + '</a>').addClass('mapplic-tooltip-link').attr('href', '#').hide().appendTo(this.el);
this.triangle = $('<div></div>').addClass('mapplic-tooltip-triangle').prependTo(this.el);
// Append
self.map.append(this.el);
}
this.set = function(location) {
if (location) {
var s = this;
if (location.image) this.image.attr('src', location.image).show();
else this.image.hide();
if (location.link) this.link.attr('href', location.link).show();
else this.link.hide();
this.title.text(location.title);
this.desc.html(location.description);
this.content[0].scrollTop = 0;
this.position(location);
}
}
this.show = function(location) {
if (location) {
if (location.action == 'none') {
this.el.stop().fadeOut(300);
return;
}
var s = this;
this.location = location;
if (self.hovertip) self.hovertip.hide();
if (location.image) this.image.attr('src', location.image).show();
else this.image.hide();
if (location.link) this.link.attr('href', location.link).show();
else this.link.hide();
this.title.text(location.title);
this.desc.html(location.description);
// Shift
var pinselect = $('.mapplic-pin[data-location="' + location.id + '"]');
if (pinselect.length == 0) {
this.shift = 20;
}
else this.shift = pinselect.height() + 10;
// Loading & positioning
$('img', this.el).load(function() {
s.position();
});
this.position();
// Making it visible
this.el.stop().show();
}
}
Below is a list of states that honor your permit:\nWA,ID,AZ,MT,WY,TX,OK ,KS,NE,SD,ND,LA,AR,MO,IA,WI,MS,AL,GA,TN,KY,IN,OH,WV,VA,NC,VT,DE,AK
So the code I gave you would only loop through if it was just those state codes. We will have to add more stuff to that to extract those. – sgtcoder Mar 09 '16 at 23:25