Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 9897658

Browse files
author
Marco Rieser
committed
Refactoring and build process
1 parent 507615d commit 9897658

19 files changed

+3648
-10515
lines changed

.gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.idea
2-
.vagrant
3-
atlassian-ide-plugin.xml
4-
Vagrantfile
2+
node_modules
3+
src/lib
4+
src/scss/*.css

LICENSE

-20
This file was deleted.

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ Installation
2626
</ul>
2727
</nav>
2828

29-
<!-- 2. Include libraries -->
29+
<!-- 2. Include jQuery -->
3030
<script src="../lib/jquery.js" type="text/javascript"></script>
31-
<script src="../lib/jquery.ui.widget.js" type="text/javascript"></script>
3231

3332
<!-- 3. Include widget -->
3433
<script src="../src/jquery.dcd.doubletaptogo.js" type="text/javascript"></script>
@@ -50,6 +49,11 @@ Options
5049

5150
Changelog
5251
============
52+
3.0.0 Refactor to jQuery Plugin
53+
-----------------
54+
* removed dependency for jQuery Widget Factory
55+
* Bugfixes
56+
5357
2.0.1 Bugfixes
5458
-----------------
5559
* added selector chain

bower.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"name": "jquery-double-tap-to-go",
3-
"version": "2.0.1",
3+
"version": "3.0.0",
44
"main": [
5-
"src/jquery.dcd.doubletaptogo.js"
5+
"dist/jquery.dcd.doubletaptogo.min.js"
66
],
77
"dependencies": {
8-
"jquery": ">=1.6",
9-
"jquery-ui": ">=1.10"
8+
"jquery": ">=3.1.1"
109
}
11-
}
10+
}

demo/index.html

-58
This file was deleted.

dist/jquery.dcd.doubletaptogo.js

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
Original Plugin by Osvaldas Valutis, www.osvaldas.info
3+
http://osvaldas.info/drop-down-navigation-responsive-and-touch-friendly
4+
Available for use under the MIT License
5+
*/
6+
/**
7+
* jquery-doubleTapToGo plugin
8+
* Copyright 2017 DACHCOM.DIGITAL AG
9+
* @author Marco Rieser
10+
* @author Volker Andres
11+
* @author Stefan Hagspiel
12+
* @version 3.0.0
13+
* @see https://github.com/dachcom-digital/jquery-doubleTapToGo
14+
*/
15+
(function ($, window, document, undefined) {
16+
'use strict';
17+
var pluginName = 'doubleTapToGo',
18+
defaults = {
19+
automatic: true,
20+
selectorClass: 'doubletap',
21+
selectorChain: 'li:has(ul)'
22+
};
23+
24+
function DoubleTapToGo (element, options) {
25+
this.element = element;
26+
this.settings = $.extend({}, defaults, options);
27+
this._defaults = defaults;
28+
this._name = pluginName;
29+
this.init();
30+
}
31+
32+
$.extend(DoubleTapToGo.prototype, {
33+
preventClick: false,
34+
currentTap: $(),
35+
init: function () {
36+
var self = this;
37+
38+
if (window.ontouchstart === undefined && !window.navigator.msMaxTouchPoints && !window.navigator.userAgent.toLowerCase().match(/windows phone os 7/i)) {
39+
return;
40+
}
41+
42+
if (window.navigator.msPointerEnabled) {
43+
$(this.element).get(0).addEventListener('MSPointerDown', self._tap.bind(self), false);
44+
} else if (window.navigator.pointerEnabled) {
45+
$(this.element).get(0).addEventListener('pointerdown', self._tap.bind(self), false);
46+
}
47+
48+
$(this.element)
49+
.on('click', '.' + this.settings.selectorClass, this._click.bind(this))
50+
.on('touchstart', '.' + this.settings.selectorClass, this._tap.bind(this))
51+
.on('remove', this._destroy.bind(this));
52+
53+
this._addSelectors();
54+
},
55+
56+
_addSelectors: function () {
57+
if (this.settings.automatic !== true) {
58+
return;
59+
}
60+
$(this.element)
61+
.find(this.settings.selectorChain)
62+
.addClass(this.settings.selectorClass);
63+
},
64+
65+
_click: function (event) {
66+
if (this.preventClick) {
67+
event.preventDefault();
68+
} else {
69+
this.currentTap = $();
70+
}
71+
},
72+
73+
_tap: function (event) {
74+
var $target = $(event.target).closest('li');
75+
if (!$target.hasClass(this.settings.selectorClass)) {
76+
this.preventClick = false;
77+
return;
78+
}
79+
if ($target.get(0) === this.currentTap.get(0)) {
80+
this.preventClick = false;
81+
return;
82+
}
83+
this.preventClick = true;
84+
this.currentTap = $target;
85+
event.stopPropagation();
86+
},
87+
88+
_destroy: function () {
89+
$(this.element).off();
90+
if (window.navigator.msPointerEnabled) {
91+
$(this.element).get(0).removeEventListener('MSPointerDown', this._tap);
92+
}
93+
if (window.navigator.pointerEnabled) {
94+
$(this.element).get(0).removeEventListener('pointerdown', this._tap);
95+
}
96+
},
97+
98+
reset: function () {
99+
this.currentTap = $();
100+
}
101+
});
102+
103+
$.fn[pluginName] = function (options) {
104+
var args = arguments,
105+
returns;
106+
if (options === undefined || typeof options === 'object') {
107+
return this.each(function () {
108+
if (!$.data(this, pluginName)) {
109+
$.data(this, pluginName, new DoubleTapToGo(this, options));
110+
}
111+
});
112+
} else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
113+
this.each(function () {
114+
var instance = $.data(this, pluginName),
115+
methodName = (options === 'destroy' ? '_destroy' : options);
116+
if (instance instanceof DoubleTapToGo && typeof instance[methodName] === 'function') {
117+
returns = instance[methodName].apply(instance, Array.prototype.slice.call(args, 1));
118+
}
119+
if (options === 'destroy') {
120+
$.data(this, pluginName, null);
121+
}
122+
});
123+
return returns !== undefined ? returns : this;
124+
}
125+
};
126+
})(jQuery, window, document);

dist/jquery.dcd.doubletaptogo.min.js

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*eslint-env node*/
2+
'use strict';
3+
4+
var gulp = require('gulp'),
5+
sass = require('gulp-sass'),
6+
rename = require('gulp-rename'),
7+
prefixer = require('gulp-autoprefixer'),
8+
uglify = require('gulp-uglify'),
9+
browserSync = require('browser-sync').create(),
10+
11+
input = {
12+
sass: [
13+
'src/**/*.scss'
14+
]
15+
};
16+
17+
gulp.task('default', ['watch']);
18+
19+
gulp.task('build', function () {
20+
gulp.src('src/js/jquery.dcd.doubletaptogo.js')
21+
.pipe(uglify({
22+
preserveComments: 'license'
23+
}))
24+
.pipe(rename({
25+
suffix: '.min'
26+
}))
27+
.pipe(gulp.dest('dist'));
28+
29+
gulp.src('src/js/jquery.dcd.doubletaptogo.js').pipe(gulp.dest('dist'));
30+
});
31+
32+
gulp.task('css', function () {
33+
gulp.src(input.sass)
34+
.pipe(sass({outputStyle: 'compressed'}))
35+
.pipe(prefixer('last 2 version'))
36+
.pipe(gulp.dest(function (file) {
37+
return file.base;
38+
}));
39+
});
40+
41+
gulp.task('watch', ['prepare', 'serve'], function () {
42+
gulp.watch(input.sass, ['css']);
43+
});
44+
45+
gulp.task('serve', function () {
46+
browserSync.init(
47+
{
48+
notify: false,
49+
logLevel: 'info',
50+
logConnections: false,
51+
logFileChanges: false,
52+
injectChanges: true,
53+
files: ['./**/*.{html,htm,css,js}'],
54+
watchOptions: {
55+
ignored: 'node_modules'
56+
},
57+
server: {
58+
baseDir: './src/'
59+
}
60+
}
61+
);
62+
});
63+
64+
gulp.task('prepare', ['css'], function () {
65+
gulp.src('node_modules/jquery/dist/jquery.min.js')
66+
.pipe(gulp.dest('src/lib/'));
67+
});

0 commit comments

Comments
 (0)