;(function($){
var defaults={
data: [],
tag: 'img',
mode: 'display',
LS_Variable: '__HotspotPlugin_LocalStorage',
hiddenClass: 'hidden',
interactivity: 'hover',
done_btnId: 'HotspotPlugin_Done',
remove_btnId: 'HotspotPlugin_Remove',
sync_btnId: 'HotspotPlugin_Server',
done_btnClass: 'btn btn-success HotspotPlugin_Done',
remove_btnClass: 'btn btn-danger HotspotPlugin_Remove',
sync_btnClass: 'btn btn-info HotspotPlugin_Server',
hotspotClass: 'HotspotPlugin_Hotspot',
hotspotAuxClass: 'HotspotPlugin_inc',
hotspotOverlayClass: 'HotspotPlugin_Overlay',
dataStuff: [
{
'property': 'Title',
'default': 'jQuery Hotspot'
},
{
'property': 'Message',
'default': 'This jQuery Plugin lets you create hotspot to any HTML element. '
}
]
};
function Hotspot(element, options){
this.config=$.extend(true, {}, defaults, options);
this.element=element;
this.imageEl=element.find(this.config.tag);
this.imageParent=this.imageEl.parent();
this.broadcast='';
var widget=this;
$.each(this.config, function(index, val){
if(typeof val==='function'){
widget.element.on(index + '.hotspot', function(){
val(widget.broadcast);
});
};});
this.init();
};
Hotspot.prototype.init=function(){
this.getData();
};
Hotspot.prototype.getData=function(){
if(($(this.config.LS_Variable).val()==''||$(this.config.LS_Variable).val())===null&&this.config.data.length==0){
return;
}
this.beautifyData();
$('body').trigger('dfd-hotspot-inited');
};
Hotspot.prototype.beautifyData=function(){
var widget=this;
if(this.config.data.length!=0){
var raw=this.config.data;
}
var obj=JSON.parse(raw);
for (var i=obj.length - 1; i >=0; i--){
var el=obj[i];
if(this.config.interactivity==='none'){
var htmlBuilt=$('<div><i class="close-item hide"></i></div>');
}else{
var htmlBuilt=$('<div><i class="close-item hide"></i></div>').addClass(this.config.hiddenClass);
}
$.each(el, function(index, val){
if(typeof val==="string"){
$('<div/>', {
html: val
}).addClass('Hotspot_' + index).appendTo(htmlBuilt);
};});
var div=$('<div/>', {
html: htmlBuilt
}).css({
'top': el.y + '%',
'left': el.x + '%'
}).addClass(this.config.hotspotClass).appendTo(this.element);
if(widget.config.interactivity==='click'||widget.config.interactivity==='hover'){
widget.addEvents(div);
}else{
htmlBuilt.removeClass(this.config.hiddenClass);
}
if(this.config.interactivity==='none'){
htmlBuilt.css('display', 'block');
}};};
Hotspot.prototype.addEvents=function($el){
var self=this;
$(window).on('load resize', function(){
var realAction=self.config.interactivity;
if(self.config.interactivity==='hover'&&typeof fl_theme.windowWidth!='undefined'&&fl_theme.windowWidth < 768){
realAction='click';
}
$el.off().on(realAction, function(event){
$(this).toggleClass('active').children('div').toggleClass(self.config.hiddenClass);
});
});
};
$.fn.hotspot=function (options){
new Hotspot(this, options);
return this;
};}(jQuery));