From b02ac54547f6aafb1610834114acbdcb5c3756e6 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 24 Aug 2012 22:31:36 +0200 Subject: [PATCH] Moved back to javascript of bootstrap 2.0.4. --- .../_application_controller.js.coffee | 41 ++-- .../app/controllers/user_info.js.coffee | 4 +- .../javascripts/app/lib/bootstrap-dropdown.js | 84 ++------ .../javascripts/app/lib/bootstrap-modal.js | 181 ++++++++---------- .../javascripts/app/lib/bootstrap-popover.js | 13 +- .../javascripts/app/lib/bootstrap-tab.js | 4 +- .../javascripts/app/lib/bootstrap-tooltip.js | 30 +-- .../app/lib/bootstrap-transition.js | 5 +- 8 files changed, 144 insertions(+), 218 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index bf0201aa0..1869a767c 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -560,7 +560,7 @@ class App.Controller extends Spine.Controller clearInterval( @intervalID[interval_id] ) if @intervalID[interval_id] interval: (action, interval, interval_id) => - + # check global var if !@intervalID @intervalID = {} @@ -587,12 +587,12 @@ class App.Controller extends Spine.Controller delay: { show: 500, hide: 1200 }, # placement: 'bottom', placement: position, - title: (e) => - user_id = $(e).data('id') + title: -> + user_id = $(@).data('id') user = App.User.find(user_id) (user.firstname || '') + ' ' + (user.lastname || '') - content: (e) => - user_id = $(e).data('id') + content: -> + user_id = $(@).data('id') user = App.User.find(user_id) # get display data @@ -608,7 +608,7 @@ class App.Controller extends Spine.Controller App.view('user_info_small')( user: user, data: data, - ) + ) ) userTicketPopups: (data) -> @@ -617,7 +617,7 @@ class App.Controller extends Spine.Controller $('.popover-inner').parent().remove() # get data - @tickets = {} + tickets = {} App.Com.ajax( type: 'GET', url: '/ticket_customer', @@ -626,36 +626,37 @@ class App.Controller extends Spine.Controller } processData: true, success: (data, status, xhr) => - @tickets = data.tickets + tickets = data.tickets ) if !data.position data.position = 'left' - - # show user popup + + # show user popup + controller = @ $(data.selector).popover( delay: { show: 500, hide: 5200 }, placement: data.position, - title: (e) => - $(e).find('[title="*"]').val() - - content: (e) => - type = $(e).filter('[data-type]').data('type') - data = @tickets[type] || [] + title: -> + $(@).find('[title="*"]').val() + + content: -> + type = $(@).filter('[data-type]').data('type') + data = tickets[type] || [] for ticket in data - + # set human time - ticket.humanTime = @humanTime(ticket.created_at) + ticket.humanTime = controller.humanTime(ticket.created_at) # insert data App.view('user_ticket_info_small')( tickets: data, - ) + ) ) loadCollection: (params) -> - + # users if params.type == 'User' for user_id, user of params.data diff --git a/app/assets/javascripts/app/controllers/user_info.js.coffee b/app/assets/javascripts/app/controllers/user_info.js.coffee index d4af1c8a8..11bf1a91c 100644 --- a/app/assets/javascripts/app/controllers/user_info.js.coffee +++ b/app/assets/javascripts/app/controllers/user_info.js.coffee @@ -42,14 +42,14 @@ class App.UserInfo extends App.Controller user: App.User.find(user_id), data: data, ) - + @userTicketPopups( selector: '.user-tickets', user_id: user_id, ) update: (e) => - + # update changes note = $(e.target).parent().find('[data-type=edit]').val() user = App.User.find(@user_id) diff --git a/app/assets/javascripts/app/lib/bootstrap-dropdown.js b/app/assets/javascripts/app/lib/bootstrap-dropdown.js index 7b9356952..454a9684b 100644 --- a/app/assets/javascripts/app/lib/bootstrap-dropdown.js +++ b/app/assets/javascripts/app/lib/bootstrap-dropdown.js @@ -1,5 +1,5 @@ /* ============================================================ - * bootstrap-dropdown.js v2.1.0 + * bootstrap-dropdown.js v2.0.4 * http://twitter.github.com/bootstrap/javascript.html#dropdowns * ============================================================ * Copyright 2012 Twitter, Inc. @@ -26,7 +26,7 @@ /* DROPDOWN CLASS DEFINITION * ========================= */ - var toggle = '[data-toggle=dropdown]' + var toggle = '[data-toggle="dropdown"]' , Dropdown = function (element) { var $el = $(element).on('click.dropdown.data-api', this.toggle) $('html').on('click.dropdown.data-api', function () { @@ -41,82 +41,34 @@ , toggle: function (e) { var $this = $(this) , $parent + , selector , isActive if ($this.is('.disabled, :disabled')) return - $parent = getParent($this) + selector = $this.attr('data-target') + + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 + } + + $parent = $(selector) + $parent.length || ($parent = $this.parent()) isActive = $parent.hasClass('open') clearMenus() - if (!isActive) { - $parent.toggleClass('open') - $this.focus() - } + if (!isActive) $parent.toggleClass('open') return false } - , keydown: function (e) { - var $this - , $items - , $active - , $parent - , isActive - , index - - if (!/(38|40|27)/.test(e.keyCode)) return - - $this = $(this) - - e.preventDefault() - e.stopPropagation() - - if ($this.is('.disabled, :disabled')) return - - $parent = getParent($this) - - isActive = $parent.hasClass('open') - - if (!isActive || (isActive && e.keyCode == 27)) return $this.click() - - $items = $('[role=menu] li:not(.divider) a', $parent) - - if (!$items.length) return - - index = $items.index($items.filter(':focus')) - - if (e.keyCode == 38 && index > 0) index-- // up - if (e.keyCode == 40 && index < $items.length - 1) index++ // down - if (!~index) index = 0 - - $items - .eq(index) - .focus() - } - } function clearMenus() { - getParent($(toggle)) - } - - function getParent($this) { - var selector = $this.attr('data-target') - , $parent - - if (!selector) { - selector = $this.attr('href') - selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 - } - selector.replace(/\//, '\/\/') - - $parent = $(selector) - $parent.length || ($parent = $this.parent()) - - return $parent + $(toggle).parent().removeClass('open') } @@ -139,12 +91,10 @@ * =================================== */ $(function () { - $('html') - .on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus) + $('html').on('click.dropdown.data-api', clearMenus) $('body') - .on('click.dropdown touchstart.dropdown.data-api', '.dropdown', function (e) { e.stopPropagation() }) - .on('click.dropdown.data-api touchstart.dropdown.data-api' , toggle, Dropdown.prototype.toggle) - .on('keydown.dropdown.data-api touchstart.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) + .on('click.dropdown', '.dropdown form', function (e) { e.stopPropagation() }) + .on('click.dropdown.data-api', toggle, Dropdown.prototype.toggle) }) }(window.jQuery); \ No newline at end of file diff --git a/app/assets/javascripts/app/lib/bootstrap-modal.js b/app/assets/javascripts/app/lib/bootstrap-modal.js index 62fbc951b..38fd0c846 100644 --- a/app/assets/javascripts/app/lib/bootstrap-modal.js +++ b/app/assets/javascripts/app/lib/bootstrap-modal.js @@ -1,5 +1,5 @@ /* ========================================================= - * bootstrap-modal.js v2.1.0 + * bootstrap-modal.js v2.0.4 * http://twitter.github.com/bootstrap/javascript.html#modals * ========================================================= * Copyright 2012 Twitter, Inc. @@ -26,11 +26,10 @@ /* MODAL CLASS DEFINITION * ====================== */ - var Modal = function (element, options) { + var Modal = function (content, options) { this.options = options - this.$element = $(element) + this.$element = $(content) .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this)) - this.options.remote && this.$element.find('.modal-body').load(this.options.remote) } Modal.prototype = { @@ -53,9 +52,8 @@ this.isShown = true - this.escape() - - this.backdrop(function () { + escape.call(this) + backdrop.call(this, function () { var transition = $.support.transition && that.$element.hasClass('fade') if (!that.$element.parent().length) { @@ -69,12 +67,7 @@ that.$element[0].offsetWidth // force reflow } - that.$element - .addClass('in') - .attr('aria-hidden', false) - .focus() - - that.enforceFocus() + that.$element.addClass('in') transition ? that.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) : @@ -98,98 +91,90 @@ $('body').removeClass('modal-open') - this.escape() + escape.call(this) - $(document).off('focusin.modal') - - this.$element - .removeClass('in') - .attr('aria-hidden', true) + this.$element.removeClass('in') $.support.transition && this.$element.hasClass('fade') ? - this.hideWithTransition() : - this.hideModal() + hideWithTransition.call(this) : + hideModal.call(this) } - , enforceFocus: function () { - var that = this - $(document).on('focusin.modal', function (e) { - if (that.$element[0] !== e.target && !that.$element.has(e.target).length) { - that.$element.focus() - } - }) + } + + + /* MODAL PRIVATE METHODS + * ===================== */ + + function hideWithTransition() { + var that = this + , timeout = setTimeout(function () { + that.$element.off($.support.transition.end) + hideModal.call(that) + }, 500) + + this.$element.one($.support.transition.end, function () { + clearTimeout(timeout) + hideModal.call(that) + }) + } + + function hideModal(that) { + this.$element + .hide() + .trigger('hidden') + + backdrop.call(this) + } + + function backdrop(callback) { + var that = this + , animate = this.$element.hasClass('fade') ? 'fade' : '' + + if (this.isShown && this.options.backdrop) { + var doAnimate = $.support.transition && animate + + this.$backdrop = $('