Giter VIP home page Giter VIP logo

jquery-hotspot's Introduction

jQuery - Hotspot

A jQuery plugin for creating Hotspots in an HTML element. This plugin operates in two modes, admin and display. The admin mode enables user to create hotspots on desired HTML elements. The display mode is used for only displaying the hotspots to the end user. The design of the hotspot created are fully customizable. User can add their own CSS class to style the hotspots.

Note: Ensures responsiveness with the latest update.

The Setup

npm install jquery-hotspot

Include jquery.hotspot.js at the bottom of the HTML page before the closing body tag. Wrap the HTML element for which the hotspot is to be obtained with another element. Also include the jquery.hotspot.css file to go with some of the default design decisions.

<div id="theElement">
  <img src="theImage.jpg" />
</div>

The plugin instance will be called with theElement.

Note: The CSS property, position for this element should be kept as relative.

#theElement {
  position: relative;
}

Usage - Display mode

The data associated with the hotspots can be passed in directly to the plugin. The data can also be fetched from a backend server by enabling ajax option.

There are three options given for hotspot-interactivity - hover, click and none.

  • hover : The data associated with the hotspot will show up on hovering over spot.
  • click : The data associated will show up on clicking the spot.
  • none : The data will be static and would not be affected by any events.

Basic call with known coordinates:

$('#theElement').hotspot({
  data: [
    { "x":18, "y":38, "Title":"The Title","Message":"Create the Message here" },
    { "x":43, "y":40, "Title":"jQuery Hotspot","Message":"This jQuery Plugin lets you create hotspot to any HTML element." }
  ],
  tag: 'img', //optional (default is img)
  interactivity: "hover", // options : click, none (default is hover)
  hotspotClass: 'Hotspot'
});

The data object above can be populated with any number of properties and can be designed with appropriate CSS. The tag variable passed to the plugin determines the type of HTML tag for which the hotspot is obtained. The hotspotClass is class of the hotspots created. One can change the look of the hotspot by applying some CSS to this class.

By default in display mode, repositioning of hotspots on window resize is enabled. To disable this, a parameter can be passed in the plugin options.

listenOnResize: false

Fetching data via AJAX call

$("#theElement").hotspot({
  ajax: true, // Switching on the ajax
  ajaxOptions: {
    url: '/hotspots',
    type: 'GET',
    ...
  },
  interactivity: "hover" // options : click, none (default is hover)
});

The data coming from the server-side is expected to be JSON encoded. The object ajaxOptions can be utilized to change the http headers, etc.

Usage - Admin mode

Standard call

$("#theElement").hotspot({
  mode: "admin", // Switching to admin mode
  ajax: true, // Turn on ajax
  ajaxOptions: {
    url: '/hotspots',
    type: 'POST',
    ...
  },
  interactivity: "hover" // options : click, none (default is hover)
});

ajax and ajaxOptions are required here so that the hotspot that are being created in the admin mode get stored in the server. However if someone turn off the ajax, then the hotspots data gets stored in the browser's LocalStorage.

Key Features

  1. Any number of messages/nodes can be stuffed in a single hotspot. To do so the schema parameter is passed to the plugin. By default there are two nodes (Title and Message)
$("#theElement").hotspot({
  mode: "admin", // Switching to admin mode
  ajax: true, // Turn on ajax
  ajaxOptions: {
    url: '/hotspots',
    type: 'POST',
    ...
  },
  schema: [
    {
      'property': 'Time',
      'default': '5:40am'
    },
    {
      'property': 'Date',
      'default': '12/11/2018'
    },
    {
      'property': 'Place',
      'default': 'Siberia'
    },
  ]
});

The default property in the schema object above will be overwritten everytime a new hotspot is created.

  1. The plugin also provides some basic functions that can be invoked after certain events in the process of creation of hotspots.
$("#theElement").hotspot({
  mode: "admin", // Switching to admin mode
  ajax: true, // Turn on ajax
  ajaxOptions: {
    url: '/hotspots',
    type: 'POST',
    ...
  },
  afterSave: function(err, data) {
    // hotspots `data` in json format can be stored
    //  & passed in `display` mode for the image
  },
  afterRemove: function(err, message) {
    // `message` from the plugin
  },
  afterSend: function(error, message) {
    // check if any `error` has occurred
  }
});

These functions can be utilized to keep track of the flow of hotspot creation.

  1. The plugin can be used with any number of HTML elements in a page. However to do so, the LS_Variable passed to the plugin should be named uniquely for every instance. This helps plugin to avoid conflicts and while using HTML5 LocalStorage.

HTML :

<div id="theElement-a">
  <img src="theImage-a.jpg" />
</div>
<div id="theElement-b">
  <img src="theImage-b.jpg" />
</div>

JavaScript :

$("#theElement-a").hotspot({
  mode: "admin",
  ...
  LS_Variable: "HotspotPlugin-a"
});

$("#theElement-b").hotspot({
  mode: "admin",
    ...
  LS_Variable: "HotspotPlugin-b"
});

For better clarity the examples folder can be checked

Fetch data via AJAX Request

Include jquery and hotspot plugin in the html code.

<script type="text/javascript">
$.ajax({url: "mytest.aspx/GetHotSpotData", success: function (result) {
  $("#HotspotPlugin_image").hotspot({
    data: result,
    interactivity: "click",
  });
}});
</script>

Also make sure result passed as data in the plugin should be an array of objects.

[
  { "x":18, "y":29, "Title":"The Title","Message":"Create the Message here" },
  { "x":14, "y":40, "Title":"jQuery Hotspot","Message":"This jQuery Plugin lets you create hotspot to any HTML element." }
]

jquery-hotspot's People

Contributors

aniruddha22 avatar aniruddhanath avatar pbozic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jquery-hotspot's Issues

How to add url links to open when user clicks the hotspot?

Hello,
First of all, thank you for sharing your code. This is not an issue. But there is no place to ask, so I am using this area to ask. I am new to jquery hotspot. I would like to add code to open website when user clicks the hotspot. How can I add href link? Can I add href link to where you have under data: [ {"x", "y"}] in basic_usage.html?

Issue with getting data using AJAX

Hi,

When i'm trying to fetch the data using AJAX, i need to pass data to the webservice that i'm calling but when the webservice is called it says no parameter is found and throws an error. The code i'm using is as follows:

var values = { imageId: "HotspotPlugin-b" };
$("#divHotspotTest").hotspot({
mode: "admin",
// uncomment
ajax: true,
ajaxOptions: {
url: 'QuestionPack.aspx/GetHotspotData',
data: JSON.stringify(values),
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: false,
success: function (response) {
console.log("Success Hotspot b: ", response);
alert("Success Hotspot ", response.d);
},
error: function (response) {
console.log("Error Hotspot b: ", response);
alert("Error hotspot b ", response.status);
}
},
LS_Variable: "HotspotPlugin-b",
done_btnId: 'done-b',
remove_btnId: 'remove-b',
server_btnId: 'server-b',
done_btnClass: 'btn btn-success controls',
remove_btnClass: 'btn btn-danger controls',
sync_btnClass: 'btn btn-info controls',
afterSave: function (message) {
alert(message);
},
afterRemove: function (message) {
alert(message);
window.location.reload();
},
afterSyncToServer: function (message) {
alert(message);
}
});

Any help would be appreciated. Thanks in advance!

Problem In Responsive View.

Hi,
I need this Hotspot creator in responsive view, how to get X,Y Positions in Percentage ?
i want to host this in mobile based app.
please help me.

Hotspots on wordpress website

Hello,
First of all, thanks for this very nice plugin.
I work under wordpress and have tried to use the jquery-hotspot, but I have some problems.
If I write the following html in the php file of my page:

`



Example - Admin mode



		    <div class="col-md-6">

			<div id="theElement">
				<img src="IMG_5990.JPG" width="480" height="400">
			</div>
			</div>
	</div>
</div>`

and the css needed:

#theElement { position: relative; display: inline-block; }

and the following javascript in my js file:

`(function($) {
$(document).ready(function() {

$('#theElement').hotspot({
data: [
{ "x":288, "y":390, "Title":"The Title","Message":"Create the Message here" },
{ "x":143, "y":400, "Title":"jQuery Hotspot","Message":"This jQuery Plugin lets you create hotspot to any HTML element." }
],
tag: 'img', //optional (default is img)
interactivity: "hover", // options : click, none (default is hover)
hotspotClass: 'Hotspot'
});
});
})(jQuery);`

My image is displayed but I have this error :
pb1

I tried to add { braces just after the ( brackets but it still doesn't work, and hotspots never appear.. :
pb2

Hoping you can help me,
Thanks a lot,
Marine

How to bind points to the background image div?

How to bind points to the background image div?

Living example

<section>
    <div class="container main-background" id="main_foto_hotspots">
      // img background
    </div>
</section>
.main-background {
  background-image: url(main_foto.webp);
  background-repeat: no-repeat;
  background-position-x: right;
  background-position-y: top;
  background-size: 50%;
}
jQuery('#main_foto_hotspots').hotspot({
  data: [
    { "x":18, "y":38, "Title":"The Title","Message":"Create the Message here" },
    { "x":43, "y":40, "Title":"jQuery Hotspot","Message":"This jQuery Plugin lets you create hotspot to any HTML element." }
  ],
  tag: '**div.background**', //optional (default is img)
  interactivity: "click", // options : click, none (default is hover)
  hotspotClass: 'Hotspot'
});

Issue when adding hotspot to a slider (siema slider)

Hi all,

I have a siema (https://github.com/pawelgrzybek/siema) slider running on my page. Adding hotspots to the visible slides is not an issue at all - adding them for slides that are not visible (visible as in not shown in the browser since overflow is set to hidden in the parent DIV - from a css perspective I believe they are set to visible) does not work.

I tried using siemas onChange event which fires every time slides change, but without any luck.

Within the onChange event I added this code:

$("#tattoo-slider-3").hotspot({
                        data: [
                            { "x":10, "y":10, "Title":"Travel Mugs","Message":"<a href='/dinnerware/tattoo-cilla-marea/?_bc_fsnf=1&Product=Mugs' class='button button--primary' style='line-height: 0.5rem;padding: 0.5rem;'>see details</a>" }
                        ],
                        tag: 'img', //optional (default is img)
                        interactivity: "hover", // options : click, none (default is hover),
                        pulse: true // this is a customization I added
                    });

I have a feeling the hotspots are not being set for items which are not visible on screen...

Can you point me into the right direction?

Thanks!
Marc

EDIT: here the link to the plugin in my production environment:
https://www.rosenthalusa-shop.com

problem in IE- 8

I am using this plugin in IE 8, but is is showing error in calling hotspot function.
error is "expected identifier, string or number"

Caching

Hi, I have the system installed on my website and when I log in as a user, add and save spots and log out, the spots are there when I login as a different user before I choose any spots. They are being 'remembered' for the next user. Is there a way to clear them out of the browser after I leave the page? many thanks

v 2.0.2 not responsive

Hello, I am using v2.0.2 and the dots are not responsive on your examples or on my own. When I shrink down the browser, the spots move off the images. If you could advise, that would be wonderful thanks

Responsive

Hello, I am using v2.0.2 and the dots are not responsive on your examples or on my own. When I shrink down the browser, the spots move off the images. If you could advise, that would be wonderful thanks

How can we add a click event on a hotspot popup

Please advise how can we add a click event for each property box opens. The scope behind this is to open particular modal on clicking a button which will be presented on the property box.

Thanks in advance. Really appreciate your work.

how to print data sent by ajax

Hi,
I want to save posted data to mysql database. I activate ajax method. My code:
$(document).ready(function(){
var TreatmentID = $("#theElement-a").attr("TreatmentID");
$("#theElement-a").hotspot({
mode: "admin",
schema: [
{
'property': 'TreatmentID',
'default': TreatmentID
},
{
'property': 'Date',
'default': '12/11/2018'
},
],
// uncomment
ajax: true,
ajaxOptions: {
'url': 'saveguide.php'
},
interactivity: "click",
LS_Variable: "HotspotPlugin-a",

		afterSave: function(err, data) {
			if (err) {
				console.log('Error occurred', err);
				return;
			}
			alert('success');
			// `data` in json format can be stored
			//  & passed in `display` mode for the image
			console.log(data);
		},
		afterRemove: function(err, message) {
			if (err) {
				console.log('Error occurred', err);
				return;
			}
			alert(message);
			window.location.reload();
		},
		afterSend: function(err, message) {
			if (err) {
				console.log('Error occurred', err);
				return;
			}
			alert(message);
		}
	});

});

how to print posted values in saveguide.php file?

Thank you
Mansour

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.