Create (hopefully) more intuitive change selector

This commit is contained in:
James Allen 2014-03-10 13:09:40 +00:00
parent ceca16e507
commit 417d76ab3f
4 changed files with 152 additions and 9 deletions

View file

@ -435,6 +435,7 @@
script(type='text/template')#changeListItemTemplate script(type='text/template')#changeListItemTemplate
div(class='change-selectors') div(class='change-selectors')
div.range
input(type="radio",name="fromVersion").change-selector-from input(type="radio",name="fromVersion").change-selector-from
input(type="radio",name="toVersion").change-selector-to input(type="radio",name="toVersion").change-selector-to

View file

@ -54,12 +54,42 @@ define [
@resetAllSelectors() @resetAllSelectors()
@triggerChangeDiff() @triggerChangeDiff()
view.on "mouseenter:to", (e) =>
@hoverToIndex = index
@resetHoverStates()
view.on "mouseleave:to", (e) =>
delete @hoverToIndex
@resetHoverStates()
view.on "mouseenter:from", (e) =>
@hoverFromIndex = index
@resetHoverStates()
view.on "mouseleave:from", (e) =>
delete @hoverFromIndex
@resetHoverStates()
view.resetSelector(index, @selectedFromIndex, @selectedToIndex) view.resetSelector(index, @selectedFromIndex, @selectedToIndex)
resetAllSelectors: () -> resetAllSelectors: () ->
for view, i in @itemViews for view, i in @itemViews
view.resetSelector(i, @selectedFromIndex, @selectedToIndex) view.resetSelector(i, @selectedFromIndex, @selectedToIndex)
resetHoverStates: () ->
if @hoverToIndex?
@$("ul").addClass("hover-state")
for view, i in @itemViews
view.resetHoverState(i, @selectedFromIndex, @hoverToIndex)
else if @hoverFromIndex?
@$("ul").addClass("hover-state")
for view, i in @itemViews
view.resetHoverState(i, @hoverFromIndex, @selectedToIndex)
else
@$("ul").removeClass("hover-state")
for view, i in @itemViews
view.setHoverUnselected()
triggerChangeDiff: () -> triggerChangeDiff: () ->
@trigger "change_diff", @collection.models[@selectedFromIndex], @collection.models[@selectedToIndex] @trigger "change_diff", @collection.models[@selectedFromIndex], @collection.models[@selectedToIndex]
@ -114,6 +144,15 @@ define [
"click .change-description" : "onClick" "click .change-description" : "onClick"
"click .change-selector-from" : "onFromSelectorClick" "click .change-selector-from" : "onFromSelectorClick"
"click .change-selector-to" : "onToSelectorClick" "click .change-selector-to" : "onToSelectorClick"
"mouseenter .change-selector-to": (args...) ->
@trigger "mouseenter:to", args...
"mouseleave .change-selector-to": (args...) ->
@trigger "mouseleave:to", args...
"mouseenter .change-selector-from": (args...) ->
@trigger "mouseenter:from", args...
"mouseleave .change-selector-from": (args...) ->
@trigger "mouseleave:from", args...
template : $("#changeListItemTemplate").html() template : $("#changeListItemTemplate").html()
@ -168,12 +207,38 @@ define [
setToChecked: (checked) -> setToChecked: (checked) ->
@$(".change-selector-to").prop("checked", checked) @$(".change-selector-to").prop("checked", checked)
setSelected: () -> setSelected: (first, last) ->
@$el.addClass("selected") @$el.addClass("selected")
if first
@$el.addClass("selected-to")
else
@$el.removeClass("selected-to")
if last
@$el.addClass("selected-from")
else
@$el.removeClass("selected-from")
setUnselected: () -> setUnselected: () ->
@$el.removeClass("selected-to")
@$el.removeClass("selected-from")
@$el.removeClass("selected") @$el.removeClass("selected")
setHoverSelected: (first, last) ->
@$el.addClass("hover-selected")
if first
@$el.addClass("hover-selected-to")
else
@$el.removeClass("hover-selected-to")
if last
@$el.addClass("hover-selected-from")
else
@$el.removeClass("hover-selected-from")
setHoverUnselected: () ->
@$el.removeClass("hover-selected-to")
@$el.removeClass("hover-selected-from")
@$el.removeClass("hover-selected")
resetSelector: (myIndex, selectedFromIndex, selectedToIndex) -> resetSelector: (myIndex, selectedFromIndex, selectedToIndex) ->
if myIndex >= selectedToIndex if myIndex >= selectedToIndex
@showFromSelector() @showFromSelector()
@ -186,13 +251,19 @@ define [
@hideToSelector() @hideToSelector()
if selectedToIndex <= myIndex <= selectedFromIndex if selectedToIndex <= myIndex <= selectedFromIndex
@setSelected() @setSelected(selectedToIndex == myIndex, selectedFromIndex == myIndex)
else else
@setUnselected() @setUnselected()
@setFromChecked(myIndex == selectedFromIndex) @setFromChecked(myIndex == selectedFromIndex)
@setToChecked(myIndex == selectedToIndex) @setToChecked(myIndex == selectedToIndex)
resetHoverState: (myIndex, hoverFromIndex, hoverToIndex) ->
if hoverToIndex <= myIndex <= hoverFromIndex
@setHoverSelected(hoverToIndex == myIndex, hoverFromIndex == myIndex)
else
@setHoverUnselected()
return ChangeListView return ChangeListView

View file

@ -46,6 +46,7 @@ define [
column = 0 column = 0
for entry, i in @model.get("diff") or [] for entry, i in @model.get("diff") or []
content = entry.u or entry.i or entry.d content = entry.u or entry.i or entry.d
content ||= ""
lines = content.split("\n") lines = content.split("\n")
startRow = row startRow = row
startColumn = column startColumn = column

View file

@ -75,23 +75,30 @@
position: relative; position: relative;
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
cursor: pointer; cursor: pointer;
min-height: 38px;
.change-selectors { .change-selectors {
position: absolute;
top: 4px;
left: 6px;
.change-selector-from { .change-selector-from {
position: absolute; position: absolute;
top: 0; bottom: 5px;
left: 0; left: 8px;
opacity: 0.8;
} }
.change-selector-to { .change-selector-to {
position: absolute; position: absolute;
top: 5px;
left: 8px;
opacity: 0.8;
}
.range {
position: absolute;
left: 12px;
width: 4px;
top: 0; top: 0;
left: 20px; bottom: 0;
} }
} }
.change-description { .change-description {
padding-left: 42px; padding-left: 26px;
} }
.change-name { .change-name {
font-size: 0.9em; font-size: 0.9em;
@ -111,6 +118,69 @@
} }
li.selected { li.selected {
background-color: #eaeaea; background-color: #eaeaea;
.change-selectors {
.range {
background-color: rgb(0, 143, 255);
}
}
}
li.selected-to {
.change-selectors {
.range {
top: 10px;
}
.change-selector-to {
opacity: 1;
}
}
}
li.selected-from {
.change-selectors {
.range {
bottom: 10px;
}
.change-selector-from {
opacity: 1;
}
}
}
}
ul.change-list.hover-state {
li {
.change-selectors {
.range {
background-color: transparent;
top: 0;
bottom: 0;
}
}
}
li.hover-selected {
.change-selectors {
.range {
background-color: #999;
}
}
}
li.hover-selected-to {
.change-selectors {
.range {
top: 10px;
}
.change-selector-to {
opacity: 1;
}
}
}
li.hover-selected-from {
.change-selectors {
.range {
bottom: 10px;
}
.change-selector-from {
opacity: 1;
}
}
} }
} }
} }