jQuery :not kullanımı

$("a[target=frameGenel]:not([href])").each(function(){
 $(this).hide();
});

JqueryUI Datepicker

Local Time ile birleştirilirse tadından yenmez…


    $(function() {
          $('#date1').datepicker();
          setMinDate();
          setInterval(setMinDate, 60000);
    });

    function setMinDate() {
          var minDate = (new Date().getHours() < 16 ? 1 : 2);
          $('#date1').datepicker('option', {minDate: minDate, defaultDate: minDate});
    }

Local Time

$(document).ready(function(){
      var timezone = "Europe/Istanbul";
      $.getJSON("http://json-time.appspot.com/time.json?tz="+timezone+"&callback=?",
        function(data){
           if (data.hour < 12) {
              alert ("Good morning in "+timezone);
          } else {
            alert ("Good afternoon in "+timezone);
          }
        });
      });

stackoverflow

Jquery vs. Postback

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
function EndRequest(sender, args)
{
    if (args.get_error() == undefined) {
            BindEvents();
     }
}
function BindEvents()
{
   $("#btnClientSide").bind('click', function()
   {
         alert('I am clicked');
   });
}

BindEvents();

jQuery ile URL

Bir çok projede URL adresinden kontrol yapmam gerekti. Örnek bir kod bloğu…

$(function(){
	var substrURL = window.location.pathname.split('/');
	var sc = substrURL[6].split('_');
	var isim = sc[1];
        ...
});

jQuery ile sayfalama

SGK portalında kullandığım uzun bir tablonun jQuery ile sayfalara bölünmesini sağlayan kod.

$(function(){

		$dataTable = $('.dataTable tbody tr');

		var rowCount		= $dataTable.length,
			visibleCount	= 10,
			pagerCount		= (rowCount - (rowCount % visibleCount)) / visibleCount,
			visiblePage		= 1,
			gt				= 0,
			lt				= 0;

		if((rowCount % visibleCount)>0){pagerCount++;}

		if(pagerCount > 1){
			for(i=1;i<=pagerCount;i++){
				$('.pager').append('<a href="#" rel="'+i+'">'+i+'</a>&nbsp;');
			}
		}

		$dataTable.slice(visibleCount, rowCount).hide();
		$('.pager a').live('click', function(){
			$dataTable.hide();
			visiblePage = $(this).attr('rel');
				gt = visibleCount * (visiblePage-1),
				lt = visibleCount * visiblePage;
					$dataTable.slice(gt,lt).show();
		});

	});

Resim boyutlandırma

resizeImage = function($img) {
	var wW	= $(window).width(),
		wH	= $(window).height(),
		wR	= wH / wW,
		iW	= $img.width(),
		iH	= $img.height(),
		iR	= iH / iW,
		nW	= 0,
		nH	= 0;

	if(wR > iR){
		nH	= wH;
		nW	= wH / iR;
	}
	else{
		nH	= wW * iR;
		nW	= wW;
	}

	$img.css({
		width	: nW + 'px',
		height	: nH + 'px',
		left	: (wW - nW) / 2 + 'px',
		top		: (wH - nH) / 2 + 'px'
	});
}

Sağ tık engelleme

$(function() {
    $(this).bind("contextmenu", function(e) {
        e.preventDefault();
    });
});

Belli bir süre sonra kapanan popup

Colorbox’ ı sayfada göründükten bir süre sonra kapanmasını sağlayan kod. Tabi css düzenlemesi ve html gerekiyor.

<script type="text/javascript">
   $(function () {
        if ($('.popupImageHolder > *').length) {
            $('.countDownContainer').show();
            $.fn.colorbox({ href: ".popupImageHolder", inline: true, open: true, onCleanup: function () { $('.countDownContainer').remove(); } });
            var t = $('.hiddenTime input').val(),
                kalanSure = 0,
                saniye = t / 1000;
            $('#sn').text(saniye);
            if (t != 0) {
                function updateTime() {
                    if (saniye > 0) {
                        var geriSay = setInterval(
                function () {
                    saniye--;
                    if (saniye == 0) { clearInterval(geriSay); $('.countDownContainer').remove(); }
                    $('#sn').text(saniye);
                }, 1000);
                    }
                    else {
                        clearInterval(geriSay);
                    }
                }
                updateTime();

                setTimeout($.fn.colorbox.close, t);
            }
        }
    });

</script>

jQuery & UpdatePanel

Update panel içinde kalan kontrollerde jQuery mmetotları tetiklenmiyor. Aşağıdaki kod ile çalıştırabilirsin.

<script type="text/javascript">
$(function () {

	var pgRegMgr = Sys.WebForms.PageRequestManager.getInstance();
	pgRegMgr.add_endRequest(EndHandler);

	function EndHandler() {
		$('.date').datepicker();
	}
});
</script>