<commit_before>
window.docomo ?= {}

class docomo.Docomo
  constructor: ($, @el = $('body')) ->
    @initialize()
    @addListeners()


  initialize: ->
    @window = $(window)
    @aside_list = @el.find '#docomo_sidebar li'
    @usages = @el.find('.docomo-showcase + pre, .docomo-showcase + .highlight > pre').addClass 'docomo-hidden docomo-usage'
    @usage_btns = @usages.before(@templUsage()).prev '.docomo-usage-toggle'


  dispose: ->
    @removeListeners()


  addListeners: ->
    @aside_list.on 'click.docomo:aside', => @toggleAside arguments...
    @usage_btns.on 'click.docomo:usage', => @toggleUsage arguments...
    @window.on 'keypress.docomo:keyed', => @keyed arguments...


  removeListeners: ->
    @aside_list.off 'click.docomo:aside'
    @usage_btns.off 'click.docomo:usage'
    @window.off 'keypress.docomo:keyed'


  keyed: (e) ->
    @toggleShortcuts() if e.keyCode is 63        # "?"
    @toggleStylingMode() if e.keyCode is 88      # "x"


  toggleAside: (e) ->
    @aside_list.removeClass 'active'
    $(e.target).closest('li').addClass 'active'


  toggleUsage: (e) ->
    e?.preventDefault()
    target = $(e.target)
    usage = @usages.eq(@usage_btns.index target).toggleClass 'docomo-hidden'
    return target.html(target.html().replace /^Hide/, 'View') if usage.hasClass 'docomo-hidden'
    return target.html(target.html().replace /^View/, 'Hide')


  toggleStylingMode: ->
    not_styles = '.docomo-showcase, .docomo-usage, .docomo-usage-toggle, h1'
    @non_styles ?= @el.find('.docomo-section').children().not not_styles
    @non_styles.toggleClass 'docomo-hidden'


  toggleShortcuts: ->
    console?.log @shortcut_output ?= @templShortcut()


# TEMPLATES #


  templUsage: ->
    '<a class="docomo-usage-toggle" href="#">View Markup</a>'


  templShortcut: ->
    """
    <SHIFT> + ? \tPrint this message
    <SHIFT> + x \tToggle showing only h1, showcase and usage blocks
    """
<commit_msg>Add local storage for remember the docs state.<commit_after>
window.docomo ?= {}

class docomo.Docomo
  constructor: ($, @el = $('body')) ->
    @has_storage = typeof Storage != undefined
    @examples_only = if @has_storage and localStorage.examples_only is "true" then true else false
    @initialize()
    @addListeners()
    @toggleStylingMode() if @examples_only


  initialize: ->
    @window = $(window)
    @aside_list = @el.find '#docomo_sidebar li'
    @usages = @el.find('.docomo-showcase + pre, .docomo-showcase + .highlight > pre').addClass 'docomo-hidden docomo-usage'
    @usage_btns = @usages.before(@templUsage()).prev '.docomo-usage-toggle'


  dispose: ->
    @removeListeners()


  addListeners: ->
    @aside_list.on 'click.docomo:aside', => @toggleAside arguments...
    @usage_btns.on 'click.docomo:usage', => @toggleUsage arguments...
    @window.on 'keypress.docomo:keyed', => @keyed arguments...


  removeListeners: ->
    @aside_list.off 'click.docomo:aside'
    @usage_btns.off 'click.docomo:usage'
    @window.off 'keypress.docomo:keyed'


  keyed: (e) ->
    @toggleShortcuts() if e.keyCode is 63        # "?"
    @toggleStylingMode() if e.keyCode is 88      # "x"


  toggleAside: (e) ->
    @aside_list.removeClass 'active'
    $(e.target).closest('li').addClass 'active'


  toggleUsage: (e) ->
    e?.preventDefault()
    target = $(e.target)
    usage = @usages.eq(@usage_btns.index target).toggleClass 'docomo-hidden'
    return target.html(target.html().replace /^Hide/, 'View') if usage.hasClass 'docomo-hidden'
    return target.html(target.html().replace /^View/, 'Hide')


  toggleStylingMode: ->
    not_styles = '.docomo-showcase, .docomo-usage, .docomo-usage-toggle, h1'
    @non_styles ?= @el.find('.docomo-section').children().not not_styles
    @non_styles.toggleClass 'docomo-hidden'
    @examples_only = @non_styles.hasClass('docomo-hidden')
    localStorage.examples_only = @examples_only if @has_storage


  toggleShortcuts: ->
    console?.log @shortcut_output ?= @templShortcut()


# TEMPLATES #


  templUsage: ->
    '<a class="docomo-usage-toggle" href="#">View Markup</a>'


  templShortcut: ->
    """
    <SHIFT> + ? \tPrint this message
    <SHIFT> + x \tToggle showing only h1, showcase and usage blocks
    """

{'fraction_non_alphanumeric': 0.16512015227218654, 'fraction_numerical': 0.0028551034975017845, 'mean_word_length': 3.425263157894737, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2883187', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1422, 'n_words': 279}