提交 f8a8999a 编写于 作者: P Phil Hughes

Cached jQuery selectors

上级 04c199a0
...@@ -47,40 +47,41 @@ class @Sidebar ...@@ -47,40 +47,41 @@ class @Sidebar
.off 'click', '.js-issuable-todo' .off 'click', '.js-issuable-todo'
.on 'click', '.js-issuable-todo', @toggleTodo .on 'click', '.js-issuable-todo', @toggleTodo
toggleTodo: (e) -> toggleTodo: ->
$this = $(@) $this = $(@)
$btnText = $this.find('span') $todoLoading = $('.js-issuable-todo-loading')
data = { $btnText = $('.js-issuable-todo-text', $this)
todo_id: $this.attr('data-id')
}
$.ajax( $.ajax(
url: $this.data('url') url: $this.data('url')
type: 'POST' type: 'POST'
dataType: 'json' dataType: 'json'
data: data data:
todo_id: $this.attr('data-id')
beforeSend: -> beforeSend: ->
$this.disable() $this.disable()
$('.js-issuable-todo-loading').removeClass 'hidden' $todoLoading.removeClass 'hidden'
).done (data) -> ).done (data) ->
$todoPendingCount = $('.todos-pending-count') $todoPendingCount = $('.todos-pending-count')
$todoPendingCount.text data.count $todoPendingCount.text data.count
$this.enable() $this.enable()
$('.js-issuable-todo-loading').addClass 'hidden' $todoLoading.addClass 'hidden'
if data.count is 0 if data.count is 0
$todoPendingCount $todoPendingCount.addClass 'hidden'
.addClass 'hidden'
else else
$todoPendingCount $todoPendingCount.removeClass 'hidden'
.removeClass 'hidden'
if data.todo? if data.todo?
$this
.attr 'aria-label', $this.data('mark-text')
.attr 'data-id', data.todo.id
$btnText.text $this.data('mark-text') $btnText.text $this.data('mark-text')
$this.attr 'data-id', data.todo.id
else else
$this.removeAttr 'data-id' $this
.attr 'aria-label', $this.data('todo-text')
.removeAttr 'data-id'
$btnText.text $this.data('todo-text') $btnText.text $this.data('todo-text')
sidebarDropdownLoading: (e) -> sidebarDropdownLoading: (e) ->
......
...@@ -9,12 +9,11 @@ ...@@ -9,12 +9,11 @@
%a.gutter-toggle.pull-right.js-sidebar-toggle{ role: "button", href: "#", aria: { label: "Toggle sidebar" } } %a.gutter-toggle.pull-right.js-sidebar-toggle{ role: "button", href: "#", aria: { label: "Toggle sidebar" } }
= sidebar_gutter_toggle_icon = sidebar_gutter_toggle_icon
- if current_user - if current_user
%button.btn.btn-default.issuable-header-btn.pull-right.js-issuable-todo{ type: "button", data: { todo_text: "Add Todo", mark_text: "Mark Done", id: (todo.id unless todo.nil?), url: issuable_todo_path(issuable) } } %button.btn.btn-default.issuable-header-btn.pull-right.js-issuable-todo{ type: "button", aria: { label: (todo.nil? ? "Add Todo" : "Mark Done") }, data: { todo_text: "Add Todo", mark_text: "Mark Done", id: (todo.id unless todo.nil?), url: issuable_todo_path(issuable) } }
- if todo.nil? %span.js-issuable-todo-text
%span - if todo.nil?
Add Todo Add Todo
- else - else
%span
Mark Done Mark Done
= icon('spin spinner', class: 'hidden js-issuable-todo-loading') = icon('spin spinner', class: 'hidden js-issuable-todo-loading')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册