/** * Функции помогающие в работе с содержимым * * @author Pavel Alexandrov * @copyright Copyright (c) 2010, Pavel Alexandrov * @license http://opensource.org/licenses/gpl-2.0.php The GNU Public License (GPL) Version 2, June 1991 * @package * @subpackage * @category JavaScript * @version 0.1 */ function ie() { var ua = window.navigator.userAgent; var msie = ua.indexOf("MSIE "); if (msie > 0){ return parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))); } return 0; } //-------------------------------------------------- // прозрачность png в IE < 7 (function($){ $.fn.fixPng=function(o){ var opt={img:'/img/s.gif'} $.extend(opt,o); window.navigator.userAgent; if( ie()!=0 && version<=6 ){ if( this.length!=0 ){ $(this[0].nodeName=='IMG'?this:$('img',this)).each( function(){ i=$(this) src=i.attr('src') if (/\.png$/i.test(src)) { i.attr({width:i.innerWidth(),height:i.innerHeight(),src:opt.img}) i.css('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"',sizingMethod='scale')") } }) } } return this } })(jQuery); //---------------------------------------------- // hack для корректной работы с width у картинок ( в webkit браузерах или кеша во всех???) // проверка загрузки изображений. // количество изображений (function($){ $.fn.waitImages=function(callback){ // callback - функция вызываемая после завершения var images function checkImages(){ if( this.complete ){ $(this).unbind('load') if( --images==0 ){ callback() } } } if( this.length!=0 ){ sel=this[0].nodeName=='IMG'?$(this):$('img',this) if( !ie() && (images=sel.length)!=0 ){ sel.load(checkImages).each(checkImages) }else{ callback() } } return this } })(jQuery); //----------------------------------------------- // Простая имплементация sprintf. // Задание вывода %index, где index индекс параметра переданного в функцию. // Нумерация с 1 String.prototype.sprintf=function(){ if( arguments.length==0 )return this str=this // Идем в обратном порядке чтобы не перекрыть например %10 на %1 for( i=arguments.length;i>0;i-- )str=str.replace('%'+i, arguments[i-1]) return str }; //-------------------------------------------------- // Скрытие и показ тегов select в IE (function($){ $.fn.IESelect=function(action){ var list if( $.browser.msie ){ if( action=='show' ){ if( $.isArray(list) ){ // Отображаем скрытые $(list).each(function(){ $(this[0]).css('visibility',this[1]) }) } }else{ // Скрываем list=[] $('select',this).each(function(){ var current=$(this).css('visibility') if( current!='hidden' ){ c=[this,current] list.push(c) $(this).css('visibility','hidden') } }) } } return this } //-------------------------------------------------- })(jQuery); //-------------------------------------------------- // Скрытие и показ тегов object (function($){ var oshlist $.fn.ObjectSH=function(action){ if( action=='show' ){ if( $.isArray(oshlist) ){ // Отображаем скрытые $(oshlist).each(function(){ $(this[0]).css('visibility',this[1]) }) } }else{ // Скрываем oshlist=[] $('object',this).each(function(){ var current=$(this).css('visibility') if( current!='hidden' ){ c=[this,current] oshlist.push(c) $(this).css('visibility','hidden') } }) } return this } //-------------------------------------------------- })(jQuery);