Skip to content
Browse files

Starting to make prototype a plugin

  • Loading branch information...
1 parent 5ffe89b commit d34ab4006a6d61a8ae37546a24614bfb74599d1d @uxder committed Mar 1, 2012
Showing with 28 additions and 10 deletions.
  1. +6 −1 samples/samples.html
  2. +22 −9 src/vivid.js
View
7 samples/samples.html
@@ -26,7 +26,12 @@
<script src="js/jquery-1.7.1.min.js"></script>
<script src="../src/vivid.js"></script>
<script>
- $('.test').vivid();
+ $('.test').vivid({
+ filter: 'blackAndWhite',
+ blackWhite: {
+ lightness: 0.3
+ }
+ });
/**
View
31 src/vivid.js
@@ -191,15 +191,25 @@ $.fn.vivid = function(options) {
});
}
-
+/**
+ * Prototype for plugin
+ */
+Vivid.filter.base = function() {
+ var s,
+ pluginName = "blackWhite",
+ options = {};
+}
/**
* Vivid blackWhite Plugin
*/
-Vivid.filter.blackWhite = (function() {
-
+Vivid.filter.blackWhite = (function( window, document, jQuery) {
//shortname for settings
- var s;
+ var s,
+ pluginName = "blackWhite",
+ options = {
+ lightness: 0.3
+ };
/**
* Constructor
@@ -208,6 +218,8 @@ Vivid.filter.blackWhite = (function() {
var filter = function(settings) {
//set the settings
s = settings;
+ // Mix in the passed-in options with the default options
+ options = $.extend( {}, options, s.options[pluginName] );
//initialize plugin
this.init();
}
@@ -218,16 +230,17 @@ Vivid.filter.blackWhite = (function() {
var imgd = s.ctx.getImageData(0, 0, s.imgW, s.imgH);
var p = imgd.data;
for (var i = 0, n = p.length; i < n; i += 4) {
- var grayscale = p[i] * .3 + p[i+1] * .59 + p[i+2] * .11;
- p[i] = grayscale; // red
- p[i+1] = grayscale; // green
- p[i+2] = grayscale; // blue
+ var grayscale = p[i] * options.lightness + p[i+1] * 0.6 + p[i+2] * 0.1;
+
+ p[i] = grayscale; //red
+ p[i+1] = grayscale; //blue
+ p[i+2] = grayscale; //green
}
s.ctx.putImageData(imgd, 0, 0);
}
}
//return the plugin object
return filter;
-})();
+})( window, document, jQuery );

0 comments on commit d34ab40

Please sign in to comment.
Something went wrong with that request. Please try again.