Created
February 10, 2014 07:59
-
-
Save YusukeHirao/8912015 to your computer and use it in GitHub Desktop.
WAI ARIAに準じたインターフェイスを実装するためのjQueryプラグイン。
「role=button」編
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.roleButton = function () { | |
return this.each(function (method) { | |
var $this, | |
isPressed; | |
function updatePressed () { | |
$this.attr('area-pressed', isPressed); | |
} | |
function changePressed () { | |
isPressed = !isPressed; | |
updatePressed(); | |
} | |
$this = $(this); | |
if ($this.data('is-role-button-instance')) { | |
isPressed = $this.attr('area-pressed') === 'true'; | |
$this.data('is-role-button-instance', true); | |
switch (method) { | |
default: | |
return isPressed; | |
} | |
} else { | |
$this.attr('role', 'button'); | |
if (!$this.attr('tabindex')) { | |
$this.attr('tabindex', 0); | |
} | |
isPressed = $this.attr('area-pressed') === 'true'; | |
$this.on('click keyup', function () { | |
$this.trigger('press', isPressed); | |
return; | |
}); | |
$this.on('press', function () { | |
changePressed(); | |
return true; | |
}); | |
updatePressed(); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment