Skip to content

Commit

Permalink
use Makefile instead of Rakefile, modify sample
Browse files Browse the repository at this point in the history
  • Loading branch information
shokai committed May 23, 2013
1 parent c82e1cf commit 4ac85e6
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 25 deletions.
11 changes: 11 additions & 0 deletions Makefile
@@ -0,0 +1,11 @@
src = src/jquery.editable.js
dest = jquery.editable.js
dest_min = jquery.editable.min.js
header = HEADER.txt

all: build

build:
cat $(header) $(src) > $(dest)
cat $(header) > $(dest_min)
uglifyjs $(src) >> $(dest_min)
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -2,7 +2,7 @@ jQuery.editable plugin
======================
Edit in place plugin for jQuery

* http://shokai.github.com/jQuery.editable/
* http://shokai.github.io/jQuery.editable/


SYNOPSIS
Expand All @@ -11,7 +11,7 @@ SYNOPSIS
Load jquery.editable.js

````html
<script src="jquery.js" type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="jquery.editable.js" type="text/javascript"></script>
````

Expand Down
15 changes: 0 additions & 15 deletions Rakefile

This file was deleted.

62 changes: 61 additions & 1 deletion jquery.editable.js
Expand Up @@ -2,4 +2,64 @@
// http://shokai.github.com/jQuery.editable
// (c) 2012 Sho Hashimoto <hashimoto@shokai.org>
// The MIT License
(function(e){e.fn.editable=function(t,n){typeof n!="function"&&(n=function(e){});if(typeof t=="string")var r=this,i=t;else var r=t.trigger,i=t.action;var s=this,o={};return o.start=function(t){r.unbind(i=="clickhold"?"mousedown":i),r!=s&&r.hide();var u=s.text().replace(/^\s+/,"").replace(/\s+$/,""),a=e("<input>").val(u).width(s.width()+s.height()).css("font-size","100%").css("margin",0).attr("id","editable_"+new Date*1).addClass("editable"),f=function(){var e=a.val().replace(/^\s+/,"").replace(/\s+$/,"");s.text(e),n({value:e,target:s,old_value:u}),o.regist(),r!=s&&r.show()};a.blur(f),a.keydown(function(e){e.keyCode==13&&f()}),s.html(a),a.focus()},o.regist=function(){if(i=="clickhold"){var e=null;r.bind("mousedown",function(t){e=setTimeout(function(){o.start(t)},500)}),r.bind("mouseup mouseout",function(t){clearTimeout(e)})}else r.bind(i,o.start)},o.regist(),this}})(jQuery);
(function($){
$.fn.editable = function(event, callback){
if(typeof callback != 'function') callback = function(arg){};
if(typeof event == "string"){
var trigger = this;
var action = event;
}
else{
var trigger = event.trigger;
var action = event.action;
}

var target = this;
var edit = {};

edit.start = function(e){
trigger.unbind(action == 'clickhold' ? 'mousedown' : action);
if(trigger != target) trigger.hide();
var old_value = target.text().replace(/^\s+/,'').replace(/\s+$/,'');
var input = $('<input>').val(old_value).
width(target.width()+target.height()).css('font-size','100%').
css('margin',0).attr('id','editable_'+(new Date()*1)).
addClass('editable');
var finish = function(){
var res = input.val().replace(/^\s+/,'').replace(/\s+$/,'');
target.text(res);
callback({value : res, target : target, old_value : old_value});
edit.regist();
if(trigger != target) trigger.show();
};

input.blur(finish);
input.keydown(function(e){
if(e.keyCode == 13) finish();
});

target.html(input);
input.focus();
};

edit.regist = function(){
if(action == 'clickhold'){
var tid = null;
trigger.bind('mousedown', function(e){
tid = setTimeout(function(){
edit.start(e);
}, 500);
});
trigger.bind('mouseup mouseout', function(e){
clearTimeout(tid);
});
}
else{
trigger.bind(action, edit.start);
}
};
edit.regist();

return this;
};
})(jQuery);
5 changes: 5 additions & 0 deletions jquery.editable.min.js

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

6 changes: 3 additions & 3 deletions src/index.html → sample/index.html
Expand Up @@ -3,9 +3,9 @@
<head>
<meta charset="UTF-8" content="text/html" http-equiv="Content-Type" />
<title>jQuery.editable demo</title>
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.editable.js" type="text/javascript"></script>
<script src="index.js" type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="../src/jquery.editable.js" type="text/javascript"></script>
<script src="main.js" type="text/javascript"></script>
<style type="text/css">
span.editable {
background-color : #FFA;
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions src/jquery.js

This file was deleted.

0 comments on commit 4ac85e6

Please sign in to comment.