Skip to content

Commit

Permalink
Some Code-Style refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Klein committed Jul 25, 2014
1 parent 1ef861d commit 180b5a5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
# Changelog

### HEAD
* Code style refactoring

### 0.8.0 - 2014-07-22
* Clean up documentation and featureRequest
Expand Down
10 changes: 5 additions & 5 deletions Gruntfile.js
Expand Up @@ -47,11 +47,11 @@ module.exports = function(grunt) {
},

concat: {
options: {
banner: '<%= functionalScope.header %>',
footer: '<%= functionalScope.footer %>',
stripBanners: false
},
// options: {
// banner: '<%= functionalScope.header %>',
// footer: '<%= functionalScope.footer %>',
// stripBanners: false
// },
js: {
src: [
'src/js/transition.js',
Expand Down
19 changes: 14 additions & 5 deletions src/js/touch-carousel.js
@@ -1,10 +1,17 @@
+function ($) {
"use strict";

/**
* Return whole plugin if touch is not supported
*/
if (!("ontouchstart" in window || navigator.msMaxTouchPoints)) return false;

// CONST
var NAMESPACE = 'touch-carousel',
var NAMESPACE = 'touch-carousel';

// TouchCarousel Constructor
// -------------------
TouchCarousel = function (element, options) {
var TouchCarousel = function (element, options) {
this.$element = $(element)
this.$itemsWrapper = this.$element.find('.carousel-inner')
this.$items = this.$element.find('.item')
Expand Down Expand Up @@ -58,7 +65,7 @@
TouchCarousel.prototype._regTouchGestures = function() {
this.$itemsWrapper
.add(this.$indicators) // fixes issue #9
.hammer({
.hammer({
drag_lock_to_axis: true,
preventDefault: true,
})
Expand Down Expand Up @@ -204,7 +211,7 @@
this.$indicators.find('.active').removeClass('active');
this.$indicators.children().eq(index).addClass('active');
}

this.$element.trigger('slid.bs.carousel');


Expand Down Expand Up @@ -261,4 +268,6 @@
}

e.preventDefault()
})
});

}(window.jQuery);
76 changes: 50 additions & 26 deletions src/js/transition.js
@@ -1,26 +1,42 @@
// Test css properties
+function ($) {
"use strict";

/**
* Return whole plugin if touch is not supported
*/
if (!("ontouchstart" in window || navigator.msMaxTouchPoints)) {
return false;
}

/**
* testProps()
* @description Test properties with all major prefixes in current browser
* @param {Array} props List of props to be tested
* @param {String} prefixed Use Boolean or prefixed css property as return value
* @return {String/Boolean} Prefixed css property or Boolean based on `prefixed` param
*/
function testProps( props, prefixed ) {
var _style = document.createElement('div').style;
for ( var i in props ) {
if ( _style[ props[i] ] !== undefined ) {
return prefixed == 'pfx' ? props[i] : true;
}
var _style = document.createElement('div').style;
for ( var i in props ) {
if ( _style[ props[i] ] !== undefined ) {
return prefixed == 'pfx' ? props[i] : true;
}
return false;
}
return false;
}


// CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/)
// ============================================================

/**
* transitionEnd()
* @description Test browser transition support
* @return {String} Return supported transition event hooks
*/
function transitionEnd() {
var el = document.createElement('bootstrap')

var transEndEventNames = {
'WebkitTransition' : 'webkitTransitionEnd'
, 'MozTransition' : 'transitionend'
, 'OTransition' : 'oTransitionEnd otransitionend'
, 'transition' : 'transitionend'
'WebkitTransition' : 'webkitTransitionEnd',
'MozTransition' : 'transitionend',
'OTransition' : 'oTransitionEnd otransitionend',
'transition' : 'transitionend'
}

for (var name in transEndEventNames) {
Expand All @@ -29,28 +45,36 @@
}
}
}
// http://blog.alexmaccaw.com/css-transitions
$.fn.emulateTransitionEnd = function (duration) {
var called = false, $el = this
$(this).one($.support.transition.end, function () { called = true })
var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
setTimeout(callback, duration)
return this
}


/**
* csstransforms()
* @description Test browser CSS transforms support
* @return {Boolean} return support condition result
*/
function csstransforms() {
var prefixes = ['transformProperty', 'WebkitTransform', 'MozTransform', 'msTransform'];
return !!testProps( prefixes );
}

// @todo: test more than only webkit ;-)
/**
* csstransforms3d()
* @description Test browser CSS transforms3d support
* @todo Test more than only webkit
* @return {Boolean} return support condition result
*/
function csstransforms3d() {
return ('WebKitCSSMatrix' in window && 'm11' in new WebKitCSSMatrix());
}

/**
* Anonymous function
* @description Save functions to jquery.support namespace
* @return {null}
*/
$(function () {
$.support.transition = transitionEnd()
$.support.csstransforms = csstransforms()
$.support.csstransforms3d = csstransforms3d()
})

}(window.jQuery);

0 comments on commit 180b5a5

Please sign in to comment.