Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Starting to make prototype a plugin

  • Loading branch information...
commit d34ab4006a6d61a8ae37546a24614bfb74599d1d 1 parent 5ffe89b
Scott Murphy authored

Showing 2 changed files with 28 additions and 10 deletions. Show diff stats Hide diff stats

  1. +6 1 samples/samples.html
  2. +22 9 src/vivid.js
7 samples/samples.html
@@ -26,7 +26,12 @@
26 26 <script src="js/jquery-1.7.1.min.js"></script>
27 27 <script src="../src/vivid.js"></script>
28 28 <script>
29   - $('.test').vivid();
  29 + $('.test').vivid({
  30 + filter: 'blackAndWhite',
  31 + blackWhite: {
  32 + lightness: 0.3
  33 + }
  34 + });
30 35
31 36
32 37 /**
31 src/vivid.js
@@ -191,15 +191,25 @@ $.fn.vivid = function(options) {
191 191 });
192 192 }
193 193
194   -
  194 +/**
  195 + * Prototype for plugin
  196 + */
  197 +Vivid.filter.base = function() {
  198 + var s,
  199 + pluginName = "blackWhite",
  200 + options = {};
  201 +}
195 202
196 203 /**
197 204 * Vivid blackWhite Plugin
198 205 */
199   -Vivid.filter.blackWhite = (function() {
200   -
  206 +Vivid.filter.blackWhite = (function( window, document, jQuery) {
201 207 //shortname for settings
202   - var s;
  208 + var s,
  209 + pluginName = "blackWhite",
  210 + options = {
  211 + lightness: 0.3
  212 + };
203 213
204 214 /**
205 215 * Constructor
@@ -208,6 +218,8 @@ Vivid.filter.blackWhite = (function() {
208 218 var filter = function(settings) {
209 219 //set the settings
210 220 s = settings;
  221 + // Mix in the passed-in options with the default options
  222 + options = $.extend( {}, options, s.options[pluginName] );
211 223 //initialize plugin
212 224 this.init();
213 225 }
@@ -218,10 +230,11 @@ Vivid.filter.blackWhite = (function() {
218 230 var imgd = s.ctx.getImageData(0, 0, s.imgW, s.imgH);
219 231 var p = imgd.data;
220 232 for (var i = 0, n = p.length; i < n; i += 4) {
221   - var grayscale = p[i] * .3 + p[i+1] * .59 + p[i+2] * .11;
222   - p[i] = grayscale; // red
223   - p[i+1] = grayscale; // green
224   - p[i+2] = grayscale; // blue
  233 + var grayscale = p[i] * options.lightness + p[i+1] * 0.6 + p[i+2] * 0.1;
  234 +
  235 + p[i] = grayscale; //red
  236 + p[i+1] = grayscale; //blue
  237 + p[i+2] = grayscale; //green
225 238 }
226 239 s.ctx.putImageData(imgd, 0, 0);
227 240 }
@@ -229,5 +242,5 @@ Vivid.filter.blackWhite = (function() {
229 242
230 243 //return the plugin object
231 244 return filter;
232   -})();
  245 +})( window, document, jQuery );
233 246

0 comments on commit d34ab40

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