1/** 2 * 3 * jqTransform 4 * by mathieu vilaplana [email protected] 5 * Designer ghyslain armand [email protected] 6 * 7 * 8 * Version 1.0 25.09.08 9 * Version 1.1 06.08.09 10 * Add event click on Checkbox and Radio 11 * Auto calculate the size of a select element 12 * Can now, disabled the elements 13 * Correct bug in ff if click on select (overflow=hidden) 14 * No need any more preloading !! 15 * 16 ******************************************** */ 17 18(function ($) { 19 var defaultOptions = {preloadImg:true}; 20 var jqTransformImgPreloaded = false; 21 22 var jqTransformPreloadHoverFocusImg = function (strImgUrl) { 23 //guillemets to remove for ie 24 strImgUrl = strImgUrl.replace(/^url\((.*)\)/, '$1').replace(/^\"(.*)\"$/, '$1'); 25 var imgHover = new Image(); 26 imgHover.src = strImgUrl.replace(/\.([a-zA-Z]*)$/, '-hover.$1'); 27 var imgFocus = new Image(); 28 imgFocus.src = strImgUrl.replace(/\.([a-zA-Z]*)$/, '-focus.$1'); 29 }; 30 31 /*************************** 32 Labels 33 ***************************/ 34 var jqTransformGetLabel = function (objfield) { 35 var $form = $(objfield.get(0).form); 36 var oLabel = objfield.next(); 37 if (!oLabel.is('label')) { 38 oLabel = objfield.prev(); 39 if (oLabel.is('label')) { 40 var inputname = objfield.attr('id'); 41 if (inputname) { 42 oLabel = $form.find('label[for="' + inputname + '"]'); 43 } 44 } 45 } 46 if (oLabel.is('label')) { 47 return oLabel.css('cursor', 'pointer'); 48 } 49 return false; 50 }; 51 52 /* Hide all open selects */ 53 var jqTransformHideSelect = function (oTarget) { 54 var ulVisible = $('.jqTransformSelectWrapper ul:visible'); 55 ulVisible.each(function () { 56 var oSelect = $(this).parents(".jqTransformSelectWrapper:first").find("select").get(0); 57 //do not hide if click on the label object associated to the select 58 if (!(oTarget && oSelect.oLabel && oSelect.oLabel.get(0) == oTarget.get(0))) { 59 $(this).trigger('collapse'); 60 $('.wpcf7-form .wpcf7-form-control-wrap.interest').removeClass('active'); 61 } 62 }); 63 }; 64 /* Check for an external click */ 65 var jqTransformCheckExternalClick = function (event) { 66 if ($(event.target).parents('.jqTransformSelectWrapper').length === 0) { 67 jqTransformHideSelect($(event.target)); 68 } 69 }; 70 71 /* Apply document listener */ 72 var jqTransformAddDocumentListener = function () { 73 $(document).mousedown(jqTransformCheckExternalClick); 74 }; 75 76 /* Add a new handler for the reset action */ 77 var jqTransformReset = function (f) { 78 var sel; 79 $('.jqTransformSelectWrapper select', f).each(function () { 80 sel = (this.selectedIndex < 0) ? 0 : this.selectedIndex; 81 $('ul', $(this).parent()).each(function () { 82 $('a:eq(' + sel + ')', this).click(); 83 }); 84 }); 85 $('a.jqTransformCheckbox, a.jqTransformRadio', f).removeClass('jqTransformChecked'); 86 $('input:checkbox, input:radio', f).each(function () { 87 if (this.checked) { 88 $('a', $(this).parent()).addClass('jqTransformChecked'); 89 } 90 }); 91 }; 92 93 /** 94 * Use this function to get the dimension of an element. If the jQuery Actual 95 * plugin is enabled this function will use it. This solves the problem with 96 * hidden elements that don't report a dimension. 97 * 98 * @param method 99 */ 100 $.fn.jqTransformGetDimension = function (method) { 101 // use jQuery Actual plugin to get the dimension 102 if ($.fn.actual) return this.actual(method); 103 104 // otherwise use standard jQuery dimensions method 105 return $.fn[method].call(this); 106 }; 107 108 /*************************** 109 Select 110 ***************************/ 111 $.fn.jqTransSelect = function () { 112 if (this.length) { 113 this.each(function (index) { 114 var $select = $(this); 115 116 if ($select.hasClass('jqTransformHidden') || $select.attr('multiple')) return; 117 118 var oLabel = jqTransformGetLabel($select); 119 120 /* First thing we do is Wrap it */ 121 var selectWidth = $select.jqTransformGetDimension('width'); 122 $select.addClass('jqTransformHidden'); 123 $select.wrap('<div class="jqTransformSelectWrapper"></div>'); 124 125 var $wrapper = $select.parent(); 126 127 128 /* Now add the html for the select */ 129 $wrapper 130 .css({width: selectWidth, zIndex: 99 - index}) 131 .prepend('<div><span></span><a href="#" class="jqTransformSelectOpen"></a></div><ul></ul>') 132 ; 133 var $ul = $('ul', $wrapper) 134 $ul 135 .css({width: selectWidth}
135) 136 .hide() 137 ; 138 139 /* Now we add the options */ 140 $('option', this).each(function (i) { 141 var oLi = $('<li><a href="#" index="' + i + '">' + $(this).html() + '</a></li>'); 142 $ul.append(oLi); 143 }); 144 145 /* Call instead of $ul.hide() to return state to normal */ 146 $ul.bind('collapse', function () { 147 $(this).hide(); 148 var $clone = $wrapper.data('clone'); 149 if ($clone) { 150 $wrapper.attr('style', $clone.attr('style')); 151 $clone.hide(); 152 $wrapper.insertAfter($clone); 153 } 154 }); 155 156 /* Add click handler to the a */ 157 $ul.find('a').click(function () { 158 $('a.selected', $wrapper).removeClass('selected'); 159 $(this).addClass('selected'); 160 var prevIndex = $select[0].selectedIndex; 161 $select[0].selectedIndex = $(this).attr('index'); 162 163 /* Fire the onchange event */ 164 if (prevIndex != $select[0].selectedIndex) { 165 var $clone = $wrapper.data('clone'); 166 var $original_select = $('select', $clone); 167 $original_select.trigger('change'); 168 } 169 $('span:eq(0)', $wrapper).html($(this).html()); 170 $ul.trigger('collapse'); 171 $('.wpcf7-form .wpcf7-form-control-wrap.interest').removeClass('active'); 172 return false; 173 }); 174 175 /* Set the default */ 176 $('a:eq(' + this.selectedIndex + ')', $ul).click(); 177 var oLinkOpen = $("a.jqTransformSelectOpen", $wrapper); 178 $('span:first', $wrapper).click(function () { 179 oLinkOpen.trigger('click'); 180 }); 181 oLabel && oLabel.click(function () { 182 oLinkOpen.trigger('click'); 183 }); 184 this.oLabel = oLabel; 185 186 /* Apply the click handler to the Open */ 187 oLinkOpen.click(function () { 188 var already_open = $ul.is(':visible'); 189 jqTransformHideSelect(); // Toggle closed or close other selects. 190 191 if (!already_open && !$select.attr('disabled')) { 192 193 // Calculate dimensions every time to adjust for any DOM changes 194 function enoughSpaceBelow () { 195 var 196 ulHeight = $ul.jqTransformGetDimension('outerHeight'); 197 spaceBelow = $(window).height() - $wrapper.outerHeight() - $wrapper.offset().top 198 ; 199 return ulHeight < spaceBelow; 200 } 201 $ul.css({ 202 width: $select.jqTransformGetDimension('width') - 2, 203 top: enoughSpaceBelow() ? $wrapper.outerHeight() : '', 204 bottom: enoughSpaceBelow() ? '' : $wrapper.outerHeight() 205 }); 206 207 $ul.toggle(); 208 $('.wpcf7-form .wpcf7-form-control-wrap.interest').toggleClass('active'); 209 210 /* if (!$wrapper.data('clone')) { 211 var $clone = $wrapper.clone() 212 .hide() 213 .insertBefore($wrapper); 214 $clone.find('select').attr('disabled', 'disabled'); 215 $wrapper.data('clone',$clone); 216 } else { 217 var $clone = $wrapper.data('clone'); 218 }*/ 219 220 /*$clone.show(); 221 $wrapper 222 .appendTo('body') 223 .css({ 224 position: 'absolute', 225 top: $clone.offset().top, 226 left: $clone.offset().left, 227 width: $clone.width(), 228 height: $clone.height() 229 })*/ 230 ; 231 } 232 return false; 233 }); 234 235 // Set the new width 236 var iSelectWidth = $select.jqTransformGetDimension('outerWidth'); 237 var oSpan = $('span:first', $wrapper); 238 // var newWidth = (iSelectWidth > oSpan.innerWidth()) ? iSelectWidth + oLinkOpen.outerWidth() : $wrapper.width(); 239 var newWidth = iSelectWidth; 240 $wrapper.css({width: newWidth}); 241 242 // Calculate the height if necessary, less elements that the default height 243 //show the ul to calculate the block, if ul is not displayed li he
243ight value is 0 244 $ul.css({display: 'block', visibility: 'hidden'}); 245 if ($ul.is(':hidden')) { 246 var hidden_containers = $($ul.parentsUntil(':visible').get().reverse()); 247 hidden_containers.each(function () { 248 var $this = $(this) 249 if ($this.is(':hidden')) { 250 $this.data('style', $this.attr('style') || false); 251 $this.css({ 252 position: 'absolute', 253 left: '-10000px', 254 display: 'block' 255 }); 256 } 257 }); 258 } 259 var iSelectHeight = ($('li', $ul).length) * ($('li:first', $ul).jqTransformGetDimension('height'));//+1 else bug ff 260 (iSelectHeight < $ul.jqTransformGetDimension('height')) && $ul.css({height: iSelectHeight, 'overflow': 'hidden'});//hidden else bug with ff 261 $ul.css({display: 'none', visibility: 'visible'}); 262 if (hidden_containers) hidden_containers.each(function () { 263 var $this = $(this); 264 if (typeof $this.data('style') != 'undefined') 265 $this.attr('style', $this.data('style') || ''); 266 }); 267 268 }); 269 270 jqTransformAddDocumentListener(); 271 } 272 return this; 273 }; 274 275 $.fn.jqTransform = function (options) { 276 var opt = $.extend({}, defaultOptions, options); 277 278 /* each form */ 279 return this.each(function () { 280 var $form = $(this); 281 if ($form.hasClass('jqtransformdone')) { 282 return; 283 } 284 $form.addClass('jqtransformdone'); 285 286 $form.bind('reset', function () { 287 var action = function () { 288 jqTransformReset(this); 289 }; 290 window.setTimeout(action, 10); 291 }); 292 293 }); 294 /* End Form each */ 295 296 }; 297 298 /* End the Plugin */ 299 300})(jQuery);
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.