Skip to content

Commit

Permalink
Removing dependence on jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
grampelberg committed Jan 17, 2011
1 parent 128230f commit ab176c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
30 changes: 18 additions & 12 deletions lib/janky.post.js
Expand Up @@ -20,26 +20,29 @@
var form = res[1];
extend({}, janky._default_opts, opts);
if (!opts.url) throw new Error("Must include a URL to send data to.");
form.attr("action", opts.url);
form.attr("method", opts.method);
form.setAttribute("action", opts.url);
form.setAttribute("method", opts.method);
extend(opts.data, {
_origin: location.href
});
janky._input(form, opts.data);
iframe.load(function() {
setTimeout(function() { iframe.remove() }, 1);
if (!iframe.get(0).contentWindow.location.href)
iframe.onload = function() {
setTimeout(function() { document.body.removeChild(iframe) }, 1);
if (!iframe.contentWindow.location.href)
return opts.error && opts.error();
var resp = iframe.get(0).contentWindow.name;
var resp = iframe.contentWindow.name;
opts.success && opts.success(JSON.parse(resp));
});
};
form.submit();
};

this.janky._form = function() {
var iframe = $("<iframe></iframe>").appendTo("body").hide();
return [iframe, iframe.contents().find(
"body").append("<form></form>").find("form")];
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
iframe.style.display = "none";
var form = document.createElement("form");
iframe.contentDocument.body.appendChild(form);
return [iframe, form];
};
this.janky._default_opts = {
method: 'get'
Expand All @@ -52,8 +55,11 @@
var val = data[k];
if (!janky.is_string(val))
val = JSON.stringify(val);
$("<input type='hidden'></input>").appendTo(form).attr(
"name", k).val(val);
var inp = document.createElement("input");
inp.setAttribute("type", "hidden");
inp.setAttribute("name", k);
inp.value = val;
form.appendChild(inp);
};
};
})();
1 change: 0 additions & 1 deletion test/index.html
Expand Up @@ -12,7 +12,6 @@ <h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<!-- Testing scripts -->
<script src="dep/json2.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="dep/qunit.js"></script>
<script src="dep/sinon-1.0.1.js"></script>
<script src="dep/sinon-ie-1.0.1.js"></script>
Expand Down

0 comments on commit ab176c3

Please sign in to comment.