Skip to content

Commit 0e3a589

Browse files
v0.0.3
1 parent ff8981d commit 0e3a589

File tree

2 files changed

+190
-191
lines changed

2 files changed

+190
-191
lines changed

Vague.js

Lines changed: 189 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -1,191 +1,190 @@
11
/**
2-
*
3-
* Version: 0.0.2
4-
* Author: Gianluca Guarini
5-
6-
* Website: http://www.gianlucaguarini.com/
7-
* Twitter: @gianlucaguarini
8-
*
9-
* Copyright (c) 2013 Gianluca Guarini
10-
*
11-
* Permission is hereby granted, free of charge, to any person
12-
* obtaining a copy of this software and associated documentation
13-
* files (the "Software"), to deal in the Software without
14-
* restriction, including without limitation the rights to use,
15-
* copy, modify, merge, publish, distribute, sublicense, and/or sell
16-
* copies of the Software, and to permit persons to whom the
17-
* Software is furnished to do so, subject to the following
18-
* conditions:
19-
*
20-
* The above copyright notice and this permission notice shall be
21-
* included in all copies or substantial portions of the Software.
22-
*
23-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25-
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28-
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29-
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30-
* OTHER DEALINGS IN THE SOFTWARE.
31-
**/
32-
33-
;(function (window,document,$) {
34-
"use strict";
35-
36-
// Plugin private cache
37-
38-
var cache = {
39-
filterId: 0
40-
};
41-
42-
var Vague = function ( elm, customOptions) {
43-
// Default oprions
44-
var defaultOptions = {
45-
intensity:5
46-
},
47-
options = $.extend( defaultOptions, customOptions);
48-
49-
/*
50-
*
51-
* PUBLIC VARS
52-
*
53-
*/
54-
55-
this.$elm = elm instanceof $ ? elm : $(elm);
56-
57-
/*
58-
*
59-
* PRIVATE VARS
60-
*
61-
*/
62-
63-
64-
var blurred = false;
65-
66-
/*
67-
*
68-
* features detection
69-
*
70-
*/
71-
72-
var browserPrefixes = ' -webkit- -moz- -o- -ms- '.split(' ');
73-
74-
var cssPrefixString = {};
75-
var cssPrefix = function(property) {
76-
if (cssPrefixString[property] || cssPrefixString[property] === '') return cssPrefixString[property] + property;
77-
var e = document.createElement('div');
78-
var prefixes = ['', 'Moz', 'Webkit', 'O', 'ms', 'Khtml']; // Various supports...
79-
for (var i in prefixes) {
80-
if (typeof e.style[prefixes[i] + property] !== 'undefined') {
81-
cssPrefixString[property] = prefixes[i];
82-
return prefixes[i] + property;
83-
}
84-
}
85-
return property.toLowerCase();
86-
};
87-
88-
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/css-filters.js
89-
var cssfilters = function () {
90-
var el = document.createElement('div');
91-
el.style.cssText = browserPrefixes.join('filter' + ':blur(2px); ');
92-
return !!el.style.length && ((document.documentMode === undefined || document.documentMode > 9));
93-
}();
94-
95-
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/svg-filters.js
96-
var svgfilters = function(){
97-
var result = false;
98-
try {
99-
result = typeof SVGFEColorMatrixElement !== undefined &&
100-
SVGFEColorMatrixElement.SVG_FECOLORMATRIX_TYPE_SATURATE == 2;
101-
}
102-
catch(e) {}
103-
return result;
104-
}();
105-
106-
/*
107-
*
108-
* PRIVATE METHODS
109-
*
110-
*/
111-
112-
var appendSVGFilter = function () {
113-
114-
var filterMarkup = "<svg id='vague-svg-blur'>" +
115-
"<filter id='blur-effect-id-" + cache.filterId + "'>" +
116-
"<feGaussianBlur stdDeviation='" + options.intensity + "' />" +
117-
"</filter>" +
118-
"</svg>";
119-
120-
$("body").append(filterMarkup);
121-
122-
};
123-
124-
/*
125-
*
126-
* PUBLIC METHODS
127-
*
128-
*/
129-
130-
this.init = function () {
131-
// checking the css filter feature
132-
133-
if (svgfilters) {
134-
appendSVGFilter();
135-
}
136-
137-
this.$elm.data("vague-filter-id",cache.filterId);
138-
139-
cache.filterId ++;
140-
141-
};
142-
143-
this.blur = function () {
144-
var filterValue,
145-
filterId = this.$elm.data("vague-filter-id"),
146-
cssProp = {};
147-
if (cssfilters) {
148-
filterValue = "blur("+ options.intensity + "px)";
149-
} else if (svgfilters) {
150-
filterValue = "url(#blur-effect-id-" + filterId + ")";
151-
} else {
152-
filterValue = "progid:DXImageTransform.Microsoft.Blur(pixelradius=" + options.intensity + ")";
153-
}
154-
cssProp[cssPrefix('Filter')] = filterValue;
155-
156-
this.$elm.css(cssProp);
157-
158-
blurred = true;
159-
};
160-
161-
this.unblur = function () {
162-
var cssProp = {};
163-
cssProp[cssPrefix('Filter')] = "none";
164-
this.$elm.css(cssProp);
165-
blurred = false;
166-
};
167-
168-
this.toggleblur = function () {
169-
if (blurred) {
170-
this.unblur();
171-
} else {
172-
this.blur();
173-
}
174-
};
175-
176-
this.destroy = function () {
177-
if (svgfilters) {
178-
$("filter#blur-effect-id-"+ this.$elm.data("vague-filter-id")).parent().remove();
179-
}
180-
this.unblur();
181-
};
182-
return this.init();
183-
};
184-
185-
$.fn.Vague = function(options) {
186-
return new Vague(this,options);
187-
};
188-
189-
window.Vague = Vague;
190-
191-
}(window,document,jQuery));
2+
*
3+
* Version: 0.0.3
4+
* Author: Gianluca Guarini
5+
* Contact: [email protected]
6+
* Website: http://www.gianlucaguarini.com/
7+
* Twitter: @gianlucaguarini
8+
*
9+
* Copyright (c) 2013 Gianluca Guarini
10+
*
11+
* Permission is hereby granted, free of charge, to any person
12+
* obtaining a copy of this software and associated documentation
13+
* files (the "Software"), to deal in the Software without
14+
* restriction, including without limitation the rights to use,
15+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
* copies of the Software, and to permit persons to whom the
17+
* Software is furnished to do so, subject to the following
18+
* conditions:
19+
*
20+
* The above copyright notice and this permission notice shall be
21+
* included in all copies or substantial portions of the Software.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30+
* OTHER DEALINGS IN THE SOFTWARE.
31+
**/
32+
33+
;(function(window, document, $) {
34+
"use strict";
35+
36+
// Plugin private cache
37+
38+
var cache = {
39+
filterId: 0
40+
};
41+
42+
var Vague = function(elm, customOptions) {
43+
// Default oprions
44+
var defaultOptions = {
45+
intensity: 5
46+
},
47+
options = $.extend(defaultOptions, customOptions);
48+
49+
/*
50+
*
51+
* PUBLIC VARS
52+
*
53+
*/
54+
55+
this.$elm = elm instanceof $ ? elm : $(elm);
56+
57+
/*
58+
*
59+
* PRIVATE VARS
60+
*
61+
*/
62+
63+
64+
var blurred = false;
65+
66+
/*
67+
*
68+
* features detection
69+
*
70+
*/
71+
72+
var browserPrefixes = ' -webkit- -moz- -o- -ms- '.split(' ');
73+
74+
var cssPrefixString = {};
75+
var cssPrefix = function(property) {
76+
if (cssPrefixString[property] || cssPrefixString[property] === '') return cssPrefixString[property] + property;
77+
var e = document.createElement('div');
78+
var prefixes = ['', 'Moz', 'Webkit', 'O', 'ms', 'Khtml']; // Various supports...
79+
for (var i in prefixes) {
80+
if (typeof e.style[prefixes[i] + property] !== 'undefined') {
81+
cssPrefixString[property] = prefixes[i];
82+
return prefixes[i] + property;
83+
}
84+
}
85+
return property.toLowerCase();
86+
};
87+
88+
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/css-filters.js
89+
var cssfilters = function() {
90+
var el = document.createElement('div');
91+
el.style.cssText = browserPrefixes.join('filter' + ':blur(2px); ');
92+
return !!el.style.length && ((document.documentMode === undefined || document.documentMode > 9));
93+
}();
94+
95+
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/svg-filters.js
96+
var svgfilters = function() {
97+
var result = false;
98+
try {
99+
result = typeof SVGFEColorMatrixElement !== undefined &&
100+
SVGFEColorMatrixElement.SVG_FECOLORMATRIX_TYPE_SATURATE == 2;
101+
} catch (e) {}
102+
return result;
103+
}();
104+
105+
/*
106+
*
107+
* PRIVATE METHODS
108+
*
109+
*/
110+
111+
var appendSVGFilter = function() {
112+
113+
var filterMarkup = "<svg id='vague-svg-blur' style='position:absolute;' width='0' height='0' >" +
114+
"<filter id='blur-effect-id-" + cache.filterId + "'>" +
115+
"<feGaussianBlur stdDeviation='" + options.intensity + "' />" +
116+
"</filter>" +
117+
"</svg>";
118+
119+
$("body").append(filterMarkup);
120+
121+
};
122+
123+
/*
124+
*
125+
* PUBLIC METHODS
126+
*
127+
*/
128+
129+
this.init = function() {
130+
// checking the css filter feature
131+
132+
if (svgfilters) {
133+
appendSVGFilter();
134+
}
135+
136+
this.$elm.data("vague-filter-id", cache.filterId);
137+
138+
cache.filterId++;
139+
140+
};
141+
142+
this.blur = function() {
143+
var filterValue,
144+
filterId = this.$elm.data("vague-filter-id"),
145+
cssProp = {};
146+
if (cssfilters) {
147+
filterValue = "blur(" + options.intensity + "px)";
148+
} else if (svgfilters) {
149+
filterValue = "url(#blur-effect-id-" + filterId + ")";
150+
} else {
151+
filterValue = "progid:DXImageTransform.Microsoft.Blur(pixelradius=" + options.intensity + ")";
152+
}
153+
cssProp[cssPrefix('Filter')] = filterValue;
154+
155+
this.$elm.css(cssProp);
156+
157+
blurred = true;
158+
};
159+
160+
this.unblur = function() {
161+
var cssProp = {};
162+
cssProp[cssPrefix('Filter')] = "none";
163+
this.$elm.css(cssProp);
164+
blurred = false;
165+
};
166+
167+
this.toggleblur = function() {
168+
if (blurred) {
169+
this.unblur();
170+
} else {
171+
this.blur();
172+
}
173+
};
174+
175+
this.destroy = function() {
176+
if (svgfilters) {
177+
$("filter#blur-effect-id-" + this.$elm.data("vague-filter-id")).parent().remove();
178+
}
179+
this.unblur();
180+
};
181+
return this.init();
182+
};
183+
184+
$.fn.Vague = function(options) {
185+
return new Vague(this, options);
186+
};
187+
188+
window.Vague = Vague;
189+
190+
}(window, document, jQuery));

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Vague.js",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"main": "Vague.js",
55
"ignore": [
66
"**/.*",

0 commit comments

Comments
 (0)