123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- (function($) {
- "use strict";
- var uniqueId = function(prefix) {
- return (prefix || 'ui-id') + '-' + Math.floor((Math.random()*1000)+1)
- }
-
-
- $('.alert').attr('role', 'alert')
- $('.close').removeAttr('aria-hidden').wrapInner('<span aria-hidden="true"></span>').append('<span class="sr-only">Fermer</span>')
-
-
- var showTooltip = $.fn.tooltip.Constructor.prototype.show
- , hideTooltip = $.fn.tooltip.Constructor.prototype.hide
- $.fn.tooltip.Constructor.prototype.show = function () {
- showTooltip.apply(this, arguments)
- var $tip = this.tip()
- , tooltipID = $tip.attr('id') || uniqueId('ui-tooltip')
- $tip.attr({'role':'tooltip','id' : tooltipID})
- this.$element.attr('aria-describedby', tooltipID)
- }
- $.fn.tooltip.Constructor.prototype.hide = function () {
- hideTooltip.apply(this, arguments)
- removeMultiValAttributes(this.$element, 'aria-describedby', this.tip().attr('id'))
- return this
- }
-
-
- var showPopover = $.fn.popover.Constructor.prototype.setContent
- , hideTPopover = $.fn.popover.Constructor.prototype.hide
- $.fn.popover.Constructor.prototype.setContent = function(){
- showPopover.apply(this, arguments)
- var $tip = this.tip()
- , tooltipID = $tip.attr('id') || uniqueId('ui-tooltip')
- $tip.attr({'role':'alert','id' : tooltipID})
- this.$element.attr('aria-describedby', tooltipID)
- this.$element.focus()
- }
- $.fn.popover.Constructor.prototype.hide = function(){
- hideTooltip.apply(this, arguments)
- removeMultiValAttributes(this.$element, 'aria-describedby', this.tip().attr('id'))
- }
-
- $('.modal-dialog').attr( {'role' : 'document'})
- var modalhide = $.fn.modal.Constructor.prototype.hide
- $.fn.modal.Constructor.prototype.hide = function(){
- var modalOpener = this.$element.parent().find('[data-target="#' + this.$element.attr('id') + '"]')
- modalhide.apply(this, arguments)
- modalOpener.focus()
- }
-
-
- var toggle = '[data-toggle=dropdown]'
- , $par
- , firstItem
- , focusDelay = 200
- , menus = $(toggle).parent().find('ul').attr('role','menu')
- , lis = menus.find('li').attr('role','presentation')
- lis.find('a').attr({'role':'menuitem', 'tabIndex':'-1'})
- $(toggle).attr({ 'aria-haspopup':'true', 'aria-expanded': 'false'})
- $(toggle).parent().on('shown.bs.dropdown',function(e){
- $par = $(this)
- var $toggle = $par.find(toggle)
- $toggle.attr('aria-expanded','true')
- setTimeout(function(){
- firstItem = $('.dropdown-menu [role=menuitem]:visible', $par)[0]
- try{ firstItem.focus()} catch(ex) {}
- }, focusDelay)
- })
- $(toggle).parent().on('hidden.bs.dropdown',function(e){
- $par = $(this)
- var $toggle = $par.find(toggle)
- $toggle.attr('aria-expanded','false')
- })
-
- $.fn.dropdown.Constructor.prototype.keydown = function (e) {
- var $par
- , firstItem
- if (!/(32)/.test(e.keyCode)) return
- $par = $(this).parent()
- $(this).trigger ("click")
- e.preventDefault() && e.stopPropagation()
- }
- $(document)
- .on('focusout.dropdown.data-api', '.dropdown-menu', function(e){
- var $this = $(this)
- , that = this
- setTimeout(function() {
- if(!$.contains(that, document.activeElement)){
- $this.parent().removeClass('open')
- $this.parent().find('[data-toggle=dropdown]').attr('aria-expanded','false')
- }
- }, 150)
- })
- .on('keydown.bs.dropdown.data-api', toggle + ', [role=menu]' , $.fn.dropdown.Constructor.prototype.keydown)
-
-
- var $tablist = $('.nav-tabs')
- , $lis = $tablist.children('li')
- , $tabs = $tablist.find('[data-toggle="tab"], [data-toggle="pill"]')
- $tablist.attr('role', 'tablist')
- $lis.attr('role', 'presentation')
- $tabs.attr('role', 'tab')
- $tabs.each(function( index ) {
- var tabpanel = $($(this).attr('href'))
- , tab = $(this)
- , tabid = tab.attr('id') || uniqueId('ui-tab')
- tab.attr('id', tabid)
- if(tab.parent().hasClass('active')){
- tab.attr( { 'tabIndex' : '0', 'aria-selected' : 'true', 'aria-controls': tab.attr('href').substr(1) } )
- tabpanel.attr({ 'role' : 'tabpanel', 'tabIndex' : '0', 'aria-hidden' : 'false', 'aria-labelledby':tabid })
- }else{
- tab.attr( { 'tabIndex' : '-1', 'aria-selected' : 'false', 'aria-controls': tab.attr('href').substr(1) } )
- tabpanel.attr( { 'role' : 'tabpanel', 'tabIndex' : '-1', 'aria-hidden' : 'true', 'aria-labelledby':tabid } )
- }
- })
- $.fn.tab.Constructor.prototype.keydown = function (e) {
- var $this = $(this)
- , $items
- , $ul = $this.closest('ul[role=tablist] ')
- , index
- , k = e.which || e.keyCode
- $this = $(this)
- if (!/(37|38|39|40)/.test(k)) return
- $items = $ul.find('[role=tab]:visible')
- index = $items.index($items.filter(':focus'))
- if (k == 38 || k == 37) index--
- if (k == 39 || k == 40) index++
- if(index < 0) index = $items.length -1
- if(index == $items.length) index = 0
- var nextTab = $items.eq(index)
- if(nextTab.attr('role') ==='tab'){
- nextTab.tab('show')
- .focus()
- }
-
- e.preventDefault()
- e.stopPropagation()
- }
- $(document).on('keydown.tab.data-api','[data-toggle="tab"], [data-toggle="pill"]' , $.fn.tab.Constructor.prototype.keydown)
- var tabactivate = $.fn.tab.Constructor.prototype.activate;
- $.fn.tab.Constructor.prototype.activate = function (element, container, callback) {
- var $active = container.find('> .active')
- $active.find('[data-toggle=tab]').attr({ 'tabIndex' : '-1','aria-selected' : false })
- $active.filter('.tab-pane').attr({ 'aria-hidden' : true,'tabIndex' : '-1' })
- tabactivate.apply(this, arguments)
- element.addClass('active')
- element.find('[data-toggle=tab]').attr({ 'tabIndex' : '0','aria-selected' : true })
- element.filter('.tab-pane').attr({ 'aria-hidden' : false,'tabIndex' : '0' })
- }
-
-
- var $colltabs = $('[data-toggle="collapse"]')
- $colltabs.attr({ 'role':'tab', 'aria-selected':'false', 'aria-expanded':'false' })
- $colltabs.each(function( index ) {
- var colltab = $(this)
- , collpanel = (colltab.attr('data-target')) ? $(colltab.attr('data-target')) : $(colltab.attr('href'))
- , parent = colltab.attr('data-parent')
- , collparent = parent && $(parent)
- , collid = colltab.attr('id') || uniqueId('ui-collapse')
- $(collparent).find('div:not(.collapse,.panel-body), h4').attr('role','presentation')
- colltab.attr('id', collid)
- if(collparent){
- collparent.attr({ 'role' : 'tablist', 'aria-multiselectable' : 'true' })
- if(collpanel.hasClass('in')){
- colltab.attr({ 'aria-controls': colltab.attr('href').substr(1), 'aria-selected':'true', 'aria-expanded':'true', 'tabindex':'0' })
- collpanel.attr({ 'role':'tabpanel', 'tabindex':'0', 'aria-labelledby':collid, 'aria-hidden':'false' })
- }else{
- colltab.attr({'aria-controls' : colltab.attr('href').substr(1), 'tabindex':'-1' })
- collpanel.attr({ 'role':'tabpanel', 'tabindex':'-1', 'aria-labelledby':collid, 'aria-hidden':'true' })
- }
- }
- })
- var collToggle = $.fn.collapse.Constructor.prototype.toggle
- $.fn.collapse.Constructor.prototype.toggle = function(){
- var prevTab = this.$parent && this.$parent.find('[aria-expanded="true"]') , href
- if(prevTab){
- var prevPanel = prevTab.attr('data-target') || (href = prevTab.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')
- , $prevPanel = $(prevPanel)
- , $curPanel = this.$element
- , par = this.$parent
- , curTab
- if (this.$parent) curTab = this.$parent.find('[data-toggle=collapse][href="#' + this.$element.attr('id') + '"]')
- collToggle.apply(this, arguments)
- if ($.support.transition) {
- this.$element.one($.support.transition.end, function(){
- prevTab.attr({ 'aria-selected':'false','aria-expanded':'false', 'tabIndex':'-1' })
- $prevPanel.attr({ 'aria-hidden' : 'true','tabIndex' : '-1'})
- curTab.attr({ 'aria-selected':'true','aria-expanded':'true', 'tabIndex':'0' })
- if($curPanel.hasClass('in')){
- $curPanel.attr({ 'aria-hidden' : 'false','tabIndex' : '0' })
- }else{
- curTab.attr({ 'aria-selected':'false','aria-expanded':'false'})
- $curPanel.attr({ 'aria-hidden' : 'true','tabIndex' : '-1' })
- }
- })
- }
- }else{
- collToggle.apply(this, arguments)
- }
- }
- $.fn.collapse.Constructor.prototype.keydown = function (e) {
- var $this = $(this)
- , $items
- , $tablist = $this.closest('div[role=tablist] ')
- , index
- , k = e.which || e.keyCode
- $this = $(this)
- if (!/(32|37|38|39|40)/.test(k)) return
- if(k==32) $this.click()
- $items = $tablist.find('[role=tab]')
- index = $items.index($items.filter(':focus'))
- if (k == 38 || k == 37) index--
- if (k == 39 || k == 40) index++
- if(index < 0) index = $items.length -1
- if(index == $items.length) index = 0
- $items.eq(index).focus()
- e.preventDefault()
- e.stopPropagation()
- }
- $(document).on('keydown.collapse.data-api','[data-toggle="collapse"]' , $.fn.collapse.Constructor.prototype.keydown)
-
-
- $('.carousel').each(function (index) {
- var $this = $(this)
- , prev = $this.find('[data-slide="prev"]')
- , next = $this.find('[data-slide="next"]')
- , $options = $this.find('.item')
- , $listbox = $options.parent()
- $this.attr( { 'data-interval' : 'false', 'data-wrap' : 'false' } )
- $listbox.attr('role', 'listbox')
- $options.attr('role', 'option')
- var spanPrev = document.createElement('span')
- spanPrev.setAttribute('class', 'sr-only')
- spanPrev.innerHTML='Previous'
- var spanNext = document.createElement('span')
- spanNext.setAttribute('class', 'sr-only')
- spanNext.innerHTML='Next'
- prev.attr('role', 'button')
- next.attr('role', 'button')
- prev.append(spanPrev)
- next.append(spanNext)
- $options.each(function () {
- var item = $(this)
- if(item.hasClass('active')){
- item.attr({ 'aria-selected': 'true', 'tabindex' : '0' })
- }else{
- item.attr({ 'aria-selected': 'false', 'tabindex' : '-1' })
- }
- })
- })
- var slideCarousel = $.fn.carousel.Constructor.prototype.slide
- $.fn.carousel.Constructor.prototype.slide = function (type, next) {
- var $active = this.$element.find('.item.active')
- , $next = next || $active[type]()
- slideCarousel.apply(this, arguments)
- $active
- .one($.support.transition.end, function () {
- $active.attr({'aria-selected':false, 'tabIndex': '-1'})
- $next.attr({'aria-selected':true, 'tabIndex': '0'})
-
- })
- }
- $.fn.carousel.Constructor.prototype.keydown = function (e) {
- var $this = $(this)
- , $ul = $this.closest('div[role=listbox]')
- , $items = $ul.find('[role=option]')
- , $parent = $ul.parent()
- , k = e.which || e.keyCode
- , index
- , i
- if (!/(37|38|39|40)/.test(k)) return
- index = $items.index($items.filter('.active'))
- if (k == 37 || k == 38) {
- $parent.carousel('prev')
- index--
- if(index < 0) index = $items.length -1
- else $this.prev().focus()
- }
- if (k == 39 || k == 40) {
- $parent.carousel('next')
- index++
- if(index == $items.length) index = 0
- else {
- $this.one($.support.transition.end, function () {
- $this.next().focus()
- })
- }
- }
- e.preventDefault()
- e.stopPropagation()
- }
- $(document).on('keydown.carousel.data-api', 'div[role=option]', $.fn.carousel.Constructor.prototype.keydown)
-
-
- var removeMultiValAttributes = function (el, attr, val) {
- var describedby = (el.attr( attr ) || "").split( /\s+/ )
- , index = $.inArray(val, describedby)
- if ( index !== -1 ) {
- describedby.splice( index, 1 )
- }
- describedby = $.trim( describedby.join( " " ) )
- if (describedby ) {
- el.attr( attr, describedby )
- } else {
- el.removeAttr( attr )
- }
- }
- })(jQuery);
|