Commits

RyanFaerman  committed f619754

added escaping of element name

  • Participants
  • Parent commits 23fec5c

Comments (0)

Files changed (2)

File jquery.uploadInPlace-min.js

  * http://www.opensource.org/licenses/mit-license.php
  */
 
-(function($){$.fn.uploadInPlace=function(options){var defaults={action:"submit.php",status:"status",method:"post",pollTime:500,success:function(){},onchange:true};var options=$.extend(defaults,options);return this.each(function(){var fieldName=$(this).attr('name');$(this).change(function(){if(options.onchange){$(this).parent().submit();}}).wrap(function(){return'<form action="'+options.action+'" target="target_'+fieldName+'" method="post" enctype="multipart/form-data"/>';}).parent().submit(function(){$.doTimeout('time_'+fieldName,options.pollTime,function(){if($('#target_'+fieldName).contents().find('#'+options.status).text()){options.success.call($('#target_'+fieldName).contents());return false;}
-else{return true;}});});$('body').append('<iframe name="target_'+$(this).attr('name')+'" id="target_'+$(this).attr('name')+'" style="display:none"></iframe>');});};})(jQuery);
+(function($){$.fn.uploadInPlace=function(options){var defaults={action:"submit.php",status:"status",method:"post",pollTime:500,success:function(){}};var options=$.extend(defaults,options);return this.each(function(){var fieldName=$(this).attr('name');$(this).change(function(){$(this).parent().submit();}).wrap(function(){return'<form action="'+options.action+'" target="target_'+fieldName+'" method="post" enctype="multipart/form-data"/>';}).parent().submit(function(){$.doTimeout('time_'+$.fn.uploadInPlace.escape(fieldName),options.pollTime,function(){if($('#target_'+$.fn.uploadInPlace.escape(fieldName)).contents().find('#'+options.status).text()){options.success.call($('#target_'+$.fn.uploadInPlace.escape(fieldName)).contents());return false;}
+else{return true;}});});$('body').append('<iframe name="target_'+fieldName+'" id="target_'+$(this).attr('name')+'" style="display:none"></iframe>');});};$.fn.uploadInPlace.escape=function(identifier){return identifier.replace(/(:|\.|\|)/g,'\\$1');}})(jQuery);

File jquery.uploadInPlace.js

-/*
- * jQuery uploadInPlace: makes a form field become one that uploads in place. v1.0 4/19/2010
- * http://bitbucket.org/ryanfaerman/uploadinplace
- * Requires the doTimeout plugin: http://benalman.com/projects/jquery-dotimeout-plugin/
- * 
- * Copyright (c) 2010 Ryan Faerman
- * If this helps you, it'd be cool if you let me know.
- * Licensed under the MIT license.
- * http://www.opensource.org/licenses/mit-license.php
- */
- 
 (function($){
-			$.fn.uploadInPlace = function(options) {
-				
-				var defaults = {
-					action: "submit.php",
-					status: "status",
-					method: "post",
-					pollTime: 500,
-					success: function(){},
-					onchange: true
-				};
-				
-				var options = $.extend(defaults, options);
-	
-				
-				return this.each(function(){
-					var fieldName = $(this).attr('name');
-					$(this).change(function(){
-						if(options.onchange) {
-							$(this).parent().submit();
-						}
-					}).wrap(function(){
-						return '<form action="'+options.action+'" target="target_'+fieldName+'" method="post" enctype="multipart/form-data"/>';
-					}).parent().submit(function(){
-						$.doTimeout('time_'+fieldName, options.pollTime, function(){
-							if($('#target_'+fieldName).contents().find('#'+options.status).text()) {
-								options.success.call($('#target_'+fieldName).contents());
-								return false;
-							}
-							else {
-								return true;
-							}
-						});
-						
-					});
-					$('body').append('<iframe name="target_'+$(this).attr('name')+'" id="target_'+$(this).attr('name')+'" style="display:none"></iframe>');
+	$.fn.uploadInPlace = function(options) {
+		
+		var defaults = {
+			action: "submit.php",
+			status: "status",
+			method: "post",
+			pollTime: 500,
+			success: function(){}
+		};
+		
+		var options = $.extend(defaults, options);
 
-
+		
+		return this.each(function(){
+			var fieldName = $(this).attr('name');
+			$(this).change(function(){
+				$(this).parent().submit();
+			}).wrap(function(){
+				return '<form action="'+options.action+'" target="target_'+fieldName+'" method="post" enctype="multipart/form-data"/>';
+			}).parent().submit(function(){
+				$.doTimeout('time_'+$.fn.uploadInPlace.escape(fieldName), options.pollTime, function(){
+					if($('#target_'+$.fn.uploadInPlace.escape(fieldName)).contents().find('#'+options.status).text()) {
+						options.success.call($('#target_'+$.fn.uploadInPlace.escape(fieldName)).contents());
+						return false;
+					}
+					else {
+						return true;
+					}
 				});
 				
-			};
-		})(jQuery);
+			});
+			$('body').append('<iframe name="target_'+fieldName+'" id="target_'+$(this).attr('name')+'" style="display:none"></iframe>');
+
+
+		});
+		
+		
+	};
+	
+	$.fn.uploadInPlace.escape = function(identifier) {
+		return identifier.replace(/(:|\.|\|)/g,'\\$1');
+	}
+	
+})(jQuery);