From 9676af0c9aa571744ceadb2226e15d5188f0be10 Mon Sep 17 00:00:00 2001 From: Hannu Leinonen Date: Tue, 4 Oct 2011 17:41:06 +0300 Subject: [PATCH] Added Jakefile for creating distributables. --- .gitignore | 3 +- Jakefile | 33 +++++++++++++++++++++ README.md | 21 ++++++++++---- dist/jquery.fileinput-1.0.js | 49 ++++++++++++++++++++++++++++++++ dist/jquery.fileinput-1.0.min.js | 1 + jquery.fileinput.js | 14 ++++----- package.json | 22 ++++++++++++++ 7 files changed, 130 insertions(+), 13 deletions(-) create mode 100644 Jakefile create mode 100644 dist/jquery.fileinput-1.0.js create mode 100644 dist/jquery.fileinput-1.0.min.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index a5a68e4..ac01f25 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .settings -.project \ No newline at end of file +.project +node_modules diff --git a/Jakefile b/Jakefile new file mode 100644 index 0000000..5f226d2 --- /dev/null +++ b/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); + }); + }); +}); diff --git a/README.md b/README.md index 2290f36..f9cfdfa 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,13 @@ JavaScript magic! Wrapping the file input on a div, adding the replacement eleme ... -### 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. @@ -36,9 +36,9 @@ With **Opera** (and **Firefox** versions before 4) we can't support the [native * **.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+ @@ -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 \ No newline at end of file +* 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! \ No newline at end of file diff --git a/dist/jquery.fileinput-1.0.js b/dist/jquery.fileinput-1.0.js new file mode 100644 index 0000000..c3edc04 --- /dev/null +++ b/dist/jquery.fileinput-1.0.js @@ -0,0 +1,49 @@ +/** + * 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 + */ +(function($) { + $.fn.fileinput = function(replacement) { + var selector = this; + var replacementHtml = ""; + if (replacement) { + replacementHtml = $(replacement).removeAttr("id").addClass("fileinput").clone().wrap("
").parent().html(); + $(replacement).remove(); + } + selector.each(function() { + var element = $(this); + element.wrap("
"); + 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); \ No newline at end of file diff --git a/dist/jquery.fileinput-1.0.min.js b/dist/jquery.fileinput-1.0.min.js new file mode 100644 index 0000000..de4fae2 --- /dev/null +++ b/dist/jquery.fileinput-1.0.min.js @@ -0,0 +1 @@ +(function(a){a.fn.fileinput=function(b){var c=this,d='';return b&&(d=a(b).removeAttr("id").addClass("fileinput").clone().wrap("
").parent().html(),a(b).remove()),c.each(function(){var b=a(this);b.wrap('
'),b.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}),b.before(d);var c=a.browser;c.opera||c.mozilla&&c.version<"2.0"?(b.css("z-index","auto"),b.prev(".fileinput").css("z-index",-1),b.removeAttr("tabindex"),b.prev(".fileinput").attr("tabindex","-1"),b.hover(function(){a(this).prev(".fileinput").addClass("hover")},function(){a(this).prev(".fileinput").removeClass("hover")}).focusin(function(){a(this).prev(".fileinput").addClass("focus")}).focusout(function(){a(this).prev(".fileinput").removeClass("focus")}).mousedown(function(){a(this).prev(".fileinput").addClass("active")}).mouseup(function(){a(this).prev(".fileinput").removeClass("active")})):b.prev(".fileinput").click(function(){b.click()})}),c}})(jQuery) \ No newline at end of file diff --git a/jquery.fileinput.js b/jquery.fileinput.js index 4ef4b62..96026bf 100644 --- a/jquery.fileinput.js +++ b/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; diff --git a/package.json b/package.json new file mode 100644 index 0000000..9e98100 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "jQuery Fileinput Plugin", + "description": "Stylable for jQuery", + "version": "1.0", + "author": "Hannu Leinonen ", + "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" + } + ] +} \ No newline at end of file