onopko
7/7/2016 - 3:22 AM

touchhover

;(function($) {
    'use strict';

    $.fn.extend({
    	touchhover: function(_enterFunction, _leaveFunction) {
            var is_touch = 'ontouchstart' in document.documentElement;

            if (is_touch) {
                return this
                    .on('touchstart', function () {
                        if (_enterFunction) _enterFunction();
                    })
                    .on('touchend', function () {
                        if (_leaveFunction) _leaveFunction();
                    });
            }
            else {
                return this
                    .on('mouseenter', function () {
                        if (_enterFunction) _enterFunction();
                    })
                    .on('mouseleave', function () {
                        if (_leaveFunction) _leaveFunction();
                    });
            }

            is_touch = void 0;
    	}
    });
})(jQuery);