common.js 1.6 KB
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;
}