Files
atom/src/stdlib/jquery-extensions.coffee
Corey Johnson & Nathan Sobo de3bbce29f Only show events w/ descriptions in EventPalette
Also, auto-generate human readable event name in editor. This is a good example of how we could do this automatically for some kind of `onCommand`, `command`, `onInteractiveEvent` method that combines the event name, documentation string, and handler in one shot.
2012-10-19 11:24:40 -06:00

68 lines
1.6 KiB
CoffeeScript

$ = require 'jquery'
_ = require 'underscore'
$.fn.scrollBottom = (newValue) ->
if newValue?
@scrollTop(newValue - @height())
else
@scrollTop() + @height()
$.fn.scrollToTop = ->
@scrollTop(0)
$.fn.scrollToBottom = ->
@scrollTop(@prop('scrollHeight'))
$.fn.scrollRight = (newValue) ->
if newValue?
@scrollLeft(newValue - @width())
else
@scrollLeft() + @width()
$.fn.pageUp = ->
@scrollTop(@scrollTop() - @height())
$.fn.pageDown = ->
@scrollTop(@scrollTop() + @height())
$.fn.containsElement = (element) ->
(element[0].compareDocumentPosition(this[0]) & 8) == 8
$.fn.preempt = (eventName, handler) ->
@on eventName, (e, args...) ->
if handler(e, args...) == false then e.stopImmediatePropagation()
eventNameWithoutNamespace = eventName.split('.')[0]
handlers = @data('events')[eventNameWithoutNamespace]
handlers.unshift(handlers.pop())
$.fn.hasParent = ->
@parent()[0]?
$.fn.flashError = ->
@addClass 'error'
removeErrorClass = => @removeClass 'error'
window.setTimeout(removeErrorClass, 200)
$.fn.trueHeight = ->
this[0].getBoundingClientRect().height
$.fn.trueWidth = ->
this[0].getBoundingClientRect().width
$.fn.document = (eventDescriptions) ->
@data('documentation', {}) unless @data('documentation')
_.extend(@data('documentation'), eventDescriptions)
$.fn.events = ->
documentation = @data('documentation') ? {}
events = {}
for eventName of @data('events') ? {}
events[eventName] = documentation[eventName] ? null
if @hasParent()
_.extend(@parent().events(), events)
else
events