$.fn.extend pseudoHover: -> $(@).addClass('unhovered').hover( -> $(@).addClass('hover').removeClass('unhovered'), -> $(@).removeClass('hover').addClass('unhovered')) appendView: (view)-> el = @append(view.el) view.render() el prependView: (view)-> el = @prepend(view.el) view.render() el serializeObject: -> o = {} a = @serializeArray() endsInArrayBrackets = /\[\]$/ $.each a, -> if o[@name] && endsInArrayBrackets.test(@name) o[@name] = [o[@name]] unless o[@name].push o[@name].push(@value || '') else o[@name] = @value || '' o highlight: -> $(@).effect('highlight', {}, 1500) reset: -> $(@).each -> @reset() disable: -> $(@).find('input[type="submit"], input[type="reset"], button').attr('disabled', 'disabled').end() enable: -> $(@).find('input[type="submit"], input[type="reset"], button').removeAttr('disabled').end() getCursorPosition: -> input = @get(0) return unless input if input.selectionStart # Standard-compliant browsers input.selectionStart else if document.selection # IE input.focus() sel = document.selection.createRange() selLen = document.selection.createRange().text.length sel.moveStart 'character', -input.value.length sel.text.length - selLen appendAsAlert: -> $alerts = $('#body .alert') $newAlert = $(@) if $alerts.length > 0 $('#body .alert').fadeOut complete: -> $(@).remove() $newAlert.prependTo($('#body')).alert() else $newAlert.prependTo($('#body')).alert() putCursorAtEnd: -> @each -> $(@).focus() # If this function exists... if @setSelectionRange # ... then use it (Doesn't work in IE) # Double the length because Opera is inconsistent about whether a carriage return is one character or two. Sigh. len = $(@).val().length * 2 @setSelectionRange(len, len) else # ... otherwise replace the contents with itself # (Doesn't work in Google Chrome) $(@).val($(@).val()) insertAtCursor: (text)-> textarea = @[0] # IE support if document.selection textarea.focus() sel = document.selection.createRange() sel.text = text # MOZILLA and others else if textarea.selectionStart || textarea.selectionStart == '0' startPos = textarea.selectionStart endPos = textarea.selectionEnd textarea.value = textarea.value.substring(0, startPos) + text + textarea.value.substring(endPos, textarea.value.length) textarea.selectionStart = startPos + text.length textarea.selectionEnd = startPos + text.length else textarea.value += text supportImages: -> $el = @ $el.append '''