Skip to content
This repository has been archived by the owner on Oct 11, 2019. It is now read-only.

Commit

Permalink
Added form processing
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-alexandrov committed Nov 27, 2012
1 parent 0274c31 commit 7a2133d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/assets/javascripts/wiselinks.js.coffee
@@ -1,9 +1,12 @@
#= require _history #= require _history


String.prototype.ends_with = (suffix) ->
this.indexOf(suffix, this.length - suffix.length) != -1

class Wiselinks class Wiselinks
constructor: (@$target = $('body'), options = {}) -> constructor: (@$target = $('body'), options = {}) ->
# check that JQuery or Zepto.js are available # check that JQuery or Zepto.js are available
throw "Load JQuery or Zepto.js to use Wiselinks" unless window.JQuery? || window.Zepto? throw "Load JQuery to use Wiselinks" unless window.jQuery?


self = this self = this


Expand All @@ -21,7 +24,7 @@ class Wiselinks


$(document).on( $(document).on(
"submit", "form[data-push], form[data-replace]" "submit", "form[data-push], form[data-replace]"
(event) -> (event) ->
self._process_form($(this)) self._process_form($(this))


event.preventDefault() event.preventDefault()
Expand Down Expand Up @@ -68,13 +71,14 @@ class Wiselinks
dataType: "html" dataType: "html"
) )


_process_form: ($form) -> _process_form: ($form) ->
self = this self = this


$disable = $form.find(':input[value=""]') $disable = $form.find(':input[value=""]')
$disable.attr('disabled', true); $disable.attr('disabled', true);


params = {} params = {}

for item in $form.serializeArray() for item in $form.serializeArray()
if item.name != 'utf8' if item.name != 'utf8'
name = if item.name.ends_with('[]') name = if item.name.ends_with('[]')
Expand All @@ -88,7 +92,7 @@ class Wiselinks
params[name] = item.value params[name] = item.value


serialized = [] serialized = []
for key in params for key of params
serialized.push("#{params[key]}=key") serialized.push("#{params[key]}=key")


serialized = serialized.join('&').replace(/%|!/g, '') serialized = serialized.join('&').replace(/%|!/g, '')
Expand Down

0 comments on commit 7a2133d

Please sign in to comment.