Skip to content

Instantly share code, notes, and snippets.

@adtaylor
Created March 16, 2012 18:00
Show Gist options
  • Save adtaylor/2051524 to your computer and use it in GitHub Desktop.
Save adtaylor/2051524 to your computer and use it in GitHub Desktop.
!(( $ ) ->
"use strict"
# CLASSNAME CLASS DEFINITION
# ========================== #
ClassName = ( element, options) ->
process = $.proxy(@.process, this)
$element = if $(element).is('body') then $(window) else $(element)
@options = $.extend({}, $.fn.pluginname.defaults, options)
@$scrollElement = $element.on('scroll.scroll.data-api', process)
@selector = (this.options.target || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) || '') + ' .nav li > a'
@$body = $('body').on('click.scroll.data-api', this.selector, process)
@refresh()
@process()
ClassName.prototype =
constructor: ClassName
method: () ->
"I'm a bad ass method"
# PLUGIN DEFINITION
# =========================== #
$.fn.pluginname = ( option ) ->
this.each () ->
$this = $(this)
data = $this.data('pluginname')
options = typeof option == 'object' and option
if !data then $this.data('pluginname', (data = new ClassName(this, options)))
if typeof option == 'string' then data[option]()
$.fn.pluginname.defaults =
offset: 10
# CLASSNAME DATA-API
# ================== #
$( ()->
$('[data-spy="scroll"]').each ()->
$spy = $(this)
$spy.pluginname($spy.data())
)
)( window.jQuery )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment