Skip to content

Commit

Permalink
switch.js 수정 > click 이벤트 적용 및 이벤트 네이밍 제안
Browse files Browse the repository at this point in the history
  • Loading branch information
kieregh committed Aug 21, 2016
1 parent 6dfc91f commit 426d467
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions js/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
var distanceX = false;
var toggle = false;
var transformProperty = window.RATCHET.getBrowserCapabilities.transform;
var supportsTouch = false;
if ('ontouchstart' in window) supportsTouch = true; //iOS & android
else if(window.navigator.msPointerEnabled) supportsTouch = true; //Win8

var findToggle = function (target) {
var i;
Expand Down Expand Up @@ -88,7 +91,8 @@
toggle.classList[(distanceX > (toggleWidth / 2 - handleWidth / 2)) ? 'add' : 'remove']('active');
});

window.addEventListener('touchend', function (e) {
function touchend(e){

if (!toggle) {
return;
}
Expand All @@ -107,11 +111,23 @@

toggle.classList[slideOn ? 'add' : 'remove']('active');

e = $.Event('checked.rc.switch', { relatedTarget: handle})
e = $.Event('changed.rc.switch', { relatedTarget: handle})
$(toggle).trigger(e);

touchMove = false;
toggle = false;
}
window.addEventListener('touchend', function(e){
touchend(e);
});

function mouseHandler(e)
{
e = e.originalEvent || e;
toggle = findToggle(e.target);
touchend(e);
}

if(supportsTouch===false) window.addEventListener("click", mouseHandler, true);

}(jQuery));

0 comments on commit 426d467

Please sign in to comment.