a-template
Advanced tools
Comparing version 0.0.7 to 0.0.8
{ | ||
"name": "a-template", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"scripts": { | ||
"build": "browserify ./src/index.js -t [ babelify --presets [ es2015 ] ] --standalone aTemplate --outfile ./build/a-template.js", | ||
"build:watch": "watchify ./src/index.js -t [ babelify --presets [ es2015 ] ] --standalone aTemplate --outfile ./build/a-template.js", | ||
"build:lib": "babel ./src/index.js --presets es2015 --out-file ./index.js" | ||
"build:lib": "babel ./src/index.js --presets es2015 --out-file ./index.js", | ||
"watch": "watchify ./src/index.js -t [ babelify --presets [ es2015 ] ] --standalone aTemplate --outfile ./build/a-template.js", | ||
"watch:lib": "watchify ./src/index.js -t [ babelify --presets [ es2015 ] ] --outfile ./index.js", | ||
"watch:all": "npm run watch & npm run watch:lib" | ||
}, | ||
@@ -9,0 +11,0 @@ "main": "./index.js", |
122
src/index.js
@@ -23,67 +23,73 @@ /** | ||
} | ||
$(document).on("input change click", "[data-bind]", function(e) { | ||
var data = $(this).data("bind"); | ||
var val = $(this).val(); | ||
var attr = $(this).attr("href"); | ||
if (attr) { | ||
val = attr.replace("#", ""); | ||
} | ||
var id = $(this).parents("[data-id]").data("id"); | ||
if (id) { | ||
var obj = getObjectById(id); | ||
if ($(e.target).attr("type") == "radio") { | ||
if ($(this).is(":checked")) { | ||
if(typeof document !== "undefined"){ | ||
//data binding | ||
$(document).on("input change click", "[data-bind]", function(e) { | ||
var data = $(this).data("bind"); | ||
var val = $(this).val(); | ||
var attr = $(this).attr("href"); | ||
if (attr) { | ||
val = attr.replace("#", ""); | ||
} | ||
var id = $(this).parents("[data-id]").data("id"); | ||
if (id) { | ||
var obj = getObjectById(id); | ||
if ($(e.target).attr("type") == "radio") { | ||
if ($(this).is(":checked")) { | ||
obj.updateDataByString(data, val); | ||
} else { | ||
obj.updateDataByString(data, ''); | ||
} | ||
} else if ($(e.target).attr("type") == "checkbox") { | ||
var name = $(this).attr("name"); | ||
var arr = []; | ||
$(":checkbox[name=" + name + "]").each(() => { | ||
if ($(this).is(":checked")) { | ||
arr.push($(this).val()); | ||
} | ||
}); | ||
obj.updateDataByString(data, arr); | ||
} else { | ||
obj.updateDataByString(data, val); | ||
} else { | ||
obj.updateDataByString(data, ''); | ||
} | ||
} else if ($(e.target).attr("type") == "checkbox") { | ||
var name = $(this).attr("name"); | ||
var arr = []; | ||
$(":checkbox[name=" + name + "]").each(() => { | ||
if ($(this).is(":checked")) { | ||
arr.push($(this).val()); | ||
} | ||
}); | ||
//action | ||
$(document).on(eventType,dataAction,function(e){ | ||
if(e.type == "click" && $(e.target).is("select")){ | ||
return; | ||
} | ||
if(e.type == "input" && $(e.target).attr("type") == "button"){ | ||
return; | ||
} | ||
var events = eventType.split(" "); | ||
var $self = $(this); | ||
var action = "action"; | ||
events.forEach(function(event){ | ||
if ($self.data("action-"+event)) { | ||
if(e.type === event){ | ||
action += "-"+event; | ||
} | ||
}); | ||
obj.updateDataByString(data, arr); | ||
} else { | ||
obj.updateDataByString(data, val); | ||
} | ||
}); | ||
var string = $self.data(action); | ||
if(!string){ | ||
return; | ||
} | ||
} | ||
}); | ||
$(document).on(eventType,dataAction,function(e){ | ||
if(e.type == "click" && $(e.target).is("select")){ | ||
return; | ||
} | ||
if(e.type == "input" && $(e.target).attr("type") == "button"){ | ||
return; | ||
} | ||
var events = eventType.split(" "); | ||
var $self = $(this); | ||
var action = "action"; | ||
events.forEach(function(event){ | ||
if ($self.data("action-"+event)) { | ||
if(e.type === event){ | ||
action += "-"+event; | ||
var action = string.replace(/\(.*?\);?/,""); | ||
var parameter = string.replace(/(.*?)\((.*?)\);?/,"$2"); | ||
var pts = parameter.split(",");//引き数 | ||
var id = $self.parents("[data-id]").data("id"); | ||
if(id){ | ||
var obj = getObjectById(id); | ||
obj.e = e; | ||
if(obj.method && obj.method[action]){ | ||
obj.method[action].apply(obj,pts); | ||
}else if(obj[action]){ | ||
obj[action].apply(obj,pts); | ||
} | ||
} | ||
}); | ||
var string = $self.data(action); | ||
if(!string){ | ||
return; | ||
} | ||
var action = string.replace(/\(.*?\);?/,""); | ||
var parameter = string.replace(/(.*?)\((.*?)\);?/,"$2"); | ||
var pts = parameter.split(",");//引き数 | ||
var id = $self.parents("[data-id]").data("id"); | ||
if(id){ | ||
var obj = getObjectById(id); | ||
obj.e = e; | ||
if(obj.method && obj.method[action]){ | ||
obj.method[action].apply(obj,pts); | ||
}else if(obj[action]){ | ||
obj[action].apply(obj,pts); | ||
} | ||
} | ||
}); | ||
} | ||
class aTemplate { | ||
@@ -90,0 +96,0 @@ constructor(opt) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
243366
4486
5
2