Skip to content

Commit

Permalink
standard --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
refractalize committed Apr 9, 2017
1 parent 6813edf commit c135a78
Show file tree
Hide file tree
Showing 41 changed files with 2,316 additions and 2,379 deletions.
140 changes: 70 additions & 70 deletions bindModel.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var listener = require('./listener');
var listener = require('./listener')
var binding = require('./binding')
var RefreshHook = require('./render').RefreshHook

module.exports = function(tag, attributes, children) {
module.exports = function (tag, attributes, children) {
var type = inputType(tag, attributes)
var bind = inputTypeBindings[type] || bindTextInput;
var bind = inputTypeBindings[type] || bindTextInput

var bindingAttr = binding(attributes.binding);
bind(attributes, children, bindingAttr.get, bindingAttr.set);
var bindingAttr = binding(attributes.binding)
bind(attributes, children, bindingAttr.get, bindingAttr.set)
}

var inputTypeBindings = {
Expand All @@ -16,145 +16,145 @@ var inputTypeBindings = {
textarea: bindTextInput,

checkbox: function (attributes, children, get, set) {
attributes.checked = get();
attributes.checked = get()

attachEventHandler(attributes, 'onclick', function (ev) {
attributes.checked = ev.target.checked;
set(ev.target.checked);
});
attributes.checked = ev.target.checked
set(ev.target.checked)
})
},

radio: function (attributes, children, get, set) {
var value = attributes.value;
attributes.checked = get() == attributes.value;
var value = attributes.value
attributes.checked = get() == attributes.value
attributes.on_hyperdomsyncchecked = listener(function (event) {
attributes.checked = event.target.checked;
});
attributes.checked = event.target.checked
})

attachEventHandler(attributes, 'onclick', function (event) {
var name = event.target.name;
var name = event.target.name
if (name) {
var inputs = document.getElementsByName(name);
var inputs = document.getElementsByName(name)
for (var i = 0, l = inputs.length; i < l; i++) {
inputs[i].dispatchEvent(customEvent('_hyperdomsyncchecked'));
inputs[i].dispatchEvent(customEvent('_hyperdomsyncchecked'))
}
}
set(value);
});
set(value)
})
},

select: function (attributes, children, get, set) {
var currentValue = get();
var currentValue = get()

var options = children.filter(function (child) {
return child.tagName.toLowerCase() == 'option';
});
return child.tagName.toLowerCase() == 'option'
})

var values = [];
var selectedIndex;
var values = []
var selectedIndex

for(var n = 0; n < options.length; n++) {
var option = options[n];
var hasValue = option.properties.hasOwnProperty('value');
var value = option.properties.value;
var text = option.children.map(function (x) { return x.text; }).join('');
for (var n = 0; n < options.length; n++) {
var option = options[n]
var hasValue = option.properties.hasOwnProperty('value')
var value = option.properties.value
var text = option.children.map(function (x) { return x.text }).join('')

values.push(hasValue? value: text);
values.push(hasValue ? value : text)

var selected = value == currentValue || text == currentValue;
var selected = value == currentValue || text == currentValue

if (selected) {
selectedIndex = n;
selectedIndex = n
}

option.properties.selected = selected;
option.properties.value = n;
option.properties.selected = selected
option.properties.value = n
}

if (selectedIndex !== undefined) {
attributes.selectedIndex = selectedIndex;
attributes.selectedIndex = selectedIndex
}

attachEventHandler(attributes, 'onchange', function (ev) {
attributes.selectedIndex = ev.target.selectedIndex;
set(values[ev.target.value]);
});
attributes.selectedIndex = ev.target.selectedIndex
set(values[ev.target.value])
})
},

file: function (attributes, children, get, set) {
var multiple = attributes.multiple;
var multiple = attributes.multiple

attachEventHandler(attributes, 'onchange', function (ev) {
if (multiple) {
set(ev.target.files);
set(ev.target.files)
} else {
set(ev.target.files[0]);
set(ev.target.files[0])
}
});
})
}
};
}

function inputType(selector, attributes) {
function inputType (selector, attributes) {
if (/^textarea\b/i.test(selector)) {
return 'textarea';
return 'textarea'
} else if (/^select\b/i.test(selector)) {
return 'select';
return 'select'
} else {
return attributes.type || 'text';
return attributes.type || 'text'
}
}

function bindTextInput(attributes, children, get, set) {
var textEventNames = ['onkeyup', 'oninput', 'onpaste', 'textInput'];
function bindTextInput (attributes, children, get, set) {
var textEventNames = ['onkeyup', 'oninput', 'onpaste', 'textInput']

var bindingValue = get();
var bindingValue = get()
if (!(bindingValue instanceof Error)) {
attributes.value = bindingValue != undefined? bindingValue: '';
attributes.value = bindingValue != undefined ? bindingValue : ''
}

attachEventHandler(attributes, textEventNames, function (ev) {
if (get() != ev.target.value) {
set(ev.target.value);
set(ev.target.value)
}
});
})
}

function attachEventHandler(attributes, eventNames, handler) {
function attachEventHandler (attributes, eventNames, handler) {
if (eventNames instanceof Array) {
for (var n = 0; n < eventNames.length; n++) {
insertEventHandler(attributes, eventNames[n], handler);
insertEventHandler(attributes, eventNames[n], handler)
}
} else {
insertEventHandler(attributes, eventNames, handler);
insertEventHandler(attributes, eventNames, handler)
}
}

function insertEventHandler(attributes, eventName, handler) {
var previousHandler = attributes[eventName];
function insertEventHandler (attributes, eventName, handler) {
var previousHandler = attributes[eventName]
if (previousHandler) {
attributes[eventName] = sequenceFunctions(handler, previousHandler);
attributes[eventName] = sequenceFunctions(handler, previousHandler)
} else {
attributes[eventName] = handler;
attributes[eventName] = handler
}
}

function sequenceFunctions(handler1, handler2) {
function sequenceFunctions (handler1, handler2) {
return function (ev) {
handler1(ev);
handler1(ev)
if (handler2 instanceof RefreshHook) {
return handler2.handler(ev);
return handler2.handler(ev)
} else {
return handler2(ev);
return handler2(ev)
}
};
}
}

function customEvent(name) {
if (typeof Event == 'function') {
return new Event(name);
function customEvent (name) {
if (typeof Event === 'function') {
return new Event(name)
} else {
var event = document.createEvent('Event');
event.initEvent(name, false, false);
return event;
var event = document.createEvent('Event')
event.initEvent(name, false, false)
return event
}
}
24 changes: 12 additions & 12 deletions binding.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var refreshify = require('./render').refreshify;
var meta = require('./meta');
var refreshify = require('./render').refreshify
var meta = require('./meta')

module.exports = function(b, options) {
module.exports = function (b, options) {
var binding = b

if (b instanceof Array) {
Expand All @@ -12,28 +12,28 @@ module.exports = function(b, options) {
throw Error('hyperdom bindings must be either an array [object, property, setter] or an object { get(), set(value) }, instead binding was: ' + JSON.stringify(b))
}

binding.set = refreshify(binding.set, options);
binding.set = refreshify(binding.set, options)

return binding;
return binding
}

function bindingObject(model, property, setter) {
var _meta;
function bindingObject (model, property, setter) {
var _meta

return {
get: function () {
return model[property];
return model[property]
},

set: function (value) {
model[property] = value;
model[property] = value
if (setter) {
return setter(value)
}
},

meta: function() {
return _meta || (_meta = meta(model, property));
meta: function () {
return _meta || (_meta = meta(model, property))
}
};
}
}
2 changes: 1 addition & 1 deletion browser.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
window.hyperdom = require('.');
window.hyperdom = require('.')
Loading

0 comments on commit c135a78

Please sign in to comment.