diff --git a/jquery.FileReader.js b/jquery.FileReader.js index 730b422..1f2977b 100644 --- a/jquery.FileReader.js +++ b/jquery.FileReader.js @@ -5,7 +5,7 @@ // if native FileReader support, then dont add the polyfill and make the plugin do nothing if (window.FileReader) { - $.fn.fileReader = function () { return this; } + $.fn.fileReader = function() { return this; }; return ; } @@ -13,7 +13,7 @@ * JQuery Plugin */ $.fn.fileReader = function( options ) { - options = $.extend($.fn.fileReader.defaults, options); + options = $.extend({}, $.fn.fileReader.defaults, options); var self = this; readyCallbacks.add(function() { @@ -21,7 +21,7 @@ }); if ($.isFunction(options.callback)) readyCallbacks.add(options.callback); - if (!FileAPIProxy.ready) { + if (!FileAPIProxy.ready && !FileAPIProxy.hasInitialized) { FileAPIProxy.init(options); } return this; @@ -40,7 +40,12 @@ filereader : 'files/filereader.swf', // The path to the filereader swf file expressInstall : null, // The path to the express install swf file debugMode : false, - callback : false // Callback function when Filereader is ready + callback : false, // Callback function when Filereader is ready + position : 'fixed', + appendTo : 'body', + offsetCss : function (trigger) { + return trigger.offset(); + } }; /** @@ -49,6 +54,7 @@ */ var main = function(el, options) { return el.each(function(i, input) { + var trigger = $(options.trigger || input); input = $(input); var id = input.attr('id'); if (!id) { @@ -62,17 +68,19 @@ FileAPIProxy.inputs[id] = input; FileAPIProxy.swfObject.add(id, options.multiple, options.accept, options.label, options.extensions); - input.css('z-index', 0) + trigger.add(input) + .css('z-index', 0) .mouseover(function (e) { if (id !== currentTarget) { e = e || window.event; currentTarget = id; FileAPIProxy.swfObject.mouseover(id); - FileAPIProxy.container - .height(input.outerHeight()) - .width(input.outerWidth()) - .css(input.offset()); } + + FileAPIProxy.container + .height(trigger.outerHeight()) + .width(trigger.outerWidth()) + .css(options.offsetCss(trigger)); }) .click(function(e) { e.preventDefault(); @@ -88,14 +96,16 @@ */ window.FileAPIProxy = { ready: false, + hasInitialized: false, init: function(o) { var self = this; + this.hasInitialized = true; this.debugMode = o.debugMode; this.container = $('