Permalink
Browse files

Initial working commit. Needs tests.

  • Loading branch information...
1 parent d474ae1 commit 41d61435873e928cbbb55ec695bf360216796517 @Wilto Wilto committed Sep 12, 2012
Showing with 233 additions and 50 deletions.
  1. +4 −4 package.json
  2. +229 −14 src/Revolver.js
  3. +0 −32 test/Revolver_test.js
View
@@ -3,22 +3,22 @@
"title": "Revolver",
"description": "A 360° panorama photo viewer.",
"version": "0.1.0",
- "homepage": "https://github.com/filamentgroup/ThreeSixty",
+ "homepage": "https://github.com/filamentgroup/Revolver",
"author": {
"name": "Mat Marquis",
"email": "mat@matmarquis.com"
},
"repository": {
"type": "git",
- "url": "git@github.com:filamentgroup/ThreeSixty.git"
+ "url": "git@github.com:filamentgroup/Revolver.git"
},
"bugs": {
- "url": "https://github.com/filamentgroup/ThreeSixty/issues"
+ "url": "https://github.com/filamentgroup/Revolver/issues"
},
"licenses": [
{
"type": "MIT",
- "url": "https://github.com/filamentgroup/ThreeSixty/blob/master/LICENSE-MIT"
+ "url": "https://github.com/filamentgroup/Revolver/blob/master/LICENSE-MIT"
}
],
"dependencies": {
View
@@ -1,28 +1,243 @@
/*
- * Revolver
- * https://github.com/filamentgroup/ThreeSixty
+ * Revolverresponsive-carousel
+ * https://github.com/filamentgroup/revolver
*
- * Copyright (c) 2012 Mat Marquis
- * Licensed under the MIT license.
+ * Copyright (c) 2012 Filament Group, Inc.
+ * Licensed under the MIT, GPL licenses.
*/
(function($) {
+ var pluginName = "threesixty",
+ initSelector = "." + pluginName,
+ itemClass = pluginName + "-item",
+ activeClass = pluginName + "-active",
+ methods = {
+ _create: function(){
+ return $( this ).each(function() {
+ var init = $( this ).data( "init" );
+ if( init ) {
+ return false;
+ }
+
+ $( this )
+ .data( "init", true)
+ .trigger( "beforecreate." + pluginName )
+ [ pluginName ]( "_init" )
+ .trigger( "create." + pluginName );
+ });
+ },
+
+ _init: function(){
+ var $dupe = $( this ).find( "img" ).clone();
+
+ return $( this ).addClass( pluginName + " " + pluginName + "-slide " )
+ .append( $dupe )
+ .children()
+ .addClass( itemClass + " introslide")
+ .first()
+ .addClass( activeClass );
+ },
+
+ _reset: function() {
+ $( ".dialog-360" ).removeClass( "fadeout" );
+ $( "." + itemClass ).addClass( "introslide" );
+ }
+ };
+
// Collection method.
- $.fn.awesome = function() {
+ $.fn[ pluginName ] = function( arrg, a, b, c ) {
return this.each(function() {
- $(this).html('awesome');
+
+ // if it's a method
+ if( arrg && typeof( arrg ) === "string" ){
+ return $.fn[ pluginName ].prototype[ arrg ].call( this, a, b, c );
+ }
+
+ // don't re-init
+ if( $( this ).data( pluginName + "data" ) ){
+ return $( this );
+ }
+
+ // otherwise, init
+ $( this ).data( pluginName + "active", true );
+ $.fn[ pluginName ].prototype._create.call( this );
});
};
- // Static method.
- $.awesome = function() {
- return 'awesome';
- };
+ // add methods
+ $.extend( $.fn[ pluginName ].prototype, methods );
- // Custom selector.
- $.expr[':'].awesome = function(elem) {
- return elem.textContent.indexOf('awesome') >= 0;
- };
+ // DOM-ready auto-init
+ $( function(){
+ $( initSelector )[ pluginName ]();
+ } );
+
+}(jQuery));
+
+/*
+ * responsive-carousel touch drag extension
+ * https://github.com/filamentgroup/responsive-carousel
+ *
+ * Copyright (c) 2012 Filament Group, Inc.
+ * Licensed under the MIT, GPL licenses.
+ */
+
+ (function($) {
+ var pluginName = "threesixty",
+ initSelector = "." + pluginName,
+ noTrans = pluginName + "-no-transition",
+ touchMethods = {
+ _dragBehavior: function(){
+ var origin,
+ data = {},
+ deltaY,
+ xPerc,
+ yPerc,
+ emitEvents = function( e ){
+ var touches = e.touches || e.originalEvent.touches,
+ $elem = $( e.target ).closest( initSelector );
+
+ if( e.type === "touchstart" ){
+ origin = {
+ x : touches[ 0 ].pageX,
+ y: touches[ 0 ].pageY
+ };
+ }
+
+ if( touches[ 0 ] && touches[ 0 ].pageX ){
+ data.touches = touches;
+ data.deltaX = touches[ 0 ].pageX - origin.x;
+ data.deltaY = touches[ 0 ].pageY - origin.y;
+ data.w = $elem.first().width();
+ data.h = $elem.first().height();
+ data.xPercent = data.deltaX / data.w;
+ data.yPercent = data.deltaY / data.h;
+ data.srcEvent = e;
+ }
+
+ $elem.trigger( "drag" + e.type.split( "touch" )[ 1 ], data );
+ return data;
+ };
+
+ $( this )
+ .bind( "touchstart", function( e ){
+ $( this ).addClass( noTrans );
+ emitEvents( e );
+ } )
+ .bind( "touchmove", function( e ){
+ var data = emitEvents( e );
+
+ if( Math.abs( data.deltaX ) > 35 && Math.abs( data.deltaY ) < 35 && data.touches.length === 1 ){
+ return false;
+ }
+ e.stopPropagation();
+ } )
+ .bind( "touchend", function( e ){
+ $( this ).removeClass( noTrans );
+ emitEvents( e );
+ } );
+ }
+ };
+
+ // add methods
+ $.extend( $.fn[ pluginName ].prototype, touchMethods );
+ // DOM-ready auto-init
+ $( initSelector ).live( "create." + pluginName, function(){
+ $( this )[ pluginName ]( "_dragBehavior" );
+ } );
+
+ }(jQuery));
+
+ (function($) {
+ var pluginName = "threesixty",
+ initSelector = "." + pluginName,
+ activeClass = pluginName + "-active",
+ itemClass = pluginName + "-item",
+ current,
+ clicked,
+ origin,
+ adjust,
+ mouseDrag = function( e ) {
+ var data = {};
+ if( e.type === "mousedown" ) {
+ clicked = true;
+ origin = {
+ x : e.pageX,
+ e : e
+ };
+ data.srcEvent = origin.e;
+ e.preventDefault();
+ }
+ if( ( e.type === "mousedown" || e.type === "mousemove" ) && clicked ) {
+ data.deltaX = e.pageX - origin.x;
+ data.srcEvent = origin.e;
+
+ if( e.type === "mousemove" ) {
+ data.moveEvent = e;
+ }
+
+ $( this ).trigger( "dragmove", [ data ] );
+ }
+ if( e.type === "mouseup" ) {
+ clicked = false;
+ }
+ },
+ getActiveSlides = function( $carousel, data ){
+ var $from = $( data.srcEvent.target ),
+ activeNum = $from.prevAll().length + 1,
+ forward = data.deltaX < 0,
+ nextNum = activeNum + (forward ? 1 : -1),
+ $children = $carousel.find( "." + itemClass ),
+ $to = $children.eq( nextNum - 1 );
+
+ if( !$to.length ){
+ $to = $children[ forward ? "first" : "last" ]();
+ }
+ return [ $from, $to ];
+ };
+
+ $( initSelector )
+ // Touch handling
+ .live( "dragstart dragmove", function( e, data ){
+ var activeSlides = getActiveSlides( $( this ), data ),
+ swipeSpeed = data.deltaX * 3.5,
+ width = activeSlides[ 0 ].width(),
+ current = parseInt( activeSlides[ 0 ].css( "left" ), 10 );
+
+ if( ( e.type === "dragstart" || data.srcEvent.type === "mousedown" ) && !data.moveEvent ){
+ adjust = current;
+ }
+
+ activeSlides[ 0 ].css( "left", ( adjust || 0 ) + swipeSpeed );
+ activeSlides[ 1 ].css( "left", ( current < -( width / 2 ) ) ? width + ( adjust || 0 ) + swipeSpeed : -width + ( adjust || 0 ) + swipeSpeed );
+
+ e.stopPropagation();
+ } )
+ .live( "dragend dragmove", function( e ) {
+ e.stopPropagation();
+ })
+ // Mouse handling
+ .live( "mousedown mousemove mouseup", mouseDrag );
}(jQuery));
+
+(function($) {
+ var pluginName = "threesixty",
+ initSelector = "." + pluginName;
+
+ // DOM-ready auto-init
+ $( ".carousel" ).live( "ajaxInclude", function(){
+ $( initSelector )[ pluginName ]( "_create" );
+ } );
+
+ $( initSelector ).live( "dragstart dragmove drag", function( e ) {
+ var $el = $( e.target );
+ } );
+
+ $( ".carousel-nav a, .all-images a, .gallery-filters a" ).live( "click", function() {
+ $( initSelector )[ pluginName ]( "_reset" );
+ } );
+
+}(jQuery));
+
View
@@ -22,36 +22,4 @@
raises(block, [expected], [message])
*/
- module('jQuery#awesome', {
- setup: function() {
- this.elems = $('#qunit-fixture').children();
- }
- });
-
- test('is chainable', 1, function() {
- // Not a bad test to run on collection methods.
- strictEqual(this.elems.awesome(), this.elems, 'should be chaninable');
- });
-
- test('is awesome', 1, function() {
- strictEqual(this.elems.awesome().text(), 'awesomeawesomeawesome', 'should be thoroughly awesome');
- });
-
- module('jQuery.awesome');
-
- test('is awesome', 1, function() {
- strictEqual($.awesome(), 'awesome', 'should be thoroughly awesome');
- });
-
- module(':awesome selector', {
- setup: function() {
- this.elems = $('#qunit-fixture').children();
- }
- });
-
- test('is awesome', 1, function() {
- // Use deepEqual & .get() when comparing jQuery objects.
- deepEqual(this.elems.filter(':awesome').get(), this.elems.last().get(), 'knows awesome when it sees it');
- });
-
}(jQuery));

0 comments on commit 41d6143

Please sign in to comment.