ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sneet...@apache.org
Subject [40/51] [partial] ARGUS-2 : Uploading eclipse support files and additional lib/js files
Date Thu, 14 Aug 2014 22:09:19 GMT
http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/185f7c50/security-admin/src/main/webapp/libs/bower/backgrid-paginator/js/backgrid-paginator.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/libs/bower/backgrid-paginator/js/backgrid-paginator.js
b/security-admin/src/main/webapp/libs/bower/backgrid-paginator/js/backgrid-paginator.js
new file mode 100644
index 0000000..9838b2c
--- /dev/null
+++ b/security-admin/src/main/webapp/libs/bower/backgrid-paginator/js/backgrid-paginator.js
@@ -0,0 +1,366 @@
+/*
+  backgrid-paginator
+  http://github.com/wyuenho/backgrid
+
+  Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors
+  Licensed under the MIT @license.
+*/
+(function (factory) {
+
+  // CommonJS
+  if (typeof exports == "object") {
+    module.exports = factory(require("underscore"),
+                             require("backbone"),
+                             require("backgrid"),
+                             require("backbone-pageable"));
+  }
+  // Browser
+  else if (typeof _ !== "undefined" &&
+           typeof Backbone !== "undefined" &&
+           typeof Backgrid !== "undefined") {
+    factory(_, Backbone, Backgrid);
+  }
+
+}(function (_, Backbone, Backgrid) {
+
+  "use strict";
+
+  /**
+     PageHandle is a class that renders the actual page handles and reacts to
+     click events for pagination.
+
+     This class acts in two modes - control or discrete page handle modes. If
+     one of the `is*` flags is `true`, an instance of this class is under
+     control page handle mode. Setting a `pageIndex` to an instance of this
+     class under control mode has no effect and the correct page index will
+     always be inferred from the `is*` flag. Only one of the `is*` flags should
+     be set to `true` at a time. For example, an instance of this class cannot
+     simultaneously be a rewind control and a fast forward control. A `label`
+     and a `title` template or a string are required to be passed to the
+     constuctor under this mode. If a `title` template is provided, it __MUST__
+     accept a parameter `label`. When the `label` is provided to the `title`
+     template function, its result will be used to render the generated anchor's
+     title attribute.
+
+     If all of the `is*` flags is set to `false`, which is the default, an
+     instance of this class will be in discrete page handle mode. An instance
+     under this mode requires the `pageIndex` to be passed from the constructor
+     as an option and it __MUST__ be a 0-based index of the list of page numbers
+     to render. The constuctor will normalize the base to the same base the
+     underlying PageableCollection collection instance uses. A `label` is not
+     required under this mode, which will default to the equivalent 1-based page
+     index calculated from `pageIndex` and the underlying PageableCollection
+     instance. A provided `label` will still be honored however. The `title`
+     parameter is also not required under this mode, in which case the default
+     `title` template will be used. You are encouraged to provide your own
+     `title` template however if you wish to localize the title strings.
+
+     If this page handle represents the current page, an `active` class will be
+     placed on the root list element.
+
+     if this page handle is at the border of the list of pages, a `disabled`
+     class will be placed on the root list element.
+
+     Only page handles that are neither `active` nor `disabled` will respond to
+     click events and triggers pagination.
+
+     @class Backgrid.Extension.PageHandle
+  */
+  var PageHandle = Backgrid.Extension.PageHandle = Backbone.View.extend({
+
+    /** @property */
+    tagName: "li",
+
+    /** @property */
+    events: {
+      "click a": "changePage"
+    },
+
+    /**
+       @property {string|function(Object.<string, string>): string} title
+       The title to use for the `title` attribute of the generated page handle
+       anchor elements. It can be a string or an Underscore template function
+       that takes a mandatory `label` parameter.
+    */
+    title: _.template('Page <%- label %>'),
+
+    /**
+       @property {boolean} isRewind Whether this handle represents a rewind
+       control
+    */
+    isRewind: false,
+
+    /**
+       @property {boolean} isBack Whether this handle represents a back
+       control
+    */
+    isBack: false,
+
+    /**
+       @property {boolean} isForward Whether this handle represents a forward
+       control
+    */
+    isForward: false,
+
+    /**
+       @property {boolean} isFastForward Whether this handle represents a fast
+       forward control
+    */
+    isFastForward: false,
+
+    /**
+       Initializer.
+
+       @param {Object} options
+       @param {Backbone.Collection} options.collection
+       @param {number} pageIndex 0-based index of the page number this handle
+       handles. This parameter will be normalized to the base the underlying
+       PageableCollection uses.
+       @param {string} [options.label] If provided it is used to render the
+       anchor text, otherwise the normalized pageIndex will be used
+       instead. Required if any of the `is*` flags is set to `true`.
+       @param {string} [options.title]
+       @param {boolean} [options.isRewind=false]
+       @param {boolean} [options.isBack=false]
+       @param {boolean} [options.isForward=false]
+       @param {boolean} [options.isFastForward=false]
+       
+       ********	New Added Options ************* 
+       @param {boolean} [options.scrollToTop=true]
+       On Page change by default it scroll to top 
+    */
+    initialize: function (options) {
+      Backbone.View.prototype.initialize.apply(this, arguments);
+
+      var collection = this.collection;
+      var state = collection.state;
+      var currentPage = state.currentPage;
+      var firstPage = state.firstPage;
+      var lastPage = state.lastPage;
+
+      _.extend(this, _.pick(options,
+                            ["isRewind", "isBack", "isForward", "isFastForward" , "scrollToTop",'paginationCache']));
+
+      var pageIndex;
+      if (this.isRewind) pageIndex = firstPage;
+      else if (this.isBack) pageIndex = Math.max(firstPage, currentPage - 1);
+      else if (this.isForward) pageIndex = Math.min(lastPage, currentPage + 1);
+      else if (this.isFastForward) pageIndex = lastPage;
+      else {
+        pageIndex = +options.pageIndex;
+        pageIndex = (firstPage ? pageIndex + 1 : pageIndex);
+      }
+      this.pageIndex = pageIndex;
+
+      if (((this.isRewind || this.isBack) && currentPage == firstPage) ||
+          ((this.isForward || this.isFastForward) && currentPage == lastPage)) {
+        this.$el.addClass("disabled");
+      }
+      else if (!(this.isRewind ||
+                 this.isBack ||
+                 this.isForward ||
+                 this.isFastForward) &&
+               currentPage == pageIndex) {
+        this.$el.addClass("active");
+      }
+
+      this.label = (options.label || (firstPage ? pageIndex : pageIndex + 1)) + '';
+      var title = options.title || this.title;
+      this.title = _.isFunction(title) ? title({label: this.label}) : title;
+    },
+
+    /**
+       Renders a clickable anchor element under a list item.
+    */
+    render: function () {
+      this.$el.empty();
+      var anchor = document.createElement("a");
+      anchor.href = '#';
+      if (this.title) anchor.title = this.title;
+      anchor.innerHTML = this.label;
+      this.el.appendChild(anchor);
+      this.delegateEvents();
+      return this;
+    },
+
+    /**
+       jQuery click event handler. Goes to the page this PageHandle instance
+       represents. No-op if this page handle is currently active or disabled.
+    */
+    changePage: function (e) {
+      e.preventDefault();
+      var $el = this.$el;
+      if (this.scrollToTop){
+    	  $("body,html").animate({scrollTop:0},800);
+      }
+      if (!$el.hasClass("active") && !$el.hasClass("disabled") && !this.paginationCache)
{
+        this.collection.getPage(this.pageIndex);
+      }else
+    	  this.collection.getPage(this.pageIndex ,{cache : true});
+      return this;
+    }
+
+  });
+
+  /**
+     Paginator is a Backgrid extension that renders a series of configurable
+     pagination handles. This extension is best used for splitting a large data
+     set across multiple pages. If the number of pages is larger then a
+     threshold, which is set to 10 by default, the page handles are rendered
+     within a sliding window, plus the rewind, back, forward and fast forward
+     control handles. The individual control handles can be turned off.
+
+     @class Backgrid.Extension.Paginator
+  */
+  Backgrid.Extension.Paginator = Backbone.View.extend({
+
+    /** @property */
+    className: "backgrid-paginator",
+
+    /** @property */
+    windowSize: 10,
+
+    /**
+       @property {Object.<string, Object.<string, string>>} controls You can
+       disable specific control handles by omitting certain keys.
+    */
+    controls: {
+      rewind: {
+        label: "《",
+        title: "First"
+      },
+      back: {
+        label: "〈",
+        title: "Previous"
+      },
+      forward: {
+        label: "〉",
+        title: "Next"
+      },
+      fastForward: {
+        label: "》",
+        title: "Last"
+      }
+    },
+
+    /**
+       @property {Backgrid.Extension.PageHandle} pageHandle. The PageHandle
+       class to use for rendering individual handles
+    */
+    pageHandle: PageHandle,
+
+    /** @property */
+    goBackFirstOnSort: true,
+
+    /**
+       Initializer.
+
+       @param {Object} options
+       @param {Backbone.Collection} options.collection
+       @param {boolean} [options.controls]
+       @param {boolean} [options.pageHandle=Backgrid.Extension.PageHandle]
+       @param {boolean} [options.goBackFirstOnSort=true]
+    */
+    initialize: function (options) {
+      this.scrollToTop = options.scrollToTop || false;		//Added scrollToTop on  Page Change
+      this.paginationCache = options.paginationCache || false;					//set cache on  Page Change.
Need Cache boolean value for backbone.fetch-cache plugin 
+      this.controls = options.controls || this.controls;
+      this.pageHandle = options.pageHandle || this.pageHandle;
+
+      var collection = this.collection;
+      this.listenTo(collection, "add", this.render);
+      this.listenTo(collection, "remove", this.render);
+      this.listenTo(collection, "reset", this.render);
+      if ((options.goBackFirstOnSort || this.goBackFirstOnSort) &&
+          collection.fullCollection) {
+        this.listenTo(collection.fullCollection, "sort", function () {
+          collection.getFirstPage();
+        });
+      }
+    },
+
+    _calculateWindow: function () {
+      var collection = this.collection;
+      var state = collection.state;
+
+      // convert all indices to 0-based here
+      var firstPage = state.firstPage;
+      var lastPage = +state.lastPage;
+      lastPage = Math.max(0, firstPage ? lastPage - 1 : lastPage);
+      var currentPage = Math.max(state.currentPage, state.firstPage);
+      currentPage = firstPage ? currentPage - 1 : currentPage;
+      var windowStart = Math.floor(currentPage / this.windowSize) * this.windowSize;
+      var windowEnd = Math.min(lastPage + 1, windowStart + this.windowSize);
+      return [windowStart, windowEnd];
+    },
+
+    /**
+       Creates a list of page handle objects for rendering.
+
+       @return {Array.<Object>} an array of page handle objects hashes
+    */
+    makeHandles: function () {
+
+      var handles = [];
+      var collection = this.collection;
+
+      var window = this._calculateWindow();
+      var winStart = window[0], winEnd = window[1];
+
+      for (var i = winStart; i < winEnd; i++) {
+        handles.push(new this.pageHandle({
+          collection: collection,
+          pageIndex: i,
+          scrollToTop : this.scrollToTop,
+          paginationCache: this.paginationCache
+        }));
+      }
+
+      var controls = this.controls;
+      _.each(["back", "rewind", "forward", "fastForward"], function (key) {
+        var value = controls[key];
+        if (value) {
+          var handleCtorOpts = {
+            collection: collection,
+            title: value.title,
+            label: value.label,
+            scrollToTop : this.scrollToTop,
+            paginationCache: this.paginationCache
+          };
+          handleCtorOpts["is" + key.slice(0, 1).toUpperCase() + key.slice(1)] = true;
+          var handle = new this.pageHandle(handleCtorOpts);
+          if (key == "rewind" || key == "back") handles.unshift(handle);
+          else handles.push(handle);
+        }
+      }, this);
+
+      return handles;
+    },
+
+    /**
+       Render the paginator handles inside an unordered list.
+    */
+    render: function () {
+      this.$el.empty();
+
+      if (this.handles) {
+        for (var i = 0, l = this.handles.length; i < l; i++) {
+          this.handles[i].remove();
+        }
+      }
+
+      var handles = this.handles = this.makeHandles();
+
+      var ul = document.createElement("ul");
+      for (var i = 0; i < handles.length; i++) {
+        ul.appendChild(handles[i].render().el);
+      }
+
+      this.el.appendChild(ul);
+
+      return this;
+    }
+
+  });
+
+}));

http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/185f7c50/security-admin/src/main/webapp/libs/bower/bootbox/js/bootbox.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/libs/bower/bootbox/js/bootbox.js b/security-admin/src/main/webapp/libs/bower/bootbox/js/bootbox.js
new file mode 100644
index 0000000..f6c6661
--- /dev/null
+++ b/security-admin/src/main/webapp/libs/bower/bootbox/js/bootbox.js
@@ -0,0 +1,660 @@
+/**
+ * bootbox.js v3.3.0
+ *
+ * http://bootboxjs.com/license.txt
+ */
+var bootbox = window.bootbox || (function(document, $) {
+    /*jshint scripturl:true sub:true */
+
+    var _locale        = 'en',
+        _defaultLocale = 'en',
+        _animate       = true,
+        _backdrop      = 'static',
+        _defaultHref   = 'javascript:;',
+        _classes       = '',
+        _btnClasses    = {},
+        _icons         = {},
+        /* last var should always be the public object we'll return */
+        that           = {};
+
+
+    /**
+     * public API
+     */
+    that.setLocale = function(locale) {
+        for (var i in _locales) {
+            if (i == locale) {
+                _locale = locale;
+                return;
+            }
+        }
+        throw new Error('Invalid locale: '+locale);
+    };
+
+    that.addLocale = function(locale, translations) {
+        if (typeof _locales[locale] === 'undefined') {
+            _locales[locale] = {};
+        }
+        for (var str in translations) {
+            _locales[locale][str] = translations[str];
+        }
+    };
+
+    that.setIcons = function(icons) {
+        _icons = icons;
+        if (typeof _icons !== 'object' || _icons === null) {
+            _icons = {};
+        }
+    };
+
+    that.setBtnClasses = function(btnClasses) {
+        _btnClasses = btnClasses;
+        if (typeof _btnClasses !== 'object' || _btnClasses === null) {
+            _btnClasses = {};
+        }
+    };
+
+    that.alert = function(/*str, label, cb*/) {
+        var str   = "",
+            label = _translate('OK'),
+            cb    = null;
+
+        switch (arguments.length) {
+            case 1:
+                // no callback, default button label
+                str = arguments[0];
+                break;
+            case 2:
+                // callback *or* custom button label dependent on type
+                str = arguments[0];
+                if (typeof arguments[1] == 'function') {
+                    cb = arguments[1];
+                } else {
+                    label = arguments[1];
+                }
+                break;
+            case 3:
+                // callback and custom button label
+                str   = arguments[0];
+                label = arguments[1];
+                cb    = arguments[2];
+                break;
+            default:
+                throw new Error("Incorrect number of arguments: expected 1-3");
+        }
+
+        return that.dialog(str, {
+            // only button (ok)
+            "label"   : label,
+            "icon"    : _icons.OK,
+            "class"   : _btnClasses.OK,
+            "callback": cb
+        }, {
+            // ensure that the escape key works; either invoking the user's
+            // callback or true to just close the dialog
+            "onEscape": cb || true
+        });
+    };
+
+    that.confirm = function(/*str, labelCancel, labelOk, cb*/) {
+        var str         = "",
+            labelCancel = _translate('CANCEL'),
+            labelOk     = _translate('CONFIRM'),
+            cb          = null;
+
+        switch (arguments.length) {
+            case 1:
+                str = arguments[0];
+                break;
+            case 2:
+                str = arguments[0];
+                if (typeof arguments[1] == 'function') {
+                    cb = arguments[1];
+                } else {
+                    labelCancel = arguments[1];
+                }
+                break;
+            case 3:
+                str         = arguments[0];
+                labelCancel = arguments[1];
+                if (typeof arguments[2] == 'function') {
+                    cb = arguments[2];
+                } else {
+                    labelOk = arguments[2];
+                }
+                break;
+            case 4:
+                str         = arguments[0];
+                labelCancel = arguments[1];
+                labelOk     = arguments[2];
+                cb          = arguments[3];
+                break;
+            default:
+                throw new Error("Incorrect number of arguments: expected 1-4");
+        }
+
+        var cancelCallback = function() {
+            if (typeof cb === 'function') {
+                return cb(false);
+            }
+        };
+
+        var confirmCallback = function() {
+            if (typeof cb === 'function') {
+                return cb(true);
+            }
+        };
+
+        return that.dialog(str, [{
+            // first button (cancel)
+            "label"   : labelCancel,
+            "icon"    : _icons.CANCEL,
+            "class"   : _btnClasses.CANCEL,
+            "callback": cancelCallback
+        }, {
+            // second button (confirm)
+            "label"   : labelOk,
+            "icon"    : _icons.CONFIRM,
+            "class"   : _btnClasses.CONFIRM,
+            "callback": confirmCallback
+        }], {
+            // escape key bindings
+            "onEscape": cancelCallback
+        });
+    };
+
+    that.prompt = function(/*str, labelCancel, labelOk, cb, defaultVal*/) {
+        var str         = "",
+            labelCancel = _translate('CANCEL'),
+            labelOk     = _translate('CONFIRM'),
+            cb          = null,
+            defaultVal  = "";
+
+        switch (arguments.length) {
+            case 1:
+                str = arguments[0];
+                break;
+            case 2:
+                str = arguments[0];
+                if (typeof arguments[1] == 'function') {
+                    cb = arguments[1];
+                } else {
+                    labelCancel = arguments[1];
+                }
+                break;
+            case 3:
+                str         = arguments[0];
+                labelCancel = arguments[1];
+                if (typeof arguments[2] == 'function') {
+                    cb = arguments[2];
+                } else {
+                    labelOk = arguments[2];
+                }
+                break;
+            case 4:
+                str         = arguments[0];
+                labelCancel = arguments[1];
+                labelOk     = arguments[2];
+                cb          = arguments[3];
+                break;
+            case 5:
+                str         = arguments[0];
+                labelCancel = arguments[1];
+                labelOk     = arguments[2];
+                cb          = arguments[3];
+                defaultVal  = arguments[4];
+                break;
+            default:
+                throw new Error("Incorrect number of arguments: expected 1-5");
+        }
+
+        var header = str;
+
+        // let's keep a reference to the form object for later
+        var form = $("<form></form>");
+        form.append("<input class='input-block-level' autocomplete=off type=text value='"
+ defaultVal + "' />");
+
+        var cancelCallback = function() {
+            if (typeof cb === 'function') {
+                // yep, native prompts dismiss with null, whereas native
+                // confirms dismiss with false...
+                return cb(null);
+            }
+        };
+
+        var confirmCallback = function() {
+            if (typeof cb === 'function') {
+                return cb(form.find("input[type=text]").val());
+            }
+        };
+
+        var div = that.dialog(form, [{
+            // first button (cancel)
+            "label"   : labelCancel,
+            "icon"    : _icons.CANCEL,
+            "class"   : _btnClasses.CANCEL,
+            "callback":  cancelCallback
+        }, {
+            // second button (confirm)
+            "label"   : labelOk,
+            "icon"    : _icons.CONFIRM,
+            "class"   : _btnClasses.CONFIRM,
+            "callback": confirmCallback
+        }], {
+            // prompts need a few extra options
+            "header"  : header,
+            // explicitly tell dialog NOT to show the dialog...
+            "show"    : false,
+            "onEscape": cancelCallback
+        });
+
+        // ... the reason the prompt needs to be hidden is because we need
+        // to bind our own "shown" handler, after creating the modal but
+        // before any show(n) events are triggered
+        // @see https://github.com/makeusabrew/bootbox/issues/69
+
+        div.on("shown", function() {
+            form.find("input[type=text]").focus();
+
+            // ensure that submitting the form (e.g. with the enter key)
+            // replicates the behaviour of a normal prompt()
+            form.on("submit", function(e) {
+                e.preventDefault();
+                div.find(".btn-primary").click();
+            });
+        });
+
+        div.modal("show");
+
+        return div;
+    };
+
+    that.dialog = function(str, handlers, options) {
+        var buttons    = "",
+            callbacks  = [];
+
+        if (!options) {
+            options = {};
+        }
+
+        // check for single object and convert to array if necessary
+        if (typeof handlers === 'undefined') {
+            handlers = [];
+        } else if (typeof handlers.length == 'undefined') {
+            handlers = [handlers];
+        }
+
+        var i = handlers.length;
+        while (i--) {
+            var label    = null,
+                href     = null,
+                _class   = null,
+                icon     = '',
+                callback = null;
+
+            if (typeof handlers[i]['label']    == 'undefined' &&
+                typeof handlers[i]['class']    == 'undefined' &&
+                typeof handlers[i]['callback'] == 'undefined') {
+                // if we've got nothing we expect, check for condensed format
+
+                var propCount = 0,      // condensed will only match if this == 1
+                    property  = null;   // save the last property we found
+
+                // be nicer to count the properties without this, but don't think it's possible...
+                for (var j in handlers[i]) {
+                    property = j;
+                    if (++propCount > 1) {
+                        // forget it, too many properties
+                        break;
+                    }
+                }
+
+                if (propCount == 1 && typeof handlers[i][j] == 'function') {
+                    // matches condensed format of label -> function
+                    handlers[i]['label']    = property;
+                    handlers[i]['callback'] = handlers[i][j];
+                }
+            }
+
+            if (typeof handlers[i]['callback']== 'function') {
+                callback = handlers[i]['callback'];
+            }
+
+            if (handlers[i]['class']) {
+                _class = handlers[i]['class'];
+            } else if (i == handlers.length -1 && handlers.length <= 2) {
+                // always add a primary to the main option in a two-button dialog
+                _class = 'btn-primary';
+            }
+
+            if (handlers[i]['link'] !== true) {
+                _class = 'btn ' + _class;
+            }
+
+            if (handlers[i]['label']) {
+                label = handlers[i]['label'];
+            } else {
+                label = "Option "+(i+1);
+            }
+
+            if (handlers[i]['icon']) {
+                icon = "<i class='"+handlers[i]['icon']+"'></i> ";
+            }
+
+            if (handlers[i]['href']) {
+                href = handlers[i]['href'];
+            }
+            else {
+                href = _defaultHref;
+            }
+
+            buttons = "<a data-handler='"+i+"' class='"+_class+"' href='" + href + "'>"+icon+""+label+"</a>"
+ buttons;
+
+            callbacks[i] = callback;
+        }
+
+        // @see https://github.com/makeusabrew/bootbox/issues/46#issuecomment-8235302
+        // and https://github.com/twitter/bootstrap/issues/4474
+        // for an explanation of the inline overflow: hidden
+        // @see https://github.com/twitter/bootstrap/issues/4854
+        // for an explanation of tabIndex=-1
+
+        var parts = ["<div class='bootbox modal' tabindex='-1' style='overflow:hidden;'>"];
+
+        if (options['header']) {
+            var closeButton = '';
+            if (typeof options['headerCloseButton'] == 'undefined' || options['headerCloseButton'])
{
+                closeButton = "<a href='"+_defaultHref+"' class='close'>&times;</a>";
+            }
+
+            parts.push("<div class='modal-header'>"+closeButton+"<h3>"+options['header']+"</h3></div>");
+        }
+
+        // push an empty body into which we'll inject the proper content later
+        parts.push("<div class='modal-body'></div>");
+
+        if (buttons) {
+            parts.push("<div class='modal-footer'>"+buttons+"</div>");
+        }
+
+        parts.push("</div>");
+
+        var div = $(parts.join("\n"));
+
+        // check whether we should fade in/out
+        var shouldFade = (typeof options.animate === 'undefined') ? _animate : options.animate;
+
+        if (shouldFade) {
+            div.addClass("fade");
+        }
+
+        var optionalClasses = (typeof options.classes === 'undefined') ? _classes : options.classes;
+        if (optionalClasses) {
+            div.addClass(optionalClasses);
+        }
+
+        // now we've built up the div properly we can inject the content whether it was a
string or a jQuery object
+        div.find(".modal-body").html(str);
+
+        function onCancel(source) {
+            // for now source is unused, but it will be in future
+            var hideModal = null;
+            if (typeof options.onEscape === 'function') {
+                // @see https://github.com/makeusabrew/bootbox/issues/91
+                hideModal = options.onEscape();
+            }
+
+            if (hideModal !== false) {
+                div.modal('hide');
+            }
+        }
+
+        // hook into the modal's keyup trigger to check for the escape key
+        div.on('keyup.dismiss.modal', function(e) {
+            // any truthy value passed to onEscape will dismiss the dialog
+            // as long as the onEscape function (if defined) doesn't prevent it
+            if (e.which === 27 && options.onEscape) {
+                onCancel('escape');
+            }
+        });
+
+        // handle close buttons too
+        div.on('click', 'a.close', function(e) {
+            e.preventDefault();
+            onCancel('close');
+        });
+
+        // well, *if* we have a primary - give the first dom element focus
+        div.on('shown', function() {
+            div.find("a.btn-primary:first").focus();
+        });
+
+        div.on('hidden', function(e) {
+            // @see https://github.com/makeusabrew/bootbox/issues/115
+            // allow for the fact hidden events can propagate up from
+            // child elements like tooltips
+            if (e.target === this) {
+                div.remove();
+            }
+        });
+
+        // wire up button handlers
+        div.on('click', '.modal-footer a', function(e) {
+
+            var handler   = $(this).data("handler"),
+                cb        = callbacks[handler],
+                hideModal = null;
+
+            // sort of @see https://github.com/makeusabrew/bootbox/pull/68 - heavily adapted
+            // if we've got a custom href attribute, all bets are off
+            if (typeof handler                   !== 'undefined' &&
+                typeof handlers[handler]['href'] !== 'undefined') {
+
+                return;
+            }
+
+            e.preventDefault();
+
+            if (typeof cb === 'function') {
+                hideModal = cb(e);
+            }
+
+            // the only way hideModal *will* be false is if a callback exists and
+            // returns it as a value. in those situations, don't hide the dialog
+            // @see https://github.com/makeusabrew/bootbox/pull/25
+            if (hideModal !== false) {
+                div.modal("hide");
+            }
+        });
+
+        // stick the modal right at the bottom of the main body out of the way
+        $("body").append(div);
+
+        div.modal({
+            // unless explicitly overridden take whatever our default backdrop value is
+            backdrop : (typeof options.backdrop  === 'undefined') ? _backdrop : options.backdrop,
+            // ignore bootstrap's keyboard options; we'll handle this ourselves (more fine-grained
control)
+            keyboard : false,
+            // @ see https://github.com/makeusabrew/bootbox/issues/69
+            // we *never* want the modal to be shown before we can bind stuff to it
+            // this method can also take a 'show' option, but we'll only use that
+            // later if we need to
+            show     : false
+        });
+
+        // @see https://github.com/makeusabrew/bootbox/issues/64
+        // @see https://github.com/makeusabrew/bootbox/issues/60
+        // ...caused by...
+        // @see https://github.com/twitter/bootstrap/issues/4781
+        div.on("show", function(e) {
+            $(document).off("focusin.modal");
+        });
+
+        if (typeof options.show === 'undefined' || options.show === true) {
+            div.modal("show");
+        }
+
+        return div;
+    };
+
+    /**
+     * #modal is deprecated in v3; it can still be used but no guarantees are
+     * made - have never been truly convinced of its merit but perhaps just
+     * needs a tidyup and some TLC
+     */
+    that.modal = function(/*str, label, options*/) {
+        var str;
+        var label;
+        var options;
+
+        var defaultOptions = {
+            "onEscape": null,
+            "keyboard": true,
+            "backdrop": _backdrop
+        };
+
+        switch (arguments.length) {
+            case 1:
+                str = arguments[0];
+                break;
+            case 2:
+                str = arguments[0];
+                if (typeof arguments[1] == 'object') {
+                    options = arguments[1];
+                } else {
+                    label = arguments[1];
+                }
+                break;
+            case 3:
+                str     = arguments[0];
+                label   = arguments[1];
+                options = arguments[2];
+                break;
+            default:
+                throw new Error("Incorrect number of arguments: expected 1-3");
+        }
+
+        defaultOptions['header'] = label;
+
+        if (typeof options == 'object') {
+            options = $.extend(defaultOptions, options);
+        } else {
+            options = defaultOptions;
+        }
+
+        return that.dialog(str, [], options);
+    };
+
+
+    that.hideAll = function() {
+        $(".bootbox").modal("hide");
+    };
+
+    that.animate = function(animate) {
+        _animate = animate;
+    };
+
+    that.backdrop = function(backdrop) {
+        _backdrop = backdrop;
+    };
+
+    that.classes = function(classes) {
+        _classes = classes;
+    };
+
+    /**
+     * private API
+     */
+
+    /**
+     * standard locales. Please add more according to ISO 639-1 standard. Multiple language
variants are
+     * unlikely to be required. If this gets too large it can be split out into separate
JS files.
+     */
+    var _locales = {
+        'br' : {
+            OK      : 'OK',
+            CANCEL  : 'Cancelar',
+            CONFIRM : 'Sim'
+        },
+        'da' : {
+            OK      : 'OK',
+            CANCEL  : 'Annuller',
+            CONFIRM : 'Accepter'
+        },
+        'de' : {
+            OK      : 'OK',
+            CANCEL  : 'Abbrechen',
+            CONFIRM : 'Akzeptieren'
+        },
+        'en' : {
+            OK      : 'OK',
+            CANCEL  : 'Cancel',
+            CONFIRM : 'OK'
+        },
+        'es' : {
+            OK      : 'OK',
+            CANCEL  : 'Cancelar',
+            CONFIRM : 'Aceptar'
+        },
+        'fr' : {
+            OK      : 'OK',
+            CANCEL  : 'Annuler',
+            CONFIRM : 'D\'accord'
+        },
+        'it' : {
+            OK      : 'OK',
+            CANCEL  : 'Annulla',
+            CONFIRM : 'Conferma'
+        },
+        'nl' : {
+            OK      : 'OK',
+            CANCEL  : 'Annuleren',
+            CONFIRM : 'Accepteren'
+        },
+        'pl' : {
+            OK      : 'OK',
+            CANCEL  : 'Anuluj',
+            CONFIRM : 'Potwierdź'
+        },
+        'ru' : {
+            OK      : 'OK',
+            CANCEL  : 'Отмена',
+            CONFIRM : 'Применить'
+        },
+        'zh_CN' : {
+            OK      : 'OK',
+            CANCEL  : '取消',
+            CONFIRM : '确认'
+        },
+        'zh_TW' : {
+            OK      : 'OK',
+            CANCEL  : '取消',
+            CONFIRM : '確認'
+        }
+    };
+
+    function _translate(str, locale) {
+        // we assume if no target locale is probided then we should take it from current
setting
+        if (typeof locale === 'undefined') {
+            locale = _locale;
+        }
+        if (typeof _locales[locale][str] === 'string') {
+            return _locales[locale][str];
+        }
+
+        // if we couldn't find a lookup then try and fallback to a default translation
+
+        if (locale != _defaultLocale) {
+            return _translate(str, _defaultLocale);
+        }
+
+        // if we can't do anything then bail out with whatever string was passed in - last
resort
+        return str;
+    }
+
+    return that;
+
+}(document, window.jQuery));
+
+// @see https://github.com/makeusabrew/bootbox/issues/71
+window.bootbox = bootbox;


Mime
View raw message