Move 'Normalize URL' out of Main.coffee to feature list.

This commit is contained in:
ccd0 2015-11-07 22:14:06 -08:00
parent 5dc7b985ad
commit d7268d2518
2 changed files with 15 additions and 11 deletions

View File

@ -130,17 +130,6 @@ Main =
# set up CSS when <head> is completely loaded
$.onExists doc, 'body', false, Main.initStyle
if Conf['Normalize URL']
switch g.VIEW
when 'thread'
pathname[2] = 'thread'
pathname = pathname[0...4]
when 'index'
pathname = pathname[0...3]
pathname2 = pathname.join '/'
if location.pathname isnt pathname2
history.replaceState history.state, '', "#{location.protocol}//#{location.host}#{pathname2}#{location.hash}"
# c.time 'All initializations'
for [name, feature] in Main.features
# c.time "#{name} initialization"
@ -366,6 +355,7 @@ Main =
features: [
['Polyfill', Polyfill]
['Normalize URL', NormalizeURL]
['Captcha Replacement', Captcha.replace]
['Redirect', Redirect]
['Header', Header]

View File

@ -0,0 +1,14 @@
NormalizeURL =
init: ->
return unless Conf['Normalize URL']
pathname = location.pathname.split /\/+/
switch g.VIEW
when 'thread'
pathname[2] = 'thread'
pathname = pathname[0...4]
when 'index'
pathname = pathname[0...3]
pathname = pathname.join '/'
if location.pathname isnt pathname
history.replaceState history.state, '', "#{location.protocol}//#{location.host}#{pathname}#{location.hash}"