Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jQuery plugin #7

Closed
dhoko opened this issue Jul 8, 2016 · 1 comment
Closed

jQuery plugin #7

dhoko opened this issue Jul 8, 2016 · 1 comment

Comments

@dhoko
Copy link
Contributor

dhoko commented Jul 8, 2016

To be able to do:

$('button').accessibleSimpleTooltipAria({
  simpletooltipText: 'test'
});

Ex:

$.fn.accessibleSimpleTooltipAria = function (options) {

    var element = $(this);
    var $tooltip_text = options.simpletooltipText || '',
    $tooltip_prefix_class = typeof options.simpletooltipPrefixClass !== 'undefined' ? options.simpletooltipPrefixClass + '-' : '',
    $tooltip_content_id = typeof options.simpletooltipContentId !== 'undefined' ? '#' + options.simpletooltipContentId : '',
    $tooltip_code;

    var index_lisible = Math.random().toString(32).slice(2, 12);

    element.attr({
        'aria-describedby' : 'label_simpletooltip_' + index_lisible
        });

    element.wrap( '<span class="' + $tooltip_prefix_class + 'simpletooltip_container"></span>' );

    $tooltip_code = '<span class="js-simpletooltip ' + $tooltip_prefix_class + 'simpletooltip" id="label_simpletooltip_' + index_lisible + '" role="tooltip" aria-hidden="true">';
    if ( $tooltip_text !== '' ) {
       $tooltip_code += '' + $tooltip_text + '';
       }
       else {
            if ( $tooltip_content_id !== '' && $($tooltip_content_id).length ) {
                $tooltip_code += $($tooltip_content_id).html();
                }
            }
    $tooltip_code += '</span>';

    $( $tooltip_code ).insertAfter(element);

  };
@nico3333fr
Copy link
Owner

Thanks to your PR, it is made ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants