/* ==================== UTILS ==================== */ export let Utils = { delayTimer : 0, /** * Apply a delay * * @return Function */ delay(callback: Function, ms: number) { clearTimeout(this.delayTimer); this.delayTimer = setTimeout(callback, ms); }, /** * Filter the URL Query to extract variables * * @see http://css-tricks.com/snippets/javascript/get-url-variables/ * * @param String query The URL query part containing the variables. * @param String variable Name of the variable we want to get. * * @return String|Boolean The variable value if available, false else. */ filterQuery(query: string, variable: string): string|boolean { const vars = query.split('&'); for (let i = 0; i < vars.length; i++) { const pair = vars[i].split('='); if (pair[0] === variable) { return pair[1]; } } return false; }, filterByData($elem: JQuery, prop: string, val: any) { if (typeof val === 'undefined') { return $elem.filter( (index: number, elem: Element) => { return typeof $(elem).data(prop) !== 'undefined' }); }; return $elem.filter( (index: number, elem: Element) => { return $(elem).data(prop) == val }); }, /** * Add a notice on top identical to the WordPress' admin notices * * @param String type The notice type. Can be "updated" or "error". * @param String msg The message. */ addNotice(type: string, msg: string) { let $notice: JQuery = $('

' + msg + '

').hide(), $dismissButton: JQuery = $('