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 18jQuery.CbUtil = {}; 19jQuery.CbUtil.element_cycler = base2.Base.extend({ 20 /** 21 * Cycle through the elements: show the next one or the 22 * given one. 23 */ 24 show : function(index) { 25 if (typeof(index) == 'undefined') index = this.shown_field + 1; 26 if (index >= this.elements.length) index = 0; 27 28 if (this.shown_field >= 0) { 29 jQuery(this.elements[this.shown_field]).hide(); 30 } 31 jQuery(this.elements[index]).show(); 32 33 this.shown_field = index; 34 }, 35 36 hide : function() { 37 if (this.shown_field < 0) return; 38 jQuery(this.elements[this.shown_field]).hide(); 39 this.shown_field = -1; 40 }, 41 42 getShown : function() { 43 return jQuery(this.elements[this.shown_field]); 44 }, 45 46 constructor : function(elements) { 47 base2.lang.assert(elements.length > 0); 48 this.base(); 49 this.shown_field = 0; 50 this.elements = elements; 51 this.original_state = []; 52 var self = this; 53 elements.each(function(index) { 54 self.original_state[index] = jQuery(this).css('display'); 55 }); 56 this.elements.hide(); 57 jQuery(this.elements[0]).show(); 58 }, 59 60 destroy : function() { 61 var self = this; 62 this.elements.each(function(index) { 63 jQuery(this).css('display', self.original_state[index]); 64 }); 65 }, 66 67 refreshElement : function() { 68 this.elements = jQuery(this.elements); 69 } 70}); 71 72jQuery.CbUtil.element_pivot = base2.Base.extend({ 73 74 constructor : function(element, pivot_tag) { 75 this.base(); 76 this.parent = jQuery(document.createElement(pivot_tag || 'span')); 77 this.parent.attr('id', element.attr('id')); 78 element.removeAttr('id'); 79 this.parent.insertAfter(element); 80 this.parent = jQuery(this.parent); 81 this.parent.append(element.remove()); 82 this.child = this.parent.children(); 83 }, 84 85 destroy : function() { 86 this.child.insertAfter(this.parent).attr('id', this.parent.attr('id')); 87 this.parent.remove(); 88 }, 89 90 refreshElement : function() { 91 this.child = jQuery(this.child); 92 this.parent = jQuery(this.parent); 93 } 94}); 95 96jQuery.CbUtil.window_closer = base2.Base.extend({ 97 constructor : function(element) { 98 this.base(); 99 this.element = element; 100 }, 101 102 destroy : function() { 103 var element = this.element; 104 while(typeof(element.CbWidget) != 'function' || typeof(element.CbWidget().close) != 'function') { 105 var parent = jQuery(element.parent()); 106 if (!parent || parent == element) { 107 return; 108 } else { 109 element = parent; 110 } 111 } 112 element.CbWidget().close(); 113 }, 114 115 refreshElement : function() { 116 this.element = jQuery(this.element); 117 } 118}); 119 120jQuery.CbUtil.base64_codec = base2.Base.extend({ 121 b64 : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", 122 123 encode : function(input) { 124 input = window.unescape(window.encodeURIComponent(input)); 125 if (typeof window.btoa === 'function') { 126 return window.btoa(input); 127 } else { 128 var output = ""; 129 var chr1, chr2, chr3, enc1, enc2, enc3, enc4; 130 var i = 0; 131 132 while (i < input.length) { 133 134 chr1 = input.charCodeAt(i++); 135 chr2 = input.charCodeAt(i++); 136 chr3 = input.charCodeAt(i++); 137 138 enc1 = chr1 >> 2; 139 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); 140 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); 141 enc4 = chr3 & 63; 142 143 if (isNaN(chr2)) { 144 enc3 = enc4 = 64; 145 } else if (isNaN(chr3)) { 146 enc4 = 64; 147 } 148 149 output += this.b64.charAt(enc1) + this.b64.charAt(enc2) + 150 this.b64.charAt(enc3) + this.b64.charAt(enc4); 151 } 152 return output; 153 } 154 }, 155 156 decode : function (input) { 157 if (typeof window.atob === 'function') { 158 output = window.atob(input); 159 } else { 160 var output = ""; 161 var chr1, chr2, chr3; 162 var enc1, enc2, enc3, enc4; 163 var i = 0; 164 165 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 166 167 while (i < input.length) { 168 enc1 = this.b64.indexOf(input.charAt(i++)); 169 enc2 = this.b64.indexOf(input.charAt(i++)); 170 enc3 = this.b64.indexOf(input.charAt(i++)); 171 enc4 = this.b64.indexOf(input.charAt(i++)); 172 173 chr1 = (enc1 << 2) | (enc2 >> 4); 174 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 175 chr3 = ((enc3 & 3) << 6) | enc4; 176 177 output += String.fromCharCode(chr1); 178 179 if (enc3 != 64) output = output + String.fromCharCode(chr2); 180 if (enc4 != 64) output = output + String.fromCharCode(chr3); 181 } 182 } 183 return window.decodeURIComponent(window.escape(output)); 184 } 185}); 186 187jQuery.CbUtil.xml_codec = base2.Base.extend({ 188 decode : function(element) { 189 var self = this; 190 switch (element.attr('type')) { 191 case 'number': 192 return +element.text(); 193 case 'string': 194 return element.text(); 195 case 'null': 196 return null; 197 case 'boolean': 198 return element.text() === '1' ? true : false;
199 case 'object': 200 var numeric = element.attr('numeric') === '1'; 201 var result = numeric ? [] : {}; 202 element.children().each(function(i, child) { 203 child = jQuery(child); 204 if (numeric) { 205 result.push(self.decode(child)); 206 } else { 207 result[child.attr('key')] = self.decode(child); 208 } 209 }); 210 return result; 211 } 212 } 213}); 214 215/** 216 * @deprecated Use the properly scoped variants 217 */ 218var CbElementCycler = jQuery.CbUtil.element_cycler; 219var CbWindowCloser = jQuery.CbUtil.window_closer; 220var CbBase64Codec = jQuery.CbUtil.base64_codec; 221var CbElementPivot = jQuery.CbUtil.element_pivot;
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.