Permalink
Browse files

more isotope stuff

  • Loading branch information...
1 parent e5657b3 commit 92e827e23e66e7ca9566a8d65469e663fd550496 @kristianmandrup committed Sep 18, 2012
View
@@ -13,28 +13,37 @@ This gem includes:
* jquery infinitescroll
* jquery event drag
-Now [Isotope](http://isotope.metafizzy.co/index.html) is also included. Masonry and Isotope can even be used in combination!
-
For random content generation
* box maker
* loremimages
-## Isotope assets
+## Isotope
+
+[Isotope](http://isotope.metafizzy.co/index.html) is also included. Isotope is very similar to Masonry and might be a nice alternative for some use cases. Why it is included ;)
+
+### Isotope assets
Javascript
* jquery.isotope.js
* jquery.isotope.min.js
+Extras:
+
+* jquery.debounced_resize.min.js
+* jquery.throttled_resize.min.js
+
Stylesheets
* isotope.css
-More stylesheets in `isotope` folder in `vendor/assets
+More isotope related stylesheets in `isotope` folder in `vendor/assets. Use as inspiration...
Please see Isotope [License](http://isotope.metafizzy.co/docs/license.html) for commercial use.
+Usage: See [Getting started](http://isotope.metafizzy.co/docs/introduction.html#getting_started)
+
## Usage
In Gemfile
@@ -0,0 +1,27 @@
+(function($,sr){
+
+ // debouncing function from John Hann
+ // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
+ var debounce = function (func, threshold, execAsap) {
+ var timeout;
+
+ return function debounced () {
+ var obj = this, args = arguments;
+ function delayed () {
+ if (!execAsap)
+ func.apply(obj, args);
+ timeout = null;
+ };
+
+ if (timeout)
+ clearTimeout(timeout);
+ else if (execAsap)
+ func.apply(obj, args);
+
+ timeout = setTimeout(delayed, threshold || 100);
+ };
+ }
+ // smartresize
+ jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
+
+})(jQuery,'smartresize');
@@ -0,0 +1,47 @@
+/*
+ * debouncedresize: special jQuery event that happens once after a window resize
+ *
+ * latest version and complete README available on Github:
+ * https://github.com/louisremi/jquery-smartresize
+ *
+ * Copyright 2012 @louis_remi
+ * Licensed under the MIT license.
+ *
+ * This saved you an hour of work?
+ * Send me music http://www.amazon.co.uk/wishlist/HNTU0468LQON
+ */
+(function($) {
+
+var $event = $.event,
+ $special,
+ resizeTimeout;
+
+$special = $event.special.debouncedresize = {
+ setup: function() {
+ $( this ).on( "resize", $special.handler );
+ },
+ teardown: function() {
+ $( this ).off( "resize", $special.handler );
+ },
+ handler: function( event, execAsap ) {
+ // Save the context
+ var context = this,
+ args = arguments,
+ dispatch = function() {
+ // set correct event type
+ event.type = "debouncedresize";
+ $event.dispatch.apply( context, args );
+ };
+
+ if ( resizeTimeout ) {
+ clearTimeout( resizeTimeout );
+ }
+
+ execAsap ?
+ dispatch() :
+ resizeTimeout = setTimeout( dispatch, $special.threshold );
+ },
+ threshold: 150
+};
+
+})(jQuery);
@@ -0,0 +1,58 @@
+/*
+ * throttledresize: special jQuery event that happens at a reduced rate compared to "resize"
+ *
+ * latest version and complete README available on Github:
+ * https://github.com/louisremi/jquery-smartresize
+ *
+ * Copyright 2012 @louis_remi
+ * Licensed under the MIT license.
+ *
+ * This saved you an hour of work?
+ * Send me music http://www.amazon.co.uk/wishlist/HNTU0468LQON
+ */
+(function($) {
+
+var $event = $.event,
+ $special,
+ dummy = {_:0},
+ frame = 0,
+ wasResized, animRunning;
+
+$special = $event.special.throttledresize = {
+ setup: function() {
+ $( this ).on( "resize", $special.handler );
+ },
+ teardown: function() {
+ $( this ).off( "resize", $special.handler );
+ },
+ handler: function( event, execAsap ) {
+ // Save the context
+ var context = this,
+ args = arguments;
+
+ wasResized = true;
+
+ if ( !animRunning ) {
+ setInterval(function(){
+ frame++;
+
+ if ( frame > $special.threshold && wasResized || execAsap ) {
+ // set correct event type
+ event.type = "throttledresize";
+ $event.dispatch.apply( context, args );
+ wasResized = false;
+ frame = 0;
+ }
+ if ( frame > 9 ) {
+ $(dummy).stop();
+ animRunning = false;
+ frame = 0;
+ }
+ }, 30);
+ animRunning = true;
+ }
+ },
+ threshold: 0
+};
+
+})(jQuery);

0 comments on commit 92e827e

Please sign in to comment.