From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- files/pl/fragmenty_kodu/okna/index.html | 86 +++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 files/pl/fragmenty_kodu/okna/index.html (limited to 'files/pl/fragmenty_kodu/okna') diff --git a/files/pl/fragmenty_kodu/okna/index.html b/files/pl/fragmenty_kodu/okna/index.html new file mode 100644 index 0000000000..46e98679a1 --- /dev/null +++ b/files/pl/fragmenty_kodu/okna/index.html @@ -0,0 +1,86 @@ +--- +title: Okna +slug: Fragmenty_kodu/Okna +tags: + - Dodatki + - Rozszerzenia + - Strony_wymagające_dopracowania + - Wszystkie_kategorie +translation_of: Archive/Add-ons/Code_snippets/Windows +--- +
+

Support for extensions using XUL/XPCOM or the Add-on SDK was removed in Firefox 57, released November 2017. As there is no supported version of Firefox enabling these technologies, this page will be removed by December 2020.

+
+ +
{{LegacyAddonsNotice}}
+ +

Otwieranie nowych okien przeglądarki

+ +

Aby otworzyć nowe okno przeglądarki, po prostu użyj window.open(). Jednak window.open() zwraca obiekt Window dla zawartości, nie dla samego okna przeglądarki, powinieneś więc najpierw pobrać Window z chrome. Najprostszym na to sposobem jest użycie nsIWindowMediator.

+ +

Przykład

+ +

 

+ +
window.open();
+var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+                   .getService(Components.interfaces.nsIWindowMediator);
+var newWindow = wm.getMostRecentWindow("navigator:browser");
+var b = newWindow.getBrowser();
+// dlaczego to robimy? nigdy nie robimy czegokolwiek z |b|
+
+ +

Przesuwalne okna

+ +

Aby uczynić okna przesuwalnymi przez kliknięcie na ich zawartość, możesz użyć procedur obsługi zdarzeń mousedown i mousemove. Poniższy kod nie zważa na to, na który element kliknęliśmy, po prostu odpowiada na wszystkie zdarzenia tego typu. Możesz wzbogacić ten kod przez zaznaczenie zdarzenia. Docelowy element i tylko ustawienie startPos, jeśli ten element pasuje do zadanych kryteriów.

+ +

Przykład

+ +

 

+ +
var startPos=0;
+var mouseDown = function(event) {
+    startPos = [ event.clientX, event.clientY];
+}
+var mouseMove = function(event) {
+   if (startPos != 0) {
+       var newX = event.screenX-startPos[0];
+       var newY = event.screenY-startPos[1];
+       window.moveTo(newX,newY);
+   }
+}
+var mouseUp = function(event) {
+   startPos=0;
+}
+
+window.addEventListener("mousedown",mouseDown, false);
+window.addEventListener("mouseup",mouseUp, false);
+window.addEventListener("mousemove",mouseMove, false);
+
+ +

 

+ +

 

+ +

XUL Titlebar Element

+ +

Aplikacje XUL wykorzystują Titlebar element, aby osiągnąć podobny rezultat bez dodatkowego kodu JavaScript.

+ +

Re-using and focusing named windows

+ +

While specifying the name parameter to window.open or window.openDialog will prevent multiple windows of that name from opening, each call will actually re-initialize the window and thus lose whatever state the user has put it in. Additionally, if the window is in the background, it may not be brought to the front. This code will check for a window of the provided name. If it finds one, it focuses it. If it doesn't, it opens one.

+ +
var windowName = "yourWindowName";
+var windowsMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
+var win = windowsMediator.getMostRecentWindow(windowName);
+if (win)
+  win.focus();
+else
+  window.open("chrome://to/your/window.xul", windowName, "features");
+
+ +

Inne źródła

+ + -- cgit v1.2.3-54-g00ecf