1/* This file is part of cbui. 2 * Copyright © 2010-2012 stiftung kulturserver.de ggmbh <[email protected]> 3 * 4 * cbui is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * cbui is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with cbui. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18/** 19 * A text widget. This simply shows the text for some ML label retrieved via 20 * jQuery(element).text(). 21 */ 22jQuery.CbWidget.text = jQuery.CbWidget.widget.extend({ 23 24 changeLanguage : function(bricks) { 25 if (this.texts.text) this.element().html(bricks[this.texts.text]); 26 if (this.texts.title) { 27 this.element().attr('title', bricks[this.texts.title]); 28 } 29 if (this.texts.alt) { 30 this.element().attr('alt', bricks[this.texts.alt]); 31 } 32 if (this.texts.ariaLabel) { 33 this.element().attr('aria-label', bricks[this.texts.ariaLabel]); 34 } 35 }, 36 37 constructor : function(element) { 38 this.base(element); 39 var label = this.element().text().trim(); 40 if (label !== '') this.texts.text = label; 41 var title = this.element().attr('title'); 42 if (title) this.texts.title = title; 43 var alt = this.element().attr('alt'); 44 if (alt) this.texts.alt = alt; 45 var ariaLabel = this.element().attr('aria-label'); 46 if (ariaLabel) this.texts.ariaLabel = ariaLabel; 47 }, 48 49 value : function(text) { 50 this.element().html(text); 51 } 52}); 53 54/** 55 * A widget showing alternate texts which can be switched using show(). By 56 * default no text is shown. This is particularly useful for error messages. 57 * 58 * It expects a DOM element with children, each of which has an ML label as 59 * text. 60 */ 61jQuery.CbWidget.multiText = jQuery.CbWidget.widget.extend({ 62 63 constructor : function(element) { 64 this.base(element); 65 this.cycler = new CbElementCycler(element.children()); 66 this.cycler.hide(); 67 var self = this; 68 this.cycler.elements.each(function(index) { 69 var label = jQuery(this).text(); 70 self.texts[index] = label; 71 }); 72 }, 73 74 handleHide : function(params) { 75 this.base(); 76 this.cycler.hide(); 77 }, 78 79 handleShow : function(params) { 80 this.base(); 81 if (typeof(params.label) == 'number') { 82 this.cycler.show(params.label); 83 } else { 84 for (var pos in this.texts) { 85 if (this.texts[pos] == params.label) { 86 this.cycler.show(pos); 87 break; 88 } 89 } 90 } 91 }, 92 93 /** 94 * Get the currently shown text. 95 * @return Currently shown text. 96 */ 97 getShown : function() { 98 return this.cycler.getShown(); 99 }, 100 101 numTexts : function() { 102 return this.cycler.elements.length; 103 }, 104 105 /** 106 * show the text belonging to the given label, provided it is available. 107 * Hide any other text. short for trigger('show', ...) 108 */ 109 showText : function(label) { 110 return this.trigger('show', {'label' : label}); 111 }, 112 113 hideText : function() { 114 return this.hide(); 115 }, 116 117 changeLanguage : function(bricks) { 118 var self = this; 119 this.cycler.elements.each(function(index) { 120 jQuery(this).html(bricks[self.texts[index]]); 121 }); 122 return this; 123 }, 124 125 handleDestroy : function() { 126 this.base(); 127 this.cycler.destroy(); 128 } 129}); 130/** 131 * A error message widget. This simply shows the text for some ML label retrieved via 132 * jQuery(element).text(). 133 */ 134jQuery.CbWidget.errorMessage = jQuery.CbWidget.widget.extend({ 135 136 changeLanguage : function(bricks) { 137 if (this.texts.text) this.element().html(bricks[this.texts.text]); 138 if (this.texts.title) { 139 this.element().attr('title', bricks[this.texts.title]); 140 } 141 }, 142 143 constructor : function(element) { 144 this.base(element);
145 var label = this.element().text().trim(); 146 if (label !== '') this.texts.text = label; 147 var title = this.element().attr('title'); 148 if (title) this.texts.title = title; 149 }, 150 151 value : function(text) { 152 this.element().html(text); 153 }, 154 155 handleShow : function(params) { 156 this.base(); 157 this.element().slideDown().addClass('visible'); 158 }, 159 160 handleHide : function(params) { 161 this.base(); 162 this.element().slideUp().removeClass('visible'); 163 } 164}); 165 166/** 167 * A text widget. This simply shows the text for some ML label retrieved via 168 * jQuery(element).text(). 169 */ 170jQuery.CbWidget.attribute = jQuery.CbWidget.widget.extend({ 171 172 changeLanguage : function(bricks) { 173 if (this.texts.text) this.element().html(bricks[this.texts.text]); 174 if (this.texts.title) { 175 this.element().attr('title', bricks[this.texts.title]); 176 } 177 if (this.texts.alt) { 178 this.element().attr('alt', bricks[this.texts.alt]); 179 } 180 if (this.texts.placeholder) { 181 this.element().attr('placeholder', bricks[this.texts.placeholder]); 182 } 183 if (this.texts.ariaLabel) { 184 this.element().attr('aria-label', bricks[this.texts.ariaLabel]); 185 } 186 }, 187 188 constructor : function(element) { 189 this.base(element); 190 var placeholder = this.element().attr('placeholder').trim(); 191 if (placeholder) this.texts.placeholder = placeholder; 192 var title = this.element().attr('title'); 193 if (title) this.texts.title = title; 194 var alt = this.element().attr('alt'); 195 if (alt) this.texts.alt = alt; 196 var ariaLabel = this.element().attr('aria-label'); 197 if (ariaLabel) this.texts.ariaLabel = ariaLabel; 198 } 199});
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.