import $ from 'jquery';
import { Keyboard } from './foundation.util.keyboard';
import { MediaQuery } from './foundation.util.mediaQuery';
-import { transitionend } from './foundation.util.core';
+import { transitionend, RegExpEscape } from './foundation.util.core';
import { Plugin } from './foundation.plugin';
import { Triggers } from './foundation.util.triggers';
}
}
- this.options.isRevealed = this.options.isRevealed || new RegExp(this.options.revealClass, 'g').test(this.$element[0].className);
+ // Get the revealOn option from the class.
+ var revealOnClass = this.$element[0].className.match(RegExpEscape(this.options.revealClass) + '([^\s])+', 'g');
+ if (revealOnClass) {
+ this.options.isRevealed = true;
+ this.options.revealOn = this.options.revealOn || revealOnClass[1];
+ }
- // Get the revealOn option from the class / ensure the `reveal-on-*` class is set.
- if (this.options.isRevealed === true) {
- this.options.revealOn = this.options.revealOn || this.$element[0].className.match(/(reveal-for-medium|reveal-for-large)/g)[0].split('-')[2];
- if (this.options.revealOn) this.$element.first().addClass(`reveal-for-${this.options.revealOn}`);
+ // Ensure the `reveal-on-*` class is set.
+ if (this.options.isRevealed === true && this.options.revealOn) {
+ this.$element.first().addClass(`${this.options.revealClass}${this.options.revealOn}`);
this._setMQChecker();
}
return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1) + (namespace ? `-${namespace}` : '');
}
+/**
+ * Escape a string so it can be used as a regexp pattern
+ * @function
+ * @see https://stackoverflow.com/a/9310752/4317384
+ *
+ * @param {String} str - string to escape.
+ * @returns {String} - escaped string
+ */
+function RegExpEscape(str){
+ return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
+}
+
function transitionend($elem){
var transitions = {
'transition': 'transitionend',
}
}
-export {rtl, GetYoDigits, transitionend};
+export {rtl, GetYoDigits, RegExpEscape, transitionend};