• Jump To … +
    breakpoints.js date-parse.js jquery.breakpoints.js jquery.calcRestrainedPos.js jquery.clientRect.js jquery.contentSize.js jquery.cookies.js jquery.css.js jquery.customEvent.js jquery.delimitedString.js jquery.disableEvent.js jquery.hostIframe.js jquery.hoverDelay.js jquery.htmlEncode.js jquery.imageSize.js jquery.isVisibleKeyCode.js jquery.menu.js jquery-menu-exampleskin.js jquery.modalDialog.deviceFixes.js jquery.modalDialog.getSettings.js jquery.modalDialog.header.js jquery.modalDialog.history.js jquery.modalDialog.js jquery.modalDialog.unobtrusive.js jquery.modalDialog.userAgent.js jquery.modalDialogContent.header.js jquery.modalDialogContent.js jquery.msAjax.js jquery.ns.js jquery.partialLoad.js jquery.postMessage.js jquery.proxyAll.js jquery.queryString.js jquery.richTooltip.js jquery.scrollAnchor.js jquery.uncomment.js jquery.url.js pointy.gestures.js pointy.js
  • jquery.modalDialog.getSettings.js

  • ¶

    Support reading settings from a node dialog’s element

    (function ($) {
        var ATTR_PREFIX = "data-dialog-";
    
        var getKeys = function (obj) {
    
            if (Object.keys) {
                return Object.keys(obj);
            }
    
            var keys = [];
            for (var key in obj) {
                if (obj.hasOwnProperty(key)) {
                    keys[keys.length] = key;
                }
            }
            return keys;
        };
    
        var parseNone = function (s) {
            if (s === "") {
                return s;
            }
            return s || null;
        };
    
        var parseBool = function (s) {
            if (s) {
                s = s.toString().toLowerCase();
                switch (s) {
                case "true":
                case "yes":
                case "1":
                    return true;
                default:
                    break;
                }
            }
    
            return false;
        };
    
        var parseFunction = function (body) {
  • ¶

    Evil is necessary to turn inline HTML handlers into functions

            /* jshint evil: true */
    
            if (!body) {
                return null;
            }
    
            return new Function("event", body);
        };
  • ¶

    The properties to copy from HTML data-dialog-* attributes to the dialog settings object

        var _props = {
            "title": parseNone,
            "onopen": parseFunction,
            "onbeforeopen": parseFunction,
            "onclose": parseFunction,
            "onbeforeclose": parseFunction,
            "maxWidth": parseInt,
            "initialHeight": parseInt,
            "ajax": parseBool,
            "onajaxerror": parseFunction,
            "destroyOnClose": parseBool,
            "skin": parseNone,
            "enableHistory": parseBool,
            "closeOnBackgroundClick": parseBool,
            "closeOnEscape": parseBool,
            "zIndex": parseInt
        };
    
        $.modalDialog = $.modalDialog || {};
  • ¶

    Copies the HTML data-dialog-* attributes to the settings object

        $.modalDialog.getSettings = function ($el) {
            var settings = {};
    
            $.each(getKeys(_props), function (i, key) {
  • ¶

    $.fn.attr is case insensitive

                var value = $el.attr(ATTR_PREFIX + key);
                if (typeof value != "undefined") {
                    var parser = _props[key];
                    settings[key] = parser(value);
                }
            });
    
            return settings;
        };
    
    })(jQuery);