common.js
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var FastClick = require('fastclick');
window.addEventListener('load', function() {
var textInput = document.querySelector('input');
FastClick.attach(document.body);
Array.prototype.forEach.call(document.getElementsByClassName('test'), function(testEl) {
testEl.addEventListener('click', function() {
textInput.focus();
}, false)
});
}, false);
// var $ = require('jquery');
var Common = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
var _this = this;
//input框 clear button
$(document).on('input', '.m-input-wrap .m-input', function() {
var val = $(this).val();
var isEmpety = !/^.+$/.test(val);
$(this).siblings('.clear-btn').toggleClass('m-hidden', isEmpety);
}).on('touchend', '.m-input-wrap .clear-btn', function(e) {
e.preventDefault();
$(this).addClass('m-hidden').siblings('.m-input').val('').focus();
});
//network status
// $(window).on('online offline', function(){
// _this.online();
// });
},
online:function(){
$('.m-tips').toggleClass('animate', !navigator.onLine).text('当前没有网络信号');
setTimeout(function(){
}, 3000);
}
};
if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
// AMD. Register as an anonymous module.
define(function() {
return Common;
});
} else if (typeof module !== 'undefined' && module.exports) {
module.exports = Common;
} else {
window.Common = Common;
}