Commit 7b6f2fb16030851dbba67a06614ec6c2aedaec4f

Authored by Dmitriy Zaporozhets
2 parents 5d66df0a 646fbe92

Merge branch 'enhancement/issue_filter_dropdown' of /home/git/repositories/gitlab/gitlabhq

app/assets/javascripts/application.js
... ... @@ -14,6 +14,7 @@
14 14 //= require jquery.waitforimages
15 15 //= require jquery.atwho
16 16 //= require jquery.scrollto
  17 +//= require jquery.blockUI
17 18 //= require turbolinks
18 19 //= require jquery.turbolinks
19 20 //= require bootstrap
... ...
app/assets/javascripts/issues.js.coffee
... ... @@ -15,8 +15,14 @@
15 15 $(this).html totalIssues + 1
16 16 else
17 17 $(this).html totalIssues - 1
18   -
19   -
  18 + $("body").on "click", ".issues-filters .dropdown-menu a", ->
  19 + $('.issues-list').block(
  20 + message: null,
  21 + overlayCSS:
  22 + backgroundColor: '#DDD'
  23 + opacity: .4
  24 + )
  25 +
20 26 reload: ->
21 27 Issues.initSelects()
22 28 Issues.initChecks()
... ... @@ -48,10 +54,6 @@
48 54 unless terms is last_terms
49 55 last_terms = terms
50 56 if terms.length >= 2 or terms.length is 0
51   - $('#search_status').val($('#status').val())
52   - $('#search_assignee_id').val($('#assignee_id').val())
53   - $('#search_milestone_id').val($('#milestone_id').val())
54   - $('#search_label_name').val($('#label_name').val())
55 57 form.submit()
56 58  
57 59 checkChanged: ->
... ... @@ -62,9 +64,9 @@
62 64 ids.push $(value).attr("data-id")
63 65  
64 66 $("#update_issues_ids").val ids
65   - $(".issues_filters").hide()
  67 + $(".issues-filters").hide()
66 68 $(".issues_bulk_update").show()
67 69 else
68 70 $("#update_issues_ids").val []
69 71 $(".issues_bulk_update").hide()
70   - $(".issues_filters").show()
  72 + $(".issues-filters").show()
... ...
app/assets/stylesheets/gitlab_bootstrap/common.scss
... ... @@ -19,6 +19,7 @@
19 19 .append-right-20 { margin-right:20px }
20 20 .append-bottom-10 { margin-bottom:10px }
21 21 .append-bottom-20 { margin-bottom:20px }
  22 +.inline { display: inline-block }
22 23  
23 24 .padded { padding:20px }
24 25 .ipadded { padding:20px!important }
... ...
app/controllers/issues_controller.rb
... ... @@ -20,6 +20,12 @@ class IssuesController < ProjectResourceController
20 20 @issues = @issues.where("title LIKE ?", "%#{terms}%") if terms.present?
21 21 @issues = @issues.page(params[:page]).per(20)
22 22  
  23 +
  24 + assignee_id, milestone_id = params[:assignee_id], params[:milestone_id]
  25 +
  26 + @assignee = @project.users.find(assignee_id) if assignee_id.present? && !assignee_id.to_i.zero?
  27 + @milestone = @project.milestones.find(milestone_id) if milestone_id.present? && !milestone_id.to_i.zero?
  28 +
23 29 respond_to do |format|
24 30 format.html # index.html.erb
25 31 format.js
... ...
app/helpers/issues_helper.rb
... ... @@ -78,4 +78,15 @@ module IssuesHelper
78 78 ""
79 79 end
80 80 end
  81 +
  82 + def project_issues_with_filter_path(project, opts)
  83 + default_opts = {
  84 + status: params[:status],
  85 + label_name: params[:label_name],
  86 + milestone_id: params[:milestone_id],
  87 + assignee_id: params[:assignee_id],
  88 + }
  89 +
  90 + project_issues_path(@project, default_opts.merge(opts))
  91 + end
81 92 end
... ...
app/helpers/labels_helper.rb
1 1 module LabelsHelper
2   - def issue_tags
3   - @project.issues.tag_counts_on(:labels).map(&:name)
  2 + def issue_label_names
  3 + @project.issues_labels.map(&:name)
4 4 end
5 5  
6 6 def labels_autocomplete_source
... ...
app/views/issues/_filter.html.haml
1 1 = form_tag project_issues_path(@project), method: 'get' do
2 2 %fieldset
3 3 %ul.nav.nav-pills.nav-stacked
4   - %li{class: ("active" if !params[:status])}
  4 + %li{class: ("active" if !params[:status] || params[:status].blank?)}
5 5 = link_to project_issues_path(@project, status: nil) do
6 6 Open
7 7 %li{class: ("active" if params[:status] == 'assigned-to-me')}
... ...
app/views/issues/_issues.html.haml
... ... @@ -12,13 +12,73 @@
12 12 = hidden_field_tag 'update[issues_ids]', []
13 13 = hidden_field_tag :status, params[:status]
14 14 = button_tag "Save", class: "btn update_selected_issues btn-small btn-save"
15   - .issues_filters
16   - = form_tag project_issues_path(@project), method: :get, remote: true do
17   - = select_tag(:label_name, options_for_select(issue_tags, params[:label_name]), prompt: "Labels")
18   - = select_tag(:assignee_id, options_from_collection_for_select([unassigned_filter] + @project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee")
19   - = select_tag(:milestone_id, options_from_collection_for_select([unassigned_filter] + issues_active_milestones, "id", "title", params[:milestone_id]), prompt: "Milestone")
20   - = hidden_field_tag :status, params[:status]
21   - = hidden_field_tag :issue_search, params[:status], id: 'filter_issue_search'
  15 + .issues-filters
  16 + %span Filter by
  17 + .dropdown.inline.prepend-left-10
  18 + %a.dropdown-toggle.btn.btn-small{href: '#', "data-toggle" => "dropdown"}
  19 + %i.icon-tags
  20 + %span.light labels:
  21 + - if params[:label_name].present?
  22 + %strong= params[:label_name]
  23 + - else
  24 + Any
  25 + %b.caret
  26 + %ul.dropdown-menu
  27 + %li
  28 + = link_to project_issues_with_filter_path(@project, label_name: nil) do
  29 + Any
  30 + - issue_label_names.each do |label_name|
  31 + %li
  32 + = link_to project_issues_with_filter_path(@project, label_name: label_name) do
  33 + %span{class: "label #{label_css_class(label_name)}"}
  34 + %i.icon-tag
  35 + = label_name
  36 + .dropdown.inline.prepend-left-10
  37 + %a.dropdown-toggle.btn.btn-small{href: '#', "data-toggle" => "dropdown"}
  38 + %i.icon-user
  39 + %span.light assignee:
  40 + - if @assignee.present?
  41 + %strong= @assignee.name
  42 + - elsif params[:assignee_id] == "0"
  43 + Unassigned
  44 + - else
  45 + Any
  46 + %b.caret
  47 + %ul.dropdown-menu
  48 + %li
  49 + = link_to project_issues_with_filter_path(@project, assignee_id: nil) do
  50 + Any
  51 + = link_to project_issues_with_filter_path(@project, assignee_id: 0) do
  52 + Unassigned
  53 + - @project.users.sort_by(&:name).each do |user|
  54 + %li
  55 + = link_to project_issues_with_filter_path(@project, assignee_id: user.id) do
  56 + = image_tag gravatar_icon(user.email), class: "avatar s16"
  57 + = user.name
  58 +
  59 + .dropdown.inline.prepend-left-10
  60 + %a.dropdown-toggle.btn.btn-small{href: '#', "data-toggle" => "dropdown"}
  61 + %i.icon-time
  62 + %span.light milestone:
  63 + - if @milestone.present?
  64 + %strong= @milestone.title
  65 + - elsif params[:milestone_id] == "0"
  66 + Unspecified
  67 + - else
  68 + Any
  69 + %b.caret
  70 + %ul.dropdown-menu
  71 + %li
  72 + = link_to project_issues_with_filter_path(@project, milestone_id: nil) do
  73 + Any
  74 + = link_to project_issues_with_filter_path(@project, milestone_id: 0) do
  75 + Unspecified
  76 + - issues_active_milestones.each do |milestone|
  77 + %li
  78 + = link_to project_issues_with_filter_path(@project, milestone_id: milestone.id) do
  79 + %strong= milestone.title
  80 + %small.light= milestone.expires_at
  81 +
22 82  
23 83 %ul.well-list.issues-list
24 84 = render @issues
... ...
vendor/assets/javascripts/jquery.blockUI.js 0 → 100644
... ... @@ -0,0 +1,590 @@
  1 +/*!
  2 + * jQuery blockUI plugin
  3 + * Version 2.60.0-2013.04.05
  4 + * @requires jQuery v1.7 or later
  5 + *
  6 + * Examples at: http://malsup.com/jquery/block/
  7 + * Copyright (c) 2007-2013 M. Alsup
  8 + * Dual licensed under the MIT and GPL licenses:
  9 + * http://www.opensource.org/licenses/mit-license.php
  10 + * http://www.gnu.org/licenses/gpl.html
  11 + *
  12 + * Thanks to Amir-Hossein Sobhi for some excellent contributions!
  13 + */
  14 +
  15 +;(function() {
  16 +/*jshint eqeqeq:false curly:false latedef:false */
  17 +"use strict";
  18 +
  19 + function setup($) {
  20 + $.fn._fadeIn = $.fn.fadeIn;
  21 +
  22 + var noOp = $.noop || function() {};
  23 +
  24 + // this bit is to ensure we don't call setExpression when we shouldn't (with extra muscle to handle
  25 + // retarded userAgent strings on Vista)
  26 + var msie = /MSIE/.test(navigator.userAgent);
  27 + var ie6 = /MSIE 6.0/.test(navigator.userAgent) && ! /MSIE 8.0/.test(navigator.userAgent);
  28 + var mode = document.documentMode || 0;
  29 + var setExpr = $.isFunction( document.createElement('div').style.setExpression );
  30 +
  31 + // global $ methods for blocking/unblocking the entire page
  32 + $.blockUI = function(opts) { install(window, opts); };
  33 + $.unblockUI = function(opts) { remove(window, opts); };
  34 +
  35 + // convenience method for quick growl-like notifications (http://www.google.com/search?q=growl)
  36 + $.growlUI = function(title, message, timeout, onClose) {
  37 + var $m = $('<div class="growlUI"></div>');
  38 + if (title) $m.append('<h1>'+title+'</h1>');
  39 + if (message) $m.append('<h2>'+message+'</h2>');
  40 + if (timeout === undefined) timeout = 3000;
  41 + $.blockUI({
  42 + message: $m, fadeIn: 700, fadeOut: 1000, centerY: false,
  43 + timeout: timeout, showOverlay: false,
  44 + onUnblock: onClose,
  45 + css: $.blockUI.defaults.growlCSS
  46 + });
  47 + };
  48 +
  49 + // plugin method for blocking element content
  50 + $.fn.block = function(opts) {
  51 + if ( this[0] === window ) {
  52 + $.blockUI( opts );
  53 + return this;
  54 + }
  55 + var fullOpts = $.extend({}, $.blockUI.defaults, opts || {});
  56 + this.each(function() {
  57 + var $el = $(this);
  58 + if (fullOpts.ignoreIfBlocked && $el.data('blockUI.isBlocked'))
  59 + return;
  60 + $el.unblock({ fadeOut: 0 });
  61 + });
  62 +
  63 + return this.each(function() {
  64 + if ($.css(this,'position') == 'static') {
  65 + this.style.position = 'relative';
  66 + $(this).data('blockUI.static', true);
  67 + }
  68 + this.style.zoom = 1; // force 'hasLayout' in ie
  69 + install(this, opts);
  70 + });
  71 + };
  72 +
  73 + // plugin method for unblocking element content
  74 + $.fn.unblock = function(opts) {
  75 + if ( this[0] === window ) {
  76 + $.unblockUI( opts );
  77 + return this;
  78 + }
  79 + return this.each(function() {
  80 + remove(this, opts);
  81 + });
  82 + };
  83 +
  84 + $.blockUI.version = 2.60; // 2nd generation blocking at no extra cost!
  85 +
  86 + // override these in your code to change the default behavior and style
  87 + $.blockUI.defaults = {
  88 + // message displayed when blocking (use null for no message)
  89 + message: '<h1>Please wait...</h1>',
  90 +
  91 + title: null, // title string; only used when theme == true
  92 + draggable: true, // only used when theme == true (requires jquery-ui.js to be loaded)
  93 +
  94 + theme: false, // set to true to use with jQuery UI themes
  95 +
  96 + // styles for the message when blocking; if you wish to disable
  97 + // these and use an external stylesheet then do this in your code:
  98 + // $.blockUI.defaults.css = {};
  99 + css: {
  100 + padding: 0,
  101 + margin: 0,
  102 + width: '30%',
  103 + top: '40%',
  104 + left: '35%',
  105 + textAlign: 'center',
  106 + color: '#000',
  107 + border: '3px solid #aaa',
  108 + backgroundColor:'#fff',
  109 + cursor: 'wait'
  110 + },
  111 +
  112 + // minimal style set used when themes are used
  113 + themedCSS: {
  114 + width: '30%',
  115 + top: '40%',
  116 + left: '35%'
  117 + },
  118 +
  119 + // styles for the overlay
  120 + overlayCSS: {
  121 + backgroundColor: '#000',
  122 + opacity: 0.6,
  123 + cursor: 'wait'
  124 + },
  125 +
  126 + // style to replace wait cursor before unblocking to correct issue
  127 + // of lingering wait cursor
  128 + cursorReset: 'default',
  129 +
  130 + // styles applied when using $.growlUI
  131 + growlCSS: {
  132 + width: '350px',
  133 + top: '10px',
  134 + left: '',
  135 + right: '10px',
  136 + border: 'none',
  137 + padding: '5px',
  138 + opacity: 0.6,
  139 + cursor: 'default',
  140 + color: '#fff',
  141 + backgroundColor: '#000',
  142 + '-webkit-border-radius':'10px',
  143 + '-moz-border-radius': '10px',
  144 + 'border-radius': '10px'
  145 + },
  146 +
  147 + // IE issues: 'about:blank' fails on HTTPS and javascript:false is s-l-o-w
  148 + // (hat tip to Jorge H. N. de Vasconcelos)
  149 + /*jshint scripturl:true */
  150 + iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank',
  151 +
  152 + // force usage of iframe in non-IE browsers (handy for blocking applets)
  153 + forceIframe: false,
  154 +
  155 + // z-index for the blocking overlay
  156 + baseZ: 1000,
  157 +
  158 + // set these to true to have the message automatically centered
  159 + centerX: true, // <-- only effects element blocking (page block controlled via css above)
  160 + centerY: true,
  161 +
  162 + // allow body element to be stetched in ie6; this makes blocking look better
  163 + // on "short" pages. disable if you wish to prevent changes to the body height
  164 + allowBodyStretch: true,
  165 +
  166 + // enable if you want key and mouse events to be disabled for content that is blocked
  167 + bindEvents: true,
  168 +
  169 + // be default blockUI will supress tab navigation from leaving blocking content
  170 + // (if bindEvents is true)
  171 + constrainTabKey: true,
  172 +
  173 + // fadeIn time in millis; set to 0 to disable fadeIn on block
  174 + fadeIn: 200,
  175 +
  176 + // fadeOut time in millis; set to 0 to disable fadeOut on unblock
  177 + fadeOut: 400,
  178 +
  179 + // time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock
  180 + timeout: 0,
  181 +
  182 + // disable if you don't want to show the overlay
  183 + showOverlay: true,
  184 +
  185 + // if true, focus will be placed in the first available input field when
  186 + // page blocking
  187 + focusInput: true,
  188 +
  189 + // elements that can receive focus
  190 + focusableElements: ':input:enabled:visible',
  191 +
  192 + // suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)
  193 + // no longer needed in 2012
  194 + // applyPlatformOpacityRules: true,
  195 +
  196 + // callback method invoked when fadeIn has completed and blocking message is visible
  197 + onBlock: null,
  198 +
  199 + // callback method invoked when unblocking has completed; the callback is
  200 + // passed the element that has been unblocked (which is the window object for page
  201 + // blocks) and the options that were passed to the unblock call:
  202 + // onUnblock(element, options)
  203 + onUnblock: null,
  204 +
  205 + // callback method invoked when the overlay area is clicked.
  206 + // setting this will turn the cursor to a pointer, otherwise cursor defined in overlayCss will be used.
  207 + onOverlayClick: null,
  208 +
  209 + // don't ask; if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493
  210 + quirksmodeOffsetHack: 4,
  211 +
  212 + // class name of the message block
  213 + blockMsgClass: 'blockMsg',
  214 +
  215 + // if it is already blocked, then ignore it (don't unblock and reblock)
  216 + ignoreIfBlocked: false
  217 + };
  218 +
  219 + // private data and functions follow...
  220 +
  221 + var pageBlock = null;
  222 + var pageBlockEls = [];
  223 +
  224 + function install(el, opts) {
  225 + var css, themedCSS;
  226 + var full = (el == window);
  227 + var msg = (opts && opts.message !== undefined ? opts.message : undefined);
  228 + opts = $.extend({}, $.blockUI.defaults, opts || {});
  229 +
  230 + if (opts.ignoreIfBlocked && $(el).data('blockUI.isBlocked'))
  231 + return;
  232 +
  233 + opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});
  234 + css = $.extend({}, $.blockUI.defaults.css, opts.css || {});
  235 + if (opts.onOverlayClick)
  236 + opts.overlayCSS.cursor = 'pointer';
  237 +
  238 + themedCSS = $.extend({}, $.blockUI.defaults.themedCSS, opts.themedCSS || {});
  239 + msg = msg === undefined ? opts.message : msg;
  240 +
  241 + // remove the current block (if there is one)
  242 + if (full && pageBlock)
  243 + remove(window, {fadeOut:0});
  244 +
  245 + // if an existing element is being used as the blocking content then we capture
  246 + // its current place in the DOM (and current display style) so we can restore
  247 + // it when we unblock
  248 + if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {
  249 + var node = msg.jquery ? msg[0] : msg;
  250 + var data = {};
  251 + $(el).data('blockUI.history', data);
  252 + data.el = node;
  253 + data.parent = node.parentNode;
  254 + data.display = node.style.display;
  255 + data.position = node.style.position;
  256 + if (data.parent)
  257 + data.parent.removeChild(node);
  258 + }
  259 +
  260 + $(el).data('blockUI.onUnblock', opts.onUnblock);
  261 + var z = opts.baseZ;
  262 +
  263 + // blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;
  264 + // layer1 is the iframe layer which is used to supress bleed through of underlying content
  265 + // layer2 is the overlay layer which has opacity and a wait cursor (by default)
  266 + // layer3 is the message content that is displayed while blocking
  267 + var lyr1, lyr2, lyr3, s;
  268 + if (msie || opts.forceIframe)
  269 + lyr1 = $('<iframe class="blockUI" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0" src="'+opts.iframeSrc+'"></iframe>');
  270 + else
  271 + lyr1 = $('<div class="blockUI" style="display:none"></div>');
  272 +
  273 + if (opts.theme)
  274 + lyr2 = $('<div class="blockUI blockOverlay ui-widget-overlay" style="z-index:'+ (z++) +';display:none"></div>');
  275 + else
  276 + lyr2 = $('<div class="blockUI blockOverlay" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>');
  277 +
  278 + if (opts.theme && full) {
  279 + s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:fixed">';
  280 + if ( opts.title ) {
  281 + s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || '&nbsp;')+'</div>';
  282 + }
  283 + s += '<div class="ui-widget-content ui-dialog-content"></div>';
  284 + s += '</div>';
  285 + }
  286 + else if (opts.theme) {
  287 + s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:absolute">';
  288 + if ( opts.title ) {
  289 + s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || '&nbsp;')+'</div>';
  290 + }
  291 + s += '<div class="ui-widget-content ui-dialog-content"></div>';
  292 + s += '</div>';
  293 + }
  294 + else if (full) {
  295 + s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage" style="z-index:'+(z+10)+';display:none;position:fixed"></div>';
  296 + }
  297 + else {
  298 + s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement" style="z-index:'+(z+10)+';display:none;position:absolute"></div>';
  299 + }
  300 + lyr3 = $(s);
  301 +
  302 + // if we have a message, style it
  303 + if (msg) {
  304 + if (opts.theme) {
  305 + lyr3.css(themedCSS);
  306 + lyr3.addClass('ui-widget-content');
  307 + }
  308 + else
  309 + lyr3.css(css);
  310 + }
  311 +
  312 + // style the overlay
  313 + if (!opts.theme /*&& (!opts.applyPlatformOpacityRules)*/)
  314 + lyr2.css(opts.overlayCSS);
  315 + lyr2.css('position', full ? 'fixed' : 'absolute');
  316 +
  317 + // make iframe layer transparent in IE
  318 + if (msie || opts.forceIframe)
  319 + lyr1.css('opacity',0.0);
  320 +
  321 + //$([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);
  322 + var layers = [lyr1,lyr2,lyr3], $par = full ? $('body') : $(el);
  323 + $.each(layers, function() {
  324 + this.appendTo($par);
  325 + });
  326 +
  327 + if (opts.theme && opts.draggable && $.fn.draggable) {
  328 + lyr3.draggable({
  329 + handle: '.ui-dialog-titlebar',
  330 + cancel: 'li'
  331 + });
  332 + }
  333 +
  334 + // ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)
  335 + var expr = setExpr && (!$.support.boxModel || $('object,embed', full ? null : el).length > 0);
  336 + if (ie6 || expr) {
  337 + // give body 100% height
  338 + if (full && opts.allowBodyStretch && $.support.boxModel)
  339 + $('html,body').css('height','100%');
  340 +
  341 + // fix ie6 issue when blocked element has a border width
  342 + if ((ie6 || !$.support.boxModel) && !full) {
  343 + var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');
  344 + var fixT = t ? '(0 - '+t+')' : 0;
  345 + var fixL = l ? '(0 - '+l+')' : 0;
  346 + }
  347 +
  348 + // simulate fixed position
  349 + $.each(layers, function(i,o) {
  350 + var s = o[0].style;
  351 + s.position = 'absolute';
  352 + if (i < 2) {
  353 + if (full)
  354 + s.setExpression('height','Math.max(document.body.scrollHeight, document.body.offsetHeight) - (jQuery.support.boxModel?0:'+opts.quirksmodeOffsetHack+') + "px"');
  355 + else
  356 + s.setExpression('height','this.parentNode.offsetHeight + "px"');
  357 + if (full)
  358 + s.setExpression('width','jQuery.support.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"');
  359 + else
  360 + s.setExpression('width','this.parentNode.offsetWidth + "px"');
  361 + if (fixL) s.setExpression('left', fixL);
  362 + if (fixT) s.setExpression('top', fixT);
  363 + }
  364 + else if (opts.centerY) {
  365 + if (full) s.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');
  366 + s.marginTop = 0;
  367 + }
  368 + else if (!opts.centerY && full) {
  369 + var top = (opts.css && opts.css.top) ? parseInt(opts.css.top, 10) : 0;
  370 + var expression = '((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"';
  371 + s.setExpression('top',expression);
  372 + }
  373 + });
  374 + }
  375 +
  376 + // show the message
  377 + if (msg) {
  378 + if (opts.theme)
  379 + lyr3.find('.ui-widget-content').append(msg);
  380 + else
  381 + lyr3.append(msg);
  382 + if (msg.jquery || msg.nodeType)
  383 + $(msg).show();
  384 + }
  385 +
  386 + if ((msie || opts.forceIframe) && opts.showOverlay)
  387 + lyr1.show(); // opacity is zero
  388 + if (opts.fadeIn) {
  389 + var cb = opts.onBlock ? opts.onBlock : noOp;
  390 + var cb1 = (opts.showOverlay && !msg) ? cb : noOp;
  391 + var cb2 = msg ? cb : noOp;
  392 + if (opts.showOverlay)
  393 + lyr2._fadeIn(opts.fadeIn, cb1);
  394 + if (msg)
  395 + lyr3._fadeIn(opts.fadeIn, cb2);
  396 + }
  397 + else {
  398 + if (opts.showOverlay)
  399 + lyr2.show();
  400 + if (msg)
  401 + lyr3.show();
  402 + if (opts.onBlock)
  403 + opts.onBlock();
  404 + }
  405 +
  406 + // bind key and mouse events
  407 + bind(1, el, opts);
  408 +
  409 + if (full) {
  410 + pageBlock = lyr3[0];
  411 + pageBlockEls = $(opts.focusableElements,pageBlock);
  412 + if (opts.focusInput)
  413 + setTimeout(focus, 20);
  414 + }
  415 + else
  416 + center(lyr3[0], opts.centerX, opts.centerY);
  417 +
  418 + if (opts.timeout) {
  419 + // auto-unblock
  420 + var to = setTimeout(function() {
  421 + if (full)
  422 + $.unblockUI(opts);
  423 + else
  424 + $(el).unblock(opts);
  425 + }, opts.timeout);
  426 + $(el).data('blockUI.timeout', to);
  427 + }
  428 + }
  429 +
  430 + // remove the block
  431 + function remove(el, opts) {
  432 + var count;
  433 + var full = (el == window);
  434 + var $el = $(el);
  435 + var data = $el.data('blockUI.history');
  436 + var to = $el.data('blockUI.timeout');
  437 + if (to) {
  438 + clearTimeout(to);
  439 + $el.removeData('blockUI.timeout');
  440 + }
  441 + opts = $.extend({}, $.blockUI.defaults, opts || {});
  442 + bind(0, el, opts); // unbind events
  443 +
  444 + if (opts.onUnblock === null) {
  445 + opts.onUnblock = $el.data('blockUI.onUnblock');
  446 + $el.removeData('blockUI.onUnblock');
  447 + }
  448 +
  449 + var els;
  450 + if (full) // crazy selector to handle odd field errors in ie6/7
  451 + els = $('body').children().filter('.blockUI').add('body > .blockUI');
  452 + else
  453 + els = $el.find('>.blockUI');
  454 +
  455 + // fix cursor issue
  456 + if ( opts.cursorReset ) {
  457 + if ( els.length > 1 )
  458 + els[1].style.cursor = opts.cursorReset;
  459 + if ( els.length > 2 )
  460 + els[2].style.cursor = opts.cursorReset;
  461 + }
  462 +
  463 + if (full)
  464 + pageBlock = pageBlockEls = null;
  465 +
  466 + if (opts.fadeOut) {
  467 + count = els.length;
  468 + els.fadeOut(opts.fadeOut, function() {
  469 + if ( --count === 0)
  470 + reset(els,data,opts,el);
  471 + });
  472 + }
  473 + else
  474 + reset(els, data, opts, el);
  475 + }
  476 +
  477 + // move blocking element back into the DOM where it started
  478 + function reset(els,data,opts,el) {
  479 + var $el = $(el);
  480 + els.each(function(i,o) {
  481 + // remove via DOM calls so we don't lose event handlers
  482 + if (this.parentNode)
  483 + this.parentNode.removeChild(this);
  484 + });
  485 +
  486 + if (data && data.el) {
  487 + data.el.style.display = data.display;
  488 + data.el.style.position = data.position;
  489 + if (data.parent)
  490 + data.parent.appendChild(data.el);
  491 + $el.removeData('blockUI.history');
  492 + }
  493 +
  494 + if ($el.data('blockUI.static')) {
  495 + $el.css('position', 'static'); // #22
  496 + }
  497 +
  498 + if (typeof opts.onUnblock == 'function')
  499 + opts.onUnblock(el,opts);
  500 +
  501 + // fix issue in Safari 6 where block artifacts remain until reflow
  502 + var body = $(document.body), w = body.width(), cssW = body[0].style.width;
  503 + body.width(w-1).width(w);
  504 + body[0].style.width = cssW;
  505 + }
  506 +
  507 + // bind/unbind the handler
  508 + function bind(b, el, opts) {
  509 + var full = el == window, $el = $(el);
  510 +
  511 + // don't bother unbinding if there is nothing to unbind
  512 + if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked')))
  513 + return;
  514 +
  515 + $el.data('blockUI.isBlocked', b);
  516 +
  517 + // don't bind events when overlay is not in use or if bindEvents is false
  518 + if (!full || !opts.bindEvents || (b && !opts.showOverlay))
  519 + return;
  520 +
  521 + // bind anchors and inputs for mouse and key events
  522 + var events = 'mousedown mouseup keydown keypress keyup touchstart touchend touchmove';
  523 + if (b)
  524 + $(document).bind(events, opts, handler);
  525 + else
  526 + $(document).unbind(events, handler);
  527 +
  528 + // former impl...
  529 + // var $e = $('a,:input');
  530 + // b ? $e.bind(events, opts, handler) : $e.unbind(events, handler);
  531 + }
  532 +
  533 + // event handler to suppress keyboard/mouse events when blocking
  534 + function handler(e) {
  535 + // allow tab navigation (conditionally)
  536 + if (e.keyCode && e.keyCode == 9) {
  537 + if (pageBlock && e.data.constrainTabKey) {
  538 + var els = pageBlockEls;
  539 + var fwd = !e.shiftKey && e.target === els[els.length-1];
  540 + var back = e.shiftKey && e.target === els[0];
  541 + if (fwd || back) {
  542 + setTimeout(function(){focus(back);},10);
  543 + return false;
  544 + }
  545 + }
  546 + }
  547 + var opts = e.data;
  548 + var target = $(e.target);
  549 + if (target.hasClass('blockOverlay') && opts.onOverlayClick)
  550 + opts.onOverlayClick();
  551 +
  552 + // allow events within the message content
  553 + if (target.parents('div.' + opts.blockMsgClass).length > 0)
  554 + return true;
  555 +
  556 + // allow events for content that is not being blocked
  557 + return target.parents().children().filter('div.blockUI').length === 0;
  558 + }
  559 +
  560 + function focus(back) {
  561 + if (!pageBlockEls)
  562 + return;
  563 + var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];
  564 + if (e)
  565 + e.focus();
  566 + }
  567 +
  568 + function center(el, x, y) {
  569 + var p = el.parentNode, s = el.style;
  570 + var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');
  571 + var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');
  572 + if (x) s.left = l > 0 ? (l+'px') : '0';
  573 + if (y) s.top = t > 0 ? (t+'px') : '0';
  574 + }
  575 +
  576 + function sz(el, p) {
  577 + return parseInt($.css(el,p),10)||0;
  578 + }
  579 +
  580 + }
  581 +
  582 +
  583 + /*global define:true */
  584 + if (typeof define === 'function' && define.amd && define.amd.jQuery) {
  585 + define(['jquery'], setup);
  586 + } else {
  587 + setup(jQuery);
  588 + }
  589 +
  590 +})();
... ...