123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- //Basic shit to understand
- //all_artesanos is the json that has the file that contains all the artesanos, this includes the studd they do,municipio,telefono,email and name
- //x is going to be what is displayed in the app, it basically has the same infromation as all_artesanos
- //THe basic mechanic is to display each artist in the search tab whenever something of them is found
- //You need at least 3 characters in one of the searchbars for it to display something
- //If nothing is written then it will display every artists
- //Some of these functions also try to make sure that the inputs are the same format as the thing they're looking up so that they dont have to follow a specific syntax to look for stuff
-
- //Tries to filter by the type of work that the artists do, if what they wrote in inputarte is included in one of them then the artists is displayed in the search bar
- function filter_artesanias(inputarte){
- var x = document.getElementsByClassName('artists');
- for (var i = 0; i < all_artesanos.length; i++){
- var especificaciones = all_artesanos[i].Especificacion;
- especificaciones = especificaciones.trim().toLowerCase();
- especificaciones = acento_replace(especificaciones);
- if (especificaciones.search(inputarte) != -1){
- x[i].style.display = "list-item";
- }
- //before it did this down here but im keeping it just in case...
- //especificaciones = especificaciones.split(',');
- //for (var j = 0; j < especificaciones.length; j++){
- //var especificacion = especificaciones[j];
- //especificacion = especificacion.trim().toLowerCase();
- //especificacion = acento_replace(especificacion);
- //if (especificacion.search(inputarte) != -1){
- //x[i].style.display = "list-item";
- //break;
- //}
-
- }
- return;
- }
-
- //Tries to filter by the municipio that they reside in or work in (not sure which one of the two it is)
- function filter_municipios(inputmuni){
- var x = document.getElementsByClassName('artists');
- for (var i = 0; i < all_artesanos.length; i++){
- var municipio = all_artesanos[i].Municipio;
- municipio = municipio.trim().toLowerCase();
- municipio = acento_replace(municipio);
- if (municipio.search(inputmuni)!= -1){
- x[i].style.display = "list-item";
- }
- }
- return;
- }
-
- //Tries to filter by any kind of information provided (name,artesania,municipio,telefono,email)
- function filter_any(input){
- var x = document.getElementsByClassName('artists');
- for (var i = 0; i < all_artesanos.length; i++){
- if (find_name(i,input)){
- x[i].style.display = "list-item";
- continue;
- }
- else if (find_artesania(i,input)){
- x[i].style.display = "list-item";
- continue;
- }
- else if (find_municipio(i,input)){
- x[i].style.display = "list-item";
- continue;
- }
- else if (find_telefono(i,input)){
- x[i].style.display = "list-item";
- continue;
- }
- else if (find_email(i,input)){
- x[i].style.display = "list-item";
- continue;
- }
- }
- return;
- }
-
- //Te trata de buscar si cualquiera de ellos tienen el input que se dio aplica a ese artista especifico (i)
- function find_any(i,input){
- //if you find any of these in that space then return 1 if you didnt find that anything matched with the input then return 0
- if (find_name(i,input) || find_telefono(i,input) || find_email(i,input) || find_artesania(i,input) || find_municipio(i,input)){
- return 1;
- }
- else{
- return 0;
- }
- }
-
- //Trata de ver si el input es parte del nombre del artista i
- //Mayuscula y acento proof
- function find_name(i,input){
- var name = all_artesanos[i].Nombre;
- name = name.trim().toLowerCase();
- name = acento_replace(name);
- if(name.search(input) != -1){
- return 1;
- }
- return 0;
- }
-
- //trata de ver si el input es parte de alguna artesania que trabaja el artista i
- //Mayuscula y acento proof
- function find_artesania(i,input){
- var artesanias = all_artesanos[i].Especificacion;
- artesanias = artesanias.trim().toLowerCase();
- artesanias = acento_replace(artesanias);
- if(artesanias.search(input) != -1){
- return 1;
- }
- //artesanias = artesanias.split(',');
- //for (var j = 0; j < artesanias.length; j++){
- //var artesania = artesanias[j];
- //artesania = artesania.trim().toLowerCase();
- //artesania = acento_replace(artesania);
- //if (artesania.search(input) != -1){
- //return 1;
- //}
- //}
- return 0;
- }
-
- //trata de ver si el input es parte del municipio del artista i
- //Mayuscula y acento proof
- function find_municipio(i,input){
- var mun = all_artesanos[i].Municipio;
- mun = mun.trim().toLowerCase();
- mun = acento_replace(mun);
- if(mun.search(input) != -1){
- return 1;
- }
- return 0;
- }
-
- //trata de ver si el input es parte del telefono del artista i
- //'(',')','-' and ' ' proof
- function find_telefono(i,input){
- var tel = all_artesanos[i]["Telefono 1"];
- tel = tel.trim();
- //To make sure they're both the same im taking out spaces,'(',')' and '-' to make sure they're both the same format
- tel = tel.replace(/\s/g,'').replace(/\u0028/g,'').replace(/\u0029/g,'').replace(/\u002D/g,'');
- input = input.replace(/\s/g,'').replace(/\u0028/g,'').replace(/\u0029/g,'').replace(/\u002D/g,'');
- if(tel.search(input) != -1){
- return 1;
- }
- return 0;
- }
-
- //trata de ver si el input es parte del email del artista i
- //Mayuscula and acento proof
- function find_email(i,input){
- var email = all_artesanos[i]["E-mail"];
- email = email.trim().toLowerCase();
- email = acento_replace(email);
- if(email.search(input) != -1){
- return 1;
- }
- return 0;
- }
-
- //Esta funcion trata de coger el numero de caso que se esta buscando, esto es para saber que
- //caso del switch para considerar
- //LOs casos dependen de lo que esta escrito en cada search bar, cada vez que se escribe en uno nuevo o cuando se borra completamente uno entonces es un caso nuevo
- function getcasenum(input,inputarte,inputmuni){
- //this will get the case number
- //think of this as 3 binary numbers where 001 would mean that only its input muni
- //010 is only inputarte and 100 is only input
- //max number is 7
- var casenum = 0;
- if (input.length != 0){
- casenum += 4;
- }
- if (inputarte.length != 0){
- casenum += 2;
- }
- if (inputmuni.length != 0){
- casenum += 1;
- }
- return casenum;
- }
-
- //case 3: artesania y municipio
- //Busca todos los artistas que trabajan con esa artesania y en ese municipio
- function search_art_mun(inputarte,inputmuni){
- var x = document.getElementsByClassName('artists');
- for (var i = 0; i < all_artesanos.length; i++){
- if (find_artesania(i,inputarte) && find_municipio(i,inputmuni)){
- x[i].style.display = "list-item";
- }
- }
- }
-
- //Busca todos los artistas que salen con el primer input y trabajan en ese municipio
- function search_any_mun(input,inputmuni){
- var x = document.getElementsByClassName('artists');
- for (var i = 0; i < all_artesanos.length; i++){
- if(find_any(i,input) && find_municipio(i,inputmuni)){
- x[i].style.display = "list-item";
- }
- }
- }
-
- //Busca todos los artistas que salen con el primer input y trabajan con esa artesania
- function search_any_art(input,inputarte){
- var x = document.getElementsByClassName('artists');
- for (var i = 0; i < all_artesanos.length; i++){
- if(find_any(i,input) && find_artesania(i,inputarte)){
- x[i].style.display = "list-item";
- }
- }
- }
-
- //Busca todos los artistas que salen con el primer input, trabajan con esa artesania y trabajan en ese municipio
- function search_any_art_mun(input,inputarte,inputmuni){
- var x = document.getElementsByClassName('artists');
- for (var i = 0; i < all_artesanos.length; i++){
- if(find_any(i,input) && find_artesania(i,inputarte) && find_municipio(i,inputmuni)){
- x[i].style.display = "list-item";
- }
- }
- }
-
- //Replacing special characters with non special characters in case input doesnt include it
- function acento_replace(string){
- var precstring = "";
- var poststring = "";
- for( i = 0; i < string.length ; i++){
- if (string.charAt(i) == 'á' || string.charAt(i) == 'é' || string.charAt(i) == 'í'|| string.charAt(i) == 'ó' || string.charAt(i) == 'ú' || string.charAt(i) == 'ü' || string.charAt(i) == 'ñ' || string.charAt(i) == 'ö'){
- precstring = string.slice(0,i);
- postcstring = "";
- if(i != string.length-1){
- postcstring = string.slice(i+1,string.length);
- }
- switch(string.charAt(i)){
- case 'á':
- string = precstring.concat('a',postcstring);
- break;
- case 'é':
- string = precstring.concat('e',postcstring);
- break;
- case 'í':
- string = precstring.concat('i',postcstring);
- break;
- case 'ó':
- string = precstring.concat('o',postcstring);
- break;
- case 'ú':
- string = precstring.concat('u',postcstring);
- break;
- case 'ü':
- string = precstring.concat('u',postcstring);
- break;
- case 'ñ':
- string = precstring.concat('n',postcstring);
- break;
- case 'ö':
- string = precstring.concat('o',postcstring);
- break;
- }
- }
- }
- return string;
- }
|