|
1 | | -# Browser environment, specs |
| 1 | +# بيئة المتصفح ومواصفاته |
2 | 2 |
|
3 | | -The JavaScript language was initially created for web browsers. Since then it has evolved and become a language with many uses and platforms. |
| 3 | +تم إنشاء لغة JavaScript فى البداية لمتصفحات الويب، منذ ذلك الحين أصبح لها استخدمات ومنصات عديدة. |
4 | 4 |
|
5 | | -A platform may be a browser, or a web-server or another *host*, even a "smart" coffee machine, if it can run JavaScript. Each of them provides platform-specific functionality. The JavaScript specification calls that a *host environment*. |
| 5 | +قد تكون تلك المنصة متصفح، خادوم ويب او *مضيف* آخر ولكن لكل واحد منهم وظيفته الخاصة التى يقوم بها .خصائص الـ JavaScript تسمى هذا *ببيئة المضيف*. |
6 | 6 |
|
7 | | -A host environment provides own objects and functions additional to the language core. Web browsers give a means to control web pages. Node.js provides server-side features, and so on. |
| 7 | +توفر بيئة العمل كائنات و وظائف خاصة إلى نواة اللغة. تعتبر المتصفحات وسيلة للتحكم بصفحات الويب. وتوفر الـ Node.js خواص من جانب الخادم, وما إلى ذلك. |
8 | 8 |
|
9 | | -Here's a bird's-eye view of what we have when JavaScript runs in a web browser: |
| 9 | +إليك نظرة شاملة لما لدينا عند تشغيل جافا سكريبت في متصفح ويب: |
10 | 10 |
|
11 | 11 |  |
12 | 12 |
|
13 | | -There's a "root" object called `window`. It has two roles: |
| 13 | +لدينا كائن "الجذر" `window` . له دورين: |
14 | 14 |
|
15 | | -1. First, it is a global object for JavaScript code, as described in the chapter <info:global-object>. |
16 | | -2. Second, it represents the "browser window" and provides methods to control it. |
17 | | - |
18 | | -For instance, here we use it as a global object: |
| 15 | +1. أولا، هو كائن عام لشفرة JavaScript، كما وصِف فى فصل <info:global-object> |
| 16 | +2. ثانيًا، يمثل "نافذة المتصفح" ويوفر طرقا للتحكم فيها. |
| 17 | +على سبيل المثال، نستخدمها هنا ككائن عام: |
19 | 18 |
|
20 | 19 | ```js run |
21 | 20 | function sayHi() { |
22 | 21 | alert("Hello"); |
23 | 22 | } |
24 | 23 |
|
25 | | -// global functions are methods of the global object: |
| 24 | +// الدالات العامة هي طرق الكائن العام: |
26 | 25 | window.sayHi(); |
27 | 26 | ``` |
28 | 27 |
|
29 | | -And here we use it as a browser window, to see the window height: |
| 28 | +وهنا نستخدمها كنافذة متصفح لرؤية ارتفاع النافذة: |
30 | 29 |
|
31 | 30 | ```js run |
32 | | -alert(window.innerHeight); // inner window height |
| 31 | +alert(window.innerHeight); // ارتفاع النافذة الداخلية |
33 | 32 | ``` |
34 | 33 |
|
35 | | -There are more window-specific methods and properties, we'll cover them later. |
| 34 | +هناك المزيد من الأساليب والخصائص الخاصة بالنافذة، وسنغطيها لاحقًا. |
36 | 35 |
|
37 | 36 | ## DOM (Document Object Model) |
38 | 37 |
|
39 | | -Document Object Model, or DOM for short, represents all page content as objects that can be modified. |
| 38 | +يمثل نموذج كائن المستند، أو اختصار DOM، محتوى الصفحة بالكامل ككائنات يمكن تعديلها. |
| 39 | + |
| 40 | +كائن `document` هو "نقطة الدخول" الرئيسية للصفحة. يمكننا تغيير أو إنشاء أي شيء على الصفحة باستخدامه. |
40 | 41 |
|
41 | | -The `document` object is the main "entry point" to the page. We can change or create anything on the page using it. |
| 42 | +على سبيل المثال: |
42 | 43 |
|
43 | | -For instance: |
44 | 44 | ```js run |
45 | | -// change the background color to red |
| 45 | +// تغيير لون الخلفية إلى اللون الأحمر |
46 | 46 | document.body.style.background = "red"; |
47 | 47 |
|
48 | | -// change it back after 1 second |
| 48 | +// تغييره مرة أخرى بعد ثانية واحدة |
49 | 49 | setTimeout(() => document.body.style.background = "", 1000); |
50 | 50 | ``` |
51 | 51 |
|
52 | | -Here we used `document.body.style`, but there's much, much more. Properties and methods are described in the specification: [DOM Living Standard](https://dom.spec.whatwg.org). |
| 52 | +استخدمنا هنا `document.body.style`، ولكن هناك الكثير والكثير. يتم وصف الخصائص والأساليب في المواصفات: **DOM الحالة القياسية** فى <https://dom.spec.whatwg.org> |
53 | 53 |
|
54 | | -```smart header="DOM is not only for browsers" |
55 | | -The DOM specification explains the structure of a document and provides objects to manipulate it. There are non-browser instruments that use DOM too. |
| 54 | +```smart header="DOM ليس فقط للمتصفحات" |
| 55 | + توضح مواصفات الـ DOM بنية المستند وتوفر كائنات لمعالجته. هناك أدوات غير المتصفح تستخدم الـ DOM أيضًا. |
56 | 56 |
|
57 | | -For instance, server-side scripts that download HTML pages and process them can also use DOM. They may support only a part of the specification though. |
| 57 | +على سبيل المثال، يمكن للبرامج النصية من جانب الخادوم التي تقوم بتنزيل صفحات HTML ومعالجتها أيضًا استخدام الـDOM. قد يدعمون جزءًا فقط من المواصفات بالرغم من ذلك. |
58 | 58 | ``` |
59 | 59 |
|
60 | | -```smart header="CSSOM for styling" |
61 | | -There's also a separate specification, [CSS Object Model (CSSOM)](https://www.w3.org/TR/cssom-1/) for CSS rules and stylesheets, that explains how they are represented as objects, and how to read and write them. |
| 60 | +يتم استخدام CSSOM مع الـ DOM عند تعديل قواعد النمط للمستند. من الناحية العملية، نادرًا ما تكون CSSOM مطلوبة، لأن قواعد CSS عادة ما تكون ثابتة. نادرًا ما نحتاج إلى إضافة/إزالة قواعد الـ CSS من الـ JavaScript، ولكن هذا ممكن أيضًا. |
62 | 61 |
|
63 | | -CSSOM is used together with DOM when we modify style rules for the document. In practice though, CSSOM is rarely required, because we rarely need to modify CSS rules from JavaScript (usually we just add/remove CSS classes, not modify their CSS rules), but that's also possible. |
| 62 | +```smart header="CSSOM للتصنيف" |
| 63 | +يتم تنظيم قواعد CSS وأوراق الأنماط بطريقة مختلفة عن HTML. هناك مواصفات منفصلة، [CSS Object Model (CSSOM)](https://www.w3.org/TR/cssom-1/), يشرح كيف يتم تمثيلها ككائنات، وكيفية قراءتها وكتابتها. |
64 | 64 | ``` |
65 | 65 |
|
66 | 66 | ## BOM (Browser Object Model) |
67 | 67 |
|
68 | | -The Browser Object Model (BOM) represents additional objects provided by the browser (host environment) for working with everything except the document. |
| 68 | +يمثل نموذج كائن المتصفح (BOM) كائنات إضافية يوفرها المتصفح (البيئة المضيفة) للعمل مع كل شيء باستثناء المستند. |
69 | 69 |
|
70 | | -For instance: |
| 70 | +على سبيل المثال: |
71 | 71 |
|
72 | | -- The [navigator](mdn:api/Window/navigator) object provides background information about the browser and the operating system. There are many properties, but the two most widely known are: `navigator.userAgent` -- about the current browser, and `navigator.platform` -- about the platform (can help to differ between Windows/Linux/Mac etc). |
73 | | -- The [location](mdn:api/Window/location) object allows us to read the current URL and can redirect the browser to a new one. |
| 72 | +- يوفر كائن [navigator](mdn:api/Window/navigator) معلومات أساسية حول المتصفح ونظام التشغيل. هناك العديد من الخصائص ، لكن الأكثر شهرة هما: `navigator.userAgent` -- حول المتصفح الحالي، و `navigator.platform` -- حول النظام الأساسي (يمكن أن يساعد على تحديد الاختلاف بين Windows/Linux/Mac إلخ). |
| 73 | +- يسمح لنا كائن [location](mdn:api/Window/location) بقراءة عنوان URL الحالي ويمكنه إعادة توجيه المتصفح إلى عنوان جديد. |
74 | 74 |
|
75 | | -Here's how we can use the `location` object: |
| 75 | +إليك كيفية استخدام كائن `location`: |
76 | 76 |
|
77 | 77 | ```js run |
78 | | -alert(location.href); // shows current URL |
| 78 | +alert(location.href); //يظهر الـ URL الحالى |
79 | 79 | if (confirm("Go to Wikipedia?")) { |
80 | | - location.href = "https://wikipedia.org"; // redirect the browser to another URL |
| 80 | + location.href = "https://wikipedia.org"; //إعادة توجيه المتصفح إلى عنوان URL آخر |
81 | 81 | } |
82 | 82 | ``` |
83 | 83 |
|
84 | | -Functions `alert/confirm/prompt` are also a part of BOM: they are directly not related to the document, but represent pure browser methods of communicating with the user. |
| 84 | +تعد الدوال `alert/confirm/prompt` جزءًا من الـ BOM: فهي لا تتعلق مباشرة بالمستند، ولكنها تمثل طرق متصفح خالصة للتواصل مع المستخدم. |
85 | 85 |
|
86 | | -```smart header="Specifications" |
87 | | -BOM is the part of the general [HTML specification](https://html.spec.whatwg.org). |
| 86 | +```smart header="مواصفات" |
| 87 | +BOM هو جزء من مواصفات[HTML specification](https://html.spec.whatwg.org). |
88 | 88 |
|
89 | | -Yes, you heard that right. The HTML spec at <https://html.spec.whatwg.org> is not only about the "HTML language" (tags, attributes), but also covers a bunch of objects, methods and browser-specific DOM extensions. That's "HTML in broad terms". Also, some parts have additional specs listed at <https://spec.whatwg.org>. |
| 89 | +نعم سمعت ذلك جيدا. مواصفات الـ HTML في <https://html.spec.whatwg.org>لا تتعلق فقط بـ "لغة HTML" (العلامات، السمات) ،ولكنه يغطي أيضًا مجموعة من الكائنات والأساليب وإضافات DOM الخاصة بالمتصفح. هذا هو "الـ HTML بعبارات عامة".أيضًا، تحتوي بعض الأجزاء على مواصفات إضافية مدرجة في <https://spec.whatwg.org>. |
90 | 90 | ``` |
91 | 91 |
|
92 | | -## Summary |
93 | | - |
94 | | -Talking about standards, we have: |
| 92 | +## ملخص |
95 | 93 |
|
96 | | -DOM specification |
97 | | -: Describes the document structure, manipulations and events, see <https://dom.spec.whatwg.org>. |
| 94 | +بالحديث عن المعايير، لدينا: |
98 | 95 |
|
99 | | -CSSOM specification |
100 | | -: Describes stylesheets and style rules, manipulations with them and their binding to documents, see <https://www.w3.org/TR/cssom-1/>. |
| 96 | +مواصفات الـ DOM |
| 97 | +: يصف هيكل الوثيقة والتلاعب والأحداث، راجع <https://dom.spec.whatwg.org>. |
101 | 98 |
|
102 | | -HTML specification |
103 | | -: Describes the HTML language (e.g. tags) and also the BOM (browser object model) -- various browser functions: `setTimeout`, `alert`, `location` and so on, see <https://html.spec.whatwg.org>. It takes the DOM specification and extends it with many additional properties and methods. |
| 99 | +مواصفات الـ CSSOM |
| 100 | +: يصف أوراق الأنماط وقواعد الأنماط والتلاعب بها وربطها بالمستندات، راجع <https://www.w3.org/TR/cssom-1/>. |
104 | 101 |
|
105 | | -Additionally, some classes are described separately at <https://spec.whatwg.org/>. |
| 102 | +مواصفات الـ HTML |
| 103 | +: تصف لغة HTML (مثل العلامات) وكذلك BOM (طراز كائن المتصفح) - وظائف المتصفح المختلفة: `setTimeout`, `alert`, `location` وما إلى ذلك، راجع <https://html.spec.whatwg.org>. يأخذ مواصفات الـ DOM ويوسعها بالعديد من الخصائص والأساليب الإضافية. |
106 | 104 |
|
107 | | -Please note these links, as there's so much stuff to learn it's impossible to cover and remember everything. |
| 105 | +بالإضافة إلى ذلك، يتم وصف بعض الفئات بشكل منفصل في <https://spec.whatwg.org/>. |
108 | 106 |
|
109 | | -When you'd like to read about a property or a method, the Mozilla manual at <https://developer.mozilla.org/en-US/search> is also a nice resource, but the corresponding spec may be better: it's more complex and longer to read, but will make your fundamental knowledge sound and complete. |
| 107 | +يرجى ملاحظة هذه الروابط، حيث أن هناك الكثير من الأشياء لمعرفة أنه من المستحيل تغطية وتذكر كل شيء. |
110 | 108 |
|
111 | | -To find something, it's often convenient to use an internet search "WHATWG [term]" or "MDN [term]", e.g <https://google.com?q=whatwg+localstorage>, <https://google.com?q=mdn+localstorage>. |
| 109 | +عندما ترغب في القراءة عن خاصية أو طريقة ما، فإن دليل Mozilla على <https://developer.mozilla.org/en-US/search> هو أيضًا مورد جيد، ولكن المواصفات المقابلة قد تكون أفضل: إنها أكثر تعقيدًا وأطول وقتًا للقراءة، ولكنها ستجعل معرفتك الأساسية سليمة وكاملة. |
112 | 110 |
|
113 | | -Now we'll get down to learning DOM, because the document plays the central role in the UI. |
| 111 | +للعثور على شيء ما، غالبًا ما يكون من الملائم استخدام البحث على الإنترنت "WHATWG [مصطلح]" او "MDN [مصطلح]", مثل <https://google.com?q=whatwg+localstorage>, <https://google.com?q=mdn+localstorage>. |
114 | 112 |
|
| 113 | +سنبدأ الآن في تعلم الـ DOM, لأن المستند يلعب الدور المركزي في واجهة المستخدم. |
0 commit comments