Permalink
Browse files

Version 0.8

Improved shinny new HTML5 input type support
  • Loading branch information...
1 parent b9418f6 commit 634f94c10e0e8c07706aa101429796e4fa1540a6 @kylebarrow committed Jul 28, 2012
Showing with 13 additions and 7 deletions.
  1. +1 −1 README.md
  2. +1 −1 chibi-min.js
  3. +11 −5 chibi.js
View
@@ -1,4 +1,4 @@
-# Chibi v0.7
+# Chibi v0.8
#### A tiny JavaScript micro-framework
View
@@ -1 +1 @@
-/*Chibi v0.7, (C)2012 Kyle Barrow, GPLv3 Licensed*/(function(){"use strict";function o(){n=!0;for(var t=0;t<e.length;t++)e[t]();e=[]}function u(){r=!0;n||o();for(var e=0;e<t.length;e++)t[e]();t=[]}function a(e,t){var n=t.length;while(n--)e(t[n])}function f(e){return e.replace(/-\w/g,function(e){return e.charAt(1).toUpperCase()})}function l(e,t){return e.currentStyle?e.currentStyle[f(t)]:s.getComputedStyle?s.getComputedStyle(e,null).getPropertyValue(t):null}function c(e,t){return encodeURIComponent(e).replace(/%20/g,"+")+"="+encodeURIComponent(t).replace(/%20/g,"+")}function h(e){var t=[],n=[],r=!1;if(e)if(e.nodeType&&e.nodeType===1)t=[e];else if(typeof e=="object"||typeof e.length=="number"&&typeof e.item=="function"){r=!0;t=e}else if(typeof e=="string"){i.querySelectorAll||(i.querySelectorAll=function(e){var t,n=i.getElementsByTagName("head")[0],r,s=[];t=i.createElement("STYLE");t.type="text/css";if(t.styleSheet){t.styleSheet.cssText=e+" {a:b}";n.appendChild(t);r=i.getElementsByTagName("*");for(var o=0;o<r.length;o++)l(r[o],"a")==="b"?s.push(r[o]):0;n.removeChild(t)}return s});t=i.querySelectorAll(e)}for(var s=0;s<t.length;s++)n[s]=t[s];return r?t:n}function p(e,t,n){try{e.style[f(t)]=n}catch(r){}}function d(e){e.style.display="";l(e,"display")==="none"?e.style.display="block":0}function v(e){e=e.reverse();e.length===1?e=e[0]:0;return e}function m(e){var t="",n;if(e.constructor===Object){for(n in e)if(e.hasOwnProperty(n))if(e[n].constructor===Array)for(var r=0;r<e[n].length;r++)t+="&"+c(n,e[n][r]);else t+="&"+c(n,e[n])}else a(function(e){if(e.nodeName==="FORM")for(var r=0;r<e.elements.length;r++){n=e.elements[r];if(!n.disabled)switch(n.type){case"text":case"textarea":t+="&"+c(n.name,n.value);break;case"select-one":n.length>0?t+="&"+c(n.name,n.value):0;break;case"select-multiple":for(var i=0;i<n.length;i++)n[i].selected?t+="&"+c(n.name,n[i].value):0;break;case"checkbox":case"radio":n.checked?t+="&"+c(n.name,n.value):0}}},e);return t.length>0?t.substring(1):""}function g(o){var u=h(o);return{ready:function(t){t&&(n?t():e.push(t))},loaded:function(e){e&&(r?e():t.push(e))},find:function(e){if(e){var t=[];switch(e){case"first":u.length>0?u=[u.shift()]:0;break;case"last":u.length>0?u=[u.pop()]:0;break;case"odd":case"even":for(var n=e==="odd"?0:1;n<u.length;n+=2)t.push(u[n]);u=t}}return u.length>0?u.length===1?u[0]:u:!1},hide:function(){a(function(e){e.style.display="none"},u)},show:function(){a(function(e){d(e)},u)},toggle:function(){a(function(e){l(e,"display")==="none"?d(e):e.style.display="none"},u)},remove:function(){var e=u.length;a(function(e){try{e.parentNode.removeChild(e)}catch(t){}},u);u=[]},css:function(e,t){var n=[];a(function(r){t?p(r,e,t):r.style[f(e)]?n.push(r.style[f(e)]):l(r,e)?n.push(l(r,e)):n.push(null)},u);if(n.length>0)return v(n)},cls:function(e,t){var n=[],r,i,s,o;if(e){r=e.split(" ");t=t||"replace"}a(function(u){i=u.className;if(e)switch(t){case"add":u.className=i+" "+e;break;case"replace":u.className=e;break;case"has":case"toggle":case"remove":o=!0;for(var a=0;a<r.length;a++){s=new RegExp("\\b"+r[a]+"\\b","g");if(t==="has"){if(!i.match(s)){o=!1;break}}else t==="toggle"?u.className=u.className.match(s)?u.className.replace(s,""):u.className+" "+r[a]:u.className=u.className.replace(s,"")}t==="has"?n.push(o):0}else n.push(i)},u);if(n.length>0)return v(n)},html:function(e,t){var n=[],r,s;a(function(o){if(t){r=i.createElement("div");r.innerHTML=e;while(s=r.lastChild)try{t==="before"?o.parentNode.insertBefore(s,o):t==="after"&&o.parentNode.insertBefore(s,o.nextSibling)}catch(u){break}}else e?o.innerHTML=e:n.push(o.innerHTML)},u);if(n.length>0)return v(n)},attr:function(e,t){var n=[];a(function(r){if(e){e=e.toLowerCase();switch(e){case"style":t?r.style.cssText=t:r.style.cssText?n.push(r.style.cssText):n.push(null);break;case"class":t?r.className=t:r.className?n.push(r.className):n.push(null);break;default:t?r.setAttribute(e,t):r.getAttribute(e)?n.push(r.getAttribute(e)):n.push(null)}}},u);if(n.length>0)return v(n)},val:function(e){var t=[],n=[];typeof e!="undefined"&&typeof e!="object"&&(e=[e]);a(function(r){if(e)switch(r.nodeName){case"SELECT":for(var i=0;i<r.length;i++)for(var s=0;s<e.length;s++){r[i].selected="";if(r[i].value===e[s]){r[i].selected="selected";break}}break;case"INPUT":switch(r.type){case"checkbox":case"radio":r.checked="";for(var i=0;i<e.length;i++)if(r.value===e[i]){r.checked="checked";break}break;default:r.value=e[0]}break;case"TEXTAREA":case"BUTTON":r.value=e[0]}else switch(r.nodeName){case"SELECT":var o=n.length;n.push([]);for(var i=0;i<r.length;i++)r[i].selected?n[o].push(r[i].value):0;switch(n[o].length){case 0:n[o]=null;break;case 1:n[o]=n[o][0]}break;case"INPUT":switch(r.type){case"checkbox":r.checked?n.push(r.value):n.push(null);break;case"radio":var u=!1;for(var i=0;i<t.length;i++)if(t[i][0]===r.name){r.checked?n[t[i][1]]=r.value:0;u=!0}if(!u){t.push([r.name,n.length]);r.checked?n.push(r.value):n.push(null)}break;default:n.push(r.value)}break;case"TEXTAREA":case"BUTTON":n.push(r.value)}},u);if(n.length>0)return v(n)},on:function(e,t,n){o===s||o===i?u=[o]:0;a(function(r){i.addEventListener?n?r.removeEventListener(e,t,!1):r.addEventListener(e,t,!1):i.attachEvent&&(n?r.detachEvent("on"+e,t):r.attachEvent("on"+e,t))},u)},ajax:function(e,t,n,r){var i,t=t||"GET",o=m(u),a="_ts="+ +(new Date);s.XMLHttpRequest?i=new XMLHttpRequest:s.ActiveXObject&&(i=new ActiveXObject("Microsoft.XMLHTTP"));if(i){t=t.toUpperCase();e=r?t==="POST"?e+"?"+a:e+"?"+o+"&"+a:t==="POST"?e:e+"?"+o;i.open(t,e,!0);t==="POST"?i.setRequestHeader("Content-Type","application/x-www-form-urlencoded"):0;i.send(o);i.onreadystatechange=function(){if(i.readyState===4&&i.status===200&&n)try{n(i.responseText)}catch(e){}}}}}}var e=[],t=[],n=!1,r=!1,i=document,s=window;if(i.addEventListener){i.addEventListener("DOMContentLoaded",o,!1);s.addEventListener("load",u,!1)}else if(i.attachEvent){i.attachEvent("onreadystatechange",o);s.attachEvent("onload",u)}else s.onload=u;s.$=g})();
+/*Chibi v0.8, (C)2012 Kyle Barrow, GPLv3 Licensed*/(function(){"use strict";function o(){n=!0;for(var t=0;t<e.length;t++)e[t]();e=[]}function u(){r=!0;n||o();for(var e=0;e<t.length;e++)t[e]();t=[]}function a(e,t){var n=t.length;while(n--)e(t[n])}function f(e){return e.replace(/-\w/g,function(e){return e.charAt(1).toUpperCase()})}function l(e,t){return e.currentStyle?e.currentStyle[f(t)]:s.getComputedStyle?s.getComputedStyle(e,null).getPropertyValue(t):null}function c(e,t){return encodeURIComponent(e).replace(/%20/g,"+")+"="+encodeURIComponent(t).replace(/%20/g,"+")}function h(e){var t=[],n=[],r=!1;if(e)if(e.nodeType&&e.nodeType===1)t=[e];else if(typeof e=="object"||typeof e.length=="number"&&typeof e.item=="function"){r=!0;t=e}else if(typeof e=="string"){i.querySelectorAll||(i.querySelectorAll=function(e){var t,n=i.getElementsByTagName("head")[0],r,s=[];t=i.createElement("STYLE");t.type="text/css";if(t.styleSheet){t.styleSheet.cssText=e+" {a:b}";n.appendChild(t);r=i.getElementsByTagName("*");for(var o=0;o<r.length;o++)l(r[o],"a")==="b"?s.push(r[o]):0;n.removeChild(t)}return s});t=i.querySelectorAll(e)}for(var s=0;s<t.length;s++)n[s]=t[s];return r?t:n}function p(e,t,n){try{e.style[f(t)]=n}catch(r){}}function d(e){e.style.display="";l(e,"display")==="none"?e.style.display="block":0}function v(e){e=e.reverse();e.length===1?e=e[0]:0;return e}function m(e){var t="",n;if(e.constructor===Object){for(n in e)if(e.hasOwnProperty(n))if(e[n].constructor===Array)for(var r=0;r<e[n].length;r++)t+="&"+c(n,e[n][r]);else t+="&"+c(n,e[n])}else a(function(e){if(e.nodeName==="FORM")for(var r=0;r<e.elements.length;r++){n=e.elements[r];if(!n.disabled)switch(n.type){case"button":case"image":case"file":case"submit":case"reset":break;case"select-one":n.length>0?t+="&"+c(n.name,n.value):0;break;case"select-multiple":for(var i=0;i<n.length;i++)n[i].selected?t+="&"+c(n.name,n[i].value):0;break;case"checkbox":case"radio":n.checked?t+="&"+c(n.name,n.value):0;break;default:t+="&"+c(n.name,n.value)}}},e);return t.length>0?t.substring(1):""}function g(o){var u=h(o);return{ready:function(t){t&&(n?t():e.push(t))},loaded:function(e){e&&(r?e():t.push(e))},find:function(e){if(e){var t=[];switch(e){case"first":u.length>0?u=[u.shift()]:0;break;case"last":u.length>0?u=[u.pop()]:0;break;case"odd":case"even":for(var n=e==="odd"?0:1;n<u.length;n+=2)t.push(u[n]);u=t}}return u.length>0?u.length===1?u[0]:u:!1},hide:function(){a(function(e){e.style.display="none"},u)},show:function(){a(function(e){d(e)},u)},toggle:function(){a(function(e){l(e,"display")==="none"?d(e):e.style.display="none"},u)},remove:function(){var e=u.length;a(function(e){try{e.parentNode.removeChild(e)}catch(t){}},u);u=[]},css:function(e,t){var n=[];a(function(r){t?p(r,e,t):r.style[f(e)]?n.push(r.style[f(e)]):l(r,e)?n.push(l(r,e)):n.push(null)},u);if(n.length>0)return v(n)},cls:function(e,t){var n=[],r,i,s,o;if(e){r=e.split(" ");t=t||"replace"}a(function(u){i=u.className;if(e)switch(t){case"add":u.className=i+" "+e;break;case"replace":u.className=e;break;case"has":case"toggle":case"remove":o=!0;for(var a=0;a<r.length;a++){s=new RegExp("\\b"+r[a]+"\\b","g");if(t==="has"){if(!i.match(s)){o=!1;break}}else t==="toggle"?u.className=u.className.match(s)?u.className.replace(s,""):u.className+" "+r[a]:u.className=u.className.replace(s,"")}t==="has"?n.push(o):0}else n.push(i)},u);if(n.length>0)return v(n)},html:function(e,t){var n=[],r,s;a(function(o){if(t){r=i.createElement("div");r.innerHTML=e;while(s=r.lastChild)try{t==="before"?o.parentNode.insertBefore(s,o):t==="after"&&o.parentNode.insertBefore(s,o.nextSibling)}catch(u){break}}else e?o.innerHTML=e:n.push(o.innerHTML)},u);if(n.length>0)return v(n)},attr:function(e,t){var n=[];a(function(r){if(e){e=e.toLowerCase();switch(e){case"style":t?r.style.cssText=t:r.style.cssText?n.push(r.style.cssText):n.push(null);break;case"class":t?r.className=t:r.className?n.push(r.className):n.push(null);break;default:t?r.setAttribute(e,t):r.getAttribute(e)?n.push(r.getAttribute(e)):n.push(null)}}},u);if(n.length>0)return v(n)},val:function(e){var t=[],n=[];typeof e!="undefined"&&typeof e!="object"&&(e=[e]);a(function(r){if(e)switch(r.nodeName){case"SELECT":for(var i=0;i<r.length;i++)for(var s=0;s<e.length;s++){r[i].selected="";if(r[i].value===e[s]){r[i].selected="selected";break}}break;case"INPUT":switch(r.type){case"checkbox":case"radio":r.checked="";for(var i=0;i<e.length;i++)if(r.value===e[i]){r.checked="checked";break}break;default:r.value=e[0]}break;case"TEXTAREA":case"BUTTON":r.value=e[0]}else switch(r.nodeName){case"SELECT":var o=n.length;n.push([]);for(var i=0;i<r.length;i++)r[i].selected?n[o].push(r[i].value):0;switch(n[o].length){case 0:n[o]=null;break;case 1:n[o]=n[o][0]}break;case"INPUT":switch(r.type){case"checkbox":r.checked?n.push(r.value):n.push(null);break;case"radio":var u=!1;for(var i=0;i<t.length;i++)if(t[i][0]===r.name){r.checked?n[t[i][1]]=r.value:0;u=!0}if(!u){t.push([r.name,n.length]);r.checked?n.push(r.value):n.push(null)}break;default:n.push(r.value)}break;case"TEXTAREA":case"BUTTON":n.push(r.value)}},u);if(n.length>0)return v(n)},on:function(e,t,n){o===s||o===i?u=[o]:0;a(function(r){i.addEventListener?n?r.removeEventListener(e,t,!1):r.addEventListener(e,t,!1):i.attachEvent&&(n?r.detachEvent("on"+e,t):r.attachEvent("on"+e,t))},u)},ajax:function(e,t,n,r){var i,t=t||"GET",o=m(u),a="_ts="+ +(new Date);s.XMLHttpRequest?i=new XMLHttpRequest:s.ActiveXObject&&(i=new ActiveXObject("Microsoft.XMLHTTP"));if(i){t=t.toUpperCase();e=r?t==="POST"?e+"?"+a:e+"?"+o+"&"+a:t==="POST"?e:e+"?"+o;i.open(t,e,!0);t==="POST"?i.setRequestHeader("Content-Type","application/x-www-form-urlencoded"):0;i.send(o);i.onreadystatechange=function(){if(i.readyState===4&&i.status===200&&n)try{n(i.responseText)}catch(e){}}}}}}var e=[],t=[],n=!1,r=!1,i=document,s=window;if(i.addEventListener){i.addEventListener("DOMContentLoaded",o,!1);s.addEventListener("load",u,!1)}else if(i.attachEvent){i.attachEvent("onreadystatechange",o);s.attachEvent("onload",u)}else s.onload=u;s.$=g})();
View
@@ -1,4 +1,4 @@
-/*Chibi v0.7, Copyright (C) 2012 Kyle Barrow
+/*Chibi v0.8, Copyright (C) 2012 Kyle Barrow
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
@@ -204,9 +204,11 @@ You should have received a copy of the GNU General Public License along with thi
if (!subelm.disabled) {
switch (subelm.type) {
// Ignore buttons, unsupported XHR 1 form fields
- case 'text':
- case 'textarea':
- querystring += '&' + queryPair(subelm.name, subelm.value);
+ case 'button':
+ case 'image':
+ case 'file':
+ case 'submit':
+ case 'reset':
break;
case 'select-one':
@@ -223,6 +225,9 @@ You should have received a copy of the GNU General Public License along with thi
case 'radio':
(subelm.checked) ? querystring += '&' + queryPair(subelm.name, subelm.value) : 0;
break;
+ // Everything else including shinny new HTML5 input types
+ default:
+ querystring += '&' + queryPair(subelm.name, subelm.value);
}
}
}
@@ -470,6 +475,7 @@ You should have received a copy of the GNU General Public License along with thi
}
nodeLoop(function(elm) {
+
if (replacement) {
switch (elm.nodeName) {
case 'SELECT':
@@ -563,7 +569,7 @@ You should have received a copy of the GNU General Public License along with thi
}
break;
-
+ // Everything else including shinny new HTML5 input types
default:
values.push(elm.value);
}

0 comments on commit 634f94c

Please sign in to comment.