Skip to content
This repository
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 163 lines (134 sloc) 5.472 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
this.vichrome ?= {}
g = this.vichrome

settings = null

setSetting = (name, val, response) ->
    chrome.extension.sendRequest({
        command : "Settings"
        type : "set"
        name : name
        value : val
    })

escChars = (str) ->
    str.replace("<", "&lt;")
       .replace(">", "&gt;")
       .replace(" ", "&nbsp;")

updateKeyMappingList = ->
    curMap = $('#keyMappingList')
    curMap.append($('<div />').html('<h3>Normal Mode Mapping (nmap)</h3>'))
    for key,com of settings.keyMappingNormal
        curMap.append( $('<div />').html( escChars key + " : " + escChars com ) )

    curMap.append($('<div />').html('<h3>Insert Mode Mapping (imap)</h3>'))
    for key,com of settings.keyMappingInsert
        curMap.append( $('<div />').html( escChars key + " : " + escChars com ) )

    curMap.append($('<div />').html('<h3>Search/Command Mode Mapping (cmap)</h3>'))
    for key,com of settings.keyMappingCommand
        curMap.append( $('<div />').html( escChars key + " : " + escChars com ) )

    curMap.append($('<div />').html('<h3>Emergency Mode Mapping (emap)</h3>'))
    for key,com of settings.keyMappingEmergency
        curMap.append( $('<div />').html( escChars key + " : " + escChars com ) )

    curMap.append($('<div />').html('<h3>Command Aliases (alias)</h3>'))
    for key,com of settings.aliases
        curMap.append( $('<div />').html( escChars key + " : " + escChars com ) )

    curMap.append($('<div />').html('<h2>PageCmd Mapping</h2>'))
    for url,map of settings.pageMap
        curMap.append( $('<div />').html("<h3>#{url}</h3>") )

        curMap.append($('<div />').html('<h3>Normal Mode Mapping</h3>'))
        for key,com of map.nmap
            curMap.append( $('<div />').html(escChars key + " : " + escChars com) )

        curMap.append($('<div />').html('<h3>Insert Mode Mapping</h3>'))
        for key,com of map.imap
            curMap.append( $('<div />').html(escChars key + " : " + escChars com) )

        curMap.append($('<div />').html('<h3>Search/Command Mode Mapping</h3>'))
        for key,com of map.cmap
            curMap.append( $('<div />').html(escChars key + " : " + escChars com) )

        curMap.append($('<div />').html('<h3>Emergency Mode Mapping</h3>'))
        for key,com of map.emap
            curMap.append( $('<div />').html(escChars key + " : " + escChars com) )

        curMap.append($('<div />').html('<h3>Command Aliases</h3>'))
        for key,com of map.alias
            curMap.append( $('<div />').html(escChars key + " : " + escChars com) )

initInputText = (name) ->
    $('#'+name).val( settings[name] ).keyup( ->
        setSetting name, $(this).val()
    )

initInputNumber = (name) ->
    $('#'+name).val( settings[name] ).keyup( ->
        setSetting name, parseInt( $(this).val() )
    ).click( ->
        setSetting name, parseInt( $(this).val() )
    ).mousewheel( ->
        setSetting name, parseInt( $(this).val() )
    )

initCheckBox = (name) ->
    $('#'+name).attr( 'checked', settings[name] ).change( ->
        setSetting name, $(this).is(':checked')
    )

initDropDown = (name) ->
    $('#'+name).val( settings[name] ).change( ->
        setSetting name, $(this).val()
    )

onSettings = (msg) ->
    if msg.name == "all" then settings = msg.value

    initInputNumber "scrollPixelCount"
    initInputNumber "commandWaitTimeOut"
    initInputNumber "minIncSearch"
    initInputNumber "commandBoxWidth"
    initInputNumber "minMigemoLength"
    initInputNumber "hintFontSize"
    initInputText "fModeAvailableKeys"
    initInputText "hintBackgroundColor"
    initInputText "hintColor"
    initInputText "hintColorSelected"
    initCheckBox "disableAutoFocus"
    initCheckBox "smoothScroll"
    initCheckBox "enableCompletion"
    initCheckBox "wrapSearch"
    initCheckBox "incSearch"
    initCheckBox "ignoreCase"
    initCheckBox "useMigemo"
    initCheckBox "fModeIgnoreCase"
    initCheckBox "notifyUpdateSucceeded"
    initCheckBox "useFModeAnimation"
    initDropDown "commandBoxAlign"
    initDropDown "searchEngine"

    $('[name="newTabPage"][value="'+settings.defaultNewTab+'"]')
    .attr( 'checked', true )
    $('[name="newTabPage"]').change( ->
        if $(this).is(':checked')
            setSetting "defaultNewTab", $(this).val()
    )

    $('#ignoredUrls').val settings.ignoredUrls.join('\n')
    $('#ignoredUrlsButton').click( ->
        setSetting "ignoredUrls", $('#ignoredUrls').val().split('\n')
    )

    $('#keyMapping').val settings.keyMappingAndAliases
    $('#keyMappingButton').click( ->
        setSetting "keyMappingAndAliases", $('#keyMapping').val()
    )

    updateKeyMappingList()

$(document).ready( ->
    chrome.extension.sendRequest( {
        command : "Settings"
        type : "get"
        name : "all"
    }, onSettings )
)

$(document).ready(->
    $('#page-container > div').hide()
    page = /#.*$/.exec(window.location.href)
    if page?
        page = page[0]
    else
        page = '#general'

    $("ul.navbar li:has(a[href=\"#{page}\"])").addClass('navbar-item-selected').show()
    $(page).show()
    console.log(page)

    $('ul.navbar li:not(.navbar-item-separator)').click( ->
        $('ul.navbar li').removeClass('navbar-item-selected')
        $(this).addClass('navbar-item-selected')
        $('#page-container > div').hide()

        tab = $(this).find('a').attr('href')
        $(tab).fadeIn(200)
        return false
    )
)
Something went wrong with that request. Please try again.