Skip to content

Commit

Permalink
remove protractor, fix currentCached, navCountVisibleCached
Browse files Browse the repository at this point in the history
  • Loading branch information
ganlanyuan committed Oct 15, 2016
1 parent 1a0eaba commit e2936fc
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 157 deletions.
23 changes: 0 additions & 23 deletions conf.js

This file was deleted.

2 changes: 1 addition & 1 deletion dist/min/tiny-slider.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/min/tiny-slider.native.js

Large diffs are not rendered by default.

79 changes: 38 additions & 41 deletions dist/tiny-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ var gn = (function (g) {
return g;
})(window.gn || {});
// extend
// @require "/src/gn/base.js"
// @require "/src/gn/gn.js"

gn.extend = function () {
var obj, name, copy,
Expand All @@ -431,19 +431,19 @@ gn.extend = function () {
return target;
};
// isInViewport
// @require "/src/gn/base.js"
// @require "/src/gn/gn.js"

gn.isInViewport = function ( elem ) {
var rect = elem.getBoundingClientRect();
return (
rect.bottom > 0 &&
rect.right > 0 &&
rect.top < document.documentElement.clientHeight &&
rect.left < document.documentElement.clientWidth
rect.bottom >= 0 &&
rect.right >= 0 &&
rect.top <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.left <= (window.innerWidth || document.documentElement.clientWidth)
);
};
// indexOf
// @require "/src/gn/base.js"
// @require "/src/gn/gn.js"

gn.indexOf = function (array, item) {
for (var i = 0; i < array.length; i++) {
Expand All @@ -452,7 +452,7 @@ gn.indexOf = function (array, item) {
return -1;
};
// get supported property
// @require "/src/gn/base.js"
// @require "/src/gn/gn.js"

gn.getSupportedProp = function (proparray){
var root = document.documentElement;
Expand All @@ -466,7 +466,7 @@ gn.getSupportedProp = function (proparray){
// var getTD = gn.getSupportedProp(['transitionDuration', 'WebkitTransitionDuration', 'MozTransitionDuration', 'OTransitionDuration']),
// getTransform = gn.getSupportedProp(['transform', 'WebkitTransform', 'MozTransform', 'OTransform']);
// DOM ready
// @require "/src/gn/base.js"
// @require "/src/gn/gn.js"

gn.ready = function ( fn ) {

Expand All @@ -482,15 +482,15 @@ gn.ready = function ( fn ) {
document.addEventListener( 'DOMContentLoaded', fn, false );
};
// isNodeList
// @require "/src/gn/base.js"
// @require "/src/gn/gn.js"

gn.isNodeList = function (el) {
// Only NodeList has the "item()" function
return typeof el.item !== 'undefined';
};

// append
// @require "/src/gn/base.js"
// @require "/src/gn/gn.js"
// @require "/src/gn/isNodeList.js"

gn.append = function(els, data) {
Expand All @@ -517,7 +517,7 @@ gn.append = function(els, data) {


// wrap
// @require "/src/gn/base.js"
// @require "/src/gn/gn.js"
// @require "/src/gn/isNodeList.js"

gn.wrap = function (els, obj) {
Expand Down Expand Up @@ -548,7 +548,7 @@ gn.wrap = function (els, obj) {


// unwrap
// @require "/src/gn/base.js"
// @require "/src/gn/gn.js"
// @require "/src/gn/isNodeList.js"

gn.unwrap = function (els) {
Expand Down Expand Up @@ -869,6 +869,7 @@ var tinySlider = (function () {
for (var j = navCountVisible; j < slideCount; j++) {
_setAttrs(allNavs[j], {'hidden': ''});
}
navCountVisibleCached = navCountVisible;
}
}

Expand Down Expand Up @@ -1007,6 +1008,7 @@ var tinySlider = (function () {
autoplayInit();
activateSlider();
addSliderEvents();
checkSlideCount();

lazyLoad();
runAutoHeight();
Expand All @@ -1017,19 +1019,19 @@ var tinySlider = (function () {
nav = controls = autoplay = loop = rewind = false;
index = 0;

hideElement(navContainer);
hideElement(controlsContainer);
hideElement(autoplayButton);
if (navContainer) { _hideElement(navContainer); }
if (controlsContainer) { _hideElement(controlsContainer); }
if (autoplayButton) { _hideElement(autoplayButton); }
} else {
nav = options.nav;
controls = options.controls;
autoplay = options.autoplay;
loop = (options.rewind) ? false : options.loop;
rewind = options.rewind;

if (nav) { showElement(navContainer); }
if (controls) { showElement(controlsContainer); }
if (autoplay) { showElement(autoplayButton); }
if (nav) { _showElement(navContainer); }
if (controls) { _showElement(controlsContainer); }
if (autoplay) { _showElement(autoplayButton); }
}
}

Expand Down Expand Up @@ -1079,18 +1081,20 @@ var tinySlider = (function () {

// update slide
function updateSlideStatus() {
var h1, h2, v1, v2, currentCached = current || cloneCount + slideCount;
var h1, h2, v1, v2, currentCached = current;
current = getCurrent();
if (current > currentCached) {
h1 = currentCached;
h2 = Math.min(currentCached + items, current);
v1 = Math.max(currentCached + items, current);
v2 = current + items;
} else if (current < currentCached) {
h1 = Math.max(current + items, currentCached);
h2 = currentCached + items;
v1 = current;
v2 = Math.min(current + items, currentCached);
if (current !== currentCached) {
if (current > currentCached) {
h1 = currentCached;
h2 = Math.min(currentCached + items, current);
v1 = Math.max(currentCached + items, current);
v2 = current + items;
} else {
h1 = Math.max(current + items, currentCached);
h2 = currentCached + items;
v1 = current;
v2 = Math.min(current + items, currentCached);
}
}

if (slideBy%1 !== 0) {
Expand Down Expand Up @@ -1590,7 +1594,8 @@ var tinySlider = (function () {
window.removeEventListener('scroll', onScroll, false);
},
// $ Private methods, for test only
hasAttr: _hasAttr, getAttr: _getAttr, setAttrs: _setAttrs, removeAttrs: _removeAttrs, removeEvents: _removeEvents, getSliderId: _getSliderId, toDegree: _toDegree, getPanDirection: _getPanDirection, nextButton: function () { return nextButton; }, index: function () { return index; },
hasAttr: _hasAttr, getAttr: _getAttr, setAttrs: _setAttrs, removeAttrs: _removeAttrs, removeEvents: _removeEvents, getSliderId: _getSliderId, toDegree: _toDegree, getPanDirection: _getPanDirection, hideElement: _hideElement, showElement: _showElement,
nextButton: function () { return nextButton; }, index: function () { return index; },
};
}

Expand Down Expand Up @@ -1656,21 +1661,13 @@ var tinySlider = (function () {
el = null;
}

function hideElement(el) {
if (el.nodeType !== 1) {
throw 'el is not a element node.';
// return;
}
function _hideElement(el) {
if (!_hasAttr(el, 'hidden')) {
_setAttrs(el, {'hidden': ''});
}
}

function showElement(el) {
if (el.nodeType !== 1) {
throw 'el is not a element node.';
// return;
}
function _showElement(el) {
if (_hasAttr(el, 'hidden')) {
_removeAttrs(el, 'hidden');
}
Expand Down
53 changes: 25 additions & 28 deletions dist/tiny-slider.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ var tinySlider = (function () {
for (var j = navCountVisible; j < slideCount; j++) {
_setAttrs(allNavs[j], {'hidden': ''});
}
navCountVisibleCached = navCountVisible;
}
}

Expand Down Expand Up @@ -437,6 +438,7 @@ var tinySlider = (function () {
autoplayInit();
activateSlider();
addSliderEvents();
checkSlideCount();

lazyLoad();
runAutoHeight();
Expand All @@ -447,19 +449,19 @@ var tinySlider = (function () {
nav = controls = autoplay = loop = rewind = false;
index = 0;

hideElement(navContainer);
hideElement(controlsContainer);
hideElement(autoplayButton);
if (navContainer) { _hideElement(navContainer); }
if (controlsContainer) { _hideElement(controlsContainer); }
if (autoplayButton) { _hideElement(autoplayButton); }
} else {
nav = options.nav;
controls = options.controls;
autoplay = options.autoplay;
loop = (options.rewind) ? false : options.loop;
rewind = options.rewind;

if (nav) { showElement(navContainer); }
if (controls) { showElement(controlsContainer); }
if (autoplay) { showElement(autoplayButton); }
if (nav) { _showElement(navContainer); }
if (controls) { _showElement(controlsContainer); }
if (autoplay) { _showElement(autoplayButton); }
}
}

Expand Down Expand Up @@ -509,18 +511,20 @@ var tinySlider = (function () {

// update slide
function updateSlideStatus() {
var h1, h2, v1, v2, currentCached = current || cloneCount + slideCount;
var h1, h2, v1, v2, currentCached = current;
current = getCurrent();
if (current > currentCached) {
h1 = currentCached;
h2 = Math.min(currentCached + items, current);
v1 = Math.max(currentCached + items, current);
v2 = current + items;
} else if (current < currentCached) {
h1 = Math.max(current + items, currentCached);
h2 = currentCached + items;
v1 = current;
v2 = Math.min(current + items, currentCached);
if (current !== currentCached) {
if (current > currentCached) {
h1 = currentCached;
h2 = Math.min(currentCached + items, current);
v1 = Math.max(currentCached + items, current);
v2 = current + items;
} else {
h1 = Math.max(current + items, currentCached);
h2 = currentCached + items;
v1 = current;
v2 = Math.min(current + items, currentCached);
}
}

if (slideBy%1 !== 0) {
Expand Down Expand Up @@ -1020,7 +1024,8 @@ var tinySlider = (function () {
window.removeEventListener('scroll', onScroll, false);
},
// $ Private methods, for test only
hasAttr: _hasAttr, getAttr: _getAttr, setAttrs: _setAttrs, removeAttrs: _removeAttrs, removeEvents: _removeEvents, getSliderId: _getSliderId, toDegree: _toDegree, getPanDirection: _getPanDirection, nextButton: function () { return nextButton; }, index: function () { return index; },
hasAttr: _hasAttr, getAttr: _getAttr, setAttrs: _setAttrs, removeAttrs: _removeAttrs, removeEvents: _removeEvents, getSliderId: _getSliderId, toDegree: _toDegree, getPanDirection: _getPanDirection, hideElement: _hideElement, showElement: _showElement,
nextButton: function () { return nextButton; }, index: function () { return index; },
};
}

Expand Down Expand Up @@ -1086,21 +1091,13 @@ var tinySlider = (function () {
el = null;
}

function hideElement(el) {
if (el.nodeType !== 1) {
throw 'el is not a element node.';
// return;
}
function _hideElement(el) {
if (!_hasAttr(el, 'hidden')) {
_setAttrs(el, {'hidden': ''});
}
}

function showElement(el) {
if (el.nodeType !== 1) {
throw 'el is not a element node.';
// return;
}
function _showElement(el) {
if (_hasAttr(el, 'hidden')) {
_removeAttrs(el, 'hidden');
}
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var config = {

watch: {
js: 'src/**/*.js',
html: ['**/*.html', 'tests/js/*.js']
html: ['**/*.html', 'tests/**/*.js']
},

js: {
Expand Down
25 changes: 0 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,6 @@
"main": "dist/tiny-slider.js",
"style": "dist/tiny-slider.css",
"sass": "src/tiny-slider.scss",
"devDependencies": {
"browser-sync": "^2.14.0",
"gulp": "^3.9.1",
"gulp-batch": "^1.0.5",
"gulp-colorize-svgs": "git+https://git@github.com/unic/gulp-colorize-svgs.git",
"gulp-concat": "^2.6.0",
"gulp-connect-php": "0.0.8",
"gulp-imagemin": "^3.0.2",
"gulp-inject": "^4.1.0",
"gulp-jshint": "^2.0.1",
"gulp-modernizr": "^1.0.0-alpha",
"gulp-plumber": "^1.1.0",
"gulp-rename": "^1.2.2",
"gulp-ruby-sass": "^2.1.0",
"gulp-sass": "^2.3.2",
"gulp-sourcemaps": "^1.6.0",
"gulp-svg2png": "^2.0.0",
"gulp-svgmin": "^1.2.2",
"gulp-svgstore": "^6.0.0",
"gulp-uglify": "^2.0.0",
"jshint": "^2.9.3",
"jshint-stylish": "^2.2.1",
"merge-stream": "^1.0.0",
"gulp-nightwatch": "^0.3.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
Loading

0 comments on commit e2936fc

Please sign in to comment.