Skip to content

Commit

Permalink
Added Jakefile for creating distributables.
Browse files Browse the repository at this point in the history
  • Loading branch information
hleinone committed Oct 4, 2011
1 parent 338b63e commit 9676af0
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
.settings
.project
.project
node_modules
33 changes: 33 additions & 0 deletions Jakefile
@@ -0,0 +1,33 @@
desc("This is the default task.");
task("default", function (params) {
var fs = require("fs");
var dot = require("dot");
var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;

console.log("Reading package.json");
fs.readFile("./package.json", "utf8", function(err, data) {
if (err) throw err;

console.log("Parsing package.json");
var pkg = JSON.parse(data);
console.log("Building " + pkg.name + " " + pkg.version);
fs.readFile("./jquery.fileinput.js", "utf8", function(err, data) {
if (err) throw err;
var cmp = dot.template(data, {evaluate: /\{\{([\s\S]+?)\}\}/g,
interpolate: /\{\{=([\s\S]+?)\}\}/g,
encode: /\{\{!([\s\S]+?)\}\}/g,
use: /\{\{#([\s\S]+?)\}\}/g, //compile time evaluation
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g, //compile time defs
strip: false,
varname: "pkg"})(pkg);
var ast = jsp.parse(cmp);
ast = pro.ast_mangle(ast);
ast = pro.ast_squeeze(ast);
var min = pro.gen_code(ast);
console.log("Writing to dist");
fs.writeFileSync("./dist/jquery.fileinput-" + pkg.version + ".min.js", min);
fs.writeFileSync("./dist/jquery.fileinput-" + pkg.version + ".js", cmp);
});
});
});
21 changes: 16 additions & 5 deletions README.md
Expand Up @@ -22,23 +22,23 @@ JavaScript magic! Wrapping the file input on a div, adding the replacement eleme
...
<input type="file" name="foo" />

### The API
### API

#### .fileinput([replacement])

**replacement** A selector for the element intended to replace the file input. The element is removed from the DOM immediately.

#### The Notes
#### Notes

With **Opera** (and **Firefox** versions before 4) we can't support the [native CSS pseudo classes](http://www.w3schools.com/css/css_pseudo_classes.asp). Instead we'll provide them real classes.

* **.hover** for :hover
* **.focus** for :focus
* **.active** for :active

### [The Demo](http://jsfiddle.net/hleinone/UF4nr/)
### [Demo](http://jsfiddle.net/hleinone/UF4nr/)

## The Requirements
## Requirements

* [jQuery](http://jquery.com/) 1.4+

Expand All @@ -48,4 +48,15 @@ With **Opera** (and **Firefox** versions before 4) we can't support the [native
* Chrome 14.0.835.186
* Safari 5.1 (6534.50)
* Internet Explorer 8.0.7601.17514
* Opera 10.51
* Opera 10.51

## Developing

1. Fork
1. Clone your fork
1. Make your modifications
1. Compile using [`jake`](https://github.com/mde/jake)
1. Test
1. Create pull request
1. ???
1. Profit!
49 changes: 49 additions & 0 deletions dist/jquery.fileinput-1.0.js
@@ -0,0 +1,49 @@
/**
* jQuery Fileinput Plugin v1.0
*
* Copyright 2011, Hannu Leinonen <hleinone@gmail.com>
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($) {
$.fn.fileinput = function(replacement) {
var selector = this;
var replacementHtml = "<button class=\"fileinput\">Browse...</button>";
if (replacement) {
replacementHtml = $(replacement).removeAttr("id").addClass("fileinput").clone().wrap("<div />").parent().html();
$(replacement).remove();
}
selector.each(function() {
var element = $(this);
element.wrap("<div class=\"fileinput-wrapper\" style=\"position: relative; display: inline-block;\" />");
element.attr("tabindex", "-1").css({"font-size": "100px", height: "100%", filter: "alpha(opacity=0)", "-moz-opacity": 0, opacity: 0, position: "absolute", right: 0, top: 0, "z-index": -1});
element.before(replacementHtml);
var ua = $.browser;
if (ua.opera || (ua.mozilla && ua.version < "2.0")) {
element.css("z-index", "auto");
element.prev(".fileinput").css("z-index", -1);
element.removeAttr("tabindex");
element.prev(".fileinput").attr("tabindex", "-1");
element.hover(function() {
$(this).prev(".fileinput").addClass("hover");
}, function() {
$(this).prev(".fileinput").removeClass("hover");
}).focusin(function() {
$(this).prev(".fileinput").addClass("focus");
}).focusout(function() {
$(this).prev(".fileinput").removeClass("focus");
}).mousedown(function() {
$(this).prev(".fileinput").addClass("active");
}).mouseup(function() {
$(this).prev(".fileinput").removeClass("active");
});
} else {
element.prev(".fileinput").click(function() {
element.click();
});
}
});
return selector;
};
})(jQuery);
1 change: 1 addition & 0 deletions dist/jquery.fileinput-1.0.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions jquery.fileinput.js
@@ -1,11 +1,11 @@
/**
* jQuery Fileinput Plugin v1.0
*
* Copyright 2011, Hannu Leinonen
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
* {{= pkg.name}} v{{= pkg.version}}
*
* Copyright 2011, {{= pkg.author}}
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($) {
$.fn.fileinput = function(replacement) {
var selector = this;
Expand Down
22 changes: 22 additions & 0 deletions package.json
@@ -0,0 +1,22 @@
{
"name": "jQuery Fileinput Plugin",
"description": "Stylable <input type=\"file\"> for jQuery",
"version": "1.0",
"author": "Hannu Leinonen <hleinone@gmail.com>",
"homepage": "http://github.com/hleinone/jquery-fileinput",
"keywords": ["jquery", "input", "file", "javascript", "style", "css", "fileinput"],
"repository": {
"type": "git",
"url": "http://github.com/hleinone/jquery-fileinput.git"
},
"licences": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
},
{
"type": "GPL",
"url": "http://www.gnu.org/licenses/gpl.html"
}
]
}

0 comments on commit 9676af0

Please sign in to comment.