Custom board title fixes.
- Fix multiline titles. - Deleting the custom title restores the original one. - Some refactoring.
This commit is contained in:
parent
9e1f2b4d0c
commit
da816661b5
@ -1503,6 +1503,9 @@ a:only-of-type > .remove {
|
|||||||
text-decoration: none !important;
|
text-decoration: none !important;
|
||||||
}
|
}
|
||||||
/* Custom Board Titles */
|
/* Custom Board Titles */
|
||||||
|
.boardTitle, .boardSubtitle {
|
||||||
|
white-space: pre-line;
|
||||||
|
}
|
||||||
.boardTitle[contenteditable="true"],
|
.boardTitle[contenteditable="true"],
|
||||||
.boardSubtitle[contenteditable="true"] {
|
.boardSubtitle[contenteditable="true"] {
|
||||||
cursor: text !important;
|
cursor: text !important;
|
||||||
|
|||||||
@ -16,21 +16,12 @@ Banner =
|
|||||||
if g.BOARD.ID isnt 'f' and g.VIEW is 'thread' and Conf['Remove Thread Excerpt']
|
if g.BOARD.ID isnt 'f' and g.VIEW is 'thread' and Conf['Remove Thread Excerpt']
|
||||||
Banner.setTitle children[1].textContent
|
Banner.setTitle children[1].textContent
|
||||||
|
|
||||||
for child, i in children
|
children[0].title = "Click to change"
|
||||||
if i is 0
|
$.on children[0], 'click', Banner.cb.toggle
|
||||||
child.title = "Click to change"
|
|
||||||
$.on child, 'click', Banner.cb.toggle
|
|
||||||
|
|
||||||
continue
|
if Conf['Custom Board Titles']
|
||||||
|
Banner.custom children[1]
|
||||||
if Conf['Custom Board Titles']
|
Banner.custom children[2] if children[2]
|
||||||
Banner.custom(child).title = "Ctrl/\u2318+click to edit board #{if i is 2
|
|
||||||
'sub'
|
|
||||||
else
|
|
||||||
''}title"
|
|
||||||
child.spellcheck = false
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
load: ->
|
load: ->
|
||||||
bannerCnt = $.id 'bannerCnt'
|
bannerCnt = $.id 'bannerCnt'
|
||||||
@ -56,41 +47,49 @@ Banner =
|
|||||||
$('img', @parentNode).src = "//s.4cdn.org/image/title/#{banner}"
|
$('img', @parentNode).src = "//s.4cdn.org/image/title/#{banner}"
|
||||||
|
|
||||||
click: (e) ->
|
click: (e) ->
|
||||||
if e.ctrlKey or e.metaKey
|
return unless (e.ctrlKey or e.metaKey) and @className in ['boardTitle', 'boardSubtitle']
|
||||||
@contentEditable = true
|
|
||||||
@focus()
|
unless Banner.original[@className]
|
||||||
|
Banner.original[@className] = @cloneNode true
|
||||||
|
$.set "#{g.BOARD}.#{@className}.orig", @textContent
|
||||||
|
|
||||||
|
@contentEditable = true
|
||||||
|
$.replace br, $.tn('\n') for br in $$ 'br', @
|
||||||
|
@focus()
|
||||||
|
|
||||||
keydown: (e) ->
|
keydown: (e) ->
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
return @blur() if !e.shiftKey and e.keyCode is 13
|
return @blur() if !e.shiftKey and e.keyCode is 13
|
||||||
|
|
||||||
focus: ->
|
|
||||||
string = "#{g.BOARD}.#{@className}"
|
|
||||||
string2 = "#{string}.orig"
|
|
||||||
|
|
||||||
items = {title: @textContent}
|
|
||||||
items[string] = ''
|
|
||||||
items[string2] = false
|
|
||||||
|
|
||||||
$.get items, (items) ->
|
|
||||||
unless items[string2] and items.title is items[string]
|
|
||||||
$.set string2, items.title
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
blur: ->
|
blur: ->
|
||||||
@contentEditable = false
|
return unless @className in ['boardTitle', 'boardSubtitle']
|
||||||
$.set "#{g.BOARD}.#{@className}", @textContent
|
|
||||||
|
if @textContent
|
||||||
|
@contentEditable = false
|
||||||
|
$.set "#{g.BOARD}.#{@className}", @textContent
|
||||||
|
else
|
||||||
|
$.rmAll @
|
||||||
|
$.add @, [Banner.original[@className].cloneNode(true).childNodes...]
|
||||||
|
$.delete "#{g.BOARD}.#{@className}"
|
||||||
|
|
||||||
|
original: {}
|
||||||
|
|
||||||
custom: (child) ->
|
custom: (child) ->
|
||||||
|
{className} = child
|
||||||
|
return unless className in ['boardTitle', 'boardSubtitle']
|
||||||
|
|
||||||
|
child.title = "Ctrl/\u2318+click to edit board #{className[5..].toLowerCase()}"
|
||||||
|
child.spellcheck = false
|
||||||
|
|
||||||
|
for event in ['click', 'keydown', 'blur']
|
||||||
|
$.on child, event, Banner.cb[event]
|
||||||
|
|
||||||
cachedTest = child.textContent
|
cachedTest = child.textContent
|
||||||
string = "#{g.BOARD}.#{child.className}"
|
string = "#{g.BOARD}.#{className}"
|
||||||
|
|
||||||
$.on child, 'click keydown focus blur', (e) -> Banner.cb[e.type].apply @, [e]
|
$.get string, '', (item) ->
|
||||||
|
|
||||||
$.get string, cachedTest, (item) ->
|
|
||||||
return unless title = item[string]
|
return unless title = item[string]
|
||||||
return if title is cachedTest
|
Banner.original[className] ?= child.cloneNode true
|
||||||
return child.textContent = title if Conf['Persistent Custom Board Titles']
|
return child.textContent = title if Conf['Persistent Custom Board Titles']
|
||||||
|
|
||||||
string2 = "#{string}.orig"
|
string2 = "#{string}.orig"
|
||||||
@ -99,7 +98,5 @@ Banner =
|
|||||||
if cachedTest is itemb[string2]
|
if cachedTest is itemb[string2]
|
||||||
child.textContent = title
|
child.textContent = title
|
||||||
else
|
else
|
||||||
$.set string, cachedTest
|
$.delete string
|
||||||
$.set string2, cachedTest
|
$.set string2, cachedTest
|
||||||
|
|
||||||
child
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user