function - Kurs HTML i CSS
- Przeglądarka zdjęć
...author Sławomir Kokłowski {@link https://www.kurshtml.edu.pl} * @copyright NIE usuwaj tego komentarza! (Do NOT remove this comment!) */ function PrzegladarkaZdjec(id, zdjecia) { this.czas = 5; // czas przejścia w trybie pokazu slajdów [sek] this.id = id; this.zdjecia = zdjecia; var timerID = null; this.wyswietl = function(nr) { clearTimeout(timerID); var f = document.getElementById(this.id); if (nr < 0) nr = f.elements['zdjecia'].options.length...
- Menu drzewiaste / Skrypt menu drzewiastego
...author Sławomir Kokłowski {@link https://www.kurshtml.edu.pl} * @copyright NIE usuwaj tego komentarza! (Do NOT remove this comment!) */ function Tree(id) { this.id = id; var url = unescape(window.location.href.replace(/#.*/, '')); var base = window.location.protocol + '//' + window.location.host + window.location.pathname.replace(/[^\/\\]+$/, ''); this.click = function () { for (var i = 0, el_node; i < this.parentNode.childNodes.length; i++) { el_node...
- Losowy element
...Aby wstawić na stronę losowy tekst lub obrazek, należy w wybranym miejscu dokumentu wkleić następujący kod: <script> Array.prototype.random = function(limit) { if (typeof limit == 'undefined' || limit < 0) limit = 1; else if (!limit) limit = this.length; for (var i = 0, source = this, target = new Array(), n = source.length; i < limit && n > 0; i++) { do { var index = Math.random(); } while (index == 1); index = Math.floor(index * n); target.push(source[index])...
- Ochrona strony
...1 && browser.indexOf(") ") == -1) ie = parseFloat(browser.substring(browser.indexOf("MSIE")+4)); var id_status_blink = 0; function status_blink(txt) { window.status = txt; if (!txt) id_status_blink = setTimeout('status_blink("KLIKNIJ WEWNĄTRZ OKNA PRZEGLĄDARKI !!!!!")', 250); else id_status_blink = setTimeout('status_blink("")', 1500); return true; } function blur_ie() { document.all["body"].style.visibility = "hidden"; clipboardData.clearData()...
- AutoIFRAME / Skrypt AutoIFRAME
...identyfikator IFRAME: var autoiframe_id = 'autoiframe'; // Domyślny dolny margines: var autoiframe_margin = 50; var autoiframe_timer = null; function autoiframe(id, margin) { if (parent != self && document.body && document.body.offsetHeight && document.body.scrollHeight) { clearTimeout(autoiframe_timer) if (typeof id != 'undefined' && id) autoiframe_id = id; parent.document.getElementById(autoiframe_id).height = 1; autoiframe_timer...
- Manipulacja instancją obiektu w JavaScript - Object.prototype / Sprawdzanie posiadania właściwości obiektu - hasOwnProperty
...z prototypu, a jedynie bezpośrednio przypisane do obiektu. Przykład Object.prototype.hasOwnProperty var obj = {test: 1, x: undefined}; obj.m = function () {}; obj.hasOwnProperty("test"); // true obj.hasOwnProperty("x"); // true obj.hasOwnProperty("m"); // true obj.hasOwnProperty("p"); // false delete obj.x; obj.hasOwnProperty("x"); // false var Cls = function () { this.p = 1; }; Cls.prototype.m = function () {}; obj = new Cls(); obj.hasOwnProperty("p"); // true...
- Manipulacja instancją obiektu w JavaScript - Object.prototype / Sprawdzanie prototypu obiektu - isPrototypeOf
...obiektu. Sprawdzany jest przy tym cały łańcuch prototypów, wynikający z dziedziczenia. Przykład Object.prototype.isPrototypeOf var Device = function () {}; var Computer = function () {}; Computer.prototype = Object.create(Device.prototype); var Laptop = function () {}; Laptop.prototype = Object.create(Computer.prototype); Device.prototype.isPrototypeOf(new Device()); // true Device.prototype.isPrototypeOf(new Computer()); // true Device.prototype.isPrototypeOf(new Laptop())...
- Operacje na tablicach w JavaScript - Array.prototype / Sortowanie elementów tablicy - sort
...przez nią zwracana. Przykład Array.prototype.sort var items = [3, 2, 1]; items.sort(); // [1, 2, 3] items; // [1, 2, 3] var f = function (x, y) { return y - x; }; items.sort(f); // [3, 2, 1] items; // [3, 2, 1] var people = [{name: "John"}, {name: "Anna"}, {name: "Tom"}]; f = function (x, y) { if (x.name y.name) return 1; return 0; }; people.sort(f); // [{name: "Anna"}, {name: "John"}, {name: "Tom"}]
- Operacje na tablicach w JavaScript - Array.prototype / Sprawdzanie warunku dla wszystkich elementów - every
...operatora && (i - ang. and) przy działaniach na wartościach skalarnych. Przykład Array.prototype.every var items = [3, 2, 1]; var f = function (x) { return x > 0; }; items.every(f); // true f = function (x) { return x this.value; }; var tester = new GreaterThan(0); items.every(tester.test, tester); // true tester.tests; // 3 tester = new GreaterThan(2); items.every(tester.test, tester); // false tester.tests; // 2...
- Operacje na tablicach w JavaScript - Array.prototype / Sprawdzanie warunku dla przynajmniej jednego elementu - some
...operatora || (lub - ang. or) przy działaniach na wartościach skalarnych. Przykład Array.prototype.some var items = [3, 2, 1]; var f = function (x) { return x > 0; }; items.some(f); // true f = function (x) { return x this.value; }; var tester = new GreaterThan(0); items.some(tester.test, tester); // true tester.tests; // 1 tester = new GreaterThan(4); items.some(tester.test, tester); // false tester.tests; // 3 items...