Aklımda Kalası Kelimeler

* давайте работать вместе
* Zarf ve Mazruf, Zerafet(xHoyratlık) ile aynı kökten(za-ra-fe) gelir
* Bedesten
* Suç subuta ermiştir - Suç sabit olmuştur
Javascript etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Javascript etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

20 Ekim 2010 Çarşamba

Javascript sınıflarına statik metot tanımlanması

Önceki yazılarımın birinde sınıf tanımı v.s. anlatmıştım. Burada da javascript sınıfın içine statik metot yazmayı eklemiş olayım:

function Sinif(){
this.YeniMetot = function(){ };
}



ya da


function Sinif(){ }

Sinif.prototype.YeniMetot = function(){ }


idi. Şimdi bu iki tanımda güzel ve aynı anlama geliyor.

Peki sınıfa bağlı yani bir sınıf örneği(nesne) oluşturmadan erişilebilen metot(statik metot) tanımlayalım.

function Sinif(){ }

Sinif.prototype.YeniMetot = function(){ }

Sinif.IsteStatikMetot = function(){ }


19 Ekim 2010 Salı

Javascript'te üst elementi bulma

Bunu yazdıktan sonra öğrendim ki $(this).parents(".divEbeveynElement") aynı işi yapıyormuş :)

// verilen child elemen için iz ile belirtilen
// kriterdeki elementi geri döner.
// f_parentBul(this,".divDuzenle");
// f_parentBul($("#divElement"),"div");
function f_parentBul(child, iz) {
//debugger;
if (iz != undefined || iz != "") {
do {
var parent = $(child).parent();
if ($(parent) == null) {
return null;
} else {
if ($(parent).is(iz)) {
return $(parent);
} else {
for (var i = 0; i < $(parent).length; i++) {
return f_parentBul($(parent)[i], iz);
}
}
}
} while (bDevam);
} else {
throw "Kontrol kriterini girmediniz.";
}
}

18 Ekim 2010 Pazartesi

Javascript'de dizi oluşturma



<html>
<head>
</head>
<body>
<script type="text/javascript">

function Person(_adi,_soyadi){
this.Adi = "";
this.Soyadi = "";

this.Set = function(_adi,_soyadi){
this.Adi = _adi;
this.Soyadi = _soyadi;
}

if(_adi===undefined) {
this.Set("Cem","Topkaya");
}else{
this.Set(_adi,_soyadi);
}
}
</script>
<div> BOŞLUK </div>
</body>
</html>


var cenk = new Person("Cenk","Topkaya");
var dizi = [{"_adi":"Cenk","_soyadi":"Topkaya"},{"_adi":"Cem","_soyadi":"Topkaya"}];
console.log(dizi.length);
console.debug(dizi);

var dizi2 = [eval(new Person("Cenk","Topkaya")),eval(new Person("Cem","Topkaya"))];
console.debug(dizi2);

var dizi3 = [new Person("Cenk","Topkaya"),new Person("Cem","Topkaya")];
console.debug(dizi3);

23 Eylül 2010 Perşembe

JQuery ile SELECT elementine neler yapabiliriz


// Add options to the end of a select
$("#myselect").append("");
$("#myselect").append("");

// Add options to the start of a select
$("#myselect").prepend("");

// Replace all the options with new options
$("#myselect").html("");

// Replace items at a certain index
$("#myselect option:eq(1)").replaceWith("");
$("#myselect option:eq(2)").replaceWith("");

// Set the element at index 2 to be selected
$("#myselect option:eq(2)").attr("selected", "selected");

// Set the selected element by text
$("#myselect").val("Some oranges").attr("selected", "selected");

// Set the selected element by value
$("#myselect").val("2");

// Remove an item at a particular index
$("#myselect option:eq(0)").remove();

// Remove first item
$("#myselect option:first").remove();

// Remove last item
$("#myselect option:last").remove();

// Get the text of the selected item
alert($("#myselect option:selected").text());

// Get the value of the selected item
alert($("#myselect option:selected").val());

// Get the index of the selected item
alert($("#myselect option").index($("#myselect option:selected")));

// Alternative way to get the selected item
alert($("#myselect option:selected").prevAll().size());

// Insert an item in after a particular position
$("#myselect option:eq(0)").after("");

// Insert an item in before a particular position
$("#myselect option:eq(3)").before("");

// Getting values when item is selected
$("#myselect").change(function() {
alert($(this).val());
alert($(this).children("option:selected").text());
});

JSON formatında Microsoft'un culturInfo javascript değişkeni


var __cultureInfo =
'{"name":"tr-TR",
"numberFormat":
{
"CurrencyDecimalDigits":2,
"CurrencyDecimalSeparator":","
,"IsReadOnly":true,
"CurrencyGroupSizes":[3],
"NumberGroupSizes":[3],
"PercentGroupSizes":[3],
"CurrencyGroupSeparator":".",
"CurrencySymbol":"TL",
"NaNSymbol":"NaN",
"CurrencyNegativePattern":8,
"NumberNegativePattern":1,
"PercentPositivePattern":2,
"PercentNegativePattern":2,
"NegativeInfinitySymbol":"-Infinity",
"NegativeSign":"-",
"NumberDecimalDigits":2,
NumberDecimalSeparator":",",
"NumberGroupSeparator":".",
"CurrencyPositivePattern":3,
"PositiveInfinitySymbol":"Infinity",
"PositiveSign":"+",
"PercentDecimalDigits":2,
"PercentDecimalSeparator":",",
"PercentGroupSeparator":".",
"PercentSymbol":"%",
"PerMilleSymbol":"‰",
"NativeDigits":["0","1","2","3","4","5","6","7","8","9"],
"DigitSubstitution":1
},
"dateTimeFormat":
{
"AMDesignator":"",
"Calendar":
{
"MinSupportedDateTime":"\/Date(-62135596800000)\/",
"MaxSupportedDateTime":"\/Date(253402293599999)\/",
"AlgorithmType":1,
"CalendarType":1,
"Eras":[1],
"TwoDigitYearMax":2029,
"IsReadOnly":true
},
"DateSeparator":".",
"FirstDayOfWeek":1,
"CalendarWeekRule":0,
"FullDateTimePattern":"dd MMMM yyyy dddd HH:mm:ss",
"LongDatePattern":"dd MMMM yyyy dddd",
"LongTimePattern":"HH:mm:ss",
"MonthDayPattern":"dd MMMM",
"PMDesignator":"",
"RFC1123Pattern":"ddd, dd MMM yyyy HH\u0027:\u0027mm\u0027:\u0027ss \u0027GMT\u0027",
"ShortDatePattern":"dd.MM.yyyy",
"ShortTimePattern":"HH:mm",
"SortableDateTimePattern":"yyyy\u0027-\u0027MM\u0027-\u0027dd\u0027T\u0027HH\u0027:\u0027mm\u0027:\u0027ss",
"TimeSeparator":":",
"UniversalSortableDateTimePattern":"yyyy\u0027-\u0027MM\u0027-\u0027dd HH\u0027:\u0027mm\u0027:\u0027ss\u0027Z\u0027",
"YearMonthPattern":"MMMM yyyy",
"AbbreviatedDayNames":["Paz","Pzt","Sal","Çar","Per","Cum","Cmt"],
"ShortestDayNames":["Pz","Pt","Sa","Ça","Pe","Cu","Ct"],
"DayNames":["Pazar","Pazartesi","Salı","Çarşamba","Perşembe","Cuma","Cumartesi"],
"AbbreviatedMonthNames":["Oca","Şub","Mar","Nis","May","Haz","Tem","Ağu","Eyl","Eki","Kas","Ara",""],
"MonthNames":["Ocak","Şubat","Mart","Nisan","Mayıs","Haziran",
"Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık",""],
"IsReadOnly":true,
"NativeCalendarName":"Gregoryen Takvimi",
"AbbreviatedMonthGenitiveNames":["Oca","Şub","Mar","Nis","May","Haz","Tem","Ağu","Eyl","Eki","Kas","Ara",""],
"MonthGenitiveNames":["Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık",""]
}
}';

20 Haziran 2010 Pazar

Hızlı JavaScript Kütüphaneler

JQuery



<script src="http://code.jquery.com/jquery-latest.min.js"></script>


JQuery Lightbox Plugin

(JQuery gerekli)



<script type="text/javascript" src="http://leandrovieira.com/projects/jquery/lightbox/js/jquery.lightbox-0.5.pack.js"></script>
<link rel="stylesheet" type="text/css" href="http://leandrovieira.com/projects/jquery/lightbox/css/jquery.lightbox-0.5.css" media="screen" />

<script type="text/javascript">
$(document).ready(function() {
// Use this example, or...
$('a[rel*=lightbox]').lightBox();
});
</script>


JQuery Slider

: http://blog.egorkhmelev.com/2010/03/jquery-slider-update/

JQuery Tooltip : http://plugins.jquery.com/project/vs-tooltip

$(document).ready(function(){
$('.tooltip').tooltip();
});

Başka tooltipler için güzel bir makale : http://www.sanalduvar.com/10-adet-jquery-tooltip-eklentisi-jquery-ile-balon-icinde-aciklama-ornekleri

JQuery Date Range Picker plugin

: http://www.filamentgroup.com/lab/date_range_picker_using_jquery_ui_16_and_jquery_ui_css_framework/

HTML
<input type="text" />
jQuery:

$('input').daterangepicker();


JQuery.Popeye plugin

(satır içi resim albumu): Demo sayfası



JQuery Autocomplete


http://jquery.bassistance.de/autocomplete/demo/


Dğer Kaynaklar:

14 Nisan 2010 Çarşamba

Kodla javascript breakpoint oluşturmak


C#

#if DEBUG
System.Diagnostics.Debugger.Break();
#endif


JavaScript

function MyCustomValidator(ctl, args)
{
debugger
var grid = igtbl_getGridById("MyGrid");
args.IsValid = grid != null;
}

7 Nisan 2010 Çarşamba

Javascript ile class tanımı ve metottan fonksiyona parametre geçirerek çağırma

Sınıf tanımı ve public, private ayrımları


Nesne üzerinden yeni property eklemek








Bu da benden bir örnek:
<script type="text/javascript">
function Ogrenci(adi, soyadi, numarasi) {
this.Adi = adi;
this.Soyadi = soyadi;
this.Numarasi = numarasi;
}

Ogrenci.prototype.f_Ekle = function
(f_Basarili, prmB, f_Hatali, prmH) 
{
alert(this.Adi);

//f_Basarili != undefined
//   aynıdır
//f_Basarili != null
if (f_Basarili != undefined) {
f_Basarili.call(this, "Basarilidan =>" + prmB);
}

if (f_Hatali != null) {
f_Hatali.call(this, "Hatalidan =>" + prmH);
}
}


function Basarili(prmBasarili) {
alert("Fonk. Başarılı: " + prmBasarili);
}

function Hatali(prmHatali) {
alert("Fonk. Hatalı: " + prmHatali);
}

var ogr = new Ogrenci("Cem", "Topkaya", 123);

// Her iki metoduda çağırmak istesek
ogr.f_Ekle(Basarili, " _Başarılıya_", Hatali, " _Hatalıya_");

ogr.f_Ekle(null, undefined, Hatali, " _Hatalıya_");

// Hataliyi cagirmadan metodu tetikleyelim.
ogr.f_Ekle(Basarili, " _Başariliya_"); 
</script>



Bu da ajax eventleri ile ilgili özet örneğim:
<script type="text/javascript">
$(document).bind("ajaxSend", function() {
// global event bind edilir 
// local before'dan sonra çalışacak
alert("ajax send bind edilmiş");
}).bind("beforeSend", function() {
//alert Çalışmayacak
alert("local event global gibi bind edilemez");
}).bind("ajaxSuccess", function() {
// global event bind edilir [çalışacak]
alert("ajaxSuccess binde edilmiş");
}).bind("ajaxComplete", function() {
// global event bind edilir [çalışacak]
alert("complete binde edilmiş");
});

// Ajax send olduğunda ve complete olduğunda 
// otomatik çalışsın diye güzel bir örnek.
// Ama global event lerde böyle bir bağlamanın
// olabileceğinin altını bir kez daha çizelim.
$("#loading").bind("ajaxSend", function(){
$(this).show();
}).bind("ajaxComplete", function(){
$(this).hide();
});


function TabloEkleri(
_tabloEkId,
_refEkId,
_refTabloPKId, _refTabloId,
_ekMetni, _anaResim, _sirasi) {

this.TabloEkId = _tabloEkId;
this.RefEkId = _refEkId;
this.RefTabloPKId = _refTabloPKId;
this.RefTabloId = _refTabloId;
this.EkMetni = _ekMetni;
this.AnaResim = _anaResim;
this.Sirasi = _sirasi;
}

TabloEkleri.prototype.f_Ekle = function(fBefore, fSuccess, fComplete, fError) {
// $.ajaxSetup metodu ile $.ajax içinde 
// eventleri bağlamamız gerekmez.
$.ajaxSetup({
beforeSend: fBefore,
complete: fComplete,
success: fSuccess,
error: fError
});
// Ya da $.ajaxSetup metodunu bir fonk. içine alarak
// fAjaxSetup(fBefore, fSuccess, fError, fComplete);
// şeklinde çağırabiliriz. Böylece aşağıdaki
// event bağlamalarına gerek kalmadığı gibi
//
// $.ajax({
//        type: "get",
//        contentType: "application/json; charset=utf-8",
//        url: "hihi.txt",
//        data: "{}",
//        dataType: "json",
// });
//
// şeklinde bir ajax metot çağrısı yapılabilir.
//
// Ama biz aşağıdaki gibi iki yöntemlede (yorum satırı 
// yapılmışlar ve açık satırlar olarak) ajax çağrısını
// görelim.

$.ajax({
type: "get",
contentType: "application/json; charset=utf-8",
url: "hihi.txt",
data: "{}",
dataType: "json",
//              beforeSend: function() {
//                    if (fBefore != undefined) {
//                        fBefore.call();
//                    }
//              },
beforeSend: fBefore,
//              success: function(data, textStatus, XMLHttpRequest) {

//                    if (fSuccess != undefined) {
//                        fSuccess.call(this, data);
//                    }
//                    /**
//                    if (data.d.Sonuc) {
//                    $.fn.colorbox({ html: data.d.Basarili });
//                    return;
//                    } else {
//                    $.fn.colorbox({ html: data.d.Hatali });
//                    }
//                    */
//              },
success: fSuccess,
//                error: function(XMLHttpRequest, textStatus, errorThrown) {
//                    //f_AjaxError(XMLHttpRequest, textStatus, errorThrown);

//                    if (fError != undefined) {
//                        fError.call(this, XMLHttpRequest, textStatus, errorThrown);
//                    }
//                    return;
//                },
error: fError,
//              complete: function(data) {
//                  if (fComplete != undefined) {
//                      fComplete.call(this, data),
//                  }
//              }
complete: fComplete
});
}        
</script>

<script type="text/javascript">
var tbl = new TabloEkleri(1, 2, 3, 4, "metin", 1, 666);

function before() {
alert("beforeeee");
}

function success(data, textStatus, XMLHttpRequest) {
alert("successsss: " + data);
}

function complete(data) {
alert("completeeeee");
}

tbl.f_Ekle(null, success, complete, null);
</script>



Ref:stackoverflow.com

Actually, your code will pretty much work as is, just declare your callback as an argument and you can call it directly using the argument name.
The basics

function doSomething(callback) {
// ...

// Call the callback
callback('stuff', 'goes', 'here');
}

function foo(a, b, c) {
// I'm the callback
alert(a + " " + b + " " + c);
}

doSomething(foo);

That will call doSomething, which will call foo, which will alert "stuff goes here".

Note that it's very important to pass the function reference (foo), rather than calling the function and passing its result (foo()). In your question, you do it properly, but it's just worth pointing out because it's a common error.
More advanced stuff

Sometimes you want to call the callback in a specific context -- e.g., so the this value inside the callback has a specific value. You can easily do that with the JavaScript call function:

function Thing(name) {
this.name = name;
}
Thing.prototype.doSomething = function(callback) {
// Call our callback, but using our own instance as the context
callback.call(this);
}

function foo() {
alert(this.name);
}

var t = new Thing('Joe');
t.doSomething();  // Alerts "Joe" via `foo`

You can also pass parameters:

function Thing(name) {
this.name = name;
}
Thing.prototype.doSomething = function(callback, salutation) {
// Call our callback, but using our own instance as the context
callback.call(this, salutation);
}

function foo(salutation) {
alert(salutation + " " + this.name);
}

var t = new Thing('Joe');
t.doSomething('Hi;');  // Alerts "Hi Joe" via `foo`

Sometimes it's useful to pass the arguments you want to give the callback as an array, rather than individually. You can use apply to do that:

function Thing(name) {
this.name = name;
}
Thing.prototype.doSomething = function(callback) {
// Call our callback, but using our own instance as the context
callback.apply(this, ['Hi', 3, 2, 1]);
}

function foo(salutation, three, two, one) {
alert(salutation + " " + this.name + " - " + three + " " + two + " " + one);
}

var t = new Thing('Joe');
t.doSomething('Hi;');  // Alerts "Hi Joe - 3 2 1" via `foo`




19 Mart 2010 Cuma

Javascript'te static ve dinamik sınıflardan nesne yaratılması


--------------------------------------------------------------------------- STATIC
function ToDo(){

}

ToDo.Liste = function(){

}

***** Kullanımı ******
var toDo = new ToDo();

// Çünkü Liste fonksiyonu ToDo sınıfından olacak nesneye bağlı değil, 
// ToDo içindeki STATIC olan Liste sınıfına bağlıdır 
var liste = new ToDo.Liste(); 

--------------------------------------------------------------------------- DYNAMIC
function ToDo(){

  this.Liste = function(){  //public bir sınıf ya da fonksiyon olarak çağırılabilir

  }

}

***** Kullanımı ******
var toDo = new ToDo();
var liste = new toDo.Liste();

9 Mart 2010 Salı

Javascript ile Select içindeki seçili option elementinin sırasını değiştirmek



<html>
<head>
<script>

function moveItem(i){
var b,o=document.getElementById("s1"),p,q;
if(i==0 && o.selectedIndex > 0){
p = o.options[o.selectedIndex];
q = o.options[o.selectedIndex - 1]
o.removeChild(p);
o.insertBefore(p,q);
}
if(i==1 && o.selectedIndex < o.options.length-1){
b = o.selectedIndex < o.options.length - 2;
p = o.options[o.selectedIndex];
if(b) q = o.options[o.selectedIndex + 2]
o.removeChild(p);
if(b) o.insertBefore(p,q); else o.appendChild(p);
}
}

</script>
</head>
<body>
<table>
<tr>
<td rowspan=2>
<select id="s1" size=3>
<option>One
<option>Two
<option>Three
</select>
</td>
<td>
</tr>
<tr>
<td>
</tr>
</table>
</body>
<script>
</script>
</html>

Javascript ile Class yapımının 3 yolu

Ref:http://www.phpied.com/3-ways-to-define-a-javascript-class/

1. Yol : Fonksiyonlar kullanılarak oluşturmak.

function Apple (type) {
this.type = type;
this.color = "red";
this.getInfo = getAppleInfo;
}

function getAppleInfo() {
return this.color + ' ' + this.type + ' apple';
}


Nesne türetmek için:

var apple = new Apple('macintosh');
apple.color = "reddish";
alert(apple.getInfo());




1.1. Yol: Function içinde dahili function ile metot tanımı

function Apple (type) {
this.type = type;
this.color = "red";
this.getInfo = function() {
return this.color + ' ' + this.type + ' apple';
};
}





2. Yol : JSON modeli. Tabii bundan nesne üretilemez.

var apple = {
type: "macintosh",
color: "red",
getInfo: function () {
return this.color + ' ' + this.type + ' apple';
}
}



Kullanımı:

apple.color = "reddish";
alert(apple.getInfo());





3. Yol :

var apple = new function() {
this.type = "macintosh";
this.color = "red";
this.getInfo = function () {
return this.color + ' ' + this.type + ' apple';
};
}


Kullanımı:

apple.color = "reddish";
alert(apple.getInfo());