Autor | Zpráva | ||
---|---|---|---|
Radim24 Profil |
#1 · Zasláno: 7. 9. 2009, 15:09:48 · Upravil/a: Radim24
Ahoj, prosím jestli by jste mi mohli poradit, nemohu najít chybu.
1) line39: Mám metodu $.set(), kde chci přidat dva objekty s parametry. 2) line40: $.extend({ 3) line41: standard_def: $.def({ zde předávám první sadu argumentů... 4) line49: zde chci přičíst další parametry 5) metodu volám takto: $.set( ($('ul#sortable_1'), 'ul') ); 6) console.log( jQuery.standard_def ); objekt obsahuje pouze čtyři parametry z té první funkce ale žádné z té druhé funkce, nevíte co s tím? Celý kód: (function($) { var start_def = { ul_padding_l: 2, ul_padding_r: 2, li_padding_l: 5, li_padding_r: 5, li_margin_l: 5, li_margin_r: 5, border: "1 1 1 1" } $.def = function(opt_1, opt_2) { if (typeof(opt_1) !== 'object') { if (opt_1 == 'start') return start_def; } else if (typeof(opt_2) === 'object') { opt_2 = $.extend({}, opt_2); return opt_2; } return opt_1; }; $.rgb2hex = function(rgb) { //convert color from RGB to hex format - by R0bb13 if ( rgb[3]!="(" ) return rgb; // pokud se nejedná o RGB formát, ukončit rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); function hex(x) { hexDigits = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"); return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16]; } return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); } })(jQuery); (function($) { var ul_def; var input_def; var li_def; $.set = function (this_, type){ $.fn.extend({ standard_def: $.def({ w: $(this_).css('width'), h: $(this_).css('height'), x: $(this_).css('offsetLeft'), y: $(this_).css('offsetTop') // s1: ' type:'+type+' x:'+x+' y:'+y+' w:'+w+' h:'+h }) , standard_def_:function(){ var ul_def = { pos: $(this_).css('position'), left: $(this_).css('left'), right: $(this_).css('right'), s1: this.standard_def.s1 + ' pos:'+pos+' left:'+left+' right:'+right } return ul_def; } }); // return standard_def_; console.log( this.standard_def ); } |
||
Radim24 Profil |
#2 · Zasláno: 7. 9. 2009, 15:56:44 · Upravil/a: Radim24
Aby jste mi lépe rozuměli, čeho chci dosáhnout:
Měl jsem původně tento kód: start_def = new $.def({ w: $(this_).css('width'), h: $(this_).css('height'), x: $(this_).css('offsetLeft'), y: $(this_).css('offsetTop') }); standard_def = new start_def({ pos: $(this_).css('position'), left: $(this_).css('left'), right: $(this_).css('right') }); console.log( start_def ); Povedlo se mi nadefinovat start_def. Chci vytvořit instanci standard_def a přidat tam další vlastnosti, jenže mi to píše, že standard_def není konstruktor. Já nevím jak mám z něho ten konstruktor udělat, protože pomocí: new start_def.extend to nejde. Prosím poraďte. |
||
ah01 Profil |
#3 · Zasláno: 7. 9. 2009, 21:23:24
|
||
Jan Tvrdík Profil |
#4 · Zasláno: 7. 9. 2009, 21:35:02
Jen doplním, že toto vlákno pravděpodobně pokračováním staršího vlákna.
|
||
Radim24 Profil |
#5 · Zasláno: 7. 9. 2009, 22:50:27
ah01
Taky si říkám. To čeho chci dosáhnout tím kódem asi nepůjde. Takže bych to chtěl zkusit pomocí new. Vím, že to nemám dobře, proto mi to nefunguje. Těžko říct, jsem z toho zmaten. Chtěl jsem abych k té základní instanci mohl přičíst argumenty - tím to stylem: Instance A = new ... (argumenty); Instance B = new A + (jiné argumenty); Instance C = new A + (jiné argumenty); Instance D = new C + (jiné argumenty); A myslím, že pomoci toho současného řešení to nejde... |
||
Časová prodleva: 15 let
|
0