Skip to content

Commit

Permalink
Changed parameters names on SqS, removed unnecesary files, minified lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
c3r38r170 committed Aug 14, 2021
1 parent 4b1f2a5 commit 12a5324
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode
.vscode
-*.html
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
Collection of personal sets of functions to speed up web development.

## TO DO
- Debug new changes introduced.
- Change SqS's cantidad parameter.
- Add version number.
- Minified version.
- ~~Get a CDN.~~ Publish to NPM.
- Translate SqS completely.
- Try to get rid of `// TODO`s.
Expand Down
1 change: 1 addition & 0 deletions c3tools-min.js

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

29 changes: 14 additions & 15 deletions c3tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,22 @@ const gEt=id=>D.getElementById(id);
* Wrapper for querySelector, querySelectorAll, and any other DOM query methods.
* @param {string} selector - CSS selector to look for.
* @param {object} [obj]={} - Wrapper
* @param {(number|boolean)} [obj.cantidad]=ONLY_ONE - Ammount of Nodes to return, defaults to false (ONLY_ONE).
* @param {HTMLElement} [obj.ancestroComun]=D - DOM element on which the query will be done.
* @param {(number|boolean)} [obj.n]=ONLY_ONE - Ammount of elements to return, defaults to false (ONLY_ONE).
* @param {HTMLElement} [obj.from]=D - DOM element on which the query will be done.
* @returns {(HTMLElement|NodeList|boolean)} The element or false if cantidad was 1 or false, a NodeList if cantidad was more than 1 or true.
*/
// TODO translate
// TODO cambiar cantidad por n
function SqS(selector,{cantidad=ONLY_ONE,ancestroComun=D}={}){
function SqS(selector,{n=ONLY_ONE,from=D}={}){
if(selector instanceof Node)//??? Node vs HTMLElement
return selector;
if(is(selector,Types.STRING)){
let resultados, restoDeSelector=selector.slice(1);
if(/[ :\[\.#,+~]/.test(restoDeSelector))
if(!cantidad||cantidad===1)
return ancestroComun.querySelector(selector)
else if(cantidad===true)
return ancestroComun.querySelectorAll(selector);
else resultados=ancestroComun.querySelectorAll(selector);
if(!n||n===1)
return from.querySelector(selector)
else if(n===true)
return from.querySelectorAll(selector);
else resultados=from.querySelectorAll(selector);
else switch(selector[0]){
case '#':
// TODO reconsider
Expand All @@ -115,7 +114,7 @@ function SqS(selector,{cantidad=ONLY_ONE,ancestroComun=D}={}){
?resultado
:false;
case '.':
resultados=ancestroComun.getElementsByClassName(restoDeSelector);
resultados=from.getElementsByClassName(restoDeSelector);
break;
case '[':
let nameMatch=/^\[name="([^"]*)"\]$/.exec(selector);
Expand All @@ -125,19 +124,19 @@ function SqS(selector,{cantidad=ONLY_ONE,ancestroComun=D}={}){
case ':':
break;
default:
resultados=ancestroComun.getElementsByTagName(selector);
resultados=from.getElementsByTagName(selector);
}
if(!cantidad||cantidad===1)
if(!n||n===1)
return resultados?resultados[0]:D.querySelector(selector);
else if(cantidad===true)
else if(n===true)
return resultados?resultados:D.querySelectorAll(selector);
else{
if(!resultados)
resultados=D.querySelectorAll(selector);
if(cantidad>=resultados.length)
if(n>=resultados.length)
return resultados;
let respuesta=[];
for(let i=0;i<cantidad;i++)
for(let i=0;i<n;i++)
respuesta.push(resultados[i]);
return respuesta;
}
Expand Down
26 changes: 0 additions & 26 deletions index.html

This file was deleted.

0 comments on commit 12a5324

Please sign in to comment.