Primo commit: trasferimento del progetto PPEasy
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Matt Stow
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,34 @@
|
||||
# jQuery RWD Image Maps
|
||||
[](https://cdnjs.com/libraries/jQuery-rwdImageMaps)
|
||||
|
||||
### Allows image maps to be used in a responsive design by recalculating the area coordinates to match the actual image size on load and window.resize
|
||||
|
||||
---
|
||||
|
||||
#### Usage:
|
||||
|
||||
* If possible, add [correct, unitless](http://dev.w3.org/html5/markup/img.html) `width` and `height` attributes to your image map images. You can override these in CSS to make them responsive.
|
||||
* Add a link to jQuery in your page, preferably at the bottom just before the closing `</body>`
|
||||
* After jQuery, either in a `<script>` block or a separate file, call:
|
||||
|
||||
```js
|
||||
$('img[usemap]').rwdImageMaps();
|
||||
```
|
||||
|
||||
You may also want to wrap it inside a `$(document).ready()` function, like so:
|
||||
|
||||
```js
|
||||
$(document).ready(function(e) {
|
||||
$('img[usemap]').rwdImageMaps();
|
||||
});
|
||||
```
|
||||
|
||||
#### Demo:
|
||||
|
||||
http://mattstow.com/experiment/responsive-image-maps/rwd-image-maps.html
|
||||
|
||||
---
|
||||
|
||||
Copyright (c) 2016 [Matt Stow](http://mattstow.com)
|
||||
Licensed under the MIT license *(see [LICENSE](https://github.com/stowball/jQuery-rwdImageMaps/blob/master/LICENSE) for details)*
|
||||
Minified version created with Online YUI Compressor: http://www.refresh-sf.com/yui/
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* rwdImageMaps jQuery plugin v1.6
|
||||
*
|
||||
* Allows image maps to be used in a responsive design by recalculating the area coordinates to match the actual image size on load and window.resize
|
||||
*
|
||||
* Copyright (c) 2016 Matt Stow
|
||||
* https://github.com/stowball/jQuery-rwdImageMaps
|
||||
* http://mattstow.com
|
||||
* Licensed under the MIT license
|
||||
*/
|
||||
;(function($) {
|
||||
$.fn.rwdImageMaps = function() {
|
||||
var $img = this;
|
||||
|
||||
var rwdImageMap = function() {
|
||||
$img.each(function() {
|
||||
if (typeof($(this).attr('usemap')) == 'undefined')
|
||||
return;
|
||||
|
||||
var that = this,
|
||||
$that = $(that);
|
||||
|
||||
// Since WebKit doesn't know the height until after the image has loaded, perform everything in an onload copy
|
||||
$('<img />').on('load', function() {
|
||||
var attrW = 'width',
|
||||
attrH = 'height',
|
||||
w = $that.attr(attrW),
|
||||
h = $that.attr(attrH);
|
||||
|
||||
if (!w || !h) {
|
||||
var temp = new Image();
|
||||
temp.src = $that.attr('src');
|
||||
if (!w)
|
||||
w = temp.width;
|
||||
if (!h)
|
||||
h = temp.height;
|
||||
}
|
||||
|
||||
var wPercent = $that.width()/100,
|
||||
hPercent = $that.height()/100,
|
||||
map = $that.attr('usemap').replace('#', ''),
|
||||
c = 'coords';
|
||||
|
||||
$('map[name="' + map + '"]').find('area').each(function() {
|
||||
var $this = $(this);
|
||||
if (!$this.data(c))
|
||||
$this.data(c, $this.attr(c));
|
||||
|
||||
var coords = $this.data(c).split(','),
|
||||
coordsPercent = new Array(coords.length);
|
||||
|
||||
for (var i = 0; i < coordsPercent.length; ++i) {
|
||||
if (i % 2 === 0)
|
||||
coordsPercent[i] = parseInt(((coords[i]/w)*100)*wPercent);
|
||||
else
|
||||
coordsPercent[i] = parseInt(((coords[i]/h)*100)*hPercent);
|
||||
}
|
||||
$this.attr(c, coordsPercent.toString());
|
||||
});
|
||||
}).attr('src', $that.attr('src'));
|
||||
});
|
||||
};
|
||||
$(window).resize(rwdImageMap).trigger('resize');
|
||||
|
||||
return this;
|
||||
};
|
||||
})(jQuery);
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* rwdImageMaps jQuery plugin v1.6
|
||||
*
|
||||
* Allows image maps to be used in a responsive design by recalculating the area coordinates to match the actual image size on load and window.resize
|
||||
*
|
||||
* Copyright (c) 2016 Matt Stow
|
||||
* https://github.com/stowball/jQuery-rwdImageMaps
|
||||
* http://mattstow.com
|
||||
* Licensed under the MIT license
|
||||
*/
|
||||
;(function(a){a.fn.rwdImageMaps=function(){var c=this;var b=function(){c.each(function(){if(typeof(a(this).attr("usemap"))=="undefined"){return}var e=this,d=a(e);a("<img />").on('load',function(){var g="width",m="height",n=d.attr(g),j=d.attr(m);if(!n||!j){var o=new Image();o.src=d.attr("src");if(!n){n=o.width}if(!j){j=o.height}}var f=d.width()/100,k=d.height()/100,i=d.attr("usemap").replace("#",""),l="coords";a('map[name="'+i+'"]').find("area").each(function(){var r=a(this);if(!r.data(l)){r.data(l,r.attr(l))}var q=r.data(l).split(","),p=new Array(q.length);for(var h=0;h<p.length;++h){if(h%2===0){p[h]=parseInt(((q[h]/n)*100)*f)}else{p[h]=parseInt(((q[h]/j)*100)*k)}}r.attr(l,p.toString())})}).attr("src",d.attr("src"))})};a(window).resize(b).trigger("resize");return this}})(jQuery);
|
||||
Reference in New Issue
Block a user