1/** 2FontSize.class.js 3Descripcion: 4 Cambia el tamaño de la fuenta para los estilos que coincidan con cierto patrones 5 como titular, bajada, cuerpo, etc. Véase la sección de configuración más abajo 6 para cambiar dichos parámetros. 7 OJO: Cambia el estilo de la primera hoja de estilos definida en la página 8 Próximamente podría quedar obsoleto, por lo que la documentación es básica 9 10Dependencias: 11 Ninguna 12 13Versión: 14 ---------------------------------------------------------------------------- 15 2.0.0 - 11/11/2009 - CVI - Primera Versión coa Orientación a Objetos 16 Basada en la version 1.10 de cambia_tam_fonts.js 17**/ 18 19var FontSize = { 20 21 /** 22 * Zona de Configuraciones 23 */ 24 25 // Tamaño actual En porcentaje 26 size_actual: 100, 27 28 // Arreglo con los tamaños a los que se podrá cambiar 29 tamanos: [70,80,90,100,130,180,250], 30 31 // patrones que se buscarán para cambiar el estilo 32 estilos: ['titular','bajada','epigrafe','cuerpo','CUERPO','CUERPO p', 'fecha',], 33 34 // indice del arrglo de tamanos (3 = 4to elemento) 35 size_actual_i: 3, 36 37 // Mensaje cuando no se puede usar esta opcion 38 msgError: 'Este Navegador no soporta aumento/disminución de tamaño de texto.', 39 40 // En el caso de que se quiera procesar otro CSS y no el primero 41 indice_hoja_estilos: 0, 42 43 44 /** ---------- 45 * Propiedades de la clase 46 */ 47 fontWeight_default: '', 48 fontFamily_default: '', 49 fontSize_default: '', 50 color_default: '', 51 fontweight: [], 52 fontfamily: [], 53 fontsize: [], 54 fontcolor: [], 55 initiated: false, 56 firstsheet: null, 57 therules: null, 58 var_elements: [], 59 60 61 /** 62 * Funcion que inicializa los tamaños de fuentes 63 * Se llama automaticamente al intentar cambiar de tamaño 64 */ 65 init: function () { 66 67 if (! document.styleSheets) { // 1.8 Funciona solo para browsers capaces. 68 return false; 69 } 70 71 // Inicializa arreglos de estilos. V1.7. 72 FontSize.firstsheet = document.styleSheets[FontSize.indice_hoja_estilos]; 73 if(FontSize.firstsheet.cssRules) { 74 FontSize.therules = FontSize.firstsheet.cssRules; 75 } else { 76 FontSize.therules = FontSize.firstsheet.rules; 77 } 78 79 // Rescata los atributos de los css del primer archivo de estilos de la 80 // pagina html (por eso se usa el subindice 0). 81 var theruleslen = FontSize.therules.length; 82 for (var j=0; j < theruleslen; j++) { // 1.2 83 if (typeof FontSize.therules[j].style !== 'undefined') { 84 FontSize.fontweight[j] = FontSize.therules[j].style.fontWeight; 85 FontSize.fontfamily[j] = FontSize.therules[j].style.fontFamily; 86 FontSize.fontsize[j] = FontSize.therules[j].style.fontSize;
87 FontSize.fontcolor[j] = FontSize.therules[j].style.color; 88 } 89 } 90 91 // Busca los elementos a modificar (css). Estos son fijos y hay que 92 // agregarlos directamente en este archivo. 93 94 for (var i=0; i < theruleslen; i++) { 95 var aux = FontSize.therules[i].selectorText; 96 97 if (typeof aux !== 'undefined') { 98 var found = 0; 99 if (aux == '*') { 100 if (typeof FontSize.therules[j].style !== 'undefined') { 101 FontSize.fontWeight_default = FontSize.therules[i].style.fontWeight; 102 FontSize.fontFamily_default = FontSize.therules[i].style.fontFamily; 103 FontSize.fontSize_default = FontSize.therules[i].style.fontSize; 104 FontSize.color_default = FontSize.therules[i].style.color; 105 } 106 } 107 // 1.8 Encuentra estilos a afectar. 108 for (var k=0; k < FontSize.estilos.length; k++) { 109 if ( (aux.indexOf(FontSize.estilos[k]) >= 0) && (aux.indexOf(':hover') < 0) ) { 110 found = 1; 111 } 112 } 113 if (found == 1) { 114 FontSize.var_elements[FontSize.var_elements.length] = i; 115 } 116 } 117 } 118 return true; 119 }, 120 121 /** 122 * Esta funcion en la que cambia los tamaños 123 * @param signo Signo para cambiar, puede se 'mas' o 'menos' 124 */ 125 cambiaSize: function (signo) { 126 if (! document.styleSheets) { // 1.8 Funciona solo para browsers capaces. 127 alert(FontSize.msgError); 128 return; 129 } 130 if(! FontSize.initited) { 131 var resp = FontSize.init(); 132 if(! resp) { 133 alert(FontSize.msgError); 134 return; 135 } 136 FontSize.initited = true; 137 } 138 139 if ( signo == 'mas' ) {// 1.3 140 if (FontSize.size_actual_i >= (FontSize.tamanos.length - 1)) { 141 return; 142 } 143 FontSize.size_actual_i++; 144 } else { 145 if (FontSize.size_actual_i <= 0) { 146 return; 147 } 148 FontSize.size_actual_i--; 149 } 150 FontSize.size_actual = FontSize.tamanos[FontSize.size_actual_i]; 151 152 // 1.5 Solo aplica cambios a elementos preseleccionados. 153 var varelemlen = FontSize.var_elements.length; 154 for (var i=0; i < varelemlen; i++) { 155 var j = FontSize.var_elements[i]; 156 if (FontSize.fontsize[j] === '') { 157 if (FontSize.fontSize_default !== '') { 158 FontSize.fontsize[j] = FontSize.fontSize_default; 159 } else { 160 FontSize.fontsize[j] = 12; 161 } 162 } // V1.7. 163 var tam_final = parseInt((parseInt(FontSize.fontsize[j], 10) * FontSize.size_actual)/100, 10); 164 165 if (tam_final - parseInt(tam_final, 10) > 0) { 166 // Si resultado da con decimal, se agrega uno al entero. 167 tam_final = parseInt(tam_final, 10) + 1; 168 } 169 FontSize.therules[j].style.fontSize = tam_final+'px'; // 1.8 170 } 171 } 172};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.