6eaaa68d141c4895f41161410f76a4883a5a261e
[yaffs-website] / web / themes / contrib / bootstrap / js / misc / progress.js
1 /**
2  * @file
3  * Extends methods from core/misc/progress.js.
4  */
5
6 (function ($, Drupal) {
7
8   'use strict';
9
10   /**
11    * Theme function for the progress bar.
12    *
13    * @param {string} id
14    *
15    * @return {string}
16    *   The HTML for the progress bar.
17    */
18   Drupal.theme.progressBar = function (id) {
19     return '<div class="progress-wrapper" aria-live="polite">' +
20              '<div class="message"></div>'+
21              '<div id ="' + id + '" class="progress progress-striped active">' +
22                '<div class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">' +
23                  '<span class="percentage"></span>' +
24                '</div>' +
25              '</div>' +
26              '<div class="progress-label"></div>' +
27            '</div>';
28   };
29
30   $.extend(Drupal.ProgressBar.prototype, /** @lends Drupal.ProgressBar */{
31
32     /**
33      * Set the percentage and status message for the progressbar.
34      *
35      * @param {number} percentage
36      * @param {string} message
37      * @param {string} label
38      */
39     setProgress: function (percentage, message, label) {
40       if (percentage >= 0 && percentage <= 100) {
41         $(this.element).find('.progress-bar').css('width', percentage + '%').attr('aria-valuenow', percentage);
42         $(this.element).find('.percentage').html(percentage + '%');
43       }
44       if (message) {
45         // Remove the unnecessary whitespace at the end of the message.
46         message = message.replace(/<br\/>&nbsp;|\s*$/, '');
47
48         $('.message', this.element).html(message);
49       }
50       if (label) {
51         $('.progress-label', this.element).html(label);
52       }
53       if (this.updateCallback) {
54         this.updateCallback(percentage, message, this);
55       }
56     },
57
58     /**
59      * Display errors on the page.
60      *
61      * @param {string} string
62      */
63     displayError: function (string) {
64       var error = $('<div class="alert alert-block alert-error"><a class="close" data-dismiss="alert" href="#">&times;</a><h4>' + Drupal.t('Error message') + '</h4></div>').append(string);
65       $(this.element).before(error).hide();
66
67       if (this.errorCallback) {
68         this.errorCallback(this);
69       }
70     }
71   });
72
73 })(jQuery, Drupal);