UNPKG

1.41 kBJavaScriptView Raw
1"use strict";
2
3import $ from 'jquery';
4
5// Core Foundation Utilities, utilized in a number of places.
6
7 /**
8 * Returns a boolean for RTL support
9 */
10function rtl() {
11 return $('html').attr('dir') === 'rtl';
12}
13
14/**
15 * returns a random base-36 uid with namespacing
16 * @function
17 * @param {Number} length - number of random base-36 digits desired. Increase for more random strings.
18 * @param {String} namespace - name of plugin to be incorporated in uid, optional.
19 * @default {String} '' - if no plugin name is provided, nothing is appended to the uid.
20 * @returns {String} - unique id
21 */
22function GetYoDigits(length, namespace){
23 length = length || 6;
24 return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1) + (namespace ? `-${namespace}` : '');
25}
26
27function transitionend($elem){
28 var transitions = {
29 'transition': 'transitionend',
30 'WebkitTransition': 'webkitTransitionEnd',
31 'MozTransition': 'transitionend',
32 'OTransition': 'otransitionend'
33 };
34 var elem = document.createElement('div'),
35 end;
36
37 for (var t in transitions){
38 if (typeof elem.style[t] !== 'undefined'){
39 end = transitions[t];
40 }
41 }
42 if(end){
43 return end;
44 }else{
45 end = setTimeout(function(){
46 $elem.triggerHandler('transitionend', [$elem]);
47 }, 1);
48 return 'transitionend';
49 }
50}
51
52export {rtl, GetYoDigits, transitionend};