JavaScript

Zbystřete své smysly technickými doplňky

<br /> {<br /> &quot;name&quot;:&quot;Ramjet Inspector&quot;,<br /> &quot;version&quot;:&quot;1.8&quot;,<br /> ... další povinné informace ...<br /> &quot;background&quot;:{<br /> &quot;scripts&quot;: [&quot;background.js&quot;]<br /> },<br /> &quot;permissions&quot;:[<br /> &quot;cookies&quot;,<br /> &quot;tabs&quot;,<br /> &quot;notifications&quot;,<br /> &quot;http://*/*&quot;,<br /> &quot;https://*/*&quot;,<br /> ],<br /> &quot;web_accessible_resources&quot;:[<br /> &quot;skin/INFO.png&quot;,<br /> &quot;skin/WARNING.png&quot;,<br /> &quot;skin/ERROR.png&quot;<br /> ]<br /> } var openNotifications = 0; //REGISTRACE LISTENERU NA ZMĚNY V COOKIES chrome.cookies.onChanged.addListener(function (data) { //zajímá nás pouze vytvoření cookie if (data.cause == "explicit" && data.

Monitoring embeded video plays

$(document).ready(function() { $("#video object").live("click", "alert('Played')"); }) var flashvars = { file: "/video/myvideo.flv", allowfullscreen: "false", allowscriptaccess: "always", image: "/img/thumbnail.jpg", bufferlength: "0", screencolor: "000000" }; swfobject.embedSWF( "/swf/u/jw-flv-player.swf", "video", "509", "382", "8.0.0", null, flashvars, { wmode: "transparent", allowFullScreen: "true" }, null, function (domObj) { $(domObj.ref).attr("onclick", "alert('Played')"); }); <!-- JW PLAYER --> <script type="text/javascript"> //<![CDATA[ var flashvars = { file: "/video/myvideo.flv", allowfullscreen: "false", allowscriptaccess: "always", image: "/img/thumbnail.jpg", bufferlength: "0", screencolor: "000000" }; swfobject.embedSWF( "/swf/u/jw-flv-player.

Zrychlete svoji webovou aplikaci pomocí Partial Update

$("#partialUpdateCnt").partialUpdate(); //první parametr je url pro partial update, //druhý parametr je ID DOM objektu jehož obsah se má vyměnit po odpovědi serveru <a href="..." onclick="return $.partialUpdate.execute(this.href, 'partialUpdateCnt');"/> <a href="..." onclick="$.post( this.href + '@partialUpdateCnt', function(data) { $('#partialUpdateCnt').replaceWith(data); }); return false; "/> var data = $("#formId").serializeArray(); $("#doplnIdKomponenty").partialUpdate(); http://www.domena.cz/stranka.html#kotva?parametr1=hodnota1

Problémy s kódováním v AJAXu a jak na ně

//jQuery //serializes all form fields into field1=value1&field2=value2 form var params = $("#myForm").serialize(); //serializes all form fields into simple JSON object var jsonData = $("#myForm").serializeArray(); //Prototype.js //serializes all form fields into field1=value1&field2=value2 form var params = $("#myForm").serialize(); //serializes all form fields into simple JSON object var jsonData = $("#myForm").serialize(true); //jQuery var params = $("#myForm").serialize(); $.get(url + ? + params, function(result) {alert(result);}); var jsonData = $("#myForm").serializeArray(); $.get(url, jsonData, function(result) {alert(result);}); //Prototype.js var params = $("#myForm").

JavaScript timers - naše staré hodiny, bijí čtyři hodiny

var serverTimeDifference; function setServerTime(serverTime) { serverTimeDifference = new Date().getTime() - serverTime.getTime(); } function getActualTime() { var actualTime = new Date(); actualTime.setTime(actualTime.getTime() - serverTimeDifference); return actualTime; }

jQuery effects - quick start

function example1() { $("#example1do").hide(); $("#example1undo").show("fast"); } function example2() { $(".example2").toggle(10000); } function example3() { $("#example3paragraph").hide("slow", function() { $(this).load("/text.txt", function(data) { $(this).show("slow"); }); }); } function testAnimations() { //ukázka z prvního příkladu //bude spuštěno paralelně - jedná se o odlišné DOM elementy $("#example1do").hide(); $("#example1undo").show("fast"); //pokud se ale to samé bude týkat stejného DOM elementu //jako je na tomto příkladě, bude spuštění sériové $("#example1do").show(); $("#example1do").hide(); //celé to jde zapsat díky tomuto chování ještě jednodušeji $("#example1do").

JavaScript Closures - překvapení Java programátora

function example1() { //this shows no allert var myFnct = function() { alert("Hello World!") }; //this shows function as string - no execution will happen alert(myFnct.toString()); //there we'll execute it myFnct(); } function example2() { //we'll fetch a function and execute it on next line var myFnct = getSomeFunction(); myFnct("Father Fourah"); //we can do it even in shorter way - looks quite ridiculous - doesn't it? getSomeFunction()("Reader"); } function getSomeFunction() { return function(name) {alert("Hello " + name)}; } function example3() { var names = ["Jan", "Petr", "Milan"]; var myFnct = function(name) {alert(name)}; forEachExecute(names, myFnct); //or the same in more compressed way forEachExecute([1,2,3], function(nmb) {alert(nmb)}); } function forEachExecute(data, callback) { for(i = 0; i < data.