Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #63 from chrishumboldt/dev-rocket
Browse files Browse the repository at this point in the history
Dev rocket
  • Loading branch information
chrishumboldt authored Apr 20, 2017
2 parents 0d6ccb6 + 0be6238 commit 0271205
Show file tree
Hide file tree
Showing 23 changed files with 407 additions and 88 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .npmignore
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
109 changes: 72 additions & 37 deletions build/js/form.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
/**
@author Chris Humboldt
**/
// Extend Rocket
Rocket.defaults.form = {
targets: '.form',
colour: 'blue',
label: 'normal',
size: 'normal',
style: 'line'
};
// Module
var RockMod_Form;
(function (RockMod_Form) {
// Functions
var check = {
off: function (elm, container) {
elm.checked = false;
Expand All @@ -18,9 +24,11 @@ var RockMod_Form;
}
};
function checkSelect(inpOption, type, elm, container) {
// Catch
if (type !== 'checkbox') {
return false;
}
// Continue
var option = (typeof inpOption === 'string') ? inpOption : false;
if (option === 'on') {
check.on(elm, container);
Expand All @@ -38,30 +46,87 @@ var RockMod_Form;
}
}
function formApply(formContainer, options) {
// Variables
var element;
var classes = ['_c-' + options.colour, '_s-' + options.style, '_sz-' + options.size];
var type;
// Functions
var bindings = {
blur: function () {
Rocket.classes.remove(formContainer, ['_focused'].concat((element.value.length < 1) ? ['_valued'] : []));
},
checkbox: function () {
checkSelect(false, type, element, formContainer);
},
focus: function () {
Rocket.classes.add(formContainer, ['_focused', '_valued']);
},
radio: function () {
radioSelect(false, type, element, formContainer);
}
};
function clearValue() {
if (type === 'text' || type === 'textarea') {
element.value = '';
Rocket.classes.remove(formContainer, ['_focused'].concat((element.value.length < 1) ? ['_valued'] : []));
}
}
function toggle(option) {
switch (type) {
case 'checkbox':
checkSelect(option, type, element, formContainer);
break;
case 'radio':
radioSelect(option, type, element, formContainer);
break;
}
;
}
// Set type
if (formContainer.querySelector('input')) {
// Inputs
element = formContainer.querySelector('input');
type = element.getAttribute('type');
}
else if (formContainer.querySelector('textarea')) {
// Textarea
element = formContainer.querySelector('textarea');
type = 'textarea';
}
else if (formContainer.querySelector('select')) {
// Selects
element = formContainer.querySelector('select');
type = 'select';
}
// Bind events
switch (type) {
case 'checkbox':
if (!Rocket.has.class(formContainer, 'rf-check') && !Rocket.has.class(formContainer, 'rf-tog')) {
Rocket.event.add(element, 'click', bindings.checkbox);
}
break;
case 'radio':
if (!Rocket.has.class(formContainer, 'rf-check') && !Rocket.has.class(formContainer, 'rf-tog')) {
Rocket.event.add(element, 'click', bindings.radio);
}
break;
default:
Rocket.event.add(element, 'focus', bindings.focus);
Rocket.event.add(element, 'blur', bindings.blur);
}
;
// Apply styles
switch (type) {
case 'checkbox':
case 'radio':
// Checked
if (element.checked) {
classes.push('_checked');
}
else {
Rocket.classes.remove(element, '_checked');
}
// Toggler?
if (Rocket.has.class(element, 'toggler')) {
classes.push('rf-tog');
}
Expand Down Expand Up @@ -100,53 +165,19 @@ var RockMod_Form;
setTimeout(function () {
Rocket.classes.add(formContainer, '_animate');
}, 50);
function clearValue() {
if (type === 'text' || type === 'textarea') {
element.value = '';
Rocket.classes.remove(formContainer, ['_focused'].concat((element.value.length < 1) ? ['_valued'] : []));
}
}
function toggle(option) {
switch (type) {
case 'checkbox':
checkSelect(option, type, element, formContainer);
break;
case 'radio':
radioSelect(option, type, element, formContainer);
break;
}
;
}
switch (type) {
case 'checkbox':
Rocket.event.add(element, 'click', function () {
checkSelect(false, type, element, formContainer);
});
break;
case 'radio':
Rocket.event.add(element, 'click', function () {
radioSelect(false, type, element, formContainer);
});
break;
default:
Rocket.event.add(element, 'focus', function () {
Rocket.classes.add(formContainer, ['_focused', '_valued']);
});
Rocket.event.add(element, 'blur', function () {
Rocket.classes.remove(formContainer, ['_focused'].concat((element.value.length < 1) ? ['_valued'] : []));
});
}
;
// Return
return {
toggle: toggle,
clear: clearValue,
form: element
};
}
function radioSelect(inpOption, type, elm, container) {
// Catch
if (type !== 'radio') {
return false;
}
// Continue
var option = (typeof inpOption === 'string') ? inpOption : false;
if (option === 'off') {
check.off(elm, container);
Expand All @@ -161,6 +192,7 @@ var RockMod_Form;
check.on(elm, container);
}
}
// Initialiser
function init(uOptions) {
if (!Rocket.is.object(uOptions)) {
uOptions = {};
Expand All @@ -173,9 +205,11 @@ var RockMod_Form;
style: Rocket.helper.setDefault(uOptions.style, Rocket.defaults.form.style)
};
var formElms = Rocket.dom.select(options.targets);
// Catch
if (formElms.length <= 0) {
return false;
}
// Continue
var objReturn = [];
for (var _i = 0, formElms_1 = formElms; _i < formElms_1.length; _i++) {
var elm = formElms_1[_i];
Expand All @@ -185,4 +219,5 @@ var RockMod_Form;
}
RockMod_Form.init = init;
})(RockMod_Form || (RockMod_Form = {}));
// Bind to Rocket
Rocket.form = RockMod_Form.init;
Empty file modified build/sass/_development.scss
100644 → 100755
Empty file.
Empty file modified build/sass/_import.scss
100644 → 100755
Empty file.
Empty file modified build/sass/css/_execute.scss
100644 → 100755
Empty file.
Empty file modified build/sass/form.scss
100644 → 100755
Empty file.
Empty file modified build/sass/module/_check.scss
100644 → 100755
Empty file.
Empty file modified build/sass/module/_input.scss
100644 → 100755
Empty file.
Empty file modified build/sass/module/_label.scss
100644 → 100755
Empty file.
Empty file modified build/sass/module/_select.scss
100644 → 100755
Empty file.
Empty file modified build/sass/module/_setup.scss
100644 → 100755
Empty file.
Empty file modified build/sass/module/_textarea.scss
100644 → 100755
Empty file.
Empty file modified build/sass/module/_toggler.scss
100644 → 100755
Empty file.
Loading

0 comments on commit 0271205

Please sign in to comment.