# ----------------------------------------------------------------------------- # Author: Alexander Kravets , # Slate Studio (http://www.slatestudio.com) # # Coding Guide: # https://github.com/thoughtbot/guides/tree/master/style/coffeescript # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # CHARACTER # ----------------------------------------------------------------------------- # # Public attributes: # modules # formInputs # itemsPerPageRequest # # Public methods: # start(@config) - start the character app with configuration # updateHash(hash, skipRoute) - change window location hash # isMobile() - check if running on mobile # showAlert(message) - show alert notification # showError(message) - show error message # # Dependencies: #= require ./chr_router # # ----------------------------------------------------------------------------- class @Chr constructor: -> @formInputs = {} @modules = {} @itemsPerPageRequest = Math.ceil($(window).height() / 60) * 2 # PRIVATE =============================================== _unset_active_items: -> $('.sidebar .menu a.active').removeClass('active') $('.list .items .item.active').removeClass('active') _set_active_menu_item: -> currentModuleName = window.location.hash.split('/')[1] for a in @$mainMenu.children() moduleName = $(a).attr('href').split('/')[1] if currentModuleName == moduleName return $(a).addClass('active') _add_menu_item: (moduleName, title) -> @$mainMenu.append "#{ title }" _bind_hashchange: -> @skipRoute = false window.onhashchange = => @_unset_active_items() if ! @skipRoute then @_route() @skipRoute = false $(this).trigger 'hashchange' $(this).on 'hashchange', => @_set_active_menu_item() _on_start: -> if location.hash != '' @_route() return $(this).trigger('hashchange') if ! @isMobile() return @updateHash('#/' + Object.keys(@modules)[0]) # PUBLIC ================================================ isMobile: -> $(window).width() < 760 updateHash: (path, @skipRoute=false) -> window.location.hash = path start: (title, @config) -> @$el =$ (@config.selector ? 'body') @$navBar =$ "