From 27cd34dd2da0897693075ba16214aaa6c5b5a146 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 29 Jul 2019 15:58:41 +0200 Subject: [PATCH] js: Add new jQuery plugin `getData()` --- public/js/helpers.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/public/js/helpers.js b/public/js/helpers.js index 9747335ff..a7eae0a9c 100644 --- a/public/js/helpers.js +++ b/public/js/helpers.js @@ -5,6 +5,16 @@ 'use strict'; + /* Get data value or default */ + $.fn.getData = function (name, fallback) { + var value = this.data(name); + if (typeof value !== 'undefined') { + return value; + } + + return fallback; + }; + /* Whether a HTML tag has a specific attribute */ $.fn.hasAttr = function(name) { // We have inconsistent behaviour across browsers (false VS undef)