.Maui Blog

SambucaJS – jQuery plugin

Small jquery plugin that adds some functionality to jquery, eg:
Check if an item is empty
Check whether an item exists
Take a parameter in the querystring of the current Web page.

/*!
 * jQuery Sambuca Plugin v0.1
 * https://dotmaui.com/
 *
 * Copyright .Maui Project and other contributors
 * Released under the MIT license
 * https://opensource.org/licenses/MIT
 *
 * Date: 2017-01-10T20:30Z
 */
(function($) {

    $.fn.isEmpty = function() {

        if (this.prop("tagName") === "INPUT" || this.prop("tagName") === "TEXTAREA") {

            return (this.val() === "");

        } else {

            return (this.html() === "");

        }

    };

    $.fn.isEmptyOrWhiteSpace = function() {

        if (this.prop("tagName") === "INPUT" || this.prop("tagName") === "TEXTAREA") {

            return $.trim(this.val()) === "";

        } else {

            return $.trim(this.html()) === "";

        }

    };

    $.fn.exists = function() {
        return (this.length > 0);
    };

    $.urlParam = function(name) {
        var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href);

        if (results === null)
            return "";

        return results[1] || 0;

    }

}(jQuery));

This plugin is also available through our CDN:
https://cdn.dotmaui.com/dotmaui/js/jquery.sambuca-0.1.min.js

Exit mobile version