Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit faa45e48be51f54cb1556e77985cca4565de4a35 0 parents
@jgallen23 authored
3  .gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+node_modules
+.monitor
2  CHANGELOG.md
@@ -0,0 +1,2 @@
+# v0.0.1
+- initial release
6 Makefile
@@ -0,0 +1,6 @@
+boosh:
+ smoosh make ./build.json
+test:
+ ./node_modules/.bin/nodeunit test/node.js
+
+.PHONY: test
1  README.md
@@ -0,0 +1 @@
+# framejax
27 build.json
@@ -0,0 +1,27 @@
+{
+ "JAVASCRIPT": {
+ "DIST_DIR": "./dist",
+ "framejax": [
+ "./lib/copyright.js",
+ "./lib/amd-top.js",
+ "./lib/framejax.js",
+ "./lib/amd-bottom.js"
+ ]
+ },
+ "JSHINT_OPTS": {
+ "boss": true,
+ "forin": false,
+ "curly": true,
+ "debug": false,
+ "devel": false,
+ "evil": false,
+ "regexp": false,
+ "undef": false,
+ "sub": true,
+ "white": false,
+ "indent": 2,
+ "whitespace": false,
+ "asi": true
+ }
+}
+
58 dist/framejax.js
@@ -0,0 +1,58 @@
+/*!
+ * framejax
+ * v0.0.3
+ * https://github.com/jgallen23/framejax
+ * copyright JGA 2011
+ * MIT License
+ */
+
+!function (name, definition) {
+ if (typeof module != 'undefined' && module.exports) module.exports = definition();
+ else if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
+ else this[name] = definition();
+}('framejax', function() {
+
+var lastId = 0;
+var addEvent = function(node, name, func) {
+ if(node.addEventListener) {
+ node.addEventListener(name, func, true);
+ } else if(node.attachEvent) {
+ name = "on"+name;
+ node.attachEvent(name, func);
+ }
+};
+
+var framejax = function(form, options, callback) {
+ if (typeof options === "function") {
+ callback = options;
+ options = {};
+ }
+
+ var upload = function() {
+ var id = '__framejax__' + lastId++;
+ var iframe = document.createElement('iframe');
+ iframe.name = id;
+ iframe.id = id;
+ iframe.width = "0";
+ iframe.height = "0";
+ iframe.style.display = "none";
+ form.target = id;
+
+ var done = function() {
+ var iframe = document.getElementById(id);
+ var doc = null;
+ if (iframe.contentDocument)
+ doc = iframe.contentDocument;
+ if (iframe.contentWindow)
+ doc = iframe.contentWindow.document;
+ callback(doc.body.innerText);
+ };
+
+ addEvent(iframe, 'load', done);
+ document.body.appendChild(iframe);
+ };
+ addEvent(form, 'submit', upload);
+};
+
+return framejax;
+});
8 dist/framejax.min.js
@@ -0,0 +1,8 @@
+/*!
+ * framejax
+ * v0.0.3
+ * https://github.com/jgallen23/framejax
+ * copyright JGA 2011
+ * MIT License
+ */
+!function(a,b){typeof module!="undefined"&&module.exports?module.exports=b():typeof define=="function"&&typeof define.amd=="object"?define(b):this[a]=b()}("framejax",function(){var a=0,b=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!0):a.attachEvent&&(b="on"+b,a.attachEvent(b,c))},c=function(c,d,e){typeof d=="function"&&(e=d,d={});var f=function(){var d="__framejax__"+a++,f=document.createElement("iframe");f.name=d,f.id=d,f.width="0",f.height="0",f.style.display="none",c.target=d;var g=function(){var a=document.getElementById(d),b=null;a.contentDocument&&(b=a.contentDocument),a.contentWindow&&(b=a.contentWindow.document),e(b.body.innerText)};b(f,"load",g),document.body.appendChild(f)};b(c,"submit",f)};return c})
40 example/server.js
@@ -0,0 +1,40 @@
+var express = require('express');
+var form = require('connect-form');
+var path = require('path');
+
+var app = express.createServer(
+ form({ keepExtensions: true })
+);
+
+app.use(express.static(path.join(__dirname, '../lib')));
+
+app.set("view options", {
+ layout: false
+});
+
+app.set("view engine", "jade");
+app.set("views", "" + __dirname + "/views");
+
+app.get('/', function(req, res) {
+ res.render('index');
+});
+
+app.post('/', function(req, res) {
+ req.form.complete(function(err, fields, files){
+ if (err) {
+ next(err);
+ } else {
+ console.log(files.img);
+ res.send(files.img.path);
+ }
+ });
+
+ // We can add listeners for several form
+ // events such as "progress"
+ req.form.on('progress', function(bytesReceived, bytesExpected){
+ var percent = (bytesReceived / bytesExpected * 100) | 0;
+ process.stdout.write('Uploading: %' + percent + '\r');
+ });
+});
+
+app.listen(3000);
13 example/views/index.jade
@@ -0,0 +1,13 @@
+!!! 5
+html
+ head
+ body
+ form(method="post",enctype="multipart/form-data",action="/")
+ input(type="file", name="img")
+ input(type="submit",value="Submit")
+ div#result
+ script(src='framejax.js')
+ script
+ framejax(document.forms[0], function(result) {
+ document.getElementById("result").innerHTML = result;
+ });
2  lib/amd-bottom.js
@@ -0,0 +1,2 @@
+return framejax;
+});
5 lib/amd-top.js
@@ -0,0 +1,5 @@
+!function (name, definition) {
+ if (typeof module != 'undefined' && module.exports) module.exports = definition();
+ else if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
+ else this[name] = definition();
+}('framejax', function() {
7 lib/copyright.js
@@ -0,0 +1,7 @@
+/*!
+ * framejax
+ * v0.0.1
+ * https://github.com/jgallen23/framejax
+ * copyright JGA 2011
+ * MIT License
+ */
41 lib/framejax.js
@@ -0,0 +1,41 @@
+var lastId = 0;
+var addEvent = function(node, name, func) {
+ if(node.addEventListener) {
+ node.addEventListener(name, func, true);
+ } else if(node.attachEvent) {
+ name = "on"+name;
+ node.attachEvent(name, func);
+ }
+};
+
+var framejax = function(form, options, callback) {
+ if (typeof options === "function") {
+ callback = options;
+ options = {};
+ }
+
+ var upload = function() {
+ var id = '__framejax__' + lastId++;
+ var iframe = document.createElement('iframe');
+ iframe.name = id;
+ iframe.id = id;
+ iframe.width = "0";
+ iframe.height = "0";
+ iframe.style.display = "none";
+ form.target = id;
+
+ var done = function() {
+ var iframe = document.getElementById(id);
+ var doc = null;
+ if (iframe.contentDocument)
+ doc = iframe.contentDocument;
+ if (iframe.contentWindow)
+ doc = iframe.contentWindow.document;
+ callback(doc.body.innerText);
+ };
+
+ addEvent(iframe, 'load', done);
+ document.body.appendChild(iframe);
+ };
+ addEvent(form, 'submit', upload);
+};
21 package.json
@@ -0,0 +1,21 @@
+{
+ "name": "framejax",
+ "description": "a iframe ajax library for uploading files",
+ "version": "0.0.1",
+ "homepage": "https://github.com/jgallen23/framejax",
+ "author": "Greg Allen <@jgaui> (http://jga.me)",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/jgallen23/framejax.git"
+ },
+ "dependencies": {
+ },
+ "devDependencies": {
+ "express": "*",
+ "jade": "*",
+ "connect-form": "*"
+ },
+ "main": "./dist/framejax.js",
+ "keywords": ["ender", "iframe", "ajax", "upload"]
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.