diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:41:45 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:41:45 -0500 |
commit | 1109132f09d75da9a28b649c7677bb6ce07c40c0 (patch) | |
tree | 0dd8b084480983cf9f9680e8aedb92782a921b13 /files/fa/web | |
parent | 4b1a9203c547c019fc5398082ae19a3f3d4c3efe (diff) | |
download | translated-content-1109132f09d75da9a28b649c7677bb6ce07c40c0.tar.gz translated-content-1109132f09d75da9a28b649c7677bb6ce07c40c0.tar.bz2 translated-content-1109132f09d75da9a28b649c7677bb6ce07c40c0.zip |
initial commit
Diffstat (limited to 'files/fa/web')
87 files changed, 19181 insertions, 0 deletions
diff --git a/files/fa/web/api/animationevent/animationevent/index.html b/files/fa/web/api/animationevent/animationevent/index.html new file mode 100644 index 0000000000..cbdb74c9e8 --- /dev/null +++ b/files/fa/web/api/animationevent/animationevent/index.html @@ -0,0 +1,67 @@ +--- +title: AnimationEvent() +slug: Web/API/AnimationEvent/AnimationEvent +translation_of: Web/API/AnimationEvent/AnimationEvent +--- +<p>{{APIRef("Web Animations")}}{{SeeCompatTable}}</p> + +<p>The <code><strong>AnimationEvent(نمای پویا)</strong></code> constructor returns a newly created {{domxref("AnimationEvent")}}, representing an event in relation with an animation.</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox"><em>animationEvent</em> = new AnimationEvent(نمای پویا, {animationName: <em>aPropertyName</em>, + elapsedTime : <em>aFloat</em>, + pseudoElement: <em>aPseudoElementName</em>}); +</pre> + +<h3 id="Parameters">Parameters</h3> + +<p><em>The <code>AnimationEvent()</code> constructor also inherits arguments from {{domxref("Event.Event", "Event()")}}.</em></p> + +<dl> + <dt><code>type</code></dt> + <dd>A {{domxref("DOMString")}} representing the name of the type of the <code>AnimationEvent</code>. It is case-sensitive and can be: <code>'animationstart'</code>, <code>'animationend'</code>, or <code>'animationiteration'</code>.</dd> + <dt><code>animationName</code> {{optional_inline}}</dt> + <dd>A {{domxref("DOMString")}} containing the value of the {{cssxref("animation-name")}} CSS property associated with the transition. It defaults to <code>""</code>.</dd> + <dt><code>elapsedTime</code> {{optional_inline}}</dt> + <dd>A <code>float</code> giving the amount of time the animation has been running, in seconds, when this event fired, excluding any time the animation was paused. For an <code>"animationstart"</code> event, <code>elapsedTime</code> is <code>0.0</code> unless there was a negative value for {{cssxref("animation-delay")}}, in which case the event will be fired with <code>elapsedTime</code> containing <code>(-1 * </code><em>delay</em><code>)</code>. It defaults to <code>0.0</code>.</dd> + <dt><code>pseudoElement</code> {{optional_inline}}</dt> + <dd>Is a {{domxref("DOMString")}}, starting with <code>"::"</code>, containing the name of the <a href="/en-US/docs/Web/CSS/Pseudo-elements" title="Learn more about pseudo-elements.">pseudo-element</a> the animation runs on. If the animation doesn't run on a pseudo-element but on the element itself, specify an empty string: <code>""</code>. It defaults to <code>""</code>.</dd> +</dl> + +<h3 id="Return_value">Return value</h3> + +<p>A new {{domxref("AnimationEvent")}}, initialized per any provided options.</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{ SpecName('CSS3 Animations', '#dom-animationevent-animationevent', 'AnimationEvent()') }}</td> + <td>{{ Spec2('CSS3 Animations')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.AnimationEvent.AnimationEvent")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/CSS/Using_CSS_animations">Using CSS animations</a></li> + <li>Animation-related CSS properties and at-rules: {{cssxref("animation")}}, {{cssxref("animation-delay")}}, {{cssxref("animation-direction")}}, {{cssxref("animation-duration")}}, {{cssxref("animation-fill-mode")}}, {{cssxref("animation-iteration-count")}}, {{cssxref("animation-name")}}, {{cssxref("animation-play-state")}}, {{cssxref("animation-timing-function")}}, {{cssxref("@keyframes")}}</li> + <li>The {{domxref("AnimationEvent")}} interface it belongs to.</li> +</ul> diff --git a/files/fa/web/api/animationevent/index.html b/files/fa/web/api/animationevent/index.html new file mode 100644 index 0000000000..b89a47286d --- /dev/null +++ b/files/fa/web/api/animationevent/index.html @@ -0,0 +1,79 @@ +--- +title: AnimationEvent +slug: Web/API/AnimationEvent +tags: + - API + - Experimental + - Interface + - NeedsTranslation + - Reference + - TopicStub + - Web Animations +translation_of: Web/API/AnimationEvent +--- +<div>{{SeeCompatTable}}{{APIRef("Web Animations API")}}</div> + +<p>The <strong><code>AnimationEvent</code></strong> interface represents events providing information related to <a href="/en-US/docs/Web/Guide/CSS/Using_CSS_animations">animations</a>.</p> + +<p>{{InheritanceDiagram}}</p> + +<h2 id="Constructor">Constructor</h2> + +<dl> + <dt>{{domxref("AnimationEvent.AnimationEvent", "AnimationEvent()")}}</dt> + <dd>Creates an <code>AnimationEvent</code> event with the given parameters.</dd> +</dl> + +<h2 id="Properties">Properties</h2> + +<p><em>Also inherits properties from its parent {{domxref("Event")}}</em>.</p> + +<dl> + <dt>{{domxref("AnimationEvent.animationName")}} {{readonlyInline}}</dt> + <dd>Is a {{domxref("DOMString")}} containing the value of the {{cssxref("animation-name")}} CSS property associated with the transition.</dd> + <dt>{{domxref("AnimationEvent.elapsedTime")}} {{readonlyInline}}</dt> + <dd>Is a <code>float</code> giving the amount of time the animation has been running, in seconds, when this event fired, excluding any time the animation was paused. For an <code>animationstart</code> event, <code>elapsedTime</code> is <code>0.0</code> unless there was a negative value for {{cssxref("animation-delay")}}, in which case the event will be fired with <code>elapsedTime</code> containing <code>(-1 * <var>delay</var>)</code>.</dd> + <dt>{{domxref("AnimationEvent.pseudoElement")}} {{readonlyInline}}</dt> + <dd>Is a {{domxref("DOMString")}}, starting with <code>'::'</code>, containing the name of the <a href="/en-US/docs/Web/CSS/Pseudo-elements">pseudo-element</a> the animation runs on. If the animation doesn't run on a pseudo-element but on the element, an empty string: <code>''</code>.</dd> +</dl> + +<h2 id="Methods">Methods</h2> + +<p><em>Also inherits methods from its parent {{domxref("Event")}}</em>.</p> + +<dl> + <dt>{{domxref("AnimationEvent.initAnimationEvent()")}} {{non-standard_inline}}{{deprecated_inline}}</dt> + <dd>Initializes a <code>AnimationEvent</code> created using the deprecated {{domxref("Document.createEvent()", "Document.createEvent(\"AnimationEvent\")")}} method.</dd> +</dl> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSS3 Animations", "#interface-animationevent", "AnimationEvent")}}</td> + <td>{{Spec2("CSS3 Animations")}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.AnimationEvent")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/CSS/Using_CSS_animations">Using CSS animations</a></li> + <li>Animation-related CSS properties and at-rules: {{cssxref("animation")}}, {{cssxref("animation-delay")}}, {{cssxref("animation-direction")}}, {{cssxref("animation-duration")}}, {{cssxref("animation-fill-mode")}}, {{cssxref("animation-iteration-count")}}, {{cssxref("animation-name")}}, {{cssxref("animation-play-state")}}, {{cssxref("animation-timing-function")}}, {{cssxref("@keyframes")}}.</li> +</ul> diff --git a/files/fa/web/api/blob/index.html b/files/fa/web/api/blob/index.html new file mode 100644 index 0000000000..e2de156275 --- /dev/null +++ b/files/fa/web/api/blob/index.html @@ -0,0 +1,129 @@ +--- +title: Blob +slug: Web/API/Blob +tags: + - API + - Files + - NeedsMobileBrowserCompatibility + - NeedsTranslation + - Reference + - TopicStub + - WebAPI +translation_of: Web/API/Blob +--- +<div>{{APIRef("File API")}}</div> + +<p>A <code>Blob</code> object represents a file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The {{domxref("File")}} interface is based on <code>Blob</code>, inheriting blob functionality and expanding it to support files on the user's system.</p> + +<p>To construct a <code>Blob</code> from other non-blob objects and data, use the {{domxref("Blob.Blob", "Blob()")}} constructor. To create a blob that contains a subset of another blob's data, use the {{domxref("Blob.slice()", "slice()")}} method. To obtain a <code>Blob</code> object for a file on the user's file system, see the {{domxref("File")}} documentation.</p> + +<p>The APIs accepting <code>Blob</code> objects are also listed on the {{domxref("File")}} documentation.</p> + +<div class="note"> +<p><strong>Note:</strong> The <code>slice()</code> method had initially taken <code>length</code> as the second argument to indicate the number of bytes to copy into the new <code>Blob</code>. If you specified values such that <code>start + length</code> exceeded the size of the source <code>Blob</code>, the returned <code>Blob</code> contained data from the start index to the end of the source <code>Blob</code>.</p> +</div> + +<div class="note"><strong>Note:</strong> Be aware that the <code>slice()</code> method has vendor prefixes on some browsers and versions: <code>blob.mozSlice()</code> for Firefox 12 and earlier and <code>blob.webkitSlice()</code> in Safari. An old version of the <code>slice()</code> method, without vendor prefixes, had different semantics, and is obsolete. The support for <code>blob.mozSlice()</code> has been dropped with Firefox 30.</div> + +<h2 id="Constructor">Constructor</h2> + +<dl> + <dt>{{domxref("Blob.Blob", "Blob(blobParts[, options])")}}</dt> + <dd>Returns a newly created <code>Blob</code> object whose content consists of the concatenation of the array of values given in parameter.</dd> +</dl> + +<h2 id="Properties">Properties</h2> + +<dl> + <dt>{{domxref("Blob.size")}} {{readonlyinline}}</dt> + <dd>The size, in bytes, of the data contained in the <code>Blob</code> object.</dd> + <dt>{{domxref("Blob.type")}} {{readonlyinline}}</dt> + <dd>A string indicating the MIME type of the data contained in the <code>Blob</code>. If the type is unknown, this string is empty.</dd> +</dl> + +<h2 id="Methods">Methods</h2> + +<dl> + <dt>{{domxref("Blob.slice()", "Blob.slice([start[, end[, contentType]]])")}}</dt> + <dd>Returns a new <code>Blob</code> object containing the data in the specified range of bytes of the source <code>Blob</code>.</dd> +</dl> + +<h2 id="Examples">Examples</h2> + +<h3 id="Blob_constructor_example_usage">Blob constructor example usage</h3> + +<p>The {{domxref("Blob.Blob", "Blob() constructor")}} allows one to create blobs from other objects. For example, to construct a blob from string:</p> + +<pre class="brush: js">var debug = {hello: "world"}; +var blob = new Blob([JSON.stringify(debug, null, 2)], {type : 'application/json'});</pre> + +<div class="warning"> +<p>Before the Blob constructor was available, this could be accomplished through the {{domxref("BlobBuilder")}} API, which is now deprecated:</p> + +<pre class="brush: js">var builder = new BlobBuilder(); +var fileParts = ['<a id="a"><b id="b">hey!</b></a>']; +builder.append(fileParts[0]); +var myBlob = builder.getBlob('text/xml'); +</pre> +</div> + +<h3 id="Example_for_creating_a_URL_to_a_typed_array_using_a_blob">Example for creating a URL to a typed array using a blob</h3> + +<p>The following code:</p> + +<pre class="brush: js">var typedArray = GetTheTypedArraySomehow(); +var blob = new Blob([typedArray.buffer], {type: 'application/octet-stream'}); // pass a useful mime type here +var url = URL.createObjectURL(blob); +// url will be something like: blob:d3958f5c-0777-0845-9dcf-2cb28783acaf +// now you can use the url in any context that regular URLs can be used in, for example img.src, etc. +</pre> + +<h3 id="Example_for_extracting_data_from_a_Blob">Example for extracting data from a Blob</h3> + +<p>One way to read content from a Blob is to use a {{domxref("FileReader")}}. The following code reads the content of a Blob as a typed array:</p> + +<pre class="brush: js">var reader = new FileReader(); +reader.addEventListener("loadend", function() { + // reader.result contains the contents of blob as a typed array +}); +reader.readAsArrayBuffer(blob);</pre> + +<p>Another way to read content from a Blob is to use a Response. The following code reads the content of a Blob as text:</p> + +<pre class="brush: js">var text = await (new Response(blob)).text(); +</pre> + +<p>By using other methods of {{domxref("FileReader")}}, it is possible to read the contents of a Blob as a string or a data URL.</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('File API','#blob','Blob')}}</td> + <td>{{Spec2('File API')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.Blob")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{domxref("BlobBuilder")}}</li> + <li>{{domxref("FileReader")}}</li> + <li>{{domxref("File")}}</li> + <li>{{domxref("URL.createObjectURL")}}</li> + <li><a href="/en-US/docs/Components.utils.importGlobalProperties">Components.utils.importGlobalProperties</a></li> +</ul> diff --git a/files/fa/web/api/canvasrenderingcontext2d/createlineargradient/index.html b/files/fa/web/api/canvasrenderingcontext2d/createlineargradient/index.html new file mode 100644 index 0000000000..d7a1e1bde6 --- /dev/null +++ b/files/fa/web/api/canvasrenderingcontext2d/createlineargradient/index.html @@ -0,0 +1,114 @@ +--- +title: CanvasRenderingContext2D.createLinearGradient() +slug: Web/API/CanvasRenderingContext2D/createLinearGradient +translation_of: Web/API/CanvasRenderingContext2D/createLinearGradient +--- +<div>{{APIRef}}</div> + +<p>The <code><strong>CanvasRenderingContext2D</strong></code><strong><code>.createLinearGradient()</code></strong> method of the Canvas 2D API creates a gradient along the line connecting two given coordinates.</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/14681/mdn-canvas-linearGradient.png" style="height: 121px; width: 264px;"></p> + +<p>This method returns a linear {{domxref("CanvasGradient")}}. To be applied to a shape, the gradient must first be assigned to the {{domxref("CanvasRenderingContext2D.fillStyle", "fillStyle")}} or {{domxref("CanvasRenderingContext2D.strokeStyle", "strokeStyle")}} properties.</p> + +<div class="note"> +<p><strong>Note:</strong> Gradient coordinates are global, i.e., relative to the current coordinate space. When applied to a shape, the coordinates are NOT relative to the shape's coordinates.</p> +</div> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">CanvasGradient <var>ctx</var>.createLinearGradient(<var>x0</var>, <var>y0</var>, <var>x1</var>, <var>y1</var>); +</pre> + +<p>The <code>createLinearGradient()</code> method is specified by four parameters defining the start and end points of the gradient line.</p> + +<h3 id="Parameters">Parameters</h3> + +<dl> + <dt><code>x0</code></dt> + <dd>The x-axis coordinate of the start point.</dd> + <dt><code>y0</code></dt> + <dd>The y-axis coordinate of the start point.</dd> + <dt><code>x1</code></dt> + <dd>The x-axis coordinate of the end point.</dd> + <dt><code>y1</code></dt> + <dd>The y-axis coordinate of the end point.</dd> +</dl> + +<h3 id="Return_value">Return value</h3> + +<dl> + <dt>{{domxref("CanvasGradient")}}</dt> + <dd>A linear <code>CanvasGradient</code> initialized with the specified line.</dd> +</dl> + +<h2 id="Examples">Examples</h2> + +<h3 id="Filling_a_rectangle_with_a_linear_gradient">Filling a rectangle with a linear gradient</h3> + +<p>This example initializes a linear gradient using the <code>createLinearGradient()</code> method. Three color stops between the gradient's start and end points are then created. Finally, the gradient is assigned to the canvas context, and is rendered to a filled rectangle.</p> + +<h4 id="HTML">HTML</h4> + +<pre class="brush: html"><canvas id="canvas"></canvas> +</pre> + +<h4 id="JavaScript">JavaScript</h4> + +<pre class="brush: js; highlight:[7]">var canvas = document.getElementById('canvas'); +var ctx = canvas.getContext('2d'); + +// Create a linear gradient +// The start gradient point is at x=20, y=0 +// The end gradient point is at x=220, y=0 +var gradient = ctx.createLinearGradient(20,0, 220,0); + +// Add three color stops +gradient.addColorStop(0, 'green'); +gradient.addColorStop(.5, 'cyan'); +gradient.addColorStop(1, 'green'); + +// Set the fill style and draw a rectangle +ctx.fillStyle = gradient; +ctx.fillRect(20, 20, 200, 100); +</pre> + +<h4 id="Result">Result</h4> + +<p>{{ EmbedLiveSample('Filling_a_rectangle_with_a_linear_gradient', 700, 180) }}</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-createlineargradient", "CanvasRenderingContext2D.createLinearGradient")}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.CanvasRenderingContext2D.createLinearGradient")}}</p> + +<h3 id="Gecko-specific_notes">Gecko-specific notes</h3> + +<ul> + <li>Starting with Gecko 2.0 {{geckoRelease("2.0")}}, specifying non-finite values now throws <code>NOT_SUPPORTED_ERR</code> instead of <code>SYNTAX_ERR</code>.</li> +</ul> + +<h2 id="See_also">See also</h2> + +<ul> + <li>The interface defining this method: {{domxref("CanvasRenderingContext2D")}}</li> + <li>{{domxref("CanvasRenderingContext2D.createRadialGradient()")}}</li> +</ul> diff --git a/files/fa/web/api/canvasrenderingcontext2d/index.html b/files/fa/web/api/canvasrenderingcontext2d/index.html new file mode 100644 index 0000000000..3b9cc7021e --- /dev/null +++ b/files/fa/web/api/canvasrenderingcontext2d/index.html @@ -0,0 +1,424 @@ +--- +title: CanvasRenderingContext2D +slug: Web/API/CanvasRenderingContext2D +tags: + - API + - Canvas + - CanvasRenderingContext2D + - Games + - Graphics + - NeedsTranslation + - Reference + - TopicStub +translation_of: Web/API/CanvasRenderingContext2D +--- +<div>{{APIRef}}</div> + +<p><span class="seoSummary">The <code><strong>CanvasRenderingContext2D</strong></code> interface, part of the <a href="/en-US/docs/Web/API/Canvas_API">Canvas API</a>, provides the 2D rendering context for the drawing surface of a {{HTMLElement("canvas")}} element. It is used for drawing shapes, text, images, and other objects.</span></p> + +<p>See the interface's properties and methods in the sidebar and below. The <a href="/en-US/docs/Web/API/Canvas_API/Tutorial" title="Canvas tutorial">Canvas tutorial</a> has more explanation, examples, and resources, as well.</p> + +<h2 id="Basic_example">Basic example</h2> + +<p>To get a <code>CanvasRenderingContext2D</code> instance, you must first have an HTML <code><canvas></code> element to work with:</p> + +<pre class="brush: html"><canvas id="my-house" width="300" height="300"></canvas></pre> + +<p>To get the canvas' 2D rendering context, call {{domxref("HTMLCanvasElement.getContext()", "getContext()")}} on the <code><canvas></code> element, supplying <code>'2d'</code> as the argument:</p> + +<pre class="brush: js">const canvas = document.getElementById('my-house'); +const ctx = canvas.getContext('2d'); +</pre> + +<p>With the context in hand, you can draw anything you like. This code draws a house:</p> + +<pre class="brush: js">// Set line width +ctx.lineWidth = 10; + +// Wall +ctx.strokeRect(75, 140, 150, 110); + +// Door +ctx.fillRect(130, 190, 40, 60); + +// Roof +ctx.beginPath(); +ctx.moveTo(50, 140); +ctx.lineTo(150, 60); +ctx.lineTo(250, 140); +ctx.closePath(); +ctx.stroke(); +</pre> + +<p>The resulting drawing looks like this:</p> + +<p>{{EmbedLiveSample("Basic_example", 700, 330)}}</p> + +<h2 id="Reference">Reference</h2> + +<h3 id="Drawing_rectangles">Drawing rectangles</h3> + +<p>There are three methods that immediately draw rectangles to the canvas.</p> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.clearRect()")}}</dt> + <dd>Sets all pixels in the rectangle defined by starting point <em>(x, y)</em> and size <em>(width, height)</em> to transparent black, erasing any previously drawn content.</dd> + <dt>{{domxref("CanvasRenderingContext2D.fillRect()")}}</dt> + <dd>Draws a filled rectangle at <em>(x, y) </em>position whose size is determined by <em>width</em> and <em>height</em>.</dd> + <dt>{{domxref("CanvasRenderingContext2D.strokeRect()")}}</dt> + <dd>Paints a rectangle which has a starting point at <em>(x, y)</em> and has a<em> w</em> width and an <em>h</em> height onto the canvas, using the current stroke style.</dd> +</dl> + +<h3 id="Drawing_text">Drawing text</h3> + +<p>The following methods draw text. See also the {{domxref("TextMetrics")}} object for text properties.</p> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.fillText()")}}</dt> + <dd>Draws (fills) a given text at the given (x, y) position.</dd> + <dt>{{domxref("CanvasRenderingContext2D.strokeText()")}}</dt> + <dd>Draws (strokes) a given text at the given (x, y)<em> </em>position.</dd> + <dt>{{domxref("CanvasRenderingContext2D.measureText()")}}</dt> + <dd>Returns a {{domxref("TextMetrics")}} object.</dd> +</dl> + +<h3 id="Line_styles">Line styles</h3> + +<p>The following methods and properties control how lines are drawn.</p> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.lineWidth")}}</dt> + <dd>Width of lines. Default <code>1.0</code>.</dd> + <dt>{{domxref("CanvasRenderingContext2D.lineCap")}}</dt> + <dd>Type of endings on the end of lines. Possible values: <code>butt</code> (default), <code>round</code>, <code>square</code>.</dd> + <dt>{{domxref("CanvasRenderingContext2D.lineJoin")}}</dt> + <dd>Defines the type of corners where two lines meet. Possible values: <code>round</code>, <code>bevel</code>, <code>miter</code> (default).</dd> + <dt>{{domxref("CanvasRenderingContext2D.miterLimit")}}</dt> + <dd>Miter limit ratio. Default <code>10</code>.</dd> + <dt>{{domxref("CanvasRenderingContext2D.getLineDash()")}}</dt> + <dd>Returns the current line dash pattern array containing an even number of non-negative numbers.</dd> + <dt>{{domxref("CanvasRenderingContext2D.setLineDash()")}}</dt> + <dd>Sets the current line dash pattern.</dd> + <dt>{{domxref("CanvasRenderingContext2D.lineDashOffset")}}</dt> + <dd>Specifies where to start a dash array on a line.</dd> +</dl> + +<h3 id="Text_styles">Text styles</h3> + +<p>The following properties control how text is laid out.</p> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.font")}}</dt> + <dd>Font setting. Default value <code>10px sans-serif</code>.</dd> + <dt>{{domxref("CanvasRenderingContext2D.textAlign")}}</dt> + <dd>Text alignment setting. Possible values: <code>start</code> (default), <code>end</code>, <code>left</code>, <code>right</code>, <code>center</code>.</dd> + <dt>{{domxref("CanvasRenderingContext2D.textBaseline")}}</dt> + <dd>Baseline alignment setting. Possible values: <code>top</code>, <code>hanging</code>, <code>middle</code>, <code>alphabetic</code> (default), <code>ideographic</code>, <code>bottom</code>.</dd> + <dt>{{domxref("CanvasRenderingContext2D.direction")}}</dt> + <dd>Directionality. Possible values: <code>ltr</code>, <code>rtl</code>, <code>inherit</code> (default).</dd> +</dl> + +<h3 id="Fill_and_stroke_styles">Fill and stroke styles</h3> + +<p>Fill styling is used for colors and styles inside shapes and stroke styling is used for the lines around shapes.</p> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.fillStyle")}}</dt> + <dd>Color or style to use inside shapes. Default <code>#000</code> (black).</dd> + <dt>{{domxref("CanvasRenderingContext2D.strokeStyle")}}</dt> + <dd>Color or style to use for the lines around shapes. Default <code>#000</code> (black).</dd> +</dl> + +<h3 id="Gradients_and_patterns">Gradients and patterns</h3> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.createLinearGradient()")}}</dt> + <dd>Creates a linear gradient along the line given by the coordinates represented by the parameters.</dd> + <dt>{{domxref("CanvasRenderingContext2D.createRadialGradient()")}}</dt> + <dd>Creates a radial gradient given by the coordinates of the two circles represented by the parameters.</dd> + <dt>{{domxref("CanvasRenderingContext2D.createPattern()")}}</dt> + <dd>Creates a pattern using the specified image (a {{domxref("CanvasImageSource")}}). It repeats the source in the directions specified by the repetition argument. This method returns a {{domxref("CanvasPattern")}}.</dd> +</dl> + +<h3 id="Shadows">Shadows</h3> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.shadowBlur")}}</dt> + <dd>Specifies the blurring effect. Default: <code>0</code></dd> + <dt>{{domxref("CanvasRenderingContext2D.shadowColor")}}</dt> + <dd>Color of the shadow. Default: fully-transparent black.</dd> + <dt>{{domxref("CanvasRenderingContext2D.shadowOffsetX")}}</dt> + <dd>Horizontal distance the shadow will be offset. Default: <code>0</code>.</dd> + <dt>{{domxref("CanvasRenderingContext2D.shadowOffsetY")}}</dt> + <dd>Vertical distance the shadow will be offset. Default: <code>0</code>.</dd> +</dl> + +<h3 id="Paths">Paths</h3> + +<p>The following methods can be used to manipulate paths of objects.</p> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.beginPath()")}}</dt> + <dd>Starts a new path by emptying the list of sub-paths. Call this method when you want to create a new path.</dd> + <dt>{{domxref("CanvasRenderingContext2D.closePath()")}}</dt> + <dd>Causes the point of the pen to move back to the start of the current sub-path. It tries to draw a straight line from the current point to the start. If the shape has already been closed or has only one point, this function does nothing.</dd> + <dt>{{domxref("CanvasRenderingContext2D.moveTo()")}}</dt> + <dd>Moves the starting point of a new sub-path to the (x, y) coordinates.</dd> + <dt>{{domxref("CanvasRenderingContext2D.lineTo()")}}</dt> + <dd>Connects the last point in the current sub-path to the specified (x, y) coordinates with a straight line.</dd> + <dt>{{domxref("CanvasRenderingContext2D.bezierCurveTo()")}}</dt> + <dd>Adds a cubic Bézier curve to the current path.</dd> + <dt>{{domxref("CanvasRenderingContext2D.quadraticCurveTo()")}}</dt> + <dd>Adds a quadratic Bézier curve to the current path.</dd> + <dt>{{domxref("CanvasRenderingContext2D.arc()")}}</dt> + <dd>Adds a circular arc to the current path.</dd> + <dt>{{domxref("CanvasRenderingContext2D.arcTo()")}}</dt> + <dd>Adds an arc to the current path with the given control points and radius, connected to the previous point by a straight line.</dd> + <dt>{{domxref("CanvasRenderingContext2D.ellipse()")}}</dt> + <dd>Adds an elliptical arc to the current path.</dd> + <dt>{{domxref("CanvasRenderingContext2D.rect()")}}</dt> + <dd>Creates a path for a rectangle at<em> </em>position (x, y) with a size that is determined by <em>width</em> and <em>height</em>.</dd> +</dl> + +<h3 id="Drawing_paths">Drawing paths</h3> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.fill()")}}</dt> + <dd>Fills the current sub-paths with the current fill style.</dd> + <dt>{{domxref("CanvasRenderingContext2D.stroke()")}}</dt> + <dd>Strokes the current sub-paths with the current stroke style.</dd> + <dt>{{domxref("CanvasRenderingContext2D.drawFocusIfNeeded()")}}</dt> + <dd>If a given element is focused, this method draws a focus ring around the current path.</dd> + <dt>{{domxref("CanvasRenderingContext2D.scrollPathIntoView()")}}</dt> + <dd>Scrolls the current path or a given path into the view.</dd> + <dt>{{domxref("CanvasRenderingContext2D.clip()")}}</dt> + <dd>Creates a clipping path from the current sub-paths. Everything drawn after <code>clip()</code> is called appears inside the clipping path only. For an example, see <a href="/en-US/docs/Web/API/Canvas_API/Tutorial/Compositing" title="Clipping paths">Clipping paths</a> in the Canvas tutorial.</dd> + <dt>{{domxref("CanvasRenderingContext2D.isPointInPath()")}}</dt> + <dd>Reports whether or not the specified point is contained in the current path.</dd> + <dt>{{domxref("CanvasRenderingContext2D.isPointInStroke()")}}</dt> + <dd>Reports whether or not the specified point is inside the area contained by the stroking of a path.</dd> +</dl> + +<h3 id="Transformations">Transformations</h3> + +<p>Objects in the <code>CanvasRenderingContext2D</code> rendering context have a current transformation matrix and methods to manipulate it. The transformation matrix is applied when creating the current default path, painting text, shapes and {{domxref("Path2D")}} objects. The methods listed below remain for historical and compatibility reasons as {{domxref("SVGMatrix")}} objects are used in most parts of the API nowadays and will be used in the future instead.</p> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.currentTransform")}} {{experimental_inline}}</dt> + <dd>Current transformation matrix ({{domxref("SVGMatrix")}} object).</dd> + <dt>{{domxref("CanvasRenderingContext2D.getTransform")}}</dt> + <dd>Retrieves the current transformation matrix being applied to the context.</dd> + <dt>{{domxref("CanvasRenderingContext2D.rotate()")}}</dt> + <dd>Adds a rotation to the transformation matrix. The angle argument represents a clockwise rotation angle and is expressed in radians.</dd> + <dt>{{domxref("CanvasRenderingContext2D.scale()")}}</dt> + <dd>Adds a scaling transformation to the canvas units by x horizontally and by y vertically.</dd> + <dt>{{domxref("CanvasRenderingContext2D.translate()")}}</dt> + <dd>Adds a translation transformation by moving the canvas and its origin x horzontally and y vertically on the grid.</dd> + <dt>{{domxref("CanvasRenderingContext2D.transform()")}}</dt> + <dd>Multiplies the current transformation matrix with the matrix described by its arguments.</dd> + <dt>{{domxref("CanvasRenderingContext2D.setTransform()")}}</dt> + <dd>Resets the current transform to the identity matrix, and then invokes the <code>transform()</code> method with the same arguments.</dd> + <dt>{{domxref("CanvasRenderingContext2D.resetTransform()")}} {{experimental_inline}}</dt> + <dd>Resets the current transform by the identity matrix.</dd> +</dl> + +<h3 id="Compositing">Compositing</h3> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.globalAlpha")}}</dt> + <dd>Alpha value that is applied to shapes and images before they are composited onto the canvas. Default <code>1.0</code> (opaque).</dd> + <dt>{{domxref("CanvasRenderingContext2D.globalCompositeOperation")}}</dt> + <dd>With <code>globalAlpha</code> applied this sets how shapes and images are drawn onto the existing bitmap.</dd> +</dl> + +<h3 id="Drawing_images">Drawing images</h3> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.drawImage()")}}</dt> + <dd>Draws the specified image. This method is available in multiple formats, providing a great deal of flexibility in its use.</dd> +</dl> + +<h3 id="Pixel_manipulation">Pixel manipulation</h3> + +<p>See also the {{domxref("ImageData")}} object.</p> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.createImageData()")}}</dt> + <dd>Creates a new, blank {{domxref("ImageData")}} object with the specified dimensions. All of the pixels in the new object are transparent black.</dd> + <dt>{{domxref("CanvasRenderingContext2D.getImageData()")}}</dt> + <dd>Returns an {{domxref("ImageData")}} object representing the underlying pixel data for the area of the canvas denoted by the rectangle which starts at <em>(sx, sy)</em> and has an <em>sw</em> width and <em>sh</em> height.</dd> + <dt>{{domxref("CanvasRenderingContext2D.putImageData()")}}</dt> + <dd>Paints data from the given {{domxref("ImageData")}} object onto the bitmap. If a dirty rectangle is provided, only the pixels from that rectangle are painted.</dd> +</dl> + +<h3 id="Image_smoothing">Image smoothing</h3> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}} {{experimental_inline}}</dt> + <dd>Image smoothing mode; if disabled, images will not be smoothed if scaled.</dd> +</dl> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.imageSmoothingQuality")}} {{experimental_inline}}</dt> + <dd>Allows you to set the quality of image smoothing.</dd> +</dl> + +<h3 id="The_canvas_state">The canvas state</h3> + +<p>The <code>CanvasRenderingContext2D</code> rendering context contains a variety of drawing style states (attributes for line styles, fill styles, shadow styles, text styles). The following methods help you to work with that state:</p> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.save()")}}</dt> + <dd>Saves the current drawing style state using a stack so you can revert any change you make to it using <code>restore()</code>.</dd> + <dt>{{domxref("CanvasRenderingContext2D.restore()")}}</dt> + <dd>Restores the drawing style state to the last element on the 'state stack' saved by <code>save()</code>.</dd> + <dt>{{domxref("CanvasRenderingContext2D.canvas")}}</dt> + <dd>A read-only back-reference to the {{domxref("HTMLCanvasElement")}}. Might be {{jsxref("null")}} if it is not associated with a {{HTMLElement("canvas")}} element.</dd> +</dl> + +<h3 id="Hit_regions">Hit regions</h3> + +<dl> + <dt>{{domxref("CanvasRenderingContext2D.addHitRegion()")}} {{experimental_inline}}</dt> + <dd>Adds a hit region to the canvas.</dd> + <dt>{{domxref("CanvasRenderingContext2D.removeHitRegion()")}} {{experimental_inline}}</dt> + <dd>Removes the hit region with the specified <code>id</code> from the canvas.</dd> + <dt>{{domxref("CanvasRenderingContext2D.clearHitRegions()")}} {{experimental_inline}}</dt> + <dd>Removes all hit regions from the canvas.</dd> +</dl> + +<h3 id="Filters">Filters</h3> + +<dl> + <dt>{{experimental_inline}} {{domxref("CanvasRenderingContext2D.filter")}}</dt> + <dd>Applies a CSS or SVG filter to the canvas, e.g., to change its brightness or bluriness.</dd> +</dl> + +<h2 id="Non-standard_APIs">Non-standard APIs</h2> + +<h3 id="Blink_and_WebKit">Blink and WebKit</h3> + +<p>Most of these APIs are <a href="https://code.google.com/p/chromium/issues/detail?id=363198">deprecated and were removed shortly after Chrome 36</a>.</p> + +<dl> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.clearShadow()</code></dt> + <dd>Removes all shadow settings like {{domxref("CanvasRenderingContext2D.shadowColor")}} and {{domxref("CanvasRenderingContext2D.shadowBlur")}}.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.drawImageFromRect()</code></dt> + <dd>This is redundant with an equivalent overload of <code>drawImage</code>.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.setAlpha()</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.globalAlpha")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.setCompositeOperation()</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.globalCompositeOperation")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.setLineWidth()</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.lineWidth")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.setLineJoin()</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.lineJoin")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.setLineCap()</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.lineCap")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.setMiterLimit()</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.miterLimit")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.setStrokeColor()</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.strokeStyle")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.setFillColor()</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.fillStyle")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.setShadow()</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.shadowColor")}} and {{domxref("CanvasRenderingContext2D.shadowBlur")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.webkitLineDash</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.getLineDash()")}} and {{domxref("CanvasRenderingContext2D.setLineDash()")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.webkitLineDashOffset</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.lineDashOffset")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.webkitImageSmoothingEnabled</code></dt> + <dd>Use {{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}} instead.</dd> +</dl> + +<h3 id="Blink_only">Blink only</h3> + +<dl> + <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.isContextLost()</code></dt> + <dd>Inspired by the same <code>WebGLRenderingContext</code> method it returns <code>true</code> if the Canvas context has been lost, or <code>false</code> if not.</dd> +</dl> + +<h3 id="WebKit_only">WebKit only</h3> + +<dl> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.webkitBackingStorePixelRatio</code></dt> + <dd>The backing store size in relation to the canvas element. See <a href="http://www.html5rocks.com/en/tutorials/canvas/hidpi/">High DPI Canvas</a>.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.webkitGetImageDataHD</code></dt> + <dd>Intended for HD backing stores, but removed from canvas specifications.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.webkitPutImageDataHD</code></dt> + <dd>Intended for HD backing stores, but removed from canvas specifications.</dd> +</dl> + +<dl> +</dl> + +<h3 id="Gecko_only">Gecko only</h3> + +<h4 id="Prefixed_APIs">Prefixed APIs</h4> + +<dl> + <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.mozCurrentTransform</code></dt> + <dd>Sets or gets the current transformation matrix, see {{domxref("CanvasRenderingContext2D.currentTransform")}}. {{ gecko_minversion_inline("7.0") }}</dd> + <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.mozCurrentTransformInverse</code></dt> + <dd>Sets or gets the current inversed transformation matrix. {{ gecko_minversion_inline("7.0") }}</dd> + <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.mozImageSmoothingEnabled</code></dt> + <dd>See {{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}}.</dd> + <dt>{{non-standard_inline}} {{deprecated_inline}} <code>CanvasRenderingContext2D.mozTextStyle</code></dt> + <dd>Introduced in in Gecko 1.9, deprecated in favor of the {{domxref("CanvasRenderingContext2D.font")}} property.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozDrawText()</code></dt> + <dd>This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0. Use {{domxref("CanvasRenderingContext2D.strokeText()")}} or {{domxref("CanvasRenderingContext2D.fillText()")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozMeasureText()</code></dt> + <dd>This method was introduced in Gecko 1.9 and is unimplemented starting with Gecko 7.0. Use {{domxref("CanvasRenderingContext2D.measureText()")}} instead.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozPathText()</code></dt> + <dd>This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0.</dd> + <dt>{{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozTextAlongPath()</code></dt> + <dd>This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0.</dd> +</dl> + +<h4 id="Internal_APIs_chrome-context_only">Internal APIs (chrome-context only)</h4> + +<dl> + <dt>{{non-standard_inline}} {{domxref("CanvasRenderingContext2D.drawWindow()")}}</dt> + <dd>Renders a region of a window into the <code>canvas</code>. The contents of the window's viewport are rendered, ignoring viewport clipping and scrolling.</dd> + <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.demote()</code></dt> + <dd>This causes a context that is currently using a hardware-accelerated backend to fallback to a software one. All state should be preserved.</dd> +</dl> + +<h3 id="Internet_Explorer">Internet Explorer</h3> + +<dl> + <dt>{{non-standard_inline}} <code>CanvasRenderingContext2D.msFillRule</code></dt> + <dd>The <a class="external" href="http://cairographics.org/manual/cairo-cairo-t.html#cairo-fill-rule-t" title="http://cairographics.org/manual/cairo-cairo-t.html#cairo-fill-rule-t">fill rule</a> to use. This must be one of <code>evenodd</code> or <code>nonzero</code> (default).</dd> +</dl> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', "#2dcontext", "CanvasRenderingContext2D")}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("api.CanvasRenderingContext2D")}}</p> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{domxref("HTMLCanvasElement")}}</li> + <li>{{HTMLElement("canvas")}}</li> +</ul> diff --git a/files/fa/web/api/element/getboundingclientrect/index.html b/files/fa/web/api/element/getboundingclientrect/index.html new file mode 100644 index 0000000000..3ec032bead --- /dev/null +++ b/files/fa/web/api/element/getboundingclientrect/index.html @@ -0,0 +1,90 @@ +--- +title: Element.getBoundingClientRect() +slug: Web/API/Element/getBoundingClientRect +translation_of: Web/API/Element/getBoundingClientRect +--- +<div>{{APIRef("DOM")}}</div> + +<p style="direction: rtl;"><code><font face="Arial, x-locale-body, sans-serif"><span style="background-color: #ffffff;"> روال </span></font><strong>Element.getBoundingClientRect() اندازه و محل قرار گیری نسبی یک ایتم را در صفحه باز می گرداند </strong></code></p> + +<p style="direction: rtl;"> </p> + +<h2 id="ترکیب" style="direction: rtl;">ترکیب</h2> + +<pre class="syntaxbox" style="direction: rtl;">var <a href="/en-US/docs/Web/API/DOMRect">domRect</a> = <a href="/en-US/docs/Web/API/Element">element</a>.getBoundingClientRect();</pre> + +<h3 id="Value">Value</h3> + +<p style="direction: rtl;">مقدار بازگشتی تابع {{domxref("DOMRect")}} شی ای می باشد که با اجتماع مسطتیلی که با آیتم {{domxref("Element.getClientRects", "getClientRects()")}} بازگشت می شود.</p> + +<p style="direction: rtl;">The returned value is a {{domxref("DOMRect")}} object which is the union of the rectangles returned by {{domxref("Element.getClientRects", "getClientRects()")}} for the element, i.e., the CSS border-boxes associated with the element. The result is the smallest rectangle which contains the entire element, with read-only <code>left</code>, <code>top</code>, <code>right</code>, <code>bottom</code>, <code>x</code>, <code>y</code>, <code>width</code>, and <code>height</code> properties describing the overall border-box in pixels. Properties other than <code>width</code> and <code>height</code> are relative to the top-left of the viewport.</p> + +<p>Empty border-boxes are completely ignored. If all the element's border-boxes are empty, then a rectangle is returned with a <code>width</code> and <code>height</code> of zero and where the <code>top</code> and <code>left</code> are the top-left of the border-box for the first CSS box (in content order) for the element.</p> + +<p>The amount of scrolling that has been done of the viewport area (or any other scrollable element) is taken into account when computing the bounding rectangle. This means that the rectangle's boundary edges (<font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.498039);">top, right, bottom, left</span></font>) change their values every time the scrolling position changes (because their values are relative to the viewport and not absolute). If you need the bounding rectangle relative to the top-left corner of the document, just add the current scrolling position to the <code>top</code> and <code>left</code> properties (these can be obtained using {{domxref("window.scrollX")}} and {{domxref("window.scrollY")}}) to get a bounding rectangle which is independent from the current scrolling position.</p> + +<p>Scripts requiring high cross-browser compatibility can use {{domxref("window.pageXOffset")}} and {{domxref("window.pageYOffset")}} instead of <code>window.scrollX</code> and <code>window.scrollY.</code> Scripts without access to these properties can use code like this:</p> + +<pre class="brush:js">// For scrollX +(((t = document.documentElement) || (t = document.body.parentNode)) + && typeof t.scrollLeft == 'number' ? t : document.body).scrollLeft +// For scrollY +(((t = document.documentElement) || (t = document.body.parentNode)) + && typeof t.scrollTop == 'number' ? t : document.body).scrollTop +</pre> + +<h2 id="مثال" style="direction: rtl;">مثال</h2> + +<pre class="brush:js">// rect is a DOMRect object with eight properties: left, top, right, bottom, x, y, width, height +var rect = obj.getBoundingClientRect(); +</pre> + +<h2 id="ویژگی_ها" style="direction: rtl;">ویژگی ها</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSSOM View", "#dom-element-getboundingclientrect", "Element.getBoundingClientRect()")}}</td> + <td>{{Spec2("CSSOM View")}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h3 id="Notes">Notes</h3> + +<p>The returned <code>DOMRect</code> object can be modified in modern browsers. This was not true with older versions which effectively returned <code>DOMRectReadOnly</code>. With IE and Edge, not being able to add missing properties to their returned <a href="https://msdn.microsoft.com/en-us/library/hh826029(VS.85).aspx"><code>ClientRect</code></a>, object prevents backfilling <code>x</code> and <code>y</code>.</p> + +<p>Due to compatibility problems (see below), it is safest to rely on only properties <code>left</code>, <code>top</code>, <code>right</code>, and <code>bottom</code>. </p> + +<p>Properties in the returned <code>DOMRect</code> object are not own properties. While the <code>in</code> operator and <code>for...in</code> will find returned properties, other APIs such as <code>Object.keys()</code> will fail. Moreover, and unexpectedly, the ES2015 and newer features such as <code>Object.assign()</code> and object rest/spread will fail to copy returned properties.</p> + +<pre class="brush: js">rect = elt.getBoundingClientRect() +// The result in emptyObj is {} +emptyObj = Object.assign({}, rect) +emptyObj = { ...rect } +{width, ...emptyObj} = rect +</pre> + +<p><code>DOMRect</code> properties <code>top</code> <code>left</code> <code>right</code> <code>bottom</code> are computed from the other property values.</p> + +<h2 id="سازگاری_با_مرورگر_ها" style="direction: rtl;">سازگاری با مرورگر ها</h2> + +<div class="hidden" style="direction: rtl;">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</div> + +<p>{{Compat("api.Element.getBoundingClientRect")}}</p> + +<h2 id="همچنین" style="direction: rtl;">همچنین</h2> + +<ul> + <li><code><a href="/en-US/docs/DOM/element.getClientRects">getClientRects()</a></code></li> + <li><a href="https://msdn.microsoft.com/en-us/library/ms536433(VS.85).aspx">MSDN: <code>getBoundingClientRect</code></a></li> + <li><a href="https://msdn.microsoft.com/en-us/library/hh826029(VS.85).aspx">MSDN: <code>ClientRect</code></a>, an earlier version of <code>DOMRect</code></li> +</ul> diff --git a/files/fa/web/api/element/index.html b/files/fa/web/api/element/index.html new file mode 100644 index 0000000000..a0d4f8ee21 --- /dev/null +++ b/files/fa/web/api/element/index.html @@ -0,0 +1,331 @@ +--- +title: Element +slug: Web/API/Element +tags: + - API + - DOM + - DOM Reference + - Element + - Interface + - NeedsTranslation + - Reference + - TopicStub + - Web API +translation_of: Web/API/Element +--- +<div>{{APIRef("DOM")}}</div> + +<p><span class="seoSummary"><strong><code>Element</code></strong> is the most general base class from which all objects in a {{DOMxRef("Document")}} inherit. It only has methods and properties common to all kinds of elements. More specific classes inherit from <code>Element</code>.</span> For example, the {{DOMxRef("HTMLElement")}} interface is the base interface for HTML elements, while the {{DOMxRef("SVGElement")}} interface is the basis for all SVG elements. Most functionality is specified further down the class hierarchy.</p> + +<p>Languages outside the realm of the Web platform, like XUL through the <code>XULElement</code> interface, also implement <code>Element</code>.</p> + +<p>{{InheritanceDiagram}}</p> + +<h2 id="Properties" name="Properties">Properties</h2> + +<p><em>Inherits properties from its parent interface, {{DOMxRef("Node")}}, and by extension that interface's parent, {{DOMxRef("EventTarget")}}. It implements the properties of {{DOMxRef("ParentNode")}}, {{DOMxRef("ChildNode")}}, {{DOMxRef("NonDocumentTypeChildNode")}}, </em>and {{DOMxRef("Animatable")}}.</p> + +<dl> + <dt>{{DOMxRef("Element.attributes")}} {{readOnlyInline}}</dt> + <dd>Returns a {{DOMxRef("NamedNodeMap")}} object containing the assigned attributes of the corresponding HTML element.</dd> + <dt>{{DOMxRef("Element.classList")}} {{readOnlyInline}}</dt> + <dd>Returns a {{DOMxRef("DOMTokenList")}} containing the list of class attributes.</dd> + <dt>{{DOMxRef("Element.className")}}</dt> + <dd>Is a {{DOMxRef("DOMString")}} representing the class of the element.</dd> + <dt>{{DOMxRef("Element.clientHeight")}} {{readOnlyInline}}</dt> + <dd>Returns a {{jsxref("Number")}} representing the inner height of the element.</dd> + <dt>{{DOMxRef("Element.clientLeft")}} {{readOnlyInline}}</dt> + <dd>Returns a {{jsxref("Number")}} representing the width of the left border of the element.</dd> + <dt>{{DOMxRef("Element.clientTop")}} {{readOnlyInline}}</dt> + <dd>Returns a {{jsxref("Number")}} representing the width of the top border of the element.</dd> + <dt>{{DOMxRef("Element.clientWidth")}} {{readOnlyInline}}</dt> + <dd>Returns a {{jsxref("Number")}} representing the inner width of the element.</dd> + <dt>{{DOMxRef("Element.computedName")}} {{readOnlyInline}}</dt> + <dd>Returns a {{DOMxRef("DOMString")}} containing the label exposed to accessibility.</dd> + <dt>{{DOMxRef("Element.computedRole")}} {{readOnlyInline}}</dt> + <dd>Returns a {{DOMxRef("DOMString")}} containing the ARIA role that has been applied to a particular element. </dd> + <dt>{{DOMxRef("Element.id")}}</dt> + <dd>Is a {{DOMxRef("DOMString")}} representing the id of the element.</dd> + <dt>{{DOMxRef("Element.innerHTML")}}</dt> + <dd>Is a {{DOMxRef("DOMString")}} representing the markup of the element's content.</dd> + <dt>{{DOMxRef("Element.localName")}} {{readOnlyInline}}</dt> + <dd>A {{DOMxRef("DOMString")}} representing the local part of the qualified name of the element.</dd> + <dt>{{DOMxRef("Element.namespaceURI")}} {{readonlyInline}}</dt> + <dd>The namespace URI of the element, or <code>null</code> if it is no namespace. + <div class="note"> + <p><strong>Note:</strong> In Firefox 3.5 and earlier, HTML elements are in no namespace. In later versions, HTML elements are in the <code><a class="linkification-ext external" href="http://www.w3.org/1999/xhtml" title="Linkification: http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a></code> namespace in both HTML and XML trees. {{ gecko_minversion_inline("1.9.2")}}</p> + </div> + </dd> + <dt>{{DOMxRef("NonDocumentTypeChildNode.nextElementSibling")}} {{readOnlyInline}}</dt> + <dd>Is an {{DOMxRef("Element")}}, the element immediately following the given one in the tree, or <code>null</code> if there's no sibling node.</dd> + <dt>{{DOMxRef("Element.outerHTML")}}</dt> + <dd>Is a {{DOMxRef("DOMString")}} representing the markup of the element including its content. When used as a setter, replaces the element with nodes parsed from the given string.</dd> + <dt>{{DOMxRef("Element.prefix")}} {{readOnlyInline}}</dt> + <dd>A {{DOMxRef("DOMString")}} representing the namespace prefix of the element, or <code>null</code> if no prefix is specified.</dd> + <dt>{{DOMxRef("NonDocumentTypeChildNode.previousElementSibling")}} {{readOnlyInline}}</dt> + <dd>Is a {{DOMxRef("Element")}}, the element immediately preceding the given one in the tree, or <code>null</code> if there is no sibling element.</dd> + <dt>{{DOMxRef("Element.scrollHeight")}} {{readOnlyInline}}</dt> + <dd>Returns a {{jsxref("Number")}} representing the scroll view height of an element.</dd> + <dt>{{DOMxRef("Element.scrollLeft")}}</dt> + <dd>Is a {{jsxref("Number")}} representing the left scroll offset of the element.</dd> + <dt>{{DOMxRef("Element.scrollLeftMax")}} {{Non-standard_Inline}} {{readOnlyInline}}</dt> + <dd>Returns a {{jsxref("Number")}} representing the maximum left scroll offset possible for the element.</dd> + <dt>{{DOMxRef("Element.scrollTop")}}</dt> + <dd>A {{jsxref("Number")}} representing number of pixels the top of the document is scrolled vertically.</dd> + <dt>{{DOMxRef("Element.scrollTopMax")}} {{Non-standard_Inline}} {{readOnlyInline}}</dt> + <dd>Returns a {{jsxref("Number")}} representing the maximum top scroll offset possible for the element.</dd> + <dt>{{DOMxRef("Element.scrollWidth")}} {{readOnlyInline}}</dt> + <dd>Returns a {{jsxref("Number")}} representing the scroll view width of the element.</dd> + <dt>{{DOMxRef("Element.shadowRoot")}}{{readOnlyInline}}</dt> + <dd>Returns the open shadow root that is hosted by the element, or null if no open shadow root is present.</dd> + <dt>{{DOMxRef("Element.openOrClosedShadowRoot")}} {{Non-standard_Inline}}{{readOnlyInline}}</dt> + <dd>Returns the shadow root that is hosted by the element, regardless if its open or closed. <strong>Available only to <a href="/en-US/docs/Mozilla/Add-ons/WebExtensions">WebExtensions</a>.</strong></dd> + <dt>{{DOMxRef("Element.slot")}} {{Experimental_Inline}}</dt> + <dd>Returns the name of the shadow DOM slot the element is inserted in.</dd> + <dt>{{DOMxRef("Element.tabStop")}} {{Non-standard_Inline}}</dt> + <dd>Is a {{jsxref("Boolean")}} indicating if the element can receive input focus via the tab key.</dd> + <dt>{{DOMxRef("Element.tagName")}} {{readOnlyInline}}</dt> + <dd>Returns a {{jsxref("String")}} with the name of the tag for the given element.</dd> + <dt>{{DOMxRef("Element.undoManager")}} {{Experimental_Inline}} {{readOnlyInline}}</dt> + <dd>Returns the {{DOMxRef("UndoManager")}} associated with the element.</dd> + <dt>{{DOMxRef("Element.undoScope")}} {{Experimental_Inline}}</dt> + <dd>Is a {{jsxref("Boolean")}} indicating if the element is an undo scope host, or not.</dd> +</dl> + +<div class="note"> +<p><strong>Note:</strong> DOM Level 3 defined <code>namespaceURI</code>, <code>localName</code> and <code>prefix</code> on the {{DOMxRef("Node")}} interface. In DOM4 they were moved to <code>Element</code>.</p> + +<p>This change is implemented in Chrome since version 46.0 and Firefox since version 48.0.</p> +</div> + +<h3 id="Properties_included_from_Slotable">Properties included from Slotable</h3> + +<p><em>The <code>Element</code> interface includes the following property, defined on the {{DOMxRef("Slotable")}} mixin.</em></p> + +<dl> + <dt>{{DOMxRef("Slotable.assignedSlot")}}{{readonlyInline}}</dt> + <dd>Returns a {{DOMxRef("HTMLSlotElement")}} representing the {{htmlelement("slot")}} the node is inserted in.</dd> +</dl> + +<h3 id="Handlers" name="Handlers">Event handlers</h3> + +<dl> + <dt>{{domxref("Element.onfullscreenchange")}}</dt> + <dd>An event handler for the {{event("fullscreenchange")}} event, which is sent when the element enters or exits full-screen mode. This can be used to watch both for successful expected transitions, but also to watch for unexpected changes, such as when your app is backgrounded.</dd> + <dt>{{domxref("Element.onfullscreenerror")}}</dt> + <dd>An event handler for the {{event("fullscreenerror")}} event, which is sent when an error occurs while attempting to change into full-screen mode.</dd> +</dl> + +<h4 id="Obsolete_event_handlers">Obsolete event handlers</h4> + +<dl> + <dt>{{DOMxRef("Element.onwheel")}}</dt> + <dd>Returns the event handling code for the {{Event("wheel")}} event. <strong>This is now implemented on {{DOMxRef("GlobalEventHandlers.onwheel", "GlobalEventHandlers")}}.</strong></dd> +</dl> + +<h2 id="Methods" name="Methods">Methods</h2> + +<p><em>Inherits methods from its parents {{DOMxRef("Node")}}, and its own parent, {{DOMxRef("EventTarget")}}<em>, and implements those of {{DOMxRef("ParentNode")}}, {{DOMxRef("ChildNode")}}<em>, {{DOMxRef("NonDocumentTypeChildNode")}}, </em></em>and {{DOMxRef("Animatable")}}.</em></p> + +<dl> + <dt>{{DOMxRef("EventTarget.addEventListener()")}}</dt> + <dd>Registers an event handler to a specific event type on the element.</dd> + <dt>{{DOMxRef("Element.attachShadow()")}}</dt> + <dd>Attatches a shadow DOM tree to the specified element and returns a reference to its {{DOMxRef("ShadowRoot")}}.</dd> + <dt>{{DOMxRef("Element.animate()")}} {{Experimental_Inline}}</dt> + <dd>A shortcut method to create and run an animation on an element. Returns the created Animation object instance.</dd> + <dt>{{DOMxRef("Element.closest()")}} {{Experimental_Inline}}</dt> + <dd>Returns the {{DOMxRef("Element")}} which is the closest ancestor of the current element (or the current element itself) which matches the selectors given in parameter.</dd> + <dt>{{DOMxRef("Element.createShadowRoot()")}} {{Non-standard_Inline}} {{Deprecated_Inline}}</dt> + <dd>Creates a <a href="/en-US/docs/Web/Web_Components/Shadow_DOM">shadow DOM</a> on on the element, turning it into a shadow host. Returns a {{DOMxRef("ShadowRoot")}}.</dd> + <dt>{{DOMxRef("Element.computedStyleMap()")}} {{Experimental_Inline}}</dt> + <dd>Returns a {{DOMxRef("StylePropertyMapReadOnly")}} interface which provides a read-only representation of a CSS declaration block that is an alternative to {{DOMxRef("CSSStyleDeclaration")}}.</dd> + <dt>{{DOMxRef("EventTarget.dispatchEvent()")}}</dt> + <dd>Dispatches an event to this node in the DOM and returns a {{jsxref("Boolean")}} that indicates whether no handler canceled the event.</dd> + <dt>{{DOMxRef("Element.getAnimations()")}} {{Experimental_Inline}}</dt> + <dd>Returns an array of Animation objects currently active on the element.</dd> + <dt>{{DOMxRef("Element.getAttribute()")}}</dt> + <dd>Retrieves the value of the named attribute from the current node and returns it as an {{jsxref("Object")}}.</dd> + <dt>{{DOMxRef("Element.getAttributeNames()")}}</dt> + <dd>Returns an array of attribute names from the current element.</dd> + <dt>{{DOMxRef("Element.getAttributeNS()")}}</dt> + <dd>Retrieves the value of the attribute with the specified name and namespace, from the current node and returns it as an {{jsxref("Object")}}.</dd> + <dt>{{DOMxRef("Element.getAttributeNode()")}} {{Obsolete_Inline}}</dt> + <dd>Retrieves the node representation of the named attribute from the current node and returns it as an {{DOMxRef("Attr")}}.</dd> + <dt>{{DOMxRef("Element.getAttributeNodeNS()")}} {{Obsolete_Inline}}</dt> + <dd>Retrieves the node representation of the attribute with the specified name and namespace, from the current node and returns it as an {{DOMxRef("Attr")}}.</dd> + <dt>{{DOMxRef("Element.getBoundingClientRect()")}}</dt> + <dd>Returns the size of an element and its position relative to the viewport.</dd> + <dt>{{DOMxRef("Element.getClientRects()")}}</dt> + <dd>Returns a collection of rectangles that indicate the bounding rectangles for each line of text in a client.</dd> + <dt>{{DOMxRef("Element.getElementsByClassName()")}}</dt> + <dd>Returns a live {{DOMxRef("HTMLCollection")}} that contains all descendants of the current element that possess the list of classes given in the parameter.</dd> + <dt>{{DOMxRef("Element.getElementsByTagName()")}}</dt> + <dd>Returns a live {{DOMxRef("HTMLCollection")}} containing all descendant elements, of a particular tag name, from the current element.</dd> + <dt>{{DOMxRef("Element.getElementsByTagNameNS()")}}</dt> + <dd>Returns a live {{DOMxRef("HTMLCollection")}} containing all descendant elements, of a particular tag name and namespace, from the current element.</dd> + <dt>{{DOMxRef("Element.hasAttribute()")}}</dt> + <dd>Returns a {{jsxref("Boolean")}} indicating if the element has the specified attribute or not.</dd> + <dt>{{DOMxRef("Element.hasAttributeNS()")}}</dt> + <dd>Returns a {{jsxref("Boolean")}} indicating if the element has the specified attribute, in the specified namespace, or not.</dd> + <dt>{{DOMxRef("Element.hasAttributes()")}}</dt> + <dd>Returns a {{jsxref("Boolean")}} indicating if the element has one or more HTML attributes present.</dd> + <dt>{{DOMxRef("Element.hasPointerCapture()")}}</dt> + <dd>Indicates whether the element on which it is invoked has pointer capture for the pointer identified by the given pointer ID.</dd> + <dt>{{DOMxRef("Element.insertAdjacentElement()")}}</dt> + <dd>Inserts a given element node at a given position relative to the element it is invoked upon.</dd> + <dt>{{DOMxRef("Element.insertAdjacentHTML()")}}</dt> + <dd>Parses the text as HTML or XML and inserts the resulting nodes into the tree in the position given.</dd> + <dt>{{DOMxRef("Element.insertAdjacentText()")}}</dt> + <dd>Inserts a given text node at a given position relative to the element it is invoked upon.</dd> + <dt>{{DOMxRef("Element.matches()")}} {{Experimental_Inline}}</dt> + <dd>Returns a {{jsxref("Boolean")}} indicating whether or not the element would be selected by the specified selector string.</dd> + <dt>{{DOMxRef("Element.querySelector()")}}</dt> + <dd>Returns the first {{DOMxRef("Node")}} which matches the specified selector string relative to the element.</dd> + <dt>{{DOMxRef("Element.querySelectorAll()")}}</dt> + <dd>Returns a {{DOMxRef("NodeList")}} of nodes which match the specified selector string relative to the element.</dd> + <dt>{{DOMxRef("Element.releasePointerCapture()")}}</dt> + <dd>Releases (stops) pointer capture that was previously set for a specific {{DOMxRef("PointerEvent","pointer event")}}.</dd> + <dt>{{DOMxRef("ChildNode.remove()")}} {{Experimental_Inline}}</dt> + <dd>Removes the element from the children list of its parent.</dd> + <dt>{{DOMxRef("Element.removeAttribute()")}}</dt> + <dd>Removes the named attribute from the current node.</dd> + <dt>{{DOMxRef("Element.removeAttributeNS()")}}</dt> + <dd>Removes the attribute with the specified name and namespace, from the current node.</dd> + <dt>{{DOMxRef("Element.removeAttributeNode()")}} {{Obsolete_Inline}}</dt> + <dd>Removes the node representation of the named attribute from the current node.</dd> + <dt>{{DOMxRef("EventTarget.removeEventListener()")}}</dt> + <dd>Removes an event listener from the element.</dd> + <dt>{{DOMxRef("Element.requestFullscreen()")}} {{Experimental_Inline}}</dt> + <dd>Asynchronously asks the browser to make the element full-screen.</dd> + <dt>{{DOMxRef("Element.requestPointerLock()")}} {{Experimental_Inline}}</dt> + <dd>Allows to asynchronously ask for the pointer to be locked on the given element.</dd> +</dl> + +<dl> + <dt>{{domxref("Element.scroll()")}}</dt> + <dd>Scrolls to a particular set of coordinates inside a given element.</dd> + <dt>{{domxref("Element.scrollBy()")}}</dt> + <dd>Scrolls an element by the given amount.</dd> + <dt>{{DOMxRef("Element.scrollIntoView()")}} {{Experimental_Inline}}</dt> + <dd>Scrolls the page until the element gets into the view.</dd> + <dt>{{domxref("Element.scrollTo()")}}</dt> + <dd>Scrolls to a particular set of coordinates inside a given element.</dd> + <dt>{{DOMxRef("Element.setAttribute()")}}</dt> + <dd>Sets the value of a named attribute of the current node.</dd> + <dt>{{DOMxRef("Element.setAttributeNS()")}}</dt> + <dd>Sets the value of the attribute with the specified name and namespace, from the current node.</dd> + <dt>{{DOMxRef("Element.setAttributeNode()")}} {{Obsolete_Inline}}</dt> + <dd>Sets the node representation of the named attribute from the current node.</dd> + <dt>{{DOMxRef("Element.setAttributeNodeNS()")}} {{Obsolete_Inline}}</dt> + <dd>Sets the node representation of the attribute with the specified name and namespace, from the current node.</dd> + <dt>{{DOMxRef("Element.setCapture()")}} {{Non-standard_Inline}}</dt> + <dd>Sets up mouse event capture, redirecting all mouse events to this element.</dd> + <dt>{{DOMxRef("Element.setPointerCapture()")}}</dt> + <dd>Designates a specific element as the capture target of future <a href="/en-US/docs/Web/API/Pointer_events">pointer events</a>.</dd> + <dt>{{DOMxRef("Element.toggleAttribute()")}}</dt> + <dd>Toggles a boolean attribute, removing it if it is present and adding it if it is not present, on the specified element.</dd> +</dl> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("Web Animations", '', '')}}</td> + <td>{{Spec2("Web Animations")}}</td> + <td>Added the <code>getAnimations()</code> method.</td> + </tr> + <tr> + <td>{{SpecName('Undo Manager', '', 'Element')}}</td> + <td>{{Spec2('Undo Manager')}}</td> + <td>Added the <code>undoScope</code> and <code>undoManager</code> properties.</td> + </tr> + <tr> + <td>{{SpecName('Pointer Events 2', '#extensions-to-the-element-interface', 'Element')}}</td> + <td>{{Spec2('Pointer Events 2')}}</td> + <td>Added the following event handlers: <code>ongotpointercapture</code> and <code>onlostpointercapture</code>.<br> + Added the following methods: <code>setPointerCapture()</code> and <code>releasePointerCapture()</code>.</td> + </tr> + <tr> + <td>{{SpecName('Pointer Events', '#extensions-to-the-element-interface', 'Element')}}</td> + <td>{{Spec2('Pointer Events')}}</td> + <td>Added the following event handlers: <code>ongotpointercapture</code> and <code>onlostpointercapture</code>.<br> + Added the following methods: <code>setPointerCapture()</code> and <code>releasePointerCapture()</code>.</td> + </tr> + <tr> + <td>{{SpecName('Selectors API Level 1', '#interface-definitions', 'Element')}}</td> + <td>{{Spec2('Selectors API Level 1')}}</td> + <td>Added the following methods: <code>querySelector()</code> and <code>querySelectorAll()</code>.</td> + </tr> + <tr> + <td>{{SpecName('Pointer Lock', 'index.html#element-interface', 'Element')}}</td> + <td>{{Spec2('Pointer Lock')}}</td> + <td>Added the <code>requestPointerLock()</code> method.</td> + </tr> + <tr> + <td>{{SpecName('Fullscreen', '#api', 'Element')}}</td> + <td>{{Spec2('Fullscreen')}}</td> + <td>Added the <code>requestFullscreen()</code> method.</td> + </tr> + <tr> + <td>{{SpecName('DOM Parsing', '#extensions-to-the-element-interface', 'Element')}}</td> + <td>{{Spec2('DOM Parsing')}}</td> + <td>Added the following properties: <code>innerHTML</code>, and <code>outerHTML</code>.<br> + Added the following method: <code>insertAdjacentHTML()</code>.</td> + </tr> + <tr> + <td>{{SpecName('CSSOM View', '#extensions-to-the-element-interface', 'Element')}}</td> + <td>{{Spec2('CSSOM View')}}</td> + <td>Added the following properties: <code>scrollTop</code>, <code>scrollLeft</code>, <code>scrollWidth</code>, <code>scrollHeight</code>, <code>clientTop</code>, <code>clientLeft</code>, <code>clientWidth</code>, and <code>clientHeight</code>.<br> + Added the following methods: <code>getClientRects()</code>, <code>getBoundingClientRect()</code>, <code>scroll()</code>, <code>scrollBy()</code>, <code>scrollTo()</code> and <code>scrollIntoView()</code>.</td> + </tr> + <tr> + <td>{{SpecName('Element Traversal', '#ecmascript-bindings', 'Element')}}</td> + <td>{{Spec2('Element Traversal')}}</td> + <td>Added inheritance of the {{DOMxRef("ElementTraversal")}} interface.</td> + </tr> + <tr> + <td>{{SpecName('DOM WHATWG', '#interface-element', 'Element')}}</td> + <td>{{Spec2('DOM WHATWG')}}</td> + <td>Added the following methods: <code>closest()</code>, <code>insertAdjacentElement()</code> and <code>insertAdjacentText()</code>.<br> + Moved <code>hasAttributes()</code> from the <code>Node</code> interface to this one.</td> + </tr> + <tr> + <td>{{SpecName("DOM4", "#interface-element", "Element")}}</td> + <td>{{Spec2("DOM4")}}</td> + <td>Removed the following methods: <code>setIdAttribute()</code>, <code>setIdAttributeNS()</code>, and <code>setIdAttributeNode()</code>.<br> + Modified the return value of <code>getElementsByTagName()</code> and <code>getElementsByTagNameNS()</code>.<br> + Removed the <code>schemaTypeInfo</code> property.</td> + </tr> + <tr> + <td>{{SpecName('DOM3 Core', 'core.html#ID-745549614', 'Element')}}</td> + <td>{{Spec2('DOM3 Core')}}</td> + <td>Added the following methods: <code>setIdAttribute()</code>, <code>setIdAttributeNS()</code>, and <code>setIdAttributeNode()</code>. These methods were never implemented and have been removed in later specifications.<br> + Added the <code>schemaTypeInfo</code> property. This property was never implemented and has been removed in later specifications.</td> + </tr> + <tr> + <td>{{SpecName('DOM2 Core', 'core.html#ID-745549614', 'Element')}}</td> + <td>{{Spec2('DOM2 Core')}}</td> + <td>The <code>normalize()</code> method has been moved to {{DOMxRef("Node")}}.</td> + </tr> + <tr> + <td>{{SpecName('DOM1', 'level-one-core.html#ID-745549614', 'Element')}}</td> + <td>{{Spec2('DOM1')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.Element")}}</p> diff --git a/files/fa/web/api/gamepadevent/index.html b/files/fa/web/api/gamepadevent/index.html new file mode 100644 index 0000000000..292215959f --- /dev/null +++ b/files/fa/web/api/gamepadevent/index.html @@ -0,0 +1,64 @@ +--- +title: GamepadEvent +slug: Web/API/GamepadEvent +translation_of: Web/API/GamepadEvent +--- +<pre class="syntaxbox notranslate">{{APIRef("Gamepad API")}}</pre> + +<p>The GamepadEvent interface of the Gamepad API contains references to gamepads connected to the system, which is what the gamepad events {{domxref("Window.gamepadconnected")}} and {{domxref("Window.gamepaddisconnected")}} are fired in response to.</p> + +<h2 id="Constructor">Constructor</h2> + +<dl> + <dt>{{domxref("GamepadEvent.GamepadEvent","GamepadEvent()")}}</dt> + <dd>Returns a new <code>GamepadEvent</code> object.</dd> +</dl> + +<h2 id="Properties">Properties</h2> + +<dl> + <dt>{{ domxref("GamepadEvent.gamepad") }} {{readonlyInline}}</dt> + <dd>Returns a {{ domxref("Gamepad") }} object, providing access to the associated gamepad data for the event fired.</dd> +</dl> + +<h2 id="Examples">Examples</h2> + +<p>The gamepad property being called on a fired {{domxref("Window.gamepadconnected")}} event.</p> + +<pre class="brush: js notranslate">window.addEventListener("gamepadconnected", function(e) { + console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.", + e.gamepad.index, e.gamepad.id, + e.gamepad.buttons.length, e.gamepad.axes.length); +});</pre> + +<p>And on a {{domxref("Window.gamepaddisconnected")}} event.</p> + +<pre class="brush: js notranslate">window.addEventListener("gamepaddisconnected", function(e) { + console.log("Gamepad disconnected from index %d: %s", + e.gamepad.index, e.gamepad.id); +});</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName("Gamepad", "#gamepadevent-interface", "GamepadEvent")}}</td> + <td>{{Spec2("Gamepad")}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2> + +<p>{{Compat("api.GamepadEvent")}}</p> + +<h2 id="See_also">See also</h2> + +<p><a href="/en-US/docs/Web/Guide/API/Gamepad">Using the Gamepad API</a></p> diff --git a/files/fa/web/api/index.html b/files/fa/web/api/index.html new file mode 100644 index 0000000000..1feb708b20 --- /dev/null +++ b/files/fa/web/api/index.html @@ -0,0 +1,13 @@ +--- +title: Web APIs +slug: Web/API +tags: + - API + - JavaScript + - Reference + - Web +translation_of: Web/API +--- +<p dir="rtl">در هنگام نوشتن کد برای برنامه های تحت وب به وسیله جاواسکریپت API های بسیار زیادی وجود دارند. در زیر لیستی از تمام رابط ها که شما ممکن است در هنگام توسعه برنامه های وب ویا سایت های خودتان بخواهید از آنها استفاده کنید موجود است.</p> + +<div>{{APIListAlpha}} </div> diff --git a/files/fa/web/api/mediatrackconstraints/index.html b/files/fa/web/api/mediatrackconstraints/index.html new file mode 100644 index 0000000000..11f3c9e37f --- /dev/null +++ b/files/fa/web/api/mediatrackconstraints/index.html @@ -0,0 +1,264 @@ +--- +title: MediaTrackConstraints +slug: Web/API/MediaTrackConstraints +translation_of: Web/API/MediaTrackConstraints +--- +<div><font><font>{{APIRef ("ضبط رسانه و جریان")}}</font></font></div> + +<p><strong><code>MediaTrackConstraints</code></strong><font><font>فرهنگ لغت استفاده می شود برای توصیف مجموعه ای از قابلیت ها و ارزش یا ارزش هر یک می تواند در را. </font><font>یک فرهنگ لغت محدودیتی به {{domxref ("MediaStreamTrack.applyConstraints"، "applyConstraints ()")}}}} منتقل می شود تا یک اسکریپت بتواند مجموعه ای از مقادیر یا محدوده دقیق (موردنیاز) یا مقادیر یا محدوده های مورد نظر برای مسیر و مجموعه اخیر محدودیت های سفارشی درخواست شده توسط {{domxref ("MediaStreamTrack.getConstraints"، "getConstraints ()")}}} بازیابی می شود.</font></font></p> + +<p><font><font>برای هر محدودیت، می توانید به طور معمول مقدار دقیق مورد نیاز خود را، ارزش ایده آل که می خواهید، محدوده ای از مقادیر قابل قبول و / یا یک مقدار که می خواهید تا حد ممکن نزدیک باشد، مشخص کنید. </font><font>خصوصیات بسته به نوع ملک محدود می شود.</font></font></p> + +<p>To learn more about how constraints work, see <a href="/en-US/docs/Web/API/Media_Streams_API/Constraints">Capabilities, constraints, and settings</a>.</p> + +<h2 id="Properties">Properties</h2> + +<p>Some combination—but not necessarily all—of the following properties will exist on the object.</p> + +<h3 id="Properties_of_all_media_tracks">Properties of all media tracks</h3> + +<dl> + <dt>{{domxref("MediaTrackConstraints.deviceId", "deviceId")}}</dt> + <dd>A {{domxref("ConstrainDOMString")}} object specifying a device ID or an array of device IDs which are acceptable and/or required.</dd> + <dt>{{domxref("MediaTrackConstraints.groupId", "groupId")}}</dt> + <dd>A {{domxref("ConstrainDOMString")}} object specifying a group ID or an array of group IDs which are acceptable and/or required.</dd> +</dl> + +<h3 id="Properties_of_audio_tracks">Properties of audio tracks</h3> + +<dl> + <dt>{{domxref("MediaTrackConstraints.autoGainControl", "autoGainControl")}}</dt> + <dd>A {{domxref("ConstrainBoolean")}} object which specifies whether automatic gain control is preferred and/or required.</dd> + <dt>{{domxref("MediaTrackConstraints.channelCount", "channelCount")}}</dt> + <dd>A {{domxref("ConstrainLong")}} specifying the channel count or range of channel counts which are acceptable and/or required.</dd> + <dt>{{domxref("MediaTrackConstraints.echoCancellation", "echoCancellation")}}</dt> + <dd>A {{domxref("ConstrainBoolean")}} object specifying whether or not echo cancellation is preferred and/or required.</dd> + <dt>{{domxref("MediaTrackConstraints.latency", "latency")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} specifying the latency or range of latencies which are acceptable and/or required.</dd> + <dt>{{domxref("MediaTrackConstraints.noiseSuppression", "noiseSuppression")}}</dt> + <dd>A {{domxref("ConstrainBoolean")}} which specifies whether noise suppression is preferred and/or required.</dd> + <dt>{{domxref("MediaTrackConstraints.sampleRate", "sampleRate")}}</dt> + <dd>A {{domxref("ConstrainLong")}} specifying the sample rate or range of sample rates which are acceptable and/or required.</dd> + <dt>{{domxref("MediaTrackConstraints.sampleSize", "sampleSize")}}</dt> + <dd>A {{domxref("ConstrainLong")}} specifying the sample size or range of sample sizes which are acceptable and/or required.</dd> + <dt>{{domxref("MediaTrackConstraints.volume", "volume")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} specifying the volume or range of volumes which are acceptable and/or required.</dd> +</dl> + +<h3 id="Properties_of_image_tracks">Properties of image tracks</h3> + +<dl> + <dt>{{domxref("MediaTrackConstraints.whiteBalanceMode","whiteBalanceMode")}}</dt> + <dd>A {{jsxref("String")}} specifying one of <code>"none"</code>, <code>"manual"</code>, <code>"sigle-shot"</code>, or <code>"continuous"</code>.</dd> + <dt>{{domxref("MediaTrackConstraints.exposureMode","exposureMode")}}</dt> + <dd>A {{jsxref("String")}} specifying one of <code>"none"</code>, <code>"manual"</code>, <code>"sigle-shot"</code>, or <code>"continuous"</code>.</dd> + <dt>{{domxref("MediaTrackConstraints.focusMode","focusMode")}}</dt> + <dd>A {{jsxref("String")}} specifying one of <code>"none"</code>, <code>"manual"</code>, <code>"sigle-shot"</code>, or <code>"continuous"</code>.</dd> + <dt>{{domxref("MediaTrackConstraints.pointsOfInterest","pointsOfInterest")}}</dt> + <dd>The pixel coordinates on the sensor of one or more points of interest. This is either an object in the form { x:<em>value</em>, y:<em>value</em> } or an array of such objects, where <em>value </em> is a double-precision integer.</dd> + <dt>{{domxref("MediaTrackConstraints.expsureCompensation","exposureCompensation")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying f-stop adjustment by up to ±3. </dd> + <dt>{{domxref("MediaTrackConstraints.colorTemperature","colorTemperature")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying a desired color temperature in degrees kelvin.</dd> + <dt>{{domxref("MediaTrackConstraints.iso","iso")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying a desired iso setting.</dd> + <dt>{{domxref("MediaTrackConstraints.brightness","brightness")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying a desired brightness setting.</dd> + <dt>{{domxref("MediaTrackConstraints.contrast","contrast")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying the degree of difference between light and dark.</dd> + <dt>{{domxref("MediaTrackConstraints.saturation","saturation")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying the degree of color intensity.</dd> + <dt>{{domxref("MediaTrackConstraints.sharpness","sharpness")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying the intensity of edges.</dd> + <dt>{{domxref("MediaTrackConstraints.focusDistance","focusDistance")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying distance to a focused object.</dd> + <dt>{{domxref("MediaTrackConstraints.zoom","zoom")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying the desired focal length.</dd> + <dt>{{domxref("MediaTrackConstraints.torch","torch")}}</dt> + <dd>A {{jsxref("Boolean")}} whter the fill light continuously connected, meaning it stays on as long as the track is active.</dd> +</dl> + +<h3 id="Properties_of_video_tracks">Properties of video tracks</h3> + +<dl> + <dt>{{domxref("MediaTrackConstraints.aspectRatio", "aspectRatio")}}</dt> + <dd>A {{domxref("ConstrainDouble")}} specifying the video aspect ratio or range of aspect ratios which are acceptable and/or required.</dd> + <dt>{{domxref("MediaTrackConstraints.facingMode", "facingMode")}}</dt> + <dd>A {{domxref("ConstrainDOMString")}} object specifying a facing or an array of facings which are acceptable and/or required.</dd> + <dt>{{domxref("MediaTrackConstraints.frameRate", "frameRate")}}</dt> + <dd><font><font>A {{domxref ("ConstrainDouble")}} تعیین نرخ فریم یا دامنه نرخ فریم که قابل قبول و / یا مورد نیاز است.</font></font></dd> + <dt><font><font>{{domxref ("MediaTrackConstraints.height"، "height")}}</font></font></dt> + <dd><font><font>A {{domxref ("ConstrainLong")}} تعیین ارتفاع ویدیو یا محدوده ارتفاع که قابل قبول و / یا مورد نیاز است.</font></font></dd> + <dt><font><font>{{domxref ("MediaTrackConstraints.width"، "width")}}</font></font></dt> + <dd><font><font>A {{domxref ("ConstrainLong")}} مشخص کردن عرض ویدئو یا طیف وسیعی از عرض که قابل قبول و / یا مورد نیاز است.</font></font></dd> +</dl> + +<h2 id="مشخصات_فنی"><font><font>مشخصات فنی</font></font></h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col"><font><font>مشخصات</font></font></th> + <th scope="col"><font><font>وضعیت</font></font></th> + <th scope="col"><font><font>اظهار نظر</font></font></th> + </tr> + <tr> + <td><font><font>{{SpecName ('Media Capture'، '# dom-mediatrackconstraints'، 'applyConstraints ()')}}</font></font></td> + <td><font><font>{{Spec2 ('رسانه ضبط')}}</font></font></td> + <td><font><font>تعریف اولیه</font></font></td> + </tr> + <tr> + <td><font><font>{{SpecName ('MediaStream تصویر'، '# mediatrackconstraintset-section'، 'applyConstraints ()')}}</font></font></td> + <td><font><font>{{Spec2 ('MediaStream Image')}}</font></font></td> + <td><font><font>محدودیت های تصویر را اضافه می کند.</font></font></td> + </tr> + </tbody> +</table> + +<h2 id="سازگاری_مرورگر"><font><font>سازگاری مرورگر</font></font></h2> + +<p><font><font>{{CompatibilityTable}}</font></font></p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th><font><font>ویژگی</font></font></th> + <th><font><font>کروم</font></font></th> + <th><font><font>فایرفاکس (Gecko)</font></font></th> + <th><font><font>اینترنت اکسپلورر</font></font></th> + <th><font><font>اپرا</font></font></th> + <th><font><font>سافاری</font></font></th> + </tr> + <tr> + <td><font><font>پشتیبانی پایه</font></font></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatOpera (46)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><code>deviceId</code></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatOpera (46)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><code>groupId</code></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatOpera (46)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>خواص آهنگ صوتی</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>خواص مسیر تصویر</font></font></td> + <td><font><font>{{CompatChrome (63)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatOpera (50)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>خواص آهنگ های ویدئویی</font></font></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatOpera (46)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th><font><font>ویژگی</font></font></th> + <th><font><font>Android Webview</font></font></th> + <th><font><font>Chrome برای آندروید</font></font></th> + <th><font><font>فایرفاکس موبایل (Gecko)</font></font></th> + <th><font><font>اینترنت اکسپلورر</font></font></th> + <th><font><font>اپرا موبایل</font></font></th> + <th><font><font>سافاری موبایل</font></font></th> + </tr> + <tr> + <td><font><font>پشتیبانی پایه</font></font></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatOperaMobile (46)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><code>deviceId</code></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatOperaMobile (46)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><code>groupId</code></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatOperaMobile (46)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>خواص آهنگ صوتی</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>خواص مسیر تصویر</font></font></td> + <td><font><font>{{CompatChrome (63)}}</font></font></td> + <td><font><font>{{CompatChrome (63)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatOperaMobile (50)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>خواص آهنگ های ویدئویی</font></font></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatChrome (59)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatOperaMobile (46)}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + </tbody> +</table> +</div> + +<h2 id="همچنین_نگاه_کنید"><font><font>همچنین نگاه کنید</font></font></h2> + +<ul> + <li><font><font>{{domxref ("MediaDevices.getUserMedia ()")}}</font></font></li> + <li><font><font>{{domxref ("MediaStreamTrack.getConstraints ()")}}</font></font></li> + <li><font><font>{{domxref ("MediaStreamTrack.applyConstraints ()")}}</font></font></li> + <li><font><font>{{domxref ("MediaDevices.getSupportedConstraints ()")}}</font></font></li> + <li><font><font>{{domxref ("MediaTrackSupportedConstraints")}}</font></font></li> + <li><font><font>{{domxref ("MediaStreamTrack.getSettings ()")}}</font></font></li> +</ul> diff --git a/files/fa/web/api/node/index.html b/files/fa/web/api/node/index.html new file mode 100644 index 0000000000..0d23b9445d --- /dev/null +++ b/files/fa/web/api/node/index.html @@ -0,0 +1,373 @@ +--- +title: Node +slug: Web/API/Node +tags: + - API + - DOM + - DOM Reference + - NeedsTranslation + - Reference + - TopicStub + - WebAPI +translation_of: Web/API/Node +--- +<div>{{APIRef("DOM")}}</div> + +<p>A <strong><code>Node</code></strong> is an interface from which a number of DOM types inherit, and allows these various types to be treated (or tested) similarly.</p> + +<p>The following interfaces all inherit from <code>Node</code> its methods and properties: {{domxref("Document")}}, {{domxref("Element")}}, {{domxref("CharacterData")}} (which {{domxref("Text")}}, {{domxref("Comment")}}, and {{domxref("CDATASection")}} inherit), {{domxref("ProcessingInstruction")}}, {{domxref("DocumentFragment")}}, {{domxref("DocumentType")}}, {{domxref("Notation")}}, {{domxref("Entity")}}, {{domxref("EntityReference")}}</p> + +<p>These interfaces may return null in particular cases where the methods and properties are not relevant. They may throw an exception - for example when adding children to a node type for which no children can exist.</p> + +<h2 id="Properties">Properties</h2> + +<p><em>Inherits properties from its parents {{domxref("EventTarget")}}</em>.<sup>[1]</sup></p> + +<dl> + <dt>{{domxref("Node.baseURI")}} {{readonlyInline}}</dt> + <dd>Returns a {{domxref("DOMString")}} representing the base URL. The concept of base URL changes from one language to another; in HTML, it corresponds to the protocol, the domain name and the directory structure, that is all until the last <code>'/'</code>.</dd> + <dt>{{domxref("Node.baseURIObject")}} {{Non-standard_inline()}} {{ Fx_minversion_inline("3") }}</dt> + <dd>(Not available to web content.) The read-only {{ Interface("nsIURI") }} object representing the base URI for the element.</dd> + <dt>{{domxref("Node.childNodes")}} {{readonlyInline}}</dt> + <dd>Returns a live {{domxref("NodeList")}} containing all the children of this node. {{domxref("NodeList")}} being live means that if the children of the <code>Node</code> change, the {{domxref("NodeList")}} object is automatically updated.</dd> + <dt>{{domxref("Node.firstChild")}} {{readonlyInline}}</dt> + <dd>Returns a {{domxref("Node")}} representing the first direct child node of the node, or <code>null</code> if the node has no child.</dd> + <dt>{{domxref("Node.lastChild")}} {{readonlyInline}}</dt> + <dd>Returns a {{domxref("Node")}} representing the last direct child node of the node, or <code>null</code> if the node has no child.</dd> + <dt>{{domxref("Node.localName")}} {{obsolete_inline}}{{readonlyInline}}</dt> + <dd>Returns a {{domxref("DOMString")}} representing the local part of the qualified name of an element. In Firefox 3.5 and earlier, the property upper-cases the local name for HTML elements (but not XHTML elements). In later versions, this does not happen, so the property is in lower case for both HTML and XHTML. {{ gecko_minversion_inline("1.9.2") }}<br> + Though recent specifications require <code>localName</code> to be defined on the {{domxref("Element")}} interface, Gecko-based browsers still implement it on the {{domxref("Node")}} interface.</dd> + <dt>{{domxref("Node.namespaceURI")}} {{obsolete_inline}}{{readonlyInline}}</dt> + <dd>The namespace URI of this node, or <code>null</code> if it is no namespace. In Firefox 3.5 and earlier, HTML elements are in no namespace. In later versions, HTML elements are in the <code><a class="linkification-ext external" href="http://www.w3.org/1999/xhtml" title="Linkification: http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a></code> namespace in both HTML and XML trees. {{ gecko_minversion_inline("1.9.2") }}<br> + Though recent specifications require <code>namespaceURI</code> to be defined on the {{domxref("Element")}} interface, Gecko-based browsers still implement it on the {{domxref("Node")}} interface.</dd> + <dt>{{domxref("Node.nextSibling")}} {{readonlyInline}}</dt> + <dd>Returns a {{domxref("Node")}} representing the next node in the tree, or <code>null</code> if there isn't such node.</dd> + <dt>{{domxref("Node.nodeName")}} {{readonlyInline}}</dt> + <dd>Returns a {{domxref("DOMString")}} containing the name of the <code>Node</code>. The structure of the name will differ with the name type. E.g. An {{domxref("HTMLElement")}} will contain the name of the corresponding tag, like <code>'audio'</code> for an {{domxref("HTMLAudioElement")}}, a {{domxref("Text")}} node will have the <code>'#text'</code> string, or a {{domxref("Document")}} node will have the <code>'#document'</code> string.</dd> + <dt>{{domxref("Node.nodePrincipal")}} {{Non-standard_inline()}}{{ Fx_minversion_inline("3") }}</dt> + <dd>A {{ Interface("nsIPrincipal") }} representing the node principal.</dd> + <dt>{{domxref("Node.nodeType")}}{{readonlyInline}}</dt> + <dd>Returns an <code>unsigned short</code> representing the type of the node. Possible values are: + <table class="standard-table"> + <tbody> + <tr> + <th scope="col">Name</th> + <th scope="col">Value</th> + </tr> + <tr> + <td><code>ELEMENT_NODE</code></td> + <td><code>1</code></td> + </tr> + <tr> + <td><code>ATTRIBUTE_NODE</code> {{deprecated_inline()}}</td> + <td><code>2</code></td> + </tr> + <tr> + <td><code>TEXT_NODE</code></td> + <td><code>3</code></td> + </tr> + <tr> + <td><code>CDATA_SECTION_NODE</code> {{deprecated_inline()}}</td> + <td><code>4</code></td> + </tr> + <tr> + <td><code>ENTITY_REFERENCE_NODE</code> {{deprecated_inline()}}</td> + <td><code>5</code></td> + </tr> + <tr> + <td><code>ENTITY_NODE</code> {{deprecated_inline()}}</td> + <td><code>6</code></td> + </tr> + <tr> + <td><code>PROCESSING_INSTRUCTION_NODE</code></td> + <td><code>7</code></td> + </tr> + <tr> + <td><code>COMMENT_NODE</code></td> + <td><code>8</code></td> + </tr> + <tr> + <td><code>DOCUMENT_NODE</code></td> + <td><code>9</code></td> + </tr> + <tr> + <td><code>DOCUMENT_TYPE_NODE</code></td> + <td><code>10</code></td> + </tr> + <tr> + <td><code>DOCUMENT_FRAGMENT_NODE</code></td> + <td><code>11</code></td> + </tr> + <tr> + <td><code>NOTATION_NODE</code> {{deprecated_inline()}}</td> + <td><code>12</code></td> + </tr> + </tbody> + </table> + </dd> + <dt>{{domxref("Node.nodeValue")}}</dt> + <dd>Is a {{domxref("DOMString")}} representing the value of an object. For most <code>Node</code> types, this returns <code>null</code> and any set operation is ignored. For nodes of type <code>TEXT_NODE</code> ({{domxref("Text")}} objects), <code>COMMENT_NODE</code> ({{domxref("Comment")}} objects), and <code>PROCESSING_INSTRUCTION_NODE</code> ({{domxref("ProcessingInstruction")}} objects), the value corresponds to the text data contained in the object.</dd> + <dt>{{domxref("Node.ownerDocument")}} {{readonlyInline}}</dt> + <dd>Returns the {{domxref("Document")}} that this node belongs to. If no document is associated with it, returns <code>null</code>.</dd> + <dt>{{domxref("Node.parentNode")}} {{readonlyInline}}</dt> + <dd>Returns a {{domxref("Node")}} that is the parent of this node. If there is no such node, like if this node is the top of the tree or if doesn't participate in a tree, this property returns <code>null</code>.</dd> + <dt>{{domxref("Node.parentElement")}} {{readonlyInline}}</dt> + <dd>Returns an {{domxref("Element")}} that is the parent of this node. If the node has no parent, or if that parent is not an {{domxref("Element")}}, this property returns <code>null</code>.</dd> + <dt>{{domxref("Node.prefix")}} {{obsolete_inline}}{{readonlyInline}}</dt> + <dd>Is a {{domxref("DOMString")}} representing the namespace prefix of the node, or <code>null</code> if no prefix is specified.<br> + Though recent specifications require <code>prefix</code> to be defined on the {{domxref("Element")}} interface, Gecko-based browsers still implement it on the {{domxref("Node")}} interface.</dd> + <dt>{{domxref("Node.previousSibling")}} {{readonlyInline}}</dt> + <dd>Returns a {{domxref("Node")}} representing the previous node in the tree, or <code>null</code> if there isn't such node.</dd> + <dt>{{domxref("Node.textContent")}}</dt> + <dd>Is a {{domxref("DOMString")}} representing the textual content of an element and all its descendants.</dd> +</dl> + +<h2 id="Methods">Methods</h2> + +<p><em>Inherits methods from its parents {{domxref("EventTarget")}}</em>.<sup>[1]</sup></p> + +<dl> + <dt>{{domxref("Node.appendChild()")}}</dt> + <dd>Insert a {{domxref("Node")}} as the last child node of this element.</dd> + <dt>{{domxref("Node.cloneNode()")}}</dt> + <dd>Clone a {{domxref("Node")}}, and optionally, all of its contents. By default, it clones the content of the node.</dd> + <dt>{{domxref("Node.compareDocumentPosition()")}}</dt> + <dd> </dd> + <dt>{{domxref("Node.contains()")}}</dt> + <dd> </dd> + <dt>{{domxref("Node.getFeature()")}} {{obsolete_inline}}</dt> + <dd>...</dd> + <dt>{{domxref("Node.getUserData()")}} {{obsolete_inline}}</dt> + <dd>Allows a user to get some {{domxref("DOMUserData")}} from the node.</dd> + <dt>{{domxref("Node.hasAttributes()")}} {{obsolete_inline}}</dt> + <dd>Returns a {{domxref("Boolean")}} indicating if the element has any attributes, or not.</dd> + <dt>{{domxref("Node.hasChildNodes()")}}</dt> + <dd>Returns a {{domxref("Boolean")}} indicating if the element has any child nodes, or not.</dd> + <dt>{{domxref("Node.insertBefore()")}}</dt> + <dd>Inserts the first {{domxref("Node")}} given in a parameter immediately before the second, child of this element, {{domxref("Node")}}.</dd> + <dt>{{domxref("Node.isDefaultNamespace()")}}</dt> + <dd> </dd> + <dt>{{domxref("Node.isEqualNode()")}}</dt> + <dd> </dd> + <dt>{{domxref("Node.isSameNode()")}} {{obsolete_inline}}</dt> + <dd> </dd> + <dt>{{domxref("Node.isSupported()")}} {{obsolete_inline}}</dt> + <dd>Returns a <a href="https://developer.mozilla.org/en-US/docs/Web/API/Boolean" title="The Boolean object is an object wrapper for a boolean value."><code>Boolean</code></a> flag containing the result of a test whether the DOM implementation implements a specific feature and this feature is supported by the specific node.</dd> + <dt>{{domxref("Node.lookupPrefix()")}}</dt> + <dd> </dd> + <dt>{{domxref("Node.lookupNamespaceURI()")}}</dt> + <dd> </dd> + <dt>{{domxref("Node.normalize()")}}</dt> + <dd>Clean up all the text nodes under this element (merge adjacent, remove empty).</dd> + <dt>{{domxref("Node.removeChild()")}}</dt> + <dd>Removes a child node from the current element, which must be a child of the current node.</dd> + <dt>{{domxref("Node.replaceChild()")}}</dt> + <dd>Replaces one child {{domxref("Node")}} of the current one with the second one given in parameter.</dd> + <dt>{{domxref("Node.setUserData()")}} {{obsolete_inline}}</dt> + <dd>Allows a user to attach, or remove, {{domxref("DOMUserData")}} to the node.</dd> + <dd> </dd> +</dl> + +<h2 id="Examples">Examples</h2> + +<h3 id="Browse_all_child_nodes">Browse all child nodes</h3> + +<p>The following function recursively cycles all child nodes of a node and executes a callback function upon them (and upon the parent node itself).</p> + +<pre class="brush: js">function DOMComb (oParent, oCallback) { + if (oParent.hasChildNodes()) { + for (var oNode = oParent.firstChild; oNode; oNode = oNode.nextSibling) { + DOMComb(oNode, oCallback); + } + } + oCallback.call(oParent); +}</pre> + +<h4 id="Syntax">Syntax</h4> + +<pre>DOMComb(parentNode, callbackFunction);</pre> + +<h4 id="Description">Description</h4> + +<p>Recursively cycle all child nodes of <code>parentNode</code> and <code>parentNode</code> itself and execute the <code>callbackFunction</code> upon them as <a href="/en-US/docs/JavaScript/Reference/Operators/this" title="en-US/docs/JavaScript/Reference/Operators/this"><code>this</code></a> objects.</p> + +<h4 id="Parameters">Parameters</h4> + +<dl> + <dt><code>parentNode</code></dt> + <dd>The parent node (<code><strong>Node</strong> <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object" title="en-US/docs/JavaScript/Reference/Global_Objects/Object">Object</a></code>).</dd> + <dt><code>callbackFunction</code></dt> + <dd>The callback function (<a href="/en-US/docs/JavaScript/Reference/Global_Objects/Function" title="en-US/docs/JavaScript/Reference/Global_Objects/Function"><code>Function</code></a>).</dd> +</dl> + +<h4 id="Sample_usage">Sample usage</h4> + +<p>The following example send to the <code>console.log</code> the text content of the body:</p> + +<pre class="brush: js">function printContent () { + if (this.nodeValue) { console.log(this.nodeValue); } +} + +onload = function () { + DOMComb(document.body, printContent); +};</pre> + +<h3 id="Remove_all_children_nested_within_a_node">Remove all children nested within a node</h3> + +<pre class="brush: js">Element.prototype.removeAll = function () { + while (this.firstChild) { this.removeChild(this.firstChild); } + return this; +};</pre> + +<h4 id="Sample_usage_2">Sample usage</h4> + +<pre class="brush: js">/* ... an alternative to document.body.innerHTML = "" ... */ +document.body.removeAll();</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('DOM WHATWG', '#interface-node', 'Node')}}</td> + <td>{{Spec2('DOM WHATWG')}}</td> + <td>Removed the following properties: <code>attributes</code>, <code>namespaceURI</code>, <code>prefix</code>, and <code>localName</code>.<br> + Removed the following methods: <code>isSupported()</code>, <code>hasAttributes()</code>, <code>isSameNode()</code>, <code>getFeature()</code>, <code>setUserData()</code>, and <code>getUserData()</code>.</td> + </tr> + <tr> + <td>{{SpecName('DOM3 Core', 'core.html#ID-1950641247', 'Node')}}</td> + <td>{{Spec2('DOM3 Core')}}</td> + <td>The methods <code>insertBefore()</code>, <code>replaceChild()</code>, <code>removeChild()</code>, and <code>appendChild()</code> returns one more kind of error (<code>NOT_SUPPORTED_ERR</code>) if called on a {{domxref("Document")}}.<br> + The <code>normalize()</code> method has been modified so that {{domxref("Text")}} node can also be normalized if the proper {{domxref("DOMConfiguration")}} flag is set.<br> + Added the following methods: <code>compareDocumentPosition()</code>, <code>isSameNode()</code>, <code>lookupPrefix()</code>, <code>isDefaultNamespace()</code>, <code>lookupNamespaceURI()</code>, <code>isEqualNode()</code>, <code>getFeature()</code>, <code>setUserData()</code>, and <code>getUserData().</code><br> + Added the following properties: <code>baseURI</code> and <code>textContent</code>.</td> + </tr> + <tr> + <td>{{SpecName('DOM2 Core', 'core.html#ID-1950641247', 'Node')}}</td> + <td>{{Spec2('DOM2 Core')}}</td> + <td>The <code>ownerDocument</code> property was slightly modified so that {{domxref("DocumentFragment")}} also returns <code>null</code>.<br> + Added the following properties: <code>namespaceURI</code>, <code>prefix</code>, and <code>localName</code>.<br> + Added the following methods: <code>normalize()</code>, <code>isSupported()</code> and <code>hasAttributes()</code>.</td> + </tr> + <tr> + <td>{{SpecName('DOM1', 'level-one-core.html#ID-1950641247', 'Node')}}</td> + <td>{{Spec2('DOM1')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<p> </p> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("1.0")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + <tr> + <td><code>getFeature()</code>{{obsolete_inline}}</td> + <td>{{CompatNo}}</td> + <td>Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("6.0")}}.<br> + Removed in {{CompatGeckoDesktop("7.0")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + <tr> + <td><code>getUserData()</code>, <code>setUserData()</code> and <code>hasAttributes()</code> {{deprecated_inline}}</td> + <td>{{CompatNo}}</td> + <td>Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("21.0")}}.<br> + Removed in {{CompatGeckoDesktop("22.0")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + <tr> + <td><code>isSameNode()</code> {{obsolete_inline}}</td> + <td>{{CompatNo}}</td> + <td>Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("9.0")}}.<br> + Removed in {{CompatGeckoDesktop("10.0")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + <tr> + <td><code>isSupported()</code> {{obsolete_inline}}</td> + <td>{{CompatUnknown}}</td> + <td>Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("21.0")}}.<br> + Removed in {{CompatGeckoDesktop("22.0")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>attributes</code></td> + <td>{{CompatNo}}</td> + <td>Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("21.0")}}.<br> + Moved to {{domxref("Element")}} in {{CompatGeckoDesktop("22.0")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("1.0")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + <tr> + <td><code>getFeature()</code>{{obsolete_inline}}</td> + <td>{{CompatNo}}</td> + <td>Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("6.0")}}.<br> + Removed in {{CompatGeckoDesktop("7.0")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] Webkit and Blink incorrectly do not make <code>Node</code> inherit from {{domxref("EventTarget")}}.</p> diff --git a/files/fa/web/api/node/innertext/index.html b/files/fa/web/api/node/innertext/index.html new file mode 100644 index 0000000000..98dd0eed8f --- /dev/null +++ b/files/fa/web/api/node/innertext/index.html @@ -0,0 +1,75 @@ +--- +title: Node.innerText +slug: Web/API/Node/innerText +translation_of: Web/API/HTMLElement/innerText +--- +<div>{{APIRef("DOM")}}</div> + +<p>{{ Non-standard_header() }}</p> + +<h2 dir="rtl" id="گزیده">گزیده</h2> + +<p dir="rtl"><code><strong>Node.innerText </strong></code><span id="result_box" lang="fa">یک ویژگی غیر استاندارد است که نشان دهنده محتوای متن یک node و زیر گروه های آن است</span><span lang="fa"><span> به عنوان گیرنده متنی که کاربر می تواند با نشانگر موس از محتوا انتخاب و آن را کپی نماید.</span></span></p> + +<p dir="rtl">{{domxref("Node.textContent")}} <span id="result_box" lang="fa"><span>یک جایگزین</span> <span>استاندارد</span> <span>تا حدی شبیه</span> <span>است، اگر چه</span> <span>تفاوت های مهمی بین</span> <span>این دو وجود دارد</span><span>.</span></span></p> + +<h2 dir="rtl" id="ویژگی_ها">ویژگی ها</h2> + +<p dir="rtl"><span class="short_text" id="result_box" lang="fa"><span>یک</span> <span>پیش نویس</span> <span>غیر رسمی از</span> ویژگی ها در <strong><a dir="rtl" href="https://rocallahan.github.io/innerText-spec/">اینجا</a></strong> <span>موجود است.</span></span></p> + +<h2 dir="rtl" id="Browser_Compatibility" name="Browser_Compatibility">سازگاری با مرورگرها</h2> + +<p>{{ CompatibilityTable() }}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>پایه پشتیبانی</td> + <td>4</td> + <td>{{ CompatGeckoDesktop(45) }}</td> + <td>6</td> + <td>9.6 (شاید پیش از این)</td> + <td>3</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>پایه پشتیبانی</td> + <td>2.3 (شاید پیش از این)</td> + <td>{{ CompatGeckoMobile(45) }}</td> + <td>10 (شاید پیش از این)</td> + <td>12</td> + <td>4.1 (شاید پیش از این)</td> + </tr> + </tbody> +</table> +</div> + +<h2 dir="rtl" id="موارد_مرتبط">موارد مرتبط</h2> + +<ul> + <li>{{domxref("HTMLElement.outerText")}}</li> + <li>{{domxref("Element.innerHTML")}}</li> +</ul> diff --git a/files/fa/web/api/node/insertbefore/index.html b/files/fa/web/api/node/insertbefore/index.html new file mode 100644 index 0000000000..5e853fc373 --- /dev/null +++ b/files/fa/web/api/node/insertbefore/index.html @@ -0,0 +1,155 @@ +--- +title: Node.insertBefore() +slug: Web/API/Node/insertBefore +translation_of: Web/API/Node/insertBefore +--- +<div> +<div>Mojtaba iranpour {{APIRef("DOM")}}</div> +</div> + +<p>The <code><strong>Node.insertBefore()</strong></code> method inserts the specified node before a reference node as a child of the current node.</p> + +<h2 id="Syntax" name="Syntax">Syntax</h2> + +<pre class="syntaxbox">var <em>insertedNode</em> = <em>parentNode</em>.insertBefore(<em>newNode</em>, <em>referenceNode</em>); +</pre> + +<p>In Mozilla Firefox, if <code><var>referenceNode</var></code> is <code>null</code><span style="font-size: 14px; line-height: 1.5;">, </span><code><var>newNode</var></code><span style="font-size: 14px; line-height: 1.5;"> is inserted at the end of the list of child nodes. If the <code><em>referenceNode </em></code>is of <em><code>[ Type ]</code> "<code><em>undefined"</em> </code></em>( this kind of argument is <code>String</code> ) will be throw, in all of the browser ( IE, Chrome and Mozilla ) a "Type Error: Invalid Argument" since the the function </span><code>insertBefore </code>accept as second argument a<em><code> [ Type ] Node.</code></em></p> + +<h2 id="Example_2">Example</h2> + +<pre class="brush: html"><div id="parentElement"> + <span id="childElement">foo bar</span> +</div> + +<script> +//Create the new node to insert +var newNode = document.createElement("span"); + +//Get a reference to the parent node +var parentDiv = document.getElementById("parentElement").parentNode; + +//Begin test case [ 1 ] : Exist a childElement --> All working correctly +var sp2 = document.getElementById("childElement"); +parentDiv.insertBefore(newNode,sp2); +//End test case [ 1 ] + +//Begin test case [ 2 ] : childElement is of Type undefined +var sp2 = undefined; //Not exist a node of id "childElement" +parentDiv.insertBefore(newNode,sp2); //implicit dynamic cast to type Node +//End test case [ 2 ] + +//Begin test case [ 3 ] : childElement is of Type "undefined" ( string ) +var sp2 = "undefined"; //Not exist a node of id "childElement" +parentDiv.insertBefore(newNode,sp2); //Generate "Type Error: Invalid Argument" +//End test case [ 3 ] +</pre> + +<ul> + <li><code>insertedNode</code> The node being inserted, that is <code>newNode</code></li> + <li><code>parentNode</code> The parent of the newly inserted node.</li> + <li><code>newNode</code> The node to insert.</li> + <li><code>referenceNode</code> The node before which <code>newNode</code> is inserted.</li> +</ul> + +<h2 id="Example" name="Example">Example</h2> + +<pre class="brush:html"><div id="parentElement"> + <span id="childElement">foo bar</span> +</div> + +<script> +// Create a new, plain <span> element +var sp1 = document.createElement("span"); + +// Get a reference to the element, before we want to insert the element +var sp2 = document.getElementById("childElement"); +// Get a reference to the parent element +var parentDiv = sp2.parentNode; + +// Insert the new element into the DOM before sp2 +parentDiv.insertBefore(sp1, sp2); +</script> +</pre> + +<p>There is no <code>insertAfter</code> method. It can be emulated by combining the <code>insertBefore</code> method with <code><a href="/en-US/docs/DOM/Node.nextSibling" title="DOM/Node.nextSibling">nextSibling</a></code>.</p> + +<p>In the previous example, <code>sp1</code> could be inserted after <code>sp2</code> using:</p> + +<pre><code>parentDiv.insertBefore(sp1, sp2.nextSibling);</code></pre> + +<p>If <code>sp2</code> does not have a next sibling, then it must be the last child — <code>sp2.nextSibling</code> returns <code>null</code>, and <code>sp1</code> is inserted at the end of the child node list (immediately after <code>sp2</code>).</p> + +<h2 id="Example2" name="Example2">Example 2</h2> + +<p>Insert an element before the first child element, using the <a href="/en-US/docs/DOM/Node.firstChild" title="Node.firstChild">firstChild</a> property.</p> + +<pre class="brush:js">// Get a reference to the element in which we want to insert a new node +var parentElement = document.getElementById('parentElement'); +// Get a reference to the first child +var theFirstChild = parentElement.firstChild; + +// Create a new element +var newElement = document.createElement("div"); + +// Insert the new element before the first child +parentElement.insertBefore(newElement, theFirstChild); +</pre> + +<p>When the element does not have a first child, then <code>firstChild</code> is <code>null</code>. The element is still appended to the parent, after the last child. Since the parent element did not have a first child, it did not have a last child either. Consequently, the new element is the only element, after insertion.</p> + +<h2 id="Browser_Compatibility" name="Browser_Compatibility">Browser compatibility</h2> + +<p>{{CompatibilityTable()}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>1.0</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Specification" name="Specification">Specification</h2> + +<ul> + <li><a href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-952280727">insertBefore</a></li> +</ul> diff --git a/files/fa/web/api/node/isequalnode/index.html b/files/fa/web/api/node/isequalnode/index.html new file mode 100644 index 0000000000..9cc089f509 --- /dev/null +++ b/files/fa/web/api/node/isequalnode/index.html @@ -0,0 +1,88 @@ +--- +title: Node.isEqualNode() +slug: Web/API/Node/isEqualNode +translation_of: Web/API/Node/isEqualNode +--- +<div> +<div>{{APIRef("DOM")}}</div> +</div> + +<p>The <code><strong>Node.isEqualNode()</strong></code> method tests whether two nodes are equal. Two nodes are equal when they have the same type, defining characteristics (for elements, this would be their ID, number of children, and so forth), its attributes match, and so on. The specific set of data points that must match varies depending on the types of the nodes.</p> + +<h2 id="Syntax" name="Syntax">Syntax</h2> + +<pre class="syntaxbox">var <var>isEqualNode</var> = <var>node</var>.isEqualNode(<var>otherNode</var>); +</pre> + +<ul> + <li><code>otherNode</code>: The {{domxref("Node")}} to compare equality with.</li> +</ul> + +<h2 id="Example">Example</h2> + +<p>In this example, we create three {{HTMLElement("div")}} blocks. The first and third have the same contents and attributes, while the second is different. Then we run some JavaScript to compare the nodes using <code>isEqualNode()</code> and output the results.</p> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html"><div>This is the first element.</div> +<div>This is the second element.</div> +<div>This is the first element.</div> + +<p id="output"></p></pre> + +<div class="hidden"> +<h3 id="CSS">CSS</h3> + +<pre class="brush: css">#output { + width: 440px; + border: 2px solid black; + border-radius: 5px; + padding: 10px; + margin-top: 20px; + display: block; +}</pre> +</div> + +<h3 id="JavaScript">JavaScript</h3> + +<pre class="brush: js">let output = document.getElementById("output"); +let divList = document.getElementsByTagName("div"); + +output.innerHTML += "div 0 equals div 0: " + divList[0].isEqualNode(divList[0]) + "<br/>"; +output.innerHTML += "div 0 equals div 1: " + divList[0].isEqualNode(divList[1]) + "<br/>"; +output.innerHTML += "div 0 equals div 2: " + divList[0].isEqualNode(divList[2]) + "<br/>";</pre> + +<h3 id="Results">Results</h3> + +<p>{{ EmbedLiveSample('Example', 480) }}</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('DOM WHATWG', '#dom-node-isequalnode', 'Node.isEqualNode')}}</td> + <td>{{Spec2('DOM WHATWG')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.Node.isEqualNode")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{domxref("Node.isSameNode()")}}</li> +</ul> diff --git a/files/fa/web/api/notification/index.html b/files/fa/web/api/notification/index.html new file mode 100644 index 0000000000..42deb63eaa --- /dev/null +++ b/files/fa/web/api/notification/index.html @@ -0,0 +1,198 @@ +--- +title: Notification +slug: Web/API/notification +tags: + - API + - Interface + - NeedsTranslation + - Notifications + - Reference + - TopicStub +translation_of: Web/API/Notification +--- +<div>{{APIRef("Web Notifications")}}{{AvailableInWorkers}}{{securecontext_header}}</div> + +<p><span class="seoSummary">The <code>Notification</code> interface of the <a href="/en-US/docs/Web/API/Notifications_API">Notifications API</a> is used to configure and display desktop notifications to the user.</span> These notifications' appearance and specific functionality vary across platforms but generally they provide a way to asynchronously provide information to the user.</p> + +<h2 id="Constructor">Constructor</h2> + +<dl> + <dt>{{domxref("Notification.Notification", "Notification()")}}</dt> + <dd>Creates a new instance of the <code>Notification</code> object.</dd> +</dl> + +<h2 id="Properties">Properties</h2> + +<h3 id="Static_properties">Static properties</h3> + +<p>These properties are available only on the <code>Notification</code> object itself.</p> + +<dl> + <dt>{{domxref("Notification.permission")}} {{readonlyinline}}</dt> + <dd>A string representing the current permission to display notifications. Possible values are: + <ul> + <li><code>denied</code> — The user refuses to have notifications displayed.</li> + <li><code>granted</code> — The user accepts having notifications displayed.</li> + <li><code>default</code> — The user choice is unknown and therefore the browser will act as if the value were denied.</li> + </ul> + </dd> +</dl> + +<h3 id="Instance_properties">Instance properties</h3> + +<p>These properties are available only on instances of the <code>Notification</code> object.</p> + +<dl> + <dt>{{domxref("Notification.actions")}} {{readonlyinline}}</dt> + <dd>The actions array of the notification as specified in the constructor's <code>options</code> parameter.</dd> + <dt>{{domxref("Notification.badge")}} {{readonlyinline}}</dt> + <dd>The URL of the image used to represent the notification when there is not enough space to display the notification itself.</dd> + <dt>{{domxref("Notification.body")}} {{readonlyinline}}</dt> + <dd>The body string of the notification as specified in the constructor's <code>options</code> parameter.</dd> + <dt>{{domxref("Notification.data")}} {{readonlyinline}}</dt> + <dd>Returns a structured clone of the notification’s data.</dd> + <dt>{{domxref("Notification.dir")}} {{readonlyinline}}</dt> + <dd>The text direction of the notification as specified in the constructor's <code>options</code> parameter.</dd> + <dt>{{domxref("Notification.lang")}} {{readonlyinline}}</dt> + <dd>The language code of the notification as specified in the constructor's <code>options</code> parameter.</dd> + <dt>{{domxref("Notification.tag")}} {{readonlyinline}}</dt> + <dd>The ID of the notification (if any) as specified in the constructor's <code>options</code> parameter.</dd> + <dt>{{domxref("Notification.icon")}} {{readonlyinline}}</dt> + <dd>The URL of the image used as an icon of the notification as specified in the constructor's <code>options</code> parameter.</dd> + <dt>{{domxref("Notification.image")}} {{readonlyinline}}</dt> + <dd>The URL of an image to be displayed as part of the notification, as specified in the constructor's <code>options</code> parameter.</dd> + <dt>{{domxref("Notification.renotify")}} {{readonlyinline}}</dt> + <dd>Specifies whether the user should be notified after a new notification replaces an old one.</dd> + <dt>{{domxref("Notification.requireInteraction")}} {{readonlyinline}}</dt> + <dd>A {{jsxref("Boolean")}} indicating that a notification should remain active until the user clicks or dismisses it, rather than closing automatically.</dd> + <dt>{{domxref("Notification.silent")}} {{readonlyinline}}</dt> + <dd>Specifies whether the notification should be silent — i.e., no sounds or vibrations should be issued, regardless of the device settings.</dd> + <dt>{{domxref("Notification.timestamp")}} {{readonlyinline}}</dt> + <dd>Specifies the time at which a notification is created or applicable (past, present, or future).</dd> + <dt>{{domxref("Notification.title")}} {{readonlyinline}}</dt> + <dd>The title of the notification as specified in the first parameter of the constructor.</dd> + <dt>{{domxref("Notification.vibrate")}} {{readonlyinline}}</dt> + <dd>Specifies a vibration pattern for devices with vibration hardware to emit.</dd> +</dl> + +<h4 id="Event_handlers">Event handlers</h4> + +<dl> + <dt>{{domxref("Notification.onclick")}}</dt> + <dd>A handler for the {{event("click")}} event. It is triggered each time the user clicks on the notification.</dd> +</dl> + +<dl> + <dt>{{domxref("Notification.onclose")}}</dt> + <dd>A handler for the {{event("close")}} event. It is triggered when the user closes the notification.</dd> +</dl> + +<dl> + <dt>{{domxref("Notification.onerror")}}</dt> + <dd>A handler for the {{event("error")}} event. It is triggered each time the notification encounters an error.</dd> + <dt>{{domxref("Notification.onshow")}}</dt> + <dd>A handler for the {{event("show")}} event. It is triggered when the notification is displayed.</dd> +</dl> + +<h2 id="Methods">Methods</h2> + +<h3 id="Static_methods">Static methods</h3> + +<p>These methods are available only on the <code>Notification</code> object itself.</p> + +<dl> + <dt>{{domxref("Notification.requestPermission()")}}</dt> + <dd>Requests permission from the user to display notifications.</dd> +</dl> + +<h3 id="Instance_methods">Instance methods</h3> + +<p>These properties are available only on an instance of the <code>Notification</code> object or through its <a href="/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain"><code>prototype</code></a>. The <code>Notification</code> object also inherits from the {{domxref("EventTarget")}} interface.</p> + +<dl> + <dt>{{domxref("Notification.close()")}}</dt> + <dd>Programmatically closes a notification.</dd> +</dl> + +<h2 id="Example">Example</h2> + +<p>Assume this basic HTML:</p> + +<pre class="brush: html"><button onclick="notifyMe()">Notify me!</button></pre> + +<p>It's possible to send a notification as follows — here we present a fairly verbose and complete set of code you could use if you wanted to first check whether notifications are supported, then check if permission has been granted for the current origin to send notifications, then request permission if required, before then sending a notification.</p> + +<pre class="brush: js">function notifyMe() { + // Let's check if the browser supports notifications + if (!("Notification" in window)) { + alert("This browser does not support desktop notification"); + } + + // Let's check whether notification permissions have already been granted + else if (Notification.permission === "granted") { + // If it's okay let's create a notification + var notification = new Notification("Hi there!"); + } + + // Otherwise, we need to ask the user for permission + else if (Notification.permission !== "denied") { + Notification.requestPermission().then(function (permission) { + // If the user accepts, let's create a notification + if (permission === "granted") { + var notification = new Notification("Hi there!"); + } + }); + } + + // At last, if the user has denied notifications, and you + // want to be respectful there is no need to bother them any more. +}</pre> + +<p>{{EmbedLiveSample('Example', '100%', 30)}}</p> + +<h3 id="Alternate_example_run_on_page_load">Alternate example: run on page load</h3> + +<p>In many cases, you don't need to be this verbose. For example, in our <a href="https://mdn.github.io/emogotchi/">Emogotchi demo</a> (<a href="https://github.com/mdn/emogotchi">see source code</a>), we simply run {{domxref("Notification.requestPermission")}} regardless to make sure we can get permission to send notifications (this uses the newer promise-based method syntax):</p> + +<pre class="brush: js">Notification.requestPermission().then(function(result) { + console.log(result); +});</pre> + +<p>Then we run a simple <code>spawnNotification()</code> function when we want to fire a notification — this is passed arguments to specify the body, icon, and title we want. Then it creates the necessary <code>options</code> object and fires the notification using the {{domxref("Notification.Notification","Notification()")}} constructor.</p> + +<pre class="brush: js">function spawnNotification(body, icon, title) { + var options = { + body: body, + icon: icon + }; + var n = new Notification(title, options); +}</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Web Notifications')}}</td> + <td>{{Spec2('Web Notifications')}}</td> + <td>Living standard</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.Notification")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API">Using the Notifications API</a></li> +</ul> diff --git a/files/fa/web/api/notification/requestpermission/index.html b/files/fa/web/api/notification/requestpermission/index.html new file mode 100644 index 0000000000..c9bd799f25 --- /dev/null +++ b/files/fa/web/api/notification/requestpermission/index.html @@ -0,0 +1,80 @@ +--- +title: Notification.requestPermission() +slug: Web/API/Notification/requestPermission +translation_of: Web/API/Notification/requestPermission +--- +<p>{{APIRef("Web Notifications")}}{{AvailableInWorkers}}{{securecontext_header}}</p> + +<p>The <strong><code>requestPermission()</code></strong> method of the {{domxref("Notification")}} interface requests permission from the user for the current origin to display notifications.</p> + +<div class="note"> +<p><strong>Note:</strong> This feature is <strong>not</strong> available in {{domxref("SharedWorker")}}</p> +</div> + +<h2 id="Syntax">Syntax</h2> + +<p>The latest spec has updated this method to a promise-based syntax that works like this:</p> + +<pre class="brush: js">Notification.requestPermission().then(function(permission) { ... });</pre> + +<p>Previously, the syntax was based on a simple callback; this version is now deprecated:</p> + +<pre class="brush: js line-numbers language-js"><code class="language-js">Notification<span class="punctuation token">.</span><span class="function token">requestPermission</span><span class="punctuation token">(</span>callback<span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre> + +<p><code class="language-js"><span class="punctuation token">Safari Version 12.0.3 still uses callback to get the permission.</span></code></p> + +<h3 id="Parameters">Parameters</h3> + +<dl> + <dt><code>callback</code> {{optional_inline}} {{deprecated_inline("gecko46")}}</dt> + <dd>An optional callback function that is called with the permission value. Deprecated in favor of the promise return value.</dd> +</dl> + +<h3 id="Returns">Returns</h3> + +<p>A {{jsxref("Promise")}} that resolves to a {{domxref("DOMString")}} with the permission picked by the user. Possible values for this string are <code>granted</code>, <code>denied</code>, or <code>default</code>.</p> + +<h2 id="Example">Example</h2> + +<p>The following snippet requests permission from the user, then logs a different result to the console depending on the user's choice.</p> + +<pre class="brush: js">Notification.requestPermission().then(function(result) { + if (result === 'denied') { + console.log('Permission wasn\'t granted. Allow a retry.'); + return; + } + if (result === 'default') { + console.log('The permission request was dismissed.'); + return; + } + // Do something with the granted permission. +});</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Web Notifications')}}</td> + <td>{{Spec2('Web Notifications')}}</td> + <td>Living standard</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.Notification.requestPermission")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API">Using the Notifications API</a></li> +</ul> diff --git a/files/fa/web/css/_colon_not/index.html b/files/fa/web/css/_colon_not/index.html new file mode 100644 index 0000000000..7f7c5cbec3 --- /dev/null +++ b/files/fa/web/css/_colon_not/index.html @@ -0,0 +1,117 @@ +--- +title: ':not()' +slug: 'Web/CSS/:not' +tags: + - سی اس اس + - شبه کلاس + - لایه + - مرجع + - وب +translation_of: 'Web/CSS/:not' +--- +<div>{{CSSRef}}</div> + +<div dir="rtl"><strong><code>not()</code></strong> <a href="https://developer.mozilla.org/en-US/docs/Web/CSS">CSS</a> <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes">pseudo-class<strong><code>:</code></strong></a><a href="/en-US/docs/Web/CSS/Pseudo-classes"> </a> همه عناصر را انتخاب میکند بجز عناصری که به عنوان ورودی به این کلاس داده شود. <span id="result_box" lang="fa"><span>از آنجایی که این کلاس از انتخاب عناصر خاصی جلوگیری می کند، به عنوان </span></span> <em>negation pseudo-class</em><span lang="fa"><span> شناخته می شود.</span></span></div> + +<div dir="rtl"> </div> + +<pre class="brush: css no-line-numbers" dir="rtl">/* paragraph همه عناصر را انتخاب میکند بجز عنصر */ +:not(p) { + color: blue; +}</pre> + +<div class="note"> +<p><strong>Notes:</strong></p> + +<ul> + <li>Useless selectors can be written using this pseudo-class. For example, <code>:not(*)</code> matches any element which is not an element, so the rule will never be applied.</li> + <li>This pseudo-class can increase the <a href="/en-US/docs/Web/CSS/Specificity">specificity</a> of a rule. For example, <code>#foo:not(#bar)</code> will match the same element as the simpler <code>#foo</code>, but has a higher specificity.</li> + <li><code>:not(.foo)</code> will match anything that isn't <code>.foo</code>, <em>including {{HTMLElement("html")}} and {{HTMLElement("body")}}.</em></li> + <li>This selector only applies to one element; you cannot use it to exclude all ancestors. For instance, <code>body :not(table) a</code> will still apply to links inside of a table, since {{HTMLElement("tr")}} will match with the <code>:not()</code> part of the selector.</li> +</ul> +</div> + +<h2 id="Syntax">Syntax</h2> + +<p dir="rtl">ورودیهای شبهکلاس <code>()not:</code> با ویرگول از یکدیگر جدا میشود.</p> + +<p dir="rtl"> </p> + +<p> </p> + +<div class="warning"> +<p>The ability to list more than one selector is experimental and not yet widely supported.</p> +</div> + +<pre class="syntaxbox">{{csssyntax}}</pre> + +<h2 id="Example">Example</h2> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html"><p>این عنصر، عنصر پاراگراف است.</p> +<p class="fancy">من چقدر خوبم!</p> +<div>این عنصر، عنصر پاراگراف نیست.</div> +</pre> + +<h3 id="CSS">CSS</h3> + +<pre class="brush: css">.fancy { + text-shadow: 2px 2px 3px gold; +} + +/* نیستند `fancy` که دارای کلاس <p> ِتمام عنصار */ +p:not(.fancy) { + color: green; +} + +/* <p> همه عناصر بجز عنصر */ +body :not(p) { + text-decoration: underline; +} + +/* <span> یا <div> همه عناصر بجز عناصر */ +body :not(div):not(span) { + font-weight: bold; +} +/* را دارا هستند `fancy` یا `crazy` همه عناصر بجز عناصری که کلاسهای */ +/* توجه داشته باشید که این نوع نوشتار هنوز پشتیبانی نمیشود. */ +body :not(.crazy, .fancy) { + font-family: sans-serif; +}</pre> + +<h3 id="Result">Result</h3> + +<p>{{EmbedLiveSample('Example')}}</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('CSS4 Selectors', '#negation', ':not()')}}</td> + <td>{{Spec2('CSS4 Selectors')}}</td> + <td>Extends its argument to allow some non-simple selectors.</td> + </tr> + <tr> + <td>{{SpecName('CSS3 Selectors', '#negation', ':not()')}}</td> + <td>{{Spec2('CSS3 Selectors')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("css.selectors.not")}}</p> +</div> diff --git a/files/fa/web/css/_doublecolon_cue/index.html b/files/fa/web/css/_doublecolon_cue/index.html new file mode 100644 index 0000000000..f1e723f7e7 --- /dev/null +++ b/files/fa/web/css/_doublecolon_cue/index.html @@ -0,0 +1,79 @@ +--- +title: '::cue (:cue)' +slug: 'Web/CSS/::cue' +translation_of: 'Web/CSS/::cue' +--- +<p> </p> + +<div>{{CSSRef}}</div> + +<p> </p> + +<p dir="rtl"><a href="/en-US/docs/Web/CSS/Pseudo-elements">شبه عنصر</a> {{ Cssxref("cue::") }} یک عنصر انتخاب شده با نشانههای WebVTT را تطابق میدهد. این <a href="/en-US/docs/Web/CSS/Pseudo-elements">شبه عنصر</a> میتواند برای<a href="/docs/Web/API/WebVTT_API#Styling_WebTT_cues"> آرایش زیرنویس و دیگر موارد</a> محتوای تصویری با VTT tracks مورد استفاده قرار گیرد.</p> + +<pre class="brush: css no-line-numbers">::cue { + color: yellow; + font-weight: bold; +}</pre> + +<h2 id="Allowable_properties">Allowable properties</h2> + +<p>Only a small subset of CSS properties can be used in a rule with <code>::cue</code> in its selector:</p> + +<ul> + <li>{{cssxref("color")}}</li> + <li>{{cssxref("opacity")}}</li> + <li>{{cssxref("visibility")}}</li> + <li>{{cssxref("text-decoration")}} and its longhand properties</li> + <li>{{cssxref("text-shadow")}}</li> + <li>{{cssxref("background")}} and its longhand properties</li> + <li>{{cssxref("outline")}} and its longhand properties</li> + <li>{{Cssxref("font")}} and its longhand properties, including {{cssxref("line-height")}}</li> + <li>{{cssxref("white-space")}}</li> + <li>{{cssxref("text-combine-upright")}}</li> + <li>{{cssxref("ruby-position")}}</li> +</ul> + +<p>The properties are applied to the entire set of cues as if they were a single unit. The only exception is that <code>background</code> and its shorthand properties apply to each cue individually, to avoid creating boxes and obscuring unexpectedly large areas of the media.</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">{{csssyntax}}</pre> + +<h2 id="Example">Example</h2> + +<p>The following CSS sets the cue style so that the text is white and the background is a translucent black box.</p> + +<pre class="brush: css">::cue { + color: #fff; + background-color: rgba(0, 0, 0, 0.6); +}</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th>Specification</th> + <th>Status</th> + <th>Comment</th> + </tr> + <tr> + <td>{{SpecName("WebVTT", "#the-cue-pseudo-element", "::cue")}}</td> + <td>{{Spec2("WebVTT")}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> + +<p>{{Compat("css.selectors.cue")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/WebVTT_API">Web Video Tracks Format (WebVTT)</a></li> +</ul> diff --git a/files/fa/web/css/adjacent_sibling_combinator/index.html b/files/fa/web/css/adjacent_sibling_combinator/index.html new file mode 100644 index 0000000000..c988c47aed --- /dev/null +++ b/files/fa/web/css/adjacent_sibling_combinator/index.html @@ -0,0 +1,80 @@ +--- +title: Adjacent sibling combinator +slug: Web/CSS/Adjacent_sibling_combinator +translation_of: Web/CSS/Adjacent_sibling_combinator +--- +<div>{{CSSRef("Selectors")}}</div> + +<p dir="rtl">ترکیب (<code>+</code>) <strong>adjacent sibling combinator</strong> دو انتخابگر را از هم جدا میکند و زمانی تطابق انجام میشود که انتخابگر دوم بلافاصله بعد از انتخابگر اول آمده باشد و هر فرزند یک والد {{domxref("element")}} باشند.</p> + +<pre class="brush: css no-line-numbers">/* باشند img پارگرافهایی که بلافاصله بعد از */ +img + p { + font-style: bold; +}</pre> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">former_element + target_element { <em>style properties</em> } +</pre> + +<h2 id="Example">Example</h2> + +<h3 id="CSS">CSS</h3> + +<pre class="brush: css">li:first-of-type + li { + color: red; +} +</pre> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html"><ul> + <li>One</li> + <li>Two!</li> + <li>Three</li> +</ul></pre> + +<h3 id="Result">Result</h3> + +<p>{{EmbedLiveSample('Example', 200, 100)}}</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('CSS4 Selectors', '#adjacent-sibling-combinators', 'next-sibling combinator')}}</td> + <td>{{Spec2('CSS4 Selectors')}}</td> + <td>Renames it the "next-sibling" combinator.</td> + </tr> + <tr> + <td>{{SpecName('CSS3 Selectors', '#adjacent-sibling-combinators', 'Adjacent sibling combinator')}}</td> + <td>{{Spec2('CSS3 Selectors')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('CSS2.1', 'selector.html#adjacent-selectors', 'Adjacent sibling selectors')}}</td> + <td>{{Spec2('CSS2.1')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("css.selectors.adjacent_sibling")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/CSS/General_sibling_selectors">General sibling selectors</a></li> +</ul> diff --git a/files/fa/web/css/all/index.html b/files/fa/web/css/all/index.html new file mode 100644 index 0000000000..8f80bf5b2b --- /dev/null +++ b/files/fa/web/css/all/index.html @@ -0,0 +1,159 @@ +--- +title: all +slug: Web/CSS/all +translation_of: Web/CSS/all +--- +<div>{{CSSRef}}</div> + +<p>The <code><strong>all</strong></code> <a href="/en-US/docs/Web/CSS">CSS</a> <a href="/en-US/docs/Web/CSS/Shorthand_properties">shorthand property</a> sets all of an element's properties (other than {{cssxref("unicode-bidi")}} and {{cssxref("direction")}}) to their initial or inherited values, or to the values specified in another stylesheet origin..</p> + +<pre class="brush:css no-line-numbers">/* Global values */ +all: initial; +all: inherit; +all: unset; + +/* CSS Cascading and Inheritance Level 4 */ +all: revert; +</pre> + +<p>{{cssinfo}}</p> + +<h2 id="Syntax">Syntax</h2> + +<p>The <code>all</code> property is specified as one of the CSS global keyword values. Note that none of these values affect the {{cssxref("unicode-bidi")}} and {{cssxref("direction")}} properties.</p> + +<h3 id="Values">Values</h3> + +<dl> + <dt>{{cssxref("initial")}}</dt> + <dd>Specifies that all the element's properties should be changed to their <a href="/en-US/docs/Web/CSS/initial_value">initial values</a>.</dd> + <dt>{{cssxref("inherit")}}</dt> + <dd>Specifies that all the element's properties should be changed to their <a href="/en-US/docs/Web/CSS/inheritance">inherited values</a>.</dd> + <dt>{{cssxref("unset")}}</dt> + <dd>Specifies that all the element's properties should be changed to their inherited values if they inherit by default, or to their initial values if not.</dd> + <dt>{{cssxref("revert")}}</dt> + <dd>Specifies behavior that depends on the stylesheet origin to which the declaration belongs: + <dl> + <dt><a href="/en-US/docs/Web/CSS/Cascade#User-agent_stylesheets">User-agent origin</a></dt> + <dd>Equivalent to <code>unset</code>.</dd> + <dt><a href="/en-US/docs/Web/CSS/Cascade#User_stylesheets">User origin</a></dt> + <dd>Rolls back the <a href="/en-US/docs/Web/CSS/Cascade">cascade</a> to the user-agent level, so that the <a href="/en-US/docs/Web/CSS/specified_value">specified values</a> are calculated as if no author-level or user-level rules were specified for the element.</dd> + <dt><a href="/en-US/docs/Web/CSS/Cascade#Author_stylesheets">Author origin</a></dt> + <dd>Rolls back the <a href="/en-US/docs/Web/CSS/Cascade">cascade</a> to the user level, so that the <a href="/en-US/docs/Web/CSS/specified_value">specified values</a> are calculated as if no author-level rules were specified for the element. For purposes of <code>revert</code>, the Author origin includes the Override and Animation origins.</dd> + </dl> + </dd> +</dl> + +<h3 id="Formal_syntax">Formal syntax</h3> + +<pre class="syntaxbox">{{csssyntax}}</pre> + +<h2 id="Examples">Examples</h2> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html"><blockquote id="quote"> + Lorem ipsum dolor sit amet, consectetur adipiscing elit. +</blockquote> +Phasellus eget velit sagittis.</pre> + +<h3 id="CSS">CSS</h3> + +<pre class="brush: css">body { + font-size: small; + background-color: #F0F0F0; + color: blue; +} + +blockquote { + background-color: skyblue; + color: red; +} +</pre> + +<h3 id="Result">Result</h3> + +<div id="ex0" style="display: inline-block; width: 225px; vertical-align: top;"> +<h4 id="No_all_property">No <code>all</code> property</h4> + +<pre class="brush: html hidden"><blockquote id="quote">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</blockquote> Phasellus eget velit sagittis.</pre> + +<pre class="brush: css hidden">body { font-size: small; background-color: #F0F0F0; color:blue; } +blockquote { background-color: skyblue; color: red; }</pre> +{{EmbedLiveSample("ex0", "200", "125")}} + +<p>The {{HTMLElement("blockquote")}} uses the browser's default styling together with a specific background and text color. It also behaves as a <em>block</em> element: the text that follows it is beneath it.</p> +</div> + +<div id="ex1" style="display: inline-block; width: 225px; vertical-align: top;"> +<h4 id="allunset"><code>all:unset</code></h4> + +<pre class="brush: html hidden"><blockquote id="quote">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</blockquote> Phasellus eget velit sagittis.</pre> + +<pre class="brush: css hidden">body { font-size: small; background-color: #F0F0F0; color:blue; } +blockquote { background-color: skyblue; color: red; } +blockquote { all: unset; }</pre> +{{EmbedLiveSample("ex1", "200", "125")}} + +<p>The {{HTMLElement("blockquote")}} doesn't use the browser default styling: it is an <em>inline</em> element now (initial value), its {{cssxref("background-color")}} is <code>transparent</code> (initial value), but its {{cssxref("font-size")}} is still <code>small</code> (inherited value) and its {{cssxref("color")}} is <code>blue</code> (inherited value).</p> +</div> + +<div id="ex2" style="display: inline-block; width: 225px; vertical-align: top;"> +<h4 id="allinitial"><code>all:initial</code></h4> + +<pre class="brush: html hidden"><blockquote id="quote">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</blockquote> Phasellus eget velit sagittis.</pre> + +<pre class="brush: css hidden">body { font-size: small; background-color: #F0F0F0; color:blue; } +blockquote { background-color: skyblue; color: red; } +blockquote { all: initial; }</pre> +{{EmbedLiveSample("ex2", "200", "125")}} + +<p>The {{HTMLElement("blockquote")}} doesn't use the browser default styling: it is an <em>inline</em> element now (initial value), its {{cssxref("background-color")}} is <code>transparent</code> (initial value), its {{cssxref("font-size")}} is <code>normal</code> (initial value) and its {{cssxref("color")}} is <code>black</code> (initial value).</p> +</div> + +<div id="ex3" style="display: inline-block; width: 225px; vertical-align: top;"> +<h4 id="allinherit"><code>all:inherit</code></h4> + +<pre class="brush: html hidden"><blockquote id="quote">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</blockquote> Phasellus eget velit sagittis.</pre> + +<pre class="brush: css hidden">body { font-size: small; background-color: #F0F0F0; color:blue; } +blockquote { background-color: skyblue; color: red; } +blockquote { all: inherit; }</pre> +{{EmbedLiveSample("ex3", "200", "125")}} + +<p>The {{HTMLElement("blockquote")}} doesn't use the browser default styling: it is a <em>block</em> element now (inherited value from its containing {{HTMLElement("body")}} element), its {{cssxref("background-color")}} is <code>#F0F0F0</code> (inherited value), its {{cssxref("font-size")}} is <code>small</code> (inherited value) and its {{cssxref("color")}} is <code>blue</code> (inherited value).</p> +</div> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{ SpecName('CSS4 Cascade', '#all-shorthand', 'all') }}</td> + <td>{{ Spec2('CSS4 Cascade') }}</td> + <td>Added the <code>revert</code> value.</td> + </tr> + <tr> + <td>{{ SpecName('CSS3 Cascade', '#all-shorthand', 'all') }}</td> + <td>{{ Spec2('CSS3 Cascade') }}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("css.properties.all")}}</p> + +<h2 id="See_also">See also</h2> + +<p>CSS global keyword values: {{cssxref("initial")}}, {{cssxref("inherit")}}, {{cssxref("unset")}}, {{cssxref("revert")}}</p> diff --git a/files/fa/web/css/css_box_model/index.html b/files/fa/web/css/css_box_model/index.html new file mode 100644 index 0000000000..ed6760a26a --- /dev/null +++ b/files/fa/web/css/css_box_model/index.html @@ -0,0 +1,116 @@ +--- +title: CSS Basic Box Model +slug: Web/CSS/CSS_Box_Model +tags: + - CSS + - CSS Box Model + - Guide + - NeedsTranslation + - Overview + - Reference + - TopicStub +translation_of: Web/CSS/CSS_Box_Model +--- +<div>{{CSSRef}}</div> + +<p><strong>CSS Basic Box Model</strong> is a module of CSS that defines the rectangular boxes—including their padding and margin—that are generated for elements and laid out according to the <a href="/en-US/docs/Web/CSS/Visual_formatting_model">visual formatting model</a>.</p> + +<h2 id="Reference">Reference</h2> + +<h3 id="Properties">Properties</h3> + +<h4 id="Properties_controlling_the_flow_of_content_in_a_box">Properties controlling the flow of content in a box</h4> + +<div class="index"> +<ul> + <li>{{CSSxRef("overflow")}}</li> + <li>{{CSSxRef("overflow-x")}}</li> + <li>{{CSSxRef("overflow-y")}}</li> +</ul> +</div> + +<h4 id="Properties_controlling_the_size_of_a_box">Properties controlling the size of a box</h4> + +<div class="index"> +<ul> + <li>{{CSSxRef("height")}}</li> + <li>{{CSSxRef("width")}}</li> + <li>{{CSSxRef("max-height")}}</li> + <li>{{CSSxRef("max-width")}}</li> + <li>{{CSSxRef("min-height")}}</li> + <li>{{CSSxRef("min-width")}}</li> +</ul> +</div> + +<h4 id="Properties_controlling_the_margins_of_a_box">Properties controlling the margins of a box</h4> + +<div class="index"> +<ul> + <li>{{CSSxRef("margin")}}</li> + <li>{{CSSxRef("margin-bottom")}}</li> + <li>{{CSSxRef("margin-left")}}</li> + <li>{{CSSxRef("margin-right")}}</li> + <li>{{CSSxRef("margin-top")}}</li> + <li>{{CSSxRef("margin-trim")}} {{Experimental_Inline}}</li> +</ul> +</div> + +<h4 id="Properties_controlling_the_paddings_of_a_box">Properties controlling the paddings of a box</h4> + +<div class="index"> +<ul> + <li>{{CSSxRef("padding")}}</li> + <li>{{CSSxRef("padding-bottom")}}</li> + <li>{{CSSxRef("padding-left")}}</li> + <li>{{CSSxRef("padding-right")}}</li> + <li>{{CSSxRef("padding-top")}}</li> +</ul> +</div> + +<h4 id="Other_properties">Other properties</h4> + +<div class="index"> +<ul> + <li>{{CSSxRef("visibility")}}</li> +</ul> +</div> + +<h2 id="Guides">Guides</h2> + +<dl> + <dt><a href="/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model">Introduction to the CSS box model</a></dt> + <dd>Explains one of the fundamental concept of CSS: the box model. This model defines how CSS lays out elements, including their content, padding, border, and margin areas.</dd> + <dt><a href="/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing">Mastering margin collapsing</a></dt> + <dd>Sometimes, two adjacent margins are collapsed into one. This article describes the rules that govern when and why this happens, and how to control it.</dd> + <dt><a href="/en-US/docs/Web/CSS/Visual_formatting_model">Visual formatting model</a></dt> + <dd>Explains the visual formatting model.</dd> +</dl> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSS3 Box")}}</td> + <td>{{Spec2("CSS3 Box")}}</td> + <td>Added <code style="white-space: nowrap;">margin-trim</code></td> + </tr> + <tr> + <td>{{SpecName("CSS2.1", "box.html")}}</td> + <td>{{Spec2("CSS2.1")}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName("CSS1")}}</td> + <td>{{Spec2("CSS1")}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> diff --git a/files/fa/web/css/css_box_model/mastering_margin_collapsing/index.html b/files/fa/web/css/css_box_model/mastering_margin_collapsing/index.html new file mode 100644 index 0000000000..95cced5f62 --- /dev/null +++ b/files/fa/web/css/css_box_model/mastering_margin_collapsing/index.html @@ -0,0 +1,83 @@ +--- +title: Mastering margin collapsing +slug: Web/CSS/CSS_Box_Model/Mastering_margin_collapsing +translation_of: Web/CSS/CSS_Box_Model/Mastering_margin_collapsing +--- +<div>{{CSSRef}}</div> + +<p>The <a href="/en-US/docs/Web/CSS/margin-top">top</a> and <a href="/en-US/docs/Web/CSS/margin-bottom">bottom</a> margins of blocks are sometimes combined (collapsed) into a single margin whose size is the largest of the individual margins (or just one of them, if they are equal), a behavior known as <strong>margin collapsing</strong>. Note that the margins of <a href="/en-US/docs/Web/CSS/float">floating</a> and <a href="/en-US/docs/Web/CSS/position#absolute">absolutely positioned</a> elements never collapse.</p> + +<p>Margin collapsing occurs in three basic cases:</p> + +<dl> + <dt dir="rtl">هم نیا</dt> + <dd dir="rtl">margin هم نیا ها با یکدیگر ادغام نمیشوند. (except when the latter sibling needs to be <a href="/en-US/docs/Web/CSS/clear">cleared</a> past floats).</dd> + <dt>No content separating parent and descendants</dt> + <dd>If there is no border, padding, inline part, <a href="/en-US/docs/Web/Guide/CSS/Block_formatting_context">block formatting context</a> created, or <em><a href="/en-US/docs/Web/CSS/clear">clearance</a></em> to separate the {{cssxref("margin-top")}} of a block from the {{cssxref("margin-top")}} of one or more of its descendant blocks; or no border, padding, inline content, {{cssxref("height")}}, {{cssxref("min-height")}}, or {{cssxref("max-height")}} to separate the {{cssxref("margin-bottom")}} of a block from the {{cssxref("margin-bottom")}} of one or more of its descendant blocks, then those margins collapse. The collapsed margin ends up outside the parent.</dd> + <dt>Empty blocks</dt> + <dd>If there is no border, padding, inline content, {{cssxref("height")}}, or {{cssxref("min-height")}} to separate a block's {{cssxref("margin-top")}} from its {{cssxref("margin-bottom")}}, then its top and bottom margins collapse.</dd> +</dl> + +<p>Some things to note:</p> + +<ul> + <li>More complex margin collapsing (of more than two margins) occurs when the above cases are combined.</li> + <li>These rules apply even to margins that are zero, so the margin of a descendant ends up outside its parent (according to the rules above) whether or not the parent's margin is zero.</li> + <li>When negative margins are involved, the size of the collapsed margin is the sum of the largest positive margin and the smallest (most negative) negative margin.</li> + <li>When all margins are negative, the size of the collapsed margin is the smallest (most negative) margin. This applies to both adjacent elements and nested elements.</li> +</ul> + +<h2 id="Examples">Examples</h2> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html notranslate"><p>The bottom margin of this paragraph is collapsed …</p> +<p>… with the top margin of this paragraph, yielding a margin of <code>1.2rem</code> in between.</p> + +<div>This parent element contains two paragraphs! + <p>This paragraph has a <code>.4rem</code> margin between it and the text above.</p> + <p>My bottom margin collapses with my parent, yielding a bottom margin of <code>2rem</code>.</p> +</div> + +<p>I am <code>2rem</code> below the element above.</p></pre> + +<h3 id="CSS">CSS</h3> + +<pre class="brush: css notranslate">div { + margin: 2rem 0; + background: lavender; +} + +p { + margin: .4rem 0 1.2rem 0; + background: yellow; +}</pre> + +<h3 id="Result">Result</h3> + +<p>{{EmbedLiveSample('Examples', 'auto', 350)}}</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSS2.1", "box.html#collapsing-margins", "margin collapsing")}}</td> + <td>{{Spec2("CSS2.1")}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{css_key_concepts}}</li> +</ul> diff --git a/files/fa/web/css/css_flexible_box_layout/basic_concepts_of_flexbox/index.html b/files/fa/web/css/css_flexible_box_layout/basic_concepts_of_flexbox/index.html new file mode 100644 index 0000000000..40e7937e9e --- /dev/null +++ b/files/fa/web/css/css_flexible_box_layout/basic_concepts_of_flexbox/index.html @@ -0,0 +1,234 @@ +--- +title: مفاهیم اولیه فلکس باکس +slug: Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox +tags: + - فلکس + - فلکس باکس + - قالب بندی + - محور +translation_of: Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox +--- +<div>{{CSSRef}}</div> + +<p class="summary">فلکسیبل باکس ماژول که معمولا به آن فلکسباکس میگویند، به عنوان یک قالببندی تک بعدی طراحی شد و به عنوان راهی برای تقسیم فضا بین بخشهای داخل یک جعبه و ابزار قدرتمندی برای ترازبندی. این مقاله یک طرح کلی از امکانات اصلی فلکسباکس را ارائه میدهد.</p> + +<p>When we describe flexbox as being one dimensional we are describing the fact that flexbox deals with layout in one dimension at a time — either as a row or as a column. This can be contrasted with the two-dimensional model of <a href="/en-US/docs/Web/CSS/CSS_Grid_Layout">CSS Grid Layout</a>, which controls columns and rows together.</p> + +<h2 id="دو_محور_فلکسباکس">دو محور فلکسباکس</h2> + +<p>When working with flexbox you need to think in terms of two axes — the main axis and the cross axis. The main axis is defined by the {{cssxref("flex-direction")}} property, and the cross axis runs perpendicular to it. Everything we do with flexbox refers back to these axes, so it is worth understanding how they work from the outset.</p> + +<h3 id="محور_اصلی">محور اصلی</h3> + +<p>محور اصلی که با <code>flex-direction</code> مشخص میشود, چهار مقدار میپذیرد:</p> + +<ul> + <li><code>row</code></li> + <li><code>row-reverse</code></li> + <li><code>column</code></li> + <li><code>column-reverse</code></li> +</ul> + +<p>اگر <code>row</code> یا <code>row-reverse</code> را انتخاب کنید, محور اصلی در جهت طبیعی متنها (<strong>inline</strong>) خواهد بود</p> + +<p><img alt="If flex-direction is set to row the main axis runs along the row in the inline direction." src="https://mdn.mozillademos.org/files/15614/Basics1.png" style="display: block; height: 152px; margin: 0px auto; width: 522px;"></p> + +<p>اگر <code>column</code> یا <code>column-reverse</code> را انتخاب کنید محور اصلی در جهت بالا به پایین (<strong>block direction</strong>) خواهد بود.</p> + +<p><img alt="If flex-direction is set to column the main axis runs in the block direction." src="https://mdn.mozillademos.org/files/15615/Basics2.png" style="display: block; height: 227px; margin: 0px auto; width: 709px;"></p> + +<h3 id="محور_قطعکننده">محور قطعکننده</h3> + +<p>The cross axis runs perpendicular to the main axis, therefore if your <code>flex-direction</code> (main axis) is set to <code>row</code> or <code>row-reverse</code> the cross axis runs down the columns.</p> + +<p><img alt="If flex-direction is set to row then the cross axis runs in the block direction." src="https://mdn.mozillademos.org/files/15616/Basics3.png" style="display: block; height: 125px; margin: 0px auto; width: 666px;"></p> + +<p>If your main axis is <code>column</code> or <code>column-reverse</code> then the cross axis runs along the rows.</p> + +<p><img alt="If flex-direction is set to column then the cross axis runs in the inline direction." src="https://mdn.mozillademos.org/files/15617/Basics4.png" style="display: block; height: 244px; margin: 0px auto; width: 523px;"></p> + +<p>Understanding which axis is which is important when we start to look at aligning and justifying flex items; flexbox features properties that align and justify content along one axis or the other.</p> + +<h2 id="خطهای_شروع_و_پایان">خطهای شروع و پایان</h2> + +<p>Another vital area of understanding is how flexbox makes no assumption about the writing mode of the document. In the past, CSS was heavily weighted towards horizontal and left-to-right writing modes. Modern layout methods encompass the range of writing modes and so we no longer assume that a line of text will start at the top left of a document and run towards the right hand side, with new lines appearing one under the other.</p> + +<p>You can read more about the relationship between flexbox and the Writing Modes specification in a later article, however the following description should help explain why we do not talk about left and right and top and bottom when we describe the direction that our flex items flow in.</p> + +<p>If the <code>flex-direction</code> is <code>row</code> and I am working in English, then the start edge of the main axis will be on the left, the end edge on the right.</p> + +<p><img alt="Working in English the start edge is on the left." src="https://mdn.mozillademos.org/files/15618/Basics5.png" style="display: block; height: 152px; margin: 0px auto; width: 631px;"></p> + +<p>If I were to work in Arabic, then the start edge of my main axis would be on the right and the end edge on the left.</p> + +<p><img alt="The start edge in a RTL language is on the right." src="https://mdn.mozillademos.org/files/15619/Basics6.png" style="display: block; height: 152px; margin: 0px auto; width: 634px;"></p> + +<p>In both cases the start edge of the cross axis is at the top of the flex container and the end edge at the bottom, as both languages have a horizontal writing mode.</p> + +<p>After a while, thinking about start and end rather than left and right becomes natural, and will be useful to you when dealing with other layout methods such as CSS Grid Layout which follow the same patterns.</p> + +<h2 id="جعبه_محتوی_از_نوع_فلکس">جعبه محتوی از نوع فلکس</h2> + +<p>An area of a document laid out using flexbox is called a <strong>flex container</strong>. To create a flex container, we set the value of the area's container's {{cssxref("display")}} property to <code>flex</code> or <code>inline-flex</code>. As soon as we do this the direct children of that container become <strong>flex items</strong>. As with all properties in CSS, some initial values are defined, so when creating a flex container all of the contained flex items will behave in the following way.</p> + +<ul> + <li>Items display in a row (the <code>flex-direction</code> property's default is <code>row</code>).</li> + <li>The items start from the start edge of the main axis.</li> + <li>The items do not stretch on the main dimension, but can shrink.</li> + <li>The items will stretch to fill the size of the cross axis.</li> + <li>The {{cssxref("flex-basis")}} property is set to <code>auto</code>.</li> + <li>The {{cssxref("flex-wrap")}} property is set to <code>nowrap</code>.</li> +</ul> + +<p>The result of this is that your items will all line up in a row, using the size of the content as their size in the main axis. If there are more items than can fit in the container, they will not wrap but will instead overflow. If some items are taller than others, all items will stretch along the cross axis to fill its full size.</p> + +<p>You can see in the live example below how this looks. Try editing the items or adding additional items in order to test the initial behavior of flexbox.</p> + +<p>{{EmbedGHLiveSample("css-examples/flexbox/basics/the-flex-container.html", '100%', 480)}} </p> + +<h3 id="تغییر_جعهت_فلکس">تغییر جعهت فلکس</h3> + +<p>Adding the {{cssxref("flex-direction")}} property to the flex container allows us to change the direction in which our flex items display. Setting <code>flex-direction: row-reverse</code> will keep the items displaying along the row, however the start and end lines are switched.</p> + +<p>If we change <code>flex-direction</code> to <code>column</code> the main axis switches and our items now display in a column. Set <code>column-reverse</code> and the start and end lines are again switched.</p> + +<p>The live example below has <code>flex-direction</code> set to <code>row-reverse</code>. Try the other values — <code>row</code>, <code>column</code> and <code>column-reverse</code> — to see what happens to the content.</p> + +<p>{{EmbedGHLiveSample("css-examples/flexbox/basics/flex-direction.html", '100%', 350)}}</p> + +<h2 id="جعبه_محتوی_فلکس_از_نوع_چندسطری_با_flex-wrap">جعبه محتوی فلکس از نوع چندسطری با flex-wrap</h2> + +<p>While flexbox is a one dimensional model, it is possible to cause our flex items to wrap onto multiple lines. In doing so, you should consider each line as a new flex container. Any space distribution will happen across that line, without reference to the lines either side.</p> + +<p>To cause wrapping behaviour add the property {{cssxref("flex-wrap")}} with a value of <code>wrap</code>. Now, should your items be too large to all display in one line, they will wrap onto another line. The live sample below contains items that have been given a width, the total width of the items being too wide for the flex container. As <code>flex-wrap</code> is set to <code>wrap</code>, the items wrap. Set it to <code>nowrap</code>, which is also the initial value, and they will instead shrink to fit the container because they are using initial flexbox values that allows items to shrink. Using <code>nowrap</code> would cause an overflow if the items were not able to shrink, or could not shrink small enough to fit.</p> + +<p>{{EmbedGHLiveSample("css-examples/flexbox/basics/flex-wrap.html", '100%', 400)}}</p> + +<p>Find out more about wrapping flex items in the guide <a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Mastering_Wrapping_of_Flex_Items">Mastering Wrapping of Flex Items</a>.</p> + +<h2 id="مختصرنویسی_با_flex-flow">مختصرنویسی با flex-flow</h2> + +<p>You can combine the two properties <code>flex-direction</code> and <code>flex-wrap</code> into the {{cssxref("flex-flow")}} shorthand. The first value specified is <code>flex-direction</code> and the second value is <code>flex-wrap</code>.</p> + +<p>In the live example below try changing the first value to one of the allowable values for <code>flex-direction</code> - <code>row</code>, <code>row-reverse</code>, <code>column</code> or <code>column-reverse</code>, and also change the second to <code>wrap</code> and <code>nowrap</code>.</p> + +<p>{{EmbedGHLiveSample("css-examples/flexbox/basics/flex-flow.html", '100%', 400)}}</p> + +<h2 id="مشخصات_آیتمهای_داخلی_فلکس">مشخصات آیتمهای داخلی فلکس</h2> + +<p>To have more control over flex items we can target them directly. We do this by way of three properties:</p> + +<ul> + <li>{{cssxref("flex-grow")}}</li> + <li>{{cssxref("flex-shrink")}}</li> + <li>{{cssxref("flex-basis")}}</li> +</ul> + +<p>We will take a brief look at these properties in this overview, and you can gain a fuller understanding in the guide <a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Controlling_Ratios_of_Flex_Items_Along_the_Main_Ax">Controlling Ratios of Flex Items on the Main Axis</a>.</p> + +<p>Before we can make sense of these properties we need to consider the concept of <strong>available space</strong>. What we are doing when we change the value of these flex properties is to change the way that available space is distributed amongst our items. This concept of available space is also important when we come to look at aligning items.</p> + +<p>If we have three 100 pixel-wide items in a container which is 500 pixels wide, then the space we need to lay out our items is 300 pixels. This leaves 200 pixels of available space. If we don’t change the initial values then flexbox will put that space after the last item.</p> + +<p><img alt="This flex container has available space after laying out the items." src="https://mdn.mozillademos.org/files/15620/Basics7.png" style="display: block; height: 198px; margin: 0px auto; width: 528px;"></p> + +<p>If we instead would like the items to grow and fill the space, then we need to have a method of distributing the leftover space between the items. This is what the <code>flex</code> properties that we apply to the items themselves, will do.</p> + +<h3 id="مشخصه_flex-basis">مشخصه <code>flex-basis</code></h3> + +<p>The <code>flex-basis</code> is what defines the size of that item in terms of the space it leaves as available space. The initial value of this property is <code>auto</code> — in this case the browser looks to see if the items have a size. In the example above, all of the items have a width of 100 pixels and so this is used as the <code>flex-basis</code>.</p> + +<p>If the items don’t have a size then the content's size is used as the flex-basis. This is why when we just declare <code>display: flex</code> on the parent to create flex items, the items all move into a row and take only as much space as they need to display their contents.</p> + +<h3 id="مشخصه_flex-grow">مشخصه <code>flex-grow</code></h3> + +<p>With the <code>flex-grow</code> property set to a positive integer, flex items can grow along the main axis from their <code>flex-basis</code>. This will cause the item to stretch and take up any available space on that axis, or a proportion of the available space if other items are allowed to grow too.</p> + +<p>If we gave all of our items in the example above a <code>flex-grow</code> value of 1 then the available space in the flex container would be equally shared between our items and they would stretch to fill the container on the main axis.</p> + +<p>The flex-grow property can be used to distribute space in proportion. If we give our first item a <code>flex-grow</code> value of 2 and the other items a value of 1, 2 parts will be given to the first item (100px out of 200px in the case of the example above), 1 part each the other two (50px each out of the 200px total).</p> + +<h3 id="مشخصه_flex-shrink">مشخصه <code>flex-shrink</code></h3> + +<p>Where the <code>flex-grow</code> property deals with adding space in the main axis, the <code>flex-shrink</code> property controls how it is taken away. If we do not have enough space in the container to lay out our items and <code>flex-shrink</code> is set to a positive integer the item can become smaller than the <code>flex-basis</code>. As with <code>flex-grow</code> different values can be assigned in order to cause one item to shrink faster than others — an item with a higher value set for <code>flex-shrink</code> will shrink faster than its siblings that have lower values.</p> + +<p>The minimum size of the item will be taken into account while working out the actual amount of shrinkage that will happen, which means that flex-shrink has the potential to appear less consistent than flex-grow in behavior. We’ll therefore take a more detailed look at how this algorithm works in the article Controlling Ratios of items along the main axis.</p> + +<div class="note"> +<p>Note that these values for <code>flex-grow</code> and <code>flex-shrink</code> are proportions. Typically if we had all of our items set to flex: <code>1 1 200px</code> and then wanted one item to grow at twice the rate, we would set that item to flex: <code>2 1 200px</code>. However you could use flex: <code>10 1 200px</code> and flex: <code>20 1 200px</code> if you wanted.</p> +</div> + +<h3 id="مختصرنویسی_مقادیر_برای_مشخصههای_فلکس">مختصرنویسی مقادیر برای مشخصههای فلکس</h3> + +<p>You will very rarely see the <code>flex-grow</code>, <code>flex-shrink</code>, and <code>flex-basis</code> properties used individually; instead they are combined into the {{cssxref("flex")}} shorthand. The <code>flex</code> shorthand allows you to set the three values in this order — <code>flex-grow</code>, <code>flex-shrink</code>, <code>flex-basis</code>.</p> + +<p>The live example below allows you to test out the different values of the flex shorthand; remember that the first value is <code>flex-grow</code>. Giving this a positive value means the item can grow. The second is <code>flex-shrink</code> — with a positive value the items can shrink, but only if their total values overflow the main axis. The final value is <code>flex-basis</code>; this is the value the items are using as their base value to grow and shrink from.</p> + +<p>{{EmbedGHLiveSample("css-examples/flexbox/basics/flex-properties.html", '100%', 510)}}</p> + +<p>There are also some predefined shorthand values which cover most of the use cases. You will often see these used in tutorials, and in many cases these are all you will need to use. The predefined values are as follows:</p> + +<ul> + <li><code>flex: initial</code></li> + <li><code>flex: auto</code></li> + <li><code>flex: none</code></li> + <li><code>flex: <positive-number></code></li> +</ul> + +<p>Setting <code>flex: initial</code> resets the item to the initial values of Flexbox. This is the same as <code>flex: 0 1 auto</code>. In this case the value of <code>flex-grow</code> is 0, so items will not grow larger than their <code>flex-basis</code> size. The value of <code>flex-shrink</code> is 1, so items can shrink if they need to rather than overflowing. The value of <code>flex-basis</code> is <code>auto</code>. Items will either use any size set on the item in the main dimension, or they will get their size from the content size.</p> + +<p>Using <code>flex: auto</code> is the same as using <code>flex: 1 1 auto</code>; everything is as with <code>flex:initial</code> but in this case the items can grow and fill the container as well as shrink if required.</p> + +<p>Using <code>flex: none</code> will create fully inflexible flex items. It is as if you wrote <code>flex: 0 0 auto</code>. The items cannot grow or shrink but will be laid out using flexbox with a <code>flex-basis</code> of <code>auto</code>.</p> + +<p>The shorthand you often see in tutorials is <code>flex: 1</code> or <code>flex: 2</code> and so on. This is as if you used <code>flex: 1 1 0</code>. The items can grow and shrink from a <code>flex-basis</code> of 0.</p> + +<p>Try these shorthand values in the live example below.</p> + +<p>{{EmbedGHLiveSample("css-examples/flexbox/basics/flex-shorthands.html", '100%', 510)}}</p> + +<h2 id="ترازبندی_همترازی_و_تقسیم_فضا_بین_بخشهای_داخلی_جعبه_محتوی_فلکس">ترازبندی, همترازی و تقسیم فضا بین بخشهای داخلی جعبه محتوی فلکس</h2> + +<p>A key feature of flexbox is the ability to align and justify items on the main- and cross-axes, and to distribute space between flex items.</p> + +<h3 id="align-items"><code>align-items</code></h3> + +<p>The {{cssxref("align-items")}} property will align the items on the cross axis.</p> + +<p>The initial value for this property is <code>stretch</code> and this is why flex items stretch to the height of the tallest one by default. They are in fact stretching to fill the flex container — the tallest item is defining the height of that.</p> + +<p>You could instead set <code>align-items</code> to <code>flex-start</code> in order to make the items line up at the start of the flex container, <code>flex-end</code> to align them to the end, or <code>center</code> to align them in the centre. Try this in the live example — I have given the flex container a height in order that you can see how the items can be moved around inside the container. See what happens if you set the value of align-items to:</p> + +<ul> + <li><code>stretch</code></li> + <li><code>flex-start</code></li> + <li><code>flex-end</code></li> + <li><code>center</code></li> +</ul> + +<p>{{EmbedGHLiveSample("css-examples/flexbox/basics/align-items.html", '100%', 520)}}</p> + +<h3 id="justify-content"><code>justify-content</code></h3> + +<p>The {{cssxref("justify-content")}} property is used to align the items on the main axis, the direction in which <code>flex-direction</code> has set the flow. The initial value is <code>flex-start</code> which will line the items up at the start edge of the container, but you could also set the value to <code>flex-end</code> to line them up at the end, or <code>center</code> to line them up in the centre.</p> + +<p>You can also use the value <code>space-between</code> to take all the spare space after the items have been laid out, and share it out evenly between the items so there will be an equal amount of space between each item. To cause an equal amount of space on the right and left of each item use the value <code>space-around</code>. With <code>space-around</code>, items have a half-size space on either end. Or, to cause items to have equal space around them use the value <code>space-evenly</code>. With <code>space-evenly</code>, items have a full-size space on either end.</p> + +<p>Try the following values of <code>justify-content</code> in the live example:</p> + +<ul> + <li><code>flex-start</code></li> + <li><code>flex-end</code></li> + <li><code>center</code></li> + <li><code>space-around</code></li> + <li><code>space-between</code></li> + <li><code>space-evenly</code></li> +</ul> + +<p>{{EmbedGHLiveSample("css-examples/flexbox/basics/justify-content.html", '100%', 380)}}</p> + +<p>In the article <a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Aligning_Items_in_a_Flex_Container">Aligning Items in a Flex Container</a> we will explore these properties in more depth, in order to have a better understanding of how they work. These simple examples however will be useful in the majority of use cases.</p> + +<h2 id="مراحل_بعدی">مراحل بعدی</h2> + +<p>After reading this article you should have an understanding of the basic features of Flexbox. In the next article we will look at <a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Relationship_of_Flexbox_to_Other_Layout_Methods">how this specification relates to other parts of CSS</a>.</p> diff --git a/files/fa/web/css/css_flexible_box_layout/index.html b/files/fa/web/css/css_flexible_box_layout/index.html new file mode 100644 index 0000000000..ffb152df28 --- /dev/null +++ b/files/fa/web/css/css_flexible_box_layout/index.html @@ -0,0 +1,163 @@ +--- +title: CSS Flexible Box Layout +slug: Web/CSS/CSS_Flexible_Box_Layout +tags: + - CSS + - CSS Flexible Boxes + - NeedsTranslation + - Overview + - Reference + - TopicStub +translation_of: Web/CSS/CSS_Flexible_Box_Layout +--- +<div>{{CSSRef}}</div> + +<p class="summary"><strong>CSS Flexible Box Layout</strong> is a module of <a href="/en-US/docs/Web/CSS">CSS</a> that defines a CSS box model optimized for user interface design, and the layout of items in one dimension. In the flex layout model, the children of a flex container can be laid out in any direction, and can “flex” their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated.</p> + +<h2 id="Basic_Example">Basic Example</h2> + +<p>In the following example a container has been set to <code>display: flex</code>, which means that the three child items become flex items. The value of <code>justify-content</code> has been set to <code>space-between</code> in order to space the items out evenly on the main axis. An equal amount of space is placed between each item with the left and right items being flush with the edges of the flex container. You can also see that the items are stretching on the cross axis, due to the default value of <code>align-items</code> being <code>stretch</code>. The items stretch to the height of the flex container, making them each appear as tall as the tallest item.</p> + +<p>{{EmbedGHLiveSample("css-examples/flexbox/basics/simple-example.html", '100%', 500)}}</p> + +<h2 id="Reference">Reference</h2> + +<h3 id="CSS_Properties">CSS Properties</h3> + +<div class="index"> +<ul> + <li>{{cssxref("align-content")}}</li> + <li>{{cssxref("align-items")}}</li> + <li>{{cssxref("align-self")}}</li> + <li>{{cssxref("flex")}}</li> + <li>{{cssxref("flex-basis")}}</li> + <li>{{cssxref("flex-direction")}}</li> + <li>{{cssxref("flex-flow")}}</li> + <li>{{cssxref("flex-grow")}}</li> + <li>{{cssxref("flex-shrink")}}</li> + <li>{{cssxref("flex-wrap")}}</li> + <li>{{cssxref("justify-content")}}</li> + <li>{{cssxref("order")}}</li> +</ul> +</div> + +<h3 id="Glossary_entries">Glossary entries</h3> + +<div class="index"> +<ul> + <li><a href="/en-US/docs/Glossary/Flexbox">Flexbox</a></li> + <li><a href="/en-US/docs/Glossary/Flex_Container">Flex Container</a></li> + <li><a href="/en-US/docs/Glossary/Flex_Item">Flex Item</a></li> + <li><a href="/en-US/docs/Glossary/Main_Axis">Main Axis</a></li> + <li><a href="/en-US/docs/Glossary/Cross_Axis">Cross Axis</a></li> + <li><a href="/en-US/docs/Glossary/Flex">Flex</a></li> +</ul> +</div> + +<h2 id="Guides">Guides</h2> + +<dl> + <dt><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox">Basic Concepts of Flexbox</a></dt> + <dd>An overview of the features of flexbox</dd> + <dt><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Relationship_of_Flexbox_to_Other_Layout_Methods">Relationship of flexbox to other layout methods</a></dt> + <dd>How flexbox relates to other layout methods, and other CSS specifications</dd> + <dt><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Aligning_Items_in_a_Flex_Container">Aligning items in a flex container</a></dt> + <dd>How the Box Alignment properties work with flexbox.</dd> + <dt><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Ordering_Flex_Items">Ordering flex items</a></dt> + <dd>Explaining the different ways to change the order and direction of items, and covering the potential issues in doing so.</dd> + <dt><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Controlling_Ratios_of_Flex_Items_Along_the_Main_Ax">Controlling Ratios of flex items along the main axis</a></dt> + <dd>This article explains the flex-grow, flex-shrink and flex-basis properties.</dd> + <dt><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Mastering_Wrapping_of_Flex_Items">Mastering wrapping of flex items</a></dt> + <dd>How to create flex containers with multiple lines and control the display of the items in those lines.</dd> + <dt><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Typical_Use_Cases_of_Flexbox">Typical use cases of flexbox</a></dt> + <dd>Common design patterns that are typical flexbox use cases.</dd> + <dt><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Backwards_Compatibility_of_Flexbox">Backwards compatibility of Flexbox</a></dt> + <dd>Browser status of flexbox, interoperability issues and supporting older browsers and versions of the spec</dd> +</dl> + +<ul> +</ul> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{ SpecName('CSS3 Flexbox') }}</td> + <td>{{ Spec2('CSS3 Flexbox') }}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p>{{CompatibilityTable()}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Firefox (Gecko)</th> + <th>Chrome</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatGeckoDesktop("20.0")}}</td> + <td>21.0{{property_prefix("-webkit")}}<br> + 29.0</td> + <td>10.0{{property_prefix("-ms")}}<br> + 11.0</td> + <td>12.10</td> + <td>6.1{{property_prefix("-webkit")}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Firefox Mobile (Gecko)</th> + <th>Android</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown()}}</td> + <td>4.4</td> + <td>11</td> + <td>12.10</td> + <td><span style="font-size: 12px; line-height: 18px;">7.1{{property_prefix("-webkit")}}</span></td> + </tr> + </tbody> +</table> +</div> + +<p> </p> + +<h2 id="See_also">See also</h2> + +<dl> + <dt><a href="https://github.com/philipwalton/flexbugs">Flexbugs</a></dt> + <dd>a community-curated list of flexbox browser bugs and workarounds</dd> + <dt><a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Mixins">Cross-browser Flexbox mixins</a></dt> + <dd>This article provides a set of mixins for those who want to create cross-browser flexbox experiences that even work in older browser that don't support the modern flexbox syntax</dd> +</dl> + +<p> </p> diff --git a/files/fa/web/css/flex_value/index.html b/files/fa/web/css/flex_value/index.html new file mode 100644 index 0000000000..2dd81e4740 --- /dev/null +++ b/files/fa/web/css/flex_value/index.html @@ -0,0 +1,53 @@ +--- +title: <flex> +slug: Web/CSS/flex_value +tags: + - سی اس اس + - قالب بندی + - وب +translation_of: Web/CSS/flex_value +--- +<div>{{CSSRef}}</div> + +<p><strong><code dir="ltr"><flex></code></strong> <a href="/en-US/docs/Web/CSS">CSS</a> <a href="/en-US/docs/Web/CSS/CSS_Types">data type</a> یک فاصله طولی منعطف را در یک جعبه محتوی گرید مشخص میکند. این نوع مقدار در {{cssxref("grid-template-columns")}}, {{cssxref("grid-template-rows")}} و سایر موارد مشابه استفاده میشود.</p> + +<h2 id="سینتکس">سینتکس</h2> + +<p>نوع داده <code><flex></code> به صورت {{cssxref("<number>")}} و در ادامه <a id="fr" name="fr"><code>fr</code></a> استفاده میشود. واحد <code>fr</code> کسری از فضای باقیمانده در جعبه محتوی گرید است. مانند سایر مقادیر در سیاساس، بین مقدار و واحد فاصلهای نیست.</p> + +<h2 id="مثال">مثال</h2> + +<pre class="brush: css">1fr /* استفاده از یک عدد طبیعی */ +2.5fr /* استفاده از یک عدد اعشاری */ +</pre> + +<h2 id="خصوصیات">خصوصیات</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">خصوصیت</th> + <th scope="col">وضعیت</th> + <th scope="col">توضیحات</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSS Grid", "#typedef-flex", "<flex>")}}</td> + <td>{{Spec2("CSS Grid")}}</td> + <td>تعریف اولیه.</td> + </tr> + </tbody> +</table> + +<h2 id="سازگاری_با_مرورگرها">سازگاری با مرورگرها</h2> + + + +<p>{{Compat("css.types.flex")}}</p> + +<h2 id="مقالات_مرتبط">مقالات مرتبط</h2> + +<ul> + <li><a href="/en-US/docs/Web/CSS/CSS_Grid_Layout">CSS Grid Layout</a></li> +</ul> diff --git a/files/fa/web/css/index.html b/files/fa/web/css/index.html new file mode 100644 index 0000000000..bfddd551f0 --- /dev/null +++ b/files/fa/web/css/index.html @@ -0,0 +1,84 @@ +--- +title: 'CSS: شیوهنامههای آبشاری' +slug: Web/CSS +tags: + - CSS + - Design + - Layout + - NeedsTranslation + - References + - TopicStub +translation_of: Web/CSS +--- +<p dir="rtl"><span class="seoSummary"><strong>شیوه نامههای آبشاری (CSS)</strong> یک زبان <a href="/fa/docs/DOM/stylesheet">شیوه نامه</a> است که نحوه نمایش یک سند در قالب <a href="/fa/docs/HTML" title="The HyperText Mark-up Language">HTML</a></span> یا <a href="/fa/docs/XML" title="fa/docs/XML">XML</a> (شامل زبانهای متنوعی مثل <a href="/fa/docs/SVG" title="fa/docs/SVG">SVG</a> یا <a href="/fa/docs/Web/MathML">MathML</a> یا {{Glossary("XHTML", "", 1)}}) را شرح می دهد<span class="seoSummary">. CSS نحوه رندر شدن عناصر روی صفحه نمایش، روی کاغذ، در گفتار ، یا روی دیگر رسانهها را شرح میدهد.</span></p> + +<p dir="rtl">CSS یکی از زبانهای اصلی <em>وب متن باز</em> و دارای استاندارد برمبنای <a class="external" href="http://w3.org/Style/CSS/#specs">خصوصیات W3C</a> است. در سطحهای مختلف، CSS1 که الان منسوخ شده است، CSS2.1 که یک توصیه است و <a href="/en-US/docs/CSS/CSS3" title="CSS3">CSS3</a>، که حالا به ماژولهای کوچکتر شکسته شده است، و در حال پیشرفت در مسیر استانداردسازی است توسعه داده شده است.</p> + +<ul class="card-grid" dir="rtl"> + <li><span>مرجع CSS</span> + + <p><a href="/fa/docs/CSS/CSS_Reference" title="en-US/docs/CSS/CSS_Reference">مرجع کامل CSS</a> ما برای <u>توسعه دهندگان وب فصلی</u> تمامی خصوصیات و مفاهیم CSS را شرح میدهد.</p> + </li> + <li><span>آموزش CSS</span> + <p><a href="fa/docs/Learn/CSS">آموزشگاه css ما</a> حاوی آموزشهای فراوان برای رساندن شما از سطح مبتدی به حرفهای است و تمامی اصول اساسی را پوشش میدهد.</p> + </li> + <li><span>معرفی CSS</span> + <p>اگر شما در توسعه وب تازهکار هستید، حتما مقاله <a href="en-US/docs/Learn/Getting_started_with_the_web/CSS_basics">مقدمات ccs</a> ما را بخوانید تا بدانید که CSS چیست و چگونه باید آن را به کار گرفت.</p> + </li> +</ul> + +<div class="row topicpage-table" dir="rtl"> +<div class="section"> +<h2 class="Documentation" id="Documentation" name="Documentation">مستندات و آموزشها در مورد CSS</h2> + +<dl> + <dt>مفاهیم کلیدی CSS</dt> + <dd><a href="/en-US/docs/CSS/Syntax" title="/en-US/docs/CSS/Syntax">نحو و قالب زبان</a> و معرفی مفاهیم بنیادی مثل <a href="/en-US/docs/CSS/Specificity" title="Specificity">ویژگی</a> و <a href="/en-US/docs/CSS/inheritance" title="inheritance">ارثبری</a>، <a href="/en-US/docs/CSS/box_model" title="Box model">مدل جعبهای</a> و <a href="/en-US/docs/CSS/margin_collapsing" title="Margin collapsing">حاشیه سقوط</a>، <a href="/en-US/docs/CSS/Understanding_z-index/The_stacking_context" title="The stacking context">پشتهسازی</a> و محتوای <a href="/en-US/docs/CSS/block_formatting_context" title="block formatting context">فرمتدهی جعبهای</a>، یا مقادیر <a href="/en-US/docs/CSS/initial_value" title="initial value">اولیه</a>، <a href="/en-US/docs/CSS/computed_value" title="computed value">محاسبه شده</a>، <a href="/en-US/docs/CSS/used_value" title="used value">استفاده شده</a> و <a href="/en-US/docs/CSS/actual_value" title="actual value">واقعی</a> را شرح میدهد. موجودیتهایی مثل <a href="/en-US/docs/CSS/Shorthand_properties" title="CSS/Shorthand_properties">خصوصیات مختصر شده CSS</a> نیز تعریف شدهاند.</dd> + <dt><a href="/en-US/docs/Web/Guide/CSS" title="/en-US/docs/Web/Guide/CSS">راهنمای توسعه دهنده CSS</a></dt> + <dd>مقالاتی برای کمک به شما تا تکنیکهای CSS را یاد بگیرید و محتوی خودتان را درخشان کنید.</dd> +</dl> + +<h2 class="Tools" id="Tools" name="Tools">ابزارهای سادهسازی توسعه CSS</h2> + +<ul> + <li><a class="external" href="http://jigsaw.w3.org/css-validator/">سرویس تایید اعتبار W3C CSS</a> چک میکند که یک CSS داده شده معتبر است. این یک ابزار ارزشمند است.</li> + <li><a class="link-https" href="https://addons.mozilla.org/en-US/firefox/addon/1843">الحاقی فایرباگ</a><span class="external"> فایرفاکس، یک الحاقی معروف برای هدایت ویرایش زنده</span> CSS روی سایتهای ملاقات شده است. برای تست بعضی تستها خیلی کاربردی است، بهرحال این الحاقی کارهای بیشتری نیز انجام میدهد.</li> + <li><a class="link-https" href="https://addons.mozilla.org/en-US/firefox/addon/60">الحاقی توسعه وب</a> نیز اجازه میدهد تا بهصورت زنده CSS سایتهای دیده شده را ببینید و ویرایش کنید. سادهتر از فایرباگ است، بهرحال قدرت کمتری دارد.</li> + <li><a class="external link-https" href="https://addons.mozilla.org/en-US/firefox/addon/179">الحاقی EditCSS</a> فایرفاکس اجازه ویرایش CSS در نوار کناری را میدهد.</li> +</ul> + +<h2 class="Related_Topics" id="Related_Topics" name="Related_Topics">موضوعات وابسته</h2> + +<ul> + <li><a href="/en-US/learn/css" title="https://developer.mozilla.org/en-US/learn/css">منابع CSS </a>را بدانید.</li> + <li>زبانهای وب بازی که اغلب CSS روی آنها اعمال شده است: <a href="/en-US/docs/HTML" title="en-US/docs/HTML">HTML</a>، <a href="/en-US/docs/SVG" title="SVG">SVG</a>، <a href="/en-US/docs/XHTML" title="en-US/docs/XHTML">XHTML</a>، <a href="/en-US/docs/XML" title="en-US/docs/XML">XML</a>.</li> + <li>تکنولوژیهای موزیلا که استفاده وسیعی از CSS میکنند: <a href="/en-US/docs/XUL" title="en-US/docs/XUL">XUL</a>، <a href="/en-US/docs/Extensions" title="en-US/docs/Extensions">الحاقیها</a> و <a href="/en-US/docs/Themes" title="en-US/docs/Themes">تمهای</a> فایرفاکس و تاندربیرد.</li> +</ul> +</div> + +<div class="section"> +<h2 class="Related_Topics" id="News" name="News">اخبار</h2> + +<ul> + <li><a href="http://www.w3.org/TR/pointerevents/" title="http://www.w3.org/TR/pointerevents/">Pointer Events</a> reached the <em>Candidate Recommandation</em> status, meaning that the CSS property <code>touch-action</code>, currently only implemented in IE10 (with the <code>-ms-</code> prefix), is no more experimental. <em>(May 6th, 2013)</em></li> + <li>Gecko's support of <a href="/en-US/docs/CSS/Tutorials/Using_CSS_flexible_boxes" title="/en-US/docs/CSS/Tutorials/Using_CSS_flexible_boxes"><em>flexible boxes</em></a> has been adapted to match a recent specification clarification: from Firefox 23, and already in Nightly, {{cssxref("::before")}} and {{cssxref("::after")}} will be flex items, and as such can be repositioned using {{cssxref("order")}} and {{cssxref("align-self")}}. <em>(May 3rd, 2013)</em></li> + <li>The CSSWG published a <a href="http://www.w3.org/TR/2013/WD-selectors4-20130502/">new working draft</a> of the Selectors Level 4 specification. It still is in the <em>exploring phase</em> and most of the new features are not supported anywhere, but it refines the behavior of scoped selectors and added two new ones: <code>:blank</code>, a relaxed {{cssxref(":empty")}} matching elements only containing spaces and carriage returns, and <code>:placeholder-shown</code>. The two pseudo-classes <code>:matches()</code> and {{cssxref(":not", ":not()")}} have been tweaked to allow more complex parameters. But beware, as this is still a very early draft, these features may change in the future. <em>(May 2nd, 2013)</em></li> +</ul> + +<h2 class="Community" id="Community" name="Community">کمک گرفتن از کمیتهها</h2> + +<p>شما در مورد مشکلات مربوط به CSS احتیاج به کمک دارید و نمیتوانید راهحل را در مستندات پیدا کنید؟</p> + +<ul> + <li><a href="/en-US/docs/CSS/Common_CSS_Questions" title="en-US/docs/CSS/Common_CSS_Questions">سوالات معمول CSS</a> که تذکراتی جهت حل مشکلات معمول CSS را ارایه میدهد.</li> + <li>به <a href="http://stackoverflow.com/questions/tagged/css" title="http://stackoverflow.com/questions/tagged/css">Stack Overflow</a> بروید، یک سایت مشترک ساحته شده و نگهدارنده Q&A است و میتوانید پاسخ سوال خودتان را جستجو و پیدا کنید. اگر نه شما قادر خواهید بود که سوال خود را در آنجا مطرح کنید.</li> + <li>طرح مشورت در انجمن، که CSS و HTML را پوشش میدهند: سوال خود را در کانال IRC موزیلا بپرسید: <a class="link-irc" href="irc://irc.mozilla.org/css">#css</a> + <ul> + <li>سوال خود را در <a class="external" href="http://www.css-discuss.org/">CSS-Discuss site and list</a> بپرسید</li> + </ul> + </li> +</ul> +</div> +</div> + +<p dir="rtl"></p> diff --git a/files/fa/web/css/margin/index.html b/files/fa/web/css/margin/index.html new file mode 100644 index 0000000000..c29a75ea06 --- /dev/null +++ b/files/fa/web/css/margin/index.html @@ -0,0 +1,207 @@ +--- +title: margin +slug: Web/CSS/margin +translation_of: Web/CSS/margin +--- +<div dir="rtl">{{CSSRef()}}</div> + +<h2 dir="rtl" id="خلاصه_مطلب">خلاصه مطلب</h2> + +<p dir="rtl">خواصیت margin درCSS حاشیه را برای چهار طرف عنصر مشخص می کند. این خواصیت خلاصه شده چهار خواصیت {{ Cssxref("margin-top") }} ، {{ Cssxref("margin-right") }} ، {{ Cssxref("margin-bottom") }} و {{ Cssxref("margin-left") }} می باشد که برای جلوگیری از مقدار دهی به هر کدام از این خواص تعبیه شده است.</p> + +<p dir="rtl">همچنین قابلیت مقداردهی با مقادیر منفی را نیز داراست.</p> + +<h2 dir="rtl" id="روش_استفاده">روش استفاده</h2> + +<pre class="brush:css" dir="rtl">/* به هر چهار جهت این مقدار اعمال می گردد */ +margin: 1em; + +/*افقی (قسمت چپ و راست) | عمودی (قسمت بالا و پایین) */ +margin: 5% auto; + +/* پایین | افقی(چپ و راست) | بالا */ +margin: 1em auto 2em; + +/* چپ | پایین | راست | بالا */ +margin: 2px 1em 0 auto; + +margin: وارث; +</pre> + +<h3 dir="rtl" id="مقادیر">مقادیر</h3> + +<p dir="rtl">یک، دو، سه و یا چهار عدد از مقادیر زیر را می پذیرد:</p> + +<dl> + <dt dir="rtl"><code><length></code></dt> + <dd dir="rtl">مقدار ثابتی را مشخص می کند. مقادیر منفی مورد قبول هستند. مقادیر قابل قبول را در {{cssxref("<length>")}} مشاهده کنید.</dd> + <dt dir="rtl"><code><percentage></code></dt> + <dd dir="rtl">A {{cssxref("<percentage>")}} relative to the <strong>width</strong> of the containing block. Negative values are allowed.</dd> + <dt dir="rtl"><code>auto</code></dt> + <dd dir="rtl"><code>auto </code>is replaced by some suitable value, e.g. it can be used for centering of blocks.<br> + <code>div { width:50%; margin:0 auto; }</code> centers the div container horizontally.</dd> +</dl> + +<ul dir="rtl"> + <li><strong>One</strong> single value applies to all <strong>four sides</strong>.</li> + <li><strong>Two</strong> values apply first to <strong>top and bottom</strong>, the second one to <strong>left and right</strong>.</li> + <li><strong>Three</strong> values apply first to <strong>top</strong>, second to <strong>left and right</strong> and third to <strong>bottom</strong>.</li> + <li><strong>Four</strong> values apply to <strong>top</strong>, <strong>right</strong>, <strong>bottom</strong> and <strong>left</strong> in that order (clockwise).</li> +</ul> + +<h3 dir="rtl" id="Formal_syntax">Formal syntax</h3> + +<pre class="syntaxbox" dir="rtl">{{csssyntax("margin")}}</pre> + +<h2 dir="rtl" id="Examples">Examples</h2> + +<h3 dir="rtl" id="Simple_example">Simple example</h3> + +<h4 dir="rtl" id="HTML">HTML</h4> + +<pre class="brush: html" dir="rtl"><div class="ex1"> + margin: auto; + background: gold; + width: 66%; +</div> +<div class="ex2"> + margin: 20px 0 0 -20px; + background: gold; + width: 66%; +</div></pre> + +<h4 dir="rtl" id="CSS">CSS</h4> + +<pre class="brush: css; highlight:[2,7]" dir="rtl">.ex1 { + margin: auto; + background: gold; + width: 66%; +} +.ex2 { + margin: 20px 0px 0 -20px; + background: gold; + width: 66%; +}</pre> + +<p dir="rtl">{{ EmbedLiveSample('Margin_Exemples') }}</p> + +<h3 dir="rtl" id="Another_example">Another example</h3> + +<pre class="brush: css" dir="rtl">margin: 5%; /* all sides 5% margin */ + +margin: 10px; /* all sides 10px margin */ + +margin: 1.6em 20px; /* top and bottom 1.6em, left and right 20px margin */ + +margin: 10px 3% 1em; /* top 10px, left and right 3%, bottom 1em margin */ + +margin: 10px 3px 30px 5px; /* top 10px, right 3px, bottom 30px, left 5px margin */ + +margin: 1em auto; /* 1em margin on top and bottom, box is horizontally centered */ + +margin: auto; /* box is horizontally centered, 0 margin on top and bottom */ +</pre> + +<h2 dir="rtl" id="Horizontal_centering_with_margin_0_auto">Horizontal centering with <code>margin: 0 auto;</code></h2> + +<p dir="rtl">To center something horizontally in modern browsers, use <code><a href="/en-US/docs/Web/CSS/display">display</a>: flex; <a href="/en-US/docs/Web/CSS/justify-content">justify-content</a>: center;</code> .</p> + +<p dir="rtl">However, in older browsers like IE8-9, these are not available. In order to center an element inside its parent, use <code>margin: 0 auto;</code></p> + +<h2 dir="rtl" id="Specifications">Specifications</h2> + +<table class="standard-table" dir="rtl"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{ SpecName('CSS3 Box', '#margin', 'margin') }}</td> + <td>{{ Spec2('CSS3 Box') }}</td> + <td>No significant change.</td> + </tr> + <tr> + <td>{{ SpecName('CSS3 Transitions', '#animatable-css', 'margin') }}</td> + <td>{{ Spec2('CSS3 Transitions') }}</td> + <td>Defines <code>margin</code> as animatable.</td> + </tr> + <tr> + <td>{{ SpecName('CSS2.1', 'box.html#margin-properties', 'margin') }}</td> + <td>{{ Spec2('CSS2.1') }}</td> + <td>Removes its effect on inline elements.</td> + </tr> + <tr> + <td>{{ SpecName('CSS1', '#margin', 'margin') }}</td> + <td>{{ Spec2('CSS1') }}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 dir="rtl" id="Browser_compatibility">Browser compatibility</h2> + +<p dir="rtl">{{ CompatibilityTable() }}</p> + +<div dir="rtl" id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>1.0</td> + <td>{{ CompatGeckoDesktop("1") }}</td> + <td>3.0</td> + <td>3.5</td> + <td>1.0 (85)</td> + </tr> + <tr> + <td><code>auto</code> value</td> + <td>1.0</td> + <td>{{ CompatGeckoDesktop("1") }}</td> + <td>6.0 (strict mode)</td> + <td>3.5</td> + <td>1.0 (85)</td> + </tr> + </tbody> +</table> +</div> + +<div dir="rtl" id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>1.0</td> + <td>{{ CompatGeckoMobile("1") }}</td> + <td>6.0</td> + <td>6.0</td> + <td>1.0</td> + </tr> + </tbody> +</table> +</div> + +<h2 dir="rtl" id="See_also">See also</h2> + +<ul> + <li dir="rtl"><a class="internal" href="/en/CSS/margin_collapsing" title="en/CSS/margin collapsing">Margin collapsing</a></li> +</ul> diff --git a/files/fa/web/css/media_queries/index.html b/files/fa/web/css/media_queries/index.html new file mode 100644 index 0000000000..e1f92ab511 --- /dev/null +++ b/files/fa/web/css/media_queries/index.html @@ -0,0 +1,131 @@ +--- +title: Media queries +slug: Web/CSS/Media_Queries +tags: + - CSS + - CSS3 Media Queries + - Media Queries + - NeedsTranslation + - Overview + - Reference + - Responsive Design + - TopicStub +translation_of: Web/CSS/Media_Queries +--- +<div>{{CSSRef("CSS3 Media Queries")}}</div> + +<p><strong>Media Queries</strong> are a key component of <a href="/en-US/docs/Web/Apps/Progressive/Responsive">responsive design</a>, which make it possible for CSS to adapt based on various parameters or device characteristics. For example, a media query can apply different styles if the screen is smaller than a certain size, or based on whether the user is holding their device in portrait or landscape mode. The {{cssxref("@media")}} at-rule is used to conditionally apply styles to a document.</p> + +<p>In addition, the media query syntax is also used in other contexts, such as in the {{HTMLElement("source")}} element's {{htmlattrxref("media", "source")}} attribute, which can be set to a media query string to use to determine whether or not to use that source when selecting the specific image to use in a {{HTMLElement("picture")}} element.</p> + +<p>In addition, the {{domxref("Window.matchMedia()")}} method can be used to test the window against a media query. You can also use {{domxref("MediaQueryList.addListener()")}} to be notified whenever the state of the queries changes. With this functionality, your site or app can respond to changes in the device configuration, orientation, or state.</p> + +<p>You can learn more about programmatically using media queries in <a href="/en-US/docs/Web/CSS/Media_Queries/Testing_media_queries">Testing media queries</a>.</p> + +<h2 id="Reference">Reference</h2> + +<h3 id="At-rules">At-rules</h3> + +<div class="index"> +<ul> + <li>{{cssxref("@import")}}</li> + <li>{{cssxref("@media")}}</li> +</ul> +</div> + +<h2 id="Guides">Guides</h2> + +<dl> + <dt><a href="/en-US/docs/Web/CSS/Media_Queries/Using_media_queries">Using media queries</a></dt> + <dd>Introduces media queries, their syntax, and the operators and media features which are used to construct media query expressions.</dd> + <dt><a href="/en-US/docs/Web/CSS/Media_Queries/Testing_media_queries">Testing media queries</a></dt> + <dd>Describes how to test media queries from your JavaScript code, programmatically, to determine the state of the device, and to set up listeners that let your code be notified when the results of media queries change (such as when the user rotates the screen, causing an orientation change).</dd> +</dl> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('CSS3 Conditional')}}</td> + <td>{{Spec2('CSS3 Conditional')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('CSS4 Media Queries')}}</td> + <td>{{Spec2('CSS4 Media Queries')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('CSS3 Media Queries')}}</td> + <td>{{Spec2('CSS3 Media Queries')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('CSS2.1', 'media.html')}}</td> + <td>{{Spec2('CSS2.1')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>1.0</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop(1.7)}}</td> + <td>9.0</td> + <td>9.2</td> + <td>1.3</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>1.0</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile(1.7)}}</td> + <td>9.0</td> + <td>9.0</td> + <td>3.1</td> + </tr> + </tbody> +</table> +</div> diff --git a/files/fa/web/css/media_queries/ابزار-تست-رسانه-پاسخگو/index.html b/files/fa/web/css/media_queries/ابزار-تست-رسانه-پاسخگو/index.html new file mode 100644 index 0000000000..286a3e8ba2 --- /dev/null +++ b/files/fa/web/css/media_queries/ابزار-تست-رسانه-پاسخگو/index.html @@ -0,0 +1,331 @@ +--- +title: ابزار تست رسانه پاسخگو +slug: Web/CSS/Media_Queries/ابزار-تست-رسانه-پاسخگو +translation_of: Web/CSS/Media_Queries/Using_media_queries +--- +<div dir="rtl">{{cssref}}</div> + +<p dir="rtl"> ابزارهای تست پاسخگو بسیار مفید هستند، زمانی که می خواهید سبک CSS را طبق نوع کلی دستگاه (مانند اندازه چاپ در مقابل سایز صفحه نمایش)، ویژگی های خاص (مانند عرض مرورگر رسانه) یا محیط (مانند شرایط نور محیط) استفاده کنید. با انواع مختلفی از دستگاه های متصل به اینترنت که امروزه در دسترس ما هستند و با وجود ابزارهای چند رسانه ای با اندازه های بیشمار، ابزار تست پاسخگو رسانه ها یک ابزار حیاتی برای ساخت وب سایت ها و برنامه هایی با سیستم طراحی حرفه ای جهت کار بر روی هر سخت افزاری که کاربران ممکن است با آن کار کنند، بشمار میرود.</p> + +<h2 dir="rtl" id="هدف_قرار_دادن_انواع_رسانه_ها"><span class="short_text" id="result_box" lang="fa"><span>هدف قرار دادن انواع رسانه ها</span></span></h2> + +<p dir="rtl">انواع رسانه ها دسته کلی یک دستگاه مشخص را توصیف می کنند. اگر چه وبسایت ها معمولا با صفحه نمایش طراحی شده اند، ممکن است بخواهید سبکهایی را ایجاد کنید که دستگاه هایی خاص مانند چاپگرها یا صفحه نمایش مبتنی بر صدا را هدف قرار میدهند. به عنوان مثال، این کد CSS چاپگر ها را هدف قرار میدهد :</p> + +<pre class="brush: css">@media print { ... }</pre> + +<p dir="rtl">همچنین می توانید به راحتی چندین دستگاه را هدف قرار دهید. به عنوان مثال، دستور<code>@media</code> با استفاده از دو ابزار رسانه پاسخگو، صفحه نمایش و همینطور چاپگر را هدف قرار میدهد:</p> + +<pre class="brush: css" dir="rtl">@media screen, print { ... }</pre> + +<p dir="rtl"><span id="result_box" lang="fa"><span class="alt-edited">برای مشاهده لیستی از رسانه های مختلف روی<a href="/fa-IR/docs/CSS/@media#Media_types"> انواع رسانه</a> کلید کنید. از آنجایی که دستگاهها را فقط در شرایط بسیار وسیع توصیف می کنند، فقط تعداد کمی از آنها در دسترس هستند؛ برای اختصاص ویژگی های خاص تر، از <em>ویژگی های رسانه</em> استفاده کنید.</span></span></p> + +<h2 dir="rtl" id="Targeting_media_features">Targeting media features</h2> + +<p><a href="/en-US/docs/CSS/@media#Media_features">Media features</a> describe the specific characteristics of a given {{glossary("user agent")}}, output device, or environment. For instance, you can apply specific styles to widescreen monitors, computers that use mice, or to devices that are being used in low-light conditions. This example applies styles when the user's <em>primary</em> input mechanism (such as a mouse) can hover over elements:</p> + +<pre class="brush: css"><a href="/en-US/docs/CSS/@media">@media</a> (hover: hover) { ... }</pre> + +<p>Many media features are <em>range features</em>, which means they can be prefixed with "min-" or "max-" to express "minimum condition" or "maximum condition" constraints. For example, this CSS will apply styles only if your browser's {{glossary("viewport")}} is equal to or narrower than 12,450 pixels:</p> + +<pre class="brush: css">@media (max-width: 12450px) { ... }</pre> + +<p>If you create a media feature query without specifying a value, the nested styles will be used as long as the feature's value is non-zero. For example, this CSS will apply to any device with a color screen:</p> + +<pre class="brush: css">@media (color) { ... }</pre> + +<p>If a feature doesn't apply to the device on which the browser is running, expressions involving that media feature are always false. For example, the styles nested inside the following query will never be used, because no speech-only device has a screen aspect ratio:</p> + +<pre class="brush: css">@media speech and (aspect-ratio: 11/5) { ... }</pre> + +<p>For more media feature examples, please see the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media#Media_features">reference page</a> for each specific feature.</p> + +<h2 id="Creating_complex_media_queries">Creating complex media queries</h2> + +<p>Sometimes you may want to create a media query that depends on multiple conditions. This is where the <em>logical operators</em> come in: <code>not</code>, <code>and</code>, and <code>only</code>. Furthermore, you can combine multiple media queries into a <em>comma-separated list</em>; this allows you to apply the same styles in different situations.</p> + +<p>In the previous example, we've already seen the <code>and</code> operator used to group a media <em>type</em> with a media <em>feature</em>. The <code>and</code> operator can also combine multiple media features into a single media query. The <code>not</code> operator, meanwhile, negates a media query, basically reversing its normal meaning. The <code>only</code> operator prevents older browsers from applying the styles.</p> + +<div class="note"> +<p><strong>Note:</strong> In most cases, the <code>all</code> media type is used by default when no other type is specified. However, if you use the <code>not</code> or <code>only</code> operators, you must explicitly specify a media type.</p> +</div> + +<h3 id="and"><code>and</code></h3> + +<p>The <code>and</code> keyword combines a media feature with a media type <em>or</em> other media features. This example combines two media features to restrict styles to landscape-oriented devices with a width of at least 30 ems:</p> + +<pre class="brush: css">@media (min-width: 30em) and (orientation: landscape) { ... }</pre> + +<p>To limit the styles to devices with a screen, you can chain the media features to the <code>screen</code> media type:</p> + +<pre class="brush: css">@media screen and (min-width: 30em) and (orientation: landscape) { ... }</pre> + +<h3 id="comma-separated_lists">comma-separated lists</h3> + +<p>You can use a comma-separated list to apply styles when the user's device matches any one of various media types, features, or states. For instance, the following rule will apply its styles if the user's device has either a minimum height of 680 pixels <em>or</em> is a screen device in portrait mode:</p> + +<pre class="brush: css">@media (min-height: 680px), screen and (orientation: portrait) { ... }</pre> + +<p>Taking the above example, if the user had a printer with a page height of 800 pixels, the media statement would return true because the first query would apply. Likewise, if the user were on a smartphone in portrait mode with a viewport height of 480 pixels, the second query would apply and the media statement would still return true.</p> + +<h3 id="not"><code>not</code></h3> + +<p>The <code>not</code> keyword inverts the meaning of an entire media query. It will only negate the specific media query it is applied to. (Thus, it will not apply to every media query in a comma-separated list of media queries.) The <code>not</code> keyword can't be used to negate an individual feature query, only an entire media query. The <code>not</code> is evaluated last in the following query:</p> + +<pre class="brush: css">@media not all and (monochrome) { ... } +</pre> + +<p>... so that the above query is evaluated like this:</p> + +<pre class="brush: css">@media not (all and (monochrome)) { ... } +</pre> + +<p>... rather than like this:</p> + +<pre class="example-bad brush: css">@media (not all) and (monochrome) { ... }</pre> + +<p>As another example, the following media query:</p> + +<pre class="brush: css">@media not screen and (color), print and (color) { ... } +</pre> + +<p>... is evaluated like this:</p> + +<pre class="brush: css">@media (not (screen and (color))), print and (color) { ... }</pre> + +<h3 id="only"><code>only</code></h3> + +<p>The <code>only</code> keyword prevents older browsers that do not support media queries with media features from applying the given styles. <em>It has no effect on modern browsers.</em></p> + +<pre class="brush: html"><link rel="stylesheet" media="only screen and (color)" href="modern-styles.css" /> +</pre> + +<h2 id="Mozilla-specific_media_features">Mozilla-specific media features</h2> + +<p>Mozilla offers several Gecko-specific media features. Some of these may be proposed as official media features in the future.</p> + +<ul> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-mac-graphite-theme">-moz-mac-graphite-theme</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-maemo-classic">-moz-maemo-classic</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-device-pixel-ratio">-moz-device-pixel-ratio</a> {{deprecated_inline("16")}}</li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-os-version">-moz-os-version</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-scrollbar-end-backward">-moz-scrollbar-end-backward</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-scrollbar-end-forward">-moz-scrollbar-end-forward</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-scrollbar-start-backward">-moz-scrollbar-start-backward</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-scrollbar-start-forward">-moz-scrollbar-start-forward</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-scrollbar-thumb-proportional">-moz-scrollbar-thumb-proportional</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-touch-enabled">-moz-touch-enabled</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-windows-accent-color-in-titlebar">-moz-windows-accent-color-in-titlebar</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-windows-classic">-moz-windows-classic</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-windows-compositor">-moz-windows-compositor</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-windows-default-theme">-moz-windows-default-theme</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-windows-glass">-moz-windows-glass</a></li> + <li><a href="/en-US/docs/Web/CSS/@media/-moz-windows-theme">-moz-windows-theme</a></li> +</ul> + +<h2 id="WebKit-specific_media_features">WebKit-specific media features</h2> + +<p id="-webkit-transform-3d">For WebKit-specific media features, please see the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media#Media_features">reference page</a> for each specific feature.</p> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome("21")}}</td> + <td>{{CompatGeckoDesktop("1.9.1")}}</td> + <td>{{CompatIE("9.0")}}</td> + <td>{{CompatOpera("9")}}</td> + <td>{{CompatSafari("4")}}</td> + </tr> + <tr> + <td><code>grid</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}} <sup>[1]</sup></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>resolution</code></td> + <td>{{CompatChrome("29")}}</td> + <td>{{CompatGeckoDesktop("1.9.1")}} <sup>[2]</sup><br> + {{CompatGeckoDesktop("8.0")}} <sup>[3]</sup></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>scan</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}<sup>[4]</sup></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>-webkit-min-device-pixel-ratio</code>, <code>-webkit-max-device-pixel-ratio</code></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}<sup>[7]</sup></td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>-webkit-transform-3d</code></td> + <td>{{CompatVersionUnknown}}<sup>[5]</sup></td> + <td>{{CompatGeckoDesktop("49")}}<sup>[6]</sup></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}<sup>[5]</sup></td> + <td>{{CompatSafari("1.0")}}<sup>[5]</sup></td> + </tr> + <tr> + <td><code>-webkit-transform-2d</code></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}<sup>[5]</sup></td> + <td>{{CompatSafari("1.0")}}<sup>[5]</sup></td> + </tr> + <tr> + <td><code>-webkit-transition</code></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}<sup>[5]</sup></td> + <td>{{CompatSafari("1.0")}}<sup>[5]</sup></td> + </tr> + <tr> + <td><code>display-mode</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoDesktop("47")}}<sup>[8]</sup></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + <tr> + <td><code>grid</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>resolution</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>scan</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>-webkit-min-device-pixel-ratio</code>, <code>-webkit-max-device-pixel-ratio</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>-webkit-transform-3d</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>-webkit-transform-2d</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>-webkit-transition</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>display-mode</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile(47)}}<sup>[8]</sup></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] <code>grid</code> media type is not supported.</p> + +<p>[2] Supports {{cssxref("<integer>")}} values only.</p> + +<p>[3] Supports {{cssxref("<number>")}} values, as per the spec.</p> + +<p>[4] <code>tv</code> media type is not supported.</p> + +<p>[5] See {{WebKitBug(22494)}}.</p> + +<p>[6] Implemented for Web compatibility reasons in Gecko 46.0 {{geckoRelease("46.0")}} behind the preference <code>layout.css.prefixes.webkit</code> defaulting to <code>false</code>. See {{bug(1239799)}}. Since Gecko 49.0 {{geckoRelease("49")}} <code>layout.css.prefixes.webkit</code> defaults to <code>true</code>.</p> + +<p>[7] Implemented as aliases for <code>min--moz-device-pixel-ratio</code> and <code>max--moz-device-pixel-ratio</code> for Web compatibility reasons in Gecko 45.0 {{geckoRelease("45.0")}} (see {{bug(1176968)}}) behind the preferences <code>layout.css.prefixes.webkit</code> and <code>layout.css.prefixes.device-pixel-ratio-webkit</code>, defaulting to <code>false</code>. Since Gecko 49.0 {{geckoRelease("49")}} <code>layout.css.prefixes.webkit</code> defaults to <code>true</code>.</p> + +<p>[8] Only the <code>fullscreen</code> and <code>browser</code> values of <code>display-mode</code> were supported in 47. <code>minimal-ui</code> and <code>standalone</code> were added in Firefox 57.</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a class="internal" href="/en-US/docs/CSS/@media#Media_types">Media types</a></li> + <li><a href="/en-US/docs/CSS/@media#Media_features">Media features</a></li> + <li><a href="/en-US/docs/CSS/Using_media_queries_from_code">Testing media queries using code</a></li> + <li><a href="http://davidwalsh.name/animate-media-queries">CSS Animations Between Media Queries</a></li> +</ul> diff --git a/files/fa/web/css/position/index.html b/files/fa/web/css/position/index.html new file mode 100644 index 0000000000..d0ccad0e5f --- /dev/null +++ b/files/fa/web/css/position/index.html @@ -0,0 +1,173 @@ +--- +title: موقعیت +slug: Web/CSS/position +translation_of: Web/CSS/position +--- +<p dir="rtl">{{CSSRef}}</p> + +<h2 dir="rtl" id="خلاصه">خلاصه</h2> + +<p dir="rtl">ویژگی <code style="font-size: 14px;">position <a href="/en-US/docs/CSS" title="/en-US/docs/CSS">CSS</a></code> قوانین دیگری برای موقعیت دادن به عناصر انتخاب میکند، طراحی شده تا برای افکتهای انیمیشن نوشته شده مفید باشد.</p> + +<p dir="rtl">{{cssinfo}}</p> + +<p dir="rtl">یک <strong>عنصر موقعیت گرفته</strong> عنصری است که ویژگی موقعیت <a href="/en-US/docs/CSS/computed_value" title="/en-US/docs/CSS/computed_value">محاسبه شده</a> relative، absolute، یا fixed است.</p> + +<p dir="rtl">یک <strong>عنصر مستقل موقعیت گرفته</strong> شده عنصری است که ویژگی موقعیت <a href="/en-US/docs/CSS/computed_value" title="/en-US/docs/CSS/computed_value">محاسبه شده</a> absolute یا fixed است.</p> + +<p dir="rtl">{{Cssxref("top")}}، {{Cssxref("right")}}، {{Cssxref("bottom")}}، و {{Cssxref("left")}} ویژگیهایی هستند که موقعیت عناصر موقعیت داده شده را مشخص میکنند.</p> + +<h2 dir="rtl" id="نحو">نحو</h2> + +<p dir="rtl"> </p> + +<pre class="twopartsyntaxbox" dir="rtl" style="margin-top: 0px; padding: 0px; white-space: normal; font-size: 14px; line-height: 18px;"><a href="/en-US/docs/CSS/Value_definition_syntax" title="/en-US/docs/CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("position")}}</pre> + +<pre dir="rtl" style="margin-bottom: 1.286em; padding: 0px; white-space: normal; font-size: 14px; line-height: 18px;">position: static position: relative position: absolute position: fixed position: inherit</pre> + +<h3 dir="rtl" id="مقادیر">مقادیر</h3> + +<p dir="rtl"><strong><em>static</em></strong></p> + +<p dir="rtl">رفتار عادی. ویژگیهای top، right، bottom، و left اعمال نمیشوند.</p> + +<p dir="rtl"><strong><em>relative</em></strong></p> + +<p dir="rtl">عناصر را طوری روی سطح پخش میکند گویی موقعیت داده نشدند، و سپس موقعیت عنصر را تنظیم میکند، بدون آنکه ترکیب را تغییر دهد (بنابراین برای عنصر یک جای باز جایی که باید داشته باشد و موقعیت داده نشده کنار میگذارد). position: relative روی عناصر <code>table-*-group</code>، <code>table-row</code>، <code>table-column</code>، <code>table-cell</code>، و <code>table-caption</code> بی تاثیر است.</p> + +<p dir="rtl"><strong><em>absolute</em></strong></p> + +<p dir="rtl">برای عنصر فضا کنار نمیگذارد. در عوض، در موقعیت نسبی مشخص شده نسبت به نزدیکترین والد موقعیت داده شده یا نسبت به بلوک شامل موقعیت میدهد. جعبههایی که موقعیت مستقل دارند میتوانند حاشیه/margin داشته باشند، آنها با هیچ یک از حواشی دیگر فروپاشی نمیکنند.</p> + +<p dir="rtl"><strong><em>fixed</em></strong></p> + +<p dir="rtl">برای عنصر فضا کنار نمیگذارد. در عوض، در موقعیت نسبی مشخص شده نسبت به نما/viewport صفحهی نمایش موقعیت میدهد و با حرکت دادن صفحه/scroll حرکت نمیکند. در زمان چاپ، در همان موقعیت روی هر صفحه ثابت میماند.</p> + +<h2 dir="rtl" id="نمونهها">نمونهها</h2> + +<h3 dir="rtl" id="موقعیت_دادن_نسبی">موقعیت دادن نسبی</h3> + +<p dir="rtl">برای نسبی موقعیت دادن یک عنصر که از بالا و چپ ۲۰ پیکسل از موقعیت عادی خودش تفاوت دارد، دستور CSS زیر استفاده میشود.</p> + +<pre dir="rtl">#two { position: relative; top: 20px; left: 20px; }</pre> + +<p dir="rtl">به عناصر دیگر توجه کنید که چطور نمایش داده میشوند در حالی که "Two" در موقعیت عادی خودش بود و فضا درنظر میگیرد.</p> + +<p dir="rtl"><img alt="" src="https://developer.mozilla.org/@api/deki/files/4922/=relative-positioning.png" style="height: 136px; width: 519px;"></p> + +<h3 dir="rtl" id="موقعیت_دادن_مستقل">موقعیت دادن مستقل</h3> + +<p dir="rtl">عناصری که نسبی موقعیت داده شدند همچنان در روند عادی عناصر در سند درنظر گرفته میشوند. در مقابل، عنصری که مستقل موقعیت داده شده از روند خارج شده بنابراین زمانی که عناصر دیگر قرار داده میشود هیچ فضایی نمیگیرد. عنصری که موقعیت مستقل گرفته است موقعیت نسبی نسبت به نزدیکترین والد موقعیت داده شده دارد. اگر والدی که موقعیت گرفته باشه وجود نداشته باشد، ظرف آغازین استفاده میشود.</p> + +<p dir="rtl">در مثال زیر، والد آبی رنگ div موقعیت نسبی گرفته است (پس نزدیکترین والد موقعیت گرفته شده خواهد بود) و جعبهی Two مستقل موقعیت گرفته است:</p> + +<pre dir="rtl">#ancestor { position: relative; background: #ddf; width: 500px; } + +#two { position: absolute; top: 20px; left: 20px; }</pre> + +<p dir="rtl"><img alt="" src="https://developer.mozilla.org/@api/deki/files/4923/=absolute-positioning.png" style="height: 134px; width: 518px;"></p> + +<p dir="rtl">اگر #ancestor موقعیت نسبی نداشته بود، جعبهی Two با موقعیت نسبی نسبت به بالاترین گوشه سمت چپ صفحه ظاهر میشد.</p> + +<p dir="rtl">موقعیت دادن ثابت</p> + +<p dir="rtl">موقعیت ثابت مشابه موقعیت دادن مستقل است، با این استثنا که بلوک شامل عنصر همان نما/viewport است. این موقعیت اغلب برای ساخت یک عنصر شناوری که حتی پس از حرکت دادن صفحه/scroll در همان موقعیت میماند استفاده میشود. در مثال زیر جعبهی "One" با فاصلهی ۸۰ پیکسل از بالا و صفحه و ۲۰ پیکسل از سمت چپ موقعیت ثابت دارد:</p> + +<pre dir="rtl">#one { position: fixed; top: 80px; left:20px; }</pre> + +<p dir="rtl">وقتی بالای صفحه را نگاه میکنید، جعبه در بالاترین گوشه سمت چپ ظاهر میشود، و پس از حرکت دادن صفحه، در همان جایگاه نسبی نسبت به نما باقی میماند:</p> + +<p dir="rtl"><img alt="" src="https://developer.mozilla.org/@api/deki/files/4924/=fixed-1.png?size=thumb" style="height: 279px; width: 356px;"></p> + +<p dir="rtl"><img alt="" src="https://developer.mozilla.org/@api/deki/files/4925/=fixed-2.png?size=thumb" style="height: 222px; width: 352px;"></p> + +<h2 dir="rtl" id="نکات">نکات</h2> + +<p dir="rtl">برای عناصری که موقعیت نسبی دارند، ویژگی {{Cssxref("top")}} یا {{Cssxref("bottom")}} جابجایی عمودی از موقعیت عادی و ویژگی {{Cssxref("left")}} یا {{Cssxref("right")}} جابجایی افقی را تعیین میکنند.</p> + +<p dir="rtl">برای عناصری که موقعیت مستقل دارند، ویژگیهای {{Cssxref("top")}}، {{Cssxref("right")}}، {{Cssxref("bottom")}}، و {{Cssxref("left")}} جابجاییها از ضلع بلوک شامل عنصر(عنصری که نسبت به آن موقعیت نسبی دارد) تعیین میکنند. حاشیه برای آن عنصر اگر وجود داشته باشد نخست حاشیهها اعمال میشوند سپس جابجاییها.</p> + +<p dir="rtl">اکثر اوقات، عناصر مستقل موقعیت گرفته شده مقادیر خودکار/auto برای {{Cssxref("height")}} و {{Cssxref("width")}} دارند تا طول و عرض عنصر متناسب با محتوای آن تغییر کند.</p> + +<p dir="rtl"><span style="line-height: 21px;">اگر {{Cssxref("top")}} و {{Cssxref("bottom")}} هر دو تعیین شوند(فنی، نه خودکار)، {{Cssxref("top")}} برنده میشود.</span></p> + +<p dir="rtl"><span style="line-height: 21px;">اگر }}Cssxref("left")}} و {{Cssxref("right")}} هر دو تعیین شوند، {{Cssxref("left")}} وقتی {{Cssxref("direction")}} ltr/چپ به راست هست (انگلیسی، ژاپنی افقی، غیره.) و {{Cssxref("right")}} برنده خواهد شد وقتی {{Cssxref("direction")}} rtl/راست به چپ هست(پارسی، عبری، غیره.).</span></p> + +<h2 dir="rtl" id="مشخصات"><span style="line-height: 21px;">مشخصات</span></h2> + +<table class="standard-table" dir="rtl"> + <thead> + <tr> + <th scope="col">دیدگاه</th> + <th scope="col">وضعیت</th> + <th scope="col">مشخصات</th> + </tr> + </thead> + <tbody> + <tr> + <td> </td> + <td>{{Spec2('CSS2.1')}}</td> + <td>{{SpecName('CSS2.1', 'visuren.html#propdef-position', 'position')}}</td> + </tr> + </tbody> +</table> + +<h2 dir="rtl" id="سازگاری_مرورگر">سازگاری مرورگر</h2> + +<p dir="rtl">{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>1.0</td> + <td>1.0 (1.0) ({{anch("Gecko notes", "See notes")}})</td> + <td>4.0</td> + <td>4.0</td> + <td>1.0 (85)</td> + </tr> + <tr> + <td><code>fixed </code>value</td> + <td>1.0</td> + <td>1.0 (1.0)</td> + <td>7.0</td> + <td>4.0</td> + <td>1.0 (85)</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>1.0 (1.0) ({{anch("Gecko notes", "See notes")}})</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<p> </p> diff --git a/files/fa/web/css/pseudo-elements/index.html b/files/fa/web/css/pseudo-elements/index.html new file mode 100644 index 0000000000..ab3de8d597 --- /dev/null +++ b/files/fa/web/css/pseudo-elements/index.html @@ -0,0 +1,97 @@ +--- +title: Pseudo-elements +slug: Web/CSS/Pseudo-elements +translation_of: Web/CSS/Pseudo-elements +--- +<div>{{CSSRef}}</div> + +<p dir="rtl">یک CSS <strong>pseudo-element</strong> کلمه کلیدی است که به انتخابگر اضافه میشود و اجازه میدهد قسمت خاصی از عنصر انتخاب شده را آرایش کنید. برای مثال، {{ Cssxref("first-line::") }} میتواند برای تغییر نوشتار و رنگ خط اول یک پاراگراف مورد استفاده قرار گیرد.</p> + +<pre class="brush: css no-line-numbers">/* The first line of every <p> element. */ +p::first-line { + color: blue; + text-transform: uppercase; +}</pre> + +<div class="note"> +<p><strong>Note:</strong> In contrast to pseudo-elements, {{cssxref("pseudo-classes")}} can be used to style an element based on its <em>state</em>.</p> +</div> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">selector::pseudo-element { + property: value; +}</pre> + +<p>You can use only one pseudo-element in a selector. It must appear after the simple selectors in the statement.</p> + +<div class="note"> +<p><strong>Note:</strong> As a rule, double colons (<code>::</code>) should be used instead of a single colon (<code>:</code>). This distinguishes pseudo-classes from pseudo-elements. However, since this distinction was not present in older versions of the W3C spec, most browsers support both syntaxes for the original pseudo-elements.</p> +</div> + +<h2 id="Index_of_standard_pseudo-elements">Index of standard pseudo-elements</h2> + +<div class="index"> +<ul> + <li>{{ Cssxref("::after") }}</li> + <li>{{ Cssxref("::before") }}</li> + <li>{{ cssxref("::cue")}}</li> + <li>{{ Cssxref("::first-letter") }}</li> + <li>{{ Cssxref("::first-line") }}</li> + <li>{{ Cssxref("::selection") }}</li> + <li>{{ Cssxref("::slotted") }}</li> + <li>{{ Cssxref("::backdrop") }} {{experimental_inline}}</li> + <li>{{ Cssxref("::placeholder") }} {{experimental_inline}}</li> + <li>{{ Cssxref("::marker") }} {{experimental_inline}}</li> + <li>{{ Cssxref("::spelling-error") }} {{experimental_inline}}</li> + <li>{{ Cssxref("::grammar-error") }} {{experimental_inline}}</li> +</ul> +</div> + +<table class="standard-table"> + <tbody> + <tr> + <th>Browser</th> + <th>Lowest Version</th> + <th>Support of</th> + </tr> + <tr> + <td rowspan="2">Internet Explorer</td> + <td>8.0</td> + <td><code>:pseudo-element</code></td> + </tr> + <tr> + <td>9.0</td> + <td><code>:pseudo-element ::pseudo-element</code></td> + </tr> + <tr> + <td rowspan="2">Firefox (Gecko)</td> + <td>1.0 (1.0)</td> + <td><code>:pseudo-element</code></td> + </tr> + <tr> + <td>1.0 (1.5)</td> + <td><code>:pseudo-element ::pseudo-element</code></td> + </tr> + <tr> + <td rowspan="2">Opera</td> + <td>4.0</td> + <td><code>:pseudo-element</code></td> + </tr> + <tr> + <td>7.0</td> + <td><code>:pseudo-element ::pseudo-element</code></td> + </tr> + <tr> + <td>Safari (WebKit)</td> + <td>1.0 (85)</td> + <td><code>:pseudo-element ::pseudo-element</code></td> + </tr> + </tbody> +</table> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/CSS/Pseudo-classes">pseudo-classes</a></li> +</ul> diff --git a/files/fa/web/css/specificity/index.html b/files/fa/web/css/specificity/index.html new file mode 100644 index 0000000000..fe692075a4 --- /dev/null +++ b/files/fa/web/css/specificity/index.html @@ -0,0 +1,343 @@ +--- +title: Specificity +slug: Web/CSS/Specificity +translation_of: Web/CSS/Specificity +--- +<p> </p> + +<div>{{CSSRef}}</div> + +<p class="summary"><strong>Specificity</strong> is the means by which browsers decide which CSS property values are the most relevant to an element and, therefore, will be applied. Specificity is based on the matching rules which are composed of different sorts of <a href="/en-US/docs/Web/CSS/CSS_Reference#Selectors">CSS selectors</a>.</p> + +<h2 id="How_is_specificity_calculated">How is specificity calculated?</h2> + +<p>Specificity is a weight that is applied to a given CSS declaration, determined by the number of each <a href="#Selector_Types">selector type</a> in the matching selector. When multiple declarations have equal specificity, the last declaration found in the CSS is applied to the element. Specificity only applies when the same element is targeted by multiple declarations. As per CSS rules, <a href="#directly-targeted-elements">directly targeted elements</a> will always take precedence over rules which an element inherits from its ancestor.</p> + +<div class="blockIndicator note"> +<p><strong>Note:</strong> <a href="#Tree_proximity_ignorance">Proximity of elements</a> in the document tree has no effect on the specificity.</p> +</div> + +<h3 id="Selector_Types">Selector Types</h3> + +<p>The following list of selector types increases by specificity:</p> + +<ol> + <li><a href="/en-US/docs/Web/CSS/Type_selectors">Type selectors</a> (e.g., <code>h1</code>) and pseudo-elements (e.g., <code>::before</code>).</li> + <li><a href="/en-US/docs/Web/CSS/Class_selectors">Class selectors</a> (e.g., <code>.example</code>), attributes selectors (e.g., <code>[type="radio"]</code>) and pseudo-classes (e.g., <code>:hover</code>).</li> + <li><a href="/en-US/docs/Web/CSS/ID_selectors">ID selectors</a> (e.g., <code>#example</code>).</li> +</ol> + +<p>Universal selector ({{CSSxRef("Universal_selectors", "*")}}), combinators ({{CSSxRef("Adjacent_sibling_combinator", "+")}}, {{CSSxRef("Child_combinator", ">")}}, {{CSSxRef("General_sibling_combinator", "~")}}, <a href="/en-US/docs/Web/CSS/Descendant_combinator" style="white-space: nowrap;">'<code> </code>'</a>, {{CSSxRef("Column_combinator", "||")}}) and negation pseudo-class ({{CSSxRef(":not", ":not()")}}) have no effect on specificity. (The selectors declared <em>inside</em> <code>:not()</code> do, however.)</p> + +<p>For more information, visit: <a href="https://specifishity.com">https://specifishity.com</a></p> + +<p>Inline styles added to an element (e.g., <code>style="font-weight: bold;"</code>) always overwrite any styles in external stylesheets, and thus can be thought of as having the highest specificity.</p> + +<h3 id="The_!important_exception">The <code>!important</code> exception</h3> + +<p>When an <code>important</code> rule is used on a style declaration, this declaration overrides any other declarations. Although technically <code>!important</code> has nothing to do with specificity, it interacts directly with it. Using <code>!important,</code> however, is <strong>bad practice</strong> and should be avoided because it makes debugging more difficult by breaking the natural <a href="/en-US/docs/Web/CSS/Cascade">cascading</a> in your stylesheets. When two conflicting declarations with the <code>!important</code> rule are applied to the same element, the declaration with a greater specificity will be applied.</p> + +<p><strong>Some rules of thumb:</strong></p> + +<ul> + <li><strong>Always</strong> look for a way to use specificity before even considering <code>!important</code></li> + <li><strong>Only</strong> use <code>!important</code> on page-specific CSS that overrides foreign CSS (from external libraries, like Bootstrap or normalize.css).</li> + <li><strong>Never</strong> use <code>!important</code> when you're writing a plugin/mashup.</li> + <li><strong>Never</strong> use <code>!important</code> on site-wide CSS.</li> +</ul> + +<p><strong>Instead of using <code>!important</code>, consider:</strong></p> + +<ol> + <li>Make better use of the CSS cascade</li> + <li> + <p>Use more specific rules. By indicating one or more elements before the element you're selecting, the rule becomes more specific and gets higher priority:</p> + + <pre class="brush: html"><div id="test"> + <span>Text</span> +</div> +</pre> + + <pre class="brush: css">div#test span { color: green; } +div span { color: blue; } +span { color: red; }</pre> + + <p>No matter the order, text will be green because that rule is most specific. (Also, the rule for blue overwrites the rule for red, notwithstanding the order of the rules)</p> + </li> + <li>As a nonsense special case for (2), duplicate simple selectors to increase specificity when you have nothing more to specify. + <pre class="brush: css">#myId#myId span { color: yellow; } +.myClass.myClass span { color: orange; }</pre> + </li> +</ol> + +<h4 id="How_!important_can_be_used">How !important can be used:</h4> + +<h5 id="A)_Overriding_inline_styles">A) Overriding inline styles</h5> + +<p>Your global CSS file that sets visual aspects of your site globally may be overwritten by inline styles defined directly on individual elements. Both inline styles and !important are considered very bad practice, but sometimes you need the latter to override the former.</p> + +<p>In this case, you could set certain styles in your global CSS file as !important, thus overriding inline styles set directly on elements.</p> + +<pre class="brush: html"><div class="foo" style="color: red;">What color am I?</div> +</pre> + +<pre class="brush: css">.foo[style*="color: red"] { + color: firebrick !important; +} +</pre> + +<p>Many JavaScript frameworks and libraries add inline styles. Using <code>!important</code> with a very targeted selector is one way to override these inline styles.</p> + +<h5 id="B)_Overriding_high_specificity">B) Overriding high specificity</h5> + +<pre class="brush: css">#someElement p { + color: blue; +} + +p.awesome { + color: red; +}</pre> + +<p>How do you make <code>awesome</code> paragraphs always turn red, even ones inside <code>#someElement</code>? Without <code>!important</code>, the first rule will have more specificity and will win over the second rule.</p> + +<h4 id="How_to_override_!important">How to override <code>!important</code></h4> + +<p>A) Add another CSS rule with <code>!important</code>, and either give the selector a higher specificity (adding a tag, id or class to the selector), or add a CSS rule with the same selector at a later point than the existing one. This works because in a specificity tie, the last rule defined wins.</p> + +<p>Some examples with a higher specificity:</p> + +<pre class="brush: css">table td { height: 50px !important; } +.myTable td { height: 50px !important; } +#myTable td { height: 50px !important; } +</pre> + +<p>B) Or add the same selector after the existing one:</p> + +<pre class="brush: css">td { height: 50px !important; }</pre> + +<p>C) Or, preferably, rewrite the original rule to avoid the use of <code>!important</code> altogether.</p> + +<pre class="brush: css">[id="someElement"] p { + color: blue; +} + +p.awesome { + color: red; +}</pre> + +<p>Including an id as part of an attribute selector instead of as an id selector gives it the same specificity as a class. Both selectors above now have the same weight. In a specificity tie, the last rule defined wins.</p> + +<h4 id="For_more_information_visit">For more information, visit:</h4> + +<ul> + <li><a href="https://stackoverflow.com/questions/3706819/what-are-the-implications-of-using-important-in-css">https://stackoverflow.com/questions/3706819/what-are-the-implications-of-using-important-in-css</a></li> + <li><a href="https://stackoverflow.com/questions/9245353/what-does-important-in-css-mean">https://stackoverflow.com/questions/9245353/what-does-important-in-css-mean</a></li> + <li><a href="https://stackoverflow.com/questions/5701149/when-to-use-important-property-in-css">https://stackoverflow.com/questions/5701149/when-to-use-important-property-in-css</a></li> + <li><a href="https://stackoverflow.com/questions/11178673/how-to-override-important">https://stackoverflow.com/questions/11178673/how-to-override-important</a></li> + <li><a href="https://stackoverflow.com/questions/2042497/when-to-use-important-to-save-the-day-when-working-with-css">https://stackoverflow.com/questions/2042497/when-to-use-important-to-save-the-day-when-working-with-css</a></li> +</ul> + +<h3 id="The_is_and_not_exceptions" name="The_is_and_not_exceptions"><a id="The_not_exception" name="The_not_exception">The <code>:is()</code> and <code>:not()</code> exceptions</a></h3> + +<p>The matches-any pseudo-class {{CSSxRef(":is", ":is()")}} {{Experimental_Inline}} and the negation pseudo-class {{CSSxRef(":not", ":not()")}} are <em>not</em> considered a pseudo-class in the specificity calculation. But selectors placed into the pseudo-class count as normal selectors when determining the count of <a href="#Selector_Types">selector types</a>.</p> + +<div id="The_not_exception-example"> +<p>This chunk of CSS ...</p> + +<pre class="brush: css">div.outer p { + color: orange; +} + +div:not(.outer) p { + color: blueviolet; +} +</pre> + +<p>... when used with the following HTML ...</p> + +<pre class="brush: html"><div class="outer"> + <p>This is in the outer div.</p> + <div class="inner"> + <p>This text is in the inner div.</p> + </div> +</div> +</pre> + +<p>... appears on the screen like this:</p> + +<p>{{EmbedLiveSample("The_not_exception-example")}}</p> +</div> + +<h3 id="The_where_exception" name="The_where_exception">The <code>:where()</code> exception {{Experimental_Inline}}</h3> + +<p>{{SeeCompatTable}}</p> + +<p>The specificity-adjustment pseudo-class {{CSSxRef(":where", ":where()")}} {{Experimental_Inline}} always has its specificity replaced with zero.</p> + +<p>This chunk of CSS ...</p> + +<pre class="brush: css">div:where(.outer) p { + color: orange; +} + +div p { + color: blueviolet; +} +</pre> + +<div class="hidden"> +<pre class="brush: css;">#no-where-support { + margin: 0.5em; + border: 1px solid red; +} + +#no-where-support:where(*) { + display: none !important; +} +</pre> +</div> + +<p>... when used with the following HTML ...</p> + +<div class="hidden"> +<pre class="brush: html;"><div id=no-where-support> +⚠️ Your browser doesn't support the <code><a href="https://developer.mozilla.org/docs/Web/CSS/:where">:where()</a></code> pseudo-class. +</div> +</pre> +</div> + +<pre class="brush: html"><div class="outer"> + <p>This is in the outer div.</p> + <div class="inner"> + <p>This text is in the inner div.</p> + </div> +</div> +</pre> + +<p>... appears on the screen like this:</p> + +<p>{{EmbedLiveSample("The_where_exception")}}</p> + +<h3 id="Form-based_specificity">Form-based specificity</h3> + +<p>Specificity is based on the form of a selector. In the following case, the selector <code>*[id="foo"]</code> counts as an attribute selector for the purpose of determining the selector's specificity, even though it selects an ID.</p> + +<p>The following CSS styles ...</p> + +<pre class="brush: css">*#foo { + color: green; +} + +*[id="foo"] { + color: purple; +} +</pre> + +<p>... when used with this markup ...</p> + +<pre class="brush: html"><p id="foo">I am a sample text.</p> +</pre> + +<p>... end up looking like this:</p> + +<p>{{EmbedLiveSample("Form-based_specificity")}}</p> + +<p>This is because it matches the same element but the ID selector has a higher specificity.</p> + +<h3 id="Tree_proximity_ignorance">Tree proximity ignorance</h3> + +<p>The proximity of an element to other elements that are referenced in a given selector has no impact on specificity. The following style declaration ...</p> + +<pre class="brush: css">body h1 { + color: green; +} + +html h1 { + color: purple; +} +</pre> + +<p>... with the following HTML ...</p> + +<pre class="brush: html"><html> + <body> + <h1>Here is a title!</h1> + </body> +</html> +</pre> + +<p>... will render as:</p> + +<p>{{EmbedLiveSample("Tree_proximity_ignorance")}}</p> + +<p>This is because the two declarations have equal <a href="#Selector_Types">selector type</a> counts, but the <code>html h1</code> selector is declared last.</p> + +<h3 id="Directly_targeted_elements_vs._inherited_styles">Directly targeted elements vs. inherited styles</h3> + +<p>Styles for a directly targeted element will always take precedence over inherited styles, regardless of the specificity of the inherited rule. This CSS ...</p> + +<pre class="brush: css">#parent { + color: green; +} + +h1 { + color: purple; +}</pre> + +<p>... with the following HTML ...</p> + +<pre class="brush: html"><html> + <body id="parent"> + <h1>Here is a title!</h1> + </body> +</html></pre> + +<p>... will also render as:</p> + +<p>{{EmbedLiveSample("Directly_targeted_elements_vs._inherited_styles")}}</p> + +<p>This is because the <code>h1</code> selector targets the element specifically, but the green selector is only inherited from its parent.</p> + +<h2 id="Specifications">Specifications</h2> + +<div style="overflow: auto;"> +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSS4 Selectors", "#specificity-rules", "Calculating a selector's specificity")}}</td> + <td>{{Spec2("CSS4 Selectors")}}</td> + <td>Add the specificity adjustment selector {{CSSxRef(":where", ":where()")}}.</td> + </tr> + <tr> + <td>{{SpecName("CSS3 Selectors", "#specificity", "Calculating a selector's specificity")}}</td> + <td>{{Spec2("CSS3 Selectors")}}</td> + <td>Add <a href="/en-US/docs/Web/CSS/Pseudo-elements">pseudo-elements</a>.</td> + </tr> + <tr> + <td>{{SpecName("CSS2.1", "cascade.html#specificity", "Calculating a selector's specificity")}}</td> + <td>{{Spec2("CSS2.1")}}</td> + <td>Add <a href="/en-US/docs/Web/CSS/Pseudo-classes">pseudo-classes</a>.</td> + </tr> + <tr> + <td>{{SpecName("CSS1", "#cascading-order", "Cascading order")}}</td> + <td>{{Spec2("CSS1")}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li>Specificity Calculator: An interactive website to test and understand your own CSS rules - <a href="https://specificity.keegan.st/">https://specificity.keegan.st/</a></li> + <li>CSS3 Selectors Specificity - <a class="external" href="http://www.w3.org/TR/selectors/#specificity" rel="freelink">http://www.w3.org/TR/selectors/#specificity</a></li> + <li>{{CSS_Key_Concepts}}</li> +</ul> diff --git a/files/fa/web/css/top/index.html b/files/fa/web/css/top/index.html new file mode 100644 index 0000000000..b0b4af4e6f --- /dev/null +++ b/files/fa/web/css/top/index.html @@ -0,0 +1,194 @@ +--- +title: بالا +slug: Web/CSS/top +tags: + - top + - بالا +translation_of: Web/CSS/top +--- +<div dir="rtl">{{CSSRef}}</div> + +<h2 dir="rtl" id="Summary" name="Summary">خلاصه مطلب</h2> + +<p dir="rtl">ویژگی CSS <code>top</code> قسمتی از موقعیت عناصر موقعیت داده شده (positioned elements) را مشخص میکند. این ویژگی تاثیری بر عناصری که موقعیت داده نشده اند (non-positioned)، ندارد.</p> + +<p dir="rtl">برای عناصری که موقعیت مستقل دارند (آنهایی که همراه {{Cssxref("position")}}: <code>absolute</code> یا {{Cssxref("position")}}: <code>fixed</code> هستند)، فاصلهی بین ضلع بالای حاشیه از عنصر و ضلع بالای بلوک شامل خودش را مشخص میکند.</p> + +<p dir="rtl">برای عناصری که موقعیت نسبی دارند (آنهایی که همراه {{Cssxref("position")}}: <code>relative</code> هستند)، اندازهی حرکتی که عنصر به زیر موقعیت عادی خود دارد مشخص میکند.</p> + +<p dir="rtl">وقتی هر دو ویژگی {{Cssxref("top")}} و {{Cssxref("bottom")}} تعیین شده باشند، موقعیت عنصر بیش از حد محدود هست و ویژگی {{Cssxref("top")}} اولویت دارد: مقدار محاسبه شدهی {{Cssxref("bottom")}} روی -{{Cssxref("top")}} قرار می گیرد، درحالی که مقدار خودش که تعیین گردیده نادیده گرفته میشود.</p> + +<p dir="rtl">{{cssinfo}}</p> + +<h2 dir="rtl" id="Syntax" name="Syntax">روش استفاده</h2> + +<pre class="twopartsyntaxbox" dir="rtl"><a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("top")}} +</pre> + +<pre dir="rtl">top: 3px /* <length> مقادیر */ +top: 2.4em + +top: 10% /* <percentages> of the height of the containing block */ + +top: auto + +top: inherit +</pre> + +<h3 dir="rtl" id="مقادیر">مقادیر</h3> + +<dl> + <dt dir="rtl"><code><طول></code></dt> + <dd dir="rtl">یک عدد منفی، null، یا مثبت هست که {{cssxref("<length>")}} نشان میدهد:</dd> + <dd> + <ul dir="rtl"> + <li>برای عناصر با موقعیت مستقل (absolutely)، فاصله ازقسمت بالایی (لبه ی بالای) بلوک را مشخص می کند؛</li> + <li>برای عناصر با موقعیت نسبی (relative)، اگر در حالت معمول (normal flow) موقعیتی (position) مشخص نشده باشد، عنصر نسبت به موقعیت معمول (normal) خود به سمت پایین حرکت می کند.</li> + </ul> + </dd> + <dt dir="rtl"><code><درصد></code></dt> + <dd dir="rtl">یک {{cssxref("<percentage>")}} از ارتفاع بلوک شامل است، همانطور که در <a href="#" title="#">خلاصه</a> شرح داده شد مورد استفاده قرار میگیرد.</dd> + <dt dir="rtl"><code>خودکار</code></dt> + <dd dir="rtl">کلیدواژهای است که بیان میکند:</dd> + <dd> + <ul dir="rtl"> + <li>برای عناصر با موقعیت مستقل، موقعیت عنصر بر مبنای ویژگی {{Cssxref("bottom")}} و ارتفاع مربوط تنظیم میشود: <code>auto</code> بعنوان ارتفاع بر مبنای محتوا.</li> + <li>برای عناصر با موقعیت نسبی، جابجایی عنصر از موقعیت اصلی خود بر مبنای ویژگی {{Cssxref("bottom")}} تنظیم میشود، یا اگر {{Cssxref("bottom")}} هم <code>auto</code> باشد، عنصر را جابجا نمیکند.</li> + </ul> + </dd> + <dt dir="rtl"><code>به ارث بردن</code></dt> + <dd dir="rtl">کلیدواژهای است که نشان میدهد مقدار همان مقداری است که از عنصر والد خود محاسبه شده است (ممکن است بلوک شامل عنصر نباشد).</dd> + <dd dir="rtl">مقدار نخست محاسبه میشود سپس بر اساس نوع آن که {{cssxref("<length>")}}، {{cssxref("<percentage>") }}، یا کلیدواژهی <code>auto</code> است بکار میرود.</dd> +</dl> + +<h2 dir="rtl" id="Examples" name="Examples">نمونهها</h2> + +<pre class="brush: css" dir="rtl">/* body میتواند با واحد px تعیین شود همینطور برای div */ +body{ + width: 100%; + height: 100%; +} + +/* برای div هم میتوان از واحد ٪ استفاده کرد */ +div { + position: absolute; + left: 15%; + top: 30%; + bottom: 30%; + width: 70%; + height: 40%; + text-align: left; + border: 3px rgb(0,0,0) solid; +}</pre> + +<pre class="brush: html" dir="rtl"> <?xml version="1.0" encoding="utf-8"?> + <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> + <head> + <meta http-equiv="Content-Type" content="application/xhtml+xml" /> + <title>Mozilla.org height top left width percentage CSS</title> + <style type="text/css"> + /* body میتواند با واحد px تعیین شود همینطور برای div */ + body { + width: 100%; + height: 100%; + } + /* برای div هم میتوان از واحد ٪ استفاده کرد */ + div { + position: absolute; + left: 15%; + top: 30%; + bottom: 30%; + width: 70%; + height: 40%; + text-align: left; + border: 3px rgb(0,0,0) solid; + } + </style> + </head> + <body> + <center> + <div> + ...محتوای آزمایشی... + </div> + </center> + + </body> + </html></pre> + +<h2 dir="rtl" id="Specifications" name="Specifications">مشخصات</h2> + +<table class="standard-table" dir="rtl"> + <thead> + <tr> + <th scope="col">مشخصات</th> + <th scope="col">وضعیت</th> + <th scope="col">دیدگاه</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('CSS3 Transitions', '#animatable-css', 'top')}}</td> + <td>{{Spec2('CSS3 Transitions')}}</td> + <td>Defines <code>top</code> as animatable.</td> + </tr> + <tr> + <td>{{SpecName('CSS2.1', 'visuren.html#propdef-top', 'top')}}</td> + <td>{{Spec2('CSS2.1')}}</td> + <td>Initial specification</td> + </tr> + </tbody> +</table> + +<h2 dir="rtl" id="Browser_compatibility" name="Browser_compatibility">سازگاری مرورگر</h2> + +<p dir="rtl">{{CompatibilityTable}}</p> + +<div dir="rtl" id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("1")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div dir="rtl" id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> diff --git a/files/fa/web/css/transform-function/index.html b/files/fa/web/css/transform-function/index.html new file mode 100644 index 0000000000..8e2080e302 --- /dev/null +++ b/files/fa/web/css/transform-function/index.html @@ -0,0 +1,163 @@ +--- +title: <transform-function> +slug: Web/CSS/transform-function +tags: + - CSS + - CSS Data Type + - CSS Transforms + - Layout + - NeedsTranslation + - Reference + - TopicStub +translation_of: Web/CSS/transform-function +--- +<div>{{CSSRef}}</div> + +<p>The <strong><code><transform-function></code></strong> <a href="/en-US/docs/Web/CSS">CSS</a> <a href="/en-US/docs/Web/CSS/CSS_Types">data type</a> represents a transformation that affects an element's appearance. Transformation functions can rotate, resize, distort, or move an element in 2D or 3D space. It is used in the {{cssxref("transform")}} property.</p> + +<h2 id="Describing_transformations_mathematically">Describing transformations mathematically</h2> + +<p>Various coordinate models can be used to describe an HTML element's size and shape, as well as any transformations applied to it. The most common is the <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian coordinate system</a>, although <a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">homogeneous coordinates</a> are also sometimes used.</p> + +<h3 id="Cartesian_coordinates"><a href="/@api/deki/files/5796/=coord_in_R2.png"><img src="/files/3438/coord_in_R2.png" style="float: right; width: 171px;"></a>Cartesian coordinates</h3> + +<p>In the Cartesian coordinate system, a two-dimensional point is described using two values: an x coordinate (abscissa) and a y coordinate (ordinate). This is represented by the vector notation <code>(x, y)</code>.</p> + +<p>In CSS (and most computer graphics), the origin <code>(0, 0)</code> represents the<em> top-left</em> corner of any element. Positive coordinates are down and to the right of the origin, while negative ones are up and to the left. Thus, a point that's 2 units to the right and 5 units down would be <code>(2, 5)</code>, while a point 3 units to the left and 12 units up would be <code>(-3, -12)</code>.</p> + +<h3 id="Transformation_functions">Transformation functions</h3> + +<p>Transformation functions alter the appearance of an element by manipulating the values of its coordinates. A linear transformation function is described using a 2x2 matrix, like this:</p> + +<div style="text-align: center;"> +<p><math> <mfenced> <mtable> <mtr><mtd>a</mtd><mtd>c</mtd></mtr> <mtr><mtd>b</mtd><mtd>d</mtd></mtr> </mtable> </mfenced> </math></p> +</div> + +<p>The function is applied to an element by using matrix multiplication. Thus, each coordinate changes based on the values in the matrix:</p> + +<div style="text-align: center;"><a href="/@api/deki/files/5799/=transform_functions_generic_transformation_cart.png"><img src="/@api/deki/files/5799/=transform_functions_generic_transformation_cart.png?size=webview" style="height: 32px; width: 189px;"></a></div> + +<p><br> + It is even possible to apply several transformations in a row:</p> + +<div style="text-align: center;"><a href="/@api/deki/files/5800/=transform_functions_transform_composition_cart.png"><img src="/@api/deki/files/5800/=transform_functions_transform_composition_cart.png?size=webview" style="height: 32px; width: 313px;"></a></div> + +<p><br> + With this notation, it is possible to describe, and therefore compose, most common transformations: rotations, scaling, or skewing. (In fact, all transformations that are linear functions can be described.) Composite transformations are effectively applied in order from right to left.</p> + +<p>However, one major transformation is not linear, and therefore must be special-cased when using this notation: translation. The translation vector <code>(tx, ty)</code> must be expressed separately, as two additional parameters.</p> + +<div class="note"> +<p><strong>Note:</strong> Though trickier than Cartesian coordinates, <a class="external" href="https://en.wikipedia.org/wiki/Homogeneous_coordinates">homogeneous coordinates</a> in <a class="external" href="https://en.wikipedia.org/wiki/Projective_geometry">projective geometry</a> lead to 3x3 transformation matrices, and can simply express translations as linear functions.</p> +</div> + +<h2 id="Syntax">Syntax</h2> + +<p>The <code><transform-function></code> data type is specified using one of the transformation functions listed below. Each function applies a geometric operation in either 2D or 3D.</p> + +<h3 id="Matrix_transformation">Matrix transformation</h3> + +<dl> + <dt>{{cssxref("transform-function/matrix","matrix()")}}</dt> + <dd>Describes a homogeneous 2D transformation matrix.</dd> + <dt>{{cssxref("transform-function/matrix3d","matrix3d()")}}</dt> + <dd>Describes a 3D transformation as a 4x4 homogeneous matrix.</dd> +</dl> + +<h3 id="Perspective">Perspective</h3> + +<dl> + <dt>{{cssxref("transform-function/perspective","perspective()")}}</dt> + <dd>Sets the distance between the user and the z=0 plane.</dd> +</dl> + +<h3 id="Rotation">Rotation</h3> + +<dl> + <dt>{{cssxref("transform-function/rotate","rotate()")}}</dt> + <dd>Rotates an element around a fixed point on the 2D plane.</dd> + <dt>{{cssxref("transform-function/rotate3d","rotate3d()")}}</dt> + <dd>Rotates an element around a fixed axis in 3D space.</dd> + <dt>{{cssxref("transform-function/rotateX","rotateX()")}}</dt> + <dd>Rotates an element around the horizontal axis.</dd> + <dt>{{cssxref("transform-function/rotateY","rotateY()")}}</dt> + <dd>Rotates an element around the vertical axis.</dd> + <dt>{{cssxref("transform-function/rotateZ","rotateZ()")}}</dt> + <dd>Rotates an element around the z-axis.</dd> +</dl> + +<h3 id="Scaling_(resizing)">Scaling (resizing)</h3> + +<dl> + <dt>{{cssxref("transform-function/scale","scale()")}}</dt> + <dd>Scales an element up or down on the 2D plane.</dd> + <dt>{{cssxref("transform-function/scale3d","scale3d()")}}</dt> + <dd>Scales an element up or down in 3D space.</dd> + <dt>{{cssxref("transform-function/scaleX","scaleX()")}}</dt> + <dd>Scales an element up or down horizontally.</dd> + <dt>{{cssxref("transform-function/scaleY","scaleY()")}}</dt> + <dd>Scales an element up or down vertically.</dd> + <dt>{{cssxref("transform-function/scaleZ","scaleZ()")}}</dt> + <dd>Scales an element up or down along the z-axis.</dd> +</dl> + +<h3 id="Skewing_(distortion)">Skewing (distortion)</h3> + +<dl> + <dt>{{cssxref("transform-function/skew","skew()")}}</dt> + <dd>Skews an element on the 2D plane.</dd> + <dt>{{cssxref("transform-function/skewX","skewX()")}}</dt> + <dd>Skews an element in the horizontal direction.</dd> + <dt>{{cssxref("transform-function/skewY","skewY()")}}</dt> + <dd>Skews an element in the vertical direction.</dd> +</dl> + +<h3 id="Translation_(moving)">Translation (moving)</h3> + +<dl> + <dt>{{cssxref("transform-function/translate","translate()")}}</dt> + <dd>Translates an element on the 2D plane.</dd> + <dt>{{cssxref("transform-function/translate3d","translate3d()")}}</dt> + <dd>Translates an element in 3D space.</dd> + <dt>{{cssxref("transform-function/translateX","translateX()")}}</dt> + <dd>Translates an element horizontally.</dd> + <dt>{{cssxref("transform-function/translateY","translateY()")}}</dt> + <dd>Translates an element vertically.</dd> + <dt>{{cssxref("transform-function/translateZ","translateZ()")}}</dt> + <dd>Translates an element along the z-axis.</dd> +</dl> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('CSS3 Transforms', '#transform-property', 'transform')}}</td> + <td>{{Spec2('CSS3 Transforms')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p> </p> + + + +<p>{{Compat("css.types.transform-function")}}</p> + +<p> </p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>CSS {{cssxref("transform")}} property</li> +</ul> diff --git a/files/fa/web/css/transform-function/rotate()/index.html b/files/fa/web/css/transform-function/rotate()/index.html new file mode 100644 index 0000000000..28c924605d --- /dev/null +++ b/files/fa/web/css/transform-function/rotate()/index.html @@ -0,0 +1,85 @@ +--- +title: rotate() +slug: Web/CSS/transform-function/rotate() +translation_of: Web/CSS/transform-function/rotate() +--- +<div>{{CSSRef}}</div> + +<p dir="rtl">تابع <strong><code>()rotate</code></strong> یک جابجایی که چرخشی دوبعدی نسبت به نقطهای ثابت است را بوجود میآورد. نوع خروجی این تابع از جنس {{cssxref("<transform-function>")}} میباشد.</p> + +<p><img src="https://mdn.mozillademos.org/files/12113/rotate.png" style="height: 175px; width: 258px;"></p> + +<p dir="rtl">محور چرخش از طریق مقدار دهی خاصیت {{ cssxref("transform-origin") }} مشخص میشود.</p> + +<h2 id="نحو">نحو</h2> + +<p dir="rtl">مقدار ساخته شده با تابع <code>()rotate</code> برای چرخش، توسط {{cssxref("<angle>")}} مشخص میشود. اگر علامت آن مثبت باشه در جهت ساعتگرد حرکت میکند؛ اگر منفی باشد در جهت پاد ساعتگرد حرکت میکند. چرخش °180 بازتاب نقطه نامیده میشود.</p> + +<pre class="syntaxbox notranslate">rotate(<em>a</em>) +</pre> + +<h3 id="مقادیر">مقادیر</h3> + +<dl> + <dt><code>a</code></dt> + <dd>Is an {{ cssxref("<angle>") }} representing the angle of the rotation. A positive angle denotes a clockwise rotation, a negative angle a counter-clockwise one.</dd> +</dl> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Cartesian coordinates on ℝ<sup>2</sup></th> + <th scope="col">Homogeneous coordinates on ℝℙ<sup>2</sup></th> + <th scope="col">Cartesian coordinates on ℝ<sup>3</sup></th> + <th scope="col">Homogeneous coordinates on ℝℙ<sup>3</sup></th> + </tr> + </thead> + <tbody> + <tr> + <td colspan="1" rowspan="2"><math> <mfenced> <mtable> <mtr><mtd>cos(a)</mtd><mtd>-sin(a)</mtd></mtr> <mtr><mtd>sin(a)</mtd><mtd>cos(a)</mtd></mtr></mtable></mfenced></math></td> + <td><math> <mfenced><mtable><mtr><mtd>cos(a)</mtd><mtd>-sin(a)</mtd><mtd>0</mtd></mtr><mtr><mtd>sin(a)</mtd><mtd>cos(a)</mtd><mtd>0</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd></mtr></mtable> </mfenced> </math></td> + <td colspan="1" rowspan="2"><math> <mfenced><mtable><mtr><mtd>cos(a)</mtd><mtd>-sin(a)</mtd><mtd>0</mtd></mtr><mtr><mtd>sin(a)</mtd><mtd>cos(a)</mtd><mtd>0</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd></mtr></mtable> </mfenced> </math></td> + <td colspan="1" rowspan="2"><math> <mfenced><mtable><mtr><mtd>cos(a)</mtd><mtd>-sin(a)</mtd><mtd>0</mtd><mtd>0</mtd></mtr><mtr><mtd>sin(a)</mtd><mtd>cos(a)</mtd><mtd>0</mtd><mtd>0</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd><mtd>0</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd></mtr></mtable> </mfenced> </math></td> + </tr> + <tr> + <td><code>[cos(a) sin(a) -sin(a) cos(a) 0 0]</code></td> + </tr> + </tbody> +</table> + +<h2 id="مثالها">مثالها</h2> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html notranslate"><div>Normal</div> +<div class="rotated">Rotated</div></pre> + +<h3 id="CSS">CSS</h3> + +<pre class="brush: css notranslate">div { + width: 80px; + height: 80px; + background-color: skyblue; +} + +.rotated { + transform: rotate(45deg); /* Equal to rotateZ(45deg) */ + background-color: pink; +} +</pre> + +<h3 id="Result">Result</h3> + +<p>{{EmbedLiveSample("Examples", "auto", 180)}}</p> + +<h2 id="سازگاری_مرورگرها">سازگاری مرورگرها</h2> + +<p>برای اطلاعات مربوط به سازگاری، لطفا <code><a href="/en-US/docs/Web/CSS/transform-function#Browser_compatibility"><transform-function></a></code> را ببنید.</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{cssxref("transform")}}</li> + <li>{{cssxref("<transform-function>")}}</li> + <li><code><a href="/en-US/docs/Web/CSS/transform-function/rotate3d">rotate3d()</a></code></li> +</ul> diff --git a/files/fa/web/css/انتخابگرـنوع/index.html b/files/fa/web/css/انتخابگرـنوع/index.html new file mode 100644 index 0000000000..5a4b5e4c89 --- /dev/null +++ b/files/fa/web/css/انتخابگرـنوع/index.html @@ -0,0 +1,78 @@ +--- +title: انتخابگر نوع +slug: Web/CSS/انتخابگرـنوع +translation_of: Web/CSS/Type_selectors +--- +<div>{{CSSRef}}</div> + +<p dir="rtl"><strong>انتخابگر نوع</strong> با نوع عنصر انتخاب میکند. به عبارت دیگر این انتخابگر به وسیله نوع عنصر، تمام عنصرهای تطابق داده شده را انتخاب میکند.</p> + +<pre class="brush: css no-line-numbers">/* را انتخاب میکند <a> همه عنصرهای */ +a { + color: red; +}</pre> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">element { <em>style properties</em> } +</pre> + +<h2 id="Example">Example</h2> + +<h3 id="CSS">CSS</h3> + +<pre class="brush: css">span { + background-color: skyblue; +} +</pre> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html"><span>Here's a span with some text.</span> +<p>Here's a p with some text.</p> +<span>Here's a span with more text.</span> +</pre> + +<h3 id="Result">Result</h3> + +<p>{{EmbedLiveSample('Example', '100%', 150)}}</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('CSS4 Selectors', '#type-selectors', 'Type (tag name) selector')}}</td> + <td>{{Spec2('CSS4 Selectors')}}</td> + <td>No changes</td> + </tr> + <tr> + <td>{{SpecName('CSS3 Selectors', '#type-selectors', 'type selectors')}}</td> + <td>{{Spec2('CSS3 Selectors')}}</td> + <td>No changes</td> + </tr> + <tr> + <td>{{SpecName('CSS2.1', 'selector.html#type-selectors', 'type selectors')}}</td> + <td>{{Spec2('CSS2.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('CSS1', '#basic-concepts', 'type selectors')}}</td> + <td>{{Spec2('CSS1')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("css.selectors.type")}}</p> diff --git a/files/fa/web/css/انتخابگرـویژگی/index.html b/files/fa/web/css/انتخابگرـویژگی/index.html new file mode 100644 index 0000000000..54cf34cd5d --- /dev/null +++ b/files/fa/web/css/انتخابگرـویژگی/index.html @@ -0,0 +1,182 @@ +--- +title: انتخابگر ویژگی +slug: Web/CSS/انتخابگرـویژگی +translation_of: Web/CSS/Attribute_selectors +--- +<div>{{CSSRef}}</div> + +<p dir="rtl"><strong>انتخابگر ویژگی</strong> بر اساس وجود ویژگی یا مقدار ویژگی انتخاب میکند.</p> + +<pre class="brush: css no-line-numbers">/* را داشته باشند title که ویژگی <a> عنصرهای */ +a[title] { + color: purple; +} + +/* باشد "https://example.org" آن برابر با href که ویژگی <a> عنصرهای */ +a[href="https://example.org"] { + color: green; +} + +/* باشد "example" آن در بردارندهی href که ویژگی <a> عنصرهای */ +a[href*="example"] { + font-size: 2em; +} + +/* به پایان رسیده باشد ".org" آن با href که ویژگی <a> عنصرهای */ +a[href$=".org"] { + font-style: italic; +}</pre> + +<dl> + <dt><code>[<em>attr</em>]</code></dt> + <dd>Represents elements with an attribute name of <em>attr</em>.</dd> + <dt><code>[<em>attr</em>=<em>value</em>]</code></dt> + <dd>Represents elements with an attribute name of <em>attr</em> whose value is exactly <em>value</em>.</dd> + <dt><code>[<em>attr</em>~=<em>value</em>]</code></dt> + <dd>Represents elements with an attribute name of <em>attr</em> whose value is a whitespace-separated list of words, one of which is exactly <em>value</em>.</dd> + <dt><code>[<em>attr</em>|=<em>value</em>]</code></dt> + <dd>Represents elements with an attribute name of <em>attr</em> whose value can be exactly <em>value</em> or can begin with <em>value</em> immediately followed by a hyphen, <code>-</code> (U+002D). It is often used for language subcode matches.</dd> + <dt><code>[<em>attr</em>^=<em>value</em>]</code></dt> + <dd>Represents elements with an attribute name of <em>attr</em> whose value is prefixed (preceded) by <em>value</em>.</dd> + <dt><code>[<em>attr</em>$=<em>value</em>]</code></dt> + <dd>Represents elements with an attribute name of <em>attr</em> whose value is suffixed (followed) by <em>value</em>.</dd> + <dt><code>[<em>attr</em>*=<em>value</em>]</code></dt> + <dd>Represents elements with an attribute name of <em>attr</em> whose value contains at least one occurrence of <em>value</em> within the string.</dd> + <dt id="case-insensitive"><code>[<em>attr</em> <em>operator</em> <em>value</em> i]</code></dt> + <dd>Adding an <code>i</code> (or <code>I</code>) before the closing bracket causes the value to be compared case-insensitively (for characters within the ASCII range).</dd> +</dl> + +<h2 id="Examples">Examples</h2> + +<h3 id="Links">Links</h3> + +<h4 id="CSS">CSS</h4> + +<pre class="brush: css">a { + color: blue; +} + +/* Internal links, beginning with "#" */ +a[href^="#"] { + background-color: gold; +} + +/* Links with "example" anywhere in the URL */ +a[href*="example"] { + background-color: silver; +} + +/* Links with "insensitive" anywhere in the URL, + regardless of capitalization */ +a[href*="insensitive" i] { + color: cyan; +} + +/* Links that end in ".org" */ +a[href$=".org"] { + color: red; +} +</pre> + +<h4 id="HTML">HTML</h4> + +<pre class="brush: html"><ul> + <li><a href="#internal">Internal link</a></li> + <li><a href="http://example.com">Example link</a></li> + <li><a href="#InSensitive">Insensitive internal link</a></li> + <li><a href="http://example.org">Example org link</a></li> +</ul></pre> + +<h4 id="Result">Result</h4> + +<p>{{EmbedLiveSample('Links')}}</p> + +<h3 id="Languages">Languages</h3> + +<h4 id="CSS_2">CSS</h4> + +<pre class="brush: css">/* All divs with a `lang` attribute are bold. */ +div[lang] { + font-weight: bold; +} + +/* All divs in US English are blue. */ +div[lang~="en-us"] { + color: blue; +} + +/* All divs in Portuguese are green. */ +div[lang="pt"] { + color: green; +} + +/* All divs in Chinese are red, whether + simplified (zh-CN) or traditional (zh-TW). */ +div[lang|="zh"] { + color: red; +} + +/* All divs with a Traditional Chinese + `data-lang` are purple. */ +/* Note: You could also use hyphenated attributes + without double quotes */ +div[data-lang="zh-TW"] { + color: purple; +} +</pre> + +<h4 id="HTML_2">HTML</h4> + +<pre class="brush: html"><div lang="en-us en-gb en-au en-nz">Hello World!</div> +<div lang="pt">Olá Mundo!</div> +<div lang="zh-CN">世界您好!</div> +<div lang="zh-TW">世界您好!</div> +<div data-lang="zh-TW">?世界您好!</div> +</pre> + +<h4 id="Result_2">Result</h4> + +<p>{{EmbedLiveSample('Languages')}}</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('CSS4 Selectors', '#attribute-selectors', 'attribute selectors')}}</td> + <td>{{Spec2('CSS4 Selectors')}}</td> + <td>Adds modifier for ASCII case-insensitive attribute value selection</td> + </tr> + <tr> + <td>{{SpecName('CSS3 Selectors', '#attribute-selectors', 'attribute selectors')}}</td> + <td>{{Spec2('CSS3 Selectors')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('CSS2.1', 'selector.html#attribute-selectors', 'attribute selectors')}}</td> + <td>{{Spec2('CSS2.1')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("css.selectors.attribute")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>Selecting a single element: {{domxref("Document.querySelector()")}}, {{domxref("DocumentFragment.querySelector()")}}, or {{domxref("Element.querySelector()")}}</li> + <li>Selecting all matching elements: {{domxref("Document.querySelectorAll()")}}, {{domxref("DocumentFragment.querySelectorAll()")}}, or {{domxref("Element.querySelectorAll()")}}</li> + <li>The above methods are all implemented based on the {{domxref("ParentNode")}} mixin; see {{domxref("ParentNode.querySelector()")}} and {{domxref("ParentNode.querySelectorAll()")}}</li> +</ul> diff --git a/files/fa/web/css/بزرگنمایی/index.html b/files/fa/web/css/بزرگنمایی/index.html new file mode 100644 index 0000000000..e664b6b4cc --- /dev/null +++ b/files/fa/web/css/بزرگنمایی/index.html @@ -0,0 +1,134 @@ +--- +title: بزرگنمایی +slug: Web/CSS/بزرگنمایی +translation_of: Web/CSS/zoom +--- +<div>{{CSSRef}}{{Non-standard_header}}</div> + +<p><span class="seoSummary">The non-standard <strong><dfn><code>zoom</code></dfn></strong> <a href="/en-US/docs/Web/CSS">CSS</a> property can be used to control the magnification level of an element.</span> {{cssxref("transform-function/scale", "transform: scale()")}} should be used instead of this property, if possible. However, unlike CSS Transforms, <code>zoom</code> affects the layout size of the element.</p> + +<pre class="brush: css no-line-numbers">/* Keyword values */ +zoom: normal; +zoom: reset; + +/* <percentage> values */ +zoom: 50%; +zoom: 200%; + +/* <number> values */ +zoom: 1.1; +zoom: 0.7; + +/* Global values */ +zoom: inherit; +zoom: initial; +zoom: unset;</pre> + +<p>{{cssinfo}}</p> + +<h2 id="Syntax">Syntax</h2> + +<h3 id="Values">Values</h3> + +<dl> + <dt><code>normal</code></dt> + <dd>Render this element at its normal size.</dd> + <dt><code>reset</code> {{non-standard_inline}}</dt> + <dd>Do not (de)magnify this element if the user applies non-pinch-based zooming (e.g. by pressing <kbd>Ctrl</kbd>-<kbd>-</kbd> or <kbd>Ctrl</kbd>+<kbd>+</kbd> keyboard shortcuts) to the document. Only supported by WebKit (and possibly Blink).</dd> + <dt>{{cssxref("<percentage>")}}</dt> + <dd>Zoom factor. <code>100%</code> is equivalent to <code>normal</code>. Values larger than <code>100%</code> zoom in. Values smaller than <code>100%</code> zoom out.</dd> + <dt>{{cssxref("<number>")}}</dt> + <dd>Zoom factor. Equivalent to the corresponding percentage (<code>1.0</code> = <code>100%</code> = <code>normal</code>). Values larger than <code>1.0</code> zoom in. Values smaller than <code>1.0</code> zoom out.</dd> +</dl> + +<h3 id="Formal_syntax">Formal syntax</h3> + +<pre class="syntaxbox">{{csssyntax}}</pre> + +<h2 id="Examples">Examples</h2> + +<h3 id="First_example">First example</h3> + +<h4 id="HTML">HTML</h4> + +<pre class="brush: html"><p class="small">Small</p> +<p class="normal">Normal</p> +<p class="big">Big</p></pre> + +<h4 id="CSS">CSS</h4> + +<pre class="brush: css">p.small { + zoom: 75%; +} +p.normal { + zoom: normal; +} +p.big { + zoom: 2.5; +} +p { + display: inline-block; +} +p:hover { + zoom: reset; +} +</pre> + +<h4 id="Result">Result</h4> + +<p>{{EmbedLiveSample('First_example')}}</p> + +<h3 id="Second_example">Second example</h3> + +<h4 id="HTML_2">HTML</h4> + +<pre class="brush: html"><div id="a" class="circle"></div> +<div id="b" class="circle"></div> +<div id="c" class="circle"></div></pre> + +<h4 id="CSS_2">CSS</h4> + +<pre class="brush: css">div.circle { + width: 25px; + height: 25px; + border-radius: 100%; + text-align: center; + vertical-align: middle; + display: inline-block; + zoom: 1.5; +} +div#a { + background-color: gold; + zoom: normal; +} +div#b { + background-color: green; + zoom: 200%; +} +div#c { + background-color: blue; + zoom: 2.9; +} +</pre> + +<h4 id="Result_2">Result</h4> + +<p>{{EmbedLiveSample('Second_example')}}</p> + +<h2 id="Specifications">Specifications</h2> + +<p>This property is nonstandard and originated in Internet Explorer. Apple has <a href="https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/doc/uid/TP30001266-SW15">a description in the Safari CSS Reference</a>. Rossen Atanassov of Microsoft has <a href="http://cdn.rawgit.com/atanassov/css-zoom/master/Overview.html">an unofficial draft specification proposal on GitHub</a>.</p> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("css.properties.zoom")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="https://css-tricks.com/almanac/properties/z/zoom/"><code>zoom</code> entry in CSS-Tricks' CSS Almanac</a></li> + <li>The <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@viewport/zoom"><code>zoom</code> viewport descriptor</a>, for use with <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@viewport"><code>@viewport</code></a></li> + <li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=390936">Bug 390936: Implement Internet Explorer <code>zoom</code> property for CSS </a>on the Firefox issue tracker Bugzilla</li> +</ul> diff --git a/files/fa/web/guide/graphics/index.html b/files/fa/web/guide/graphics/index.html new file mode 100644 index 0000000000..e43abf0371 --- /dev/null +++ b/files/fa/web/guide/graphics/index.html @@ -0,0 +1,51 @@ +--- +title: گرافیک در وب +slug: Web/Guide/Graphics +tags: + - 2D + - 3D + - Canvas + - Graphics + - NeedsTranslation + - TopicStub + - Web + - WebGL +translation_of: Web/Guide/Graphics +--- +<p dir="rtl">اغلب سایتها و برنامههای جدید نیاز به نمایش گرافیکها را دارند<span class="seoSummary">.</span> در حالی که نمایش عکسهای ثابت میتواند به سادگی از طریق استفاده از المان {{HTMLElement("img")}} استفاده شود، یا با تنظیم عکس پشت زمبنه المانهای HTML با استفاده از خصوصیت {{cssxref("background-image")}} . شما اغلب میخواهید که عکسها را آزاد ایجاد کنید، یا بعد از این دستکاری کنید. <span class="seoSummary">این مقاله بینشی برای نحوه چگونگی انجام آن را برای شما فراهم میکند.</span></p> +<div class="row topicpage-table" dir="rtl"> + <div class="section"> + <h2 class="Documentation" id="Docs_for_add-on_developers" name="Docs_for_add-on_developers">گرافیکهای 2D</h2> + <dl> + <dt> + <a href="/en-US/docs/Web/Guide/Graphics/Drawing_graphics_with_canvas">ترسیم گرافیکها با بوم نقاشی</a></dt> + <dd> + راهنمای مقدماتی برای استفاده از المان {{HTMLElement("canvas")}} جهت رسم گرافیکهای 2D.</dd> + <dt> + <a href="/en-US/docs/SVG">SVG</a></dt> + <dd> + گرافیک برداری مقیاسپذیر (SVG) به شما اجازه میدهد تا از خطوط، بوم نقاشی، و دیگر اشکال هندسی برای نمایش گرافیکها استفاده کنید. با جلوگیری از استفاده از نقشه بیتها، شما میتوانید تصاویری با هر مقیاس ایجاد کنید.</dd> + </dl> + <p><span class="alllinks"><a href="/en-US/docs/tag/Graphics">نمایش همه...</a></span></p> + </div> + <div class="section"> + <h2 class="Documentation" id="Docs_for_add-on_developers" name="Docs_for_add-on_developers">گرافیکهای 3D</h2> + <dl> + <dt> + <a href="/en-US/docs/Web/WebGL">WebGL</a></dt> + <dd> + یک راهنما برای شروع با WebGL، APIهای گرافیکی 3D برای وب است. این تکنولوژی به شما اجازه استفاده از OpenGL ES استاندارد در محتوی وب را میدهد.</dd> + </dl> + </div> +</div> +<h2 dir="rtl" id="تصویر">تصویر</h2> +<dl> + <dt dir="rtl"> + <a href="/en-US/docs/Web/Guide/HTML/Using_HTML5_audio_and_video">استفاده از صدا و تصویر HTML5</a></dt> + <dd dir="rtl"> + تصویر تعبیه شده در اسناد HTML و کنترل بازپخش آن.</dd> + <dt dir="rtl"> + <a href="/en-US/docs/WebRTC">WebRTC</a></dt> + <dd dir="rtl"> + RTC درWebRTC به معنای ارتباطات بلادرنگ است، تکنولوژی است که به اشتراک گذاری جریان صوت/تصویر بین مرورگرهای سرویس گیرنده ها را امکان پذیر می کند (جفت ها).</dd> +</dl> diff --git a/files/fa/web/guide/index.html b/files/fa/web/guide/index.html new file mode 100644 index 0000000000..b4901157d6 --- /dev/null +++ b/files/fa/web/guide/index.html @@ -0,0 +1,29 @@ +--- +title: راهنمای توسعه دهنده وب +slug: Web/Guide +tags: + - Guide + - Landing + - NeedsTranslation + - TopicStub + - Web +translation_of: Web/Guide +--- +<p>These articles provide how-to information to help you make use of specific technologies and APIs.</p> + +<div class="note"> +<p><strong>Note:</strong> This page is going to be a mess for a little while until we finish migrating content. Our apologies!</p> +</div> + +<div>{{LandingPageListSubpages}}</div> + +<dl> + <dt><a href="/en-US/docs/JavaScript" title="/en-US/docs/JavaScript">JavaScript</a></dt> + <dd>JavaScript is the powerful scripting language used to create applications for the Web.</dd> +</dl> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/Reference" title="/en-US/docs/Web/Reference">Web Developer Reference</a></li> +</ul> diff --git a/files/fa/web/html/element/a/index.html b/files/fa/web/html/element/a/index.html new file mode 100644 index 0000000000..dc10c3f5be --- /dev/null +++ b/files/fa/web/html/element/a/index.html @@ -0,0 +1,490 @@ +--- +title: '<a>: The Anchor element' +slug: Web/HTML/Element/a +tags: + - فارسی +translation_of: Web/HTML/Element/a +--- +<div>{{HTMLRef}}</div> + +<p><span class="seoSummary">The <strong>HTML <code><a></code> element</strong> (or <em>anchor</em> element), with <a href="#href">its <code>href</code> attribute</a>, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address.</span> Content within each <code><a></code> <strong>should</strong> indicate the link's destination.</p> + +<div>{{EmbedInteractiveExample("pages/tabbed/a.html")}}</div> + + + +<h2 id="Attributes">Attributes</h2> + +<p>This element's attributes include the <a href="/en-US/docs/Web/HTML/Global_attributes">global attributes</a>.</p> + +<dl> + <dt id="download">{{HTMLAttrDef("download")}}{{HTMLVersionInline(5)}}</dt> + <dd>Prompts the user to save the linked URL instead of navigating to it. Can be used with or without a value:</dd> + <dd> + <ul> + <li>Without a value, the browser will suggest a filename/extension, generated from various sources: + <ul> + <li>The {{HTTPHeader("Content-Disposition")}} HTTP header</li> + <li>The final segment in the URL <a href="/en-US/docs/Web/API/URL/pathname">path</a></li> + <li>The {{Glossary("MIME_type", "media type")}} (from the ({{HTTPHeader("Content-Type")}} header, the start of a <a href="/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"><code>data:</code> URL</a>, or {{domxref("Blob.type")}} for a <a href="/en-US/docs/Web/API/URL/createObjectURL"><code>blob:</code> URL</a>)</li> + </ul> + </li> + <li>Defining a value suggests it as the filename. <code>/</code> and <code>\</code> characters are converted to underscores (<code>_</code>). Filesystems may forbid other characters in filenames, so browsers will adjust the suggested name if necessary.</li> + </ul> + + <div class="note"><strong>Notes:</strong> + + <ul> + <li><code>download</code> only works for <a href="/en-US/docs/Web/Security/Same-origin_policy">same-origin URLs</a>, or the <code>blob:</code> and <code>data:</code> schemes.</li> + <li> + <p>Note: if the <code>Content-Disposition</code> header has different information from the <code>download</code> attribute, resulting behaviour may differ:</p> + + <ul> + <li> + <p>If the header specifies a <code>filename</code>, it takes priority over the attribute.</p> + </li> + <li> + <p>If the header specifies a disposition of <code>inline</code> but no filename, Chrome, and Firefox 82 and later, prioritize the attribute and treat it as a download. Firefox versions before 82 prioritize the header and will display the content.</p> + </li> + </ul> + </li> + </ul> + </div> + </dd> + <dt id="href">{{HTMLAttrDef("href")}}</dt> + <dd> + <p>The URL that the hyperlink points to. Links are not restricted to HTTP-based URLs — they can use any URL scheme supported by browsers:</p> + + <ul> + <li>Sections of a page with fragment URLs</li> + <li>Pieces of media files with media fragments</li> + <li>Telephone numbers with <code>tel:</code> URLs</li> + <li>Email addresses with <code>mailto:</code> URLs</li> + <li>While web browsers may not support other URL schemes, web sites can with <code><a href="/en-US/docs/Web/API/Navigator/registerProtocolHandler">registerProtocolHandler()</a></code></li> + </ul> + </dd> + <dt id="hreflang">{{HTMLAttrDef("hreflang")}}</dt> + <dd>Hints at the human language of the linked URL. No built-in functionality. Allowed values are the same as <a href="/en-US/docs/Web/HTML/Global_attributes/lang">the global <code>lang</code> attribute</a>.</dd> + <dt id="ping">{{HTMLAttrDef("ping")}}</dt> + <dd>A space-separated list of URLs. When the link is followed, the browser will send {{HTTPMethod("POST")}} requests with the body <code>PING</code> to the URLs. Typically for tracking.</dd> + <dt id="referrerpolicy">{{HTMLAttrDef("referrerpolicy")}}{{Experimental_Inline}}</dt> + <dd>How much of the <a href="/en-US/docs/Web/HTTP/Headers/Referer">referrer</a> to send when following the link. See <a href="/en-US/docs/Web/HTTP/Headers/Referrer-Policy"><code>Referrer-Policy</code></a> for possible values and their effects.</dd> + <dt id="rel">{{HTMLAttrDef("rel")}}</dt> + <dd>The relationship of the linked URL as space-separated <a href="/en-US/docs/Web/HTML/Link_types">link types</a>.</dd> + <dt id="target">{{HTMLAttrDef("target")}}</dt> + <dd>Where to display the linked URL, as the name for a <em>browsing context</em> (a tab, window, or <code><iframe></code>). The following keywords have special meanings for where to load the URL: + <ul> + <li><code>_self</code>: the current browsing context. (Default)</li> + <li><code>_blank</code>: usually a new tab, but users can configure browsers to open a new window instead.</li> + <li><code>_parent</code>: the parent browsing context of the current one. If no parent, behaves as <code>_self</code>.</li> + <li><code>_top</code>: the topmost browsing context (the "highest" context that’s an ancestor of the current one). If no ancestors, behaves as <code>_self</code>.</li> + </ul> + + <div class="note"> + <p><strong>Note:</strong> When using <code>target</code>, add <code>rel="noreferrer noopener"</code> to avoid exploitation of the <code>window.opener</code> API;</p> + </div> + + <div class="note"> + <p><strong>Note:</strong> In newer browser versions (e.g. Firefox 79+) setting <code>target="_blank"</code> on <code><a></code> elements implicitly provides the same <code>rel</code> behavior as setting <code>rel="noopener"</code>.</p> + </div> + </dd> + <dt id="type">{{HTMLAttrDef("type")}}</dt> + <dd>Hints at the linked URL’s format with a {{Glossary("MIME type")}}. No built-in functionality.</dd> +</dl> + +<h3 id="Obsolete_attributes">Obsolete attributes</h3> + +<dl> + <dt id="charset">{{HTMLAttrDef("charset")}}{{Obsolete_Inline("HTML5")}}</dt> + <dd>Hinted at the {{Glossary("character encoding")}} of the linked URL. + <div class="note"> + <p><strong>Note:</strong> This attribute is obsolete and <strong>should not be used by authors</strong>. Use the HTTP {{HTTPHeader("Content-Type")}} header on the linked URL.</p> + </div> + </dd> + <dt id="coords">{{HTMLAttrDef("coords")}}{{Obsolete_Inline("HTML5")}}</dt> + <dd>Used with <a href="#shape">the <code>shape</code> attribute</a>. A comma-separated list of coordinates.</dd> + <dt id="name">{{HTMLAttrDef("name")}}{{Obsolete_Inline("HTML5")}}</dt> + <dd>Was required to define a possible target location in a page. In HTML 4.01, <code>id</code> and <code>name</code> could both be used on <code><a></code>, as long as they had identical values. + <div class="note"> + <p><strong>Note:</strong> Use the global attribute {{HTMLAttrxRef("id")}} instead.</p> + </div> + </dd> + <dt id="rev">{{HTMLAttrDef("rev")}}{{Obsolete_Inline("HTML5")}}</dt> + <dd>Specified a reverse link; the opposite of <a href="#rel">the <code>rel</code> attribute</a>. Deprecated for being very confusing.</dd> + <dt id="shape">{{HTMLAttrDef("shape")}}{{Obsolete_Inline("HTML5")}}</dt> + <dd>The shape of the hyperlink’s region in an image map. + <div class="note"><strong>Note:</strong> Use the {{HTMLElement("area")}} element for image maps instead.</div> + </dd> +</dl> + +<h2 id="Properties">Properties</h2> + +<table class="properties"> + <tbody> + <tr> + <th scope="row"><a href="/en-US/docs/Web/HTML/Content_categories">Content categories</a></th> + <td><a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">Flow content</a>, <a href="/en-US/docs/Web/HTML/Content_categories#Phrasing_content">phrasing content</a>, <a href="/en-US/docs/Web/HTML/Content_categories#Interactive_content">interactive content</a>, palpable content.</td> + </tr> + <tr> + <th scope="row">Permitted content</th> + <td><a href="/en-US/docs/Web/HTML/Content_categories#Transparent_content_model">Transparent</a>, containing either <a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">flow content</a> (excluding <a href="/en-US/docs/Web/HTML/Content_categories#Interactive_content">interactive content</a>) or <a href="/en-US/docs/Web/HTML/Content_categories#Phrasing_content">phrasing content</a>.</td> + </tr> + <tr> + <th scope="row">Tag omission</th> + <td>{{no_tag_omission}}</td> + </tr> + <tr> + <th scope="row">Permitted parents</th> + <td>Any element that accepts <a href="/en-US/docs/Web/HTML/Content_categories#Phrasing_content">phrasing content</a>, or any element that accepts <a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">flow content</a>, but not other <code><a></code> elements.</td> + </tr> + <tr> + <th scope="row">Implicit ARIA role</th> + <td>{{ARIARole("link")}} when <code>href</code> attribute is present, otherwise <a href="https://www.w3.org/TR/html-aria/#dfn-no-corresponding-role">no corresponding role</a></td> + </tr> + <tr> + <th scope="row">Permitted ARIA roles</th> + <td> + <p>When <code>href</code> attribute is present:</p> + + <ul> + <li>{{ARIARole("button")}}</li> + <li>{{ARIARole("checkbox")}}</li> + <li>{{ARIARole("menuitem")}}</li> + <li>{{ARIARole("menuitemcheckbox")}}</li> + <li>{{ARIARole("menuitemradio")}}</li> + <li>{{ARIARole("option")}}</li> + <li>{{ARIARole("radio")}}</li> + <li>{{ARIARole("switch")}}</li> + <li>{{ARIARole("tab")}}</li> + <li>{{ARIARole("treeitem")}}</li> + </ul> + + <p>When <code>href</code> attribute is not present:</p> + + <ul> + <li>any</li> + </ul> + </td> + </tr> + <tr> + <th scope="row">DOM interface</th> + <td>{{DOMxRef("HTMLAnchorElement")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Examples">Examples</h2> + +<h3 id="Linking_to_an_absolute_URL">Linking to an absolute URL</h3> + +<h4 id="HTML">HTML</h4> + +<pre class="brush: html notranslate"><a href="https://www.mozilla.com"> + Mozilla +</a></pre> + +<h4 id="Result">Result</h4> + +<p>{{EmbedLiveSample('Linking_to_an_absolute_URL')}}</p> + +<h3 id="Linking_to_relative_URLs">Linking to relative URLs</h3> + +<h4 id="HTML_2">HTML</h4> + +<pre class="brush: html notranslate"><a href="//example.com">Scheme-relative URL</a> +<a href="/en-US/docs/Web/HTML">Origin-relative URL</a> +<a href="./p">Directory-relative URL</a> +</pre> + +<div class="hidden"> +<h4 id="CSS">CSS</h4> + +<pre class="brush: css notranslate">a { display: block; margin-bottom: 0.5em }</pre> +</div> + +<h4 id="Result_2">Result</h4> + +<p>{{EmbedLiveSample('Linking_to_relative_URLs')}}</p> + +<h3 id="Linking_to_an_element_on_the_same_page">Linking to an element on the same page</h3> + +<pre class="brush: html notranslate"><!-- <a> element links to the section below --> +<p><a href="#Section_further_down"> + Jump to the heading below +</a></p> + +<!-- Heading to link to --> +<h2 id="Section_further_down">Section further down</h2> +</pre> + +<div class="blockIndicator note"> +<p><strong>Note:</strong> You can use <code>href="#top"</code> or the empty fragment (<code>href="#"</code>) to link to the top of the current page, <a href="https://html.spec.whatwg.org/multipage/browsing-the-web.html#scroll-to-the-fragment-identifier">as defined in the HTML specification</a>.</p> +</div> + +<h3 id="Linking_to_an_email_address">Linking to an email address</h3> + +<p>To create links that open in the user's email program to let them send a new message, use the <code>mailto:</code> scheme:</p> + +<pre class="brush: html notranslate"><a href="mailto:nowhere@mozilla.org">Send email to nowhere</a></pre> + +<p>For details about <code>mailto:</code> URLs, such as including a subject or body, see <a href="/en-US/docs/Web/Guide/HTML/Email_links">Email links</a> or {{RFC(6068)}}.</p> + +<h3 id="Linking_to_telephone_numbers">Linking to telephone numbers</h3> + +<pre class="brush: html notranslate"><a href="tel:+49.157.0156">+49 157 0156</a> +<a href="tel:+1(555)5309">(555) 5309</a></pre> + +<p><code>tel:</code> link behavior varies with device capabilities:</p> + +<ul> + <li>Cellular devices autodial the number.</li> + <li>Most operating systems have programs that can make calls, like Skype or FaceTime.</li> + <li>Websites can make phone calls with {{domxref("Navigator/registerProtocolHandler", "registerProtocolHandler")}}, such as <code>web.skype.com</code>.</li> + <li>Other behaviors include saving the number to contacts, or sending the number to another device.</li> +</ul> + +<p>See {{RFC(3966)}} for syntax, additional features, and other details about the <code>tel:</code> URL scheme.</p> + +<h3 id="Using_the_download_attribute_to_save_a_<canvas>_as_a_PNG">Using the download attribute to save a <canvas> as a PNG</h3> + +<p>To save a {{HTMLElement("canvas")}} element’s contents as an image, you can create a link with a <code>download</code> attribute and the canvas data as a <code>data:</code> URL:</p> + +<h4 id="Example_painting_app_with_save_link">Example painting app with save link</h4> + +<h5 id="HTML_3">HTML</h5> + +<pre class="brush: html notranslate"><p>Paint by holding down the mouse button and moving it. + <a href="" download="my_painting.png">Download my painting</a> +</p> + +<canvas width="300" height="300"></canvas> +</pre> + +<h5 id="CSS_2">CSS</h5> + +<pre class="brush: css notranslate">html { + font-family: sans-serif; +} +canvas { + background: #fff; + border: 1px dashed; +} +a { + display: inline-block; + background: #69c; + color: #fff; + padding: 5px 10px; +}</pre> + +<h5 id="JavaScript">JavaScript</h5> + +<pre class="brush: js notranslate">var canvas = document.querySelector('canvas'), + c = canvas.getContext('2d'); +c.fillStyle = 'hotpink'; + +function draw(x, y) { + if (isDrawing) { + c.beginPath(); + c.arc(x, y, 10, 0, Math.PI*2); + c.closePath(); + c.fill(); + } +} + +canvas.addEventListener('mousemove', event => + draw(event.offsetX, event.offsetY) +); +canvas.addEventListener('mousedown', () => isDrawing = true); +canvas.addEventListener('mouseup', () => isDrawing = false); + +document.querySelector('a').addEventListener('click', event => + event.target.href = canvas.toDataURL() +); +</pre> + +<h5 id="Result_3">Result</h5> + +<p>{{EmbedLiveSample('Example_painting_app_with_save_link', '100%', '400')}}</p> + +<h2 id="Security_and_privacy">Security and privacy</h2> + +<p><code><a></code> elements can have consequences for users’ security and privacy. See <a href="/en-US/docs/Web/Security/Referer_header:_privacy_and_security_concerns"><code>Referer</code> header: privacy and security concerns</a> for information.</p> + +<p>Using <code>target="_blank"</code> without <code>rel="noreferrer"</code> and <code>rel="noopener"</code> makes the website vulnerable to {{domxref("window.opener")}} API exploitation attacks (<a href="https://www.jitbit.com/alexblog/256-targetblank---the-most-underestimated-vulnerability-ever/">vulnerability description</a>), although note that, in newer browser versions (e.g. Firefox 79+) setting <code>target="_blank"</code> implicitly provides the same protection as setting <code>rel="noopener"</code>.</p> + +<h2 id="Accessibility">Accessibility</h2> + +<h3 id="Strong_link_text">Strong link text</h3> + +<p><strong>The content inside a link should indicate where the link goes</strong>, even out of context.</p> + +<h4 id="Inaccessible_weak_link_text">Inaccessible, weak link text</h4> + +<p>A sadly common mistake is to only link the words “click here” or “here”:</p> + +<pre class="brush: html example-bad notranslate"><p> + Learn more about our products <a href="/products">here</a>. +</p> +</pre> + +<h4 id="Strong_link_text_2">Strong link text</h4> + +<p>Luckily, this is an easy fix, and it’s actually shorter than the inaccessible version!</p> + +<pre class="brush: html example-good notranslate"><p> + Learn more <a href="/products">about our products</a>. +</p></pre> + +<p>Assistive software have shortcuts to list all links on a page. However, strong link text benefits all users — the “list all links” shortcut emulates how sighted users quickly scan pages.</p> + +<h3 id="onclick_events">onclick events</h3> + +<p>Anchor elements are often abused as fake buttons by setting their <code>href</code> to <code>#</code> or <code>javascript:void(0)</code> to prevent the page from refreshing, then listening for their <code>click</code> events .</p> + +<p>These bogus <code>href</code> values cause unexpected behavior when copying/dragging links, opening links in a new tab/window, bookmarking, or when JavaScript is loading, errors, or is disabled. They also convey incorrect semantics to assistive technologies, like screen readers.</p> + +<p>Use a {{HTMLElement("button")}} instead. In general, <strong>you should only use a hyperlink for navigation to a real URL</strong>.</p> + +<h3 id="External_links_and_linking_to_non-HTML_resources">External links and linking to non-HTML resources</h3> + +<p>Links that open in a new tab/window via <code>target="_blank"</code>, or links that point to a download file should indicate what will happen when the link is followed.</p> + +<p>People experiencing low vision conditions, navigating with the aid of screen reading technology, or with cognitive concerns may be confused when a new tab, window, or application opens unexpectedly. Older screen-reading software may not even announce the behavior.</p> + +<h4 id="Link_that_opens_a_new_tabwindow">Link that opens a new tab/window</h4> + +<pre class="brush: html notranslate"><a target="_blank" href="https://www.wikipedia.org"> + Wikipedia (opens in new tab) +</a> +</pre> + +<h4 id="Link_to_a_non-HTML_resource">Link to a non-HTML resource</h4> + +<pre class="brush: html notranslate"><a href="2017-annual-report.ppt"> + 2017 Annual Report (PowerPoint) +</a> +</pre> + +<p>If an icon is used to signify link behavior, make sure it has {{HTMLAttrxRef("alt", "img", "alt text", "true")}}:</p> + +<pre class="brush: html notranslate"><a target="_blank" href="https://www.wikipedia.org"> + Wikipedia + <img alt="(opens in new tab)" src="newtab.svg"> +</a> + +<a href="2017-annual-report.ppt"> + 2017 Annual Report + <img alt="(PowerPoint file)" src="ppt-icon.svg"> +</a></pre> + +<ul> + <li><a href="https://webaim.org/techniques/hypertext/hypertext_links">WebAIM: Links and Hypertext - Hypertext Links</a></li> + <li><a href="/en-US/docs/Web/Accessibility/Understanding_WCAG/Understandable#Guideline_3.2_—_Predictable_Make_Web_pages_appear_and_operate_in_predictable_ways">MDN / Understanding WCAG, Guideline 3.2</a></li> + <li><a href="https://www.w3.org/TR/WCAG20-TECHS/G200.html">G200: Opening new windows and tabs from a link only when necessary</a></li> + <li><a href="https://www.w3.org/TR/WCAG20-TECHS/G201.html">G201: Giving users advanced warning when opening a new window</a></li> +</ul> + +<h3 id="Skip_links">Skip links</h3> + +<p>A <strong>skip link</strong> is a link placed as early as possible in {{HTMLElement("body")}} content that points to the beginning of the page's main content. Usually, CSS hides a skip link offscreen until focused.</p> + +<pre class="notranslate"><body> + <a href="#content">Skip to main content</a> + + <header> + … + </header> + + <main id="content"> <!-- The skip link jumps to here --> +</pre> + +<pre class="brush: css notranslate">.skip-link { + position: absolute; + top: -3em; + background: #fff; +} +.skip-link:focus { + top: 0; +}</pre> + +<p>Skip links let keyboard users bypass content repeated throughout multiple pages, such as header navigation.</p> + +<p>Skip links are especially useful for people who navigate with the aid of assistive technology such as switch control, voice command, or mouth sticks/head wands, where the act of moving through repetitive links can be laborious.</p> + +<ul> + <li><a href="https://webaim.org/techniques/skipnav/">WebAIM: "Skip Navigation" Links</a></li> + <li><a href="https://a11yproject.com/posts/skip-nav-links/">How-to: Use Skip Navigation links</a></li> + <li><a href="/en-US/docs/Web/Accessibility/Understanding_WCAG/Operable#Guideline_2.4_%E2%80%94_Navigable_Provide_ways_to_help_users_navigate_find_content_and_determine_where_they_are">MDN / Understanding WCAG, Guideline 2.4 explanations</a></li> + <li><a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/navigation-mechanisms-skip.html">Understanding Success Criterion 2.4.1</a></li> +</ul> + +<h3 id="Size_and_proximity">Size and proximity</h3> + +<h4 id="Size">Size</h4> + +<p>Interactive elements, like links, should provide an area large enough that it is easy to activate them. This helps a variety of people, including those with motor control issues and those using imprecise inputs such as a touchscreen. A minimum size of 44×44 <a href="https://www.w3.org/TR/WCAG21/#dfn-css-pixels">CSS pixels</a> is recommended.</p> + +<p>Text-only links in prose content are exempt from this requirement, but it’s still a good idea to make sure enough text is hyperlinked to be easily activated.</p> + +<ul> + <li><a href="https://www.w3.org/WAI/WCAG21/Understanding/target-size.html">Understanding Success Criterion 2.5.5: Target Size</a></li> + <li><a href="http://adrianroselli.com/2019/06/target-size-and-2-5-5.html">Target Size and 2.5.5</a></li> + <li><a href="https://a11yproject.com/posts/large-touch-targets/">Quick test: Large touch targets</a></li> +</ul> + +<h4 id="Proximity">Proximity</h4> + +<p>Interactive elements, like links, placed in close visual proximity should have space separating them. Spacing helps people with motor control issues, who may otherwise accidentally activate the wrong interactive content.</p> + +<p>Spacing may be created using CSS properties like {{CSSxRef("margin")}}.</p> + +<ul> + <li><a href="https://axesslab.com/hand-tremors/">Hand tremors and the giant-button-problem</a></li> +</ul> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("Referrer Policy", "#referrer-policy-delivery-referrer-attribute", "referrer attribute")}}</td> + <td>{{Spec2("Referrer Policy")}}</td> + <td>Added the <code>referrerpolicy</code> attribute.</td> + </tr> + <tr> + <td>{{SpecName("HTML WHATWG", "textlevel-semantics.html#the-a-element", "<a>")}}</td> + <td>{{Spec2("HTML WHATWG")}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName("HTML5 W3C", "textlevel-semantics.html#the-a-element", "<a>")}}</td> + <td>{{Spec2("HTML5 W3C")}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName("HTML4.01", "struct/links.html#h-12.2", "<a>")}}</td> + <td>{{Spec2("HTML4.01")}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("html.elements.a")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{HTMLElement("link")}} is similar to <code><a></code>, but for metadata hyperlinks that are invisible to users.</li> + <li>{{CSSxRef(":link")}} is a CSS pseudo-class that will match <code><a></code> elements with valid <code>href</code> attributes.</li> +</ul> diff --git a/files/fa/web/html/element/abbr/index.html b/files/fa/web/html/element/abbr/index.html new file mode 100644 index 0000000000..b7a78b41f7 --- /dev/null +++ b/files/fa/web/html/element/abbr/index.html @@ -0,0 +1,142 @@ +--- +title: <abbr> +slug: Web/HTML/Element/abbr +translation_of: Web/HTML/Element/abbr +--- +<p id="Summary">{{HTMLRef}}</p> + +<p dir="rtl">عنصر <abbr> (یا عنصر مخفف) نشان دهننده مخفف و به صورت اختتیاری شرحی کامل برای آن است. درصورت وجود شرح ، باید آن را به طور کامل بدون چیز دیگری در در صفت title بنویسید.</p> + +<pre class="brush: html"><p>I do <abbr title="Hypertext Markup Language">HTML</abbr></p></pre> + +<p style="margin-top: -1.5em;"><small>See more in depth examples in the <em><a href="https://developer.mozilla.org/en-US/Learn/HTML/Howto/Mark_abbreviations_and_make_them_understandable">How to mark abbreviations and make them understandable</a></em> article.</small></p> + +<table class="properties"> + <tbody> + <tr> + <th scope="row">DOM Interface</th> + <td>{{domxref("HTMLElement")}}</td> + </tr> + <tr> + <th scope="row"><a href="/en-US/docs/HTML/Content_categories">Content categories</a></th> + <td><a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">Flow content</a>, <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="HTML/Content categories#Phrasing content">phrasing content</a>, palpable content</td> + </tr> + <tr> + <th scope="row">Permitted content</th> + <td><a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="HTML/Content_categories#Phrasing_content">Phrasing content</a></td> + </tr> + <tr> + <th scope="row">Permitted parent elements</th> + <td>Any element that accepts <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="HTML/Content_categories#Phrasing_content">phrasing content</a></td> + </tr> + </tbody> +</table> + +<h2 dir="rtl" id="صفات">صفات</h2> + +<p dir="rtl">این عنصر تنها شامل <a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes">صفات عمومی</a> است.</p> + +<p dir="rtl">برای تعریف شرح کامل مخفف از صفت {{htmlattrxref("title")}} استفده کنید.</p> + +<h2 dir="rtl" id="Specifications" name="Specifications">مشخصات</h2> + +<p dir="rtl"> </p> + +<table class="standard-table" dir="rtl"> + <thead> + <tr> + <th scope="col">مشخصه</th> + <th scope="col">وضعیت</th> + <th scope="col">توضیح</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', 'text-level-semantics.html#the-abbr-element', '<abbr>')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('HTML5 W3C', 'text-level-semantics.html#the-abbr-element', '<abbr>')}}</td> + <td>{{Spec2('HTML5 W3C')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('HTML4.01', 'struct/text.html#edef-ABBR', '<abbr>')}}</td> + <td>{{Spec2('HTML4.01')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 dir="rtl" id="سازگاری_با_مرورگر">سازگاری با مرورگر</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>2.0</td> + <td>{{CompatGeckoDesktop(1.0)}} [1]</td> + <td>7.0</td> + <td>1.3</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] Up to Gecko 1.9.2 (Firefox 3.6), Firefox implemented the {{domxref("HTMLSpanElement")}} interface for this element instead of the {{domxref("HTMLElement")}} interface.</p> + +<h2 dir="rtl" id="ظاهر_پیش_فرض">ظاهر پیش فرض</h2> + +<p dir="rtl">هدف از این عنصر صرفا راحتی نویسند است و همه مرورگر ها آن را به صورت خطی (inline) نمایش میدهند.</p> + +<ul> + <li dir="rtl">برخی از مرورگر های مانند Internet Explorer ، این عنصر را همانند عنصر {{HTMLElement("span")}} نمایش میدهند</li> + <li dir="rtl">Opern ، Firefox و برخی دیگر به محتوای آن یک آندرلاین نقطه نقطه اضافه میکنند.</li> +</ul> + +<h2 dir="rtl" id="همچنین_ببینید">همچنین ببینید</h2> + +<ul> + <li dir="rtl"><a href="/en-US/Learn/HTML/Element/abbr">Using the <abbr> element</a></li> + <li>Other elements conveying <a href="/en-US/docs/HTML/Text_level_semantics_conveying_elements" title="HTML/Text level semantics conveying elements">text-level semantics</a>: {{HTMLElement("a")}}, {{HTMLElement("em")}}, {{HTMLElement("strong")}}, {{HTMLElement("small")}}, {{HTMLElement("cite")}}, {{HTMLElement("q")}}, {{HTMLElement("dfn")}}, {{HTMLElement("time")}}, {{HTMLElement("code")}}, {{HTMLElement("var")}}, {{HTMLElement("samp")}}, {{HTMLElement("kbd")}}, {{HTMLElement("sub")}}, {{HTMLElement("sup")}}, {{HTMLElement("b")}}, {{HTMLElement("i")}}, {{HTMLElement("mark")}}, {{HTMLElement("ruby")}}, {{HTMLElement("rp")}}, {{HTMLElement("rt")}}, {{HTMLElement("bdo")}}, {{HTMLElement("span")}}, {{HTMLElement("br")}}, {{HTMLElement("wbr")}}.</li> +</ul> + +<div> </div> + +<div> </div> diff --git a/files/fa/web/html/element/data/index.html b/files/fa/web/html/element/data/index.html new file mode 100644 index 0000000000..9d06506179 --- /dev/null +++ b/files/fa/web/html/element/data/index.html @@ -0,0 +1,94 @@ +--- +title: <data> +slug: Web/HTML/Element/data +translation_of: Web/HTML/Element/data +--- +<div>{{HTMLRef}}</div> + +<p>The <strong>HTML <code><data></code> element</strong> links a given content with a machine-readable translation. If the content is time- or date-related, the {{HTMLElement("time")}} element must be used.</p> + +<div>{{EmbedInteractiveExample("pages/tabbed/data.html", "tabbed-standard")}}</div> + +<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples </a> and send us a pull request.</p> + +<table class="properties"> + <tbody> + <tr> + <th scope="row"><a href="/en-US/docs/HTML/Content_categories">Content categories</a></th> + <td><a href="/en-US/docs/HTML/Content_categories#Flow_content">Flow content</a>, <a href="/en-US/docs/HTML/Content_categories#Phrasing_content">phrasing content</a>, palpable content.</td> + </tr> + <tr> + <th scope="row">Permitted content</th> + <td><a href="/en-US/docs/HTML/Content_categories#Phrasing_content">Phrasing content</a>.</td> + </tr> + <tr> + <th scope="row">Tag omission</th> + <td>{{no_tag_omission}}</td> + </tr> + <tr> + <th scope="row">Permitted parents</th> + <td>Any element that accepts <a href="/en-US/docs/HTML/Content_categories#Phrasing_content">phrasing content</a>.</td> + </tr> + <tr> + <th scope="row">DOM interface</th> + <td>{{domxref("HTMLDataElement")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Attributes">Attributes</h2> + +<p>This element's attributes include the <a href="/en-US/docs/HTML/Global_attributes">global attributes</a>.</p> + +<dl> + <dt>{{htmlattrdef("value")}}</dt> + <dd>This attribute specifies the machine-readable translation of the content of the element.</dd> +</dl> + +<h2 id="Example">Example</h2> + +<p>The following example displays product names but also associates each name with a product number.</p> + +<pre class="brush: html"><p>New Products</p> +<ul> + <li><data value="398">Mini Ketchup</data></li> + <li><data value="399">Jumbo Ketchup</data></li> + <li><data value="400">Mega Jumbo Ketchup</data></li> +</ul> +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', 'semantics.html#the-data-element', '<data>')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>No change from {{SpecName('HTML5 W3C')}}</td> + </tr> + <tr> + <td>{{SpecName('HTML5 W3C', 'text-level-semantics.html#the-data-element', '<data>')}}</td> + <td>{{Spec2('HTML5 W3C')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("html.elements.data")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>The HTML {{HTMLElement("time")}} element.</li> +</ul> diff --git a/files/fa/web/html/element/em/index.html b/files/fa/web/html/element/em/index.html new file mode 100644 index 0000000000..527d56af2f --- /dev/null +++ b/files/fa/web/html/element/em/index.html @@ -0,0 +1,150 @@ +--- +title: <em> +slug: Web/HTML/Element/em +translation_of: Web/HTML/Element/em +--- +<h2 dir="rtl" id="خلاصه">خلاصه</h2> + +<p dir="rtl">برچسب HTML تاکید <em> نشانه آن است که متن دارای تاکید و اهمیت بیشری می باشد. برچسب <em> میتواند به صورت تو در تو باشد و هر مرحله از تودرتویی به معنای درجه بیشتری از مهم بودن میباشد.</p> + +<p dir="rtl"> </p> + +<div class="note" dir="rtl"><strong>توجه داشته یاشید: </strong>به صورت معمول این عنصر به صورت مورب (کج) نمایش داده میشود ، با این حال، حقیقتا نباید برای اضافه کردن ظاهر مورب از این تگ استفاده نمود. برای مشخص کردن عنوان کاری (مانند: کتاب ، بازی ، آهنگ و ...) از {{HTMLElement("cite")}} استفاده کنید. این عنصر نیز معمولا با ظاهر مورب نمایش داده میشود. همچنین از {{HTMLElement("strong")}} برای متن هایی استفاده کنید که درجه اهمیت بیشتری نسبت به متن های اطراف دارند.</div> + +<table class="properties"> + <tbody> + <tr> + <th scope="row"><a href="/en-US/docs/Web/HTML/Content_categories">Content categories</a></th> + <td><a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">Flow content</a>, <a href="/en-US/docs/Web/HTML/Content_categories#Phrasing_content">phrasing content</a>, palpable content</td> + </tr> + <tr> + <th scope="row">Permitted content</th> + <td><a href="/en-US/docs/Web/HTML/Content_categories#Phrasing_content">Phrasing content</a>.</td> + </tr> + <tr> + <th scope="row">Tag omission</th> + <td>{{no_tag_omission}}</td> + </tr> + <tr> + <th scope="row">Permitted parent elements</th> + <td>Any element that accepts <a href="/en-US/docs/Web/HTML/Content_categories#Phrasing_content">phrasing content</a>.</td> + </tr> + <tr> + <th scope="row">DOM interface</th> + <td>{{domxref("HTMLElement")}} Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements the {{domxref("HTMLSpanElement")}} interface for this element.</td> + </tr> + </tbody> +</table> + +<h2 dir="rtl" id="ویژگی_ها">ویژگی ها</h2> + +<p dir="rtl">این عنصر تنها شامل <a href="/en-US/docs/Web/HTML/Global_attributes">ویژگی های همگانی</a> می باشد.</p> + +<h2 dir="rtl" id="مثال">مثال</h2> + +<p dir="rtl">عنصر <em> اغلب برای نمایش تضاد ضمنی یا صریح استفاده میشود.</p> + +<pre class="brush: html" dir="rtl"><p> + In HTML 5, what was previously called <em>block-level</em> content is now called <em>flow</em> content. +</p></pre> + +<h3 dir="rtl" id="Result" name="Result">نتیجه</h3> + +<p>In HTML 5, what was previously called <em>block-level</em> content is now called <em>flow</em> content.</p> + +<h2 dir="rtl" id="<i>_در_مقابل_<em>"><i> در مقابل <em></h2> + +<p dir="rtl"><span style="line-height: 1.5;">این اکثرا برای توسعه دهندگان جدید گیج کننده است ، که چرا تعداد بسیاری عنصر مختلف برای تاکید بر برخی از متن وجود دارد. اتفاقا <i> و <em> یکی از شاید ترین این موارد هستند ، چرا از <i> و <em> با هم استفاده کنیم؟ آنها دقیقا یک نتیجه را تولید میکنند ، درست است؟</span></p> + +<p dir="rtl">نه دقیقا. نتیجه بصری اینگونه است، اما به صورت پیش فرض، این دو برچسب نتیجه خود را به صورت مورب نشان میدهند. اما از لحاظ معنایی این دو متفاوت اند. برچسب <em> نشان دهنده تاکید بر محتوای آن است درحای که <i> نشان دهنده یک متن معمولی است. مانند نام یک فیلم یا کتاب یک لغت خارجی یا زمانی که متن مربوط به تعریف یک لغت بجای استفاده از معنای آن باشد میباشد.</p> + +<p dir="rtl">مثالی برای <em> میتواند این باشد:«این را همین اکنون انجام بده!» یا «ما باید کاری برای آن میکردیم.» یک شخص یا نرم افزار که متن را میخواند متن های مورب را با تاکید بیشتری میخواند.</p> + +<p dir="rtl">به عنوان مثالی برای <i> میتوان گفت:«ملکه مری دیشب با ناز و عشوه راه میرفت.» در اینجا هیچ تاکید خواص و یا اهمیت اضافه ای به "ملکه مری" وجود ندارد. این تنها نشان دهنده این است که شی ما در سوال ملکه ای به نام مری نیست. بلکه یک کشتی به نام ملکه مری است. مثال دیگری برای <i> میتواند این باشد:«این کلمه یک مقاله است»</p> + +<h2 dir="rtl" id="Specifications" name="Specifications">مشخصات</h2> + +<table class="standard-table" dir="rtl"> + <thead> + <tr> + <th scope="col">مشخصه</th> + <th scope="col">وضعیت</th> + <th scope="col">توضیح</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', 'text-level-semantics.html#the-em-element', '<em>')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('HTML5 W3C', 'text-level-semantics.html#the-em-element', '<em>')}}</td> + <td>{{Spec2('HTML5 W3C')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('HTML4.01', 'struct/text.html#h-9.2.1', '<em>')}}</td> + <td>{{Spec2('HTML4.01')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 dir="rtl" id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>1.0</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 dir="rtl" id="See_also" name="See_also">همچنین ببینید</h2> + +<ul dir="rtl"> + <li>{{HTMLElement("i")}}</li> +</ul> + +<div>{{HTMLRef}}</div> diff --git a/files/fa/web/html/element/heading_elements/index.html b/files/fa/web/html/element/heading_elements/index.html new file mode 100644 index 0000000000..9caa97cd0b --- /dev/null +++ b/files/fa/web/html/element/heading_elements/index.html @@ -0,0 +1,143 @@ +--- +title: Heading elements +slug: Web/HTML/Element/Heading_Elements +translation_of: Web/HTML/Element/Heading_Elements +--- +<h2 dir="rtl" id="خلاصه">خلاصه</h2> +<p dir="rtl">عنصر<strong> سرفصل</strong> در شش سطح برای سر فصل گذاری پیاده سازی شده است , <h1> برای مهم ترین(برجسته ترین) و <h6> برای کم اهمیت ترین. عنصر سر فصل به طور خلاصه موضوع اصلی بخش را معرفی می کند.</p> +<p>Heading information may be used by user agents, for example, to construct a table of contents for a document automatically.</p> +<ul class="htmlelt" dir="rtl"> + <li dir="ltr"><dfn><a href="/en-US/docs/HTML/Content_categories" title="HTML/Content_categories">Content categories</a></dfn> <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">Flow content</a>, heading content, palpable content.</li> + <li dir="ltr"><dfn>Permitted content</dfn> <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="HTML/Content_categories#Phrasing_content">Phrasing content</a>.</li> + <li dir="ltr"><dfn>Tag omission</dfn> {{no_tag_omission}}</li> + <li dir="ltr"><dfn>Permitted parent elements</dfn> Any element that accepts <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">flow content</a>; or as a child of an {{HTMLElement("hgroup")}} element</li> + <li dir="ltr"><dfn>DOM interface</dfn> {{domxref("HTMLHeadingElement")}}</li> +</ul> +<h2 dir="rtl" id="صفات">صفات</h2> +<p dir="rtl"><span style="line-height: 21px;">این عنصر ها شامل </span><a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes" style="line-height: 21px;" title="HTML/Global attributes">صفات سراسری</a><span style="line-height: 21px;"> میشوند. </span><a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes" style="line-height: 21px;" title="HTML/Global attributes"> </a></p> +<p dir="rtl">صفت <strong>align</strong> یک صفت {{deprecated_inline}} در {{HTMLVersionInline(4.01)}} و {{obsolete_inline}} در {{HTMLVersionInline(5)}} است.</p> +<h2 dir="rtl" id="مثال_ها">مثال ها</h2> +<h3 dir="rtl" id="تمام_سرفصل_ها">تمام سرفصل ها</h3> +<pre class="brush: html" dir="rtl"><h1>Heading level 1</h1> +<h2>Heading level 2</h2> +<h3>Heading level 3</h3> +<h4>Heading level 4</h4> +<h5>Heading level 5</h5> +<h6>Heading level 6</h6> +</pre> +<p dir="rtl">خروجی کد HTML بالا :</p> +<p dir="rtl"><img alt="Image:HTML-headers2.png" src="/@api/deki/files/245/=HTML-headers2.png" style="float: left;"></p> +<p dir="rtl"> </p> +<p dir="rtl"> </p> +<p dir="rtl"> </p> +<p dir="rtl"> </p> +<h3 dir="rtl" id="sect1"> </h3> +<h3 dir="rtl" id="مثال_در_صفحه">مثال در صفحه :</h3> +<pre class="brush: html"><h1>Heading elements</h1> +<h2>Summary</h2> +<p>Some text here...</p> + +<h2>Examples</h2> +<h3>Example 1</h3> +<p>Some text here...</p> + +<h3>Example 2</h3> +<p>Some text here...</p> + +<h2>see also</h2> +<p>Some text here...</p> +</pre> +<p>خروجی کد HTML بالا :</p> +<p><img alt="Image:HTML-headers1.png" src="/@api/deki/files/244/=HTML-headers1.png" style="float: left;"></p> +<p> </p> +<p> </p> +<p> </p> +<p> </p> +<p> </p> +<p> </p> +<p> </p> +<p> </p> +<h2 dir="rtl" id="توجه">توجه</h2> +<p dir="rtl">از سطح های پایین برای کوچک کردن اندازه فونت سرفصل <strong>استفاده</strong> <strong>نکنید</strong>: به جای آن از ویژگی اندازه فونت در <a href="/en-US/docs/CSS/font-size" title="/en-US/docs/CSS/font-size">CSS font-size</a> CSS استفاده کنید.</p> +<p dir="rtl"> از همه سطح ها استفاده کنید : همیشه از سطح ۱ <h1> شروع کنید، بعد سطح ۲ <h2> و به همین ترتیب تا آخر ... . همچنین سعی کنید در هر صفحه فقط یک بار از سطح ۱ <h1> برای سر فصل استفاده کنید.</p> +<p dir="rtl">برای تعریف نمای کلی (outline) اسناد در {{HTMLVersionInline(5)}}, از {{HTMLElement("section")}} استفاده کنید . سرفصل ها برای بخش ها و زیر بخش ها عنوان را مشخص می کنند. شما همچنین می توانید محتوای سرفصل ها را گروه بندی کنید با استفاده از عنصر {{HTMLElement("div")}}.</p> +<h2 dir="rtl" id="Specifications" name="Specifications">مشخصات</h2> +<table class="standard-table" dir="rtl"> + <thead> + <tr> + <th scope="col">مشخصات</th> + <th scope="col">وضعیت</th> + <th scope="col">توضیحات</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', 'sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements', '<h1>, <h2>, <h3>, <h4>, <h5>, and <h6>')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('HTML5 W3C', 'the-aside-element.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements', '<h1>, <h2>, <h3>, <h4>, <h5>, and <h6>')}}</td> + <td>{{Spec2('HTML5 W3C')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('HTML4.01', 'global.html#h-7.5.5', '<h1>, <h2>, <h3>, <h4>, <h5>, and <h6>')}}</td> + <td>{{Spec2('HTML4.01')}}</td> + <td> </td> + </tr> + </tbody> +</table> +<h2 dir="rtl" id="سازگاری_در_مرورگرها">سازگاری در مرورگرها</h2> +<p dir="rtl">{{CompatibilityTable}}</p> +<div dir="rtl" id="compat-desktop"> + <table class="compat-table"> + <tbody> + <tr> + <th>ویژگی</th> + <th>کروم</th> + <th>فایرفاکس (Gecko)</th> + <th>اینترنت اکسپلورر</th> + <th>اپرا</th> + <th>Safari</th> + </tr> + <tr> + <td>پشتیبانی اولیه</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("1.0")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> + </table> +</div> +<div dir="rtl" id="compat-mobile"> + <table class="compat-table"> + <tbody> + <tr> + <th>ویژگی</th> + <th>اندروید</th> + <th>فایرفاکس موبایل (Gecko)</th> + <th>اینترنت اکسپلورر موبایل</th> + <th>اپرا موبایل</th> + <th>Safari موبابل</th> + </tr> + <tr> + <td>پشتیبانی اولیه</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("1.0")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> + </table> +</div> +<h2 dir="rtl" id="همچنین_ببینید">همچنین ببینید</h2> +<ul dir="rtl"> + <li>{{HTMLElement("p")}}</li> + <li>{{HTMLElement("div")}}</li> + <li>{{HTMLElement("section")}}</li> +</ul> +<p dir="rtl">{{HTML:Element_Navigation}}</p> diff --git a/files/fa/web/html/element/index.html b/files/fa/web/html/element/index.html new file mode 100644 index 0000000000..e7bd8d2984 --- /dev/null +++ b/files/fa/web/html/element/index.html @@ -0,0 +1,203 @@ +--- +title: عنصرهای HTML +slug: Web/HTML/Element +translation_of: Web/HTML/Element +--- +<p dir="rtl">فهرست پیشرو مرجعی است برای تمام عنصرهای HTML، که دربرگیرندهی عنصرهای جدید در HTML5 نیز میباشد.</p> +<p dir="rtl"><strong>عنصرهای HTML</strong> اجزایی هستند که مشخص میکنند اسناد HTML چگونه باید ساخته شوند، و چه نوع محتوایی در کدام قسمت از سند HTML باید قرار بگیرند. نام آنها باید بین دو علامت ">" و "<" به صورت "<نام عنصر>" قرار میگیرد که به چنین ساختاری یک <em>برچسب</em> گفته میشود. اگر عنصر شامل محتوای دیگری باشد، با یک <em>برچسب پایانی</em> خاتمه مییابد، به صورتی که نام عنصر به همراه یک خط مورب آورده میشود: <code><نام عنصر/>. </code>برخی از عنصرها به برچسب پایانی نیازی ندارند مانند عنصر <code><img></code> که به عنصرهای <em>تهی</em> معروف هستند. اسناد HTML شامل فهرستی درختواره از عنصرهای مختلف هستند، که نام هر یک مشخص کنندهی عملکردش است. برای نمونه عنصر <code><title></code> نشاندهندهی عنوان یک سند است. در ادامه فهرستی الفبایی از عنصرهای HTML وجود دارد.</p> +<h3 dir="rtl" id="A">A</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("a") }} (پیوند)</li> + <li>{{ HTMLElement("abbr") }} (مخفف - کوتاهسازی)</li> + <li>{{ HTMLElement("acronym") }} که {{ obsoleteGeneric("inline","HTML5") }} - در عوض از {{ HTMLElement("abbr") }} استفاده شود</li> + <li>{{ HTMLElement("address") }} (نشانی یا اطلاعات تماس)</li> + <li>{{ HTMLElement("applet") }} که {{ deprecatedGeneric("inline","HTML4") }} و {{ obsoleteGeneric("inline","HTML5") }} - در عوض از {{ HTMLElement("object") }} استفاده شود.</li> + <li>{{ HTMLElement("area") }} (پیوند تصویر-نقشه)</li> + <li>{{ HTMLElement("article") }} (مقالهی مجزا) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("aside") }} (محتوای مرتبط با موضوع اصلی) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("audio") }} (فایل صوتی ضمیمهشده) {{ HTMLVersionInline(5) }}</li> +</ul> +<h3 dir="rtl" id="B">B</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("b") }} (قبلا با نام Bold شناخته میشد)</li> + <li>{{ HTMLElement("base") }} (نشانی پایه)</li> + <li>{{ HTMLElement("basefont") }} که {{ deprecatedGeneric("inline","HTML4") }} و {{ obsoleteGeneric("inline","HTML5") }}</li> + <li>{{ HTMLElement("bdi") }} (محتوای دوطرفه-دوجهت) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("bdo") }} ()</li> + <li>{{ HTMLElement("bgsound") }} (صدای پسزمینه) {{ Non-standard_inline() }}</li> + <li>{{ HTMLElement("big") }} که {{ obsolete_inline("html5") }}</li> + <li>{{ HTMLElement("blink") }} که {{ Non-standard_inline() }}</li> + <li>{{ HTMLElement("blockquote") }} (نقلقول صریح)</li> + <li>{{ HTMLElement("body") }} (بدنهی اصلی سند)</li> + <li>{{ HTMLElement("br") }} (رفتن به خط بعد)</li> + <li>{{ HTMLElement("button") }} (دکمه)</li> +</ul> +<h3 dir="rtl" id="C">C</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("canvas") }} (محیط رسم گرافیکهای پویا) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("caption") }} (عنوان جدول)</li> + <li>{{ HTMLElement("center") }} که {{ Deprecated_inline("html4") }} و {{ obsoleteGeneric("inline","HTML5") }}</li> + <li>{{ HTMLElement("cite") }} (عنوان شغل)</li> + <li>{{ HTMLElement("code") }} (قطعه کد)</li> + <li>{{ HTMLElement("col") }} (ستون جدول)</li> + <li>{{ HTMLElement("colgroup") }} (گروهبندی ستون جدول)</li> + <li>{{ HTMLElement("command") }} (بررسی وضعیت کاربر) {{ HTMLVersionInline(5) }}</li> +</ul> +<h3 dir="rtl" id="D">D</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("datalist") }} (فهرستی از گزینههای از پیش تعریف شده) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("dd") }} (توصیف عبارت)</li> + <li>{{ HTMLElement("del") }} (متن حذفشده)</li> + <li>{{ HTMLElement("details") }} (فراهم آوردن جزییات بیشتر برای کاربر در قالب یک ویجت) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("dfn") }} (تعریف)</li> + <li>{{ HTMLElement("dir") }} که {{ deprecatedGeneric("inline","HTML4") }} و {{ obsoleteGeneric("inline","HTML5") }}</li> + <li>{{ HTMLElement("dl") }} (فهرست تعریفی)</li> + <li>{{ HTMLElement("dt") }} (عبارت تعریفی)</li> +</ul> +<h3 dir="rtl" id="E">E</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("em") }} (تاکید)</li> + <li>{{ HTMLElement("embed") }} (جاسازی یا همان embed کردن) {{ HTMLVersionInline(5) }}</li> +</ul> +<h3 dir="rtl" id="F">F</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("fieldset") }} (مجموعهای کنترلهای یک فرم)</li> + <li>{{ HTMLElement("figcaption") }} (عنوان شکل) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("figure") }} (شکل) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("font") }} که {{ deprecatedGeneric("inline","HTML4") }} و {{ obsoleteGeneric("inline","HTML5") }}</li> + <li>{{ HTMLElement("footer") }} (قسمت انتهایی صفحه) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("form") }} (فرم HTML - جهت جمعآوری اطلاعات از کاربر)</li> + <li>{{ HTMLElement("frame") }} که {{ obsoleteGeneric("inline","HTML5") }}</li> + <li>{{ HTMLElement("frameset") }} که {{ obsoleteGeneric("inline","HTML5") }}</li> +</ul> +<h3 dir="rtl" id="G">G</h3> +<h3 dir="rtl" id="H">H</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("h1") }}، {{ HTMLElement("h2") }}، {{ HTMLElement("h3") }}، {{ HTMLElement("h4") }}، {{ HTMLElement("h5") }}، {{ HTMLElement("h6") }} (عنصرهای مورد نیاز برای عنوانگذاری)</li> + <li>{{ HTMLElement("head") }} (قسمت ابتدایی سند HTML که اطلاعات فرادادهای را شامل میشود)</li> + <li>{{ HTMLElement("header") }} (قسمت ابتدایی صفحه) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("hgroup") }} (گروهی از عناصر که در Heading به کار میروند) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("hr") }} (خط افقی برای جداسازی موضوع)</li> + <li>{{ HTMLElement("html") }} (ریشهی سند HTML، جایی که همه چیز شروع میشود)</li> +</ul> +<h3 dir="rtl" id="I">I</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("i") }} (متن کج)</li> + <li>{{ HTMLElement("iframe") }} (قاب یا frame داخلی)</li> + <li>{{ HTMLElement("img") }} (تصویر)</li> + <li>{{ HTMLElement("input") }} (از اجزای فرم - دریافت ورودی از کاربر)</li> + <li>{{ HTMLElement("ins") }} (متن درجشده)</li> + <li>{{ HTMLElement("isindex") }} که {{ deprecatedGeneric("inline","HTML4") }}</li> +</ul> +<h3 dir="rtl" id="J">J</h3> +<h3 dir="rtl" id="K">K</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("kbd") }} (ورودی صفحهکلید)</li> + <li>{{ HTMLElement("keygen") }} (تولیدکنندهی زوجکلید - متنی تصادفی)</li> +</ul> +<h3 dir="rtl" id="L">L</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("label") }} (برچسب برای کنترلهای فرم)</li> + <li>{{ HTMLElement("legend") }} (عبارتی که بالای مجموعهای از فیلدها قرار میگیرد)</li> + <li>{{ HTMLElement("li") }} (گزینه(ها)ی فهرست)</li> + <li>{{ HTMLElement("link") }} (فرادادهای برای ارتباطهای بینسندی)</li> + <li>{{ HTMLElement("listing") }} (فهرستسازی کد) {{ deprecatedGeneric("inline","HTML3.2") }}</li> +</ul> +<h3 dir="rtl" id="M">M</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("map") }} (نقشهی تصویر)</li> + <li>{{ HTMLElement("mark") }} (متن علامتگذاریشده) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("marquee") }} که {{ Non-standard_inline() }}</li> + <li>{{ HTMLElement("menu") }} (فهرستی از فرمانها) که در HTML4 کنارگذاشته شد اما در HTML5 دوباره استفاده میشود</li> + <li>{{ HTMLElement("meta") }} (فراداده - اطلاعاتی که در مرورگر قابل مشاهده نیستند اما معنای خاصی دارند)</li> + <li>{{ HTMLElement("meter") }} (مقیاس یا اندازهی عددی) {{ HTMLVersionInline(5) }}</li> +</ul> +<h3 dir="rtl" id="N">N</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("nav") }} (پیمایش) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("nobr") }} (عدم درج فاصله) {{ Non-standard_inline() }}</li> + <li>{{ HTMLElement("noframes") }} که {{ obsoleteGeneric("inline","HTML4") }}</li> + <li>{{ HTMLElement("noscript") }} (محتوای اسکریپت بازگشتی)</li> +</ul> +<h3 dir="rtl" id="O">O</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("object") }} (آبجکت یا شی جاسازیشده)</li> + <li>{{ HTMLElement("ol") }} (فهرست مرتب یا شمارهدار)</li> + <li>{{ HTMLElement("optgroup") }} (گروهبندی گزینهها)</li> + <li>{{ HTMLElement("option") }} (گزینهی انتخابی)</li> + <li>{{ HTMLElement("output") }} (نتیجهی محاسبهشده) {{ HTMLVersionInline(5) }}</li> +</ul> +<h3 dir="rtl" id="P">P</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("p") }} (پاراگراف)</li> + <li>{{ HTMLElement("param") }} (پارامتر یک شی)</li> + <li>{{ HTMLElement("plaintext") }} که {{ Deprecated_inline("html2") }}</li> + <li>{{ HTMLElement("pre") }} (متن قالببندیشده)</li> + <li>{{ HTMLElement("progress") }} (نشانگر پیشرفت) {{ HTMLVersionInline(5) }}</li> +</ul> +<h3 dir="rtl" id="Q">Q</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("q") }} (نقلقول)</li> +</ul> +<h3 dir="rtl" id="R">R</h3> +<p dir="rtl">(عنصرهای Ruby به برنامههای پشتیبانی نظیر <a href="https://addons.mozilla.org/en-US/firefox/addon/1935" title="https://addons.mozilla.org/en-US/firefox/addon/1935">XHTML Ruby Support</a> یا <a href="https://addons.mozilla.org/en-US/firefox/addon/6812" title="https://addons.mozilla.org/en-US/firefox/addon/6812">HTML Ruby</a> نیاز دارند که مورد آخر هنور در حال توسعه است)</p> +<ul dir="rtl"> + <li>{{ HTMLElement("rp") }} (پرانتزگذاری در Ruby) که {{ HTMLVersionInline(5) }} و {{ unimplemented_inline() }}</li> + <li>{{ HTMLElement("rt") }} (متن Ruby) که {{ HTMLVersionInline(5) }} و {{ unimplemented_inline() }}</li> + <li>{{ HTMLElement("ruby") }} که {{ HTMLVersionInline(5) }} و {{ unimplemented_inline(33339) }}</li> +</ul> +<h3 dir="rtl" id="S">S</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("s") }} (خطی که از میان عبارت میگذرد) {{ deprecatedGeneric("inline","HTML4") }}</li> + <li>{{ HTMLElement("samp") }} (متن نمونه و پیشنهادی)</li> + <li>{{ HTMLElement("script") }} (اسکریپتی که در سند به کار میرود در این قسمت باید نوشته شود)</li> + <li>{{ HTMLElement("section") }} (بخش جداساز سند) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("select") }} (فهرست انتخابی)</li> + <li>{{ HTMLElement("small") }} (متن با اندازهی کوچک)</li> + <li>{{ HTMLElement("source") }} (جایی که رسانه (فایل صوتی یا تصویری) در آن تعریف میشود) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("spacer") }} (فضای خالی) {{ Non-standard_inline() }}</li> + <li>{{ HTMLElement("span") }} (محدودهی متن)</li> + <li>{{ HTMLElement("strike") }} مانند {{ HTMLElement("s") }} که {{ deprecatedGeneric("inline","HTML4") }}</li> + <li>{{ HTMLElement("strong") }} (نشاندهندهی تاکید زیاد - تاکید قوی)</li> + <li>{{ HTMLElement("style") }} (شیوه نامهی آبشاری یا مخزنی برای تعریف کدهای CSS موردنظر)</li> + <li>{{ HTMLElement("sub") }} (زیرنویس برای متن یا عبارتی خاص)</li> + <li>{{ HTMLElement("summary") }} (خلاصهی جزییات) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("sup") }} (بالانویس برای متن یا عبارتی خاص)</li> +</ul> +<h3 dir="rtl" id="T">T</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("table") }} (جهت نمایش دادههای جدولی)</li> + <li>{{ HTMLElement("tbody") }} (بدنهی جدول)</li> + <li>{{ HTMLElement("td") }} (سلول یا خانهی جدول)</li> + <li>{{ HTMLElement("textarea") }} (ورودی متنی چندخطی)</li> + <li>{{ HTMLElement("tfoot") }} (قسمت انتهایی جدول)</li> + <li>{{ HTMLElement("th") }} (سلول یا خانهی عنوان جدول)</li> + <li>{{ HTMLElement("thead") }} (عنوان جدول)</li> + <li>{{ HTMLElement("time") }} (تاریخ یا زمان) {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("title") }} (عنوان سند)</li> + <li>{{ HTMLElement("tr") }} (سطر جدول)</li> + <li>{{ HTMLElement("track") }} که {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("tt") }} که {{ deprecatedGeneric("inline","HTML5") }}</li> +</ul> +<h3 dir="rtl" id="U">U</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("u") }} (استفاده به عنوان خطزیرین تا HTML4، تغییرشکلیافته در HTML5) که {{ deprecatedGeneric("inline","HTML4") }} و {{ HTMLVersionInline(5) }}</li> + <li>{{ HTMLElement("ul") }} (فهرست نامرتب یا نقطهدار)</li> +</ul> +<h3 dir="rtl" id="V">V</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("var") }} (متغیر)</li> + <li>{{ HTMLElement("video") }} (جهت نمایش ویدیو بدون نیاز به پلاگینهای شخصثالث مانند فلش) {{ HTMLVersionInline(5) }}</li> +</ul> +<h3 dir="rtl" id="W">W</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("wbr") }} (شکستن کلمه به اجزای کوچکتر) {{ HTMLVersionInline(5) }}</li> +</ul> +<h3 dir="rtl" id="X">X</h3> +<ul dir="rtl"> + <li>{{ HTMLElement("xmp") }} (جهت نمایش مثال) {{ deprecatedGeneric("inline","HTML3.2") }} و {{ obsoleteGeneric("inline","HTML4") }}</li> +</ul> +<h3 dir="rtl" id="Y">Y</h3> +<h3 dir="rtl" id="Z">Z</h3> +<p dir="rtl">{{ languages( { "de": "de/HTML/Element", "es": "es/HTML/Elemento", "fr": "fr/HTML/Element", "ja": "ja/HTML/Element", "pl": "pl/HTML/Element", "ko": "ko/HTML/Element", "nl": "nl/HTML/HTML_Tags", "ru": "Ru/HTML/Element", "zh-cn": "cn/HTML/Element", "zh-tw": "zh_tw/HTML/HTML_元素" } ) }}</p> +<p dir="rtl">{{ HTML:Element_Navigation() }}</p> diff --git a/files/fa/web/html/element/input/index.html b/files/fa/web/html/element/input/index.html new file mode 100644 index 0000000000..47a1d82d22 --- /dev/null +++ b/files/fa/web/html/element/input/index.html @@ -0,0 +1,1376 @@ +--- +title: <input> +slug: Web/HTML/Element/Input +translation_of: Web/HTML/Element/input +--- +<div class="summary"> +<p><font><font>HTML </font></font><strong><code><font><font><ورودی></font></font></code><font><font> عنصر</font></font></strong><font><font> استفاده می شود برای ایجاد کنترل های تعاملی برای اشکال مبتنی بر وب به منظور شرایط داده ها از کاربر. </font><font>معناشناسی </font></font><code><font><font><ورودی></font></font></code><font><font> بسته به ارزش آن </font></font><code><font><font>نوع</font></font></code><font><font> ویژگی.</font></font></p> +</div> + +<ul class="htmlelt"> + <li><dfn><a href="/en-US/docs/HTML/Content_categories"><font><font>دسته بندی های مطالب</font></font></a></dfn> <a href="/en-US/docs/HTML/Content_categories#Flow_content"><font><font> جریان محتوا</font></font></a><font><font> ، ذکر شده است، submittable، resettable، عنصر فرم ارتباط، </font></font><a href="/en-US/docs/HTML/Content_categories#Phrasing_content"><font><font>محتوا جملهبندی</font></font></a><font><font> . </font></font><br> + <font><font>اگر {{htmlattrxref ("</font></font>input<font><font>", "</font></font>type<font><font>")}} است نه </font></font><code><font><font>پنهان</font></font></code><font><font> ارزش، عنصر labellable، محتوای قابل لمس.</font></font></li> + <li><dfn><font><font>مجاز محتوای</font></font></dfn><font><font> هیچ، آن است {{</font></font>Glossary<font><font> ("عنصر خالی", "</font></font>empty element<font><font>")}}.</font></font></li> + <li><dfn><font><font>حذف برچسب</font></font></dfn><font><font> باید یک برچسب شروع کرده اند و باید یک تگ پایانی ندارد.</font></font></li> + <li><dfn><font><font>مجاز عناصر پدر و مادر</font></font></dfn><font><font> هر عنصر است که می پذیرد </font></font><a href="/en-US/docs/HTML/Content_categories#Phrasing_content"><font><font>محتوای جملهبندی</font></font></a><font><font> .</font></font></li> + <li><dfn><font><font>DOM رابط</font></font></dfn><font><font> {{domxref ("HTMLInputElement")}}</font></font></li> +</ul> + +<h2 id="خواص"><font><font>خواص</font></font></h2> + +<p><font><font>این عنصر شامل </font></font><a href="/en-US/docs/HTML/Global_attributes"><font><font>ویژگی های کلی</font></font></a><font><font> .</font></font></p> + +<dl> + <dt><font><font>{{htmlattrdef ("</font></font>type<font><font>")}}</font></font></dt> + <dd><font><font>نوع کنترل برای نمایش. </font><font>نوع پیش فرض متن است، اگر این ویژگی مشخص نشده است. </font><font>مقادیر ممکن عبارتند از:</font></font> + <ul> + <li><code><font><font>دکمه</font></font></code><font><font> : یک دکمه را فشار با هیچ رفتار پیش فرض.</font></font></li> + <li><code><font><font>چک باکس</font></font></code><font><font> : جعبه چک. </font><font>شما باید با استفاده از </font></font><strong><font><font>ارزش</font></font></strong><font><font> ویژگی برای تعریف ارزش ارائه شده توسط این آیتم استفاده کنید. </font><font>استفاده از </font></font><strong><font><font>چک</font></font></strong><font><font> ویژگی برای نشان که آیا این آیتم انتخاب شده است. </font><font>شما همچنین می توانید استفاده از </font></font><strong><font><font>نامشخص</font></font></strong><font><font> ویژگی به نشان می دهد که چک باکس است در حالت نامشخص (در اکثر سیستم عامل، این تساوی یک خط افقی در سراسر چک باکس).</font></font></li> + <li><code><font><font>رنگ</font></font></code><font><font> : {{HTMLVersionInline ("5")}} کنترل برای تعیین رنگ. </font><font>UI جمع کننده رنگ ندارد ویژگی های مورد نیاز دیگر از پذیرش رنگ ساده به عنوان متن ( </font></font><a href="http://www.w3.org/TR/html5/forms.html#color-state-(type=color)"><font><font>اطلاعات بیشتر</font></font></a><font><font> ).</font></font></li> + <li><code><font><font>تاریخ</font></font></code><font><font> : {{HTMLVersionInline ("5")}} کنترل برای ورود به یک تاریخ (سال، ماه، روز و، با هیچ زمان).</font></font></li> + <li><code><font><font>تاریخ ساعت</font></font></code><font><font> : {{HTMLVersionInline ("5")}} کنترل برای ورود به تاریخ و زمان (ساعت، دقیقه، دوم، و کسری از ثانیه) بر اساس منطقه محلی UTC تنظیم شده است.</font></font></li> + <li><code><font><font>تاریخ ساعت محلی</font></font></code><font><font> : {{HTMLVersionInline ("5")}} کنترل برای ورود به تاریخ و زمان، با هیچ منطقه زمان.</font></font></li> + <li><code><font><font>ایمیل</font></font></code><font><font> : {{HTMLVersionInline ("5")}} درست برای ویرایش یک آدرس ایمیل. </font><font>مقدار ورودی دارای اعتبار است که شامل هر دو رشته خالی یا یک معتبر آدرس ایمیل تنها قبل از ارسال. </font><font>{{cssxref (": معتبر")}} و {{cssxref (": نامعتبر")}} CSS شبه کلاس ها به عنوان مناسب استفاده شود.</font></font></li> + <li><code><font><font>فایل</font></font></code><font><font> : کنترل که اجازه می دهد کاربر را انتخاب کنید یک فایل. </font><font>با استفاده از </font></font><strong><font><font>شرایط</font></font></strong><font><font> ویژگی برای تعریف انواع فایل هایی که کنترل می توانید انتخاب کنید.</font></font></li> + <li><code><font><font>پنهان</font></font></code><font><font> : کنترل است که نشان داده نمی شود، اما که مقدار آن به سرور را مشاهده کنید.</font></font></li> + <li><code><font><font>تصویر</font></font></code><font><font> : گرافیکی دکمه ارسال. </font><font>شما باید با استفاده </font></font><strong><font><font>SRC</font></font></strong><font><font> ویژگی برای تعریف منبع تصویر و </font></font><strong><font><font>ALT</font></font></strong><font><font> ویژگی برای تعریف متن جایگزین. </font><font>شما می توانید با استفاده از </font></font><strong><font><font>ارتفاع</font></font></strong><font><font> و </font></font><strong><font><font>عرض</font></font></strong><font><font> ویژگی برای تعریف اندازه تصویر در پیکسل.</font></font></li> + <li><code><font><font>ماه</font></font></code><font><font> : {{HTMLVersionInline ("5")}} کنترل برای ورود به یک ماه و سال، با هیچ منطقه زمان.</font></font></li> + <li><code><font><font>تعداد</font></font></code><font><font> : {{HTMLVersionInline ("5")}} کنترل برای وارد کردن شماره ممیز شناور.</font></font></li> + <li><code><font><font>رمز عبور</font></font></code><font><font> : درست متن تک خط که ارزش پنهان است. </font><font>استفاده از </font></font><strong><font><font>MAXLENGTH</font></font></strong><font><font> ویژگی برای تعیین حداکثر طول ارزش است که می تواند وارد شود.</font></font></li> + <li><code><font><font>رادیو</font></font></code><font><font> : یک دکمه رادیویی. </font><font>شما باید با استفاده از </font></font><strong><font><font>ارزش</font></font></strong><font><font> ویژگی برای تعریف ارزش ارائه شده توسط این آیتم استفاده کنید. </font><font>استفاده از </font></font><strong><font><font>چک</font></font></strong><font><font> ویژگی برای نشان که آیا این آیتم به صورت پیش فرض انتخاب شده است. </font><font>دکمه های رادیویی که همان مقدار برای </font></font><strong><font><font>نام</font></font></strong><font><font> ویژگی در همان "گروه دکمه رادیویی" می باشد. </font><font>تنها با یک دکمه رادیویی در یک گروه را می توان در یک زمان انتخاب شده است.</font></font></li> + <li><code><font><font>محدوده</font></font></code><font><font> : {{HTMLVersionInline ("5")}} کنترل برای وارد کردن شماره که مقدار دقیق آن مهم نیست. </font><font>این کنترل نوع استفاده از مقادیر پیش فرض زیر اگر صفات مربوطه مشخص نشده است:</font></font> + <ul> + <li><code><font><font>دقیقه</font></font></code><font><font> : 0</font></font></li> + <li><code><font><font>حداکثر</font></font></code><font><font> : 100</font></font></li> + <li><code><font><font>ارزش</font></font></code><font><font> : </font></font><code><font><font>دقیقه</font></font></code><font><font> + ( </font></font><code><font><font>حداکثر</font></font></code><font><font> - </font></font><code><font><font>دقیقه</font></font></code><font><font> ) / 2، یا </font></font><code><font><font>دقیقه</font></font></code><font><font> اگر </font></font><code><font><font>حداکثر</font></font></code><font><font> کمتر از است </font></font><code><font><font>دقیقه</font></font></code></li> + <li><code><font><font>گام</font></font></code><font><font> : 1</font></font></li> + </ul> + </li> + <li><code><font><font>تنظیم مجدد</font></font></code><font><font> : یک دکمه که بازنشانی محتویات فرم به مقادیر پیش فرض.</font></font></li> + <li><code><font><font>جستجو</font></font></code><font><font> : {{HTMLVersionInline ("5")}} فیلد متنی تک خط برای ورود به رشته جستجو. </font><font>خط میشکند صورت خودکار از ارزش ورودی حذف شده است.</font></font></li> + <li><code><font><font>ارسال</font></font></code><font><font> : یک دکمه که تسلیم فرم.</font></font></li> + <li><code><font><font>تلفن</font></font></code><font><font> : {{HTMLVersionInline ("5")}} کنترل برای وارد کردن شماره تلفن. </font><font>خط میشکند صورت خودکار از ارزش ورودی برداشته شود، اما هیچ نحو دیگر اجرا شده است. </font><font>شما می توانید ویژگی های از قبیل استفاده از </font></font><strong><font><font>الگوی</font></font></strong><font><font> و </font></font><strong><font><font>MAXLENGTH</font></font></strong><font><font> برای محدود کردن مقادیر وارد شده در کنترل. </font><font>{{cssxref (": معتبر")}} و {{cssxref (": نامعتبر")}} CSS شبه کلاس ها به عنوان مناسب استفاده شود.</font></font></li> + <li><code><font><font>متن</font></font></code><font><font> : درست متن تک خط. </font><font>خط میشکند صورت خودکار از ارزش ورودی حذف شده است.</font></font></li> + <li><code><font><font>زمان</font></font></code><font><font> : {{HTMLVersionInline ("5")}} کنترل برای ورود به یک مقدار زمان با هیچ منطقه زمان.</font></font></li> + <li><code><font><font>آدرس</font></font></code><font><font> : {{HTMLVersionInline ("5")}} زمینه برای ویرایش یک URL. </font><font>مقدار ورودی دارای اعتبار است که شامل هر دو رشته خالی یا یک URL مطلق معتبر قبل از ارسال. </font><font>خط میشکند و منجر و یا فرار فضای سفید به طور خودکار از ارزش ورودی حذف شده است. </font><font>شما می توانید ویژگی های از قبیل استفاده از </font></font><strong><font><font>الگوی</font></font></strong><font><font> و </font></font><strong><font><font>MAXLENGTH</font></font></strong><font><font> برای محدود کردن مقادیر وارد شده در کنترل. </font><font>{{cssxref (": معتبر")}} و {{cssxref (": نامعتبر")}} CSS شبه کلاس ها به عنوان مناسب استفاده شود.</font></font></li> + <li><code><font><font>هفته</font></font></code><font><font> : {{HTMLVersionInline ("5")}} کنترل برای ورود به عضویت متشکل از تعداد هفته سال و تعداد هفته با هیچ منطقه زمان.</font></font></li> + </ul> + </dd> + <dt><font><font>{{htmlattrdef ("</font></font>accept<font><font>")}}</font></font></dt> + <dd><font><font>اگر مقدار از </font></font><strong><font><font>نوع</font></font></strong><font><font> ویژگی است </font></font><code><font><font>فایل</font></font></code><font><font> ، این ویژگی را نشان می دهد نوع فایل که سرور می پذیرد. </font><font>در غیر این صورت آن را نادیده گرفته است. </font><font>مقدار باید یک لیست با کاما از هم جدا از منحصر به فرد specifiers نوع محتوا:</font></font> + <ul> + <li><font><font>پسوند فایل با شروع با شخصیت STOP (U + 002E). </font><font>(به عنوان مثال: ".JPG، فعلی، doc است")</font></font></li> + <li><font><font>نوع MIME پرونده معتبر بدون پسوند</font></font></li> + <li><code><font><font>صوتی / *</font></font></code><font><font> نمایندگی فایل های صوتی {{HTMLVersionInline ("5")}}</font></font></li> + <li><code><font><font>ویدئو / *</font></font></code><font><font> نمایندگی فایل های ویدئویی {{HTMLVersionInline ("5")}}</font></font></li> + <li><code><font><font>تصویر / *</font></font></code><font><font> فایل های نمایندگی تصویر {{HTMLVersionInline ("5")}}</font></font></li> + </ul> + </dd> + <dt><font><font>{{htmlattrdef ("accesskey")}} {{HTMLVersionInline (4)}} تنها، {{obsoleteGeneric ("درون خطی"، "HTML5")}}</font></font></dt> + <dd><font><font>تک شخصیت است که کاربر می تواند فشار دهید برای تغییر تمرکز ورودی به کنترل. </font><font>این ویژگی جهانی در HTML5 است.</font></font></dd> + <dt><font><font>{{htmlattrdef ("mozactionhint")}} {{غیر standard_inline}}</font></font></dt> + <dd><font><font>مشخص "اشاره عمل" مورد استفاده برای تعیین چگونگی برچسب کلید را وارد کنید در دستگاه های تلفن همراه با صفحه کلید مجازی. </font><font>ارزش پشتیبانی می شوند </font></font><code><font><font>به</font></font></code><font><font> ، </font></font><code><font><font>انجام</font></font></code><font><font> ، </font></font><code><font><font>بعدی</font></font></code><font><font> ، </font></font><code><font><font>جستجو</font></font></code><font><font> ، و </font></font><code><font><font>ارسال</font></font></code><font><font> . </font><font>این به طور خودکار دریافت به رشته مناسب نقشه برداری (و حروف حساس).</font></font></dd> + <dt><font><font>{{htmlattrdef ("autocapitalize")}} {{غیر standard_inline}}</font></font></dt> + <dd><font><font>این یک ویژگی غیر استاندارد استفاده شده توسط سیستم عامل iOS صفری موبایل که کنترل اینکه آیا و چگونه ارزش متن باید به طور خودکار با حروف بزرگ آن را به عنوان وارد / ویرایش توسط کاربر است. </font><font>مقادیر غیر بد دانسته دسترس در iOS 5 و بعد می باشد. </font><font>مقادیر ممکن عبارتند از:</font></font> + <ul> + <li><code><font><font>هیچ</font></font></code><font><font> : کاملا غیر فعال سرمایه اتوماتیک</font></font></li> + <li><code><font><font>جملات</font></font></code><font><font> : به صورت خودکار اولین حرف از جملات.</font></font></li> + <li><code><font><font>کلمات</font></font></code><font><font> : به صورت خودکار اولین حرف از کلمه است.</font></font></li> + <li><code><font><font>شخصیت</font></font></code><font><font> : به صورت خودکار تمام شخصیت های سرمایه گذاری.</font></font></li> + <li><code><font><font>در</font></font></code><font><font> : {{deprecated_inline ()}} توصیه از سیستم عامل iOS 5.</font></font></li> + <li><code><font><font>خاموش</font></font></code><font><font> : {{deprecated_inline ()}} توصیه از سیستم عامل iOS 5.</font></font></li> + </ul> + </dd> + <dt><font><font>{{htmlattrdef ("تکمیل خودکار")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>این ویژگی نشان می دهد که آیا ارزش کنترل می تواند به صورت خودکار توسط مرورگر به پایان رسید. </font><font>این صفت نادیده گرفته اگر مقدار از </font></font><strong><font><font>نوع</font></font></strong><font><font> صفت </font></font><code><font><font>پنهان، رمز عبور، </font></font></code> <code><font><font>چک باکس</font></font></code><font><font> ، </font></font><code><font><font>رادیو</font></font></code><font><font> ، </font></font><code><font><font>فایل</font></font></code><font><font> ، یا یک نوع دکمه ( </font></font><code><font><font>دکمه</font></font></code><font><font> ، </font></font><code><font><font>ارائه</font></font></code><font><font> ، </font></font><code><font><font>تنظیم مجدد</font></font></code><font><font> ، </font></font><code><font><font>تصویر</font></font></code><font><font> ). </font><font>مقادیر ممکن عبارتند از:</font></font> + <ul> + <li><code><font><font>خاموش</font></font></code><font><font> : کاربر باید به صراحت ارزش به این زمینه برای هر استفاده را وارد کنید، و یا سند روش تکمیل خودکار خود را فراهم می کند. </font><font>مرورگر به صورت خودکار تکمیل ورود نیست.</font></font></li> + <li><code><font><font>در</font></font></code><font><font> : مرورگر به طور خودکار می تواند ارزش بر اساس ارزش است که کاربر در طول استفاده قبلی وارد تکمیل.</font></font></li> + </ul> + + <p><font><font>اگر </font></font><strong><font><font>تکمیل خودکار</font></font></strong><font><font> صفت در یک عنصر ورودی مشخص نشده است، پس از آن مرورگر با استفاده از </font></font><strong><font><font>تکمیل خودکار</font></font></strong><font><font> مقدار ویژگی از </font></font><code><font><font><ورودی></font></font></code><font><font> صاحب فرم عنصر. </font><font>صاحب فرم یا است </font></font><code><font><font>فرم</font></font></code><font><font> عنصر که این </font></font><code><font><font><ورودی></font></font></code><font><font> عنصر از نوادگان یا عنصر فرم که است </font></font><strong><font><font>ID</font></font></strong><font><font> توسط مشخص </font></font><strong><font><font>فرم</font></font></strong><font><font> صفت عناصر ورودی. </font><font>برای کسب اطلاعات بیشتر، نگاه کنید به {{htmlattrxref ("تکمیل خودکار"، "فرم")}} ویژگی در {{روی HTMLElement ("فرم")}}.</font></font></p> + + <p><strong><font><font>تکمیل خودکار</font></font></strong><font><font> ویژگی نیز تعیین می فایرفاکس خواهد شد، بر خلاف سایر مرورگرها، </font></font><a href="http://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing"><font><font>اصرار دولت غیر فعال پویا و (در صورت وجود) checkedness پویا</font></font></a><font><font> از {{روی HTMLElement ("ورودی")}} در سراسر بارهای صفحه. </font><font>ویژگی تداوم به طور پیش فرض فعال است. </font><font>تنظیم مقدار از </font></font><strong><font><font>تکمیل خودکار</font></font></strong><font><font> ویژگی به </font></font><code><font><font>فعال</font></font></code><font><font> غیر فعال کردن این ویژگی. </font><font>این کار حتی زمانی که </font></font><strong><font><font>تکمیل خودکار</font></font></strong><font><font> ویژگی به طور معمول به {{روی HTMLElement ("ورودی")}} به موجب آن صدق نمی کند </font></font><strong><font><font>نوع</font></font></strong><font><font> . </font><font>مشاهده {{اشکال (654072)}}.</font></font></p> + </dd> + <dt><font><font>{{htmlattrdef ("رقم")}} {{غیر standard_inline}}</font></font></dt> + <dd><font><font>این یک ویژگی غیر استاندارد پشتیبانی شده توسط صفری است که مورد استفاده برای کنترل اینکه آیا autocorrection باید فعال زمانی که کاربر وارد شده است / ویرایش ارزش متن {{روی HTMLElement ("ورودی")}}. </font><font>مقادیر ویژگی ممکن است:</font></font> + <ul> + <li><code><font><font>در</font></font></code><font><font> : فعال کردن autocorrection</font></font></li> + <li><code><font><font>خاموش</font></font></code><font><font> : autocorrection غیر فعال کردن</font></font></li> + </ul> + </dd> + <dt><font><font>{{htmlattrdef ("فوکوس خودکار")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>این ویژگی بولی شما اجازه می دهد مشخص است که یک کنترل فرم باید تمرکز ورودی هنگامی که بارهای صفحه، مگر اینکه کاربر را لغو، به عنوان مثال با تایپ کردن در یک کنترل متفاوت است. </font><font>تنها یک عنصر فرم در یک سند می تواند داشته </font></font><strong><font><font>فوکوس خودکار</font></font></strong><font><font> ویژگی، که یک بولی. </font><font>این را نمی توان اعمال اگر </font></font><strong><font><font>نوع</font></font></strong><font><font> صفت به راه </font></font><code><font><font>پنهان</font></font></code><font><font> (که شده است، شما نمی توانید به طور خودکار تمرکز به کنترل پنهان است).</font></font></dd> + <dt><font><font>{{htmlattrdef ("ذخیره خودکار")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>این ویژگی باید به عنوان یک ارزش منحصر به فرد تعریف شده است. </font><font>اگر ارزش نوع ویژگی است </font></font><code><font><font>جستجو</font></font></code><font><font> ، ارزش عبارت جستجوی قبلی در کرکره در سراسر بار صفحه ادامه خواهد داشت.</font></font></dd> + <dt><font><font>{{htmlattrdef ("چک")}}</font></font></dt> + <dd> + <p><font><font>هنگامی که ارزش </font></font><strong><font><font>نوع</font></font></strong><font><font> ویژگی است </font></font><code><font><font>رادیو</font></font></code><font><font> یا </font></font><code><font><font>چک باکس</font></font></code><font><font> ، حضور این ویژگی بولی نشان می دهد که کنترل به طور پیش فرض انتخاب شده. </font><font>در غیر این صورت آن را نادیده گرفته است.</font></font></p> + + <p><font><font>فایرفاکس خواهد شد، بر خلاف سایر مرورگرها، به طور پیش فرض، </font></font><a href="http://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing"><font><font>اصرار پویا بررسی دولت</font></font></a><font><font> از {{روی HTMLElement ("ورودی")}} در سراسر بارهای صفحه. </font><font>با استفاده از {{htmlattrxref ("تکمیل خودکار"، "ورودی")}} ویژگی برای کنترل این ویژگی.</font></font></p> + </dd> + <dt><font><font>{{htmlattrdef ("غیر فعال")}}</font></font></dt> + <dd> + <p><font><font>این ویژگی بولی نشان می دهد که کنترل فرم در دسترس است برای تعامل نیست. </font><font>به طور خاص، </font></font><code><font><font>کلیک</font></font></code><font><font> رویداد </font></font><a class="external" href="https://html.spec.whatwg.org/multipage/forms.html#enabling-and-disabling-form-controls:-the-disabled-attribute"><font><font>خواهد شد اعزام نمی</font></font></a><font><font> در کنترل غیر فعال است. </font><font>همچنین، ارزش یک کنترل غیر فعال است با فرم ارسال نشده است.</font></font></p> + + <p><font><font>فایرفاکس خواهد شد، بر خلاف سایر مرورگرها، به طور پیش فرض، </font></font><a href="http://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing"><font><font>اصرار دولت معلول پویا</font></font></a><font><font> از {{روی HTMLElement ("ورودی")}} در سراسر بارهای صفحه. </font><font>با استفاده از {{htmlattrxref ("تکمیل خودکار"، "ورودی")}} ویژگی برای کنترل این ویژگی.</font></font></p> + </dd> + <dt><font><font>{{htmlattrdef ("فرم")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>عنصر فرم که عنصر ورودی با (آن همراه </font></font><em><font><font>صاحب فرم</font></font></em><font><font> ). </font><font>ارزش ویژگی باید داشته باشد </font></font><strong><font><font>ID</font></font></strong><font><font> از {{روی HTMLElement ("فرم")}} عنصر در همان سند. </font><font>اگر این ویژگی مشخص نشده است، این </font></font><code><font><font><ورودی></font></font></code><font><font> عنصر باید از نسل {{روی HTMLElement ("فرم")}} عنصر باشد. </font><font>این ویژگی شما را قادر به قرار دادن </font></font><code><font><font><ورودی></font></font></code><font><font> عناصر در هر نقطه در یک سند، نه فقط به عنوان فرزندان عناصر فرم خود را. </font><font>ورودی تنها می توان با یک فرم در ارتباط است.</font></font></dd> + <dt><font><font>{{htmlattrdef ("formaction")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>URI از برنامه ای است که پردازش اطلاعات ارائه شده توسط عنصر ورودی، اگر آن یک دکمه یا عکس ارسال کنید. </font><font>اگر مشخص شده، آن را لغو می {{htmlattrxref ("عمل"، "فرم")}} ویژگی از صاحب فرم عنصر است.</font></font></dd> + <dt><font><font>{{htmlattrdef ("formenctype")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>اگر عنصر ورودی دکمه ارسال و یا تصویر است، این ویژگی نوع محتوا است که برای ارائه به صورت به سرور مشخص می کند. </font><font>مقادیر ممکن عبارتند از:</font></font> + <ul> + <li><code><font><font>نرم افزار / X-WWW-فرم-urlencoded</font></font></code><font><font> : مقدار پیش فرض اگر ویژگی مشخص نشده است.</font></font></li> + <li><code><font><font>چند / فرم داده</font></font></code><font><font> : با استفاده از این ارزش اگر شما با استفاده از {{روی HTMLElement ("ورودی")}} عنصر با {{htmlattrxref ("نوع"، "ورودی")}} مجموعه نسبت به </font></font><code><font><font>فایل</font></font></code><font><font> .</font></font></li> + <li><code><font><font>متن / ساده</font></font></code></li> + </ul> + + <p><font><font>اگر این ویژگی مشخص است، آن را لغو می {{htmlattrxref ("Enctype فرم"، "فرم")}} ویژگی از صاحب فرم عنصر است.</font></font></p> + </dd> + <dt><font><font>{{htmlattrdef ("formmethod")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>اگر عنصر ورودی دکمه ارسال و یا تصویر است، این ویژگی به روش HTTP که مرورگر استفاده می کند برای ارسال فرم مشخص می کند. </font><font>مقادیر ممکن عبارتند از:</font></font> + <ul> + <li><code><font><font>ارسال</font></font></code><font><font> : داده ها از فرم در بدن از فرم شامل است و به سرور ارسال می شود.</font></font></li> + <li><code><font><font>دریافت</font></font></code><font><font> ها: داده ها از فرم به اضافه </font></font><strong><font><font>فرم</font></font></strong><font><font> نسبت URI، با "؟" </font><font>به عنوان یک جدا، و URI نتیجه به سرور ارسال می شود. </font><font>با استفاده از این روش هنگامی که فرم هیچ عوارض جانبی و تنها حاوی کاراکترهای اسکی.</font></font></li> + </ul> + + <p><font><font>اگر مشخص شده، این ویژگی را لغو می {{htmlattrxref ("روش"، "فرم")}} ویژگی از صاحب فرم عنصر است.</font></font></p> + </dd> + <dt><font><font>{{htmlattrdef ("formnovalidate")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>اگر عنصر ورودی دکمه ارسال و یا تصویر است، این ویژگی بولی مشخص می کند که به شکل نیست به اعتبار زمانی که آن را مشاهده کنید. </font><font>اگر این ویژگی مشخص است، آن را لغو می {{htmlattrxref ("novalidate"، "فرم")}} ویژگی از صاحب فرم عنصر است.</font></font></dd> + <dt><font><font>{{htmlattrdef ("formtarget")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>اگر عنصر ورودی دکمه ارسال و یا تصویر است، این ویژگی یک نام یا کلمه کلیدی نشان می دهد که در آن به نمایش پاسخ این است که پس از ارسال فرم دریافت است. </font><font>این نام، و یا کلمه کلیدی برای، است </font></font><em><font><font>زمینه مرور</font></font></em><font><font> (به عنوان مثال، تب، پنجره، و یا فریم های درون خطی). </font><font>اگر این ویژگی مشخص است، آن را لغو می {{htmlattrxref ("هدف"، "فرم")}} ویژگی از صاحب فرم عناصر است. </font><font>کلمات کلیدی زیر دارای معانی خاص:</font></font> + <ul> + <li><font><font>_ </font></font><code><font><font>خود</font></font></code><font><font> : بار پاسخ به زمینه مرور همان یک جریان. </font><font>این مقدار به طور پیش فرض است اگر ویژگی مشخص نشده است.</font></font></li> + <li><code><font><font>_blank</font></font></code><font><font> : بار پاسخ به یک محیط جدید مرور که نامش ذکر نشده.</font></font></li> + <li><code><font><font>_parent</font></font></code><font><font> : بار پاسخ به زمینه مرور پدر و مادر از یک جریان. </font><font>اگر هیچ پدر و مادر وجود دارد، این گزینه رفتار به همان شیوه به عنوان </font></font><code><font><font>_self</font></font></code><font><font> .</font></font></li> + <li><code><font><font>_top</font></font></code><font><font> : بار پاسخ به زمینه مرور در سطح بالا (که شده است، زمینه مرور است که از اجداد یک جریان، و هیچ پدر و مادر). </font><font>اگر هیچ پدر و مادر وجود دارد، این گزینه رفتار به همان شیوه به عنوان </font></font><code><font><font>_self</font></font></code><font><font> .</font></font></li> + </ul> + </dd> + <dt><font><font>{{htmlattrdef ("ارتفاع")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>اگر مقدار از </font></font><strong><font><font>نوع</font></font></strong><font><font> ویژگی است </font></font><code><font><font>تصویر</font></font></code><font><font> ، این ویژگی ارتفاع تصویر نمایش داده شده برای دکمه تعریف می کند.</font></font></dd> + <dt><font><font>{{htmlattrdef ("تدریجی")}} {{غیر standard_inline}}</font></font></dt> + <dd><font><font>این یک ویژگی غیر استاندارد پشتیبانی شده توسط صفری که فقط شامل زمانی که است </font></font><strong><font><font>نوع</font></font></strong><font><font> است </font></font><code><font><font>جستجو</font></font></code><font><font> . </font><font>اگر ویژگی حال حاضر، صرف نظر از آنچه ارزش خود را است، {{روی HTMLElement ("ورودی")}} آتش سوزی </font></font><a href="/en-US/docs/Web/Events/search"><code><font><font>جستجو</font></font></code></a><font><font> وقایع را به عنوان کاربر ویرایش ارزش متن. </font><font>این رویداد تنها پس از ایست-اجرای تعریف کرده است از ضربه زدن به کلید جدید ترین سپری اخراج. </font><font>کلید جدید تنظیم مجدد ایست. </font><font>به عبارت دیگر، شلیک رویداد debounced است. </font><font>اگر ویژگی وجود ندارد، </font></font><a href="/en-US/docs/Web/Events/search"><code><font><font>جستجو</font></font></code></a><font><font> رویداد تنها اخراج وقتی که کاربر به صراحت با دادن یک (مثلا با کلید Enter در حالی که در زمینه فشار دادن).</font></font></dd> + <dt><font><font>{{htmlattrdef ("inputmode")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>اشاره به مرورگر است که برای آن صفحه کلید برای نمایش. </font><font>این ویژگی صدق زمانی که ارزش </font></font><strong><font><font>نوع</font></font></strong><font><font> متن، رمز عبور، ایمیل، و یا URL است. </font><font>مقادیر ممکن عبارتند از:</font></font> + <ul> + <li><code><font><font>کلمه به کلمه</font></font></code><font><font> : عدد و الفبایی، محتوای غیر نثر مانند نام کاربری و کلمه عبور.</font></font></li> + <li><code><font><font>لاتین</font></font></code><font><font> : ورودی لاتین اسکریپت در زبان مورد نظر کاربر با ایدز تایپ مانند پیش بینی متن را فعال کنید. </font><font>برای ارتباط انسان-به-کامپیوتر مانند جعبه جستجو.</font></font></li> + <li><code><font><font>لاتین نام</font></font></code><font><font> : عنوان </font></font><em><font><font>لاتین</font></font></em><font><font> ، اما برای نام انسان است.</font></font></li> + <li><code><font><font>لاتین نثر</font></font></code><font><font> : به عنوان </font></font><em><font><font>لاتین</font></font></em><font><font> ، اما با ایدز تایپ تهاجمی تر. </font><font>برای انسان به انسان ارتباطی مانند پیام های فوری برای ایمیل.</font></font></li> + <li><code><font><font>تمام عرض لاتین</font></font></code><font><font> : عنوان </font></font><em><font><font>لاتین نثر</font></font></em><font><font> ، اما برای زبان دوم کاربر.</font></font></li> + <li><code><font><font>کانا</font></font></code><font><font> : کانا یا ورودی romaji، به طور معمول ورودی هیراگانا، با استفاده از شخصیت های تمام عرض، با پشتیبانی از تبدیل به کانجی. </font><font>در نظر گرفته شده برای ورودی متن ژاپنی.</font></font></li> + <li><code><font><font>کاتاکانا</font></font></code><font><font> : ورودی کاتاکانا، با استفاده از شخصیت های تمام عرض، با پشتیبانی از تبدیل به کانجی. </font><font>در نظر گرفته شده برای ورودی متن ژاپنی.</font></font></li> + <li><code><font><font>عددی</font></font></code><font><font> : ورودی عددی، از جمله کلید برای رقم 0 تا 9، ترجیح شخصیت هزاران جدا کاربر، و شخصیت برای نشان اعداد منفی. </font><font>در نظر گرفته شده برای کدهای عددی، به عنوان مثال شماره کارت اعتباری. </font><font>برای اعداد واقعی، ترجیح می دهند با استفاده از <نوع ورودی = "تعداد"></font></font></li> + <li><code><font><font>تلفن</font></font></code><font><font> : ورودی تلفن، از جمله ستاره و کلید پوند. </font><font>استفاده از <ورودی نوع = "تلفن"> در صورت امکان به جای.</font></font></li> + <li><code><font><font>ایمیل</font></font></code><font><font> : ورودی ایمیل. </font><font>استفاده از <ورودی نوع = "ایمیل"> در صورت امکان به جای.</font></font></li> + <li><code><font><font>آدرس</font></font></code><font><font> : URL ورودی. </font><font>استفاده از <ورودی نوع = "URL"> در صورت امکان به جای.</font></font></li> + </ul> + </dd> + <dt><font><font>{{htmlattrdef ("فهرست")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>شناسایی یک لیست از گزینه های از پیش تعریف شده به پیشنهاد به کاربر. </font><font>مقدار باید باشد </font></font><strong><font><font>ID</font></font></strong><font><font> از {{روی HTMLElement ("کنترل DataList")}} عنصر در همان سند. </font><font>مرورگر تنها گزینه هایی که مقادیر معتبر برای این عنصر ورودی می باشد. </font><font>این صفت زمانی که نادیده گرفته </font></font><strong><font><font>نوع</font></font></strong><font><font> مقدار ویژگی است </font></font><code><font><font>پنهان</font></font></code><font><font> ، </font></font><code><font><font>چک باکس</font></font></code><font><font> ، </font></font><code><font><font>رادیو</font></font></code><font><font> ، </font></font><code><font><font>فایل</font></font></code><font><font> ، یا یک نوع فشار دهید.</font></font></dd> + <dt><font><font>{{htmlattrdef ("حداکثر")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>حداکثر ارزش (عددی یا تاریخ-زمان) را برای این آیتم، که نباید کمتر از حداقل (آن </font></font><strong><font><font>دقیقه</font></font></strong><font><font> ویژگی) ارزش.</font></font></dd> + <dt><font><font>{{htmlattrdef ("MAXLENGTH")}}</font></font></dt> + <dd><font><font>اگر مقدار از </font></font><strong><font><font>نوع</font></font></strong><font><font> ویژگی است </font></font><code><font><font>متن</font></font></code><font><font> ، </font></font><code><font><font>ایمیل</font></font></code><font><font> ، </font></font><code><font><font>جستجو</font></font></code><font><font> ، </font></font><code><font><font>رمز عبور</font></font></code><font><font> ، </font></font><code><font><font>تلفن</font></font></code><font><font> ، و یا </font></font><code><font><font>URL</font></font></code><font><font> ، این ویژگی به حداکثر تعداد کاراکتر (در نقاط کد یونیکد) که کاربر می تواند وارد مشخص. </font><font>برای دیگر انواع کنترل، آن را نادیده گرفته است. </font><font>این می تواند ارزش بیش از </font></font><strong><font><font>اندازه</font></font></strong><font><font> ویژگی. </font><font>اگر آن مشخص نشده است، کاربر می تواند تعداد نامحدودی از حرف وارد نمایید. </font><font>مشخص نتایج تعداد منفی در رفتار پیش فرض. </font><font>که شده است، کاربر می تواند تعداد نامحدودی از حرف وارد نمایید. </font><font>محدودیت ارزیابی شده است تنها زمانی که ارزش صفت تغییر کرده است.</font></font></dd> + <dt><font><font>{{htmlattrdef ("دقیقه")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>حداقل ارزش (عددی یا تاریخ-زمان) را برای این آیتم، که نباید بیشتر از حداکثر (آن </font></font><strong><font><font>حداکثر</font></font></strong><font><font> ویژگی) ارزش.</font></font></dd> + <dt><font><font>{{htmlattrdef ("minlength")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>اگر مقدار از </font></font><strong><font><font>نوع</font></font></strong><font><font> ویژگی است </font></font><code><font><font>متن</font></font></code><font><font> ، </font></font><code><font><font>ایمیل</font></font></code><font><font> ، </font></font><code><font><font>جستجو</font></font></code><font><font> ، </font></font><code><font><font>رمز عبور</font></font></code><font><font> ، </font></font><code><font><font>تلفن</font></font></code><font><font> ، و یا </font></font><code><font><font>URL</font></font></code><font><font> ، این ویژگی حداقل تعداد کاراکتر (در نقاط کد یونیکد) که کاربر می تواند وارد مشخص. </font><font>برای دیگر انواع کنترل، آن را نادیده گرفته است.</font></font></dd> + <dt><font><font>{{htmlattrdef ("چند")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>این ویژگی بولی نشان می دهد که آیا کاربر می تواند بیش از یک مقدار را وارد کنید. </font><font>این ویژگی صدق زمانی که </font></font><strong><font><font>نوع</font></font></strong><font><font> صفت قرار است به </font></font><code><font><font>ایمیل</font></font></code><font><font> و یا </font></font><code><font><font>فایل</font></font></code><font><font> . </font><font>در غیر این صورت آن را نادیده گرفته است.</font></font></dd> + <dt><font><font>{{htmlattrdef ("نام")}}</font></font></dt> + <dd><font><font>نام کنترل، که با داده های فرم را مشاهده کنید.</font></font></dd> + <dt><font><font>{{htmlattrdef ("الگوی")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>یک عبارت منظم که ارزش کنترل است در برابر بررسی می شود. </font><font>الگوی باید کل ارزش، نه فقط برخی از زیر مجموعه مطابقت. </font><font>استفاده از </font></font><strong><font><font>عنوان</font></font></strong><font><font> ویژگی برای توصیف الگوی برای کمک به کاربر. </font><font>این ویژگی صدق زمانی که ارزش </font></font><strong><font><font>نوع</font></font></strong><font><font> ویژگی است </font></font><code><font><font>متن</font></font></code><font><font> ، </font></font><code><font><font>جستجو</font></font></code><font><font> ، </font></font><code><font><font>تلفن</font></font></code><font><font> ، </font></font><code><font><font>آدرس</font></font></code><font><font> و یا </font></font><code><font><font>ایمیل</font></font></code><font><font> . </font><font>در غیر این صورت آن را نادیده گرفته است. </font><font>زبان عبارت منظم همان را جاوا اسکریپت است. </font><font>الگوی توسط اسلش رو به جلو احاطه نیست.</font></font></dd> + <dt><font><font>{{htmlattrdef ("حفره یا سوراخ")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>اشاره به کاربر از آنچه می تواند در کنترل وارد شده است. </font><font>متن حفره یا سوراخ باید بازده حمل و یا خط تغذیه نیست. </font><font>این ویژگی صدق زمانی که ارزش </font></font><strong><font><font>نوع</font></font></strong><font><font> ویژگی است </font></font><code><font><font>متن</font></font></code><font><font> ، </font></font><code><font><font>جستجو</font></font></code><font><font> ، </font></font><code><font><font>تلفن</font></font></code><font><font> ، </font></font><code><font><font>آدرس</font></font></code><font><font> و یا </font></font><code><font><font>ایمیل</font></font></code><font><font> . </font><font>در غیر این صورت آن را نادیده گرفته است.</font></font> + <div class="note"><strong><font><font>توجه:</font></font></strong><font><font> آیا استفاده نمی </font></font><code><font><font>حفره یا سوراخ</font></font></code><font><font> نسبت به جای {{روی HTMLElement ("برچسب")}} عنصر. </font><font>اهداف خود متفاوت است: {{روی HTMLElement ("برچسب")}} ویژگی را توصیف نقش عنصر فرم. </font><font>که است، آن را نشان می دهد که چه نوع از اطلاعات است انتظار می رود، </font></font><code><font><font>حفره یا سوراخ</font></font></code><font><font> ویژگی یک اشاره در مورد فرمت محتوای باید باشد. </font><font>موارد که در آن وجود دارد </font></font><code><font><font>حفره یا سوراخ</font></font></code><font><font> صفت هرگز به کاربر نمایش داده، به طوری که فرم باید بدون آن قابل فهم باشد.</font></font></div> + </dd> + <dt><font><font>{{htmlattrdef ("فقط خواندنی")}}</font></font></dt> + <dd><font><font>این ویژگی بولی نشان می دهد که کاربر می تواند ارزش های کنترل را تغییر دهید.</font></font> + <p><font><font>{{HTMLVersionInline ("5")}} این صفت اگر مقدار از نادیده گرفته </font></font><strong><font><font>نوع</font></font></strong><font><font> صفت </font></font><code><font><font>پنهان</font></font></code><font><font> ، </font></font><code><font><font>محدوده</font></font></code><font><font> ، </font></font><code><font><font>رنگ</font></font></code><font><font> ، </font></font><code><font><font>چک باکس</font></font></code><font><font> ، </font></font><code><font><font>رادیو</font></font></code><font><font> ، </font></font><code><font><font>فایل</font></font></code><font><font> ، یا یک نوع فشار دهید.</font></font></p> + </dd> + <dt><font><font>{{htmlattrdef ("نیاز")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>این ویژگی مشخص می کند که کاربر باید در یک مقدار قبل از ارسال فرم را پر کنید. </font><font>این می تواند مورد استفاده قرار گیرد که </font></font><strong><font><font>نوع</font></font></strong><font><font> صفت </font></font><code><font><font>پنهان</font></font></code><font><font> ، </font></font><code><font><font>تصویر</font></font></code><font><font> ، و یا یک نوع دکمه ( </font></font><code><font><font>ارسال</font></font></code><font><font> ، </font></font><code><font><font>تنظیم مجدد</font></font></code><font><font> ، و یا </font></font><code><font><font>دکمه</font></font></code><font><font> ). </font><font>{{cssxref (": اختیاری")}} و {{cssxref (": نیاز")}} CSS شبه کلاس خواهد شد به میدان به عنوان مناسب استفاده شود.</font></font></dd> + <dt><font><font>{{htmlattrdef ("selectionDirection")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>جهت است که در آن انتخاب رخ داده است. </font><font>این است "رو به جلو" اگر انتخاب از ساخته شده بود به سمت چپ به راست در محل LTR و یا راست به چپ در محلی RTL، و یا "عقب مانده" اگر انتخاب در جهت مخالف ساخته شده است. </font><font>این می تواند "هیچ" اگر جهت انتخاب ناشناخته است.</font></font></dd> + <dt><font><font>{{htmlattrdef ("اندازه")}}</font></font></dt> + <dd><font><font>اندازه اولیه از کنترل. </font><font>این مقدار است در پیکسل مگر اینکه ارزش </font></font><strong><font><font>نوع</font></font></strong><font><font> ویژگی است </font></font><code><font><font>متن</font></font></code><font><font> یا </font></font><code><font><font>رمز عبور</font></font></code><font><font> ، که در این صورت، آن را یک عدد صحیح از شخصیت است. </font><font>شروع در HTML5، این ویژگی فقط زمانی که </font></font><strong><font><font>نوع</font></font></strong><font><font> صفت به راه </font></font><code><font><font>متن</font></font></code><font><font> ، </font></font><code><font><font>جستجو</font></font></code><font><font> ، </font></font><code><font><font>تلفن</font></font></code><font><font> ، </font></font><code><font><font>آدرس</font></font></code><font><font> ، </font></font><code><font><font>ایمیل</font></font></code><font><font> ، و یا </font></font><code><font><font>رمز عبور</font></font></code><font><font> . </font><font>در غیر این صورت آن را نادیده گرفته است. </font><font>علاوه بر این، اندازه باید بزرگتر از صفر باشد. </font><font>اگر شما یک اندازه مشخص نیست، یک مقدار به طور پیش فرض از 20 استفاده شده است.</font></font></dd> + <dt><font><font>{{htmlattrdef ("چک کردن غلط املایی")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>تنظیم مقدار این ویژگی به </font></font><code><font><font>درست</font></font></code><font><font> نشان می دهد که عنصر نیاز به املا و دستور زبان آن بررسی می شود. </font><font>ارزش </font></font><code><font><font>به طور پیش فرض</font></font></code><font><font> نشان می دهد که عنصر است با توجه به رفتار پیش فرض، احتمالا در عنصر پدر و مادر خود را بر اساس به عمل </font></font><code><font><font>چک کردن غلط املایی</font></font></code><font><font> ارزش. </font><font>ارزش </font></font><code><font><font>نادرست</font></font></code><font><font> نشان می دهد که عنصر باید بررسی شود.</font></font></dd> + <dt><font><font>{{htmlattrdef ("SRC")}}</font></font></dt> + <dd><font><font>اگر مقدار از </font></font><strong><font><font>نوع</font></font></strong><font><font> ویژگی است </font></font><code><font><font>تصویر</font></font></code><font><font> ، این ویژگی URI برای محل از یک تصویر به روی گرافیکی نمایش دکمه ارسال را مشخص. </font><font>در غیر این صورت آن را نادیده گرفته است.</font></font></dd> + <dt><font><font>{{htmlattrdef ("گام")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>با این نسخهها کار میکند </font></font><strong><font><font>دقیقه</font></font></strong><font><font> و </font></font><strong><font><font>حداکثر</font></font></strong><font><font> نسبت به محدود کردن افزایش که در آن یک مقدار عددی یا تاریخ-زمان می تواند مجموعه ای. </font><font>این می تواند رشته </font></font><code><font><font>هر</font></font></code><font><font> و یا تعداد ممیز شناور مثبت است. </font><font>اگر این ویژگی است به تنظیم نشده </font></font><code><font><font>هر</font></font></code><font><font> ، کنترل تنها ارزش می پذیرد در تقسیم عددی بر مضرب ارزش گام بیشتر از حداقل.</font></font></dd> + <dt><font><font>{{htmlattrdef ("tabindex")}}-عنصر خاص در {{HTMLVersionInline (4)}}، جهانی در {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>موقعیت عنصر در tabbing منظور ناوبری برای سند جاری.</font></font></dd> + <dt><font><font>{{htmlattrdef ("usemap")}} {{HTMLVersionInline (4)}} تنها، {{obsoleteGeneric ("درون خطی"، "HTML5")}}</font></font></dt> + <dd><font><font>نام {{روی HTMLElement ("نقشه")}} عنصر به عنوان یک تصویر نقشه.</font></font></dd> + <dt><font><font>{{htmlattrdef ("مقدار")}}</font></font></dt> + <dd><font><font>مقدار اولیه از کنترل. </font><font>این ویژگی اختیاری به جز زمانی که ارزش است </font></font><strong><font><font>نوع</font></font></strong><font><font> ویژگی است </font></font><code><font><font>رادیو</font></font></code><font><font> یا </font></font><code><font><font>چک باکس</font></font></code><font><font> . </font></font><br> + <font><font>توجه داشته باشید که زمانی که بارگیری مجدد صفحه، مارمولک خانگی و اینترنت اکسپلورر </font></font><a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=46845#c186"><font><font>خواهد شد مقدار مشخص شده در کد HTML فوق به چشم پوشی</font></font></a><font><font> ، اگر مقدار قبل از بازنگری تغییر یافت.</font></font></dd> + <dt><font><font>{{htmlattrdef ("عرض")}} {{HTMLVersionInline ("5")}}</font></font></dt> + <dd><font><font>اگر مقدار از </font></font><strong><font><font>نوع</font></font></strong><font><font> ویژگی است </font></font><code><font><font>تصویر</font></font></code><font><font> ، این ویژگی عرض تصویر نمایش داده شده برای دکمه تعریف می کند.</font></font></dd> + <dt><font><font>{{htmlattrdef ("X-moz-errormessage")}} {{غیر standard_inline}}</font></font></dt> + <dd><font><font>این فرمت موزیلا اجازه می دهد تا شما را به مشخص پیغام خطا برای نمایش زمانی که یک میدان می کند با موفقیت اعتبار نیست.</font></font></dd> +</dl> + +<h2 id="یادداشت"><font><font>یادداشت</font></font></h2> + +<h3 id="ورودی_فایل"><font><font>ورودی فایل</font></font></h3> + +<div class="note"> +<p><strong><font><font>توجه داشته باشید:</font></font></strong><font><font> شروع در {{مارمولک خانگی ("2.0")}}، خواستار </font></font><code><font><font>کلیک ()</font></font></code><font><font> روش در {{روی HTMLElement ("ورودی")}} عنصر از نوع "فایل" باز می شود جمع کننده فایل و کاربر فایل را انتخاب کنید اجازه می دهد. </font><font>مشاهده </font></font><a href="/en-US/docs/Using_files_from_web_applications"><font><font>با استفاده از فایل ها از برنامه های کاربردی وب</font></font></a><font><font> برای مثال و جزئیات بیشتر.</font></font></p> +</div> + +<p><font><font>شما می توانید مقدار یک جمع کننده فایل از یک اسکریپت تنظیم نشده. </font><font>انجام کاری مانند زیر اثر ندارد:</font></font></p> + +<pre class="brush: js">ور E = getElementById ("someFileInputElement")؛ +e.value = "غذ"؛ +</pre> + +<h3 id="پیام_های_خطا"><font><font>پیام های خطا</font></font></h3> + +<p><font><font>اگر می خواهید فایرفاکس به ارائه یک پیام خطای سفارشی در زمانی که یک میدان قادر به اعتبارسنجی، شما می توانید با استفاده از </font></font><code><font><font>X-moz-errormessage</font></font></code><font><font> ویژگی به انجام این کار:</font></font></p> + +<pre class="brush: html"><نوع ورودی = "ایمیل" X-moz-errormessage = "لطفا یک آدرس ایمیل معتبر را مشخص کنید."> +</pre> + +<p><font><font>توجه داشته باشید، با این حال، که این استاندارد نیست و یک اثر در مرورگرهای دیگر ندارد.</font></font></p> + +<h2 id="نمونه"><font><font>نمونه</font></font></h2> + +<h3 id="جعبه_ورودی_ساده"><font><font>جعبه ورودی ساده</font></font></h3> + +<pre class="brush: html"><! - ورودی عمومی -> +<نوع ورودی = "متن" نام = "ورودی" مقدار = "در اینجا تایپ کنید"> +</pre> + +<p><input><img alt="" class="ife_marker" id="input_ife_marker_0" style="border: 0pt none; cursor: pointer; display: inline; height: 19px; width: 14px;" title="حداکثر طول فیلد نامشخص است"></p> + +<h3 id="سناریو_مورد_استفاده_مشترک"><font><font>سناریو مورد استفاده مشترک</font></font></h3> + +<pre class="brush: html"><! - فرم مشترک است که شامل تگ های ورودی -> +<اقدام فرم = روش "getform.php" = "دریافت"> + نام: <نوع ورودی = "متن" نام = "FIRST_NAME" /> <br /> + تاریخ و زمان آخرین نام: <نوع ورودی = "متن" نام = "LAST_NAME" /> <br /> + فرستادن به ایمیل: <ورودی نوع = "ایمیل" نام = "USER_EMAIL" /> <br /> +<نوع ورودی = "ارسال" مقدار = "ارسال" /> +</ FORM> +</pre> + +<h3 id="با_استفاده_از_mozactionhint_در_فایرفاکس_موبایل"><font><font>با استفاده از mozactionhint در فایرفاکس موبایل</font></font></h3> + +<p><font><font>شما می توانید {{htmlattrxref ("mozactionhint"، "ورودی")}} نسبت به تعیین متن برای برچسب کلید وارد کنید بر روی صفحه کلید مجازی هنگامی که فرم شما در فایرفاکس موبایل ارائه استفاده کنید. </font><font>به عنوان مثال، به یک "بعدی" برچسب، شما می توانید این کار:</font></font></p> + +<pre class="brush: html"><نوع ورودی = "متن" mozactionhint = "بعدی" نام = "sometext" /> +</pre> + +<p><font><font>نتیجه این است:</font></font></p> + +<p><a href="/@api/deki/files/4970/=mozactionhint.png"><img alt="mozactionhint.png" class="default internal" src="/@api/deki/files/4970/=mozactionhint.png?size=webview" style="border: 1px solid black; height: 350px; width: 210px;"></a></p> + +<h2 id="Specifications" name="Specifications"><font><font>مشخصات</font></font></h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col"><font><font>مشخصات</font></font></th> + <th scope="col"><font><font>وضعیت</font></font></th> + <th scope="col"><font><font>توضیح</font></font></th> + </tr> + </thead> + <tbody> + <tr> + <td><font><font>{{SpecName ('HTML WHATWG'، 'ورودی-element.html #-ورودی-عنصر'، '<ورودی>')}}</font></font></td> + <td><font><font>{{Spec2 ('HTML WHATWG')}}</font></font></td> + <td> </td> + </tr> + <tr> + <td><font><font>{{SpecName ('HTML5 W3C'، 'forms.html #-ورودی-عنصر'، '<ورودی>')}}</font></font></td> + <td><font><font>{{Spec2 ('HTML5 W3C')}}</font></font></td> + <td> </td> + </tr> + <tr> + <td><font><font>{{SpecName ('HTML4.01'، 'تعامل / # forms.html H-17.4'، '<FORM>')}}</font></font></td> + <td><font><font>{{Spec2 ('HTML4.01')}}</font></font></td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="سازگاری_مرورگر"><font><font>سازگاری مرورگر</font></font></h2> + +<p><font><font>{{CompatibilityTable}}</font></font></p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th><font><font>خصوصیات</font></font></th> + <th><font><font>کروم</font></font></th> + <th><font><font>فایرفاکس (مارمولک خانگی)</font></font></th> + <th><font><font>اینترنت اکسپلورر</font></font></th> + <th><font><font>اپرا</font></font></th> + <th><font><font>سیاحت اکتشافی در افریقا</font></font></th> + </tr> + <tr> + <td><font><font>حمایت عمومی</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>2 یا قبل از آن</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = دکمه</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>3</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = چک باکس</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}} </font></font><br> + <font><font>{{CompatGeckoDesktop ("1.9.2")}} برای </font></font><code><font><font>رشد نامحدود</font></font></code><font><font> ارزش</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = رنگ</font></font></td> + <td><font><font>21.0</font></font></td> + <td> + <p><font><font>{{CompatGeckoDesktop ("29.0")}} (نه برای ویندوز لمسی نشده)</font></font></p> + </td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>11.01</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع = تاریخ</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatNo}} </font></font><br> + <font><font>{{unimplemented_inline ("825294")}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}} (به رسمیت شناخته شده اما هیچ UI)</font></font></td> + </tr> + <tr> + <td><font><font>نوع = تاریخ ساعت</font></font></td> + <td> + <p><font><font>{{CompatNo}} </font></font><br> + <font><font>(به رسمیت شناخته شده اما هیچ UI)</font></font></p> + </td> + <td><font><font>{{CompatNo}} </font></font><br> + <font><font>{{unimplemented_inline ("825294")}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}} (به رسمیت شناخته شده اما هیچ UI)</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = تاریخ ساعت محلی</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatNo}} </font></font><br> + <font><font>{{unimplemented_inline ("825294")}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}} (به رسمیت شناخته شده اما هیچ UI)</font></font></td> + </tr> + <tr> + <td><font><font>نوع = ایمیل</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع = فایل</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>3.02</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = پنهان</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = تصویر</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>مارمولک خانگی 2.0 تنها x و y می فرستد مختصات زمانی که کلیک، دیگر نمی به نام / مقدار این عنصر</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = ماه</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatNo}} </font></font><br> + <font><font>{{unimplemented_inline ("446510")}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}} (به رسمیت شناخته شده اما هیچ UI)</font></font></td> + </tr> + <tr> + <td><font><font>نوع = تعداد</font></font></td> + <td><font><font>6.0 (محلی سازی در کروم 11)</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("29.0")}}</font></font></td> + <td><font><font>10 </font></font><br> + <font><font>(به رسمیت شناخته شده اما هیچ UI)</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع = رمز عبور</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = رادیو</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}} </font></font><br> + <font><font>{{CompatGeckoDesktop ("1.9.2")}} برای </font></font><code><font><font>رشد نامحدود</font></font></code><font><font> ارزش</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = دامنه</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("23.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>10.62 (11.01 اضافه شده پشتیبانی از مقدار پیش فرض)</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع = تنظیم مجدد</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = جستجو</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>11.01</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع = ارسال</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = تلفن</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>11.01</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع = متن</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = زمان</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatNo}} </font></font><br> + <font><font>{{unimplemented_inline ("825294")}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}} (به رسمیت شناخته شده اما هیچ UI)</font></font></td> + </tr> + <tr> + <td><font><font>نوع = URL</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع = هفته</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatNo}} </font></font><br> + <font><font>{{unimplemented_inline ("825294")}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}} (به رسمیت شناخته شده اما هیچ UI)</font></font></td> + </tr> + <tr> + <td> + <p><font><font>شرایط = [فرمت فایل]</font></font></p> + </td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + </tr> + <tr> + <td> + <p><font><font>شرایط = [نوع MIME پرونده]</font></font></p> + </td> + <td><font><font>هشت</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("16.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + </tr> + <tr> + <td><font><font>شرایط = صوتی / *</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}} </font></font><br> + <font><font>فیلترها برای پسوند فایل های صوتی زیر: .aac، .aif، .flac، .iff، .m4a، .m4b، .mid، .midi، MP3، .mpa، .mpc ، .oga، .ogg، .ra، .ram، .snd، پنل های ال، .WMA</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + </tr> + <tr> + <td><font><font>شرایط = ویدیو / *</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}} </font></font><br> + <font><font>فیلترها برای پسوند فایل تصویری زیر: .AVI، دیویکس،. FLV، .m4v، .mkv، ویدئویی، .mp4، .mpeg، .MPG، .ogm، .ogv ، .ogx، .rm، .rmvb، .smil، .webm، WMV، .xvid</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + </tr> + <tr> + <td><font><font>شرایط = تصویر / *</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}} </font></font><br> + <font><font>فیلترها برای پسوند فایل تصویر زیر: .jpe، .JPG، .jpeg، با فرمت .gif فعلی، bmp و، .ico، .svg، .svgz، .tif، .tiff ، .ai، .drw، .pct، .psp، .xcf، فایل PSD، .raw</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + </tr> + <tr> + <td><font><font>= [شرایط. </font><font>+ EXT]</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("37.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>ویژه accesskey</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>6</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>mozactionhint</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + </tr> + <tr> + <td><font><font>تکمیل خودکار</font></font></td> + <td><font><font>17.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>5</font></font></td> + <td><font><font>9.6</font></font></td> + <td><font><font>5.2</font></font></td> + </tr> + <tr> + <td><font><font>فوکوس خودکار</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>9.6</font></font></td> + <td><font><font>5.0</font></font></td> + </tr> + <tr> + <td><font><font>بررسی</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>غیر فعال</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>6</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>فرم</font></font></td> + <td><font><font>9.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>formaction</font></font></td> + <td><font><font>9.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>5.2</font></font></td> + </tr> + <tr> + <td><font><font>formenctype</font></font></td> + <td><font><font>9.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>formmethod</font></font></td> + <td><font><font>9.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>5.2</font></font></td> + </tr> + <tr> + <td><font><font>formnovalidate</font></font></td> + <td><font><font>5.0 (در 6.0 تنها با DOCTYPE HTML5 کار، پشتیبانی اعتبار در 7.0 غیر فعال و دوباره فعال در 10.0 بود)</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>formtarget</font></font></td> + <td><font><font>9.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>5.2</font></font></td> + </tr> + <tr> + <td><font><font>ارتفاع</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("16.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>افزایشی</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>inputmode</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + </tr> + <tr> + <td><font><font>فهرست</font></font></td> + <td><font><font>20.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>9.6</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + </tr> + <tr> + <td><font><font>حداکثر</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("16.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>MAXLENGTH</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7")}}</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>دقیقه</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("16.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>minlength</font></font></td> + <td><font><font>40.0</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>چندین</font></font></td> + <td><font><font>1.0 (پشتیبانی برای نوع = فایل و نوع = ایمیل از 5.0)</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.9.2")}} برای </font></font><strong><font><font>نوع</font></font></strong><font><font> = فایل </font></font><br> + <font><font>{{CompatVersionUnknown}} برای </font></font><strong><font><font>نوع</font></font></strong><font><font> = ایمیل</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>1.0 (پشتیبانی 10.62 برای نوع = فایل و به عنوان از 11.01 نوع = ایمیل)</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نام</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>الگو</font></font></td> + <td><font><font>5.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>9.6</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + </tr> + <tr> + <td><font><font>حفره یا سوراخ</font></font></td> + <td><font><font>10.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>11.00</font></font></td> + <td><font><font>5.0</font></font></td> + </tr> + <tr> + <td><font><font>فقط خواندنی</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>6 (از دست رفته برای </font></font><strong><font><font>نوع</font></font></strong><font><font> از </font></font><code><font><font>چک باکس</font></font></code><font><font> ، </font></font><code><font><font>رادیو</font></font></code><font><font> )</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>ضروری</font></font></td> + <td><font><font>5.0 (پشتیبانی از عنصر انتخاب به عنوان 10)</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("2.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>9.6</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + </tr> + <tr> + <td><font><font>اندازه</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>چک کردن غلط املایی</font></font></td> + <td><font><font>10.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.9.2")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>11.0</font></font></td> + <td><font><font>چهار</font></font></td> + </tr> + <tr> + <td><font><font>SRC</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>2</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>گام</font></font></td> + <td><font><font>6.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("16.0")}}</font></font></td> + <td><font><font>10</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>5.0</font></font></td> + </tr> + <tr> + <td><font><font>tabindex</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("1.7 و یا قبل از آن")}}</font></font></td> + <td><font><font>6 (عناصر با tabindex> 0 می پیمایش نمی شود)</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>عرض</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("16.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>1.0</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th><font><font>خصوصیات</font></font></th> + <th><font><font>آندروید</font></font></th> + <th><font><font>فایرفاکس موبایل (مارمولک خانگی)</font></font></th> + <th><font><font>اینترنت اکسپلورر موبایل</font></font></th> + <th><font><font>اپرا موبایل</font></font></th> + <th><font><font>صفری موبایل</font></font></th> + </tr> + <tr> + <td><font><font>حمایت عمومی</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع = دکمه</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع = چک باکس</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع = رنگ</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoDesktop ("27.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نوع = تاریخ</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>5.0</font></font></td> + </tr> + <tr> + <td><font><font>نوع = تاریخ ساعت</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = تاریخ ساعت محلی</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = ایمیل</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>3.1 (بدون اعتبار سنجی اما می دهد یک صفحه کلید خاص)</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = فایل</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}} [1]</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = پنهان</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = تصویر</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = ماه</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = تعداد</font></font></td> + <td><font><font>2.3 (بدون اعتبار سنجی اما می دهد یک صفحه کلید خاص)</font></font></td> + <td><font><font>{{CompatGeckoMobile ("29.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>4.0 (بدون اعتبار سنجی اما می دهد یک صفحه کلید خاص)</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = رمز عبور</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = رادیو</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = دامنه</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>5.0</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = تنظیم مجدد</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = جستجو</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>چهار</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = ارسال</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = تلفن</font></font></td> + <td><font><font>2.3</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>3.1</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = متن</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = زمان</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = URL</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>3.1 (بدون اعتبار سنجی اما می دهد یک صفحه کلید خاص)</font></font></td> + </tr> + <tr> + <td style="white-space: nowrap;"><font><font>نوع = هفته</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>شرایط = [نوع MIME پرونده]</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>شرایط = صوتی / *</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>شرایط = تصویر / *</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>شرایط = ویدیو / *</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>= [شرایط. </font><font>+ EXT]</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("37.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>ویژه accesskey</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>تکمیل خودکار</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>فوکوس خودکار</font></font></td> + <td><font><font>3.2</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>بررسی</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>غیر فعال</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>فرم</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>formaction</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>5.0</font></font></td> + </tr> + <tr> + <td><font><font>formenctype</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>formmethod</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>5.0</font></font></td> + </tr> + <tr> + <td><font><font>formnovalidate</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>formtarget</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>5.0</font></font></td> + </tr> + <tr> + <td><font><font>ارتفاع</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("16.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>فهرست</font></font></td> + <td><font><font>{{CompatNo}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>حداکثر</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("16.0")}} (UI ممکن unimplemented باقی می ماند)</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>MAXLENGTH</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>دقیقه</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("16.0")}} (UI ممکن unimplemented باقی می ماند)</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>minlength</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>چندین</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>نام</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>1.0</font></font></td> + </tr> + <tr> + <td><font><font>الگو</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>حفره یا سوراخ</font></font></td> + <td><font><font>2.3</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>11.10</font></font></td> + <td><font><font>4</font></font></td> + </tr> + <tr> + <td><font><font>فقط خواندنی</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>ضروری</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>اندازه</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + <td><font><font>{{CompatVersionUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>چک کردن غلط املایی</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("2.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>11.0</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>SRC</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>گام</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("16.0")}} (UI ممکن unimplemented باقی می ماند)</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>10.62</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>tabindex</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + <tr> + <td><font><font>عرض</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatGeckoMobile ("16.0")}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + <td><font><font>{{CompatUnknown}}</font></font></td> + </tr> + </tbody> +</table> +</div> + +<p><font><font>[1]: </font></font><a href="http://blog.uploadcare.com/post/97884147203/you-cannot-upload-files-to-a-server-using-mobile-safari"><font><font>ارسال فایل شکسته شد</font></font></a><font><font> برای IOS 8.0 و 8.0.1 در موبایل صفری. </font><font>اشکال در IOS 8.0.2 ثابت شد.</font></font></p> + +<p><font><font>صفری موبایل برای IOS اعمال سبک به طور پیش فرض از </font></font><code><font><font>{{cssxref ("کدورت")}}: 0.4</font></font></code><font><font> به متن غیر فعال {{روی HTMLElement ("ورودی")}} عناصر. </font><font>سایر مرورگرهای اصلی در حال حاضر نمی اشتراک این سبک به طور پیش فرض خاص است.</font></font></p> + +<p><font><font>در Safari موبایل برای IOS، تنظیم </font></font><code><font><font>{{cssxref ("صفحه نمایش")}}: بلوک</font></font></code><font><font> در {{روی HTMLElement ("ورودی")}} از </font></font><code><font><font>نوع = "تاریخ"</font></font></code><font><font> ، </font></font><code><font><font>نوع = "زمان"</font></font></code><font><font> ، </font></font><code><font><font>نوع = "تاریخ ساعت محلی "</font></font></code><font><font> ، و یا </font></font><code><font><font>نوع = "ماه"</font></font></code><font><font> باعث می شود که متن درون {{روی HTMLElement ("ورودی")}} برای تبدیل شدن به صورت عمودی به misaligned.</font></font></p> + +<p><font><font>به عنوان Chrome v39، </font></font><code><font><font><ورودی نوع = "تاریخ"></font></font></code><font><font> مدل دهید با </font></font><code><font><font>{{cssxref ("صفحه نمایش")}}: جدول سلول. </font><font>{{cssxref ("عرض")}}: 100٪؛</font></font></code><font><font> . یک دارای {{cssxref ("دقیقه عرض")}} اعمال شده توسط کروم و نمی توان آن را باریک تر از این حداقل عرض تبدیل </font></font><a href="https://code.google.com/p/chromium/issues/detail?id=346051"><font><font>ببینید کروم اشکال # 346051.</font></font></a></p> + +<h3 id="یادداشت_مارمولک_خانگی"><font><font>یادداشت مارمولک خانگی</font></font></h3> + +<p><font><font>فایرفاکس خواهد شد، بر خلاف سایر مرورگرها، به طور پیش فرض، </font></font><a href="http://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing"><font><font>اصرار دولت غیر فعال پویا و (در صورت وجود) checkedness پویا</font></font></a><font><font> از {{روی HTMLElement ("ورودی")}} در سراسر بارهای صفحه. </font><font>تنظیم مقدار از {{htmlattrxref ("تکمیل خودکار"، "ورودی")}} نسبت به </font></font><code><font><font>فعال</font></font></code><font><font> غیر فعال کردن این ویژگی. </font><font>این کار حتی زمانی که {{htmlattrxref ("تکمیل خودکار"، "ورودی")}} ویژگی به طور معمول به {{روی HTMLElement ("ورودی")}} به موجب آن {{htmlattrxref ("نوع"، "ورودی صدق نمی کند ")}}. </font><font>مشاهده {{اشکال (654072)}}.</font></font></p> + +<p><font><font>شروع در مارمولک خانگی 9.0 {{geckoRelease ("9.0")}}، فایرفاکس برای آندروید کاربران امکان می دهد ضبط تصاویر با استفاده از دوربین خود و ارسال آنها، بدون نیاز به مرورگر را ترک کنند. </font><font>توسعه دهندگان وب می توانید این ویژگی را به سادگی مشخص تنظیم اجرای </font></font><code><font><font>شرایط</font></font></code><font><font> مقدار ویژگی به "تصویر / *" در خود </font></font><code><font><font>فایل</font></font></code><font><font> ورودی، مثل این:</font></font></p> + +<p><code><font><font><ورودی نوع = "فایل" شرایط = "تصویر / *"></font></font></code></p> + +<p><font><font>فایرفاکس برای آندروید مجموعه به طور پیش فرض {{cssxref ("تصویر پس زمینه")}} شیب در همه </font></font><code><font><font>نوع = "متن"</font></font></code><font><font> ، </font></font><code><font><font>نوع = "فایل"</font></font></code><font><font> ، </font></font><code><font><font>نوع = "را فشار دهید"</font></font></code><font><font> ، و </font></font><code><font><font>نوع = "ارسال"</font></font></code><font><font> ورودی. </font><font>این را می توان با استفاده از غیرفعال </font></font><code><font><font>تصویر پس زمینه: هیچ کدام</font></font></code><font><font> .</font></font></p> + +<p><font><font>فایرفاکس برای آندروید همچنین مجموعه به طور پیش فرض {{cssxref ("مرز")}} در تمام </font></font><code><font><font><ورودی نوع = "فایل"></font></font></code><font><font> عناصر.</font></font></p> + +<h4 id="محلی_کردن"><font><font>محلی کردن</font></font></h4> + +<p><font><font>ورودی مجاز برای برخی از <ورودی> انواع در منطقه بستگی دارد. </font><font>در برخی از مناطق، 1،000.00 یک شماره تلفن معتبر است، در حالی که در دیگر مناطق راه معتبر برای ورود به این تعداد 1.000،00 است.</font></font></p> + +<p><font><font>فایرفاکس با استفاده از فن آوری هوشمند زیر برای تعیین مکان به اعتبار ورودی کاربر (حداقل برای نوع = "تعداد"):</font></font></p> + +<ul> + <li><font><font>سعی کنید به زبان مشخص شده توسط 'زبان' / 'XML: زبان' ویژگی در عنصر یا هر یک از پدر و مادر خود را.</font></font></li> + <li><font><font>سعی کنید به زبان مشخص شده توسط هر هدر HTTP Content-زبان و یا</font></font></li> + <li><font><font>اگر هیچ موردی مشخص، استفاده از زبان مرورگر.</font></font></li> +</ul> + +<h2 id="همچنین_ببینید"><font><font>همچنین ببینید</font></font></h2> + +<ul> + <li><font><font>دیگر عناصر مرتبط با فرم: {{روی HTMLElement ("فرم")}}، {{روی HTMLElement ("را فشار دهید")}}، {{روی HTMLElement ("کنترل DataList")}}، {{روی HTMLElement ("افسانه")}}، {{روی HTMLElement ("برچسب")}}، {{روی HTMLElement ("انتخاب کنید")}}، {{روی HTMLElement ("optgroup")}}، {{روی HTMLElement ("گزینه")}}، {{روی HTMLElement ("ناحیه ی متن ")}}، {{روی HTMLElement (" کرک ")}}، {{روی HTMLElement (" از فیلدها ")}}، {{روی HTMLElement (" خروجی ")}}، {{روی HTMLElement (" پیشرفت ")}} و { {روی HTMLElement ("متر")}}.</font></font></li> + <li><a class="external" href="http://webdesignerwall.com/tutorials/cross-browser-html5-placeholder-text"><font><font>صلیب مرورگر متن حفره یا سوراخ HTML5</font></font></a></li> +</ul> + +<p><font><font>{{HTMLRef}}</font></font></p> diff --git a/files/fa/web/html/global_attributes/id/index.html b/files/fa/web/html/global_attributes/id/index.html new file mode 100644 index 0000000000..c57e277c10 --- /dev/null +++ b/files/fa/web/html/global_attributes/id/index.html @@ -0,0 +1,67 @@ +--- +title: شناسه +slug: Web/HTML/Global_attributes/id +translation_of: Web/HTML/Global_attributes/id +--- +<div dir="rtl">{{HTMLSidebar("Global_attributes")}}</div> + +<div dir="rtl"><strong><code>id</code> {{glossary("global attribute")}} (صفت سراسری <code>id</code>)</strong> شناسه (ID) ایست که باید در تمام سند بیهمتا باشد. هدف آن شناسایی عنصری خاص به هنگام پیوند دادن (با استفاده از <a href="https://wiki.developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Identifying_resources_on_the_Web#Fragment">شناسهی تکه</a>)، اسکریپتنویسی، یا طراحی ( با {{glossary("CSS")}}) است.</div> + +<div>{{EmbedInteractiveExample("pages/tabbed/attribute-id.html","tabbed-shorter")}}</div> + +<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples </a> and send us a pull request.</p> + +<div class="blockIndicator warning"> +<p dir="rtl">مقدار این صفت یک رشتهی مبهم است، به این معنی که نویسندگان وب نباید از آن برای رساندن اطلاعاتی که برای انسان قابل خواندن است استفاده کنند.</p> +</div> + +<p dir="rtl">مقدار <code>id</code> نباید حاوی {{glossary("whitespace")}} (فاصلهها، تبها و مانند آن) باشد. در شناسه هایی که حاوی فاصلهی سفید (whitespace) هستند، مرورگرها فاصلهی سفید را بخشی از شناسه در نظر میگیرند. برخلاف صفت {{htmlattrxref("class")}}، که مقادیر جداشده با فاصله را مجاز میداند، عنصرها تنها میتوانند یک مقدار شناسه داشته باشند. </p> + +<div class="blockIndicator note"> +<p dir="rtl"><strong>پانویس: </strong>استفاده از کاراکترهایی بجز حروف {{glossary("ASCII")}} (اسکی)، ارقام، <code>'_'</code>، <code>'-'</code> و <code>'.'</code> ممکن است موجب مشکلات سازگاری شود؛ چون در HTML 4 مجاز نبودند. اگرچه این محدودیت در{{glossary("HTML5")}} برداشته شدهاست؛ برای سازگاری، شناسه باید با حرف آغاز شود.</p> +</div> + +<h2 id="مشخصات">مشخصات</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">مشخصه</th> + <th scope="col">وضعیت</th> + <th scope="col">توضیح</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', "dom.html#the-id-attribute", "id")}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>No change from latest snapshot, {{SpecName('HTML5.1')}}</td> + </tr> + <tr> + <td>{{SpecName('HTML5.1', "dom.html#the-id-attribute", "id")}}</td> + <td>{{Spec2('HTML5.1')}}</td> + <td>Snapshot of {{SpecName('HTML WHATWG')}}, no change from {{SpecName('HTML5 W3C')}}</td> + </tr> + <tr> + <td>{{SpecName('HTML5 W3C', "dom.html#the-id-attribute", "id")}}</td> + <td>{{Spec2('HTML5 W3C')}}</td> + <td>Snapshot of {{SpecName('HTML WHATWG')}}, now accept <code>'_'</code>, <code>'-'</code> and <code>'.'</code> if not at the beginning of the id. It is also a true global attribute.</td> + </tr> + <tr> + <td>{{SpecName('HTML4.01', 'struct/global.html#adef-id', 'id')}}</td> + <td>{{Spec2('HTML4.01')}}</td> + <td>Supported on all elements but {{HTMLElement("base")}}, {{HTMLElement("head")}}, {{HTMLElement("html")}}, {{HTMLElement("meta")}}, {{HTMLElement("script")}}, {{HTMLElement("style")}}, and {{HTMLElement("title")}}.</td> + </tr> + </tbody> +</table> + +<h2 id="سازگاری_مرورگر">سازگاری مرورگر</h2> + + + +<p>{{Compat("html.global_attributes.id")}}</p> + +<h2 id="همچنین_ببینید">همچنین ببینید</h2> + +<ul> + <li>.همهی <a href="https://wiki.developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes">صفتهای سراسری</a></li> + <li>{{domxref("Element.id")}} که بازتاب کنندهی این صفت است.</li> +</ul> diff --git a/files/fa/web/html/global_attributes/index.html b/files/fa/web/html/global_attributes/index.html new file mode 100644 index 0000000000..067b89b21c --- /dev/null +++ b/files/fa/web/html/global_attributes/index.html @@ -0,0 +1,201 @@ +--- +title: Global attributes +slug: Web/HTML/Global_attributes +tags: + - Attribute + - HTML + - NeedsTranslation + - Reference + - TopicStub + - Web +translation_of: Web/HTML/Global_attributes +--- +<div>{{HTMLSidebar("Global_attributes")}}</div> + +<p><strong>Global attributes</strong> are attributes common to all HTML elements; they can be used on all elements, though they may have no effect on some elements.</p> + +<p>Global attributes may be specified on all <a href="/en-US/docs/Web/HTML/Element">HTML elements</a>, <em>even those not specified in the standard</em>. That means that any non-standard elements must still permit these attributes, even though using those elements means that the document is no longer HTML5-compliant. For example, HTML5-compliant browsers hide content marked as <code><foo hidden>...</foo></code>, even though <code><foo></code> is not a valid HTML element.</p> + +<p>In addition to the basic HTML global attributes, the following global attributes also exist:</p> + +<ul> + <li>{{HTMLAttrDef("xml:lang")}} and {{HTMLAttrDef("xml:base")}} — these are inherited from the XHTML specifications and deprecated, but kept for compatibility purposes.</li> + <li>The multiple <code><strong><a href="/en-US/docs/Web/Accessibility/ARIA">aria-*</a></strong></code> attributes, used for improving accessibility.</li> + <li>The <a href="/en-US/docs/Web/Guide/Events/Event_handlers">event handler</a> attributes: <code><strong>onabort</strong></code>, <code><strong>onautocomplete</strong></code>, <code><strong>onautocompleteerror</strong></code>, <code><strong>onblur</strong></code>, <code><strong>oncancel</strong></code>, <code><strong>oncanplay</strong></code>, <code><strong>oncanplaythrough</strong></code>, <code><strong>onchange</strong></code>, <code><strong>onclick</strong></code>, <code><strong>onclose</strong></code>, <code><strong>oncontextmenu</strong></code>, <code><strong>oncuechange</strong></code>, <code><strong>ondblclick</strong></code>, <code><strong>ondrag</strong></code>, <code><strong>ondragend</strong></code>, <code><strong>ondragenter</strong></code>, <code><strong>ondragexit</strong></code>, <code><strong>ondragleave</strong></code>, <code><strong>ondragover</strong></code>, <code><strong>ondragstart</strong></code>, <code><strong>ondrop</strong></code>, <code><strong>ondurationchange</strong></code>, <code><strong>onemptied</strong></code>, <code><strong>onended</strong></code>, <code><strong>onerror</strong></code>, <code><strong>onfocus</strong></code>, <code><strong>oninput</strong></code>, <code><strong>oninvalid</strong></code>, <code><strong>onkeydown</strong></code>, <code><strong>onkeypress</strong></code>, <code><strong>onkeyup</strong></code>, <code><strong>onload</strong></code>, <code><strong>onloadeddata</strong></code>, <code><strong>onloadedmetadata</strong></code>, <code><strong>onloadstart</strong></code>, <code><strong>onmousedown</strong></code>, <code><strong>onmouseenter</strong></code>, <code><strong>onmouseleave</strong></code>, <code><strong>onmousemove</strong></code>, <code><strong>onmouseout</strong></code>, <code><strong>onmouseover</strong></code>, <code><strong>onmouseup</strong></code>, <code><strong>onmousewheel</strong></code>, <code><strong>onpause</strong></code>, <code><strong>onplay</strong></code>, <code><strong>onplaying</strong></code>, <code><strong>onprogress</strong></code>, <code><strong>onratechange</strong></code>, <code><strong>onreset</strong></code>, <code><strong>onresize</strong></code>, <code><strong>onscroll</strong></code>, <code><strong>onseeked</strong></code>, <code><strong>onseeking</strong></code>, <code><strong>onselect</strong></code>, <code><strong>onshow</strong></code>, <code><strong>onsort</strong></code>, <code><strong>onstalled</strong></code>, <code><strong>onsubmit</strong></code>, <code><strong>onsuspend</strong></code>, <code><strong>ontimeupdate</strong></code>, <code><strong>ontoggle</strong></code>, <code><strong>onvolumechange</strong></code>, <code><strong>onwaiting</strong></code>.</li> +</ul> + +<h2 id="List_of_global_attributes">List of global attributes</h2> + +<dl> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/accesskey">{{HTMLAttrDef("accesskey")}}</a></dt> + <dd>Provides a hint for generating a keyboard shortcut for the current element. This attribute consists of a space-separated list of characters. The browser should use the first one that exists on the computer keyboard layout.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/autocapitalize">{{HTMLAttrDef("autocapitalize")}}</a></dt> + <dd>Controls whether and how text input is automatically capitalized as it is entered/edited by the user. It can have the following values: + <ul> + <li><code>off</code> or <code>none</code>, no autocapitalization is applied (all letters default to lowercase)</li> + <li><code>on</code> or <code>sentences</code>, the first letter of each sentence defaults to a capital letter; all other letters default to lowercase</li> + <li><code>words</code>, the first letter of each word defaults to a capital letter; all other letters default to lowercase</li> + <li><code>characters</code>, all letters should default to uppercase</li> + </ul> + </dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/class">{{HTMLAttrDef("class")}}</a></dt> + <dd>A space-separated list of the classes of the element. Classes allows CSS and JavaScript to select and access specific elements via the <a href="/en-US/docs/Web/CSS/Class_selectors">class selectors</a> or functions like the method {{DOMxRef("Document.getElementsByClassName()")}}.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/contenteditable">{{HTMLAttrDef("contenteditable")}}</a></dt> + <dd>An enumerated attribute indicating if the element should be editable by the user. If so, the browser modifies its widget to allow editing. The attribute must take one of the following values: + <ul> + <li><code>true</code> or the <em>empty string</em>, which indicates that the element must be editable;</li> + <li><code>false</code>, which indicates that the element must not be editable.</li> + </ul> + </dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/contextmenu">{{HTMLAttrDef("contextmenu")}}{{Obsolete_Inline}}</a></dt> + <dd>The <code><a href="#attr-id"><strong>id</strong></a></code> of a {{HTMLElement("menu")}} to use as the contextual menu for this element.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/data-*">{{HTMLAttrDef("data-*")}}</a></dt> + <dd>Forms a class of attributes, called custom data attributes, that allow proprietary information to be exchanged between the <a href="/en-US/docs/Web/HTML">HTML</a> and its {{glossary("DOM")}} representation that may be used by scripts. All such custom data are available via the {{DOMxRef("HTMLElement")}} interface of the element the attribute is set on. The {{DOMxRef("HTMLElement.dataset")}} property gives access to them.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/dir">{{HTMLAttrDef("dir")}}</a></dt> + <dd>An enumerated attribute indicating the directionality of the element's text. It can have the following values: + <ul> + <li><code>ltr</code>, which means <em>left to right </em>and is to be used for languages that are written from the left to the right (like English);</li> + <li><code>rtl</code>, which means <em>right to left</em> and is to be used for languages that are written from the right to the left (like Arabic);</li> + <li><code>auto</code>, which lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then it applies that directionality to the whole element.</li> + </ul> + </dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/draggable">{{HTMLAttrDef("draggable")}}</a></dt> + <dd>An enumerated attribute indicating whether the element can be dragged, using the <a href="/en-us/docs/DragDrop/Drag_and_Drop">Drag and Drop API</a>. It can have the following values: + <ul> + <li><code>true</code>, which indicates that the element may be dragged</li> + <li><code>false</code>, which indicates that the element may not be dragged.</li> + </ul> + </dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/dropzone">{{HTMLAttrDef("dropzone")}}</a> {{deprecated_inline}}</dt> + <dd>An enumerated attribute indicating what types of content can be dropped on an element, using the <a href="/en-US/docs/DragDrop/Drag_and_Drop">Drag and Drop API</a>. It can have the following values: + <ul> + <li><code>copy</code>, which indicates that dropping will create a copy of the element that was dragged</li> + <li><code>move</code>, which indicates that the element that was dragged will be moved to this new location.</li> + <li><code>link</code>, will create a link to the dragged data.</li> + </ul> + </dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/exportparts">{{HTMLAttrDef("exportparts")}}</a> {{Experimental_Inline}}</dt> + <dd>Used to transitively export shadow parts from a nested shadow tree into a containing light tree.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/hidden">{{HTMLAttrDef("hidden")}}</a></dt> + <dd>A Boolean attribute indicates that the element is not yet, or is no longer, <em>relevant</em>. For example, it can be used to hide elements of the page that can't be used until the login process has been completed. The browser won't render such elements. This attribute must not be used to hide content that could legitimately be shown.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/id">{{HTMLAttrDef("id")}}</a></dt> + <dd>Defines a unique identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/inputmode">{{HTMLAttrDef("inputmode")}}</a></dt> + <dd>Provides a hint to browsers as to the type of virtual keyboard configuration to use when editing this element or its contents. Used primarily on {{HTMLElement("input")}} elements, but is usable on any element while in {{HTMLAttrxRef("contenteditable")}} mode.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/is">{{HTMLAttrDef("is")}}</a></dt> + <dd>Allows you to specify that a standard HTML element should behave like a registered custom built-in element (see <a href="/en-US/docs/Web/Web_Components/Using_custom_elements">Using custom elements</a> for more details).</dd> +</dl> + +<div class="note"> +<p><strong>Note: </strong>The <code>item*</code> attributes are part of the <a class="external" href="https://html.spec.whatwg.org/multipage/microdata.html#microdata">WHATWG HTML Microdata feature</a>.</p> +</div> + +<dl> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/itemid">{{HTMLAttrDef("itemid")}}</a></dt> + <dd>The unique, global identifier of an item.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/itemprop">{{HTMLAttrDef("itemprop")}}</a></dt> + <dd>Used to add properties to an item. Every HTML element may have an <code>itemprop</code> attribute specified, where an <code>itemprop</code> consists of a name and value pair.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/itemref">{{HTMLAttrDef("itemref")}}</a></dt> + <dd>Properties that are not descendants of an element with the <code>itemscope</code> attribute can be associated with the item using an <code>itemref</code>. It provides a list of element ids (not <code>itemid</code>s) with additional properties elsewhere in the document.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/itemscope">{{HTMLAttrDef("itemscope")}}</a></dt> + <dd><code>itemscope</code> (usually) works along with {{HTMLAttrxRef("itemtype")}} to specify that the HTML contained in a block is about a particular item. <code>itemscope</code> creates the Item and defines the scope of the <code>itemtype</code> associated with it. <code>itemtype</code> is a valid URL of a vocabulary (such as <a class="external external-icon" href="https://schema.org/">schema.org</a>) that describes the item and its properties context.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/itemtype">{{HTMLAttrDef("itemtype")}}</a></dt> + <dd>Specifies the URL of the vocabulary that will be used to define <code>itemprop</code>s (item properties) in the data structure. {{HTMLAttrxRef("itemscope")}} is used to set the scope of where in the data structure the vocabulary set by <code>itemtype</code> will be active.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/lang">{{HTMLAttrDef("lang")}}</a></dt> + <dd>Helps define the language of an element: the language that non-editable elements are in, or the language that editable elements should be written in by the user. The attribute contains one “language tag” (made of hyphen-separated “language subtags”) in the format defined in <a class="external" href="https://www.ietf.org/rfc/bcp/bcp47.txt"><em>Tags for Identifying Languages (BCP47)</em></a>. <a href="#attr-xml:lang"><strong>xml:lang</strong></a> has priority over it.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/part">{{HTMLAttrDef("part")}}</a></dt> + <dd>A space-separated list of the part names of the element. Part names allows CSS to select and style specific elements in a shadow tree via the {{CSSxRef("::part")}} pseudo-element.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/slot">{{HTMLAttrDef("slot")}}</a></dt> + <dd>Assigns a slot in a <a href="/en-US/docs/Web/Web_Components/Shadow_DOM">shadow DOM</a> shadow tree to an element: An element with a <code>slot</code> attribute is assigned to the slot created by the {{HTMLElement("slot")}} element whose {{HTMLAttrxRef("name", "slot")}} attribute's value matches that <code>slot</code> attribute's value.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/spellcheck">{{HTMLAttrDef("spellcheck")}}</a></dt> + <dd>An enumerated attribute defines whether the element may be checked for spelling errors. It may have the following values: + <ul> + <li><code>true</code>, which indicates that the element should be, if possible, checked for spelling errors;</li> + <li><code>false</code>, which indicates that the element should not be checked for spelling errors.</li> + </ul> + </dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/style">{{HTMLAttrDef("style")}}</a></dt> + <dd>Contains <a href="/en-US/docs/Web/CSS">CSS</a> styling declarations to be applied to the element. Note that it is recommended for styles to be defined in a separate file or files. This attribute and the {{HTMLElement("style")}} element have mainly the purpose of allowing for quick styling, for example for testing purposes.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/tabindex">{{HTMLAttrDef("tabindex")}}</a></dt> + <dd>An integer attribute indicating if the element can take input focus (is <em>focusable</em>), if it should participate to sequential keyboard navigation, and if so, at what position. It can take several values: + <ul> + <li>a <em>negative value</em> means that the element should be focusable, but should not be reachable via sequential keyboard navigation;</li> + <li><code>0</code> means that the element should be focusable and reachable via sequential keyboard navigation, but its relative order is defined by the platform convention;</li> + <li>a <em>positive value</em> means that the element should be focusable and reachable via sequential keyboard navigation; the order in which the elements are focused is the increasing value of the <a href="#attr-tabindex"><strong>tabindex</strong></a>. If several elements share the same tabindex, their relative order follows their relative positions in the document.</li> + </ul> + </dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/title">{{HTMLAttrDef("title")}}</a></dt> + <dd>Contains a text representing advisory information related to the element it belongs to. Such information can typically, but not necessarily, be presented to the user as a tooltip.</dd> + <dt><a href="/en-US/docs/Web/HTML/Global_attributes/translate">{{HTMLAttrDef("translate")}}</a> {{Experimental_Inline}}</dt> + <dd>An enumerated attribute that is used to specify whether an element's attribute values and the values of its {{DOMxRef("Text")}} node children are to be translated when the page is localized, or whether to leave them unchanged. It can have the following values: + <ul> + <li>empty string and <code>yes</code>, which indicates that the element will be translated.</li> + <li><code>no</code>, which indicates that the element will not be translated.</li> + </ul> + </dd> +</dl> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("HTML WHATWG", "dom.html#global-attributes", "Global attributes")}}</td> + <td>{{Spec2("HTML WHATWG")}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName("CSS Shadow Parts", "#exposing")}}</td> + <td>{{Spec2("CSS Shadow Parts")}}</td> + <td>Added the <code>part</code> and <code>exportparts</code> global attributes.</td> + </tr> + <tr> + <td>{{SpecName("HTML5.2", "dom.html#global-attributes", "Global attributes")}}</td> + <td>{{Spec2("HTML5.2")}}</td> + <td>Snapshot of {{SpecName("HTML WHATWG")}}. From {{SpecName("HTML5.1")}}, <code>itemid</code>, <code>itemprop</code>, <code>itemref</code>, <code>itemscope</code>, and <code>itemtype</code> have been added.</td> + </tr> + <tr> + <td>{{SpecName("HTML5.1", "dom.html#global-attributes", "Global attributes")}}</td> + <td>{{Spec2("HTML5.1")}}</td> + <td>Snapshot of {{SpecName("HTML WHATWG")}}. From {{SpecName("HTML5 W3C")}}, <code>contextmenu</code>, <code>draggable</code>, <code>dropzone</code>, and <code>spellcheck</code> have been added.</td> + </tr> + <tr> + <td>{{SpecName("HTML5 W3C", "dom.html#global-attributes", "Global attributes")}}</td> + <td>{{Spec2("HTML5 W3C")}}</td> + <td>Snapshot of {{SpecName("HTML WHATWG")}}. From {{SpecName("HTML4.01")}}, the concept of global attributes is introduced and the <code>dir</code>, <code>lang</code>, <code>style</code>, <code>id</code>, <code>class</code>, <code>tabindex</code>, <code>accesskey</code>, and <code>title</code> are now true global attributes.<br> + <code>xml:lang</code> which was initially part of XHTML, is now also part of HTML.<br> + <code>hidden</code>, <code>data-*</code>, <code>contenteditable</code>, and <code>translate</code> have been added.</td> + </tr> + <tr> + <td>{{SpecName("HTML4.01")}}</td> + <td>{{Spec2("HTML4.01")}}</td> + <td>There are no global attributes defined. Several attributes that will become global attributes in subsequent specifications are defined on a subset of elements.<br> + <code>class</code> and <code>style</code> are supported on all elements but {{HTMLElement("base")}}, {{HTMLElement("basefont")}}, {{HTMLElement("head")}}, {{HTMLElement("html")}}, {{HTMLElement("meta")}}, {{HTMLElement("param")}}, {{HTMLElement("script")}}, {{HTMLElement("style")}}, and {{HTMLElement("title")}}.<br> + <code>dir</code> is supported on all elements but {{HTMLElement("applet")}}, {{HTMLElement("base")}}, {{HTMLElement("basefont")}}, {{HTMLElement("bdo")}}, {{HTMLElement("br")}}, {{HTMLElement("frame")}}, {{HTMLElement("frameset")}}, {{HTMLElement("iframe")}}, {{HTMLElement("param")}}, and {{HTMLElement("script")}}.<br> + <code>id</code> is supported on all elements but {{HTMLElement("base")}}, {{HTMLElement("head")}}, {{HTMLElement("html")}}, {{HTMLElement("meta")}}, {{HTMLElement("script")}}, {{HTMLElement("style")}}, and {{HTMLElement("title")}}.<br> + <code>lang</code> is supported on all elements but {{HTMLElement("applet")}}, {{HTMLElement("base")}}, {{HTMLElement("basefont")}}, {{HTMLElement("br")}}, {{HTMLElement("frame")}}, {{HTMLElement("frameset")}}, {{HTMLElement("iframe")}}, {{HTMLElement("param")}}, and {{HTMLElement("script")}}.<br> + <code>tabindex</code> is only supported on {{HTMLElement("a")}}, {{HTMLElement("area")}}, {{HTMLElement("button")}}, {{HTMLElement("object")}}, {{HTMLElement("select")}}, and {{HTMLElement("textarea")}}.<br> + <code>accesskey</code> is only supported on {{HTMLElement("a")}}, {{HTMLElement("area")}}, {{HTMLElement("button")}}, {{HTMLElement("input")}}, {{HTMLElement("label")}}, {{HTMLElement("legend")}} and {{HTMLElement("textarea")}}.<br> + <code>title</code> is supported on all elements but {{HTMLElement("base")}}, {{HTMLElement("basefont")}}, {{HTMLElement("head")}}, {{HTMLElement("html")}}, {{HTMLElement("meta")}}, {{HTMLElement("param")}}, {{HTMLElement("script")}}, and {{HTMLElement("title")}}.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("html.global_attributes")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{DOMxRef("Element")}} and {{DOMxRef("GlobalEventHandlers")}} interfaces that allow to query most global attributes.</li> +</ul> diff --git a/files/fa/web/html/index.html b/files/fa/web/html/index.html new file mode 100644 index 0000000000..5d9c861feb --- /dev/null +++ b/files/fa/web/html/index.html @@ -0,0 +1,64 @@ +--- +title: HTML +slug: Web/HTML +tags: + - HTML + - HTML5 + - Landing + - NeedsTranslation + - TopicStub + - Web +translation_of: Web/HTML +--- +<div>{{HTMLSidebar}}</div> + +<p class="summary" dir="rtl"><span class="seoSummary">HTML </span>(زبان نشانه گذاری متنی مضاعف یا Hyper Text Markup Languge) بوده و <span class="seoSummary">نخستین زبانی است که برای ساخت بخش های مختلف وب استفاده می شود.. آن برای معنادادن و ساختاربندی کردن محتوای وب به کار می رود. فناوریهایی دیگری در صفحات وب در کنار HTML به کار گرفته می شوند تا ظاهر یا نحوه نمایش یک صفحه وب (مانند CSS) یا عملکرد/رفتار آن (مانندJavaScript) را ایجاد و کنترل کنند.</span></p> + +<p dir="rtl"><span class="seoSummary">"متن مضاعف یا همان Hyper text" به اتصال صفحات وب به هم، اتصال بخش های یک صفحه وب به یکدیگر و یا در نگاه بالاتر اتصال چندین وب سایت به یکدیگر اشاره دارد. لینک ها یکی از بنیادی ترین بخش های وبسایت ها هستند. با با بارگذاری محتواهایتان بر روی وب و سپس اضافه کردن لینک های معنادار بین آن ها شما یکی از اصول اساسی در مشارکت فعال دنیای وب را به اجرا درآورده اید. </span></p> + +<p dir="rtl"><span class="seoSummary">زبان HTML از «نشانه گذاری یا Markup» برای تعریف نوشته، تصویر و یا دیگر محتواها در یک مرورگر وب استفاده می کند. نشانه گذاریی که در زبان HTML به کار می رود از «عناصر یا ELement ها ویژه ای مانند:</span></p> + +<p dir="rtl" style="direction: ltr;"> {{HTMLElement("head")}}, {{HTMLElement("title")}}, {{HTMLElement("body")}}, {{HTMLElement("header")}}, {{HTMLElement("footer")}}, {{HTMLElement("article")}}, {{HTMLElement("section")}}, {{HTMLElement("p")}}, {{HTMLElement("div")}}, {{HTMLElement("span")}}, {{HTMLElement("img")}}</p> + +<p dir="rtl">و موارد بسیار دیگر استفاده می کند..</p> + +<p dir="rtl">عناصر HTML با استفاده از «تگ ها Tage» از متن های ساده نوشتاری جدا می شوند، این عناصر با یک جفت علامت شکسته «<» و «>» احاطه می شوند. نام عناصر در میان این تگ ها وارد می شوند و مهم نیست که با حروف بزرگ و یا کوچک نوشته شوند. به همین خاطر می توان آن ها را به صورت با حروف کوچک و یا حروف بزرگ نوشت. برای مثال تگ <title> می تواند به صورت <Title> ، <TITLE> و یا هر شکل دیگری نوشته شود.</p> + +<p dir="rtl">در مقالات زیر می تواند مطالب بیشتری را درباره HTML بخوانید و بیاموزید.</p> + +<ul class="card-grid" dir="rtl"> + <li> + <h2 id="معرفی_HTML">معرفی HTML</h2> + + <p>اگر به تازگی برنامه نویسی وب را شروع کرده این بخش می تواند به شما کمک کند که بهتر با <a href="https://wiki.developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/HTML_basics">اصول HTML</a> آشنا شوید.</p> + </li> + <li> + <h2 id="آموزش_HTM"><span>آموزش HTM</span></h2> + + <p><span>در این قسمت مقالاتی ارائه شده است که به شما استفاده کردن از HTML و تگ های آن را یاد می دهد همچنین در کنار آن ها آموزش ها و مثال هایی نیز آمده شده است که می تواند به شناخت<a href="https://wiki.developer.mozilla.org/en-US/docs/Learn/HTML"> زمینه HTML</a> کمک شایانی برایتان فراهم آورد.</span></p> + </li> + <li><span>منابع HTML</span> + <p>در <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference">مراجع متعدد</a> می توانید انبوهی از مطالب مفید درباره عناصر را بیابید که هر کدام از این مقالات نیز دارای زیرمجموعه های مفصلی هستند. در کنار آن <a href="https://wiki.developer.mozilla.org/en-US/docs/Web/HTML/Link_types">لینک</a> هایی قرار داشته است که شما را به مطالب مرتبط راهنمایی می کند.</p> + </li> +</ul> + +<div class="row topicpage-table" dir="rtl"> +<div class="section"> +<h2 class="Documentation" id="Documentation" name="Documentation">منابع</h2> + +<p>{{SubpagesWithSummaries}}</p> + +<p><a href="https://developer.mozilla.org/en-US/docs/tag/HTML" title="Article tagged: HTML"><span class="alllinks">نمایش همه...</span></a></p> +</div> + +<div class="section"> +<h2 class="Tools" id="Tools" name="Tools">راهنمایی ها و آموزشها</h2> + +<dl> + <dt>راهنمای توسعه دهندهی HTML</dt> + <dd>مقالههای MDN تکنیکهای خاصی که در هنگام ساخت محتوی وب با HTML میتوانید استفاده کنید، همچنین آموزشها و اصولی که ممکن است برای شما مفید باشند را نمایش میدهند.</dd> +</dl> +</div> +</div> + +<p dir="rtl"></p> diff --git a/files/fa/web/html/tips_for_authoring_fast-loading_html_pages/index.html b/files/fa/web/html/tips_for_authoring_fast-loading_html_pages/index.html new file mode 100644 index 0000000000..94048c4ba7 --- /dev/null +++ b/files/fa/web/html/tips_for_authoring_fast-loading_html_pages/index.html @@ -0,0 +1,127 @@ +--- +title: نکاتی دربارهی ایجاد صفحات HTML سریع +slug: Web/HTML/Tips_for_authoring_fast-loading_HTML_pages +translation_of: Learn/HTML/Howto/Author_fast-loading_HTML_pages +--- +<p dir="rtl">نکات زیر بر اساس دانش و تجربه به دست آمدهاند.</p> +<p dir="rtl">یک صفحهی وب بهینه نه تنها برای مخاطبهای شما تعاملیتر است، بلکه روی وبسرور و اتصال اینترنت شما نیز تاثیرگذار است. این امر میتواند برای سایتهایی که ترافیک بالایی دارند مانند سایتهای خبری، مسالهای اساسی باشد.</p> +<p dir="rtl">بهینهسازی عملکرد یک صفحه فقط برای کاربران با اینترنت کم سرعت مطرح نیست. بلکه برای آن دسته از کاربران با اینترنت پرسرعت نیز تاثیر به سزایی دارد.</p> +<h2 dir="rtl" id="Tips" name="Tips">نکتهها</h2> +<h3 dir="rtl" id="Reduce_page_weight" name="Reduce_page_weight">کاهش دادن وزن صفحه</h3> +<p dir="rtl">وزن صفحه، یکی از مهمترین فاکتورهای بارگیری یک صفحه است.</p> +<p dir="rtl">کاهش وزن صفحه به این معنا است که با حذف کردن جاهای خالی و خطوط کمکی (comment) و با انتقال اسکریپتها و برگههای سبک سلسلهمراتبی به فایلهای خارجی، سرعت بارگیری صفحه را تا حد امکان افزایش دهیم.</p> +<p dir="rtl">ابزاری مانند <a href="http://tidy.sourceforge.net/" title="http://tidy.sourceforge.net/">HTML Tidy</a> میتوانند به صورت خودکار جاهای خالی اضافی را از یک سند HTML حذف کنند. ابزار دیگری نیز وجود دارند که فایلهای جاوااسکریپت را با تکنیکهای فشردهسازی، فشرده کرده و با کاهش حجم آنها باعث افزایش سرعت بارگیری صفحه میشوند.</p> +<h3 dir="rtl" id="Minimize_the_number_of_files" name="Minimize_the_number_of_files">کاهش تعداد فایلها</h3> +<p dir="rtl">با کاهش یافتن تعداد فایلهای مورد نیاز یک صفحه، تعداد درخواستهای <a href="/en-US/docs/HTTP" title="/en-US/docs/HTTP">HTTP</a> جهت بارگیری صفحه نیز کاهش مییابد.</p> +<p dir="rtl">بسته به تنظیمات حافظهی نهان مرورگر، ممکن است درخواست <code>If-Modified-Since</code> به وبسرور برای هر فایل CSS، جاوااسکریپت یا تصویر فرستاده شود که در آن مشخص میشود آیا فایل نسبت به آخرین باری که دانلود شده، تغییر کرده است یا خیر.</p> +<p dir="rtl">با کاهش تعداد فایلهایی که در یک صفحه به آنها ارجاع داده میشود، تعداد درخواستها به سرور و پاسخهایی که از سرور ارسال میشود نیز کاهش مییابد.</p> +<p dir="rtl">اگر از تصاویر پسزمینه در فایل CSS خود به نسبت زیادی استفاده میکنید میتوانید با استفاده از تکینیکی به نام image sprite این تصاویر را با هم ترکیب کنید تا تعداد درخواستهای ارسالی به سرور کاهش یابد. تنها کافی است با تغییر موقعیت تصویر در صفحه نحوهی نمایش آن را در حالتهای مختلف تنظیم کنید. این تکنیک برای عنصرهایی که ابعاد محدودی در صفحه دارند به خوبی کار میکند. اگرچه تعداد درخواستهای http کمتر و cache کردن هر تصویر نیز میتواند به عنوان راه حل جایگزین مطرح باشد.</p> +<p dir="rtl">زمان زیادی که صرف میشود تا آخرین تاریخ تغییر یک فایل مشخص شود، میتواند منجر به تاخیر در نمایش اولیه از یک صفحه شود، چرا که مرورگر قبل از اینکه صفحه را پردازش کند باید زمان تغییر یا modification هر فایل CSS یا جاوااسکریپت را بررسی کند.</p> +<h3 dir="rtl" id="Reduce_domain_lookups" name="Reduce_domain_lookups">کاهش تعداد ارجاعها به دامنههای مختلف</h3> +<p dir="rtl">از آنجایی که هر دامنهی منحصر به فرد در فرآیند DNS Lookup هزینهی زمانی دارد، زمان بارگذاری صفحه با توجه به تعداد دامنههای مختلف در فایلهای CSS ،جاوااسکریپت و تصویرها افزایش مییابد.</p> +<p dir="rtl">با این حال همیشه به یاد داشته باشید تا آنجا که ممکن است از حداقل تعداد دامنههای مختلف در صفحات سایت استفاده کنید.</p> +<h3 dir="rtl" id="Cache_reused_content" name="Cache_reused_content">محتوای کاربردی را Cache کنید</h3> +<p dir="rtl">اطمینان یابید هر محتوایی که قابل cache شدن است، این اتفاق برایش افتاده باشد و زمان پایانی cache نیز دارا باشد.</p> +<p dir="rtl">در حقیقت باید به فایل سرآیند (header) با نام <code>Last-Modified</code> توجه خاصی داشت. کار این فایل ذخیرهسازی آخرین زمانی است که به صفحات ثابت (<code>html و css و ...</code>) از طریق user agent یا همان مرورگر بر اساس زمان موجود در وب سرور، ارجاع شده است. البته این موضوع در رابطه با صفحات پویا (php و aspx و ...) اتفاق نمیافتد، یعنی این فایل سرآیند ارسال نمیشود.</p> +<p dir="rtl">دربارهی صفحاتی که به صورت پویا ایجاد میشوند، اندکی تحقیق در این باره میتواند بسیار مفید باشد. با استفاده از پیوندهای زیر اطلاعات بیشتری دربارهی cache کردن صفحات پویا کسب کنید:</p> +<ol dir="rtl"> + <li><a class="external" href="http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers">HTTP Conditional Get for RSS Hackers</a></li> + <li><a class="external" href="http://annevankesteren.nl/archives/2005/05/http-304">HTTP 304: Not Modified</a></li> + <li><a class="external" href="http://www.cmlenz.net/blog/2005/05/on_http_lastmod.html">On HTTP Last-Modified and ETag</a></li> +</ol> +<h3 dir="rtl" id="Optimally_order_the_components_of_the_page" name="Optimally_order_the_components_of_the_page">ترتیب بهینهی اجزای تشکیل دهندهی صفحه</h3> +<p dir="rtl">ابتدا محتوای صفحه بارگذاری شود، همراه با هرفایل CSS یا JavaScript که در نمایش اولیهی آن تاثیر دارد، تا کاربر بتواند در کوتاهترین زمان ممکن به محتوای صفحه دسترسی داشته باشد. این محتوا معمولا از متن تشکیل میشود که در زمان کوتاهی میتواند در اختیار کاربر قرار گیرد.</p> +<p dir="rtl">هرگونه ویژگی پویا که پس از بارگذاری کامل صفحه مورد نیاز هستند، در مرحلهی اول باید غیرفعال گردد و تنها زمانی فعال شود که تمام محتوای صفحه بارگذاری شده باشد. از جملهی این ویژگیها میتوان به فایلهای JavaScript اشاره کرد که در انتهای سند قرار میگیرند که این امر موجب بارگذاری سریع صفحات میشود.</p> +<h3 dir="rtl" id="Reduce_the_number_of_inline_scripts" name="Reduce_the_number_of_inline_scripts">کاهش تعداد اسکریپتهای برخط (inline)</h3> +<p dir="rtl">این نوع اسکریپتها میتوانند زمان زیادی را به خود اختصاص دهند، چرا که parser باید در نظر بگیرد که یک اسکریپت برخط میتواند ساختار صفحه را هنگامی که خود صفحه در حال parse شدن است، تغییر دهد. کاهش تعداد این اسکریپتها به صورت عمومی، و کاهش استفاده از <code>document.write</code> به صورت اختصاصی، میتواند منجر به افزایش سرعت در بارگذاری صفحات شود. همچنین استفاده از روشهای پیشرفته در <a href="/en-US/docs/AJAX" title="/en-US/docs/AJAX">AJAX</a> جهت تغییر در محتوای صفحه به جای استفاده از <code>document.write</code> توصیه میشود.</p> +<h3 dir="rtl" id="Use_modern_CSS_and_valid_markup" name="Use_modern_CSS_and_valid_markup">استفاده از CSS پیشرفته و عنصرهای معتبر</h3> +<p dir="rtl">استفاده از CSS به صورت صحیح میتواند تعداد عنصرهای مورد نیاز در صفحه را به شکل قابل ملاحظهای کاهش دهد. از جمله این تکنیکها میتوان به جایگزین کردن برخی تصاویر (که به spacer معروف هستند) با معادل CSS آنها جهت قالببندی صفحه اشاره کرد.</p> +<p dir="rtl">استفاده از عنصرهای معتبر نیز مزایای خود را دارد. اول از همه، مرورگرها دیگر نیازی ندارند تا فرآیند بررسی خطا در کد HTML را انجام دهند. ((البته این موضوع با بحث فلسفی آن که ابتدا کاربر محتوای خود را وارد میکند سپس به صورت منطقی فرآیند بررسی آن محتوا آغار میشود، متفاوت است)).</p> +<p dir="rtl">به علاوه، استفاده از عنصرهای معتبر این امکان را در اختیار سایر ابزار میگذارد تا صفحات سایت شما را بررسی (<em>pre-process</em>) کنند. برای نمونه، <a href="http://tidy.sourceforge.net/" title="http://tidy.sourceforge.net/">HTML Tidy</a> میتواند فضای خالی در صفحات و تگهای پایانی اختیاری را حذف کند; اگرچه این ابزار در صفحاتی که دارای خطاهای بسیار در عنصرها باشند، اجرا نمیشود.</p> +<h3 dir="rtl" id="Chunk_your_content" name="Chunk_your_content">محتوا را طبقهبندی کنید</h3> +<p dir="rtl">استفاده از جدولها در قالببندی صفحات یک روش منسوخ است که دیگر نباید استفاده شود. در عوض از عنصر {{ HTMLElement("div") }} و در آیندهی نزدیک از <a href="/en-US/docs/CSS/Using_CSS_multi-column_layouts" title="/en-US/docs/CSS/Using_CSS_multi-column_layouts">ساختار چند ستونی CSS3</a> یا <a href="/en-US/docs/Using_flexbox" title="/en-US/docs/Using_flexbox">ساختار منعطف جعبهای CSS3</a> باید استفاده شود.</p> +<p dir="rtl">جدولها هنوز هم به عنوان عنصرهای معتبر در صفحه شناخته میشوند اما تنها باید برای نمایش دادههای جدولی استفاده گردند. برای این که مرورگرها صفحهی شما را سریعتر پردازش کنند باید از جدولهای تودرتو خودداری کنید.</p> +<p dir="rtl">به جای اینکه از ساختاری مانند این استفاده کنید:</p> +<pre><TABLE> + <TABLE> + <TABLE> + ... + </TABLE> + </TABLE> +</TABLE></pre> +<p dir="rtl">در عوض از جدولهایی که جداگانه هستند یا divها استفاده کنید.</p> +<pre><TABLE>...</TABLE> +<TABLE>...</TABLE> +<TABLE>...</TABLE> +</pre> +<p dir="rtl">همچنین میتوانید مستندات <a href="http://www.w3.org/TR/css3-multicol/" title="http://www.w3.org/TR/css3-multicol/">CSS3 Multi-column Layout</a> یا <a href="http://www.w3.org/TR/css3-flexbox/" title="http://www.w3.org/TR/css3-flexbox/">CSS3 Flexible Box Layout</a> را مشاهده کنید.</p> +<h3 dir="rtl" id="Specify_sizes_for_images_and_tables" name="Specify_sizes_for_images_and_tables">مشخص کردن اندازهی تصویرها و جدولها</h3> +<p dir="rtl">اگر مرورگر به محض دریافت تصویر یا جدول بتواند اندازهی آن را تشخیص دهد، این امر موجب نمایش هر چه بهتر محتوای صفحه در زمان بارگذاری خواهد شد. به همین منظور استفاده از <code>height</code> و <code>width</code> برای تصویرها در هر جایی که ممکن است باید استفاده گردند.</p> +<p dir="rtl">برای جدولها نیز میتوان از قطعه کد CSS زیر استفاده کرد:</p> +<pre> table-layout: fixed; +</pre> +<p dir="rtl">همچنین باید از تگهای <code>COL</code> و <code>COLGROUP</code> برای مشخص کردن عرض جدولهای استفاده کرد.</p> +<h3 dir="rtl" id="Choose_your_user-agent_requirements_wisely" name="Choose_your_user-agent_requirements_wisely">حداقل محدودیتهای مرورگر را در نظر بگیرید</h3> +<p dir="rtl">برای اینکه صفحهی شما در مرورگرهای مختلف با کمترین اختلاف ممکن نمایش داده شود، اطمینان یابید که حداقل استانداردهای مورد نیاز مرورگرها در پروژههایتان رعایت شده باشند. این بدان معنا نیست که محتوای شما باید در تمامی مرورگرها دقیقا به یک شکل نمایش یابد، به خصوص مرورگرهای قدیمی.</p> +<p dir="rtl">در حقیقت، حداقل پیشنیازهای شما باید منطبق با مرورگرهای پیشرفتهای باشند که استانداردهای وب را رعایت میکنند که این مرورگرها شامل Firefox 3.6 به بالا برای تمامی پلتفرمها، Internet Explorer 8 به بالا در ویندوز، Opera 10 به بالا در ویندوز و Safari 4 به بالا در Mac OS X هستند.</p> +<p dir="rtl">اگرچه، بسیاری از نکاتی که در این مقاله فهرست شدهاند، تکنیکهای عمومی هستند که میتوان برای هر مرورگری و برای هر صفحهی وب به کار برد، جدا از پشتیبانی مرورگرها.</p> +<h2 dir="rtl" id="Example_page_structure" name="Example_page_structure">ساختار صفحهی مورد نظر ما</h2> +<p>· <code>HTML</code></p> +<dl> + <dd> + · <code>HEAD</code></dd> +</dl> +<dl> + <dd> + <dl> + <dd> + · <code>LINK </code>...</dd> + <dd dir="rtl"> + فایلهای CSS که جهت نمایش صفحه مورد نیاز هستند. تعداد این فایلها را پایین نگه دارید تا عملکرد صفحه افزایش یابد. همچنین میتوان سایر فایلهای CSS نامربتط با این صفحه را در فایلهای دیگر قرار داد.</dd> + </dl> + </dd> +</dl> +<dl> + <dd> + <dl> + <dd> + · <code>SCRIPT </code>...</dd> + <dd dir="rtl"> + فایلهای JavaScript که <strong>موردنیاز</strong> توابعی هستند که در زمان بارگذاری صفحه فراخوانی میشوند. تعداد این فایلها را جهت عملکرد بهتر صفحه، پایین نگه دارید.</dd> + </dl> + </dd> +</dl> +<dl> + <dd> + · <code>BODY</code></dd> + <dd dir="rtl"> + محتوای مورد نظر صفحه که در قالب جدولها یا divها گردآوری شدهاند. این محتوا میتواند جدا از سایر اجزای صفحه نمایش یابد.</dd> +</dl> +<dl> + <dd> + <dl> + <dd> + · <code>SCRIPT </code>...</dd> + <dd dir="rtl"> + هر اسکریپتی که در ساختار صفحه (DHTML) تغییر ایجاد میکند. این اسکریپتها میتوانند پس از بارگذاری تمام صفحه و نمایش محتوا به کاربر، اجرا شوند. بنابراین دلیلی ندارد که بارگذاری آنها قبل از محتوا صورت گیرد که در این صورت نمایش محتوا به کاربر با تاخیر همراه میشود.</dd> + <dd dir="rtl"> + اگر تصویری جهت حرکتهای rollover در نظر گرفتهاید، باید در این قسمت از صفحه preload یا پیشبارگذاری شوند، جایی که محتوای صفحه قبل از آن نمایش داده شده است.</dd> + </dl> + </dd> +</dl> +<h2 dir="rtl" id="Related_Links" name="Related_Links">پیوندهای مرتبط</h2> +<ul> + <li dir="rtl">کتاب: <a href="http://www.websiteoptimization.com/" title="http://www.websiteoptimization.com/">"Speed Up Your Site" نوشتهی Andy King</a></li> + <li dir="rtl"><a href="http://webmonkey.wired.com/webmonkey/design/site_building/tutorials/tutorial2.html" title="http://webmonkey.wired.com/webmonkey/design/site_building/tutorials/tutorial2.html">آموزش بهینهسازی سایت</a> (WebMonkey)</li> + <li dir="rtl">مقالهی عالی و کامل <a href="http://developer.yahoo.com/performance/rules.html" title="http://developer.yahoo.com/performance/rules.html">Best Practices for Speeding Up Your Web Site</a> از (Yahoo)</li> +</ul> +<div class="originaldocinfo"> + <h2 id="Original_Document_Information" name="Original_Document_Information">Original Document Information</h2> + <ul> + <li>Author(s): Bob Clary, Technology Evangelist, Netscape Communications</li> + <li>Last Updated Date: Published 04 Apr 2003</li> + <li>Copyright Information: Copyright © 2001-2003 Netscape. All rights reserved.</li> + <li>Note: This reprinted article was originally part of the DevEdge site.</li> + </ul> +</div> +<p> </p> diff --git a/files/fa/web/html/افزودن_رنگ/index.html b/files/fa/web/html/افزودن_رنگ/index.html new file mode 100644 index 0000000000..99f2d980cf --- /dev/null +++ b/files/fa/web/html/افزودن_رنگ/index.html @@ -0,0 +1,502 @@ +--- +title: اضافه کردن رنگ به عناصر با استفاده از سی اس اس +slug: Web/HTML/افزودن_رنگ +translation_of: Web/HTML/Applying_color +--- +<div>{{HTMLRef}}</div> + +<p>The use of color is a fundamental form of human expression. Children experiment with color before they even have the manual dexterity to draw. Maybe that's why color is one of the first things people often want to experiment with when learning to develop web sites. <span class="seoSummary">With <a href="/en-US/docs/Web/CSS">CSS</a>, there are lots of ways to add color to your <a href="/en-US/docs/Web/HTML">HTML</a> <a href="/en-US/docs/Web/HTML/Element">elements</a> to create just the look you want. This article is a primer introducing each of the ways CSS color can be used in HTML.</span></p> + +<p>Fortunately, adding color to your HTML is actually really easy to do, and you can add color to nearly anything.</p> + +<p>We're going to touch on most of what you'll need to know when using color, including a {{anch("Things that can have color", "list of what you can color and what CSS properties are involved")}}, {{anch("How to describe a color", "how you describe colors")}}, and how to actually {{anch("Using color", "use colors both in stylesheets and in scripts")}}. We'll also take a look at how to {{anch("Letting the user picka color", "let the user pick a color")}}.</p> + +<p>Then we'll wrap things up with a brief discussion of how to {{anch("Using color wisely", "use color wisely")}}: how to select appropriate colors, keeping in mind the needs of people with differing visual capabilities.</p> + +<h2 id="Things_that_can_have_color">Things that can have color</h2> + +<p>At the element level, everything in HTML can have color applied to it. Instead, let's look at things in terms of the kinds of things that are drawn in the elements, such as text and borders and so forth. For each, we'll see a list of the CSS properties that apply color to them.</p> + +<p>At a fundamental level, the {{cssxref("color")}} property defines the foreground color of an HTML element's content and the {{cssxref("background-color")}} property defines the element's background color. These can be used on just about any element.</p> + +<h3 id="Text">Text</h3> + +<p>Whenever an element is rendered, these properties are used to determine the color of the text, its background, and any decorations on the text.</p> + +<dl> + <dt>{{cssxref("color")}}</dt> + <dd>The color to use when drawing the text and any <a href="/en-US/docs/Learn/CSS/Styling_text/Fundamentals#Font_style_font_weight_text_transform_and_text_decoration">text decorations</a> (such as the addition of under- or overlines, strike-through lines, and so forth.</dd> + <dt>{{cssxref("background-color")}}</dt> + <dd>The text's background color.</dd> + <dt>{{cssxref("text-shadow")}}</dt> + <dd>Configures a shadow effect to apply to text. Among the options for the shadow is the shadow's base color (which is then blurred and blended with the background based on the other parameters). See {{SectionOnPage("/en-US/docs/Learn/CSS/Styling_text/Fundamentals", "Text drop shadows")}} to learn more.</dd> + <dt>{{cssxref("text-decoration-color")}}</dt> + <dd>By default, text decorations (such as underlines, strikethroughs, etc) use the <code>color</code> property as their colors. However, you can override that behavior and use a different color for them with the <code>text-decoration-color</code> property.</dd> + <dt>{{cssxref("text-emphasis-color")}}</dt> + <dd>The color to use when drawing emphasis symbols adjacent to each character in the text. This is used primarily when drawing text for East Asian languages.</dd> + <dt>{{cssxref("caret-color")}}</dt> + <dd>The color to use when drawing the {{Glossary("caret")}} (sometimes referred to as the text input cursor) within the element. This is only useful in elements that are editable, such as {{HTMLElement("input")}} and {{HTMLElement("textarea")}} or elements whose HTML {{htmlattrxref("contenteditable")}} attribute is set.</dd> +</dl> + +<h3 id="Boxes">Boxes</h3> + +<p>Every element is a box with some sort of content, and has a background and a border in addition to whatever contents the box may have.</p> + +<dl> + <dt>{{anch("Borders")}}</dt> + <dd>See the section {{anch("Borders")}} for a list of the CSS properties you can use to set the colors of a box's borders.</dd> + <dt>{{cssxref("background-color")}}</dt> + <dd>The background color to use in areas of the element that have no foreground content.</dd> + <dt>{{cssxref("column-rule-color")}}</dt> + <dd>The color to use when drawing the line separating columns of text.</dd> + <dt>{{cssxref("outline-color")}}</dt> + <dd>The color to use when drawing an outline around the outside of the element. This outline is different from the border in that it doesn't get space set aside for it in the document (so it may overlap other content). It's generally used as a focus indicator, to show which element will receive input events.</dd> +</dl> + +<h3 id="Borders">Borders</h3> + +<p>Any element can have a <a href="/en-US/docs/Learn/CSS/Styling_boxes/Borders">border</a> drawn around it. A basic element border is a line drawn around the edges of the element's content. See {{SectionOnPage("/en-US/docs/Learn/CSS/Introduction_to_CSS/Box_model", "Box properties")}} to learn about the relationship between elements and their borders, and the article <a href="/en-US/docs/Learn/CSS/Styling_boxes/Borders">Styling borders using CSS</a> to learn more about applying styles to borders.</p> + +<p>You can use the {{cssxref("border")}} shorthand property, which lets you configure everything about the border in one shot (including non-color features of borders, such as its <a href="/en-US/docs/Web/CSS/border-width">width</a>, <a href="/en-US/docs/Web/CSS/border-style">style</a> (solid, dashed, etc.), and so forth.</p> + +<dl> + <dt>{{cssxref("border-color")}}</dt> + <dd>Specifies a single color to use for every side of the element's border.</dd> + <dt>{{cssxref("border-left-color")}}, {{cssxref("border-right-color")}}, {{cssxref("border-top-color")}}, and {{cssxref("border-bottom-color")}}</dt> + <dd>Lets you set the color of the corresponding side of the element's border.</dd> + <dt>{{cssxref("border-block-start-color")}} and {{cssxref("border-block-end-color")}}</dt> + <dd>With these, you can set the color used to draw the borders which are closest to the start and end of the block the border surrounds. In a left-to-right writing mode (such as the way English is written), the block start border is the top edge and the block end is the bottom. This differs from the inline start and end, which are the left and right edges (corresponding to where each line of text in the box begins and ends).</dd> + <dt>{{cssxref("border-inline-start-color")}} and {{cssxref("border-inline-end-color")}}</dt> + <dd>These let you color the edges of the border closest to to the beginning and the end of the start of lines of text within the box. Which side this is will vary depending on the {{cssxref("writing-mode")}}, {{cssxref("direction")}}, and {{cssxref("text-orientation")}} properties, which are typically (but not always) used to adjust text directionality based on the language being displayed. For example, if the box's text is being rendered right-to-left, then the <code>border-inline-start-color</code> is applied to the right side of the border.</dd> +</dl> + +<h3 id="Other_ways_to_use_color">Other ways to use color</h3> + +<p>CSS isn't the only web technology that supports color. There are graphics technologies that are available on the web which also support color.</p> + +<dl> + <dt>The HTML <a href="/en-US/docs/Web/API/Canvas_API">Canvas API</a></dt> + <dd>Lets you draw 2D bitmapped graphics in a {{HTMLElement("canvas")}} element. See our <a href="/en-US/docs/Web/API/Canvas_API/Tutorial">Canvas tutorial</a> to learn more.</dd> + <dt><a href="/en-US/docs/Web/SVG">SVG</a> (Scalable Vector Graphics)</dt> + <dd>Lets you draw images using commands that draw specific shapes, patterns, and lines to produce an image. SVG commands are formatted as XML, and can be embedded directly into a web page or can be placed in he page using the {{HTMLElement("img")}} element, just like any other type of image.</dd> + <dt><a href="/en-US/docs/Web/API/WebGL_API">WebGL</a></dt> + <dd>The Web Graphics Library is an OpenGL ES-based API for drawing high-performance 2D and 3D graphics on the Web. See <a href="/en-US/docs/Learn/WebGL">Learn WebGL for 2D and 3D</a> graphics to find out more.</dd> +</dl> + +<h2 id="How_to_describe_a_color">How to describe a color</h2> + +<p>In order to represent a color in CSS, you have to find a way to translate the analog concept of "color" into a digital form that a computer can use. This is typically done by breaking down the color into components, such as how much of each of a set of primary colors to mix together, or how bright to make the color. As such, there are several ways you can describe color in CSS.</p> + +<p>For more detailed discussion of each of the color value types, see the reference for the CSS {{cssxref("<color>")}} unit.</p> + +<h3 id="Keywords">Keywords</h3> + +<p>A set of standard color names have been defined, letting you use these keywords instead of numeric representations of colors if you choose to do so and there's a keyword representing the exact color you want to use. Color keywords include the standard primary and secondary colors (such as <code>red</code>, <code>blue</code>, or <code>orange</code>), shades of gray (from <code>black</code> to <code>white</code>, including colors like <code>darkgray</code> and <code>lightgrey</code>), and a variety of other blended colors including <code>lightseagreen</code>, <code>cornflowerblue</code>, and <code>rebeccapurple</code>.</p> + +<p>See {{SectionOnPage("/en-US/docs/Web/CSS/color_value", "Color keywords", "code")}} for a list of all available color keywords.</p> + +<h3 id="RGB_values">RGB values</h3> + +<p>There are three ways to represent an RGB color in CSS.</p> + +<h4 id="Hexadecimal_string_notation">Hexadecimal string notation</h4> + +<p>Hexadecimal string notation represents a color using hexadecimal digits to represent each of the color components (red, green, and blue). It may also include a fourth component: the alpha channel (or opacity). Each color component can be represented as a number between 0 and 255 (0x00 and 0xFF) or, optionally, as a number between 0 and 15 (0x0 and 0xF). All components <em>must</em> be specified using the same number of digits. If you use the single-digit notation, the final color is computed by using each component's digit twice; that is, <code>"#D"</code> becomes <code>"#DD"</code> when drawing.</p> + +<p>A color in hexadecimal string notation always begins with the character <code>"#"</code>. After that come the hexadecimal digits of the color code. The string is case-insensitive.</p> + +<dl> + <dt><code>"#rrggbb"</code></dt> + <dd>Specifies a fully-opaque color whose red component is the hexadecimal number <code>0xrr</code>, green component is <code>0xgg</code>, and blue component is <code>0xbb</code>.</dd> + <dt><code>"#rrggbbaa"</code></dt> + <dd>Specifies a color whose red component is the hexadecimal number <code>0xrr</code>, green component is <code>0xgg</code>, and blue component is <code>0xbb</code>. The alpha channel is specified by <code>0xaa</code>; the lower this value is, the more translucent the color becomes.</dd> + <dt><code>"#rgb"</code></dt> + <dd>Specifies a color whose red component is the hexadecimal number <code>0xrr</code>, green component is <code>0xgg</code>, and blue component is <code>0xbb</code>.</dd> + <dt><code>"#rgba"</code></dt> + <dd>Specifies a color whose red component is the hexadecimal number <code>0xrr</code>, green component is <code>0xgg</code>, and blue component is <code>0xbb</code>. The alpha channel is specified by <code>0xaa</code>; the lower this value is, the more translucent the color becomes.</dd> +</dl> + +<p>As an example, you can represent the opaque color bright blue as <code>"#0000ff"</code> or <code>"#00f"</code>. To make it 25% opaque, you can use <code>"#0000ff44"</code> or <code>"#00f4"</code>.</p> + +<h4 id="RGB_functional_notation">RGB functional notation</h4> + +<p>RGB (Red/Green/Blue) functional notation, like hexadecimal string notation, represents colors using their red, green, and blue components (as well as, optionally, an alpha channel component for opacity). However, instead of using a string, the color is defined using the CSS function {{cssxref("color_value", "rgb()", "#rgb()")}}. This function accepts as its input parameters the values of the red, green, and blue components and an optional fourth parameter, the value for the alpha channel.</p> + +<p>Legal values for each of these parameters are:</p> + +<dl> + <dt><code>red</code>, <code>green</code>, and <code>blue</code></dt> + <dd>Each must be an {{cssxref("<integer>")}} value between 0 and 255 (inclusive), or a {{cssxref("<percentage>")}} from 0% to 100%.</dd> + <dt><code>alpha</code></dt> + <dd>The alpha channel is a number between 0.0 (fully transparent) and 1.0 (fully opaque). You can also specify a percentage where 0% is the same as 0.0 and 100% is the same as 1.0.</dd> +</dl> + +<p>For example, a bright red that's 50% opaque can be represented as <code>rgb(255, 0, 0, 0.5)</code> or <code>rgb(100%, 0, 0, 50%)</code>.</p> + +<h3 id="HSL_functional_notation">HSL functional notation</h3> + +<p>Designers and artists often prefer to work using the {{interwiki("wikipedia", "HSL and HSV", "HSL")}} (Hue/Saturation/Luminosity) color method. On the web, HSL colors are represented using HSL functional notation. The <code>hsl()</code> CSS function is very similar to the <code>rgb()</code> function in usage otherwise.</p> + +<div style="padding-bottom: 20px;"> +<figure style="width: 500px;"><img alt="HSL color cylinder" src="https://mdn.mozillademos.org/files/15445/1200px-HSL_color_solid_cylinder_alpha_lowgamma.png" style="height: 375px; width: 500px;"> +<figcaption><em><strong>Figure 1. An HSL color cylinder.</strong> Hue defines the actual color based on the position along a circular color wheel representing the colors of the visible spectrum. Saturation is a percentage of how much of the way between being a shade of gray and having the maximum possible amount of the given hue. As the value of luminance (or lightness) increases, the color transitions from the darkest possible to the brightest possible (from black to white). Image courtesy of user <a href="http://commons.wikimedia.org/wiki/User:SharkD">SharkD</a> on <a href="https://www.wikipedia.org/">Wikipedia</a>, distributed under the <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY-SA 3.0</a> license.</em></figcaption> +</figure> +</div> + +<p>The value of the hue (H) component of an HSL color is an angle from red around through yellow, green, cyan, blue, and magenta (ending up back at red again at 360°) that identifies what the base color is. The value can be specified in any {{cssxref("<angle>")}} unit supported by CSS, including degrees (<code>deg</code>), radians (<code>rad</code>), gradians (<code>grad</code>), or turns (<code>turn</code>). But this doesn't control how vivid or dull, or how bright or dark the color is.</p> + +<p>The saturation (S) component of the color specifies what percentage of the final color is comprised of the specified hue. The rest is defined by the grey level provided by the luminance (L) component.</p> + +<p>Think of it like creating the perfect paint color:</p> + +<ol> + <li>You start with base paint that's the maximum intensity possible for a given color, such as the most intense blue that can be represented by the user's screen. This is the <strong>hue</strong> (H) component: a value representing the angle around the color wheel for the vivid hue we want to use as our base.</li> + <li>Then select a greyscale paint that corresponds how bright you want the color to be; this is the luminance. Do you want it to be very bright and nearly white, or very dark and closer to black, or somewhere in between? This is specified using a percentage, where 0% is perfectly black and 100% is perfectly white. (regardless of the saturation or hue). In between values are a literal grey area.</li> + <li>Now that you have a grey paint and a perfectly vivid color, you need to mix them together. The saturation (S) component of the color indicates what percentage of the final color should be comprised of that perfectly vivid color. The rest of the final color is made up of the grey paint that represents the saturation.</li> +</ol> + +<p>You can also optionally include an alpha channel, to make the color less than 100% opaque.</p> + +<p>Here are some sample colors in HSL notation:</p> + +<div id="hsl-swatches"> +<div class="hidden"> +<pre class="brush: css">table { + border: 1px solid black; + font: 16px "Open Sans", Helvetica, Arial, sans-serif; + border-spacing: 0; + border-collapse: collapse; +} + +th, td { + border: 1px solid black; + padding:4px 6px; + text-align: left; +} + +th { + background-color: hsl(0, 0%, 75%); +}</pre> + +<pre class="brush: html"><table> + <thead> + <tr> + <th scope="col">Color in HSL notation</th> + <th scope="col">Example</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>hsl(90deg, 100%, 50%)</code></td> + <td style="background-color: hsl(90deg, 100%, 50%);">&nbsp;</td> + </tr> + <tr> + <td><code>hsl(90, 100%, 50%)</code></td> + <td style="background-color: hsl(90, 100%, 50%);">&nbsp;</td> + </tr> + <tr> + <td><code>hsl(0.15turn, 50%, 75%)</code></td> + <td style="background-color: hsl(0.15turn, 50%, 75%);">&nbsp;</td> + </tr> + <tr> + <td><code>hsl(0.15turn, 90%, 75%)</code></td> + <td style="background-color: hsl(0.15turn, 90%, 75%);">&nbsp;</td> + </tr> + <tr> + <td><code>hsl(0.15turn, 90%, 50%)</code></td> + <td style="background-color: hsl(0.15turn, 90%, 50%);">&nbsp;</td> + </tr> + <tr> + <td><code>hsl(270deg, 90%, 50%)</code></td> + <td style="background-color: hsl(270deg, 90%, 50%);">&nbsp;</td> + </tr> + </tbody> +</table></pre> +</div> + +<p>{{EmbedLiveSample("hsl-swatches", 300, 260)}}</p> +</div> + +<div class="note"> +<p>Note that when you omit the hue's unit, it's assumed to be in degrees (<code>deg</code>).</p> +</div> + +<h2 id="Using_color">Using color</h2> + +<p>Now that you know what CSS properties exist that let you apply color to elements and the formats you can use to describe colors, you can put this together to begin to make use of color. As you may have seen from the list under {{anch("Things that can have color")}}, there are plenty of things you can color with CSS. Let's look at this from two sides: using color within a {{Glossary("stylesheet")}}, and adding and changing color using {{Glossary("JavaScript")}} code to alter the styles of elements.</p> + +<h3 id="Specifying_colors_in_stylesheets">Specifying colors in stylesheets</h3> + +<p>The easiest way to apply color to elements—and the way you'll usually do it—is to simply specify colors in the CSS that's used when rendering elements. While we won't use every single property mentioned previously, we'll look at a couple of examples. The concept is the same anywhere you use color.</p> + +<p>Let's take a look at an example, starting by looking at the results we're trying to achieve:</p> + +<div>{{EmbedLiveSample("Specifying_colors_in_stylesheets", 650, 150)}}</div> + +<h4 id="HTML">HTML</h4> + +<p>The HTML responsible for creating the above example is shown here:</p> + +<pre class="brush: html"><div class="wrapper"> + <div class="box boxLeft"> + <p> + This is the first box. + </p> + </div> + <div class="box boxRight"> + <p> + This is the second box. + </p> + </div> +</div></pre> + +<p>This is pretty simple, using a {{HTMLElement("div")}} as a wrapper around the contents, which consists of two more <code><div></code>s, each styled differently with a single paragraph ({{HTMLElement("p")}}) in each box.</p> + +<p>The magic happens, as usual, in the CSS, where we'll apply colors define the layout for the HTML above.</p> + +<h4 id="CSS">CSS</h4> + +<p>We'll look at the CSS to create the above results a piece at a time, so we can review the interesting parts one by one.</p> + +<pre class="brush: css">.wrapper { + width: 620px; + height: 110px; + margin: 0; + padding: 10px; + border: 6px solid mediumturquoise; +}</pre> + +<p>The <code>.wrapper</code> class is used to assign styles to the {{HTMLElement("div")}} that encloses all of our other content. This establishes thesize of the container using {{cssxref("width")}} and {{cssxref("height")}} as well as its {{cssxref("margin")}} and {{cssxref("padding")}}.</p> + +<p>Of more interest to our discussion here is the use of the {{cssxref("border")}} property to establish a border around the outside edge of the element. This border is a solid line, 6 pixels wide, in the color <code>mediumturquoise</code>.</p> + +<p>Our two colored boxes share a number of properties in common, so next we establish a class, <code>.box</code>, that defines those shared properties:</p> + +<pre class="brush: css">.box { + width: 290px; + height: 100px; + margin: 0; + padding: 4px 6px; + font: 28px "Marker Felt", "Zapfino", cursive; + display: flex; + justify-content: center; + align-items: center; +}</pre> + +<p>In brief, <code>.box</code> establishes the size of each box, as well as the configuration of the font used within. We also take advantage of <a href="/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout">CSS Flexbox</a> to easily center the contents of each box. We enable <code>flex</code> mode using {{cssxref("display", "display: flex")}}, and set both {{cssxref("justify-content")}} and {{cssxref("align-items")}} to <code>center</code>. Then we can create a class for each of the two boxes that defines the propeties that differ between the two.</p> + +<pre class="brush: css">.boxLeft { + float: left; + background-color: rgb(245, 130, 130); + outline: 2px solid darkred; +}</pre> + +<p>The <code>.boxLeft</code> class—which, cleverly, is used to style the box on the left—floats the box to the left, then sets up the colors:</p> + +<ul> + <li>The box's background color is set by changing the value of the CSS {{cssxref("background-color")}} property to <code>rgb(245, 130, 130)</code>.</li> + <li>An outline is defined for the box. Unlike the more commonly used <code>border</code>, {{cssxref("outline")}} doesn't affect layout at all; it draws over the top of whatever may happen to be outside the element's box instead of making room as <code>border</code> does. This outline is a solid, dark red line that's two pixels thick. Note the use of the <code>darkred</code> keyword when specifying the color.</li> + <li>Notice that we're not explicitly setting the text color. That means the value of {{cssxref("color")}} will be inherited from the nearest containing element that defines it. By default, that's black.</li> +</ul> + +<pre class="brush: css">.boxRight { + float: right; + background-color: hsl(270deg, 50%, 75%); + outline: 4px dashed rgb(110, 20, 120); + color: hsl(0deg, 100%, 100%); + text-decoration: underline wavy #88ff88; + text-shadow: 2px 2px 3px black; +}</pre> + +<p>Finally, the <code>.boxRight</code> class describes the unique properties of the box that's drawn on the right. It's configured to float the box to the right so that it appears next to the previous box. Then the following colors are established:</p> + +<ul> + <li>The <code>background-color</code> is set using the HSL value specified using <code>hsl(270deg, 50%, 75%)</code>. This is a medium purple color.</li> + <li>The box's <code>outline</code> is used to specify that the box should be enclosed in a four pixel thick dashed line whose color is a somewhat deeper purple (<code>rgb(110, 20, 120)</code>).</li> + <li>The foreground (text) color is specified by setting the {{cssxref("color")}} property to <code>hsl(0deg, 100%, 100%)</code>. This is one of many ways to specify the color white.</li> + <li>We add a green wavy line under the text with {{cssxref("text-decoration")}}.</li> + <li>Finally, a bit of a shadow is added to the text using {{cssxref("text-shadow")}}. Its <code>color</code> parameter is set to <code>black</code>.</li> +</ul> + +<h2 id="Letting_the_user_pick_a_color">Letting the user pick a color</h2> + +<p>There are many situations in which your web site may need to let the user select a color. Perhaps you have a customizable user interface, or you're implementing a drawing app. Maybe you have editable text and need to let the user choose the text color. Or perhaps your app lets the user assign colors to folders or items. Although historically it's been necessary to implement your own {{interwiki("wikipedia", "color picker")}}, HTML now provides support for browsers to provide one for your use through the {{HTMLElement("input")}} element, by using <code>"color"</code> as the value of its {{htmlattrxref("type", "input")}} attribute.</p> + +<p>The <code><input></code> element represents a color only in the {{anch("Hexadecimal string notation", "hexadecimal string notation")}} covered above.</p> + +<h3 id="Example_Picking_a_color">Example: Picking a color</h3> + +<p>Let's look at a simple example, in which the user can choose a color. As the user adjusts the color, the border around the example changes to reflect the new color. After finishing up and picking the final color, the color picker's value is displayed.</p> + +<p>{{EmbedLiveSample("Example_Picking_a_color", 525, 275)}}</p> + +<div class="note"> +<p>On macOS, you indicate that you've finalized selection of the color by closing the color picker window.</p> +</div> + +<h4 id="HTML_2">HTML</h4> + +<p>The HTML here creates a box that contains a color picker control (with a label created using the {{HTMLElement("label")}} element) and an empty paragraph element ({{HTMLElement("p")}}) into which we'll output some text from our JavaScript code.</p> + +<pre class="brush: html"><div id="box"> + <label for="colorPicker">Border color:</label> + <input type="color" value="#8888ff" id="colorPicker"> + <p id="output"></p> +</div></pre> + +<h4 id="CSS_2">CSS</h4> + +<p>The CSS simply establishes a size for the box and some basic styling for appearances. The border is also established with a 2-pixel width and a border color that won't last, courtesy of the JavaScript below...</p> + +<pre class="brush: css">#box { + width: 500px; + height: 200px; + border: 2px solid rgb(245, 220, 225); + padding: 4px 6px; + font: 16px "Lucida Grande", "Helvetica", "Arial", "sans-serif" +}</pre> + +<h4 id="JavaScript">JavaScript</h4> + +<p>The script here handles the task of updating the starting color of the border to match the color picker's value. Then two event handlers are added to deal with input from the <code><a href="/en-US/docs/Web/HTML/Element/input/color"><input type="color"></a></code> element.</p> + +<pre class="brush: js">let colorPicker = document.getElementById("colorPicker"); +let box = document.getElementById("box"); +let output = document.getElementById("output"); + +box.style.borderColor = colorPicker.value; + +colorPicker.addEventListener("input", function(event) { + box.style.borderColor = event.target.value; +}, false); + +colorPicker.addEventListener("change", function(event) { + output.innerText = "Color set to " + colorPicker.value + "."; +}, false);</pre> + +<p>The {{event("input")}} event is sent every time the value of the element changes; that is, every time the user adjusts the color in the color picker. Each time this event arrives, we set the box's border color to match the color picker's current value.</p> + +<p>The {{event("change")}} event is received when the color picker's value is finalized. We respond by setting the contents of the <code><p></code> element with the ID <code>"output"</code> to a string describing the finally selected color.</p> + +<h2 id="Using_color_wisely">Using color wisely</h2> + +<p>Making the right choices when selecting colors when designing a web site can be a tricky process, especially if you aren't well-grounded in art, design, or at least basic color theory. The wrong color choice can render your site unattractive, or even worse, leave the content unreadable due to problems with contrast or conflicting colors. Worse still, if using the wrong colors can result in your content being outright unusable by people withcertain vision problems, particularly color blindness.</p> + +<h3 id="Finding_the_right_colors">Finding the right colors</h3> + +<p>Coming up with just the right colors can be tricky, especially without training in art or design. Fortunately, there are tools available that can help you. While they can't replace having a good designer helping you make these decisions, they can definitely get you started.</p> + +<h4 id="Base_color">Base color</h4> + +<p>The first step is to choose your <strong>base color</strong>. This is the color that in some way defines your web site or the subject matter of the site. Just as we associate green with the beverage {{interwiki("wikipedia", "Mountain Dew")}} and one might think of the color blue in relationship with the sky or the ocean, choosing an appropriate base color to represent your site is a good place to start. There are plenty of ways to select a base color; a few ideas include:</p> + +<ul> + <li>A color that is naturally associated with the topic of your content, such as the existing color identified with a product or idea or a color representative of the emotion you wish to convey.</li> + <li>A color that comes from imagery associated with what your content is about. If you're creating a web site about a given item or product, choose a color that's physically present on that item.</li> + <li>Browse web sites that let you look at lots of existing color palettes and images to find inspiration.</li> +</ul> + +<p>When trying to decide upon a base color, you may find that browser extensions that let you select colors from web content can be particularly handy. Some of these are even specifically designed to help with this sort of work. For example, the web site <a href="http://www.colorzilla.com/">ColorZilla</a> offers an extension (<a href="http://www.colorzilla.com/chrome">Chrome</a> / <a href="http://www.colorzilla.com/firefox">Firefox</a>) that offers an eyedropper tool for picking colors from the web. It can also take averages of the colors of pixels in various sized areas or even a selected area of the page.</p> + +<div class="note"> +<p>The advantage to averaging colors can be that often what looks like a solid color is actually a surprisingly varied number of related colors all used in concert, blending to create a desired effect. Picking just one of these pixels can result in getting a color that on its own looks very out of place.</p> +</div> + +<h4 id="Fleshing_out_the_palette">Fleshing out the palette</h4> + +<p>Once you have decided on your base color, there are plenty of online tools that can help you build out a palette of appropriate colors to use along with your base color by applying color theory to your base color to determine appropriate added colors. Many of these tools also support viewing the colors filtered so you can see what they would look like to people with various forms of color blindness. See {{anch("Color and accessibility")}} for a brief explanation of why this matters.</p> + +<p>A few examples (all free to use as of the time this list was last revised):</p> + +<ul> + <li><a href="/en-US/docs/Web/CSS/CSS_Colors/Color_picker_tool">MDN's color picker tool</a></li> + <li><a href="http://paletton.com">Paletton</a></li> + <li><a href="https://color.adobe.com/create/color-wheel">Adobe Color CC online color wheel</a></li> +</ul> + +<p>When designing your palette, be sure to keep in mind that in addition to the colors these tools typically generate, you'll probably also need to add some core neutral colors such as white (or nearly white), black (or nearly black), and some number of shades of gray.</p> + +<div class="note"> +<p>Usually, you are far better off using the smallest number of colors possible. By using color to accentuate rather than adding color to everything on the page, you keep your content easy to read and the colors you do use have far more impact.</p> +</div> + +<h3 id="Color_theory_resources">Color theory resources</h3> + +<p>A full review of color theory is beyond the scope of this article, but there are plenty of articles about color theory available, as well as courses you can find at nearby schools and universities. A couple of useful resources about color theory:</p> + +<dl> + <dt><a href="https://www.khanacademy.org/partner-content/pixar/color">Color Science</a> (<a href="https://www.khanacademy.org/">Khan Academy</a> in association with <a href="https://www.pixar.com/">Pixar</a>)</dt> + <dd>An online course which introduces concepts such as what color is, how it's percieved, and how to use colors to express ideas. Presented by Pixar artists and designers.</dd> + <dt>{{interwiki("wikipedia", "Color theory")}} on Wikipedia</dt> + <dd>Wikipedia's entry on color theory, which has a lot of great information from a technical perspective. It's not really a resource for helping you with the color sleection process, but is still full of useful information.</dd> +</dl> + +<h3 id="Color_and_accessibility">Color and accessibility</h3> + +<p>There are several ways color can be an {{Glossary("accessibility")}} problem. Improper or careless use of color can result in a web site or app that a percentage of your target audience may not be able to use adequately, resulting in lost traffic, lost business, and possibly even a public relations problem. So it's important to consider your use of color carefully.</p> + +<p>You should do at least basic research into {{interwiki("wikipedia", "color blindness")}}. There are several kinds; the most common is red-green color blindness, which causes people to be unable to differentiate between the colors red and green. There are others, too, ranging from inabilities to tell the difference between certain colors to total inability to see color at all.</p> + +<div class="note"> +<p>The most important rule: never use color as the only way to know something. If, for example, you indicate success or failure of an operation by changing the color of a shape from white to green for success and red for failure, users with red-green color-blindness won't be able to use your site properly. Instead, perhaps use both text and color together, so that everyone can understand what's happening.</p> +</div> + +<p>For more information about color blindness, see the following articles:</p> + +<ul> + <li><a href="https://medlineplus.gov/colorblindness.html">Medline Plus: Color Blindness</a> (United States National Institute of Health)</li> + <li><a href="https://www.aao.org/eye-health/diseases/what-is-color-blindness">American Academy of Ophthamology: What Is Color Blindness?</a></li> + <li><a href="https://www.usability.gov/get-involved/blog/2010/02/color-blindness.html">Color Blindness & Web Design</a> (Usability.gov: United States Department of Health and Human Services)</li> +</ul> + +<h3 id="Palette_design_example">Palette design example</h3> + +<p>Let's consider a quick example of selecting an appropriate color palette for a site. Imagine that you're building a web site for a new game that takes place on the planet Mars. So let's do a <a href="https://www.google.com/search?q=Mars&tbm=isch">Google search for photos of Mars</a>. Lots of good examples of Martian coloration there. We carefully avoid the mockups and the photos from movies. And we decide to use a photo taken by one of the Mars landers humanity has parked on the surface over the last few decades, since the game takes place on the planet's surface. We use a color picker tool to select a sample of the color we choose.</p> + +<p>Using an eyedropper tool, we identify a color we like and determine that the color in question is <code>#D79C7A</code>, which is an appropriate rusty orange-red color that's so stereotypical of the Martian surface.</p> + +<p>Having selected our base color, we need to build out our palette. We decide to use <a href="http://www.paletton.com/">Paletton</a> to come up with the other colors we need. Upon opening Paletton, we see:</p> + +<p><img alt="Right after loading Paletton." src="https://mdn.mozillademos.org/files/15451/paletton1.png" style="height: 361px; width: 600px;"></p> + +<p>Next, we enter our color's hex code (<code>D79C7A</code>) into the "Base RGB" box at the bottom-left corner of the tool:</p> + +<p><img alt="After entering base color" src="https://mdn.mozillademos.org/files/15453/paletton2.png" style="height: 361px; width: 600px;"></p> + +<p>We now see a monochromatic palette based on the color we picked from the Mars photo. If you need a lot of related colors for some reason, those are likely to be good ones. But what we really want is an accent color. Something that will pop along side the base color. To find that, we click the "add complementary" toggle underneath the menu that lets you select the palette type (currently "Monochromatic"). Paletton computes an appropriate accent color; clicking on the accent color down in the bottom-right corner tells us that this color is <code>#508D7C</code>.</p> + +<p><img alt="Now with complementary colors included." src="https://mdn.mozillademos.org/files/15455/paletton3.png" style="height: 361px; width: 600px;"></p> + +<p>If you're unhappy with the color that's proposed to you, you can change the color scheme, to see if you find something you like better. For example, if we don't like the proposed greenish-blue color, we can click the Triad color scheme icon, which presents us with the following:</p> + +<p><img alt="Triad color scheme selected" src="https://mdn.mozillademos.org/files/15457/paletton4.png" style="height: 361px; width: 600px;"></p> + +<p>That greyish blue in the top-right looks pretty good. Clicking on it, we find that it's <code>#556E8D</code>. That would be used as the accent color, to be used sparingly to make things stand out, such as in headlines or in the highlighting of tabs or other indicators on the site:</p> + +<p><img alt="Triad color scheme selected" src="https://mdn.mozillademos.org/files/15459/paletton-color-detail.png" style="height: 370px; width: 526px;"></p> + +<p>Now we have our base color and our accent. On top of that, we have a few complementary shades of each, just in case we need them for gradients and the like. The colors can then be exported in a number of formats so you can make use of them.</p> + +<p>Once you have these colors, you will probably still need to select appropriate neutral colors. Common design practice is to try to find the sweet spot where there's just enough contrast that the text is crisp and readable but not enough contrast to become harsh for the eyes. It's easy to go too far in one way or another so be sure to get feedback on your colors once you've selected them and have examples of them in use available. If the contrast is too low, your text will tend to be washed out by the background, leaving it unreadable, but if your contrast is too high, the user may find your site garish and unpleasant to look at.</p> + +<h3 id="Color_backgrounds_contrast_and_printing">Color, backgrounds, contrast, and printing</h3> + +<p>What looks good on screen may look very different on paper. In addition, ink can be expensive, and if a user is printing your page, they don't necessarily need all the backgrounds and such using up their precious ink when all that matters is the text itself. Most browsers, by default, remove background images when printing documents.</p> + +<p>If your background colors and images have been selected carefully and/or are crucial to the usefulness of the content, you can use the CSS {{cssxref("color-adjust")}} property to tell the browser that it should not make adjustments to the appearance of content.</p> + +<p>The default value of <code>color-adjust</code>, <code>economy</code>, indicates that the browser is allowed to make appearance changes as it deems necessary in order to try to optimize the legibility and/or print economy of the content, given the type of output device the document is being drawn onto.</p> + +<p>You can set <code>color-adjust</code> to <code>exact</code> to tell the browser that the element or elements on which you use it have been designed specifically to best work with the colors and images left as they are. With this set, the browser won't tamper with the appearance of the element, and will draw it as indicated by your CSS.</p> + +<div class="note"> +<p><strong>Note:</strong> There is no guarantee, though, that <code>color-adjust: exact</code> will result in your CSS being used exactly as given. If the browser provides user preferences to change the output (such as a "don't print backgrounds" checkbox in a print dialog box), that overrides the value of <code>color-adjust</code>.</p> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Drawing_graphics">Drawing graphics</a></li> + <li><a href="/en-US/docs/Web/Guide/Graphics">Graphics on the web</a></li> + <li><a href="/en-US/docs/Tools/DevToolsColors">MDN's color picker tool</a></li> +</ul> diff --git a/files/fa/web/http/index.html b/files/fa/web/http/index.html new file mode 100644 index 0000000000..934464e4d7 --- /dev/null +++ b/files/fa/web/http/index.html @@ -0,0 +1,84 @@ +--- +title: HTTP +slug: Web/HTTP +translation_of: Web/HTTP +--- +<p>Mohamad</p> + +<div class="hidden"> +<h5 id="en-USdocsHTTPSidebar"><a href="/en-US/docs/">/en-US/docs/</a>{{HTTPSidebar}}</h5> +</div> + +<p class="summary"><strong><dfn>Hypertext Transfer Protocol (HTTP)</dfn></strong> is an <a href="https://en.wikipedia.org/wiki/Application_Layer">application-layer</a> protocol for transmitting hypermedia documents, such as HTML. It was designed for communication between web browsers and web servers, but it can also be used for other purposes. HTTP follows a classical <a href="https://en.wikipedia.org/wiki/Client%E2%80%93server_model">client-server model</a>, with a client opening a connection to make a request, then waiting until it receives a response. HTTP is a <a href="https://en.wikipedia.org/wiki/Stateless_protocol">stateless protocol</a>, meaning that the server does not keep any data (state) between two requests. Though often based on a TCP/IP layer, it can be used on any reliable <a href="http://en.wikipedia.org/wiki/Transport_Layer">transport layer</a>; that is, a protocol that doesn't lose messages silently, such as UDP.</p> + +<div class="column-container"> +<div class="column-half"> +<h2 id="Tutorials">Tutorials</h2> + +<p>Learn how to use HTTP with guides and tutorials.</p> + +<dl> + <dt><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview">Overview of HTTP</a></dt> + <dd>The basic features of the client-server protocol: what it can do and its intended uses.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching">HTTP Cache</a></dt> + <dd>Caching is very important for fast Web sites. This article describes different methods of caching and how to use HTTP Headers to control them.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies">HTTP Cookies</a></dt> + <dd>How cookies work is defined by <a href="http://tools.ietf.org/html/rfc6265">RFC 6265</a>. When serving an HTTP request, a server can send a <code>Set-Cookie</code> HTTP header with the response. The client then returns the cookie's value with every request to the same server in the form of a <code>Cookie</code> request header. The cookie can also be set to expire on a certain date, or restricted to a specific domain and path.</dd> + <dt><a href="/en-US/docs/Web/HTTP/CORS">Cross-Origin Resource Sharing (CORS)</a></dt> + <dd><strong>Cross-site HTTP requests</strong> are HTTP requests for resources from a <strong>different domain</strong> than the domain of the resource making the request. For instance, an HTML page from Domain A (<code>http://domaina.example/</code>) makes a request for an image on Domain B (<code>http://domainb.foo/image.jpg</code>) via the <code>img</code> element. Web pages today very commonly load cross-site resources, including CSS stylesheets, images, scripts, and other resources. CORS allows web developers to control how their site reacts to cross-site requests.</dd> +</dl> + +<dl> + <dt><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Evolution_of_HTTP">Evolution of HTTP</a></dt> + <dd>A brief description of the changes between the early versions of HTTP, to the modern HTTP/2 and beyond.</dd> + <dt><a href="https://wiki.mozilla.org/Security/Guidelines/Web_Security">Mozilla web security guidelines</a></dt> + <dd>A collection of tips to help operational teams with creating secure web applications.</dd> +</dl> + +<dl> + <dt><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages">HTTP Messages</a></dt> + <dd>Describes the type and structure of the different kind of messages of HTTP/1.x and HTTP/2.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Session">A typical HTTP session</a></dt> + <dd>Shows and explains the flow of a usual HTTP session.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Connection_management_in_HTTP_1.x">Connection management in HTTP/1.x</a></dt> + <dd>Describes the three connection management models available in HTTP/1.x, their strengths, and their weaknesses.</dd> +</dl> +</div> + +<div class="column-half"> +<h2 id="Reference">Reference</h2> + +<p>Browse through detailed HTTP reference documentation.</p> + +<dl> + <dt><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers">HTTP Headers</a></dt> + <dd>HTTP message headers are used to describe a resource, or the behavior of the server or the client. Custom proprietary headers can be added using the <code>X-</code> prefix; others in an <a href="http://www.iana.org/assignments/message-headers/perm-headers.html">IANA registry</a>, whose original content was defined in <a href="http://tools.ietf.org/html/rfc4229">RFC 4229</a>. IANA also maintains a <a href="http://www.iana.org/assignments/message-headers/prov-headers.html">registry of proposed new HTTP message headers</a>.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods">HTTP Request Methods</a></dt> + <dd>The different operations that can be done with HTTP: {{HTTPMethod("GET")}}, {{HTTPMethod("POST")}}, and also less common requests like {{HTTPMethod("OPTIONS")}}, {{HTTPMethod("DELETE")}}, or {{HTTPMethod("TRACE")}}.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Response_codes">HTTP Status Response Codes</a></dt> + <dd>HTTP response codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes: informational responses, successful responses, redirections, client errors, and servers errors.</dd> +</dl> + +<dl> + <dt><a href="/en-US/docs/Web/HTTP/Headers/Content-Security-Policy">CSP directives</a></dt> + <dd>The {{HTTPHeader("Content-Security-Policy")}} response header fields allows web site administrators to control resources the user agent is allowed to load for a given page. With a few exceptions, policies mostly involve specifying server origins and script endpoints.</dd> +</dl> + +<h2 id="Tools_resources">Tools & resources</h2> + +<p>Helpful tools and resources for understanding and debugging HTTP.</p> + +<dl> + <dt><a href="/en-US/docs/Tools">Firefox Developer Tools</a></dt> + <dd><a href="/en-US/docs/Tools/Network_Monitor">Network monitor</a></dd> + <dt><a href="https://observatory.mozilla.org/">Mozilla Observatory</a></dt> + <dd> + <p>A project designed to help developers, system administrators, and security professionals configure their sites safely and securely.</p> + </dd> + <dt><a class="external" href="https://redbot.org/">RedBot</a></dt> + <dd>Tools to check your cache-related headers</dd> + <dt><a href="http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/">How Browsers Work</a></dt> + <dd>A very comprehensive article on browser internals and request flow through HTTP protocol. A MUST-READ for any web developer.</dd> +</dl> +</div> +</div> diff --git a/files/fa/web/http/status/index.html b/files/fa/web/http/status/index.html new file mode 100644 index 0000000000..b39296ce25 --- /dev/null +++ b/files/fa/web/http/status/index.html @@ -0,0 +1,202 @@ +--- +title: HTTP response status codes +slug: Web/HTTP/Status +tags: + - HTTP + - Landing + - NeedsTranslation + - Overview + - Reference + - Status code + - TopicStub + - Web +translation_of: Web/HTTP/Status +--- +<div>{{HTTPSidebar}}</div> + +<p class="summary"><span class="seoSummary">HTTP response status codes indicate whether a specific <a href="/en-US/docs/Web/HTTP">HTTP</a> request has been successfully completed. Responses are grouped in five classes: </span></p> + +<ol> + <li><span class="seoSummary">Informational responses (<code>100</code>–<code>199</code>),</span></li> + <li><span class="seoSummary">Successful responses (<code>200</code>–<code>299</code>),</span></li> + <li><span class="seoSummary">Redirects (<code>300</code>–<code>399</code>),</span></li> + <li><span class="seoSummary">Client errors (<code>400</code>–<code>499</code>),</span></li> + <li><span class="seoSummary">and Server errors (<code>500</code>–<code>599</code>).</span></li> +</ol> + +<p>The below status codes are defined by <a href="https://tools.ietf.org/html/rfc2616#section-10">section 10 of RFC 2616</a>. You can find an updated specification in <a href="https://tools.ietf.org/html/rfc7231#section-6.5.1">RFC 7231</a>.</p> + +<div class="blockIndicator note"> +<p>If you receive a response that is not in this list, it is a non-standard response, possibly custom to the server's software.</p> +</div> + +<h2 id="Information_responses">Information responses</h2> + +<dl> + <dt>{{HTTPStatus(100, "100 Continue")}}</dt> + <dd>This interim response indicates that everything so far is OK and that the client should continue the request, or ignore the response if the request is already finished.</dd> + <dt>{{HTTPStatus(101, "101 Switching Protocol")}}</dt> + <dd>This code is sent in response to an {{HTTPHeader("Upgrade")}} request header from the client, and indicates the protocol the server is switching to.</dd> + <dt>{{HTTPStatus(102, "102 Processing")}} ({{Glossary("WebDAV")}})</dt> + <dd>This code indicates that the server has received and is processing the request, but no response is available yet.</dd> + <dt>{{HTTPStatus(103, "103 Early Hints")}}</dt> + <dd>This status code is primarily intended to be used with the {{HTTPHeader("Link")}} header, letting the user agent start <a href="/en-US/docs/Web/HTML/Preloading_content">preloading</a> resources while the server prepares a response.</dd> +</dl> + +<h2 id="Successful_responses">Successful responses</h2> + +<dl> + <dt>{{HTTPStatus(200, "200 OK")}}</dt> + <dd>The request has succeeded. The meaning of the success depends on the HTTP method: + <ul> + <li><code>GET</code>: The resource has been fetched and is transmitted in the message body.</li> + <li><code>HEAD</code>: The entity headers are in the message body.</li> + <li><code>PUT</code> or <code>POST</code>: The resource describing the result of the action is transmitted in the message body.</li> + <li><code>TRACE</code>: The message body contains the request message as received by the server</li> + </ul> + </dd> + <dt>{{HTTPStatus(201, "201 Created")}}</dt> + <dd>The request has succeeded and a new resource has been created as a result. This is typically the response sent after <code>POST</code> requests, or some <code>PUT</code> requests.</dd> + <dt>{{HTTPStatus(202, "202 Accepted")}}</dt> + <dd>The request has been received but not yet acted upon. It is noncommittal, since there is no way in HTTP to later send an asynchronous response indicating the outcome of the request. It is intended for cases where another process or server handles the request, or for batch processing.</dd> + <dt>{{HTTPStatus(203, "203 Non-Authoritative Information")}}</dt> + <dd>This response code means the returned meta-information is not exactly the same as is available from the origin server, but is collected from a local or a third-party copy. This is mostly used for mirrors or backups of another resource. Except for that specific case, the "200 OK" response is preferred to this status.</dd> + <dt>{{HTTPStatus(204, "204 No Content")}}</dt> + <dd>There is no content to send for this request, but the headers may be useful. The user-agent may update its cached headers for this resource with the new ones.</dd> + <dt>{{HTTPStatus(205, "205 Reset Content")}}</dt> + <dd>Tells the user-agent to reset the document which sent this request.</dd> + <dt>{{HTTPStatus(206, "206 Partial Content")}}</dt> + <dd>This response code is used when the {{HTTPHeader("Range")}} header is sent from the client to request only part of a resource.</dd> + <dt>{{HTTPStatus(207, "207 Multi-Status")}} ({{Glossary("WebDAV")}})</dt> + <dd>Conveys information about multiple resources, for situations where multiple status codes might be appropriate.</dd> + <dt>{{HTTPStatus(208, "208 Already Reported")}} ({{Glossary("WebDAV")}})</dt> + <dd>Used inside a <code><dav:propstat></code> response element to avoid repeatedly enumerating the internal members of multiple bindings to the same collection.</dd> + <dt>{{HTTPStatus(226, "226 IM Used")}} (<a href="https://tools.ietf.org/html/rfc3229">HTTP Delta encoding</a>)</dt> + <dd>The server has fulfilled a <code>GET</code> request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance.</dd> +</dl> + +<h2 id="Redirection_messages">Redirection messages</h2> + +<dl> + <dt>{{HTTPStatus(300, "300 Multiple Choice")}}</dt> + <dd>The request has more than one possible response. The user-agent or user should choose one of them. (There is no standardized way of choosing one of the responses, but HTML links to the possibilities are recommended so the user can pick.)</dd> + <dt>{{HTTPStatus(301, "301 Moved Permanently")}}</dt> + <dd>The URL of the requested resource has been changed permanently. The new URL is given in the response.</dd> + <dt>{{HTTPStatus(302, "302 Found")}}</dt> + <dd>This response code means that the URI of requested resource has been changed <em>temporarily</em>. Further changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests.</dd> + <dt>{{HTTPStatus(303, "303 See Other")}}</dt> + <dd>The server sent this response to direct the client to get the requested resource at another URI with a GET request.</dd> + <dt>{{HTTPStatus(304, "304 Not Modified")}}</dt> + <dd>This is used for caching purposes. It tells the client that the response has not been modified, so the client can continue to use the same cached version of the response.</dd> + <dt><code>305 Use Proxy</code> {{deprecated_inline}}</dt> + <dd>Defined in a previous version of the HTTP specification to indicate that a requested response must be accessed by a proxy. It has been deprecated due to security concerns regarding in-band configuration of a proxy.</dd> + <dt><code>306 unused</code></dt> + <dd>This response code is no longer used; it is just reserved. It was used in a previous version of the HTTP/1.1 specification.</dd> + <dt>{{HTTPStatus(307, "307 Temporary Redirect")}}</dt> + <dd>The server sends this response to direct the client to get the requested resource at another URI with same method that was used in the prior request. This has the same semantics as the <code>302 Found</code> HTTP response code, with the exception that the user agent <em>must not</em> change the HTTP method used: If a <code>POST</code> was used in the first request, a <code>POST</code> must be used in the second request.</dd> + <dt>{{HTTPStatus(308, "308 Permanent Redirect")}}</dt> + <dd>This means that the resource is now permanently located at another URI, specified by the <code>Location:</code> HTTP Response header. This has the same semantics as the <code>301 Moved Permanently</code> HTTP response code, with the exception that the user agent <em>must not</em> change the HTTP method used: If a <code>POST</code> was used in the first request, a <code>POST</code> must be used in the second request.</dd> +</dl> + +<h2 id="Client_error_responses">Client error responses</h2> + +<dl> + <dt>{{HTTPStatus(400, "400 Bad Request")}}</dt> + <dd>The server could not understand the request due to invalid syntax.</dd> + <dt>{{HTTPStatus(401, "401 Unauthorized")}}</dt> + <dd>Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.</dd> + <dt>{{HTTPStatus(402, "402 Payment Required")}} {{experimental_inline}}</dt> + <dd>This response code is reserved for future use. The initial aim for creating this code was using it for digital payment systems, however this status code is used very rarely and no standard convention exists.</dd> + <dt>{{HTTPStatus(403, "403 Forbidden")}}</dt> + <dd>The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401, the client's identity is known to the server.</dd> + <dt>{{HTTPStatus(404, "404 Not Found")}}</dt> + <dd>The server can not find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 to hide the existence of a resource from an unauthorized client. This response code is probably the most famous one due to its frequent occurrence on the web.</dd> + <dt>{{HTTPStatus(405, "405 Method Not Allowed")}}</dt> + <dd>The request method is known by the server but has been disabled and cannot be used. For example, an API may forbid DELETE-ing a resource. The two mandatory methods, <code>GET</code> and <code>HEAD</code>, must never be disabled and should not return this error code.</dd> + <dt>{{HTTPStatus(406, "406 Not Acceptable")}}</dt> + <dd>This response is sent when the web server, after performing <a href="/en-US/docs/HTTP/Content_negotiation#Server-driven_negotiation">server-driven content negotiation</a>, doesn't find any content that conforms to the criteria given by the user agent.</dd> + <dt>{{HTTPStatus(407, "407 Proxy Authentication Required")}}</dt> + <dd>This is similar to 401 but authentication is needed to be done by a proxy.</dd> + <dt>{{HTTPStatus(408, "408 Request Timeout")}}</dt> + <dd>This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection. This response is used much more since some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also note that some servers merely shut down the connection without sending this message.</dd> + <dt>{{HTTPStatus(409, "409 Conflict")}}</dt> + <dd>This response is sent when a request conflicts with the current state of the server.</dd> + <dt>{{HTTPStatus(410, "410 Gone")}}</dt> + <dd>This response is sent when the requested content has been permanently deleted from server, with no forwarding address. Clients are expected to remove their caches and links to the resource. The HTTP specification intends this status code to be used for "limited-time, promotional services". APIs should not feel compelled to indicate resources that have been deleted with this status code.</dd> + <dt>{{HTTPStatus(411, "411 Length Required")}}</dt> + <dd>Server rejected the request because the <code>Content-Length</code> header field is not defined and the server requires it.</dd> + <dt>{{HTTPStatus(412, "412 Precondition Failed")}}</dt> + <dd>The client has indicated preconditions in its headers which the server does not meet.</dd> + <dt>{{HTTPStatus(413, "413 Payload Too Large")}}</dt> + <dd>Request entity is larger than limits defined by server; the server might close the connection or return an <code>Retry-After</code> header field.</dd> + <dt>{{HTTPStatus(414, "414 URI Too Long")}}</dt> + <dd>The URI requested by the client is longer than the server is willing to interpret.</dd> + <dt>{{HTTPStatus(415, "415 Unsupported Media Type")}}</dt> + <dd>The media format of the requested data is not supported by the server, so the server is rejecting the request.</dd> + <dt>{{HTTPStatus(416, "416 Range Not Satisfiable")}}</dt> + <dd>The range specified by the <code>Range</code> header field in the request can't be fulfilled; it's possible that the range is outside the size of the target URI's data.</dd> + <dt>{{HTTPStatus(417, "417 Expectation Failed")}}</dt> + <dd>This response code means the expectation indicated by the <code>Expect</code> request header field can't be met by the server.</dd> + <dt>{{HTTPStatus(418, "418 I'm a teapot")}}</dt> + <dd>The server refuses the attempt to brew coffee with a teapot.</dd> + <dt>{{HTTPStatus(421, "421 Misdirected Request")}}</dt> + <dd>The request was directed at a server that is not able to produce a response. This can be sent by a server that is not configured to produce responses for the combination of scheme and authority that are included in the request URI.</dd> + <dt>{{HTTPStatus(422, "422 Unprocessable Entity")}} ({{Glossary("WebDAV")}})</dt> + <dd>The request was well-formed but was unable to be followed due to semantic errors.</dd> + <dt>{{HTTPStatus(423, "423 Locked")}} ({{Glossary("WebDAV")}})</dt> + <dd>The resource that is being accessed is locked.</dd> + <dt>{{HTTPStatus(424, "424 Failed Dependency")}} ({{Glossary("WebDAV")}})</dt> + <dd>The request failed due to failure of a previous request.</dd> + <dt>{{HTTPStatus(425, "425 Too Early")}}</dt> + <dd>Indicates that the server is unwilling to risk processing a request that might be replayed.</dd> + <dt>{{HTTPStatus(426, "426 Upgrade Required")}}</dt> + <dd>The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. The server sends an {{HTTPHeader("Upgrade")}} header in a 426 response to indicate the required protocol(s).</dd> + <dt>{{HTTPStatus(428, "428 Precondition Required")}}</dt> + <dd>The origin server requires the request to be conditional. This response is intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict.</dd> + <dt>{{HTTPStatus(429, "429 Too Many Requests")}}</dt> + <dd>The user has sent too many requests in a given amount of time ("rate limiting").</dd> + <dt>{{HTTPStatus(431, "431 Request Header Fields Too Large")}}</dt> + <dd>The server is unwilling to process the request because its header fields are too large. The request may be resubmitted after reducing the size of the request header fields.</dd> + <dt>{{HTTPStatus(451, "451 Unavailable For Legal Reasons")}}</dt> + <dd>The user-agent requested a resource that cannot legally be provided, such as a web page censored by a government.</dd> +</dl> + +<h2 id="Server_error_responses">Server error responses</h2> + +<dl> + <dt>{{HTTPStatus(500, "500 Internal Server Error")}}</dt> + <dd>The server has encountered a situation it doesn't know how to handle.</dd> + <dt>{{HTTPStatus(501, "501 Not Implemented")}}</dt> + <dd>The request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are <code>GET</code> and <code>HEAD</code>.</dd> + <dt>{{HTTPStatus(502, "502 Bad Gateway")}}</dt> + <dd>This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response.</dd> + <dt>{{HTTPStatus(503, "503 Service Unavailable")}}</dt> + <dd>The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded. Note that together with this response, a user-friendly page explaining the problem should be sent. This responses should be used for temporary conditions and the <code>Retry-After:</code> HTTP header should, if possible, contain the estimated time before the recovery of the service. The webmaster must also take care about the caching-related headers that are sent along with this response, as these temporary condition responses should usually not be cached.</dd> + <dt>{{HTTPStatus(504, "504 Gateway Timeout")}}</dt> + <dd>This error response is given when the server is acting as a gateway and cannot get a response in time.</dd> + <dt>{{HTTPStatus(505, "505 HTTP Version Not Supported")}}</dt> + <dd>The HTTP version used in the request is not supported by the server.</dd> + <dt>{{HTTPStatus(506, "506 Variant Also Negotiates")}}</dt> + <dd>The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.</dd> + <dt>{{HTTPStatus(507, "507 Insufficient Storage")}} ({{Glossary("WebDAV")}})</dt> + <dd>The method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request.</dd> + <dt>{{HTTPStatus(508, "508 Loop Detected")}} ({{Glossary("WebDAV")}})</dt> + <dd>The server detected an infinite loop while processing the request.</dd> + <dt>{{HTTPStatus(510, "510 Not Extended")}}</dt> + <dd>Further extensions to the request are required for the server to fulfil it.</dd> + <dt>{{HTTPStatus(511, "511 Network Authentication Required")}}</dt> + <dd>The 511 status code indicates that the client needs to authenticate to gain network access.</dd> +</dl> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("http.status")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="https://en.wikipedia.org/wiki/List_of_HTTP_status_codes">List of HTTP status codes on Wikipedia</a></li> + <li><a href="http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml">IANA official registry of HTTP status codes</a></li> +</ul> diff --git a/files/fa/web/index.html b/files/fa/web/index.html new file mode 100644 index 0000000000..fdf74108ac --- /dev/null +++ b/files/fa/web/index.html @@ -0,0 +1,53 @@ +--- +title: تکنولوژی های وب برای توسعه دهندگان +slug: Web +tags: + - تکنولوژی های وب + - رابط های کاربردی + - رابط های کاربری + - وب +translation_of: Web +--- +<p dir="rtl"><strong>وب باز ، فرصتی باورنکردنی برای بادگیری این تکنولوژی. شما باید یاد بگیرید چگونه از آنها (تکنولوژِی ها) استفاده کنید. در زیر پیوند هایی به اسناد تکنولوژی های ما وجود دارد.</strong></p> + +<div class="row topicpage-table" dir="rtl"> +<div class="section"> +<h2 class="Documentation" id="Docs_for_add-on_developers" name="Docs_for_add-on_developers">مستندات برای توسعه دهندگان</h2> + +<dl> + <dt><a href="/en-US/docs/Web/Reference" title="/en-US/docs/Web/Reference">منابع توسعه دهنده وب</a></dt> + <dd><strong>یک لیست از تمام منابع تکنولوژی های وب از جمله HTML , CSS و غیره.</strong></dd> + <dt><a href="/en-US/docs/Web/Guide" title="https://addons.mozilla.org/en-US/developers/docs/sdk/latest/">راهنمای توسعه دهنده</a></dt> + <dd><strong>راهنمای توسعه دهنده وب محیطی را فراهم میکند که شما بتوانید چگونگی استفاده از تمامی تکنولوژی های وب را فرابگیرید.</strong></dd> + <dt><a href="/en-US/docs/Web/Tutorials" title="/en-US/docs/Web/Tutorials">خودآموز هایی برای توسعه دهندگان وب</a></dt> + <dd><strong>یک لیست از تمامی خودآموزها برای یادگیری قدم به قدم رابط های کاربری (APIs) وب ، اکنولوژی ها و غیره.</strong></dd> + <dt><a href="/en-US/docs/Web/Apps" title="/en-US/docs/Web/Apps">توسعه برنامه های وب</a></dt> + <dd><strong>مستندات برای توسعه دهندگان نرم افزار های تحت وب ، نرم افزارهای تحت وب را یک بار و برای همیشه بنویسید و در همه جا استفاده کنید، از جمله موبایل ، رایانه رومیزی ، سیستم عامل فایرفاکس و غیره...</strong></dd> +</dl> + +<p><span class="alllinks"><a href="/en-US/docs/tag/Web">نمایش همه . . .</a></span></p> +</div> + +<div class="section"> +<h2 class="Documentation" id="Docs_for_add-on_developers" name="Docs_for_add-on_developers">منابع تکنولوژی های وب</h2> + +<dl> + <dt><a href="/en-US/docs/Web/API" title="/en-US/docs/Web/API">رابط های کاربردی (APIs) وب</a></dt> + <dd><strong>منابع کامل از هر یک از رابط های کاربردی و کاربری وب شامل DOM و تمام رابط های کاربردی و کاربری که شما میتوانید از آنها در نرم افزار های تحت وب خود استفاده کنید.</strong></dd> + <dt><a href="/en-US/docs/Web/HTML" title="/en-US/docs/Web/HTML">HTML</a></dt> + <dd><strong>زبان نشانه گذاری ابر متن <span id="result_box" lang="fa"><span class="hps">زبان مورد استفاده</span> <span class="hps">برای توصیف</span> <span class="hps">و تعریف</span> <span class="hps">محتوای</span> <span class="hps">یک صفحه وب</span> <span class="hps">است</span><span>.</span></span></strong></dd> + <dt><a href="/en-US/docs/Web/CSS" title="/en-US/docs/Web/CSS">CSS</a></dt> + <dd><strong>شیوه نامه های آبشاری (Cascading Style Sheets) برای توصیف ظاهر محتوای وب استفاده میشوند.</strong></dd> + <dt><a href="/en-US/docs/Web/SVG" title="/en-US/docs/Web/SVG">SVG</a></dt> + <dd><strong>گرافیک برداری مقیاس پذیر (Scalable Vector Graphics) به شما اجازه میدهد بجای استفاده از تصاویر با رسم بردارهایی هموار شکل مورد نظر خود را رسم و توصیف کنید.</strong></dd> + <dt><a href="/en-US/docs/Web/MathML" title="/en-US/docs/Web/MathML">MathML</a></dt> + <dd><strong>زبان نشانه گذاری ریاضی (Mathematical Markup Language) به شما امکان نمایش معادلات ساده و پیچیده ی ریاضی را میدهد.</strong></dd> +</dl> +</div> +</div> + +<h3 dir="rtl" id="موقت">موقت</h3> + +<p dir="rtl"><strong>مواردی که در حال حاضر سازمان در آنها فعالیت دارد.</strong></p> + +<p dir="rtl">{{ListSubpages}}</p> diff --git a/files/fa/web/javascript/a_re-introduction_to_javascript/index.html b/files/fa/web/javascript/a_re-introduction_to_javascript/index.html new file mode 100644 index 0000000000..4811a5e430 --- /dev/null +++ b/files/fa/web/javascript/a_re-introduction_to_javascript/index.html @@ -0,0 +1,951 @@ +--- +title: A re-introduction to JavaScript (JS tutorial) +slug: Web/JavaScript/A_re-introduction_to_JavaScript +translation_of: Web/JavaScript/A_re-introduction_to_JavaScript +--- +<div>{{jsSidebar}}</div> + +<p>چرا دوباره معرفی شود؟ زیرا جاوااسکریپت از لحاظ ایجاد سوتفاهم در جهان مشهور است. این اغلب به عنوان یک اسباب بازی مورد تمسخر قرار می گیرد ، اما در زیر لایه ساده فریبنده آن ، ویژگی های قدرتمند زبان در انتظار است. جاوا اسکریپت اکنون توسط تعداد باورنکردنی از برنامه های با مشخصات بالا استفاده می شود ، نشان می دهد که دانش عمیق تر از این فن آوری مهارت مهمی برای هر توسعه دهنده وب یا تلفن همراه است.</p> + +<p>It's useful to start with an overview of the language's history. JavaScript was created in 1995 by Brendan Eich while he was an engineer at Netscape. JavaScript was first released with Netscape 2 early in 1996. It was originally going to be called LiveScript, but it was renamed in an ill-fated marketing decision that attempted to capitalize on the popularity of Sun Microsystem's Java language — despite the two having very little in common. This has been a source of confusion ever since.</p> + +<p>Several months later, Microsoft released JScript with Internet Explorer 3. It was a mostly-compatible JavaScript work-alike. Several months after that, Netscape submitted JavaScript to <a class="external" href="http://www.ecma-international.org/">Ecma International</a>, a European standards organization, which resulted in the first edition of the <a href="/en-US/docs/Glossary/ECMAScript">ECMAScript</a> standard that year. The standard received a significant update as <a class="external" href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript edition 3</a> in 1999, and it has stayed pretty much stable ever since. The fourth edition was abandoned, due to political differences concerning language complexity. Many parts of the fourth edition formed the basis for ECMAScript edition 5, published in December of 2009, and for the 6th major edition of the standard, published in June of 2015.</p> + +<div class="note"> +<p>Because it is more familiar, we will refer to ECMAScript as "JavaScript" from this point on.</p> +</div> + +<p>Unlike most programming languages, the JavaScript language has no concept of input or output. It is designed to run as a scripting language in a host environment, and it is up to the host environment to provide mechanisms for communicating with the outside world. The most common host environment is the browser, but JavaScript interpreters can also be found in a huge list of other places, including Adobe Acrobat, Adobe Photoshop, SVG images, Yahoo's Widget engine, server-side environments such as <a href="http://nodejs.org/">Node.js</a>, NoSQL databases like the open source <a href="http://couchdb.apache.org/">Apache CouchDB</a>, embedded computers, complete desktop environments like <a href="http://www.gnome.org/">GNOME</a> (one of the most popular GUIs for GNU/Linux operating systems), and others.</p> + +<h2 id="Overview">Overview</h2> + +<p>JavaScript is a multi-paradigm, dynamic language with types and operators, standard built-in objects, and methods. Its syntax is based on the Java and C languages — many structures from those languages apply to JavaScript as well. JavaScript supports object-oriented programming with object prototypes, instead of classes (see more about <a href="/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain" title="prototypical inheritance">prototypical inheritance</a> and ES2015 <a href="/en-US/docs/Web/JavaScript/Reference/Classes">classes</a>). JavaScript also supports functional programming — because they are objects, functions may be stored in variables and passed around like any other object.</p> + +<p>Let's start off by looking at the building blocks of any language: the types. JavaScript programs manipulate values, and those values all belong to a type. JavaScript's types are:</p> + +<ul> + <li>{{jsxref("Number")}}</li> + <li>{{jsxref("String")}}</li> + <li>{{jsxref("Boolean")}}</li> + <li>{{jsxref("Function")}}</li> + <li>{{jsxref("Object")}}</li> + <li>{{jsxref("Symbol")}} (new in ES2015)</li> +</ul> + +<p>... oh, and {{jsxref("undefined")}} and {{jsxref("null")}}, which are ... slightly odd. And {{jsxref("Array")}}, which is a special kind of object. And {{jsxref("Date")}} and {{jsxref("RegExp")}}, which are objects that you get for free. And to be technically accurate, functions are just a special type of object. So the type diagram looks more like this:</p> + +<ul> + <li>{{jsxref("Number")}}</li> + <li>{{jsxref("String")}}</li> + <li>{{jsxref("Boolean")}}</li> + <li>{{jsxref("Symbol")}} (new in ES2015)</li> + <li>{{jsxref("Object")}} + <ul> + <li>{{jsxref("Function")}}</li> + <li>{{jsxref("Array")}}</li> + <li>{{jsxref("Date")}}</li> + <li>{{jsxref("RegExp")}}</li> + </ul> + </li> + <li>{{jsxref("null")}}</li> + <li>{{jsxref("undefined")}}</li> +</ul> + +<p>And there are some built-in {{jsxref("Error")}} types as well. Things are a lot easier if we stick with the first diagram, however, so we'll discuss the types listed there for now.</p> + +<h2 id="Numbers">Numbers</h2> + +<p>Numbers in JavaScript are "double-precision 64-bit format IEEE 754 values", according to the spec — There's <strong><em>no such thing as an integer</em></strong> in JavaScript (except {{jsxref("BigInt")}}), so you have to be a little careful. See this example:</p> + +<pre class="syntaxbox notranslate">console.log(3 / 2); // 1.5, <em>not</em> 1 +console.log(Math.floor(3 / 2)); // 1</pre> + +<p>So an <em>apparent integer</em> is in fact <em>implicitly a float</em>.</p> + +<p>Also, watch out for stuff like:</p> + +<pre class="brush: js notranslate">0.1 + 0.2 == 0.30000000000000004; +</pre> + +<p>In practice, integer values are treated as 32-bit ints, and some implementations even store it that way until they are asked to perform an instruction that's valid on a Number but not on a 32-bit integer. This can be important for bit-wise operations.</p> + +<p>The standard <a href="/en-US/docs/Web/JavaScript/Reference/Operators#Arithmetic_operators">arithmetic operators</a> are supported, including addition, subtraction, modulus (or remainder) arithmetic, and so forth. There's also a built-in object that we did not mention earlier called {{jsxref("Math")}} that provides advanced mathematical functions and constants:</p> + +<pre class="brush: js notranslate">Math.sin(3.5); +var circumference = 2 * Math.PI * r; +</pre> + +<p>You can convert a string to an integer using the built-in {{jsxref("Global_Objects/parseInt", "parseInt()")}} function. This takes the base for the conversion as an optional second argument, which you should always provide:</p> + +<pre class="brush: js notranslate">parseInt('123', 10); // 123 +parseInt('010', 10); // 10 +</pre> + +<p>In older browsers, strings beginning with a "0" are assumed to be in octal (radix 8), but this hasn't been the case since 2013 or so. Unless you're certain of your string format, you can get surprising results on those older browsers:</p> + +<pre class="brush: js notranslate">parseInt('010'); // 8 +parseInt('0x10'); // 16 +</pre> + +<p>Here, we see the {{jsxref("Global_Objects/parseInt", "parseInt()")}} function treat the first string as octal due to the leading 0, and the second string as hexadecimal due to the leading "0x". The <em>hexadecimal notation is still in place</em>; only octal has been removed.</p> + +<p>If you want to convert a binary number to an integer, just change the base:</p> + +<pre class="brush: js notranslate">parseInt('11', 2); // 3 +</pre> + +<p>Similarly, you can parse floating point numbers using the built-in {{jsxref("Global_Objects/parseFloat", "parseFloat()")}} function. Unlike its {{jsxref("Global_Objects/parseInt", "parseInt()")}} cousin, <code>parseFloat()</code> always uses base 10.</p> + +<p>You can also use the unary <code>+</code> operator to convert values to numbers:</p> + +<pre class="brush: js notranslate">+ '42'; // 42 ++ '010'; // 10 ++ '0x10'; // 16 +</pre> + +<p>A special value called {{jsxref("NaN")}} (short for "Not a Number") is returned if the string is non-numeric:</p> + +<pre class="brush: js notranslate">parseInt('hello', 10); // NaN +</pre> + +<p><code>NaN</code> is toxic: if you provide it as an operand to any mathematical operation, the result will also be <code>NaN</code>:</p> + +<pre class="brush: js notranslate">NaN + 5; // NaN +</pre> + +<p>You can test for <code>NaN</code> using the built-in {{jsxref("Global_Objects/isNaN", "isNaN()")}} function:</p> + +<pre class="brush: js notranslate">isNaN(NaN); // true +</pre> + +<p>JavaScript also has the special values {{jsxref("Infinity")}} and <code>-Infinity</code>:</p> + +<pre class="brush: js notranslate"> 1 / 0; // Infinity +-1 / 0; // -Infinity +</pre> + +<p>You can test for <code>Infinity</code>, <code>-Infinity</code> and <code>NaN</code> values using the built-in {{jsxref("Global_Objects/isFinite", "isFinite()")}} function:</p> + +<pre class="brush: js notranslate">isFinite(1 / 0); // false +isFinite(-Infinity); // false +isFinite(NaN); // false +</pre> + +<div class="note">The {{jsxref("Global_Objects/parseInt", "parseInt()")}} and {{jsxref("Global_Objects/parseFloat", "parseFloat()")}} functions parse a string until they reach a character that isn't valid for the specified number format, then return the number parsed up to that point. However the "+" operator simply converts the string to <code>NaN</code> if there is an invalid character contained within it. Just try parsing the string "10.2abc" with each method by yourself in the console and you'll understand the differences better.</div> + +<h2 id="Strings">Strings</h2> + +<p>Strings in JavaScript are sequences of <a href="/en-US/docs/Web/JavaScript/Guide/Values,_variables,_and_literals#Unicode">Unicode characters</a>. This should be welcome news to anyone who has had to deal with internationalization. More accurately, they are sequences of UTF-16 code units; each code unit is represented by a 16-bit number. Each Unicode character is represented by either 1 or 2 code units.</p> + +<p>If you want to represent a single character, you just use a string consisting of that single character.</p> + +<p>To find the length of a string (in code units), access its <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length">length</a></code> property:</p> + +<pre class="brush: js notranslate">'hello'.length; // 5 +</pre> + +<p>There's our first brush with JavaScript objects! Did we mention that you can use strings like {{jsxref("Object", "objects", "", 1)}} too? They have {{jsxref("String", "methods", "#Methods", 1)}} as well that allow you to manipulate the string and access information about the string:</p> + +<pre class="brush: js notranslate">'hello'.charAt(0); // "h" +'hello, world'.replace('world', 'mars'); // "hello, mars" +'hello'.toUpperCase(); // "HELLO" +</pre> + +<h2 id="Other_types">Other types</h2> + +<p>JavaScript distinguishes between {{jsxref("null")}}, which is a value that indicates a deliberate non-value (and is only accessible through the <code>null</code> keyword), and {{jsxref("undefined")}}, which is a value of type <code>undefined</code> that indicates an uninitialized variable — that is, a value hasn't even been assigned yet. We'll talk about variables later, but in JavaScript it is possible to declare a variable without assigning a value to it. If you do this, the variable's type is <code>undefined</code>. <code>undefined</code> is actually a constant.</p> + +<p>JavaScript has a boolean type, with possible values <code>true</code> and <code>false</code> (both of which are keywords.) Any value can be converted to a boolean according to the following rules:</p> + +<ol> + <li><code>false</code>, <code>0</code>, empty strings (<code>""</code>), <code>NaN</code>, <code>null</code>, and <code>undefined</code> all become <code>false.</code></li> + <li>All other values become <code>true.</code></li> +</ol> + +<p>You can perform this conversion explicitly using the <code>Boolean()</code> function:</p> + +<pre class="brush: js notranslate">Boolean(''); // false +Boolean(234); // true +</pre> + +<p>However, this is rarely necessary, as JavaScript will silently perform this conversion when it expects a boolean, such as in an <code>if</code> statement (see below). For this reason, we sometimes speak simply of "true values" and "false values," meaning values that become <code>true</code> and <code>false</code>, respectively, when converted to booleans. Alternatively, such values can be called "truthy" and "falsy", respectively.</p> + +<p>Boolean operations such as <code>&&</code> (logical <em>and</em>), <code>||</code> (logical <em>or</em>), and <code>!</code> (logical <em>not</em>) are supported; see below.</p> + +<h2 id="Variables">Variables</h2> + +<p>New variables in JavaScript are declared using one of three keywords: <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/let">let</a></code>, <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/const">const</a></code>, or <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/var" title="/en/JavaScript/Reference/Statements/var">var</a></code>.<br> + <br> + <strong><code>let</code> </strong>allows you to declare block-level variables. The declared variable is available from the <em>block</em> it is enclosed in.</p> + +<pre class="brush: js notranslate">let a; +let name = 'Simon'; +</pre> + +<p>The following is an example of scope with a variable declared with <code><strong>let</strong></code>:</p> + +<pre class="brush: js notranslate">// myLetVariable is *not* visible out here + +for (let myLetVariable = 0; myLetVariable < 5; myLetVariable++) { + // myLetVariable is only visible in here +} + +// myLetVariable is *not* visible out here + +</pre> + +<p><code><strong>const</strong></code> allows you to declare variables whose values are never intended to change. The variable is available from the <em>block</em> it is declared in.</p> + +<pre class="brush: js notranslate">const Pi = 3.14; // variable Pi is set +Pi = 1; // will throw an error because you cannot change a constant variable.</pre> + +<p><br> + <code><strong>var</strong></code> is the most common declarative keyword. It does not have the restrictions that the other two keywords have. This is because it was traditionally the only way to declare a variable in JavaScript. A variable declared with the <strong><code>var</code> </strong>keyword is available from the <em>function</em> it is declared in.</p> + +<pre class="brush: js notranslate">var a; +var name = 'Simon';</pre> + +<p>An example of scope with a variable declared with <strong><code>var</code>:</strong></p> + +<pre class="brush: js notranslate">// myVarVariable *is* visible out here + +for (var myVarVariable = 0; myVarVariable < 5; myVarVariable++) { + // myVarVariable is visible to the whole function +} + +// myVarVariable *is* visible out here +</pre> + +<p>If you declare a variable without assigning any value to it, its type is <code>undefined</code>.</p> + +<p>An important difference between JavaScript and other languages like Java is that in JavaScript, blocks do not have scope; only functions have a scope. So if a variable is defined using <code>var</code> in a compound statement (for example inside an <code>if</code> control structure), it will be visible to the entire function. However, starting with ECMAScript 2015, <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/let">let</a></code> and <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/const">const</a></code> declarations allow you to create block-scoped variables.</p> + +<h2 id="Operators">Operators</h2> + +<p>JavaScript's numeric operators are <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code> and <code>%</code> which is the remainder operator (<a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Remainder_%28%29">which is the same as modulo</a>.) Values are assigned using <code>=</code>, and there are also compound assignment statements such as <code>+=</code> and <code>-=</code>. These extend out to <code>x = x <em>operator</em> y</code>.</p> + +<pre class="brush: js notranslate">x += 5; +x = x + 5; +</pre> + +<p>You can use <code>++</code> and <code>--</code> to increment and decrement respectively. These can be used as a prefix or postfix operators.</p> + +<p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Addition" title="/en/JavaScript/Reference/Operators/String_Operators"><code>+</code> operator</a> also does string concatenation:</p> + +<pre class="brush: js notranslate">'hello' + ' world'; // "hello world" +</pre> + +<p>If you add a string to a number (or other value) everything is converted into a string first. This might trip you up:</p> + +<pre class="brush: js notranslate">'3' + 4 + 5; // "345" + 3 + 4 + '5'; // "75" +</pre> + +<p>Adding an empty string to something is a useful way of converting it to a string itself.</p> + +<p><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators" title="/en/JavaScript/Reference/Operators/Comparison_Operators">Comparisons</a> in JavaScript can be made using <code><</code>, <code>></code>, <code><=</code> and <code>>=</code>. These work for both strings and numbers. Equality is a little less straightforward. The double-equals operator performs type coercion if you give it different types, with sometimes interesting results:</p> + +<pre class="brush: js notranslate">123 == '123'; // true +1 == true; // true +</pre> + +<p>To avoid type coercion, use the triple-equals operator:</p> + +<pre class="brush: js notranslate">123 === '123'; // false +1 === true; // false +</pre> + +<p>There are also <code>!=</code> and <code>!==</code> operators.</p> + +<p>JavaScript also has <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators" title="/en/JavaScript/Reference/Operators/Bitwise_Operators">bitwise operations</a>. If you want to use them, they're there.</p> + +<h2 id="Control_structures">Control structures</h2> + +<p>JavaScript has a similar set of control structures to other languages in the C family. Conditional statements are supported by <code>if</code> and <code>else</code>; you can chain them together if you like:</p> + +<pre class="brush: js notranslate">var name = 'kittens'; +if (name == 'puppies') { + name += ' woof'; +} else if (name == 'kittens') { + name += ' meow'; +} else { + name += '!'; +} +name == 'kittens meow'; +</pre> + +<p>JavaScript has <code>while</code> loops and <code>do-while</code> loops. The first is good for basic looping; the second for loops where you wish to ensure that the body of the loop is executed at least once:</p> + +<pre class="brush: js notranslate">while (true) { + // an infinite loop! +} + +var input; +do { + input = get_input(); +} while (inputIsNotValid(input)); +</pre> + +<p>JavaScript's <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for"><code>for</code> loop</a> is the same as that in C and Java: it lets you provide the control information for your loop on a single line.</p> + +<pre class="brush: js notranslate">for (var i = 0; i < 5; i++) { + // Will execute 5 times +} +</pre> + +<p>JavaScript also contains two other prominent for loops: <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of"><code>for</code>...<code>of</code></a></p> + +<pre class="brush: js notranslate">for (let value of array) { + // do something with value +} +</pre> + +<p>and <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in"><code>for</code>...<code>in</code></a>:</p> + +<pre class="brush: js notranslate">for (let property in object) { + // do something with object property +} +</pre> + +<p>The <code>&&</code> and <code>||</code> operators use short-circuit logic, which means whether they will execute their second operand is dependent on the first. This is useful for checking for null objects before accessing their attributes:</p> + +<pre class="brush: js notranslate">var name = o && o.getName(); +</pre> + +<p>Or for caching values (when falsy values are invalid):</p> + +<pre class="brush: js notranslate">var name = cachedName || (cachedName = getName()); +</pre> + +<p>JavaScript has a ternary operator for conditional expressions:</p> + +<pre class="brush: js notranslate">var allowed = (age > 18) ? 'yes' : 'no'; +</pre> + +<p>The <code>switch</code> statement can be used for multiple branches based on a number or string:</p> + +<pre class="brush: js notranslate">switch (action) { + case 'draw': + drawIt(); + break; + case 'eat': + eatIt(); + break; + default: + doNothing(); +} +</pre> + +<p>If you don't add a <code>break</code> statement, execution will "fall through" to the next level. This is very rarely what you want — in fact it's worth specifically labeling deliberate fallthrough with a comment if you really meant it to aid debugging:</p> + +<pre class="brush: js notranslate">switch (a) { + case 1: // fallthrough + case 2: + eatIt(); + break; + default: + doNothing(); +} +</pre> + +<p>The default clause is optional. You can have expressions in both the switch part and the cases if you like; comparisons take place between the two using the <code>===</code> operator:</p> + +<pre class="brush: js notranslate">switch (1 + 3) { + case 2 + 2: + yay(); + break; + default: + neverhappens(); +} +</pre> + +<h2 id="Objects">Objects</h2> + +<p>JavaScript objects can be thought of as simple collections of name-value pairs. As such, they are similar to:</p> + +<ul> + <li>Dictionaries in Python.</li> + <li>Hashes in Perl and Ruby.</li> + <li>Hash tables in C and C++.</li> + <li>HashMaps in Java.</li> + <li>Associative arrays in PHP.</li> +</ul> + +<p>The fact that this data structure is so widely used is a testament to its versatility. Since everything (bar core types) in JavaScript is an object, any JavaScript program naturally involves a great deal of hash table lookups. It's a good thing they're so fast!</p> + +<p>The "name" part is a JavaScript string, while the value can be any JavaScript value — including more objects. This allows you to build data structures of arbitrary complexity.</p> + +<p>There are two basic ways to create an empty object:</p> + +<pre class="brush: js notranslate">var obj = new Object(); +</pre> + +<p>And:</p> + +<pre class="brush: js notranslate">var obj = {}; +</pre> + +<p>These are semantically equivalent; the second is called object literal syntax and is more convenient. This syntax is also the core of JSON format and should be preferred at all times.</p> + +<p>Object literal syntax can be used to initialize an object in its entirety:</p> + +<pre class="brush: js notranslate">var obj = { + name: 'Carrot', + for: 'Max', // 'for' is a reserved word, use '_for' instead. + details: { + color: 'orange', + size: 12 + } +}; +</pre> + +<p>Attribute access can be chained together:</p> + +<pre class="brush: js notranslate">obj.details.color; // orange +obj['details']['size']; // 12 +</pre> + +<p>The following example creates an object prototype(<code>Person</code>) and an instance of that prototype(<code>you</code>).</p> + +<pre class="brush: js notranslate">function Person(name, age) { + this.name = name; + this.age = age; +} + +// Define an object +var you = new Person('You', 24); +// We are creating a new person named "You" aged 24. + +</pre> + +<p><strong>Once created</strong>, an object's properties can again be accessed in one of two ways:</p> + +<pre class="brush: js notranslate">// dot notation +obj.name = 'Simon'; +var name = obj.name; +</pre> + +<p>And...</p> + +<pre class="brush: js notranslate">// bracket notation +obj['name'] = 'Simon'; +var name = obj['name']; +// can use a variable to define a key +var user = prompt('what is your key?') +obj[user] = prompt('what is its value?') +</pre> + +<p>These are also semantically equivalent. The second method has the advantage that the name of the property is provided as a string, which means it can be calculated at run-time. However, using this method prevents some JavaScript engine and minifier optimizations being applied. It can also be used to set and get properties with names that are <a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords" title="/en/JavaScript/Reference/Reserved_Words">reserved words</a>:</p> + +<pre class="brush: js notranslate">obj.for = 'Simon'; // Syntax error, because 'for' is a reserved word +obj['for'] = 'Simon'; // works fine +</pre> + +<div class="note"> +<p>Starting in ECMAScript 5, reserved words may be used as object property names "in the buff". This means that they don't need to be "clothed" in quotes when defining object literals. See the ES5 <a href="http://es5.github.io/#x7.6.1">Spec</a>.</p> +</div> + +<p>For more on objects and prototypes see <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype">Object.prototype</a>. For an explanation of object prototypes and the object prototype chains see <a href="/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain">Inheritance and the prototype chain</a>.</p> + +<div class="note"> +<p>Starting in ECMAScript 2015, object keys can be defined by the variable using bracket notation upon being created. <code>{[phoneType]: 12345}</code> is possible instead of just <code>var userPhone = {}; userPhone[phoneType] = 12345</code>.</p> +</div> + +<h2 id="Arrays">Arrays</h2> + +<p>Arrays in JavaScript are actually a special type of object. They work very much like regular objects (numerical properties can naturally be accessed only using <code>[]</code> syntax) but they have one magic property called '<code>length</code>'. This is always one more than the highest index in the array.</p> + +<p>One way of creating arrays is as follows:</p> + +<pre class="brush: js notranslate">var a = new Array(); +a[0] = 'dog'; +a[1] = 'cat'; +a[2] = 'hen'; +a.length; // 3 +</pre> + +<p>A more convenient notation is to use an array literal:</p> + +<pre class="brush: js notranslate">var a = ['dog', 'cat', 'hen']; +a.length; // 3 +</pre> + +<p>Note that <code>array.length</code> isn't necessarily the number of items in the array. Consider the following:</p> + +<pre class="brush: js notranslate">var a = ['dog', 'cat', 'hen']; +a[100] = 'fox'; +a.length; // 101 +</pre> + +<p>Remember — the length of the array is one more than the highest index.</p> + +<p>If you query a non-existent array index, you'll get a value of <code>undefined</code> in return:</p> + +<pre class="brush: js notranslate">typeof a[90]; // undefined +</pre> + +<p>If you take the above about <code>[]</code> and <code>length</code> into account, you can iterate over an array using the following <code>for</code> loop:</p> + +<pre class="brush: js notranslate">for (var i = 0; i < a.length; i++) { + // Do something with a[i] +} +</pre> + +<p>ES2015 introduced the more concise <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of"><code>for</code>...<code>of</code></a> loop for iterable objects such as arrays:</p> + +<pre class="brush:js notranslate">for (const currentValue of a) { + // Do something with currentValue +}</pre> + +<p>You could also iterate over an array using a <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in" title="/en/JavaScript/Reference/Statements/for...in"><code>for</code>...<code>in</code></a> loop, however this does not iterate over the array elements, but the array indices. Furthermore, if someone added new properties to <code>Array.prototype</code>, they would also be iterated over by such a loop. Therefore this loop type is not recommended for arrays.</p> + +<p>Another way of iterating over an array that was added with ECMAScript 5 is <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach">forEach()</a></code>:</p> + +<pre class="brush: js notranslate">['dog', 'cat', 'hen'].forEach(function(currentValue, index, array) { + // Do something with currentValue or array[index] +}); +</pre> + +<p>If you want to append an item to an array simply do it like this:</p> + +<pre class="brush: js notranslate">a.push(item);</pre> + +<p>Arrays come with a number of methods. See also the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">full documentation for array methods</a>.</p> + +<table> + <thead> + <tr> + <th scope="col">Method name</th> + <th scope="col">Description</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>a.toString()</code></td> + <td>Returns a string with the <code>toString()</code> of each element separated by commas.</td> + </tr> + <tr> + <td><code>a.toLocaleString()</code></td> + <td>Returns a string with the <code>toLocaleString()</code> of each element separated by commas.</td> + </tr> + <tr> + <td><code>a.concat(item1[, item2[, ...[, itemN]]])</code></td> + <td>Returns a new array with the items added on to it.</td> + </tr> + <tr> + <td><code>a.join(sep)</code></td> + <td>Converts the array to a string — with values delimited by the <code>sep</code> param</td> + </tr> + <tr> + <td><code>a.pop()</code></td> + <td>Removes and returns the last item.</td> + </tr> + <tr> + <td><code>a.push(item1, ..., itemN)</code></td> + <td>Appends items to the end of the array.</td> + </tr> + <tr> + <td><code>a.shift()</code></td> + <td>Removes and returns the first item.</td> + </tr> + <tr> + <td><code>a.unshift(item1[, item2[, ...[, itemN]]])</code></td> + <td>Prepends items to the start of the array.</td> + </tr> + <tr> + <td><code>a.slice(start[, end])</code></td> + <td>Returns a sub-array.</td> + </tr> + <tr> + <td><code>a.sort([cmpfn])</code></td> + <td>Takes an optional comparison function.</td> + </tr> + <tr> + <td><code>a.splice(start, delcount[, item1[, ...[, itemN]]])</code></td> + <td>Lets you modify an array by deleting a section and replacing it with more items.</td> + </tr> + <tr> + <td><code>a.reverse()</code></td> + <td>Reverses the array.</td> + </tr> + </tbody> +</table> + +<h2 id="Functions">Functions</h2> + +<p>Along with objects, functions are the core component in understanding JavaScript. The most basic function couldn't be much simpler:</p> + +<pre class="brush: js notranslate">function add(x, y) { + var total = x + y; + return total; +} +</pre> + +<p>This demonstrates a basic function. A JavaScript function can take 0 or more named parameters. The function body can contain as many statements as you like and can declare its own variables which are local to that function. The <code>return</code> statement can be used to return a value at any time, terminating the function. If no return statement is used (or an empty return with no value), JavaScript returns <code>undefined</code>.</p> + +<p>The named parameters turn out to be more like guidelines than anything else. You can call a function without passing the parameters it expects, in which case they will be set to <code>undefined</code>.</p> + +<pre class="brush: js notranslate">add(); // NaN +// You can't perform addition on undefined +</pre> + +<p>You can also pass in more arguments than the function is expecting:</p> + +<pre class="brush: js notranslate">add(2, 3, 4); // 5 +// added the first two; 4 was ignored +</pre> + +<p>That may seem a little silly, but functions have access to an additional variable inside their body called <a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments" title="/en/JavaScript/Reference/Functions_and_function_scope/arguments"><code>arguments</code></a>, which is an array-like object holding all of the values passed to the function. Let's re-write the add function to take as many values as we want:</p> + +<pre class="brush: js notranslate">function add() { + var sum = 0; + for (var i = 0, j = arguments.length; i < j; i++) { + sum += arguments[i]; + } + return sum; +} + +add(2, 3, 4, 5); // 14 +</pre> + +<p>That's really not any more useful than writing <code>2 + 3 + 4 + 5</code> though. Let's create an averaging function:</p> + +<pre class="brush: js notranslate">function avg() { + var sum = 0; + for (var i = 0, j = arguments.length; i < j; i++) { + sum += arguments[i]; + } + return sum / arguments.length; +} + +avg(2, 3, 4, 5); // 3.5 +</pre> + +<p>This is pretty useful, but it does seem a little verbose. To reduce this code a bit more we can look at substituting the use of the arguments array through <a href="/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters">Rest parameter syntax</a>. In this way, we can pass in any number of arguments into the function while keeping our code minimal. The <strong>rest parameter operator</strong> is used in function parameter lists with the format: <strong>...variable</strong> and it will include within that variable the entire list of uncaptured arguments that the function was called with. We will also replace the <strong>for</strong> loop with a <strong>for...of</strong> loop to return the values within our variable.</p> + +<pre class="brush: js notranslate">function avg(...args) { + var sum = 0; + for (let value of args) { + sum += value; + } + return sum / args.length; +} + +avg(2, 3, 4, 5); // 3.5 +</pre> + +<div class="note">In the above code, the variable <strong>args</strong> holds all the values that were passed into the function.<br> +<br> +It is important to note that wherever the rest parameter operator is placed in a function declaration it will store all arguments <em>after</em> its declaration, but not before. <em>i.e. function</em> <em>avg(</em><strong>firstValue, </strong><em>...args)</em><strong> </strong>will store the first value passed into the function in the <strong>firstValue </strong>variable and the remaining arguments in <strong>args</strong>. That's another useful language feature but it does lead us to a new problem. The <code>avg()</code> function takes a comma-separated list of arguments — but what if you want to find the average of an array? You could just rewrite the function as follows:</div> + +<pre class="brush: js notranslate">function avgArray(arr) { + var sum = 0; + for (var i = 0, j = arr.length; i < j; i++) { + sum += arr[i]; + } + return sum / arr.length; +} + +avgArray([2, 3, 4, 5]); // 3.5 +</pre> + +<p>But it would be nice to be able to reuse the function that we've already created. Luckily, JavaScript lets you call a function with an arbitrary array of arguments, using the {{jsxref("Function.apply", "apply()")}} method of any function object.</p> + +<pre class="brush: js notranslate">avg.apply(null, [2, 3, 4, 5]); // 3.5 +</pre> + +<p>The second argument to <code>apply()</code> is the array to use as arguments; the first will be discussed later on. This emphasizes the fact that functions are objects too.</p> + +<div class="note"> +<p>You can achieve the same result using the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator">spread operator</a> in the function call.</p> + +<p>For instance: <code>avg(...numbers)</code></p> +</div> + +<p>JavaScript lets you create anonymous functions.</p> + +<pre class="brush: js notranslate">var avg = function() { + var sum = 0; + for (var i = 0, j = arguments.length; i < j; i++) { + sum += arguments[i]; + } + return sum / arguments.length; +}; +</pre> + +<p>This is semantically equivalent to the <code>function avg()</code> form. It's extremely powerful, as it lets you put a full function definition anywhere that you would normally put an expression. This enables all sorts of clever tricks. Here's a way of "hiding" some local variables — like block scope in C:</p> + +<pre class="brush: js notranslate">var a = 1; +var b = 2; + +(function() { + var b = 3; + a += b; +})(); + +a; // 4 +b; // 2 +</pre> + +<p>JavaScript allows you to call functions recursively. This is particularly useful for dealing with tree structures, such as those found in the browser DOM.</p> + +<pre class="brush: js notranslate">function countChars(elm) { + if (elm.nodeType == 3) { // TEXT_NODE + return elm.nodeValue.length; + } + var count = 0; + for (var i = 0, child; child = elm.childNodes[i]; i++) { + count += countChars(child); + } + return count; +} +</pre> + +<p>This highlights a potential problem with anonymous functions: how do you call them recursively if they don't have a name? JavaScript lets you name function expressions for this. You can use named <a href="/en-US/docs/Glossary/IIFE">IIFEs (Immediately Invoked Function Expressions)</a> as shown below:</p> + +<pre class="brush: js notranslate">var charsInBody = (function counter(elm) { + if (elm.nodeType == 3) { // TEXT_NODE + return elm.nodeValue.length; + } + var count = 0; + for (var i = 0, child; child = elm.childNodes[i]; i++) { + count += counter(child); + } + return count; +})(document.body); +</pre> + +<p>The name provided to a function expression as above is only available to the function's own scope. This allows more optimizations to be done by the engine and results in more readable code. The name also shows up in the debugger and some stack traces, which can save you time when debugging.</p> + +<p>Note that JavaScript functions are themselves objects — like everything else in JavaScript — and you can add or change properties on them just like we've seen earlier in the Objects section.</p> + +<h2 id="Custom_objects">Custom objects</h2> + +<div class="note">For a more detailed discussion of object-oriented programming in JavaScript, see <a href="/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript">Introduction to Object-Oriented JavaScript</a>.</div> + +<p>In classic Object Oriented Programming, objects are collections of data and methods that operate on that data. JavaScript is a prototype-based language that contains no class statement, as you'd find in C++ or Java (this is sometimes confusing for programmers accustomed to languages with a class statement). Instead, JavaScript uses functions as classes. Let's consider a person object with first and last name fields. There are two ways in which the name might be displayed: as "first last" or as "last, first". Using the functions and objects that we've discussed previously, we could display the data like this:</p> + +<pre class="brush: js notranslate">function makePerson(first, last) { + return { + first: first, + last: last + }; +} +function personFullName(person) { + return person.first + ' ' + person.last; +} +function personFullNameReversed(person) { + return person.last + ', ' + person.first; +} + +var s = makePerson('Simon', 'Willison'); +personFullName(s); // "Simon Willison" +personFullNameReversed(s); // "Willison, Simon" +</pre> + +<p>This works, but it's pretty ugly. You end up with dozens of functions in your global namespace. What we really need is a way to attach a function to an object. Since functions are objects, this is easy:</p> + +<pre class="brush: js notranslate">function makePerson(first, last) { + return { + first: first, + last: last, + fullName: function() { + return this.first + ' ' + this.last; + }, + fullNameReversed: function() { + return this.last + ', ' + this.first; + } + }; +} + +var s = makePerson('Simon', 'Willison'); +s.fullName(); // "Simon Willison" +s.fullNameReversed(); // "Willison, Simon" +</pre> + +<p>Note on the <code><a href="/en-US/docs/Web/JavaScript/Reference/Operators/this" title="/en/JavaScript/Reference/Operators/this">this</a></code> keyword. Used inside a function, <code>this</code> refers to the current object. What that actually means is specified by the way in which you called that function. If you called it using <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Accessing_properties" title="/en/JavaScript/Reference/Operators/Member_Operators">dot notation or bracket notation</a> on an object, that object becomes <code>this</code>. If dot notation wasn't used for the call, <code>this</code> refers to the global object.</p> + +<p>Note that <code>this</code> is a frequent cause of mistakes. For example:</p> + +<pre class="brush: js notranslate">var s = makePerson('Simon', 'Willison'); +var fullName = s.fullName; +fullName(); // undefined undefined +</pre> + +<p>When we call <code>fullName()</code> alone, without using <code>s.fullName()</code>, <code>this</code> is bound to the global object. Since there are no global variables called <code>first</code> or <code>last</code> we get <code>undefined</code> for each one.</p> + +<p>We can take advantage of the <code>this</code> keyword to improve our <code>makePerson</code> function:</p> + +<pre class="brush: js notranslate">function Person(first, last) { + this.first = first; + this.last = last; + this.fullName = function() { + return this.first + ' ' + this.last; + }; + this.fullNameReversed = function() { + return this.last + ', ' + this.first; + }; +} +var s = new Person('Simon', 'Willison'); +</pre> + +<p>We have introduced another keyword: <code><a href="/en-US/docs/Web/JavaScript/Reference/Operators/new" title="/en/JavaScript/Reference/Operators/new">new</a></code>. <code>new</code> is strongly related to <code>this</code>. It creates a brand new empty object, and then calls the function specified, with <code>this</code> set to that new object. Notice though that the function specified with <code>this</code> does not return a value but merely modifies the <code>this</code> object. It's <code>new</code> that returns the <code>this</code> object to the calling site. Functions that are designed to be called by <code>new</code> are called constructor functions. Common practice is to capitalize these functions as a reminder to call them with <code>new</code>.</p> + +<p>The improved function still has the same pitfall with calling <code>fullName()</code> alone.</p> + +<p>Our person objects are getting better, but there are still some ugly edges to them. Every time we create a person object we are creating two brand new function objects within it — wouldn't it be better if this code was shared?</p> + +<pre class="brush: js notranslate">function personFullName() { + return this.first + ' ' + this.last; +} +function personFullNameReversed() { + return this.last + ', ' + this.first; +} +function Person(first, last) { + this.first = first; + this.last = last; + this.fullName = personFullName; + this.fullNameReversed = personFullNameReversed; +} +</pre> + +<p>That's better: we are creating the method functions only once, and assigning references to them inside the constructor. Can we do any better than that? The answer is yes:</p> + +<pre class="brush: js notranslate">function Person(first, last) { + this.first = first; + this.last = last; +} +Person.prototype.fullName = function() { + return this.first + ' ' + this.last; +}; +Person.prototype.fullNameReversed = function() { + return this.last + ', ' + this.first; +}; +</pre> + +<p><code>Person.prototype</code> is an object shared by all instances of <code>Person</code>. It forms part of a lookup chain (that has a special name, "prototype chain"): any time you attempt to access a property of <code>Person</code> that isn't set, JavaScript will check <code>Person.prototype</code> to see if that property exists there instead. As a result, anything assigned to <code>Person.prototype</code> becomes available to all instances of that constructor via the <code>this</code> object.</p> + +<p>This is an incredibly powerful tool. JavaScript lets you modify something's prototype at any time in your program, which means you can add extra methods to existing objects at runtime:</p> + +<pre class="brush: js notranslate">var s = new Person('Simon', 'Willison'); +s.firstNameCaps(); // TypeError on line 1: s.firstNameCaps is not a function + +Person.prototype.firstNameCaps = function() { + return this.first.toUpperCase(); +}; +s.firstNameCaps(); // "SIMON" +</pre> + +<p>Interestingly, you can also add things to the prototype of built-in JavaScript objects. Let's add a method to <code>String</code> that returns that string in reverse:</p> + +<pre class="brush: js notranslate">var s = 'Simon'; +s.reversed(); // TypeError on line 1: s.reversed is not a function + +String.prototype.reversed = function() { + var r = ''; + for (var i = this.length - 1; i >= 0; i--) { + r += this[i]; + } + return r; +}; + +s.reversed(); // nomiS +</pre> + +<p>Our new method even works on string literals!</p> + +<pre class="brush: js notranslate">'This can now be reversed'.reversed(); // desrever eb won nac sihT +</pre> + +<p>As mentioned before, the prototype forms part of a chain. The root of that chain is <code>Object.prototype</code>, whose methods include <code>toString()</code> — it is this method that is called when you try to represent an object as a string. This is useful for debugging our <code>Person</code> objects:</p> + +<pre class="brush: js notranslate">var s = new Person('Simon', 'Willison'); +s.toString(); // [object Object] + +Person.prototype.toString = function() { + return '<Person: ' + this.fullName() + '>'; +} + +s.toString(); // "<Person: Simon Willison>" +</pre> + +<p>Remember how <code>avg.apply()</code> had a null first argument? We can revisit that now. The first argument to <code>apply()</code> is the object that should be treated as '<code>this</code>'. For example, here's a trivial implementation of <code>new</code>:</p> + +<pre class="brush: js notranslate">function trivialNew(constructor, ...args) { + var o = {}; // Create an object + constructor.apply(o, args); + return o; +} +</pre> + +<p>This isn't an exact replica of <code>new</code> as it doesn't set up the prototype chain (it would be difficult to illustrate). This is not something you use very often, but it's useful to know about. In this snippet, <code>...args</code> (including the ellipsis) is called the "<a href="/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters">rest arguments</a>" — as the name implies, this contains the rest of the arguments.</p> + +<p>Calling</p> + +<pre class="brush: js notranslate">var bill = trivialNew(Person, 'William', 'Orange');</pre> + +<p>is therefore almost equivalent to</p> + +<pre class="brush: js notranslate">var bill = new Person('William', 'Orange');</pre> + +<p><code>apply()</code> has a sister function named <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call" title="/en/JavaScript/Reference/Global_Objects/Function/call"><code>call</code></a>, which again lets you set <code>this</code> but takes an expanded argument list as opposed to an array.</p> + +<pre class="brush: js notranslate">function lastNameCaps() { + return this.last.toUpperCase(); +} +var s = new Person('Simon', 'Willison'); +lastNameCaps.call(s); +// Is the same as: +s.lastNameCaps = lastNameCaps; +s.lastNameCaps(); // WILLISON +</pre> + +<h3 id="Inner_functions">Inner functions</h3> + +<p>JavaScript function declarations are allowed inside other functions. We've seen this once before, with an earlier <code>makePerson()</code> function. An important detail of nested functions in JavaScript is that they can access variables in their parent function's scope:</p> + +<pre class="brush: js notranslate">function parentFunc() { + var a = 1; + + function nestedFunc() { + var b = 4; // parentFunc can't use this + return a + b; + } + return nestedFunc(); // 5 +} +</pre> + +<p>This provides a great deal of utility in writing more maintainable code. If a called function relies on one or two other functions that are not useful to any other part of your code, you can nest those utility functions inside it. This keeps the number of functions that are in the global scope down, which is always a good thing.</p> + +<p>This is also a great counter to the lure of global variables. When writing complex code it is often tempting to use global variables to share values between multiple functions — which leads to code that is hard to maintain. Nested functions can share variables in their parent, so you can use that mechanism to couple functions together when it makes sense without polluting your global namespace — "local globals" if you like. This technique should be used with caution, but it's a useful ability to have.</p> + +<h2 id="Closures">Closures</h2> + +<p>This leads us to one of the most powerful abstractions that JavaScript has to offer — but also the most potentially confusing. What does this do?</p> + +<pre class="brush: js notranslate">function makeAdder(a) { + return function(b) { + return a + b; + }; +} +var add5 = makeAdder(5); +var add20 = makeAdder(20); +add5(6); // ? +add20(7); // ? +</pre> + +<p>The name of the <code>makeAdder()</code> function should give it away: it creates new 'adder' functions, each of which, when called with one argument, adds it to the argument that it was created with.</p> + +<p>What's happening here is pretty much the same as was happening with the inner functions earlier on: a function defined inside another function has access to the outer function's variables. The only difference here is that the outer function has returned, and hence common sense would seem to dictate that its local variables no longer exist. But they <em>do</em> still exist — otherwise, the adder functions would be unable to work. What's more, there are two different "copies" of <code>makeAdder()</code>'s local variables — one in which <code>a</code> is 5 and the other one where <code>a</code> is 20. So the result of that function calls is as follows:</p> + +<pre class="brush: js notranslate">add5(6); // returns 11 +add20(7); // returns 27 +</pre> + +<p>Here's what's actually happening. Whenever JavaScript executes a function, a 'scope' object is created to hold the local variables created within that function. It is initialized with any variables passed in as function parameters. This is similar to the global object that all global variables and functions live in, but with a couple of important differences: firstly, a brand new scope object is created every time a function starts executing, and secondly, unlike the global object (which is accessible as <code>this</code> and in browsers as <code>window</code>) these scope objects cannot be directly accessed from your JavaScript code. There is no mechanism for iterating over the properties of the current scope object, for example.</p> + +<p>So when <code>makeAdder()</code> is called, a scope object is created with one property: <code>a</code>, which is the argument passed to the <code>makeAdder()</code> function. <code>makeAdder()</code> then returns a newly created function. Normally JavaScript's garbage collector would clean up the scope object created for <code>makeAdder()</code> at this point, but the returned function maintains a reference back to that scope object. As a result, the scope object will not be garbage-collected until there are no more references to the function object that <code>makeAdder()</code> returned.</p> + +<p>Scope objects form a chain called the scope chain, similar to the prototype chain used by JavaScript's object system.</p> + +<p>A <strong>closure</strong> is the combination of a function and the scope object in which it was created. Closures let you save state — as such, they can often be used in place of objects. You can find <a href="http://stackoverflow.com/questions/111102/how-do-javascript-closures-work">several excellent introductions to closures</a>.</p> diff --git a/files/fa/web/javascript/index.html b/files/fa/web/javascript/index.html new file mode 100644 index 0000000000..2d8a11b00f --- /dev/null +++ b/files/fa/web/javascript/index.html @@ -0,0 +1,128 @@ +--- +title: جاوا اسکریپت +slug: Web/JavaScript +tags: + - JavaScript + - Landing + - NeedsTranslation + - TopicStub +translation_of: Web/JavaScript +--- +<div class="callout-box"><strong><a href="/fa/docs/Web/JavaScript/A_re-introduction_to_JavaScript">یک معرفی مجدد برای جاوااسکریپت</a></strong><br> +یک بررسی کلی برا آنهایی که <em>فکر میکنند</em> در مورد جاوااسکریپت میدانند</div> + +<p dir="rtl">{{JsSidebar}}</p> + +<p dir="rtl"><strong>JavaScript</strong><sup>®</sup> (اغلب به <strong>JS</strong> مخفف میشود) سبک، مفسر، زبان شیگرا شده با <a href="https://en.wikipedia.org/wiki/First-class_functions" title="https://en.wikipedia.org/wiki/First-class_functions">first-class functions</a>، به عنوان زبان اسکریپت نویسی برای صفحات وب شناخته شده است، اما <a class="external" href="http://en.wikipedia.org/wiki/JavaScript#Uses_outside_web_pages">در خیلی از محیطهای غیر مرورگری</a> مانند <a class="external" href="http://nodejs.org/">node.js</a> یا <a href="http://couchdb.apache.org">Apache CouchDB</a> نیز استفاده شده است. زبان اسکریت نویسی آن <a class="mw-redirect" href="https://en.wikipedia.org/wiki/Prototype-based" title="Prototype-based">مبتنی بر نمونه</a> است، <a href="/en-US/docs/multiparadigmlanguage.html" title="/en-US/docs/multiparadigmlanguage.html">چند نمونه</a> که پویا است،<span style="color: #666666; line-height: 21px;"> </span><a href="https://en.wikipedia.org/wiki/Type_safety" style="line-height: 21px;" title="Type safety">نوع امن</a><span style="line-height: 1.572;"> و از شی گرایی پشتیبانی میکند، سبک های برنامه نویسی تابعی را دارد. اطلاعات بیشتر را میتوانید از صفحه <a href="/fa/docs/docs/Web/JavaScript/About_JavaScript">درباره جاوااسکریپت</a></span><span style="line-height: 1.572;"> مشاهده نمایید.</span></p> + +<p dir="rtl">استاندارد جاوااسکریپت <a href="/fa/docs/JavaScript/Language_Resources">اکمااسکریپت</a> (<a href="/fa/docs/JavaScript/Language_Resources">ECMAScript</a>) است که از سال ۲۰۱۲ تمامی مرورگرهای مدرن استاندارد اکمااسکریپت نسخه ۵.۱ را به صورت کامل پشتیبانی میکنند، همچنین مرورگرهای قدیمیتر نسخه ۳ از اکمااسکریپت را پشتیبانی میکنند. از ماه June سال ۲۰۱۵ اکمااسکریپت ۶ (ES6) یا همان اکمااسکریپت ۲۰۱۵ (ES2015) مورد قبول واقع شده است. توضیحات تکمیلی در مورد اکمااسکریپت ۶ را می توانید در <a class="external" href="http://wiki.ecmascript.org/doku.php?id=harmony:proposals">dedicated wiki</a> مشاهده نمایید.</p> + +<p dir="rtl">این بخش از سایت به زبان جاوااسکریپت اختصاص داده شده است، قسمتهایی که مختص به صفحات وب، یا دیگر محیطهای میزبانی نیست. برای اطلاعات در مورد APIهای خاص برای صفحات وب، لطفا <a href="/fa/docs/DOM">DOM</a> را ببینید. در مورد اینکه چگونه DOM وJavaScript با همدیگر مناسب هستند در <a href="/fa/docs/Gecko_DOM_Reference/Introduction#DOM_and_JavaScript">مرجع DOM</a> اطلاعات بیشتری را بخوانید.</p> + +<p dir="rtl">JavaScript به صورت <strong>«جاواسکریپت»</strong> خوانده میشود، ولی در فارسی به صورت <strong>«جاوااسکریپت»</strong> ترجمه میشود و اگر به صورت «جاوا اسکریپت» ترجمه شود اشتباه است چون دو کلمه جدا از هم نیست و اگر به صورت دو کلمه جدا نوشته شود خطلاهای نگارشی ایجاد میشود، به طور مثال ممکن است کلمه جاوا در انتهای خط و کلمه اسکریپت در ابتدای خط بعدی نوشته شود.</p> + +<div class="row topicpage-table" dir="rtl"> +<div class="section"> +<h2 class="Documentation" id="مستندات">مستندات</h2> + +<dl> + <dt><a href="/fa/docs/Web/JavaScript/Guide">راهنمای جاوااسکریپت</a></dt> + <dd>اگر شما در جاوااسکریپت تازهکار هستید، باید این راهنما را بخوانید.</dd> + <dt><a href="/fa/docs/Web/JavaScript/Reference">مرجع جاوااسکریپت</a></dt> + <dd>این مرجع جاوااسکریپت شامل مستندات کاملی برای جاوااسکریپت نسخه ۱.۵ و بهروزرسانیهای آن است.</dd> +</dl> + +<h3 id="مقالات_معرفی">مقالات معرفی</h3> + +<dl> + <dt><a href="/fa/docs/Web/JavaScript/JavaScript_technologies_overview">نمای کلی تکنولوژیهای جاوااسکریپت</a></dt> + <dd>آشنایی با چشم انداز جاوااسکریپت برای مرورگر</dd> +</dl> + +<h3 id="مقالات_پیشرفته">مقالات پیشرفته</h3> + +<dl> + <dt><a href="/fa/docs/Web/JavaScript/Data_structures">ساختارهای دادهای جاوااسکریپت</a></dt> + <dd>نمای کلی ساختارهای دادهای قابل دسترس در جاپااسکریپت</dd> + <dt><a href="/fa/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain">وراثت و زنجیره نمونه</a></dt> + <dd>توضیح ارثبری مبتنی بر نمونه که بهصورت گستردهای اشتباده و ناچیز شمرده شده است</dd> +</dl> + +<h3 id="مقالات_دیگر">مقالات دیگر</h3> + +<dl> + <dt><a href="/fa/docs/Web/Guide/HTML/Canvas_tutorial">آموزش بوم نقاشی</a></dt> + <dd><canvas> یک المان HTML5 است که برای رسم گرافیکها با استفاده از اسکریپت نویسی استفاده میشود. آن میتواند، برای مثال برای رسم گرافیکها، ترکیب عکس و یا انجام ساده (و نه خیلی ساده) انیمیشنها استفاده شود.</dd> + <dt><a href="/fa/docs/Web/JavaScript/Language_Resources">مراجع زبان جاوااسکریپت</a></dt> + <dd>شرح زبان جاوااسکریپت استاندارد.</dd> + <dt><a class="external" href="http://msdn.microsoft.com/en-us/library/ff405926.aspx">مستندات پشتیبانی استانداردهای اینترنت اکسپلورر</a></dt> + <dd>مایکروسافت مستنداتی منتشر کرده است که "تغییرات، توضیحات، و الحاقیات برخی استانداردهای مورد تایید پشتیبانی شده توسط اینترنت اکسپلورر." را شرح میدهد، بعضی از آنها مربوط به جاوااسکریپت هستند:</dd> + <dd> + <ul> + <li><a class="external" href="http://msdn.microsoft.com/en-us/library/ff520996.aspx">[MS-ES3]: Internet Explorer ECMA-262 ECMAScript Language Specification Standards Support Document </a></li> + <li><a class="external" href="http://msdn.microsoft.com/en-us/library/ff521046.aspx">[MS-ES3EX]: Microsoft JScript Extensions to the ECMAScript Language Specification Third Edition </a></li> + <li><a class="external" href="http://msdn.microsoft.com/en-us/library/ff960769.aspx">[MS-ES5]: Internet Explorer ECMA-262 ECMAScript Language Specification (Fifth Edition) Standards Support Document </a></li> + <li><a class="external" href="http://msdn.microsoft.com/en-us/library/ff955363.aspx">[MS-ES5EX]: Internet Explorer Extensions to the ECMA-262 ECMAScript Language Specification (Fifth Edition)</a></li> + </ul> + </dd> +</dl> + +<p><span class="alllinks"><a href="/en-US/docs/tag/JavaScript">View All...</a></span></p> +</div> + +<div class="section"> +<h2 class="Tools" id="ابزارها_منابع_پیشرفته">ابزارها & منابع پیشرفته</h2> + +<ul> + <li><a href="/fa/docs/Tools">ابزارهای توسعه فایرفاکس</a> - ابزارهای عالی تعبیه شده در فایرفاکس.</li> + <li><a href="http://koding.com">Koding</a> پلت فرم توسعه آنلاین با پشتیبانی جاوااسکریپت</li> + <li><a href="http://www.learnstreet.com/">LearnStreet</a> - آموزشها و تمرینهای عملی رایگان آنلاین.</li> + <li><a href="http://www.codecademy.com/">Codecademy</a> - دوره جاوااسکریپت رایگان با مشکلات تعاملی</li> + <li><a href="http://codeschool.com">Code School </a>- یادگیری بوسیله انجام دادن، چندین دوره جاو.ا اسکریپت</li> + <li><a href="http://frontendmasters.com/" title="http://frontendmasters.com/">Frontend Masters</a> - فیلمهای کارگاه آموزشی جاوااسکریپت و توسعه وب نهایی</li> + <li><a href="http://www.letscodejavascript.com/" title="http://www.letscodejavascript.com/">Let’s Code: Test-Driven JavaScript</a> - سریهای ضبط خیلی دقیق صفحه، توسعه حرفهای جاوااسکریپت</li> + <li><a class="link-https" href="https://github.com/rwldrn/idiomatic.js">Idiomatic.js</a> - اصول نوشتن جاوااسکریپت استوار، اصطلاحی</li> + <li><a href="/en-US/docs/JavaScript/Memory_Management">Memory Management in JavaScript</a> . نمای کلی از چگونگی عملکرد حافظه در جاوااسکریپت</li> + <li><a class="external" href="http://www.getfirebug.com/">Firebug</a> - اشکالزدایی و پروفایلینگ جاوااسکریپت</li> + <li><a href="/en-US/docs/Venkman">Venkman</a> - دیباگر جاوااسکریپت</li> + <li><a href="/en-US/docs/JavaScript/Shells">JavaScript Shells</a> - تست قطعه کدهای کوچک</li> + <li><a class="external" href="http://jshint.com">JSHint</a> - ابزاری که در تشخیص خطا و مشکلات بالقوه در کد جاوااسکریپت شما کمک میکند</li> + <li><a class="external" href="http://www.jslint.com/lint.html">JSLint</a> - چک کننده نحو، در برابر اعمال بد هشدار میدهد</li> + <li><a class="external" href="http://usejsdoc.org/">JSDoc</a> - تولید مستندات از کد</li> + <li><a class="external" href="http://online-marketing-technologies.com/tools/javascript-redirection-generator.html" title="JavaScript Redirect">JavaScript Redirect</a> - ابزار تغییر مسیر پیشرفته جاوااسکریپت</li> + <li><a class="external" href="http://www.aptana.com">Aptana Studio</a> - <span id="result_box" lang="fa"><span class="hps">IDE</span> <span class="hps">متن باز</span> <span class="hps">با</span> پشتیبانی <span class="hps">آژاکس</span> <span class="hps">و</span> <span class="hps">جاوااسکریپت</span> <span class="atn hps">(</span><span>بر اساس</span> eclipse<span>)</span></span></li> + <li><a class="external" href="http://netbeans.org/features/javascript/">Netbeans</a> - IDE متن باز شامل پشتیبانی پیچیده از جاوااسکریپت</li> + <li><a class="external" href="http://www.eclipse.org/downloads/packages/eclipse-ide-javascript-web-developers/heliossr1">Eclipse</a> - IDE متن باز شامل جعبه ابزار توسعه جاوااسکریپت</li> + <li><a class="external" href="http://www.c9.io">Cloud9 IDE</a> - IDE متن باز که در مرورگر اجرا شده با قابلیت پشتیبانی از جاوااسکریپت و Node.js</li> + <li><a class="external" href="http://prettydiff.com/">Pretty Diff </a>- یک ابزار متفاوت برای مقایسه کد خرد شده با کد معمولی</li> + <li><a href="http://www.objectplayground.com/" title="http://www.objectplayground.com/">Object Playground</a> - ابزاری برای درک شیگرایی جاوااسکریپت</li> + <li><a class="link-https" href="https://addons.mozilla.org/en-US/firefox/addon/7434">Extension Developer's Extension</a> - محیط و شل JS را ارایه میدهد</li> + <li><a href="http://boilerplatejs.org/">BoilerplateJS</a> - مرجع معماری برای پروژههای جاوااسکریپت در مقیاس بزرگ</li> + <li><a href="http://www.jsfiddle.net/">JSFiddle</a> - مورد استفاده برای آزمایش و اصلاح وب سایت با جاوااسکریپت آنلاین. </li> + <li><a href="/fa/docs/JavaScript/Other_JavaScript_tools">دیگر ابزارهای جاوااسکریپت</a></li> +</ul> + +<p><span class="alllinks"><a href="/en-US/docs/tag/JavaScript:Tools">نمایش همه...</a></span></p> + +<h2 class="Community" id="Other_resources" name="Other resources">دیگر منابع</h2> + +<dl> + <dt><a class="external" href="http://bonsaiden.github.com/JavaScript-Garden">JavaScript Garden</a></dt> + <dd>سایتی با اطلاعات مفید در مورد قطعات داخلیتر جاوااسکریپت.</dd> + <dt><a class="link-https" href="https://github.com/bebraw/jswiki/wiki">JSWiki</a></dt> + <dd>یک ویکی مبتنی بر Githubکه منابع و کتابخانهها را ایندکس گذاری کرده است.</dd> + <dt><a href="http://stackoverflow.com/questions/tagged/javascript">Stack Overflow</a></dt> + <dd>یک سایت همکاری ساخته و نگهداری شده Q&A و میتوانید برای جواب سوال خودرا در آن جستجو کنید. اگر جواب سوال خودرا پیدا نکردید میتوانید سوال خودرا در آنجا مطرح کنید.</dd> + <dt><a href="http://pineapple.io/resources/tagged/javascript?type=tutorials&sort=all_time">Pineapple · JavaScript</a></dt> + <dd>یک پایگاه داده بزرگ از آموزش و منابع حال حاضر جاوااسکریپت.</dd> + <dt><a href="http://lifeofjs.com">Life of JavaScript</a></dt> + <dd>منابع عالی در مورد جاوااسکریپت شامل کتاب، ارایهها، فیلمها، فیدها، سایتها، کتابخانهها، محیطهای کاری، ابزارها که در یکجا جمع آموری شده است.</dd> +</dl> + +<h2 class="Related_Topics" id="Related_Topics" name="Related_Topics">موضوعات مرتبط</h2> + +<ul> + <li><a href="/fa/docs/AJAX">AJAX</a>, <a href="/fa/docs/DOM">DOM</a>, <a class="internal" href="/fa/docs/JavaScript/Server-Side_JavaScript">Server-Side JavaScript</a>, <a href="/fa/docs/DHTML">DHTML</a>, <a href="/fa/docs/Mozilla/Projects/SpiderMonkey">SpiderMonkey</a>, <a href="/fa/docs/HTML/Canvas">Canvas</a>, <a href="/fa/docs/JavaScript/JQuery">JQuery</a></li> +</ul> +</div> +</div> diff --git a/files/fa/web/javascript/inheritance_and_the_prototype_chain/index.html b/files/fa/web/javascript/inheritance_and_the_prototype_chain/index.html new file mode 100644 index 0000000000..73aac306f7 --- /dev/null +++ b/files/fa/web/javascript/inheritance_and_the_prototype_chain/index.html @@ -0,0 +1,533 @@ +--- +title: ارث بری و پروتوتایپ در جاوا اسکریپت +slug: Web/JavaScript/Inheritance_and_the_prototype_chain +translation_of: Web/JavaScript/Inheritance_and_the_prototype_chain +--- +<div>{{jsSidebar("Advanced")}}</div> + +<p>جاوا اسکریپت ممکن است برای کسانی که با زبانهای شی گرا آشنایی دارند کمی گیج کننده باشد (زبانهایی مثل Java یاC++), بدلیل اینکه این زبان پویاست و کمپایل نمیشود و همچنین مفهومی به نام <code>class</code> را ندارد (البته واژه<code>class</code> در نسخه ES2015 معرفی شد, ولی در واقع فقط ظاهر قضیه عوض شده و در باطن کماکان ارث بری در جاوااسکریپت همان سیستم پروتوتایپ است).</p> + +<p>وقتی صحبت از وراثت باشد جاوا اسکریپت فقط یک شی دارد : objects.</p> + +<p>هر آبجکت در جاوااسکریپت یک مشخصه (<strong>property </strong>) مخفی دارد که به یک شی دیگر در رم اشاره میکند که این شی دوم همان <strong>پروتوتایپِ </strong>شی اول است. </p> + +<p> ، این پروتوتایپ هم برای خودش یک پروتوتایپ دارد و ... الی آخر . تا جایی که بالاترین شی در زنجیره پروتوتایپش <code>null</code> است . از آنجایی که <code>null</code> پروتوتایپ ندارد لذا این شی آخر حلقه در این زنجیره است . به این زنجیره ، <strong>زنجیره پروتوتایپ</strong> میگویند</p> + +<p>تقریبا همه اشیا در جاوا اسکریپت فرزند {{jsxref("Object")}} هستند که این شیء ، بالاترین شی در زنجیره پروتوتایپ است</p> + +<p>در حالیکه ممکن است این به عنوان یکی از ضعف های جاوااسکریپت به نظر بیاد ولی در واقع مدل ارث بری پروتوتایپی از مدل سنتی قدرتمند تر است . به طور مثال ساختن مدل سنتی ارث بری با استفاده از مدل پروتوتایپی کار بسیار ساده ای است.</p> + +<h2 id="ارث_بری_با_زنجیره_پروتوتایپ">ارث بری با زنجیره پروتوتایپ</h2> + +<h3 id="ارث_بری_خصوصیات_(properties)">ارث بری خصوصیات (properties)</h3> + +<p>اشیا در جاوا اسکریپت مثل کیف هایی پر از خصوصیات(properties) هستند . اشیا در این زبان همونطور که گفته شد یک لینک به پروتوتایپ خودشون هم دران . وقتی میخواهیم به یک خصوصیت از یک شی دسترسی پیدا کنیم اگر آن خصوصیت در خود شی پیدا نشد جاوا اسکریپت در پروتوتایپ دنبال آن خصوصیت میگردد ، اگر در آنجاهم نشد در پروتوتایپِ مربوط به آن پروتوتایپ و به همین ترتیب تا آخر زنجیره پروتوتایپ پیش میرود که یا property فراخوانی شده پیدا شود یا به انتهای زنجیره برسیم و جستجو تمام شود.</p> + +<div class="note"> +<p> در کدهای اکمااسکریپت زیر منظور از <code>someObject.[[Prototype]]</code> پروتوتایپِ <code>someObject</code> است . از ECMAScript 2015 پروتوتایپ )<code>[[Prototype]](</code> از طریق {{jsxref("Object.getPrototypeOf()")}} و یا {{jsxref("Object.setPrototypeOf()")}} قابل دسترسی است . این روش معادل است با استفاده از <code>__proto__</code> که روشی استاندارد نیست ولی در اکثر مرورگرها پیاده سازی شده و قابل استفاده است.</p> + +<p>این رو نباید با <code><em>func</em>.prototype</code> که در حقیقت یک property از توابع هست اشتباه کنیم ، که کاربردش هم جایی هست که بخواهیم همه اشیایی که توسط function مورد نظر ساخته شدن ، همه دارای پروتایپ دلخواه ما باشن</p> + +<p><code><strong>Object.prototype</strong></code> در واقع {{jsxref("Object")}} در زنجیره پروتوتایپ است</p> +</div> + +<p>وقتی ما یک propertyاز یک شی رو فراخونی میکنیم اتفاقی که میافته به این صورته :</p> + +<pre class="brush: js">// Let's create an object o from function f with its own properties a and b: +let f = function () { + this.a = 1; + this.b = 2; +} +let o = new f(); // {a: 1, b: 2} + +// add properties in f function's prototype +f.prototype.b = 3; +f.prototype.c = 4; + +// do not set the prototype f.prototype = {b:3,c:4}; this will break the prototype chain +// o.[[Prototype]] has properties b and c. +// o.[[Prototype]].[[Prototype]] is Object.prototype. +// Finally, o.[[Prototype]].[[Prototype]].[[Prototype]] is null. +// This is the end of the prototype chain, as null, +// by definition, has no [[Prototype]]. +// Thus, the full prototype chain looks like: +// {a: 1, b: 2} ---> {b: 3, c: 4} ---> Object.prototype ---> null + +console.log(o.a); // 1 +// Is there an 'a' own property on o? Yes, and its value is 1. + +console.log(o.b); // 2 +// Is there a 'b' own property on o? Yes, and its value is 2. +// The prototype also has a 'b' property, but it's not visited. +// This is called "property shadowing." + +console.log(o.c); // 4 +// Is there a 'c' own property on o? No, check its prototype. +// Is there a 'c' own property on o.[[Prototype]]? Yes, its value is 4. + +console.log(o.d); // undefined +// Is there a 'd' own property on o? No, check its prototype. +// Is there a 'd' own property on o.[[Prototype]]? No, check its prototype. +// o.[[Prototype]].[[Prototype]] is null, stop searching, +// no property found, return undefined. +</pre> + +<p><a href="https://repl.it/@khaled_hossain_code/prototype">Code Link</a></p> + +<p>Setting a property to an object creates an own property. The only exception to the getting and setting behavior rules is when there is an inherited property with a <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Defining_getters_and_setters">getter or a setter</a>.</p> + +<h3 id="Inheriting_methods">Inheriting "methods"</h3> + +<p>JavaScript does not have "methods" in the form that class-based languages define them. In JavaScript, any function can be added to an object in the form of a property. An inherited function acts just as any other property, including property shadowing as shown above (in this case, a form of <em>method overriding</em>).</p> + +<p>When an inherited function is executed, the value of <a href="/en-US/docs/Web/JavaScript/Reference/Operators/this"><code>this</code></a> points to the inheriting object, not to the prototype object where the function is an own property.</p> + +<pre class="brush: js">var o = { + a: 2, + m: function() { + return this.a + 1; + } +}; + +console.log(o.m()); // 3 +// When calling o.m in this case, 'this' refers to o + +var p = Object.create(o); +// p is an object that inherits from o + +p.a = 4; // creates a property 'a' on p +console.log(p.m()); // 5 +// when p.m is called, 'this' refers to p. +// So when p inherits the function m of o, +// 'this.a' means p.a, the property 'a' of p + + +</pre> + +<h2 id="Using_prototypes_in_JavaScript">Using prototypes in JavaScript</h2> + +<p>Let's look at what happens behind the scenes in a bit more detail.</p> + +<p>In JavaScript, as mentioned above, functions are able to have properties. All functions have a special property named <code>prototype</code>. Please note that the code below is free-standing (it is safe to assume there is no other JavaScript on the webpage other than the below code). For the best learning experience, it is highly reccomended that you open a console (which, in Chrome and Firefox, can be done by pressing Ctrl+Shift+I), navigating to the "console" tab, copying-and-pasting in the below JavaScript code, and run it by pressing the Enter/Return key.</p> + +<pre class="brush: js">function doSomething(){} +console.log( doSomething.prototype ); +// It does not matter how you declare the function, a +// function in javascript will always have a default +// prototype property. +var doSomething = function(){}; +console.log( doSomething.prototype ); +</pre> + +<p>As seen above, <code>doSomething()</code> has a default <code>prototype</code> property, as demonstrated by the console. After running this code, the console should have displayed an object that looks similar to this.</p> + +<pre class="brush: js">{ + constructor: ƒ doSomething(), + __proto__: { + constructor: ƒ Object(), + hasOwnProperty: ƒ hasOwnProperty(), + isPrototypeOf: ƒ isPrototypeOf(), + propertyIsEnumerable: ƒ propertyIsEnumerable(), + toLocaleString: ƒ toLocaleString(), + toString: ƒ toString(), + valueOf: ƒ valueOf() + } +}</pre> + +<p>We can add properties to the prototype of <code>doSomething()</code>, as shown below.</p> + +<pre class="brush: js">function doSomething(){} +doSomething.prototype.foo = "bar"; +console.log( doSomething.prototype );</pre> + +<p>This results in:</p> + +<pre class="brush: js">{ + foo: "bar", + constructor: ƒ doSomething(), + __proto__: { + constructor: ƒ Object(), + hasOwnProperty: ƒ hasOwnProperty(), + isPrototypeOf: ƒ isPrototypeOf(), + propertyIsEnumerable: ƒ propertyIsEnumerable(), + toLocaleString: ƒ toLocaleString(), + toString: ƒ toString(), + valueOf: ƒ valueOf() + } +} +</pre> + +<p>We can now use the <code>new</code> operator to create an instance of <code>doSomething()</code> based on this prototype. To use the new operator, simply call the function normally except prefix it with <code>new</code>. Calling a function with the <code>new</code> operator returns an object that is an instance of the function. Properties can then be added onto this object.</p> + +<p>Try the following code:</p> + +<pre class="brush: js">function doSomething(){} +doSomething.prototype.foo = "bar"; // add a property onto the prototype +var doSomeInstancing = new doSomething(); +doSomeInstancing.prop = "some value"; // add a property onto the object +console.log( doSomeInstancing );</pre> + +<p>This results in an output similar to the following:</p> + +<pre class="brush: js">{ + prop: "some value", + __proto__: { + foo: "bar", + constructor: ƒ doSomething(), + __proto__: { + constructor: ƒ Object(), + hasOwnProperty: ƒ hasOwnProperty(), + isPrototypeOf: ƒ isPrototypeOf(), + propertyIsEnumerable: ƒ propertyIsEnumerable(), + toLocaleString: ƒ toLocaleString(), + toString: ƒ toString(), + valueOf: ƒ valueOf() + } + } +}</pre> + +<p>As seen above, the <code>__proto__</code> of <code>doSomeInstancing</code> is <code>doSomething.prototype</code>. But, what does this do? When you access a property of <code>doSomeInstancing</code>, the browser first looks to see if <code>doSomeInstancing</code> has that property.</p> + +<p>If <code>doSomeInstancing</code> does not have the property, then the browser looks for the property in the <code>__proto__</code> of <code>doSomeInstancing</code> (a.k.a. doSomething.prototype). If the <code>__proto__</code> of doSomeInstancing has the property being looked for, then that property on the <code>__proto__</code> of doSomeInstancing is used.</p> + +<p>Otherwise, if the <code>__proto__</code> of doSomeInstancing does not have the property, then the <code>__proto__</code> of the <code>__proto__</code> of doSomeInstancing is checked for the property. By default, the <code>__proto__</code> of any function's prototype property is <code>window.Object.prototype</code>. So, the <code>__proto__</code> of the <code>__proto__</code> of doSomeInstancing (a.k.a. the <code>__proto__</code> of doSomething.prototype (a.k.a. <code>Object.prototype</code>)) is then looked through for the property being searched for.</p> + +<p>If the property is not found in the <code>__proto__</code> of the <code>__proto__</code> of doSomeInstancing, then the <code>__proto__</code> of the <code>__proto__</code> of the <code>__proto__</code> of doSomeInstancing is looked through. However, there is a problem: the <code>__proto__</code> of the <code>__proto__</code> of the <code>__proto__</code> of doSomeInstancing does not exist. Then, and only then, after the entire prototype chain of <code>__proto__</code>'s is looked through, and there are no more <code>__proto__</code>s does the browser assert that the property does not exist and conclude that the value at the property is <code>undefined</code>.</p> + +<p>Let's try entering some more code into the console:</p> + +<pre class="brush: js">function doSomething(){} +doSomething.prototype.foo = "bar"; +var doSomeInstancing = new doSomething(); +doSomeInstancing.prop = "some value"; +console.log("doSomeInstancing.prop: " + doSomeInstancing.prop); +console.log("doSomeInstancing.foo: " + doSomeInstancing.foo); +console.log("doSomething.prop: " + doSomething.prop); +console.log("doSomething.foo: " + doSomething.foo); +console.log("doSomething.prototype.prop: " + doSomething.prototype.prop); +console.log("doSomething.prototype.foo: " + doSomething.prototype.foo);</pre> + +<p>This results in the following:</p> + +<pre class="brush: js">doSomeInstancing.prop: some value +doSomeInstancing.foo: bar +doSomething.prop: undefined +doSomething.foo: undefined +doSomething.prototype.prop: undefined +doSomething.prototype.foo: bar</pre> + +<h2 id="Different_ways_to_create_objects_and_the_resulting_prototype_chain">Different ways to create objects and the resulting prototype chain</h2> + +<h3 id="Objects_created_with_syntax_constructs">Objects created with syntax constructs</h3> + +<pre class="brush: js">var o = {a: 1}; + +// The newly created object o has Object.prototype as its [[Prototype]] +// o has no own property named 'hasOwnProperty' +// hasOwnProperty is an own property of Object.prototype. +// So o inherits hasOwnProperty from Object.prototype +// Object.prototype has null as its prototype. +// o ---> Object.prototype ---> null + +var b = ['yo', 'whadup', '?']; + +// Arrays inherit from Array.prototype +// (which has methods indexOf, forEach, etc.) +// The prototype chain looks like: +// b ---> Array.prototype ---> Object.prototype ---> null + +function f() { + return 2; +} + +// Functions inherit from Function.prototype +// (which has methods call, bind, etc.) +// f ---> Function.prototype ---> Object.prototype ---> null +</pre> + +<h3 id="With_a_constructor">With a constructor</h3> + +<p>A "constructor" in JavaScript is "just" a function that happens to be called with the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/new">new operator</a>.</p> + +<pre class="brush: js">function Graph() { + this.vertices = []; + this.edges = []; +} + +Graph.prototype = { + addVertex: function(v) { + this.vertices.push(v); + } +}; + +var g = new Graph(); +// g is an object with own properties 'vertices' and 'edges'. +// g.[[Prototype]] is the value of Graph.prototype when new Graph() is executed. +</pre> + +<h3 id="With_Object.create">With <code>Object.create</code></h3> + +<p>ECMAScript 5 introduced a new method: {{jsxref("Object.create()")}}. Calling this method creates a new object. The prototype of this object is the first argument of the function:</p> + +<pre class="brush: js">var a = {a: 1}; +// a ---> Object.prototype ---> null + +var b = Object.create(a); +// b ---> a ---> Object.prototype ---> null +console.log(b.a); // 1 (inherited) + +var c = Object.create(b); +// c ---> b ---> a ---> Object.prototype ---> null + +var d = Object.create(null); +// d ---> null +console.log(d.hasOwnProperty); +// undefined, because d doesn't inherit from Object.prototype +</pre> + +<div> +<h3 id="With_the_class_keyword">With the <code>class</code> keyword</h3> + +<p>ECMAScript 2015 introduced a new set of keywords implementing <a href="/en-US/docs/Web/JavaScript/Reference/Classes">classes</a>. The new keywords include {{jsxref("Statements/class", "class")}}, {{jsxref("Classes/constructor", "constructor")}}, {{jsxref("Classes/static", "static")}}, {{jsxref("Classes/extends", "extends")}}, and {{jsxref("Operators/super", "super")}}.</p> + +<pre class="brush: js">'use strict'; + +class Polygon { + constructor(height, width) { + this.height = height; + this.width = width; + } +} + +class Square extends Polygon { + constructor(sideLength) { + super(sideLength, sideLength); + } + get area() { + return this.height * this.width; + } + set sideLength(newLength) { + this.height = newLength; + this.width = newLength; + } +} + +var square = new Square(2); +</pre> + +<h3 id="Performance">Performance</h3> + +<p>The lookup time for properties that are high up on the prototype chain can have a negative impact on the performance, and this may be significant in the code where performance is critical. Additionally, trying to access nonexistent properties will always traverse the full prototype chain.</p> + +<p>Also, when iterating over the properties of an object, <strong>every</strong> enumerable property that is on the prototype chain will be enumerated. To check whether an object has a property defined on <em>itself</em> and not somewhere on its prototype chain, it is necessary to use the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty"><code>hasOwnProperty</code></a> method which all objects inherit from <code>Object.prototype</code>. To give you a concrete example, let's take the above graph example code to illustrate it:</p> + +<pre class="brush: js">console.log(g.hasOwnProperty('vertices')); +// true + +console.log(g.hasOwnProperty('nope')); +// false + +console.log(g.hasOwnProperty('addVertex')); +// false + +console.log(g.__proto__.hasOwnProperty('addVertex')); +// true +</pre> + +<p><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty"><code>hasOwnProperty</code></a> is the only thing in JavaScript which deals with properties and does <strong>not</strong> traverse the prototype chain.</p> + +<p>Note: It is <strong>not</strong> enough to check whether a property is <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>. The property might very well exist, but its value just happens to be set to <code>undefined</code>.</p> +</div> + +<h3 id="Bad_practice_Extension_of_native_prototypes">Bad practice: Extension of native prototypes</h3> + +<p>One misfeature that is often used is to extend <code>Object.prototype</code> or one of the other built-in prototypes.</p> + +<p>This technique is called monkey patching and breaks <em>encapsulation</em>. While used by popular frameworks such as Prototype.js, there is still no good reason for cluttering built-in types with additional <em>non-standard</em> functionality.</p> + +<p>The <strong>only</strong> good reason for extending a built-in prototype is to backport the features of newer JavaScript engines, like <code>Array.forEach</code>.</p> + +<h3 id="Summary_of_methods_for_extending_the_protoype_chain">Summary of methods for extending the protoype chain</h3> + +<p>Here are all 5 ways and their pros/cons. All of the examples listed below create exactly the same resulting <code>inst</code> object (thus logging the same results to the console), except in different ways for the purpose of illustration.</p> + +<table class="standard-table" style="text-align: top;"> + <tbody> + <tr> + <td style="width: 1%;">Name</td> + <td style="vertical-align: top; width: 1%;">Example(s)</td> + <td style="vertical-align: top;">Pro(s)</td> + <td style="vertical-align: top; width: 60%;">Con(s)</td> + </tr> + <tr> + <td>New-initialization</td> + <td style="vertical-align: top;"> + <pre class="brush: js"> +function foo(){} +foo.prototype = { + foo_prop: "foo val" +}; +function bar(){} +var proto = new foo; +proto.bar_prop = "bar val"; +bar.prototype = proto; +var inst = new bar; +console.log(inst.foo_prop); +console.log(inst.bar_prop); +</pre> + </td> + <td style="vertical-align: top;">Supported in every browser imaginable (support goes all the way back to IE 5.5!). Also, it is very fast, very standard, and very JIST-optimizable.</td> + <td style="vertical-align: top;">In order to use this method, the function in question must be initialized. During this initialization, the constructor may store unique information that must be generated per-object. However, this unique information would only be generated once, potentially leading to problems. Additionally, the initialization of the constructor may put unwanted methods onto the object. However, both these are generally not problems at all (in fact, usually beneficial) if it is all your own code and you know what does what where.</td> + </tr> + <tr> + <td>Object.create</td> + <td style="vertical-align: top;"> + <pre class="brush: js"> +function foo(){} +foo.prototype = { + foo_prop: "foo val" +}; +function bar(){} +var proto = Object.create( + foo.prototype +); +proto.bar_prop = "bar val"; +bar.prototype = proto; +var inst = new bar; +console.log(inst.foo_prop); +console.log(inst.bar_prop); +</pre> + + <pre class="brush: js"> +function foo(){} +foo.prototype = { + foo_prop: "foo val" +}; +function bar(){} +var proto = Object.create( + foo.prototype, + { + bar_prop: { + value: "bar val" + } + } +); +bar.prototype = proto; +var inst = new bar; +console.log(inst.foo_prop); +console.log(inst.bar_prop)</pre> + </td> + <td style="vertical-align: top;">Support in all in-use-today browsers which are all non-microsoft browsers plus IE9 and up. Allows the direct setting of __proto__ in a way that is one-time-only so that the browser can better optimize the object. Also allows the creation of objects without a prototype via <code>Object.create(null)</code>.</td> + <td style="vertical-align: top;">Not supported in IE8 and below. However, as Microsoft has discontinued extended support for systems running theses old browsers, this should not be a concern for most applications. Additionally, the slow object initialization can be a performance black hole if using the second argument because each object-descriptor property has its own separate descriptor object. When dealing with hundreds of thousands of object descriptors in the form of object, there can arise a serious issue with lag.</td> + </tr> + <tr> + <td> + <p>Object.setPrototypeOf</p> + </td> + <td style="vertical-align: top;"> + <pre class="brush: js"> +function foo(){} +foo.prototype = { + foo_prop: "foo val" +}; +function bar(){} +var proto = { + bar_prop: "bar val" +}; +Object.setPrototypeOf( + proto, foo.prototype +); +bar.prototype = proto; +var inst = new bar; +console.log(inst.foo_prop); +console.log(inst.bar_prop); +</pre> + + <pre class="brush: js"> +function foo(){} +foo.prototype = { + foo_prop: "foo val" +}; +function bar(){} +var proto; +proto=Object.setPrototypeOf( + { bar_prop: "bar val" }, + foo.prototype +); +bar.prototype = proto; +var inst = new bar; +console.log(inst.foo_prop); +console.log(inst.bar_prop)</pre> + </td> + <td style="vertical-align: top;">Support in all in-use-today browsers which are all non-microsoft browsers plus IE9 and up. Allows the dynamic manipulation of an objects prototype and can even force a prototype on a prototype-less object created with <code>Object.create(null)</code>.</td> + <td style="vertical-align: top;">Should-be-depredicated and ill-performant. Making your Javascript run fast is completely out of the question if you dare use this in the final production code because many browsers optimize the prototype and try to guess the location of the method in the memory when calling an instance in advance, but setting the prototype dynamically disrupts all these optimizations and can even force some browsers to recompile for deoptimization your code just to make it work according to the specs. Not supported in IE8 and below.</td> + </tr> + <tr> + <td>__proto__</td> + <td style="vertical-align: top;"> + <pre class="brush: js"> +function foo(){} +foo.prototype = { + foo_prop: "foo val" +}; +function bar(){} +var proto = { + bar_prop: "bar val"; + __proto__: foo.prototype +}; +bar.prototype = proto; +var inst = new bar; +console.log(inst.foo_prop); +console.log(inst.bar_prop); +</pre> + + <pre class="brush: js"> +var inst = { + __proto__: { + bar_prop: "bar val", + __proto__: { + foo_prop: "foo val", + __proto__: Object + } + } +}; +console.log(inst.foo_prop); +console.log(inst.bar_prop)</pre> + </td> + <td style="vertical-align: top;">Support in all in-use-today browsers which are all non-microsoft browsers plus IE11 and up. Setting __proto__ to something that is not an object only fails silently. It does not throw an exception.</td> + <td style="vertical-align: top;">Grossly depredicated and non-performant. Making your Javascript run fast is completely out of the question if you dare use this in the final production code because many browsers optimize the prototype and try to guess the location of the method in the memory when calling an instance in advance, but setting the prototype dynamically disrupts all these optimizations and can even force some browsers to recompile for deoptimization your code just to make it work according to the specs. Not supported in IE10 and below.</td> + </tr> + </tbody> +</table> + +<h2 id="prototype_and_Object.getPrototypeOf"><code>prototype</code> and <code>Object.getPrototypeOf</code></h2> + +<p>JavaScript is a bit confusing for developers coming from Java or C++, as it's all dynamic, all runtime, and it has no classes at all. It's all just instances (objects). Even the "classes" we simulate are just a function object.</p> + +<p>You probably already noticed that our <code>function A</code> has a special property called <code>prototype</code>. This special property works with the JavaScript <code>new </code>operator. The reference to the prototype object is copied to the internal <code>[[Prototype]]</code> property of the new instance. For example, when you do <code>var a1 = new A()</code>, JavaScript (after creating the object in memory and before running function <code>A()</code> with <code>this</code> defined to it) sets <code>a1.[[Prototype]] = A.prototype</code>. When you then access properties of the instance, JavaScript first checks whether they exist on that object directly, and if not, it looks in <code>[[Prototype]]</code>. This means that all the stuff you define in <code>prototype</code> is effectively shared by all instances, and you can even later change parts of <code>prototype</code> and have the changes appear in all existing instances, if you wanted to.</p> + +<p>If, in the example above, you do <code>var a1 = new A(); var a2 = new A();</code> then <code>a1.doSomething</code> would actually refer to <code>Object.getPrototypeOf(a1).doSomething</code>, which is the same as the <code>A.prototype.doSomething</code> you defined, i.e. <code>Object.getPrototypeOf(a1).doSomething == Object.getPrototypeOf(a2).doSomething == A.prototype.doSomething</code>.</p> + +<p>In short, <code>prototype</code> is for types, while <code>Object.getPrototypeOf()</code> is the same for instances.</p> + +<p><code>[[Prototype]]</code> is looked at <em>recursively</em>, i.e. <code>a1.doSomething</code>, <code>Object.getPrototypeOf(a1).doSomething</code>, <code>Object.getPrototypeOf(Object.getPrototypeOf(a1)).doSomething</code> etc., until it's found or <code>Object.getPrototypeOf </code>returns null.</p> + +<p>So, when you call</p> + +<pre class="brush: js">var o = new Foo();</pre> + +<p>JavaScript actually just does</p> + +<pre class="brush: js">var o = new Object(); +o.[[Prototype]] = Foo.prototype; +Foo.call(o);</pre> + +<p>(or something like that) and when you later do</p> + +<pre class="brush: js">o.someProp;</pre> + +<p>it checks whether <code>o</code> has a property <code>someProp</code>. If not, it checks <code>Object.getPrototypeOf(o).someProp</code>, and if that doesn't exist it checks <code>Object.getPrototypeOf(Object.getPrototypeOf(o)).someProp</code>, and so on.</p> + +<h2 id="In_conclusion">In conclusion</h2> + +<p>It is <strong>essential</strong> to understand the prototypal inheritance model before writing complex code that makes use of it. Also, be aware of the length of the prototype chains in your code and break them up if necessary to avoid possible performance problems. Further, the native prototypes should <strong>never</strong> be extended unless it is for the sake of compatibility with newer JavaScript features.</p> diff --git a/files/fa/web/javascript/reference/classes/index.html b/files/fa/web/javascript/reference/classes/index.html new file mode 100644 index 0000000000..e031309f9f --- /dev/null +++ b/files/fa/web/javascript/reference/classes/index.html @@ -0,0 +1,418 @@ +--- +title: Classes +slug: Web/JavaScript/Reference/Classes +tags: + - Classes + - Constructors + - ECMAScript 2015 + - Guide + - Inheritance + - Intermediate + - JavaScript + - NeedsTranslation + - TopicStub +translation_of: Web/JavaScript/Reference/Classes +--- +<div>{{JsSidebar("Classes")}}</div> + +<p>Classes are a template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on prototypes but also have some syntax and semantics that are not shared with ES5 classalike semantics.</p> + +<h2 id="Defining_classes">Defining classes</h2> + +<p>Classes are in fact "special <a href="/en-US/docs/Web/JavaScript/Reference/Functions">functions</a>", and just as you can define <a href="/en-US/docs/Web/JavaScript/Reference/Operators/function">function expressions</a> and <a href="/en-US/docs/Web/JavaScript/Reference/Statements/function">function declarations</a>, the class syntax has two components: <a href="/en-US/docs/Web/JavaScript/Reference/Operators/class">class expressions</a> and <a href="/en-US/docs/Web/JavaScript/Reference/Statements/class">class declarations</a>.</p> + +<h3 id="Class_declarations">Class declarations</h3> + +<p>One way to define a class is using a <strong>class declaration</strong>. To declare a class, you use the <code>class</code> keyword with the name of the class ("Rectangle" here).</p> + +<pre class="brush: js notranslate">class Rectangle { + constructor(height, width) { + this.height = height; + this.width = width; + } +}</pre> + +<h4 id="Hoisting">Hoisting</h4> + +<p>An important difference between <strong>function declarations</strong> and <strong>class declarations</strong> is that function declarations are <a href="/en-US/docs/Glossary/Hoisting">hoisted</a> and class declarations are not. You first need to declare your class and then access it, otherwise code like the following will throw a {{jsxref("ReferenceError")}}:</p> + +<pre class="brush: js example-bad notranslate">const p = new Rectangle(); // ReferenceError + +class Rectangle {} +</pre> + +<h3 id="Class_expressions">Class expressions</h3> + +<p>A <strong>class expression</strong> is another way to define a class. Class expressions can be named or unnamed. The name given to a named class expression is local to the class's body. (it can be retrieved through the class's (not an instance's) {{jsxref("Function.name", "name")}} property, though).</p> + +<pre class="brush: js notranslate">// unnamed +let Rectangle = class { + constructor(height, width) { + this.height = height; + this.width = width; + } +}; +console.log(Rectangle.name); +// output: "Rectangle" + +// named +let Rectangle = class Rectangle2 { + constructor(height, width) { + this.height = height; + this.width = width; + } +}; +console.log(Rectangle.name); +// output: "Rectangle2" +</pre> + +<div class="note"> +<p><strong>Note:</strong> Class <strong>expressions</strong> are subject to the same hoisting restrictions as described in the <a href="#Class_declarations">Class declarations</a> section.</p> +</div> + +<h2 id="Class_body_and_method_definitions">Class body and method definitions</h2> + +<p>The body of a class is the part that is in curly brackets <code>{}</code>. This is where you define class members, such as methods or constructor.</p> + +<h3 id="Strict_mode">Strict mode</h3> + +<p>The body of a class is executed in <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a>, i.e., code written here is subject to stricter syntax for increased performance, some otherwise silent errors will be thrown, and certain keywords are reserved for future versions of ECMAScript.</p> + +<h3 id="Constructor">Constructor</h3> + +<p>The <code><a href="/en-US/docs/Web/JavaScript/Reference/Classes/constructor">constructor</a></code> method is a special method for creating and initializing an object created with a <code>class</code>. There can only be one special method with the name "constructor" in a class. A {{jsxref("SyntaxError")}} will be thrown if the class contains more than one occurrence of a <code>constructor</code> method.</p> + +<p>A constructor can use the <code>super</code> keyword to call the constructor of the super class.</p> + +<h3 id="Prototype_methods">Prototype methods</h3> + +<p>See also <a href="/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions">method definitions</a>.</p> + +<pre class="brush: js notranslate">class Rectangle { + constructor(height, width) { + this.height = height; + this.width = width; + } + // Getter + get area() { + return this.calcArea(); + } + // Method + calcArea() { + return this.height * this.width; + } +} + +const square = new Rectangle(10, 10); + +console.log(square.area); // 100</pre> + +<h3 id="Static_methods">Static methods</h3> + +<p>The <code><a href="/en-US/docs/Web/JavaScript/Reference/Classes/static">static</a></code> keyword defines a static method for a class. Static methods are called without <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript#The_object_(class_instance)" title='An example of class instance is "var john = new Person();"'>instantiating </a>their class and <strong>cannot </strong>be called through a class instance. Static methods are often used to create utility functions for an application.</p> + +<pre class="brush: js notranslate">class Point { + constructor(x, y) { + this.x = x; + this.y = y; + } + + static distance(a, b) { + const dx = a.x - b.x; + const dy = a.y - b.y; + + return Math.hypot(dx, dy); + } +} + +const p1 = new Point(5, 5); +const p2 = new Point(10, 10); +p1.distance; //undefined +p2.distance; //undefined + +console.log(Point.distance(p1, p2)); // 7.0710678118654755 +</pre> + +<h3 id="Binding_this_with_prototype_and_static_methods">Binding <code>this</code> with prototype and static methods</h3> + +<p>When a static or prototype method is called without a value for <code><a href="/en-US/docs/Web/JavaScript/Reference/Operators/this">this</a></code>, such as by assigning a variable to the method and then calling it, the <code>this</code> value will be <code>undefined</code> inside the method. This behavior will be the same even if the <code><a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">"use strict"</a></code> directive isn't present, because code within the <code>class</code> body's syntactic boundary is always executed in strict mode.</p> + +<pre class="brush: js notranslate">class Animal { + speak() { + return this; + } + static eat() { + return this; + } +} + +let obj = new Animal(); +obj.speak(); // the Animal object +let speak = obj.speak; +speak(); // undefined + +Animal.eat() // class Animal +let eat = Animal.eat; +eat(); // undefined</pre> + +<p>If we rewrite the above using traditional function-based syntax in non–strict mode, then <code>this</code> method calls is automatically bound to the initial <code>this</code> value, which by default is the <a href="/en-US/docs/Glossary/Global_object">global object</a>. In strict mode, autobinding will not happen; the value of <code>this</code> remains as passed.</p> + +<pre class="brush: js notranslate">function Animal() { } + +Animal.prototype.speak = function() { + return this; +} + +Animal.eat = function() { + return this; +} + +let obj = new Animal(); +let speak = obj.speak; +speak(); // global object (in non–strict mode) + +let eat = Animal.eat; +eat(); // global object (in non-strict mode) +</pre> + +<h3 id="Instance_properties">Instance properties</h3> + +<p>Instance properties must be defined inside of class methods:</p> + +<pre class="brush: js notranslate">class Rectangle { + constructor(height, width) { + this.height = height; + this.width = width; + } +}</pre> + +<p>Static (class-side) data properties and prototype data properties must be defined outside of the ClassBody declaration:</p> + +<pre class="brush: js notranslate">Rectangle.staticWidth = 20; +Rectangle.prototype.prototypeWidth = 25; +</pre> + +<h3 id="Field_declarations">Field declarations</h3> + +<div class="warning"> +<p>Public and private field declarations are an <a href="https://github.com/tc39/proposal-class-fields">experimental feature (stage 3)</a> proposed at <a href="https://tc39.es">TC39</a>, the JavaScript standards committee. Support in browsers is limited, but the feature can be used through a build step with systems like <a href="https://babeljs.io/">Babel</a>.</p> +</div> + +<h4 id="Public_field_declarations">Public field declarations</h4> + +<p>With the JavaScript field declaration syntax, the above example can be written as:</p> + +<pre class="brush: js notranslate">class Rectangle { + height = 0; + width; + constructor(height, width) { + this.height = height; + this.width = width; + } +} +</pre> + +<p>By declaring fields up-front, class definitions become more self-documenting, and the fields are always present.</p> + +<p>As seen above, the fields can be declared with or without a default value.</p> + +<p>See <a href="/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields">public class fields</a> for more information.</p> + +<h4 id="Private_field_declarations">Private field declarations</h4> + +<p>Using private fields, the definition can be refined as below.</p> + +<pre class="brush: js notranslate">class Rectangle { + #height = 0; + #width; + constructor(height, width) { + this.#height = height; + this.#width = width; + } +} +</pre> + +<p>It's an error to reference private fields from outside of the class; they can only be read or written within the class body. By defining things which are not visible outside of the class, you ensure that your classes' users can't depend on internals, which may change version to version.</p> + +<div class="note"> +<p>Private fields can only be declared up-front in a field declaration.</p> +</div> + +<p>Private fields cannot be created later through assigning to them, the way that normal properties can.</p> + +<p>For more information, see <a href="/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields">private class fields</a>.</p> + +<h2 id="Sub_classing_with_extends">Sub classing with <code>extends</code></h2> + +<p>The <code><a href="/en-US/docs/Web/JavaScript/Reference/Classes/extends">extends</a></code> keyword is used in <em>class declarations</em> or <em>class expressions</em> to create a class as a child of another class.</p> + +<pre class="brush: js notranslate">class Animal { + constructor(name) { + this.name = name; + } + + speak() { + console.log(`${this.name} makes a noise.`); + } +} + +class Dog extends Animal { + constructor(name) { + super(name); // call the super class constructor and pass in the name parameter + } + + speak() { + console.log(`${this.name} barks.`); + } +} + +let d = new Dog('Mitzie'); +d.speak(); // Mitzie barks. +</pre> + +<p>If there is a constructor present in the subclass, it needs to first call super() before using "this".</p> + +<p>One may also extend traditional function-based "classes":</p> + +<pre class="brush: js notranslate">function Animal (name) { + this.name = name; +} + +Animal.prototype.speak = function () { + console.log(`${this.name} makes a noise.`); +} + +class Dog extends Animal { + speak() { + console.log(`${this.name} barks.`); + } +} + +let d = new Dog('Mitzie'); +d.speak(); // Mitzie barks. + +// For similar methods, the child's method takes precedence over parent's method</pre> + +<p>Note that classes cannot extend regular (non-constructible) objects. If you want to inherit from a regular object, you can instead use {{jsxref("Object.setPrototypeOf()")}}:</p> + +<pre class="brush: js notranslate">const Animal = { + speak() { + console.log(`${this.name} makes a noise.`); + } +}; + +class Dog { + constructor(name) { + this.name = name; + } +} + +// If you do not do this you will get a TypeError when you invoke speak +Object.setPrototypeOf(Dog.prototype, Animal); + +let d = new Dog('Mitzie'); +d.speak(); // Mitzie makes a noise. +</pre> + +<h2 id="Species">Species</h2> + +<p>You might want to return {{jsxref("Array")}} objects in your derived array class <code>MyArray</code>. The species pattern lets you override default constructors.</p> + +<p>For example, when using methods such as {{jsxref("Array.map", "map()")}} that returns the default constructor, you want these methods to return a parent <code>Array</code> object, instead of the <code>MyArray</code> object. The {{jsxref("Symbol.species")}} symbol lets you do this:</p> + +<pre class="brush: js notranslate">class MyArray extends Array { + // Overwrite species to the parent Array constructor + static get [Symbol.species]() { return Array; } +} + +let a = new MyArray(1,2,3); +let mapped = a.map(x => x * x); + +console.log(mapped instanceof MyArray); // false +console.log(mapped instanceof Array); // true +</pre> + +<h2 id="Super_class_calls_with_super">Super class calls with <code>super</code></h2> + +<p>The <code><a href="/en-US/docs/Web/JavaScript/Reference/Operators/super">super</a></code> keyword is used to call corresponding methods of super class. This is one advantage over prototype-based inheritance.</p> + +<pre class="brush: js notranslate">class Cat { + constructor(name) { + this.name = name; + } + + speak() { + console.log(`${this.name} makes a noise.`); + } +} + +class Lion extends Cat { + speak() { + super.speak(); + console.log(`${this.name} roars.`); + } +} + +let l = new Lion('Fuzzy'); +l.speak(); +// Fuzzy makes a noise. +// Fuzzy roars. +</pre> + +<h2 id="Mix-ins">Mix-ins</h2> + +<p>Abstract subclasses or <em>mix-ins</em> are templates for classes. An ECMAScript class can only have a single superclass, so multiple inheritance from tooling classes, for example, is not possible. The functionality must be provided by the superclass.</p> + +<p>A function with a superclass as input and a subclass extending that superclass as output can be used to implement mix-ins in ECMAScript:</p> + +<pre class="brush: js notranslate">let calculatorMixin = Base => class extends Base { + calc() { } +}; + +let randomizerMixin = Base => class extends Base { + randomize() { } +}; +</pre> + +<p>A class that uses these mix-ins can then be written like this:</p> + +<pre class="brush: js notranslate">class Foo { } +class Bar extends calculatorMixin(randomizerMixin(Foo)) { }</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-class-definitions', 'Class definitions')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("javascript.classes")}}</p> + +<h2 id="Re-running_a_class_definition">Re-running a class definition</h2> + +<p>A class can't be redefined. Attempting to do so produces a <code>SyntaxError</code>.</p> + +<p>If you're experimenting with code in a web browser, such as the Firefox Web Console (<strong>Tools </strong>><strong> Web Developer </strong>><strong> Web Console</strong>) and you 'Run' a definition of a class with the same name twice, you'll get a <code>SyntaxError: redeclaration of let <em>ClassName</em>;</code>. (See further discussion of this issue in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1428672">bug 1428672</a>.) Doing something similar in Chrome Developer Tools gives you a message like <code>Uncaught SyntaxError: Identifier '<em>ClassName</em>' has already been declared at <anonymous>:1:1</code>.</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Functions">Functions</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/class"><code>class</code> declaration</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/class"><code>class</code> expression</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields">Public class fields</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields">Private class fields</a></li> + <li>{{jsxref("Operators/super", "super")}}</li> + <li><a href="https://hacks.mozilla.org/2015/07/es6-in-depth-classes/">Blog post: "ES6 In Depth: Classes"</a></li> + <li><a href="https://github.com/tc39/proposal-class-fields">Fields and public/private class properties proposal (stage 3)</a></li> +</ul> diff --git a/files/fa/web/javascript/reference/errors/index.html b/files/fa/web/javascript/reference/errors/index.html new file mode 100644 index 0000000000..c295fccea6 --- /dev/null +++ b/files/fa/web/javascript/reference/errors/index.html @@ -0,0 +1,31 @@ +--- +title: JavaScript error reference +slug: Web/JavaScript/Reference/Errors +tags: + - Debugging + - Error + - Errors + - Exception + - JavaScript + - NeedsTranslation + - TopicStub + - exceptions +translation_of: Web/JavaScript/Reference/Errors +--- +<p>{{jsSidebar("Errors")}}</p> + +<p>Below, you'll find a list of errors which are thrown by JavaScript. These errors can be a helpful debugging aid, but the reported problem isn't always immediately clear. The pages below will provide additional details about these errors. Each error is an object based upon the {{jsxref("Error")}} object, and has a <code>name</code> and a <code>message</code>.</p> + +<p>Errors displayed in the Web console may include a link to the corresponding page below to help you quickly comprehend the problem in your code.</p> + +<h2 id="List_of_errors">List of errors</h2> + +<p>In this list, each page is listed by name (the type of error) and message (a more detailed human-readable error message). Together, these two properties provide a starting point toward understanding and resolving the error. For more information, follow the links below!</p> + +<p>{{ListSubPages("/en-US/docs/Web/JavaScript/Reference/Errors")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Learn/JavaScript/First_steps/What_went_wrong">What went wrong? Troubleshooting JavaScript</a>: Beginner's introductory tutorial on fixing JavaScript errors.</li> +</ul> diff --git a/files/fa/web/javascript/reference/errors/too_much_recursion/index.html b/files/fa/web/javascript/reference/errors/too_much_recursion/index.html new file mode 100644 index 0000000000..02a8d54c45 --- /dev/null +++ b/files/fa/web/javascript/reference/errors/too_much_recursion/index.html @@ -0,0 +1,114 @@ +--- +title: 'InternalError: too much recursion' +slug: Web/JavaScript/Reference/Errors/Too_much_recursion +translation_of: Web/JavaScript/Reference/Errors/Too_much_recursion +--- +<div>{{jsSidebar("Errors")}}</div> + +<h2 id="Message">Message</h2> + +<pre class="syntaxbox">Error: Out of stack space (Edge) +InternalError: too much recursion (Firefox) +RangeError: Maximum call stack size exceeded (Chrome) +</pre> + +<h2 id="Error_type">Error type</h2> + +<p>{{jsxref("InternalError")}}.</p> + +<h2 id="What_went_wrong">What went wrong?</h2> + +<p>A function that calls itself is called a <em>recursive function</em>. Once a condition is met, the function stops calling itself. This is called a <em>base case</em>.</p> + +<p>In some ways, recursion is analogous to a loop. Both execute the same code multiple times, and both require a condition (to avoid an infinite loop, or rather, infinite recursion in this case). <span class="seoSummary">When there are too many function calls, or a function is missing a base case, JavaScript will throw this error.</span></p> + +<h2 id="Examples">Examples</h2> + +<p>This recursive function runs 10 times, as per the exit condition.</p> + +<pre class="brush: js">function loop(x) { + if (x >= 10) // "x >= 10" is the exit condition + return; + // do stuff + loop(x + 1); // the recursive call +} +loop(0);</pre> + +<p>Setting this condition to an extremely high value, won't work:</p> + +<pre class="brush: js example-bad">function loop(x) { + if (x >= 1000000000000) + return; + // do stuff + loop(x + 1); +} +loop(0); + +// InternalError: too much recursion</pre> + +<p>This recursive function is missing a base case. As there is no exit condition, the function will call itself infinitely.</p> + +<pre class="brush: js example-bad">function loop(x) { + // The base case is missing + +loop(x + 1); // Recursive call +} + +loop(0); + +// InternalError: too much recursion</pre> + +<h3 id="Class_error_too_much_recursion">Class error: too much recursion</h3> + +<pre class="brush: js example-bad">class Person{ + constructor(){} + set name(name){ + this.name = name; // Recursive call + } +} + + +const tony = new Person(); +tony.name = "Tonisha"; // InternalError: too much recursion +</pre> + +<p>When a value is assigned to the property name (this.name = name;) JavaScript needs to set that property. When this happens, the setter function is triggered.</p> + +<pre class="brush: js example-bad">set name(name){ + this.name = name; // Recursive call +} +</pre> + +<div class="note"> +<p>In this example when the setter is triggered, it is told to do the same thing again: <em>to set the same property that it is meant to handle.</em> This causes the function to call itself, again and again, making it infinitely recursive.</p> +</div> + +<p>This issue also appears if the same variable is used in the getter.</p> + +<pre class="brush: js example-bad">get name(){ + return this.name; // Recursive call +} +</pre> + +<p>To avoid this problem, make sure that the property being assigned to inside the setter function is different from the one that initially triggered the setter.The same goes for the getter.</p> + +<pre class="brush: js">class Person{ + constructor(){} + set name(name){ + this._name = name; + } + get name(){ + return this._name; + } +} +const tony = new Person(); +tony.name = "Tonisha"; +console.log(tony); +</pre> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{Glossary("Recursion")}}</li> + <li><a href="/en-US/docs/Web/JavaScript/Guide/Functions#Recursion">Recursive functions</a></li> +</ul> diff --git a/files/fa/web/javascript/reference/errors/unexpected_token/index.html b/files/fa/web/javascript/reference/errors/unexpected_token/index.html new file mode 100644 index 0000000000..77fa2e06c5 --- /dev/null +++ b/files/fa/web/javascript/reference/errors/unexpected_token/index.html @@ -0,0 +1,84 @@ +--- +title: 'SyntaxError: Unexpected token' +slug: Web/JavaScript/Reference/Errors/Unexpected_token +translation_of: Web/JavaScript/Reference/Errors/Unexpected_token +--- +<div class="twocolumns"> + +</div> + +<div class="threecolumns"> +<p>{{jsSidebar("Errors")}}</p> +</div> + +<p>The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo.</p> + +<h2 id="Message">Message</h2> + +<pre class="syntaxbox notranslate">SyntaxError: expected expression, got "x" +SyntaxError: expected property name, got "x" +SyntaxError: expected target, got "x" +SyntaxError: expected rest argument name, got "x" +SyntaxError: expected closing parenthesis, got "x" +SyntaxError: expected '=>' after argument list, got "x" +</pre> + +<h2 id="Error_type">Error type</h2> + +<p>{{jsxref("SyntaxError")}}</p> + +<h2 id="What_went_wrong">What went wrong?</h2> + +<p>A specific language construct was expected, but something else was provided. This might be a simple typo.</p> + +<h2 id="Examples">Examples</h2> + +<h3 id="Expression_expected">Expression expected</h3> + +<p>For example, when chaining expressions, trailing commas are not allowed.</p> + +<pre class="brush: js example-bad notranslate">for (let i = 0; i < 5,; ++i) { + console.log(i); +} +// SyntaxError: expected expression, got ')' +</pre> + +<p>Correct would be omitting the comma or adding another expression:</p> + +<pre class="brush: js example-good notranslate">for (let i = 0; i < 5; ++i) { + console.log(i); +} +</pre> + +<h3 id="Not_enough_brackets">Not enough brackets</h3> + +<p>Sometimes, you leave out brackets around <code>if</code> statements:</p> + +<pre class="brush: js example-bad line-numbers language-js notranslate">function round(n, upperBound, lowerBound){ + if(n > upperBound) || (n < lowerBound){ + throw 'Number ' + String(n) + ' is more than ' + String(upperBound) + ' or less than ' + String(lowerBound); + }else if(n < ((upperBound + lowerBound)/2)){ + return lowerBound; + }else{ + return upperBound; + } +} // SyntaxError: expected expression, got '||'</pre> + +<p>The brackets may look correct at first, but note how the <code>||</code> is outside the brackets. Correct would be putting brackets around the <code>||</code>:</p> + +<pre class="brush: js example-good notranslate">function round(n, upperBound, lowerBound){ + if((n > upperBound) || (n < lowerBound)){ + throw 'Number ' + String(n) + ' is more than ' + String(upperBound) + ' or less than ' + String(lowerBound); + }else if(n < ((upperBound + lowerBound)/2)){ + return lowerBound; + }else{ + return upperBound; + } +} +</pre> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{jsxref("SyntaxError")}}</li> +</ul> diff --git a/files/fa/web/javascript/reference/functions/index.html b/files/fa/web/javascript/reference/functions/index.html new file mode 100644 index 0000000000..4f1c4136cc --- /dev/null +++ b/files/fa/web/javascript/reference/functions/index.html @@ -0,0 +1,596 @@ +--- +title: Functions +slug: Web/JavaScript/Reference/Functions +tags: + - Constructor + - Function + - Functions + - JavaScript + - NeedsTranslation + - Parameter + - TopicStub + - parameters +translation_of: Web/JavaScript/Reference/Functions +--- +<div>{{jsSidebar("Functions")}}</div> + +<p>Generally speaking, a function is a "subprogram" that can be <em>called</em> by code external (or internal in the case of recursion) to the function. Like the program itself, a function is composed of a sequence of statements called the <em>function body</em>. Values can be <em>passed</em> to a function, and the function will <em>return</em> a value.</p> + +<p>In JavaScript, functions are first-class objects, because they can have properties and methods just like any other object. What distinguishes them from other objects is that functions can be called. In brief, they are <code><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Function">Function</a></code> objects.</p> + +<p>For more examples and explanations, see also the <a href="/en-US/docs/Web/JavaScript/Guide/Functions">JavaScript guide about functions</a>.</p> + +<h2 id="Description">Description</h2> + +<p>Every function in JavaScript is a <code>Function</code> object. See {{jsxref("Function")}} for information on properties and methods of <code>Function</code> objects.</p> + +<p>To return a value other than the default, a function must have a <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/return">return</a></code> statement that specifies the value to return. A function without a return statement will return a default value. In the case of a <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor">constructor</a> called with the <code><a href="/en-US/docs/Web/JavaScript/Reference/Operators/new">new</a></code> keyword, the default value is the value of its <code>this</code> parameter. For all other functions, the default return value is {{jsxref("undefined")}}.</p> + +<p>The parameters of a function call are the function's <em>arguments</em>. Arguments are passed to functions <em>by value</em>. If the function changes the value of an argument, this change is not reflected globally or in the calling function. However, object references are values, too, and they are special: if the function changes the referred object's properties, that change is visible outside the function, as shown in the following example:</p> + +<pre class="brush: js">/* Declare the function 'myFunc' */ +function myFunc(theObject) { + theObject.brand = "Toyota"; + } + + /* + * Declare variable 'mycar'; + * create and initialize a new Object; + * assign reference to it to 'mycar' + */ + var mycar = { + brand: "Honda", + model: "Accord", + year: 1998 + }; + + /* Logs 'Honda' */ + console.log(mycar.brand); + + /* Pass object reference to the function */ + myFunc(mycar); + + /* + * Logs 'Toyota' as the value of the 'brand' property + * of the object, as changed to by the function. + */ + console.log(mycar.brand); +</pre> + +<p>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/this"><code>this</code> keyword</a> does not refer to the currently executing function, so you must refer to <code>Function</code> objects by name, even within the function body.</p> + +<h2 id="Defining_functions">Defining functions</h2> + +<p>There are several ways to define functions:</p> + +<h3 id="The_function_declaration_(function_statement)">The function declaration (<code>function</code> statement)</h3> + +<p>There is a special syntax for declaring functions (see <a href="/en-US/docs/Web/JavaScript/Reference/Statements/function">function statement</a> for details):</p> + +<pre class="syntaxbox">function <em>name</em>([<em>param</em>[, <em>param</em>[, ... <em>param</em>]]]) { + <em>statements</em> +} +</pre> + +<dl> + <dt><code>name</code></dt> + <dd>The function name.</dd> +</dl> + +<dl> + <dt><code>param</code></dt> + <dd>The name of an argument to be passed to the function. A function can have up to 255 arguments.</dd> +</dl> + +<dl> + <dt><code>statements</code></dt> + <dd>The statements comprising the body of the function.</dd> +</dl> + +<h3 id="The_function_expression_(function_expression)">The function expression (<code>function</code> expression)</h3> + +<p>A function expression is similar to and has the same syntax as a function declaration (see <a href="/en-US/docs/Web/JavaScript/Reference/Operators/function">function expression</a> for details). A function expression may be a part of a larger expression. One can define "named" function expressions (where the name of the expression might be used in the call stack for example) or "anonymous" function expressions. Function expressions are not <em>hoisted</em> onto the beginning of the scope, therefore they cannot be used before they appear in the code.</p> + +<pre class="syntaxbox">function [<em>name</em>]([<em>param</em>[, <em>param</em>[, ... <em>param</em>]]]) { + <em>statements</em> +} +</pre> + +<dl> + <dt><code>name</code></dt> + <dd>The function name. Can be omitted, in which case the function becomes known as an anonymous function.</dd> +</dl> + +<dl> + <dt><code>param</code></dt> + <dd>The name of an argument to be passed to the function. A function can have up to 255 arguments.</dd> + <dt><code>statements</code></dt> + <dd>The statements comprising the body of the function.</dd> +</dl> + +<p>Here is an example of an <strong>anonymous</strong> function expression (the <code>name</code> is not used):</p> + +<pre class="brush: js">var myFunction = function() { + statements +}</pre> + +<p>It is also possible to provide a name inside the definition in order to create a <strong>named</strong> function expression:</p> + +<pre class="brush: js">var myFunction = function namedFunction(){ + statements +} +</pre> + +<p>One of the benefit of creating a named function expression is that in case we encounted an error, the stack trace will contain the name of the function, making it easier to find the origin of the error.</p> + +<p>As we can see, both examples do not start with the <code>function</code> keyword. Statements involving functions which do not start with <code>function</code> are function expressions.</p> + +<p>When functions are used only once, a common pattern is an <strong>IIFE (<em>Immediately Invokable Function Expression</em>)</strong>.</p> + +<pre class="brush: js">(function() { + statements +})();</pre> + +<p>IIFE are function expressions that are invoked as soon as the function is declared.</p> + +<h3 id="The_generator_function_declaration_(function*_statement)">The generator function declaration (<code>function*</code> statement)</h3> + +<p>There is a special syntax for generator function declarations (see {{jsxref('Statements/function*', 'function* statement')}} for details):</p> + +<pre class="syntaxbox">function* <em>name</em>([<em>param</em>[, <em>param</em>[, ... <em>param</em>]]]) { + <em>statements</em> +} +</pre> + +<dl> + <dt><code>name</code></dt> + <dd>The function name.</dd> +</dl> + +<dl> + <dt><code>param</code></dt> + <dd>The name of an argument to be passed to the function. A function can have up to 255 arguments.</dd> +</dl> + +<dl> + <dt><code>statements</code></dt> + <dd>The statements comprising the body of the function.</dd> +</dl> + +<h3 id="The_generator_function_expression_(function*_expression)">The generator function expression (<code>function*</code> expression)</h3> + +<p>A generator function expression is similar to and has the same syntax as a generator function declaration (see {{jsxref('Operators/function*', 'function* expression')}} for details):</p> + +<pre class="syntaxbox">function* [<em>name</em>]([<em>param</em>[, <em>param</em>[, ... <em>param</em>]]]) { + <em>statements</em> +} +</pre> + +<dl> + <dt><code>name</code></dt> + <dd>The function name. Can be omitted, in which case the function becomes known as an anonymous function.</dd> +</dl> + +<dl> + <dt><code>param</code></dt> + <dd>The name of an argument to be passed to the function. A function can have up to 255 arguments.</dd> + <dt><code>statements</code></dt> + <dd>The statements comprising the body of the function.</dd> +</dl> + +<h3 id="The_arrow_function_expression_(>)">The arrow function expression (=>)</h3> + +<p>An arrow function expression has a shorter syntax and lexically binds its <code>this</code> value (see <a href="/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">arrow functions</a> for details):</p> + +<pre class="syntaxbox">([param[, param]]) => { + statements +} + +param => expression +</pre> + +<dl> + <dt><code>param</code></dt> + <dd>The name of an argument. Zero arguments need to be indicated with <code>()</code>. For only one argument, the parentheses are not required. (like <code>foo => 1</code>)</dd> + <dt><code>statements or expression</code></dt> + <dd>Multiple statements need to be enclosed in brackets. A single expression requires no brackets. The expression is also the implicit return value of the function.</dd> +</dl> + +<h3 id="The_Function_constructor">The <code>Function</code> constructor</h3> + +<div class="note"> +<p><strong>Note:</strong> Using the <code>Function</code> constructor to create functions is not recommended since it needs the function body as a string which may prevent some JS engine optimizations and can also cause other problems.</p> +</div> + +<p>As all other objects, {{jsxref("Function")}} objects can be created using the <code>new</code> operator:</p> + +<pre class="syntaxbox">new Function (<em>arg1</em>, <em>arg2</em>, ... <em>argN</em>, <em>functionBody</em>) +</pre> + +<dl> + <dt><code>arg1, arg2, ... arg<em>N</em></code></dt> + <dd>Zero or more names to be used by the function as formal parameters. Each must be a proper JavaScript identifier.</dd> +</dl> + +<dl> + <dt><code>functionBody</code></dt> + <dd>A string containing the JavaScript statements comprising the function body.</dd> +</dl> + +<p>Invoking the <code>Function</code> constructor as a function (without using the <code>new</code> operator) has the same effect as invoking it as a constructor.</p> + +<h3 id="The_GeneratorFunction_constructor">The <code>GeneratorFunction</code> constructor</h3> + +<div class="note"> +<p><strong>Note:</strong> <code>GeneratorFunction</code> is not a global object, but could be obtained from generator function instance (see {{jsxref("GeneratorFunction")}} for more detail).</p> +</div> + +<div class="note"> +<p><strong>Note:</strong> Using the <code>GeneratorFunction</code> constructor to create functions is not recommended since it needs the function body as a string which may prevent some JS engine optimizations and can also cause other problems.</p> +</div> + +<p>As all other objects, {{jsxref("GeneratorFunction")}} objects can be created using the <code>new</code> operator:</p> + +<pre class="syntaxbox">new GeneratorFunction (<em>arg1</em>, <em>arg2</em>, ... <em>argN</em>, <em>functionBody</em>) +</pre> + +<dl> + <dt><code>arg1, arg2, ... arg<em>N</em></code></dt> + <dd>Zero or more names to be used by the function as formal argument names. Each must be a string that conforms to the rules for a valid JavaScript identifier or a list of such strings separated with a comma; for example "<code>x</code>", "<code>theValue</code>", or "<code>a,b</code>".</dd> +</dl> + +<dl> + <dt><code>functionBody</code></dt> + <dd>A string containing the JavaScript statements comprising the function definition.</dd> +</dl> + +<p>Invoking the <code>Function</code> constructor as a function (without using the <code>new</code> operator) has the same effect as invoking it as a constructor.</p> + +<h2 id="Function_parameters">Function parameters</h2> + +<h3 id="Default_parameters">Default parameters</h3> + +<p>Default function parameters allow formal parameters to be initialized with default values if no value or <code>undefined</code> is passed. For more details, see<a href="/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters"> default parameters</a>.</p> + +<h3 id="Rest_parameters">Rest parameters</h3> + +<p>The rest parameter syntax allows to represent an indefinite number of arguments as an array. For more details, see <a href="/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters">rest parameters</a>.</p> + +<h2 id="The_arguments_object">The <code>arguments</code> object</h2> + +<p>You can refer to a function's arguments within the function by using the <code>arguments</code> object. See <a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments">arguments</a>.</p> + +<ul> + <li><code><a href="/en-US/docs/JavaScript/Reference/Functions_and_function_scope/arguments">arguments</a></code>: An array-like object containing the arguments passed to the currently executing function.</li> + <li><code><a href="/en-US/docs/JavaScript/Reference/Functions_and_function_scope/arguments/callee">arguments.callee</a></code> {{Deprecated_inline}}: The currently executing function.</li> + <li><code><a href="/en-US/docs/JavaScript/Reference/Functions_and_function_scope/arguments/caller">arguments.caller</a></code> {{Obsolete_inline}} : The function that invoked the currently executing function.</li> + <li><code><a href="/en-US/docs/JavaScript/Reference/Functions_and_function_scope/arguments/length">arguments.length</a></code>: The number of arguments passed to the function.</li> +</ul> + +<h2 id="Defining_method_functions">Defining method functions</h2> + +<h3 id="Getter_and_setter_functions">Getter and setter functions</h3> + +<p>You can define getters (accessor methods) and setters (mutator methods) on any standard built-in object or user-defined object that supports the addition of new properties. The syntax for defining getters and setters uses the object literal syntax.</p> + +<dl> + <dt><a href="/en-US/docs/Web/JavaScript/Reference/Functions/get">get</a></dt> + <dd> + <p>Binds an object property to a function that will be called when that property is looked up.</p> + </dd> + <dt><a href="/en-US/docs/Web/JavaScript/Reference/Functions/set">set</a></dt> + <dd>Binds an object property to a function to be called when there is an attempt to set that property.</dd> +</dl> + +<h3 id="Method_definition_syntax">Method definition syntax</h3> + +<p>Starting with ECMAScript 2015, you are able to define own methods in a shorter syntax, similar to the getters and setters. See <a href="/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions">method definitions</a> for more information.</p> + +<pre class="brush: js">var obj = { + foo() {}, + bar() {} +};</pre> + +<h2 id="Function_constructor_vs._function_declaration_vs._function_expression"><code>Function</code> constructor vs. function declaration vs. function expression</h2> + +<p>Compare the following:</p> + +<p>A function defined with the <code>Function</code> constructor assigned to the variable <code>multiply:</code></p> + +<pre class="brush: js">var multiply = new Function('x', 'y', 'return x * y');</pre> + +<p>A <em>function declaration</em> of a function named <code>multiply</code>:</p> + +<pre class="brush: js">function multiply(x, y) { + return x * y; +} // there is no semicolon here +</pre> + +<p>A <em>function expression</em> of an anonymous function assigned to the variable <code>multiply:</code></p> + +<pre class="brush: js">var multiply = function(x, y) { + return x * y; +}; +</pre> + +<p>A <em>function expression</em> of a function named <code>func_name</code> assigned to the variable <code>multiply:</code></p> + +<pre class="brush: js">var multiply = function func_name(x, y) { + return x * y; +}; +</pre> + +<h3 id="Differences">Differences</h3> + +<p>All do approximately the same thing, with a few subtle differences:</p> + +<p>There is a distinction between the function name and the variable the function is assigned to. The function name cannot be changed, while the variable the function is assigned to can be reassigned. The function name can be used only within the function's body. Attempting to use it outside the function's body results in an error (or <code>undefined</code> if the function name was previously declared via a <code>var</code> statement). For example:</p> + +<pre class="brush: js">var y = function x() {}; +alert(x); // throws an error +</pre> + +<p>The function name also appears when the function is serialized via <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString"><code>Function</code>'s toString method</a>.</p> + +<p>On the other hand, the variable the function is assigned to is limited only by its scope, which is guaranteed to include the scope in which the function is declared.</p> + +<p>As the 4th example shows, the function name can be different from the variable the function is assigned to. They have no relation to each other. A function declaration also creates a variable with the same name as the function name. Thus, unlike those defined by function expressions, functions defined by function declarations can be accessed by their name in the scope they were defined in:</p> + +<p>A function defined by '<code>new Function'</code> does not have a function name. However, in the <a href="/en-US/docs/Mozilla/Projects/SpiderMonkey">SpiderMonkey</a> JavaScript engine, the serialized form of the function shows as if it has the name "anonymous". For example, <code>alert(new Function())</code> outputs:</p> + +<pre class="brush: js">function anonymous() { +} +</pre> + +<p>Since the function actually does not have a name, <code>anonymous</code> is not a variable that can be accessed within the function. For example, the following would result in an error:</p> + +<pre class="brush: js">var foo = new Function("alert(anonymous);"); +foo(); +</pre> + +<p>Unlike functions defined by function expressions or by the <code>Function</code> constructor, a function defined by a function declaration can be used before the function declaration itself. For example:</p> + +<pre class="brush: js">foo(); // alerts FOO! +function foo() { + alert('FOO!'); +} +</pre> + +<p>A function defined by a function expression or by a function declaration inherits the current scope. That is, the function forms a closure. On the other hand, a function defined by a <code>Function</code> constructor does not inherit any scope other than the global scope (which all functions inherit).</p> + +<pre class="brush: js">/* + * Declare and initialize a variable 'p' (global) + * and a function 'myFunc' (to change the scope) inside which + * declare a varible with same name 'p' (current) and + * define three functions using three different ways:- + * 1. function declaration + * 2. function expression + * 3. function constructor + * each of which will log 'p' + */ +var p = 5; +function myFunc() { + var p = 9; + + function decl() { + console.log(p); + } + var expr = function() { + console.log(p); + }; + var cons = new Function('\tconsole.log(p);'); + + decl(); + expr(); + cons(); +} +myFunc(); + +/* + * Logs:- + * 9 - for 'decl' by function declaration (current scope) + * 9 - for 'expr' by function expression (current scope) + * 5 - for 'cons' by Function constructor (global scope) + */ +</pre> + +<p>Functions defined by function expressions and function declarations are parsed only once, while those defined by the <code>Function</code> constructor are not. That is, the function body string passed to the <code>Function</code> constructor must be parsed each and every time the constructor is called. Although a function expression creates a closure every time, the function body is not reparsed, so function expressions are still faster than "<code>new Function(...)</code>". Therefore the <code>Function</code> constructor should generally be avoided whenever possible.</p> + +<p>It should be noted, however, that function expressions and function declarations nested within the function generated by parsing a <code>Function constructor</code> 's string aren't parsed repeatedly. For example:</p> + +<pre class="brush: js">var foo = (new Function("var bar = \'FOO!\';\nreturn(function() {\n\talert(bar);\n});"))(); +foo(); // The segment "function() {\n\talert(bar);\n}" of the function body string is not re-parsed.</pre> + +<p>A function declaration is very easily (and often unintentionally) turned into a function expression. A function declaration ceases to be one when it either:</p> + +<ul> + <li>becomes part of an expression</li> + <li>is no longer a "source element" of a function or the script itself. A "source element" is a non-nested statement in the script or a function body:</li> +</ul> + +<pre class="brush: js">var x = 0; // source element +if (x === 0) { // source element + x = 10; // not a source element + function boo() {} // not a source element +} +function foo() { // source element + var y = 20; // source element + function bar() {} // source element + while (y === 10) { // source element + function blah() {} // not a source element + y++; // not a source element + } +} +</pre> + +<h3 id="Examples">Examples</h3> + +<pre class="brush: js">// function declaration +function foo() {} + +// function expression +(function bar() {}) + +// function expression +x = function hello() {} + + +if (x) { + // function expression + function world() {} +} + + +// function declaration +function a() { + // function declaration + function b() {} + if (0) { + // function expression + function c() {} + } +} +</pre> + +<h2 id="Block-level_functions">Block-level functions</h2> + +<p>In <a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a>, starting with ES2015, functions inside blocks are now scoped to that block. Prior to ES2015, block-level functions were forbidden in strict mode.</p> + +<pre class="brush: js">'use strict'; + +function f() { + return 1; +} + +{ + function f() { + return 2; + } +} + +f() === 1; // true + +// f() === 2 in non-strict mode +</pre> + +<h3 id="Block-level_functions_in_non-strict_code">Block-level functions in non-strict code</h3> + +<p>In a word: Don't.</p> + +<p>In non-strict code, function declarations inside blocks behave strangely. For example:</p> + +<pre class="brush: js">if (shouldDefineZero) { + function zero() { // DANGER: compatibility risk + console.log("This is zero."); + } +} +</pre> + +<p>ES2015 says that if <code>shouldDefineZero</code> is false, then <code>zero</code> should never be defined, since the block never executes. However, it's a new part of the standard. Historically, this was left unspecified, and some browsers would define <code>zero</code> whether the block executed or not.</p> + +<p>In <a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a>, all browsers that support ES2015 handle this the same way: <code>zero</code> is defined only if <code>shouldDefineZero</code> is true, and only in the scope of the <code>if</code>-block.</p> + +<p>A safer way to define functions conditionally is to assign a function expression to a variable:</p> + +<pre class="brush: js">var zero; +if (shouldDefineZero) { + zero = function() { + console.log("This is zero."); + }; +} +</pre> + +<h2 id="Examples_2">Examples</h2> + +<h3 id="Returning_a_formatted_number">Returning a formatted number</h3> + +<p>The following function returns a string containing the formatted representation of a number padded with leading zeros.</p> + +<pre class="brush: js">// This function returns a string padded with leading zeros +function padZeros(num, totalLen) { + var numStr = num.toString(); // Initialize return value as string + var numZeros = totalLen - numStr.length; // Calculate no. of zeros + for (var i = 1; i <= numZeros; i++) { + numStr = "0" + numStr; + } + return numStr; +} +</pre> + +<p>The following statements call the padZeros function.</p> + +<pre class="brush: js">var result; +result = padZeros(42,4); // returns "0042" +result = padZeros(42,2); // returns "42" +result = padZeros(5,4); // returns "0005" +</pre> + +<h3 id="Determining_whether_a_function_exists">Determining whether a function exists</h3> + +<p>You can determine whether a function exists by using the <code>typeof</code> operator. In the following example, a test is performed to determine if the <code>window</code> object has a property called <code>noFunc</code> that is a function. If so, it is used; otherwise some other action is taken.</p> + +<pre class="brush: js"> if ('function' === typeof window.noFunc) { + // use noFunc() + } else { + // do something else + } +</pre> + +<p>Note that in the <code>if</code> test, a reference to <code>noFunc</code> is used—there are no brackets "()" after the function name so the actual function is not called.</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Initial definition. Implemented in JavaScript 1.0</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-13', 'Function Definition')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-function-definitions', 'Function definitions')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>New: Arrow functions, Generator functions, default parameters, rest parameters.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-function-definitions', 'Function definitions')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("javascript.functions")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{jsxref("Statements/function", "function statement")}}</li> + <li>{{jsxref("Operators/function", "function expression")}}</li> + <li>{{jsxref("Statements/function*", "function* statement")}}</li> + <li>{{jsxref("Operators/function*", "function* expression")}}</li> + <li>{{jsxref("Function")}}</li> + <li>{{jsxref("GeneratorFunction")}}</li> + <li>{{jsxref("Functions/Arrow_functions", "Arrow functions")}}</li> + <li>{{jsxref("Functions/Default_parameters", "Default parameters")}}</li> + <li>{{jsxref("Functions/rest_parameters", "Rest parameters")}}</li> + <li>{{jsxref("Functions/arguments", "Arguments object")}}</li> + <li>{{jsxref("Functions/get", "getter")}}</li> + <li>{{jsxref("Functions/set", "setter")}}</li> + <li>{{jsxref("Functions/Method_definitions", "Method definitions")}}</li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope">Functions and function scope</a></li> +</ul> diff --git a/files/fa/web/javascript/reference/global_objects/array/index.html b/files/fa/web/javascript/reference/global_objects/array/index.html new file mode 100644 index 0000000000..8780c0cb7b --- /dev/null +++ b/files/fa/web/javascript/reference/global_objects/array/index.html @@ -0,0 +1,464 @@ +--- +title: Array +slug: Web/JavaScript/Reference/Global_Objects/Array +tags: + - Array + - Example + - Global Objects + - JavaScript + - NeedsTranslation + - Reference + - TopicStub +translation_of: Web/JavaScript/Reference/Global_Objects/Array +--- +<div>{{JSRef}}</div> + +<div dir="rtl">شیء <strong><code>Array</code></strong> در جاوااسکریپت یک شیء عمومی است که در ساخت آرایه ها استفاده می شود که اشیائی سطح بالا شبیه فهرست هستند.</div> + +<div dir="rtl"></div> + +<p dir="rtl"><strong>ساخت یک آرایه</strong></p> + +<pre class="brush: js">var fruits = ['Apple', 'Banana']; + +console.log(fruits.length); +// 2 +</pre> + +<p dir="rtl"><strong>دسترسی به یک آیتم در آرایه (بر اساس نمایه)</strong></p> + +<pre class="brush: js">var first = fruits[0]; +// Apple + +var last = fruits[fruits.length - 1]; +// Banana +</pre> + +<p dir="rtl"><strong>اجرای حلقه روی آرایه</strong></p> + +<pre class="brush: js">fruits.forEach(function(item, index, array) { + console.log(item, index); +}); +// Apple 0 +// Banana 1 +</pre> + +<p dir="rtl"><strong>اضافه کردن به انتهای آرایه</strong></p> + +<pre class="brush: js">var newLength = fruits.push('Orange'); +// ["Apple", "Banana", "Orange"] +</pre> + +<p dir="rtl"><strong>حذف کردن از انتهای آرایه</strong></p> + +<pre class="brush: js">var last = fruits.pop(); // remove Orange (from the end) +// ["Apple", "Banana"]; +</pre> + +<p dir="rtl"><strong>حذف کردن از ابتدای آرایه</strong></p> + +<pre class="brush: js">var first = fruits.shift(); // remove Apple from the front +// ["Banana"]; +</pre> + +<p dir="rtl"><strong>اضافه کردن به ابتدای آرایه</strong></p> + +<pre class="brush: js">var newLength = fruits.unshift('Strawberry') // add to the front +// ["Strawberry", "Banana"]; +</pre> + +<p dir="rtl"><strong>پیدا کردن نمایه یک آیتم در یک آرایه</strong></p> + +<pre class="brush: js">fruits.push('Mango'); +// ["Strawberry", "Banana", "Mango"] + +var pos = fruits.indexOf('Banana'); +// 1 +</pre> + +<p dir="rtl"><strong>پاک کردن یک آیتم بر اساس موقعیت نمایه</strong></p> + +<pre class="brush: js">var removedItem = fruits.splice(pos, 1); // this is how to remove an item + +// ["Strawberry", "Mango"]</pre> + +<p dir="rtl"><strong>پاک کردن آیتم ها بر اساس موقعیت نمایه</strong></p> + +<pre class="brush: js">var vegetables = ['Cabbage', 'Turnip', 'Radish', 'Carrot']; +console.log(vegetables); +// ["Cabbage", "Turnip", "Radish", "Carrot"] + +var pos = 1, n = 2; + +var removedItems = vegetables.splice(pos, n); +// this is how to remove items, n defines the number of items to be removed, +// from that position(pos) onward to the end of array. + +console.log(vegetables); +// ["Cabbage", "Carrot"] (the original array is changed) + +console.log(removedItems); +// ["Turnip", "Radish"]</pre> + +<p dir="rtl"><strong>کپی کردن یک آرایه</strong></p> + +<pre class="brush: js">var shallowCopy = fruits.slice(); // this is how to make a copy +// ["Strawberry", "Mango"] +</pre> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">[<var>element0</var>, <var>element1</var>, ..., <var>elementN</var>] +new Array(<var>element0</var>, <var>element1</var>[, ...[, <var>elementN</var>]]) +new Array(<var>arrayLength</var>)</pre> + +<h3 id="Parameters">Parameters</h3> + +<dl> + <dt><code>element<em>N</em></code></dt> + <dd>A JavaScript array is initialized with the given elements, except in the case where a single argument is passed to the <code>Array</code> constructor and that argument is a number (see the arrayLength parameter below). Note that this special case only applies to JavaScript arrays created with the <code>Array</code> constructor, not array literals created with the bracket syntax.</dd> + <dt><code>arrayLength</code></dt> + <dd>If the only argument passed to the <code>Array</code> constructor is an integer between 0 and 2<sup>32</sup>-1 (inclusive), this returns a new JavaScript array with its <code>length</code> property set to that number (<strong>Note:</strong> this implies an array of <code>arrayLength</code> empty slots, not slots with actual <code>undefined</code> values). If the argument is any other number, a {{jsxref("RangeError")}} exception is thrown.</dd> +</dl> + +<h2 id="Description">Description</h2> + +<p>Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations. Neither the length of a JavaScript array nor the types of its elements are fixed. Since an array's length can change at any time, and data can be stored at non-contiguous locations in the array, JavaScript arrays are not guaranteed to be dense; this depends on how the programmer chooses to use them. In general, these are convenient characteristics; but if these features are not desirable for your particular use, you might consider using typed arrays.</p> + +<p>Arrays cannot use strings as element indexes (as in an <a href="https://en.wikipedia.org/wiki/Associative_array">associative array</a>) but must use integers. Setting or accessing via non-integers using <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Objects_and_properties">bracket notation</a> (or <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors">dot notation</a>) will not set or retrieve an element from the array list itself, but will set or access a variable associated with that array's <a href="/en-US/docs/Web/JavaScript/Data_structures#Properties">object property collection</a>. The array's object properties and list of array elements are separate, and the array's <a href="/en-US/docs/Web/JavaScript/Guide/Indexed_collections#Array_methods">traversal and mutation operations</a> cannot be applied to these named properties.</p> + +<h3 id="Accessing_array_elements">Accessing array elements</h3> + +<p>JavaScript arrays are zero-indexed: the first element of an array is at index <code>0</code>, and the last element is at the index equal to the value of the array's {{jsxref("Array.length", "length")}} property minus 1. Using an invalid index number returns <code>undefined</code>.</p> + +<pre class="brush: js">var arr = ['this is the first element', 'this is the second element', 'this is the last element']; +console.log(arr[0]); // logs 'this is the first element' +console.log(arr[1]); // logs 'this is the second element' +console.log(arr[arr.length - 1]); // logs 'this is the last element' +</pre> + +<p>Array elements are object properties in the same way that <code>toString</code> is a property, but trying to access an element of an array as follows throws a syntax error because the property name is not valid:</p> + +<pre class="brush: js">console.log(arr.0); // a syntax error +</pre> + +<p>There is nothing special about JavaScript arrays and the properties that cause this. JavaScript properties that begin with a digit cannot be referenced with dot notation; and must be accessed using bracket notation. For example, if you had an object with a property named <code>'3d'</code>, it can only be referenced using bracket notation. E.g.:</p> + +<pre class="brush: js">var years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]; +console.log(years.0); // a syntax error +console.log(years[0]); // works properly +</pre> + +<pre class="brush: js">renderer.3d.setTexture(model, 'character.png'); // a syntax error +renderer['3d'].setTexture(model, 'character.png'); // works properly +</pre> + +<p>Note that in the <code>3d</code> example, <code>'3d'</code> had to be quoted. It's possible to quote the JavaScript array indexes as well (e.g., <code>years['2']</code> instead of <code>years[2]</code>), although it's not necessary. The 2 in <code>years[2]</code> is coerced into a string by the JavaScript engine through an implicit <code>toString</code> conversion. It is, for this reason, that <code>'2'</code> and <code>'02'</code> would refer to two different slots on the <code>years</code> object and the following example could be <code>true</code>:</p> + +<pre class="brush: js">console.log(years['2'] != years['02']); +</pre> + +<p>Similarly, object properties which happen to be reserved words(!) can only be accessed as string literals in bracket notation (but it can be accessed by dot notation in firefox 40.0a2 at least):</p> + +<pre class="brush: js">var promise = { + 'var' : 'text', + 'array': [1, 2, 3, 4] +}; + +console.log(promise['var']); +</pre> + +<h3 id="Relationship_between_length_and_numerical_properties">Relationship between <code>length</code> and numerical properties</h3> + +<p>A JavaScript array's {{jsxref("Array.length", "length")}} property and numerical properties are connected. Several of the built-in array methods (e.g., {{jsxref("Array.join", "join()")}}, {{jsxref("Array.slice", "slice()")}}, {{jsxref("Array.indexOf", "indexOf()")}}, etc.) take into account the value of an array's {{jsxref("Array.length", "length")}} property when they're called. Other methods (e.g., {{jsxref("Array.push", "push()")}}, {{jsxref("Array.splice", "splice()")}}, etc.) also result in updates to an array's {{jsxref("Array.length", "length")}} property.</p> + +<pre class="brush: js">var fruits = []; +fruits.push('banana', 'apple', 'peach'); + +console.log(fruits.length); // 3 +</pre> + +<p>When setting a property on a JavaScript array when the property is a valid array index and that index is outside the current bounds of the array, the engine will update the array's {{jsxref("Array.length", "length")}} property accordingly:</p> + +<pre class="brush: js">fruits[5] = 'mango'; +console.log(fruits[5]); // 'mango' +console.log(Object.keys(fruits)); // ['0', '1', '2', '5'] +console.log(fruits.length); // 6 +</pre> + +<p>Increasing the {{jsxref("Array.length", "length")}}.</p> + +<pre class="brush: js">fruits.length = 10; +console.log(Object.keys(fruits)); // ['0', '1', '2', '5'] +console.log(fruits.length); // 10 +</pre> + +<p>Decreasing the {{jsxref("Array.length", "length")}} property does, however, delete elements.</p> + +<pre class="brush: js">fruits.length = 2; +console.log(Object.keys(fruits)); // ['0', '1'] +console.log(fruits.length); // 2 +</pre> + +<p>This is explained further on the {{jsxref("Array.length")}} page.</p> + +<h3 id="Creating_an_array_using_the_result_of_a_match">Creating an array using the result of a match</h3> + +<p>The result of a match between a regular expression and a string can create a JavaScript array. This array has properties and elements which provide information about the match. Such an array is returned by {{jsxref("RegExp.exec")}}, {{jsxref("String.match")}}, and {{jsxref("String.replace")}}. To help explain these properties and elements, look at the following example and then refer to the table below:</p> + +<pre class="brush: js">// Match one d followed by one or more b's followed by one d +// Remember matched b's and the following d +// Ignore case + +var myRe = /d(b+)(d)/i; +var myArray = myRe.exec('cdbBdbsbz'); +</pre> + +<p>The properties and elements returned from this match are as follows:</p> + +<table class="fullwidth-table"> + <tbody> + <tr> + <td class="header">Property/Element</td> + <td class="header">Description</td> + <td class="header">Example</td> + </tr> + <tr> + <td><code>input</code></td> + <td>A read-only property that reflects the original string against which the regular expression was matched.</td> + <td>cdbBdbsbz</td> + </tr> + <tr> + <td><code>index</code></td> + <td>A read-only property that is the zero-based index of the match in the string.</td> + <td>1</td> + </tr> + <tr> + <td><code>[0]</code></td> + <td>A read-only element that specifies the last matched characters.</td> + <td>dbBd</td> + </tr> + <tr> + <td><code>[1], ...[n]</code></td> + <td>Read-only elements that specify the parenthesized substring matches, if included in the regular expression. The number of possible parenthesized substrings is unlimited.</td> + <td>[1]: bB<br> + [2]: d</td> + </tr> + </tbody> +</table> + +<h2 id="Properties">Properties</h2> + +<dl> + <dt><code>Array.length</code></dt> + <dd>The <code>Array</code> constructor's length property whose value is 1.</dd> + <dt>{{jsxref("Array.@@species", "get Array[@@species]")}}</dt> + <dd>The constructor function that is used to create derived objects.</dd> + <dt>{{jsxref("Array.prototype")}}</dt> + <dd>Allows the addition of properties to all array objects.</dd> +</dl> + +<h2 id="Methods">Methods</h2> + +<dl> + <dt>{{jsxref("Array.from()")}}</dt> + <dd>Creates a new <code>Array</code> instance from an array-like or iterable object.</dd> + <dt>{{jsxref("Array.isArray()")}}</dt> + <dd>Returns true if a variable is an array, if not false.</dd> + <dt>{{jsxref("Array.of()")}}</dt> + <dd>Creates a new <code>Array</code> instance with a variable number of arguments, regardless of number or type of the arguments.</dd> +</dl> + +<h2 id="Array_instances"><code>Array</code> instances</h2> + +<p>All <code>Array</code> instances inherit from {{jsxref("Array.prototype")}}. The prototype object of the <code>Array</code> constructor can be modified to affect all <code>Array</code> instances.</p> + +<h3 id="Properties_2">Properties</h3> + +<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype', 'Properties')}}</div> + +<h3 id="Methods_2">Methods</h3> + +<h4 id="Mutator_methods">Mutator methods</h4> + +<div>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype', 'Mutator_methods')}}</div> + +<h4 id="Accessor_methods">Accessor methods</h4> + +<div>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype', 'Accessor_methods')}}</div> + +<h4 id="Iteration_methods">Iteration methods</h4> + +<div>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype', 'Iteration_methods')}}</div> + +<h2 id="Array_generic_methods"><code>Array</code> generic methods</h2> + +<div class="warning"> +<p><strong>Array generics are non-standard, deprecated and will get removed in the near future</strong>.</p> +</div> + +<p>{{Obsolete_Header("Gecko71")}}</p> + +<p>Sometimes you would like to apply array methods to strings or other array-like objects (such as function {{jsxref("Functions/arguments", "arguments", "", 1)}}). By doing this, you treat a string as an array of characters (or otherwise treat a non-array as an array). For example, in order to check that every character in the variable <var>str</var> is a letter, you would write:</p> + +<pre class="brush: js">function isLetter(character) { + return character >= 'a' && character <= 'z'; +} + +if (Array.prototype.every.call(str, isLetter)) { + console.log("The string '" + str + "' contains only letters!"); +} +</pre> + +<p>This notation is rather wasteful and JavaScript 1.6 introduced a generic shorthand:</p> + +<pre class="brush: js">if (Array.every(str, isLetter)) { + console.log("The string '" + str + "' contains only letters!"); +} +</pre> + +<p>{{jsxref("Global_Objects/String", "Generics", "#String_generic_methods", 1)}} are also available on {{jsxref("String")}}.</p> + +<p>These are <strong>not</strong> part of ECMAScript standards and they are not supported by non-Gecko browsers. As a standard alternative, you can convert your object to a proper array using {{jsxref("Array.from()")}}; although that method may not be supported in old browsers:</p> + +<pre class="brush: js">if (Array.from(str).every(isLetter)) { + console.log("The string '" + str + "' contains only letters!"); +} +</pre> + +<h2 id="Examples">Examples</h2> + +<h3 id="Creating_an_array">Creating an array</h3> + +<p>The following example creates an array, <code>msgArray</code>, with a length of 0, then assigns values to <code>msgArray[0]</code> and <code>msgArray[99]</code>, changing the length of the array to 100.</p> + +<pre class="brush: js">var msgArray = []; +msgArray[0] = 'Hello'; +msgArray[99] = 'world'; + +if (msgArray.length === 100) { + console.log('The length is 100.'); +} +</pre> + +<h3 id="Creating_a_two-dimensional_array">Creating a two-dimensional array</h3> + +<p>The following creates a chess board as a two-dimensional array of strings. The first move is made by copying the 'p' in (6,4) to (4,4). The old position (6,4) is made blank.</p> + +<pre class="brush: js">var board = [ + ['R','N','B','Q','K','B','N','R'], + ['P','P','P','P','P','P','P','P'], + [' ',' ',' ',' ',' ',' ',' ',' '], + [' ',' ',' ',' ',' ',' ',' ',' '], + [' ',' ',' ',' ',' ',' ',' ',' '], + [' ',' ',' ',' ',' ',' ',' ',' '], + ['p','p','p','p','p','p','p','p'], + ['r','n','b','q','k','b','n','r'] ]; + +console.log(board.join('\n') + '\n\n'); + +// Move King's Pawn forward 2 +board[4][4] = board[6][4]; +board[6][4] = ' '; +console.log(board.join('\n')); +</pre> + +<p>Here is the output:</p> + +<pre class="eval">R,N,B,Q,K,B,N,R +P,P,P,P,P,P,P,P + , , , , , , , + , , , , , , , + , , , , , , , + , , , , , , , +p,p,p,p,p,p,p,p +r,n,b,q,k,b,n,r + +R,N,B,Q,K,B,N,R +P,P,P,P,P,P,P,P + , , , , , , , + , , , , , , , + , , , ,p, , , + , , , , , , , +p,p,p,p, ,p,p,p +r,n,b,q,k,b,n,r +</pre> + +<h3 id="Using_an_array_to_tabulate_a_set_of_values">Using an array to tabulate a set of values</h3> + +<pre class="brush: js">values = []; +for (var x = 0; x < 10; x++){ + values.push([ + 2 ** x, + 2 * x ** 2 + ]) +}; +console.table(values)</pre> + +<p>Results in</p> + +<pre class="eval">0 1 0 +1 2 2 +2 4 8 +3 8 18 +4 16 32 +5 32 50 +6 64 72 +7 128 98 +8 256 128 +9 512 162</pre> + +<p>(First column is the (index))</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.4', 'Array')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td>New methods added: {{jsxref("Array.isArray")}}, {{jsxref("Array.prototype.indexOf", "indexOf")}}, {{jsxref("Array.prototype.lastIndexOf", "lastIndexOf")}}, {{jsxref("Array.prototype.every", "every")}}, {{jsxref("Array.prototype.some", "some")}}, {{jsxref("Array.prototype.forEach", "forEach")}}, {{jsxref("Array.prototype.map", "map")}}, {{jsxref("Array.prototype.filter", "filter")}}, {{jsxref("Array.prototype.reduce", "reduce")}}, {{jsxref("Array.prototype.reduceRight", "reduceRight")}}</td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-array-objects', 'Array')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>New methods added: {{jsxref("Array.from")}}, {{jsxref("Array.of")}}, {{jsxref("Array.prototype.find", "find")}}, {{jsxref("Array.prototype.findIndex", "findIndex")}}, {{jsxref("Array.prototype.fill", "fill")}}, {{jsxref("Array.prototype.copyWithin", "copyWithin")}}</td> + </tr> + <tr> + <td>{{SpecName('ES7', '#sec-array-objects', 'Array')}}</td> + <td>{{Spec2('ES7')}}</td> + <td>New method added: {{jsxref("Array.prototype.includes()")}}</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-array-objects', 'Array')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("javascript.builtins.Array")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Indexing_object_properties">JavaScript Guide: “Indexing object properties”</a></li> + <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Indexed_collections#Array_object">JavaScript Guide: “Indexed collections: <code>Array</code> object”</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Array_comprehensions">Array comprehensions</a></li> + <li><a href="https://github.com/plusdude/array-generics">Polyfill for JavaScript 1.8.5 Array Generics and ECMAScript 5 Array Extras</a></li> + <li><a href="/en-US/docs/JavaScript_typed_arrays">Typed Arrays</a></li> +</ul> diff --git a/files/fa/web/javascript/reference/global_objects/array/of/index.html b/files/fa/web/javascript/reference/global_objects/array/of/index.html new file mode 100644 index 0000000000..0c5aa6d2fa --- /dev/null +++ b/files/fa/web/javascript/reference/global_objects/array/of/index.html @@ -0,0 +1,102 @@ +--- +title: Array.of() +slug: Web/JavaScript/Reference/Global_Objects/Array/of +translation_of: Web/JavaScript/Reference/Global_Objects/Array/of +--- +<div>{{JSRef}}</div> + +<div>متد Array.of() یک آرایه ی جدید شامل آرگومان های ارسال شده به آن میباشد میسازد، صرفنظر از تعداد و نوع آرگومان ها. </div> + +<p>تفاوت متد Array.of() و متد سازنده ی Array() در این میباشد که Array.of(7) یک آرایه با یک المنت که مقدارش 7 میباشد میسازد. در حالیکه Array(7) یک آرایه ی جدید با طول 7 که شامل 7 المنت یا slot با مقدار empty میسازد نه با مقدار undefined.</p> + +<pre class="brush: js">Array.of(7); // [7] +Array.of(1, 2, 3); // [1, 2, 3] + +Array(7); // array of 7 empty slots +Array(1, 2, 3); // [1, 2, 3] +</pre> + +<h2 id="نحوه_استفاده">نحوه استفاده</h2> + +<pre class="syntaxbox">Array.of(<var>element0</var>[, <var>element1</var>[, ...[, <var>elementN</var>]]])</pre> + +<h3 id="پارامترها">پارامترها</h3> + +<dl> + <dt><code>element<em>N</em></code></dt> + <dd>لیست المنت هایی که باید درون آرایه قرار بگیرند.</dd> +</dl> + +<h3 id="مقدار_بازگشتی">مقدار بازگشتی</h3> + +<p>یک نمونه جدید از {{jsxref("Array")}} .</p> + +<h2 id="توضیحات">توضیحات</h2> + +<p>این تابع بخشی از ECMAScript 2015 استاندارد است. برای اطلاعات بیشتر لینک های زیر مراجعه کنید:</p> + +<p dir="ltr"><a href="https://gist.github.com/rwaldron/1074126"><code>Array.of</code></a> و <a href="https://gist.github.com/rwaldron/1074126"><code>Array.from</code> proposal</a> و <a href="https://gist.github.com/rwaldron/3186576"><code>Array.of</code> polyfill</a>.</p> + +<h2 id="مثال">مثال</h2> + +<pre class="brush: js">Array.of(1); // [1] +Array.of(1, 2, 3); // [1, 2, 3] +Array.of(undefined); // [undefined] +</pre> + +<h2 id="چند_کاره_سازی">چند کاره سازی</h2> + +<p>در صورت عدم وجود <code>Array.of()</code> به صورت پیشفرض، با اجرای کد زیر قبل اجرای سایر کدها، تابع <code>Array.of()</code> را برای شما در کلاس Array پیاده سازی و قابل استفاده می نماید. برید حالشو ببرید.</p> + +<pre class="brush: js">if (!Array.of) { + Array.of = function() { + return Array.prototype.slice.call(arguments); + // Or + let vals = []; + for(let prop in arguments){ + vals.push(arguments[prop]); + } + return vals; + } +} +</pre> + +<h2 id="مشخصه_ها">مشخصه ها</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">مشخصه</th> + <th scope="col">وضعیت</th> + <th scope="col">توضیح</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ESDraft', '#sec-array.of', 'Array.of')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('ES2015', '#sec-array.of', 'Array.of')}}</td> + <td>{{Spec2('ES2015')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="سازگاری_با_سایر_مرورگرها">سازگاری با سایر مرورگرها</h2> + +<div> + + +<p>{{Compat("javascript.builtins.Array.of")}}</p> +</div> + +<h2 id="همچنین_ببینید"><strong>همچنین ببینید</strong></h2> + +<ul> + <li>{{jsxref("Array")}}</li> + <li>{{jsxref("Array.from()")}}</li> + <li>{{jsxref("TypedArray.of()")}}</li> +</ul> diff --git a/files/fa/web/javascript/reference/global_objects/array/reduce/index.html b/files/fa/web/javascript/reference/global_objects/array/reduce/index.html new file mode 100644 index 0000000000..6145fa772e --- /dev/null +++ b/files/fa/web/javascript/reference/global_objects/array/reduce/index.html @@ -0,0 +1,579 @@ +--- +title: Array.prototype.reduce() +slug: Web/JavaScript/Reference/Global_Objects/Array/Reduce +translation_of: Web/JavaScript/Reference/Global_Objects/Array/Reduce +--- +<div>{{JSRef}}</div> + +<p> The <code><strong>reduce()</strong></code> method executes a <strong>reducer</strong> function (that you provide) on each element of the array, resulting in a single output value.</p> + +<p style="direction: rtl;">متد reduce یک تابع reducer (کاهش دهنده) را بر روی هر کدام از المانهای آرایه اجرا میکند و در خروجی یک آرایه برمیگرداند. توجه داشته باشید که تابع reducer را شما باید بنویسید.</p> + +<div style="direction: rtl;">{{EmbedInteractiveExample("pages/js/array-reduce.html")}}</div> + + + +<p style="direction: rtl;">یک تابع کاهش دهنده 4 آرگومان دریافت میکند</p> + +<p>The <strong>reducer</strong> function takes four arguments:</p> + +<ol> + <li>Accumulator (acc) (انباشت کننده)</li> + <li>Current Value (cur) (مقدار فعلی)</li> + <li>Current Index (idx) (اندیس فعلی)</li> + <li>Source Array (src) (آرایهی مبدا)</li> +</ol> + +<p>Your <strong>reducer</strong> function's returned value is assigned to the accumulator, whose value is remembered across each iteration throughout the array and ultimately becomes the final, single resulting value.</p> + +<p style="direction: rtl;">بنابراین آرگومان اول تابع reduce، کاهش دهنده، و آرگومان دوم، انباشتگر میباشد. به این ترتیب پس از اعمال کاهش دهنده بر روی هر کدام از المانهای آرایه، انباشت کننده یا اکیومیولیتور نیز اعمال اثر میکند.</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox"><var>arr.reduce(callback(accumulator, currentValue[, index[, array]])[, initialValue])</var></pre> + +<h3 id="Parameters">Parameters</h3> + +<dl> + <dt><code>callback</code></dt> + <dd>A function to execute on each element in the array (except for the first, if no <code>initialValue</code> is supplied), taking four arguments: + <dl> + <dt><code>accumulator</code></dt> + <dd>The accumulator accumulates the callback's return values. It is the accumulated value previously returned in the last invocation of the callback, or <code>initialValue</code>, if supplied (see below).</dd> + <dt><code>currentValue</code></dt> + <dd>The current element being processed in the array.</dd> + <dt><code>index</code> {{optional_inline}}</dt> + <dd>The index of the current element being processed in the array. Starts from index 0 if an <code>initialValue</code> is provided. Otherwise, starts from index 1.</dd> + <dt><code>array</code> {{optional_inline}}</dt> + <dd>The array <code>reduce()</code> was called upon.</dd> + </dl> + </dd> + <dt><code>initialValue</code> {{optional_inline}}</dt> + <dd>A value to use as the first argument to the first call of the <code>callback</code>. If no <code>initialValue</code> is supplied, the first element in the array will be used and skipped. Calling <code>reduce()</code> on an empty array without an <code>initialValue</code> will throw a <code>TypeError</code>.</dd> +</dl> + +<h3 id="Return_value">Return value</h3> + +<p>The single value that results from the reduction.</p> + +<p style="direction: rtl;">مقدار بازگشتی مقداری واحد است.</p> + +<h2 id="Description">Description</h2> + +<p>The <code>reduce()</code> method executes the <code>callback</code> once for each assigned value present in the array, taking four arguments:</p> + +<p style="direction: rtl;">تابع reduce، کال بک را یک بار بر روی مقدارهای الصاق شده در ارایه اعمال می کند و چهار ارگومان (ورودی) زیر را می پذیرد.</p> + +<ul> + <li><code>accumulator</code></li> + <li><code>currentValue</code></li> + <li><code>currentIndex</code></li> + <li><code>array</code></li> +</ul> + +<p>The first time the callback is called, <code>accumulator</code> and <code>currentValue</code> can be one of two values. If <code>initialValue</code> is provided in the call to <code>reduce()</code>, then <code>accumulator</code> will be equal to <code>initialValue</code>, and <code>currentValue</code> will be equal to the first value in the array. If no <code>initialValue</code> is provided, then <code>accumulator</code> will be equal to the first value in the array, and <code>currentValue</code> will be equal to the second.</p> + +<div class="note"> +<p><strong>Note:</strong> If <code>initialValue</code> is not provided, <code>reduce()</code> will execute the callback function starting at index 1, skipping the first index. If <code>initialValue</code> is provided, it will start at index 0.</p> +</div> + +<p>If the array is empty and no <code>initialValue</code> is provided, {{jsxref("TypeError")}} will be thrown. If the array only has one element (regardless of position) and no <code>initialValue</code> is provided, or if <code>initialValue</code> is provided but the array is empty, the solo value will be returned <em>without </em>calling<em> <code>callback</code>.</em></p> + +<p>It is usually safer to provide an <code>initialValue</code> because there are three possible outputs without <code>initialValue</code>, as shown in the following example.</p> + +<p style="direction: rtl;">برای احتیاط بهتر است که همیشه یک initialValue یا مقدار اولیه درنظر گرفت زیرا در صورت در نظر نگرفتن مقدار اولیه سه حالت ممکن است رخ دهد که در مثال زیر توضیح داده شده است.</p> + +<pre class="brush: js">var maxCallback = ( acc, cur ) => Math.max( acc.x, cur.x ); +var maxCallback2 = ( max, cur ) => Math.max( max, cur ); + +// reduce() without initialValue +[ { x: 22 }, { x: 42 } ].reduce( maxCallback ); // 42 +[ { x: 22 } ].reduce( maxCallback ); // { x: 22 } +[ ].reduce( maxCallback ); // TypeError + +// map/reduce; better solution, also works for empty or larger arrays +[ { x: 22 }, { x: 42 } ].map( el => el.x ) + .reduce( maxCallback2, -Infinity ); +</pre> + +<h3 id="How_reduce_works">How reduce() works</h3> + +<p>Suppose the following use of <code>reduce()</code> occurred:</p> + +<pre class="brush: js">[0, 1, 2, 3, 4].reduce(function(accumulator, currentValue, currentIndex, array) { + return accumulator + currentValue; +}); +</pre> + +<p>The callback would be invoked four times, with the arguments and return values in each call being as follows:</p> + +<table> + <thead> + <tr> + <th scope="col"><code>callback</code></th> + <th scope="col"><code>accumulator</code></th> + <th scope="col"><code>currentValue</code></th> + <th scope="col"><code>currentIndex</code></th> + <th scope="col"><code>array</code></th> + <th scope="col">return value</th> + </tr> + </thead> + <tbody> + <tr> + <th scope="row">first call</th> + <td><code>0</code></td> + <td><code>1</code></td> + <td><code>1</code></td> + <td><code>[0, 1, 2, 3, 4]</code></td> + <td><code>1</code></td> + </tr> + <tr> + <th scope="row">second call</th> + <td><code>1</code></td> + <td><code>2</code></td> + <td><code>2</code></td> + <td><code>[0, 1, 2, 3, 4]</code></td> + <td><code>3</code></td> + </tr> + <tr> + <th scope="row">third call</th> + <td><code>3</code></td> + <td><code>3</code></td> + <td><code>3</code></td> + <td><code>[0, 1, 2, 3, 4]</code></td> + <td><code>6</code></td> + </tr> + <tr> + <th scope="row">fourth call</th> + <td><code>6</code></td> + <td><code>4</code></td> + <td><code>4</code></td> + <td><code>[0, 1, 2, 3, 4]</code></td> + <td><code>10</code></td> + </tr> + </tbody> +</table> + +<p>The value returned by <code>reduce()</code> would be that of the last callback invocation (<code>10</code>).</p> + +<p>You can also provide an {{jsxref("Functions/Arrow_functions", "Arrow Function","",1)}} instead of a full function. The code below will produce the same output as the code in the block above:</p> + +<pre class="brush: js">[0, 1, 2, 3, 4].reduce( (accumulator, currentValue, currentIndex, array) => accumulator + currentValue ); +</pre> + +<p>If you were to provide an <code>initialValue</code> as the second argument to <code>reduce()</code>, the result would look like this:</p> + +<pre class="brush: js">[0, 1, 2, 3, 4].reduce((accumulator, currentValue, currentIndex, array) => { + return accumulator + currentValue; +}, 10); +</pre> + +<table> + <thead> + <tr> + <th scope="col"><code>callback</code></th> + <th scope="col"><code>accumulator</code></th> + <th scope="col"><code>currentValue</code></th> + <th scope="col"><code>currentIndex</code></th> + <th scope="col"><code>array</code></th> + <th scope="col">return value</th> + </tr> + </thead> + <tbody> + <tr> + <th scope="row">first call</th> + <td><code>10</code></td> + <td><code>0</code></td> + <td><code>0</code></td> + <td><code>[0, 1, 2, 3, 4]</code></td> + <td><code>10</code></td> + </tr> + <tr> + <th scope="row">second call</th> + <td><code>10</code></td> + <td><code>1</code></td> + <td><code>1</code></td> + <td><code>[0, 1, 2, 3, 4]</code></td> + <td><code>11</code></td> + </tr> + <tr> + <th scope="row">third call</th> + <td><code>11</code></td> + <td><code>2</code></td> + <td><code>2</code></td> + <td><code>[0, 1, 2, 3, 4]</code></td> + <td><code>13</code></td> + </tr> + <tr> + <th scope="row">fourth call</th> + <td><code>13</code></td> + <td><code>3</code></td> + <td><code>3</code></td> + <td><code>[0, 1, 2, 3, 4]</code></td> + <td><code>16</code></td> + </tr> + <tr> + <th scope="row">fifth call</th> + <td><code>16</code></td> + <td><code>4</code></td> + <td><code>4</code></td> + <td><code>[0, 1, 2, 3, 4]</code></td> + <td><code>20</code></td> + </tr> + </tbody> +</table> + +<p>The value returned by <code>reduce()</code> in this case would be <code>20</code>.</p> + +<h2 id="Examples">Examples</h2> + +<h3 id="Sum_all_the_values_of_an_array">Sum all the values of an array</h3> + +<pre class="brush: js">var sum = [0, 1, 2, 3].reduce(function (accumulator, currentValue) { + return accumulator + currentValue; +}, 0); +// sum is 6 + +</pre> + +<p>Alternatively written with an arrow function:</p> + +<pre class="brush: js">var total = [ 0, 1, 2, 3 ].reduce( + ( accumulator, currentValue ) => accumulator + currentValue, + 0 +);</pre> + +<h3 id="Sum_of_values_in_an_object_array">Sum of values in an object array</h3> + +<p>To sum up the values contained in an array of objects, you <strong>must</strong> supply an <code>initialValue</code>, so that each item passes through your function.</p> + +<pre class="brush: js">var initialValue = 0; +var sum = [{x: 1}, {x: 2}, {x: 3}].reduce(function (accumulator, currentValue) { + return accumulator + currentValue.x; +},initialValue) + +console.log(sum) // logs 6 +</pre> + +<p>Alternatively written with an arrow function:</p> + +<pre class="brush: js">var initialValue = 0; +var sum = [{x: 1}, {x: 2}, {x: 3}].reduce( + (accumulator, currentValue) => accumulator + currentValue.x + ,initialValue +); + +console.log(sum) // logs 6</pre> + +<h3 id="Flatten_an_array_of_arrays">Flatten an array of arrays</h3> + +<pre class="brush: js">var flattened = [[0, 1], [2, 3], [4, 5]].reduce( + function(accumulator, currentValue) { + return accumulator.concat(currentValue); + }, + [] +); +// flattened is [0, 1, 2, 3, 4, 5] +</pre> + +<p>Alternatively written with an arrow function:</p> + +<pre class="brush: js">var flattened = [[0, 1], [2, 3], [4, 5]].reduce( + ( accumulator, currentValue ) => accumulator.concat(currentValue), + [] +); +</pre> + +<h3 id="Counting_instances_of_values_in_an_object">Counting instances of values in an object</h3> + +<pre class="brush: js">var names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice']; + +var countedNames = names.reduce(function (allNames, name) { + if (name in allNames) { + allNames[name]++; + } + else { + allNames[name] = 1; + } + return allNames; +}, {}); +// countedNames is: +// { 'Alice': 2, 'Bob': 1, 'Tiff': 1, 'Bruce': 1 } +</pre> + +<h3 id="Grouping_objects_by_a_property">Grouping objects by a property</h3> + +<pre class="brush: js">var people = [ + { name: 'Alice', age: 21 }, + { name: 'Max', age: 20 }, + { name: 'Jane', age: 20 } +]; + +function groupBy(objectArray, property) { + return objectArray.reduce(function (acc, obj) { + var key = obj[property]; + if (!acc[key]) { + acc[key] = []; + } + acc[key].push(obj); + return acc; + }, {}); +} + +var groupedPeople = groupBy(people, 'age'); +// groupedPeople is: +// { +// 20: [ +// { name: 'Max', age: 20 }, +// { name: 'Jane', age: 20 } +// ], +// 21: [{ name: 'Alice', age: 21 }] +// } +</pre> + +<h3 id="Bonding_arrays_contained_in_an_array_of_objects_using_the_spread_operator_and_initialValue">Bonding arrays contained in an array of objects using the spread operator and initialValue</h3> + +<pre class="brush: js">// friends - an array of objects +// where object field "books" - list of favorite books +var friends = [{ + name: 'Anna', + books: ['Bible', 'Harry Potter'], + age: 21 +}, { + name: 'Bob', + books: ['War and peace', 'Romeo and Juliet'], + age: 26 +}, { + name: 'Alice', + books: ['The Lord of the Rings', 'The Shining'], + age: 18 +}]; + +// allbooks - list which will contain all friends' books + +// additional list contained in initialValue +var allbooks = friends.reduce(function(accumulator, currentValue) { + return [...accumulator, ...currentValue.books]; +}, ['Alphabet']); + +// allbooks = [ +// 'Alphabet', 'Bible', 'Harry Potter', 'War and peace', +// 'Romeo and Juliet', 'The Lord of the Rings', +// 'The Shining' +// ]</pre> + +<h3 id="Remove_duplicate_items_in_array">Remove duplicate items in array</h3> + +<div class="blockIndicator note"> +<p><strong>Note:</strong> If you are using an environment compatible with {{jsxref("Set")}} and {{jsxref("Array.from()")}}, you could use <code>let orderedArray = Array.from(new Set(myArray));</code> to get an array where duplicate items have been removed.</p> +</div> + +<pre class="brush: js">var myArray = ['a', 'b', 'a', 'b', 'c', 'e', 'e', 'c', 'd', 'd', 'd', 'd']; +var myOrderedArray = myArray.reduce(function (accumulator, currentValue) { + if (accumulator.indexOf(currentValue) === -1) { + accumulator.push(currentValue); + } + return accumulator +}, []) + +console.log(myOrderedArray);</pre> + +<h3 id="Running_Promises_in_Sequence">Running Promises in Sequence</h3> + +<pre class="brush: js">/** + * Runs promises from array of functions that can return promises + * in chained manner + * + * @param {array} arr - promise arr + * @return {Object} promise object + */ +function runPromiseInSequence(arr, input) { + return arr.reduce( + (promiseChain, currentFunction) => promiseChain.then(currentFunction), + Promise.resolve(input) + ); +} + +// promise function 1 +function p1(a) { + return new Promise((resolve, reject) => { + resolve(a * 5); + }); +} + +// promise function 2 +function p2(a) { + return new Promise((resolve, reject) => { + resolve(a * 2); + }); +} + +// function 3 - will be wrapped in a resolved promise by .then() +function f3(a) { + return a * 3; +} + +// promise function 4 +function p4(a) { + return new Promise((resolve, reject) => { + resolve(a * 4); + }); +} + +const promiseArr = [p1, p2, f3, p4]; +runPromiseInSequence(promiseArr, 10) + .then(console.log); // 1200 +</pre> + +<h3 id="Function_composition_enabling_piping">Function composition enabling piping</h3> + +<pre class="brush: js">// Building-blocks to use for composition +const double = x => x + x; +const triple = x => 3 * x; +const quadruple = x => 4 * x; + +// Function composition enabling pipe functionality +const pipe = (...functions) => input => functions.reduce( + (acc, fn) => fn(acc), + input +); + +// Composed functions for multiplication of specific values +const multiply6 = pipe(double, triple); +const multiply9 = pipe(triple, triple); +const multiply16 = pipe(quadruple, quadruple); +const multiply24 = pipe(double, triple, quadruple); + +// Usage +multiply6(6); // 36 +multiply9(9); // 81 +multiply16(16); // 256 +multiply24(10); // 240 + +</pre> + +<h3 id="write_map_using_reduce">write map using reduce</h3> + +<pre class="brush: js">if (!Array.prototype.mapUsingReduce) { + Array.prototype.mapUsingReduce = function(callback, thisArg) { + return this.reduce(function(mappedArray, currentValue, index, array) { + mappedArray[index] = callback.call(thisArg, currentValue, index, array); + return mappedArray; + }, []); + }; +} + +[1, 2, , 3].mapUsingReduce( + (currentValue, index, array) => currentValue + index + array.length +); // [5, 7, , 10] + +</pre> + +<h2 id="Polyfill">Polyfill</h2> + +<pre class="brush: js">// Production steps of ECMA-262, Edition 5, 15.4.4.21 +// Reference: http://es5.github.io/#x15.4.4.21 +// https://tc39.github.io/ecma262/#sec-array.prototype.reduce +if (!Array.prototype.reduce) { + Object.defineProperty(Array.prototype, 'reduce', { + value: function(callback /*, initialValue*/) { + if (this === null) { + throw new TypeError( 'Array.prototype.reduce ' + + 'called on null or undefined' ); + } + if (typeof callback !== 'function') { + throw new TypeError( callback + + ' is not a function'); + } + + // 1. Let O be ? ToObject(this value). + var o = Object(this); + + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = o.length >>> 0; + + // Steps 3, 4, 5, 6, 7 + var k = 0; + var value; + + if (arguments.length >= 2) { + value = arguments[1]; + } else { + while (k < len && !(k in o)) { + k++; + } + + // 3. If len is 0 and initialValue is not present, + // throw a TypeError exception. + if (k >= len) { + throw new TypeError( 'Reduce of empty array ' + + 'with no initial value' ); + } + value = o[k++]; + } + + // 8. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + // b. Let kPresent be ? HasProperty(O, Pk). + // c. If kPresent is true, then + // i. Let kValue be ? Get(O, Pk). + // ii. Let accumulator be ? Call( + // callbackfn, undefined, + // « accumulator, kValue, k, O »). + if (k in o) { + value = callback(value, o[k], k, o); + } + + // d. Increase k by 1. + k++; + } + + // 9. Return accumulator. + return value; + } + }); +} +</pre> + +<p>If you need to support truly obsolete JavaScript engines that do not support <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty">Object.defineProperty()</a></code>, it is best not to polyfill <code>Array.prototype</code> methods at all, as you cannot make them <strong>non-enumerable</strong>.</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.4.4.21', 'Array.prototype.reduce()')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td>Initial definition. Implemented in JavaScript 1.8.</td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-array.prototype.reduce', 'Array.prototype.reduce()')}}</td> + <td>{{Spec2('ES6')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-array.prototype.reduce', 'Array.prototype.reduce()')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("javascript.builtins.Array.reduce")}}</p> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{jsxref("Array.prototype.reduceRight()")}}</li> +</ul> diff --git a/files/fa/web/javascript/reference/global_objects/function/index.html b/files/fa/web/javascript/reference/global_objects/function/index.html new file mode 100644 index 0000000000..4c80478bda --- /dev/null +++ b/files/fa/web/javascript/reference/global_objects/function/index.html @@ -0,0 +1,156 @@ +--- +title: Function +slug: Web/JavaScript/Reference/Global_Objects/Function +tags: + - Constructor + - Function + - JavaScript + - NeedsTranslation + - TopicStub +translation_of: Web/JavaScript/Reference/Global_Objects/Function +--- +<div>{{JSRef}}</div> + +<p>The <strong><code>Function</code> constructor</strong> creates a new <code>Function</code> object. Calling the constructor directly can create functions dynamically, but suffers from security and similar (but far less significant) performance issues to {{jsxref("eval")}}. However, unlike eval, the Function constructor creates functions which execute in the global scope only.</p> + +<div>{{EmbedInteractiveExample("pages/js/function-constructor.html")}}</div> + + + +<p>Every JavaScript function is actually a <code>Function</code> object. This can be seen with the code <code>(function(){}).constructor === Function</code> which returns true.</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox"><code>new Function ([<var>arg1</var>[, <var>arg2</var>[, ...<var>argN</var>]],] <var>functionBody</var>)</code></pre> + +<h3 id="Parameters">Parameters</h3> + +<dl> + <dt><code>arg1, arg2, ... arg<em>N</em></code></dt> + <dd>Names to be used by the function as formal argument names. Each must be a string that corresponds to a valid JavaScript identifier or a list of such strings separated with a comma; for example "<code>x</code>", "<code>theValue</code>", or "<code>a,b</code>".</dd> + <dt><code>functionBody</code></dt> + <dd>A string containing the JavaScript statements comprising the function definition.</dd> +</dl> + +<h2 id="Description">Description</h2> + +<p><code>Function</code> objects created with the <code>Function</code> constructor are parsed when the function is created. This is less efficient than declaring a function with a <a href="/en-US/docs/Web/JavaScript/Reference/Operators/function">function expression</a> or <a href="/en-US/docs/Web/JavaScript/Reference/Statements/function">function statement</a> and calling it within your code because such functions are parsed with the rest of the code.</p> + +<p>All arguments passed to the function are treated as the names of the identifiers of the parameters in the function to be created, in the order in which they are passed. Omitting an argument will result in the value of that parameter being <code>undefined</code>.</p> + +<p>Invoking the <code>Function</code> constructor as a function (without using the <code>new</code> operator) has the same effect as invoking it as a constructor.</p> + +<h2 id="Properties_and_Methods_of_Function">Properties and Methods of <code>Function</code></h2> + +<p>The global <code>Function</code> object has no methods or properties of its own. However, since it is a function itself, it does inherit some methods and properties through the prototype chain from {{jsxref("Function.prototype")}}.</p> + +<h2 id="Function_prototype_object"><code>Function</code> prototype object</h2> + +<h3 id="Properties">Properties</h3> + +<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/prototype', 'Properties')}}</div> + +<h3 id="Methods">Methods</h3> + +<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/prototype', 'Methods')}}</div> + +<h2 id="Function_instances"><code>Function</code> instances</h2> + +<p><code>Function</code> instances inherit methods and properties from {{jsxref("Function.prototype")}}. As with all constructors, you can change the constructor's prototype object to make changes to all <code>Function</code> instances.</p> + +<h2 id="Examples">Examples</h2> + +<h3 id="Specifying_arguments_with_the_Function_constructor">Specifying arguments with the <code>Function</code> constructor</h3> + +<p>The following code creates a <code>Function</code> object that takes two arguments.</p> + +<pre class="brush: js">// Example can be run directly in your JavaScript console + +// Create a function that takes two arguments and returns the sum of those arguments +var adder = new Function('a', 'b', 'return a + b'); + +// Call the function +adder(2, 6); +// > 8 +</pre> + +<p>The arguments "<code>a</code>" and "<code>b</code>" are formal argument names that are used in the function body, "<code>return a + b</code>".</p> + +<h3 id="Difference_between_Function_constructor_and_function_declaration">Difference between Function constructor and function declaration</h3> + +<p>Functions created with the <code>Function</code> constructor do not create closures to their creation contexts; they always are created in the global scope. When running them, they will only be able to access their own local variables and global ones, not the ones from the scope in which the <code>Function</code> constructor was created. This is different from using {{jsxref("eval")}} with code for a function expression.</p> + +<pre class="brush: js">var x = 10; + +function createFunction1() { + var x = 20; + return new Function('return x;'); // this |x| refers global |x| +} + +function createFunction2() { + var x = 20; + function f() { + return x; // this |x| refers local |x| above + } + return f; +} + +var f1 = createFunction1(); +console.log(f1()); // 10 +var f2 = createFunction2(); +console.log(f2()); // 20<code> +</code></pre> + +<p>While this code works in web browsers, <code>f1()</code> will produce a <code>ReferenceError</code> in Node.js, as <code>x</code> will not be found. This is because the top-level scope in Node is not the global scope, and <code>x</code> will be local to the module.</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Initial definition. Implemented in JavaScript 1.0.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.3', 'Function')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-function-objects', 'Function')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-function-objects', 'Function')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("javascript.builtins.Function")}}</p> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{jsxref("Functions", "Functions and function scope")}}</li> + <li>{{jsxref("Statements/function", "function statement")}}</li> + <li>{{jsxref("Operators/function", "function expression")}}</li> + <li>{{jsxref("Statements/function*", "function* statement")}}</li> + <li>{{jsxref("Operators/function*", "function* expression")}}</li> + <li>{{jsxref("AsyncFunction")}}</li> + <li>{{jsxref("GeneratorFunction")}}</li> +</ul> diff --git a/files/fa/web/javascript/reference/global_objects/index.html b/files/fa/web/javascript/reference/global_objects/index.html new file mode 100644 index 0000000000..4db59a377c --- /dev/null +++ b/files/fa/web/javascript/reference/global_objects/index.html @@ -0,0 +1,128 @@ +--- +title: Standard built-in objects +slug: Web/JavaScript/Reference/Global_Objects +tags: + - JavaScript + - NeedsTranslation + - TopicStub +translation_of: Web/JavaScript/Reference/Global_Objects +--- +<div> + <div> + {{jsSidebar("Objects")}}</div> +</div> +<h2 id="Summary" name="Summary">Summary</h2> +<p>This chapter documents all the JavaScript standard built-in objects, along with their methods and properties.</p> +<div class="onlyinclude"> + <p>The term "global objects" (or standard built-in objects) here is not to be confused with the <em>global object</em>. Here, global objects refer to <em>objects in the global scope</em> (but only if ECMAScript 5 strict mode is not used! Otherwise it returns <code>undefined</code>). The <em>global object</em> itself can be accessed by the {{jsxref("Operators/this", "this")}} operator in the global scope. In fact, the global scope <em>consists</em><em> of</em> the properties of the global object (including inherited properties, if any).</p> + <p>Other objects in the global scope are either <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Creating_new_objects">created by the user script</a> or provided by the host application. The host objects available in browser contexts are documented in the <a href="/en-US/docs/Web/API/Reference">API reference</a>. For more information about the distinction between the <a href="/en-US/docs/DOM/DOM_Reference">DOM</a> and core <a href="/en-US/docs/Web/JavaScript">JavaScript</a>, see <a href="/en-US/docs/Web/JavaScript/JavaScript_technologies_overview">JavaScript technologies overview</a>.</p> + <h2 id="Standard_objects_(by_category)">Standard objects (by category)</h2> + <h3 id="Value_properties">Value properties</h3> + <p>Global properties returning a simple value.</p> + <ul> + <li>{{jsxref("Infinity")}}</li> + <li>{{jsxref("NaN")}}</li> + <li>{{jsxref("undefined")}}</li> + <li>{{jsxref("null")}} literal</li> + </ul> + <h3 id="Function_properties">Function properties</h3> + <p>Global functions returning the result of a specific routine.</p> + <ul> + <li>{{jsxref("Global_Objects/eval", "eval()")}}</li> + <li>{{jsxref("Global_Objects/uneval", "uneval()")}} {{non-standard_inline()}}</li> + <li>{{jsxref("Global_Objects/isFinite", "isFinite()")}}</li> + <li>{{jsxref("Global_Objects/isNaN", "isNaN()")}}</li> + <li>{{jsxref("Global_Objects/parseFloat", "parseFloat()")}}</li> + <li>{{jsxref("Global_Objects/parseInt", "parseInt()")}}</li> + <li>{{jsxref("Global_Objects/decodeURI", "decodeURI()")}}</li> + <li>{{jsxref("Global_Objects/decodeURIComponent", "decodeURIComponent()")}}</li> + <li>{{jsxref("Global_Objects/encodeURI", "encodeURI()")}}</li> + <li>{{jsxref("Global_Objects/encodeURIComponent", "encodeURIComponent()")}}</li> + <li>{{jsxref("Global_Objects/escape", "escape()")}} {{deprecated_inline()}}</li> + <li>{{jsxref("Global_Objects/unescape", "unescape()")}} {{deprecated_inline()}}</li> + </ul> + <h3 id="Fundamental_objects">Fundamental objects</h3> + <p>General language objects, functions and errors.</p> + <ul> + <li>{{jsxref("Object")}}</li> + <li>{{jsxref("Function")}}</li> + <li>{{jsxref("Boolean")}}</li> + <li>{{jsxref("Symbol")}} {{experimental_inline()}}</li> + <li>{{jsxref("Error")}}</li> + <li>{{jsxref("EvalError")}}</li> + <li>{{jsxref("InternalError")}}</li> + <li>{{jsxref("RangeError")}}</li> + <li>{{jsxref("ReferenceError")}}</li> + <li>{{jsxref("StopIteration")}}</li> + <li>{{jsxref("SyntaxError")}}</li> + <li>{{jsxref("TypeError")}}</li> + <li>{{jsxref("URIError")}}</li> + </ul> + <h3 id="Numbers_and_dates">Numbers and dates</h3> + <p>Objects dealing with numbers, dates and mathematical calculations.</p> + <ul> + <li>{{jsxref("Number")}}</li> + <li>{{jsxref("Math")}}</li> + <li>{{jsxref("Date")}}</li> + </ul> + <h3 id="Text_processing">Text processing</h3> + <p>Objects for manipulating texts.</p> + <ul> + <li>{{jsxref("String")}}</li> + <li>{{jsxref("RegExp")}}</li> + </ul> + <h3 id="Indexed_collections">Indexed collections</h3> + <p>Collections ordered by an index. Array-type objects.</p> + <ul> + <li>{{jsxref("Array")}}</li> + <li>{{jsxref("Int8Array")}}</li> + <li>{{jsxref("Uint8Array")}}</li> + <li>{{jsxref("Uint8ClampedArray")}}</li> + <li>{{jsxref("Int16Array")}}</li> + <li>{{jsxref("Uint16Array")}}</li> + <li>{{jsxref("Int32Array")}}</li> + <li>{{jsxref("Uint32Array")}}</li> + <li>{{jsxref("Float32Array")}}</li> + <li>{{jsxref("Float64Array")}}</li> + <li>{{jsxref("ParallelArray")}} {{non-standard_inline()}}</li> + </ul> + <h3 id="Keyed_collections">Keyed collections</h3> + <p>Collections of objects as keys. Elements iterable in insertion order.</p> + <ul> + <li>{{jsxref("Map")}} {{experimental_inline()}}</li> + <li>{{jsxref("Set")}} {{experimental_inline()}}</li> + <li>{{jsxref("WeakMap")}} {{experimental_inline()}}</li> + <li>{{jsxref("WeakSet")}} {{experimental_inline()}}</li> + </ul> + <h3 id="Structured_data">Structured data</h3> + <p>Data buffers and <strong>J</strong>ava<strong>S</strong>cript <strong>O</strong>bject <strong>N</strong>otation.</p> + <ul> + <li>{{jsxref("ArrayBuffer")}}</li> + <li>{{jsxref("DataView")}}</li> + <li>{{jsxref("JSON")}}</li> + </ul> + <h3 id="Control_abstraction_objects">Control abstraction objects</h3> + <ul> + <li>{{jsxref("Iterator")}} {{non-standard_inline()}}</li> + <li>{{jsxref("Generator")}} {{experimental_inline()}}</li> + <li>{{jsxref("Promise")}} {{experimental_inline()}}</li> + </ul> + <h3 id="Reflection">Reflection</h3> + <ul> + <li>{{jsxref("Reflect")}} {{experimental_inline()}}</li> + <li>{{jsxref("Proxy")}} {{experimental_inline()}}</li> + </ul> + <h3 id="Internationalization">Internationalization</h3> + <p>Additions to the ECMAScript core for language-sensitive functionalities.</p> + <ul> + <li>{{jsxref("Intl")}}</li> + <li>{{jsxref("Global_Objects/Collator", "Intl.Collator")}}</li> + <li>{{jsxref("Global_Objects/DateTimeFormat", "Intl.DateTimeFormat")}}</li> + <li>{{jsxref("Global_Objects/NumberFormat", "Intl.NumberFormat")}}</li> + </ul> + <h3 id="Other">Other</h3> + <ul> + <li><code><a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments">arguments</a></code></li> + </ul> +</div> +<p> </p> diff --git a/files/fa/web/javascript/reference/global_objects/null/index.html b/files/fa/web/javascript/reference/global_objects/null/index.html new file mode 100644 index 0000000000..b90e55a245 --- /dev/null +++ b/files/fa/web/javascript/reference/global_objects/null/index.html @@ -0,0 +1,126 @@ +--- +title: 'null' +slug: Web/JavaScript/Reference/Global_Objects/null +translation_of: Web/JavaScript/Reference/Global_Objects/null +--- +<div> </div> + +<p dir="rtl">مقدار null نمایان گر مقداری هست که به صورت دستی (عمدی) می توانیم به یک متغییر نسبت دهیم،null یکی از {{Glossary("Primitive", "نوع های اولیه")}}. جاوا اسکریپت می باشد.</p> + +<h2 dir="rtl" id="شیوه_ی_نوشتن">شیوه ی نوشتن</h2> + +<pre dir="rtl"><code>null</code></pre> + +<h2 dir="rtl" id="توضیح">توضیح</h2> + +<p dir="rtl" id="Syntax">null باید به صورت حروف کوچک نوشته شود،null اقلب برای مشخص کردن مکان object به کار برده می شود و به هیچ object وابسته نمی باشد</p> + +<p dir="rtl">زمانی که می خواهید مقدار null یا undefined را بررسی کنید به <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators">تفاوت مابین عملگر های بررسی (==) و (===) اگاه باشید</a>.</p> + +<pre class="brush: js">// foo does not exist. It is not defined and has never been initialized: +> foo +"ReferenceError: foo is not defined" + +// foo is known to exist now but it has no type or value: +> var foo = null; foo +"null" +</pre> + +<h3 dir="rtl" id="تفاوت_بین_null_و_undefined">تفاوت بین null و undefined</h3> + +<pre class="brush: js">typeof null // object (bug in ECMAScript, should be null) +typeof undefined // undefined +null === undefined // false +null == undefined // true +</pre> + +<h2 dir="rtl" id="مشخصات">مشخصات</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">مشخصات</th> + <th scope="col">وضعیت</th> + <th scope="col">توضیحات</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-4.3.11', 'null value')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-null-value', 'null value')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-null-value', 'null value')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 dir="rtl" id="سازگاری_مرورگرها">سازگاری مرورگرها</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 dir="rtl" id="بیشتر_بخوانید">بیشتر بخوانید</h2> + +<ul> + <li>{{jsxref("undefined")}}</li> + <li>{{jsxref("NaN")}}</li> +</ul> diff --git a/files/fa/web/javascript/reference/global_objects/regexp/index.html b/files/fa/web/javascript/reference/global_objects/regexp/index.html new file mode 100644 index 0000000000..3419d5977b --- /dev/null +++ b/files/fa/web/javascript/reference/global_objects/regexp/index.html @@ -0,0 +1,597 @@ +--- +title: RegExp +slug: Web/JavaScript/Reference/Global_Objects/RegExp +tags: + - Constructor + - JavaScript + - NeedsTranslation + - RegExp + - Regular Expressions + - TopicStub +translation_of: Web/JavaScript/Reference/Global_Objects/RegExp +--- +<div>{{JSRef("Global_Objects", "RegExp")}}</div> + +<h2 id="Summary">Summary</h2> + +<p>The <code><strong>RegExp</strong></code> constructor creates a regular expression object for matching text with a pattern.</p> + +<p>For an introduction on what regular expressions are, read the <a href="/en-US/docs/Web/JavaScript/Guide/Regular_Expressions">Regular Expressions chapter in the JavaScript Guide</a>.</p> + +<h2 id="Constructor">Constructor</h2> + +<p>Literal and constructor notations are possible:</p> + +<pre class="syntaxbox"><code>/<em>pattern</em>/<em>flags; +</em></code> +new <code>RegExp(<em>pattern</em> <em>[, flags]</em>)</code>; +</pre> + +<h3 id="Parameters">Parameters</h3> + +<dl> + <dt><code>pattern</code></dt> + <dd>The text of the regular expression.</dd> + <dt><code>flags</code></dt> + <dd> + <p>If specified, flags can have any combination of the following values:</p> + + <dl> + <dt><code>g</code></dt> + <dd>global match</dd> + <dt><code>i</code></dt> + <dd>ignore case</dd> + <dt><code>m</code></dt> + <dd>multiline; treat beginning and end characters (^ and $) as working over multiple lines (i.e., match the beginning or end of <em>each</em> line (delimited by \n or \r), not only the very beginning or end of the whole input string)</dd> + <dt><code>y</code></dt> + <dd>sticky; matches only from the index indicated by the <code>lastIndex</code> property of this regular expression in the target string (and does not attempt to match from any later indexes).</dd> + </dl> + </dd> +</dl> + +<h2 id="Description">Description</h2> + +<p>There are 2 ways to create a RegExp object: a literal notation and a constructor. To indicate strings, the parameters to the literal notation do not use quotation marks while the parameters to the constructor function do use quotation marks. So the following expressions create the same regular expression:</p> + +<pre class="brush: js">/ab+c/i; +new RegExp("ab+c", "i"); +</pre> + +<p>The literal notation provides compilation of the regular expression when the expression is evaluated. Use literal notation when the regular expression will remain constant. For example, if you use literal notation to construct a regular expression used in a loop, the regular expression won't be recompiled on each iteration.</p> + +<p>The constructor of the regular expression object, for example, <code>new RegExp("ab+c")</code>, provides runtime compilation of the regular expression. Use the constructor function when you know the regular expression pattern will be changing, or you don't know the pattern and are getting it from another source, such as user input.</p> + +<p>When using the constructor function, the normal string escape rules (preceding special characters with \ when included in a string) are necessary. For example, the following are equivalent:</p> + +<pre class="brush: js">var re = /\w+/; +var re = new RegExp("\\w+"); +</pre> + +<h2 id="Special_characters_meaning_in_regular_expressions">Special characters meaning in regular expressions</h2> + +<ul> + <li><a href="#character-classes">Character Classes</a></li> + <li><a href="#character-sets">Character Sets</a></li> + <li><a href="#boundaries">Boundaries</a></li> + <li><a href="#grouping-back-references">Grouping and back references</a></li> + <li><a href="#quantifiers">Quantifiers</a></li> +</ul> + +<table class="fullwidth-table"> + <tbody> + <tr id="character-classes"> + <th colspan="2">Character Classes</th> + </tr> + <tr> + <th>Character</th> + <th>Meaning</th> + </tr> + <tr> + <td><code>.</code></td> + <td> + <p>(The dot, the decimal point) matches any single character <em>except</em> the newline characters: <code>\n</code> <code>\r</code> <code>\u2028</code> or <code>\u2029</code>.</p> + + <p>Note that the <code>m</code> multiline flag doesn't change the dot behavior. So to match a pattern across multiple lines the character set <code>[^]</code> can be used (if you don't mean an old version of IE, of course), it will match any character including newlines.</p> + + <p>For example, <code>/.y/</code> matches "my" and "ay", but not "yes", in "yes make my day".</p> + </td> + </tr> + <tr> + <td><code>\d</code></td> + <td> + <p>Matches a digit character in the basic Latin alphabet. Equivalent to <code>[0-9]</code>.</p> + + <p>For example, <code>/\d/</code> or <code>/[0-9]/</code> matches '2' in "B2 is the suite number."</p> + </td> + </tr> + <tr> + <td><code>\D</code></td> + <td> + <p>Matches any character that is not a digit in the basic Latin alphabet. Equivalent to <code>[^0-9]</code>.</p> + + <p>For example, <code>/\D/</code> or <code>/[^0-9]/</code> matches 'B' in "B2 is the suite number."</p> + </td> + </tr> + <tr> + <td><code>\w</code></td> + <td> + <p>Matches any alphanumeric character from the basic Latin alphabet, including the underscore. Equivalent to <code>[A-Za-z0-9_]</code>.</p> + + <p>For example, <code>/\w/</code> matches 'a' in "apple," '5' in "$5.28," and '3' in "3D."</p> + </td> + </tr> + <tr> + <td><code>\W</code></td> + <td> + <p>Matches any character that is not a word character from the basic Latin alphabet. Equivalent to <code>[^A-Za-z0-9_]</code>.</p> + + <p>For example, <code>/\W/</code> or <code>/[^A-Za-z0-9_]/</code> matches '%' in "50%."</p> + </td> + </tr> + <tr> + <td><code>\s</code></td> + <td> + <p>Matches a single white space character, including space, tab, form feed, line feed and other Unicode spaces. Equivalent to <code>[ \f\n\r\t\v\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004 \u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f \u3000]</code>.</p> + + <p>For example, <code>/\s\w*/</code> matches ' bar' in "foo bar."</p> + </td> + </tr> + <tr> + <td><code>\S</code></td> + <td> + <p>Matches a single character other than white space. Equivalent to <code><code>[^ \f\n\r\t\v\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004 \u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]</code></code>.</p> + + <p>For example, <code>/\S\w*/</code> matches 'foo' in "foo bar."</p> + </td> + </tr> + <tr> + <td><code>\t</code></td> + <td>Matches a tab.</td> + </tr> + <tr> + <td><code>\r</code></td> + <td>Matches a carriage return.</td> + </tr> + <tr> + <td><code>\n</code></td> + <td>Matches a linefeed.</td> + </tr> + <tr> + <td><code>\v</code></td> + <td>Matches a vertical tab.</td> + </tr> + <tr> + <td><code>\f</code></td> + <td>Matches a form-feed.</td> + </tr> + <tr> + <td><code>[\b]</code></td> + <td>Matches a backspace. (Not to be confused with <code>\b</code>)</td> + </tr> + <tr> + <td><code>\0</code></td> + <td>Matches a NUL character. Do not follow this with another digit.</td> + </tr> + <tr> + <td><code>\c<em>X</em></code></td> + <td> + <p>Where <code><em>X</em></code> is a letter from A - Z. Matches a control character in a string.</p> + + <p>For example, <code>/\cM/</code> matches control-M in a string.</p> + </td> + </tr> + <tr> + <td><code>\x<em>hh</em></code></td> + <td>Matches the character with the code <code><em>hh</em></code> (two hexadecimal digits)</td> + </tr> + <tr> + <td><code>\u<em>hhhh</em></code></td> + <td>Matches the character with the Unicode value <code><em>hhhh</em></code> (four hexadecimal digits).</td> + </tr> + <tr> + <td><code>\</code></td> + <td> + <p>For characters that are usually treated literally, indicates that the next character is special and not to be interpreted literally.</p> + + <p>For example, <code>/b/</code> matches the character 'b'. By placing a backslash in front of b, that is by using <code>/\b/</code>, the character becomes special to mean match a word boundary.</p> + + <p><em>or</em></p> + + <p>For characters that are usually treated specially, indicates that the next character is not special and should be interpreted literally.</p> + + <p>For example, * is a special character that means 0 or more occurrences of the preceding character should be matched; for example, <code>/a*/</code> means match 0 or more "a"s. To match <code>*</code> literally, precede it with a backslash; for example, <code>/a\*/</code> matches 'a*'.</p> + </td> + </tr> + </tbody> + <tbody> + <tr id="character-sets"> + <th colspan="2"> + <p>Character Sets</p> + </th> + </tr> + <tr> + <th>Character</th> + <th>Meaning</th> + </tr> + <tr> + <td><code>[xyz]</code></td> + <td> + <p>A character set. Matches any one of the enclosed characters. You can specify a range of characters by using a hyphen.</p> + + <p>For example, <code>[abcd]</code> is the same as <code>[a-d]</code>. They match the 'b' in "brisket" and the 'c' in "chop".</p> + </td> + </tr> + <tr> + <td><code>[^xyz]</code></td> + <td> + <p>A negated or complemented character set. That is, it matches anything that is not enclosed in the brackets. You can specify a range of characters by using a hyphen.</p> + + <p>For example, <code>[^abc]</code> is the same as <code>[^a-c]</code>. They initially match 'o' in "bacon" and 'h' in "chop."</p> + </td> + </tr> + </tbody> + <tbody> + <tr id="boundaries"> + <th colspan="2">Boundaries</th> + </tr> + <tr> + <th>Character</th> + <th>Meaning</th> + </tr> + <tr> + <td><code>^</code></td> + <td> + <p>Matches beginning of input. If the multiline flag is set to true, also matches immediately after a line break character.</p> + + <p>For example, <code>/^A/</code> does not match the 'A' in "an A", but does match the first 'A' in "An A."</p> + </td> + </tr> + <tr> + <td><code>$</code></td> + <td> + <p>Matches end of input. If the multiline flag is set to true, also matches immediately before a line break character.</p> + + <p>For example, <code>/t$/</code> does not match the 't' in "eater", but does match it in "eat".</p> + </td> + </tr> + <tr> + <td><code>\b</code></td> + <td> + <p>Matches a zero-width word boundary, such as between a letter and a space. (Not to be confused with <code>[\b]</code>)</p> + + <p>For example, <code>/\bno/</code> matches the 'no' in "at noon"; <code>/ly\b/</code> matches the 'ly' in "possibly yesterday."</p> + </td> + </tr> + <tr> + <td><code>\B</code></td> + <td> + <p>Matches a zero-width non-word boundary, such as between two letters or between two spaces.</p> + + <p>For example, <code>/\Bon/</code> matches 'on' in "at noon", and <code>/ye\B/</code> matches 'ye' in "possibly yesterday."</p> + </td> + </tr> + </tbody> + <tbody> + <tr id="grouping-back-references"> + <th colspan="2">Grouping and back references</th> + </tr> + <tr> + <th>Character</th> + <th>Meaning</th> + </tr> + <tr> + <td><code>(<em>x</em>)</code></td> + <td> + <p>Matches <code><em>x</em></code> and remembers the match. These are called capturing parentheses.</p> + + <p>For example, <code>/(foo)/</code> matches and remembers 'foo' in "foo bar." The matched substring can be recalled from the resulting array's elements <code>[1], ..., [n]</code> or from the predefined <code>RegExp</code> object's properties <code>$1, ..., $9</code>.</p> + + <p>Capturing groups have a performance penalty. If you don't need the matched substring to be recalled, prefer non-capturing parentheses (see below).</p> + </td> + </tr> + <tr> + <td><code>\<em>n</em></code></td> + <td> + <p>Where <code><em>n</em></code> is a positive integer. A back reference to the last substring matching the n parenthetical in the regular expression (counting left parentheses).</p> + + <p>For example, <code>/apple(,)\sorange\1/</code> matches 'apple, orange,' in "apple, orange, cherry, peach." A more complete example follows this table.</p> + </td> + </tr> + <tr> + <td><code>(?:<em>x</em>)</code></td> + <td>Matches <code><em>x</em></code> but does not remember the match. These are called non-capturing parentheses. The matched substring can not be recalled from the resulting array's elements <code>[1], ..., [n]</code> or from the predefined <code>RegExp</code> object's properties <code>$1, ..., $9</code>.</td> + </tr> + </tbody> + <tbody> + <tr id="quantifiers"> + <th colspan="2">Quantifiers</th> + </tr> + <tr> + <th>Character</th> + <th>Meaning</th> + </tr> + <tr> + <td><code><em>x</em>*</code></td> + <td> + <p>Matches the preceding item <em>x</em> 0 or more times.</p> + + <p>For example, <code>/bo*/</code> matches 'boooo' in "A ghost booooed" and 'b' in "A bird warbled", but nothing in "A goat grunted".</p> + </td> + </tr> + <tr> + <td><code><em>x</em>+</code></td> + <td> + <p>Matches the preceding item <em>x</em> 1 or more times. Equivalent to <code>{1,}</code>.</p> + + <p>For example, <code>/a+/</code> matches the 'a' in "candy" and all the a's in "caaaaaaandy".</p> + </td> + </tr> + <tr> + <td><code><em>x</em>*?</code><br> + <code><em>x</em>+?</code></td> + <td> + <p>Matches the preceding item <em>x</em> like <code>*</code> and <code>+</code> from above, however the match is the smallest possible match.</p> + + <p>For example, <code>/".*?"/</code> matches '"foo"' in '"foo" "bar"' and does not match '"foo" "bar"' as without the <code>?</code> behind the <code>*</code>.</p> + </td> + </tr> + <tr> + <td><code><em>x</em>?</code></td> + <td> + <p>Matches the preceding item <em>x</em> 0 or 1 time.</p> + + <p>For example, <code>/e?le?/</code> matches the 'el' in "angel" and the 'le' in "angle."</p> + + <p>If used immediately after any of the quantifiers <code>*</code>, <code>+</code>, <code>?</code>, or <code>{}</code>, makes the quantifier non-greedy (matching the minimum number of times), as opposed to the default, which is greedy (matching the maximum number of times).</p> + + <p>Also used in lookahead assertions, described under <code>(?=)</code>, <code>(?!)</code>, and <code>(?:)</code> in this table.</p> + </td> + </tr> + <tr> + <td><code><em>x</em>(?=<em>y</em>)</code></td> + <td>Matches <code><em>x</em></code> only if <code><em>x</em></code> is followed by <code><em>y</em></code>. For example, <code>/Jack(?=Sprat)/</code> matches 'Jack' only if it is followed by 'Sprat'. <code>/Jack(?=Sprat|Frost)/</code> matches 'Jack' only if it is followed by 'Sprat' or 'Frost'. However, neither 'Sprat' nor 'Frost' is part of the match results.</td> + </tr> + <tr> + <td><code><em>x</em>(?!<em>y</em>)</code></td> + <td> + <p>Matches <code><em>x</em></code> only if <code><em>x</em></code> is not followed by <code><em>y</em></code>. For example, <code>/\d+(?!\.)/</code> matches a number only if it is not followed by a decimal point.</p> + + <p><code>/\d+(?!\.)/.exec("3.141")</code> matches 141 but not 3.141.</p> + </td> + </tr> + <tr> + <td><code><em>x</em>|<em>y</em></code></td> + <td> + <p>Matches either <code><em>x</em></code> or <code><em>y</em></code>.</p> + + <p>For example, <code>/green|red/</code> matches 'green' in "green apple" and 'red' in "red apple."</p> + </td> + </tr> + <tr> + <td><code><em>x</em>{<em>n</em>}</code></td> + <td> + <p>Where <code><em>n</em></code> is a positive integer. Matches exactly <code><em>n</em></code> occurrences of the preceding item <em>x</em>.</p> + + <p>For example, <code>/a{2}/</code> doesn't match the 'a' in "candy," but it matches all of the a's in "caandy," and the first two a's in "caaandy."</p> + </td> + </tr> + <tr> + <td><code><em>x</em>{<em>n</em>,}</code></td> + <td> + <p>Where <code><em>n</em></code> is a positive integer. Matches at least <code><em>n</em></code> occurrences of the preceding item <em>x</em>.</p> + + <p>For example, <code>/a{2,}/</code> doesn't match the 'a' in "candy", but matches all of the a's in "caandy" and in "caaaaaaandy."</p> + </td> + </tr> + <tr> + <td><code><em>x</em>{<em>n</em>,<em>m</em>}</code></td> + <td> + <p>Where <code><em>n</em></code> and <code><em>m</em></code> are positive integers. Matches at least <code><em>n</em></code> and at most <code><em>m</em></code> occurrences of the preceding item <em>x</em>.</p> + + <p>For example, <code>/a{1,3}/</code> matches nothing in "cndy", the 'a' in "candy," the two a's in "caandy," and the first three a's in "caaaaaaandy". Notice that when matching "caaaaaaandy", the match is "aaa", even though the original string had more a's in it.</p> + </td> + </tr> + </tbody> +</table> + +<h3 id="Properties"><span style="font-size: 1.714285714285714rem;">Properties</span></h3> + +<dl> + <dt>{{jsxref("RegExp.prototype")}}</dt> + <dd>Allows the addition of properties to all objects.</dd> + <dt>RegExp.length</dt> + <dd>The value of <code>RegExp.length</code> is 2.</dd> +</dl> + +<div>{{jsOverrides("Function", "Properties", "prototype")}}</div> + +<h3 id="Methods">Methods</h3> + +<p>The global <code>RegExp</code> object has no methods of its own, however, it does inherit some methods through the prototype chain.</p> + +<div>{{jsOverrides("Function", "Methods", "prototype")}}</div> + +<h2 id="RegExp_prototype_objects_and_instances"><code>RegExp</code> prototype objects and instances</h2> + +<h3 id="Properties_2">Properties</h3> + +<div>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/prototype','Properties')}}</div> + +<h3 id="Methods_2">Methods</h3> + +<div>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/prototype','Methods')}}</div> + +<h2 id="Examples">Examples</h2> + +<h3 id="Example_Using_a_regular_expression_to_change_data_format">Example: Using a regular expression to change data format</h3> + +<p>The following script uses the {{jsxref("String.replace", "replace")}} method of the {{jsxref("Global_Objects/String", "String")}} instance to match a name in the format <em>first last</em> and output it in the format <em>last</em>, <em>first</em>. In the replacement text, the script uses <code>$1</code> and <code>$2</code> to indicate the results of the corresponding matching parentheses in the regular expression pattern.</p> + +<pre class="brush: js">var re = /(\w+)\s(\w+)/; +var str = "John Smith"; +var newstr = str.replace(re, "$2, $1"); +console.log(newstr);</pre> + +<p>This displays "Smith, John".</p> + +<h3 id="Example_Using_regular_expression_on_multiple_lines">Example: Using regular expression on multiple lines</h3> + +<pre class="brush: js">var s = "Please yes\nmake my day!"; +s.match(/yes.*day/); +// Returns null +s.match(/yes[^]*day/); +// Returns 'yes\nmake my day' +</pre> + +<h3 id="Example_Using_a_regular_expression_with_the_sticky_flag">Example: Using a regular expression with the "sticky" flag</h3> + +<p>This example demonstrates how one could use the sticky flag on regular expressions to match individual lines of multiline input.</p> + +<pre class="brush: js">var text = "First line\nSecond line"; +var regex = /(\S+) line\n?/y; + +var match = regex.exec(text); +<span style="font-size: 1rem;">console.log</span>(match[1]); // prints "First" +<span style="font-size: 1rem;">console.log</span>(regex.lastIndex); // prints 11 + +var match2 = regex.exec(text); +<span style="font-size: 1rem;">console.log</span>(match2[1]); // prints "Second" +<span style="font-size: 1rem;">console.log</span>(regex.lastIndex); // prints "22" + +var match3 = regex.exec(text); +<span style="font-size: 1rem;">console.log</span>(match3 === null); // prints "true"</pre> + +<p>One can test at run-time whether the sticky flag is supported, using <code>try { … } catch { … }</code>. For this, either an <code>eval(…)</code> expression or the <code>RegExp(<var>regex-string</var>, <var>flags-string</var>)</code> syntax must be used (since the <code>/<var>regex</var>/<var>flags</var></code> notation is processed at compile-time, so throws an exception before the <code>catch</code> block is encountered). For example:</p> + +<pre class="brush: js">var supports_sticky; +try { RegExp('','y'); supports_sticky = true; } +catch(e) { supports_sticky = false; } +alert(supports_sticky); // alerts "true"</pre> + +<h3 id="Example_Regular_expression_and_Unicode_characters">Example: Regular expression and Unicode characters</h3> + +<p>As mentioned above, <code>\w</code> or <code>\W</code> only matches ASCII based characters; for example, 'a' to 'z', 'A' to 'Z', 0 to 9 and '_'. To match characters from other languages such as Cyrillic or Hebrew, use <code>\uhhhh</code>., where "hhhh" is the character's Unicode value in hexadecimal. This example demonstrates how one can separate out Unicode characters from a word.</p> + +<pre class="brush: js">var text = "Образец text на русском языке"; +var regex = /[\u0400-\u04FF]+/g; + +var match = regex.exec(text); +<span style="font-size: 1rem;">console.log</span>(match[0]); // prints "Образец" +<span style="font-size: 1rem;">console.log</span>(regex.lastIndex); // prints "7" + +var match2 = regex.exec(text); +<span style="font-size: 1rem;">console.log</span>(match2[0]); // prints "на" [did not print "text"] +<span style="font-size: 1rem;">console.log</span>(regex.lastIndex); // prints "15" + +// and so on</pre> + +<p>Here's an external resource for getting the complete Unicode block range for different scripts: <a href="http://kourge.net/projects/regexp-unicode-block" title="http://kourge.net/projects/regexp-unicode-block">Regexp-unicode-block</a></p> + +<h3 id="Example_Extracting_subdomain_name_from_URL">Example: Extracting subdomain name from URL</h3> + +<pre class="brush: js">var url = "http://xxx.domain.com"; +<span style="font-size: 1rem;">console.log</span>(/[^.]+/.exec(url)[0].substr(7)); // prints "xxx"</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>ECMAScript 1st Edition. Implemented in JavaScript 1.1</td> + <td>Standard</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.10', 'RegExp')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-regexp-regular-expression-objects', 'RegExp')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p>{{ CompatibilityTable() }}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + </tr> + <tr> + <td>Sticky flag ("y")</td> + <td>39 (behind flag)</td> + <td>{{ CompatGeckoDesktop("1.9") }} ES4-Style {{bug(773687)}}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + </tr> + <tr> + <td>Sticky flag ("y")</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatGeckoDesktop("1.9") }} ES4-Style {{bug(773687)}}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Guide/Regular_Expressions" title="JavaScript/Guide/Regular_Expressions">Regular Expressions</a> chapter in the <a href="/en-US/docs/Web/JavaScript/Guide" title="JavaScript/Guide">JavaScript Guide</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match">String.prototype.match()</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace">String.prototype.replace()</a></li> +</ul> diff --git a/files/fa/web/javascript/reference/global_objects/regexp/test/index.html b/files/fa/web/javascript/reference/global_objects/regexp/test/index.html new file mode 100644 index 0000000000..1690ceb375 --- /dev/null +++ b/files/fa/web/javascript/reference/global_objects/regexp/test/index.html @@ -0,0 +1,123 @@ +--- +title: RegExp.prototype.test() +slug: Web/JavaScript/Reference/Global_Objects/RegExp/test +tags: + - جاوا اسکریپت + - جستجو + - متد +translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/test +--- +<div dir="rtl"> + {{JSRef("Global_Objects", "RegExp")}}</div> +<h2 dir="rtl" id="Summary" name="Summary">خلاصه</h2> +<p dir="rtl"><strong>متد test یک جستجو برای یافتن رشته خاص در متن یا رشته مورد نظر انجام میدهد و True یا False برمیگرداند.</strong></p> +<h2 dir="rtl" id="Syntax" name="Syntax">ساختار</h2> +<pre dir="rtl"><var>regexObj</var>.test(str)</pre> +<h3 dir="rtl" id="Parameters" name="Parameters"><strong>پارامتر ها</strong></h3> +<dl> + <dt dir="rtl"> + <code>str</code></dt> + <dd dir="rtl"> + <strong>رشته ای که میخواهید با متن مورد نظر تطابق دهید.</strong></dd> +</dl> +<h3 dir="rtl" id="مقدار_بازگشتی"><strong>مقدار بازگشتی</strong></h3> +<p dir="rtl"><strong>مقدار بازگشتی از نوع Boolean بوده و True یا False میباشد.</strong></p> +<h2 dir="rtl" id="Description" name="Description">توضیحات</h2> +<p dir="rtl"><strong>متد test() زمانی استفاده میشود که میخواهید الگو مورد نظر خود را در یک متن جستجو کنید و از وجود آن در متن مورد نظر با خبر شوید.</strong></p> +<p dir="rtl"><strong>متدهای مرتبط :</strong> {jsxref("String.search") , {jsxref("RegExp.exec", "exec")</p> +<h2 dir="rtl" id="Examples" name="Examples">مثال</h2> +<h3 dir="rtl" id="Example:_Using_test" name="Example:_Using_test"><code>مثال: استفاده از test</code></h3> +<p dir="rtl"><strong>مثال زیر یک خروجی را چاپ میکند که اشاره به موفقیت آمیز بودن جستجو دارد:</strong></p> +<pre class="brush: js" dir="rtl">function testinput(re, str){ + var midstring; + if (re.test(str)) { + midstring = " contains "; + } else { + midstring = " does not contain "; + } + console.log(str + midstring + re.source); +} +</pre> +<h2 dir="rtl" id="خصوصیات">خصوصیات</h2> +<table class="standard-table" dir="rtl"> + <tbody> + <tr> + <th scope="col">خصوصیت</th> + <th scope="col">وضعیت</th> + <th scope="col">یاداشت</th> + </tr> + <tr> + <td>ECMAScript 3rd Edition. Implemented in JavaScript 1.2</td> + <td>Standard</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.10.6.3', 'RegExp.test')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-regexp.prototype.test', 'RegExp.test')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + </tbody> +</table> +<h2 dir="rtl" id="سازگاری_با_مرورگرها">سازگاری با مرورگرها</h2> +<p dir="rtl">{{ CompatibilityTable() }}</p> +<div dir="rtl" id="compat-desktop"> + <table class="compat-table"> + <tbody> + <tr> + <th>خصوصیات</th> + <th>گوگل کروم</th> + <th>فایرفاکس</th> + <th>اینترنت اکسپلورر</th> + <th>اپرا</th> + <th>سافاری</th> + </tr> + <tr> + <td>پشتیبانی ابتدایی</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + </tr> + </tbody> + </table> +</div> +<div dir="rtl" id="compat-mobile"> + <table class="compat-table"> + <tbody> + <tr> + <th>خصوصیات</th> + <th>اندروید</th> + <th>گوگل کروم برای اندروید</th> + <th>فایرفاکس موبایل</th> + <th>اینترنت اکسپلورر موبایل</th> + <th>اپرا موبایل</th> + <th>سافاری موبایل</th> + </tr> + <tr> + <td>پشتیبانی ابتدایی</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + <td>{{ CompatVersionUnknown() }}</td> + </tr> + </tbody> + </table> +</div> +<h3 dir="rtl" id="sect1"> </h3> +<h3 dir="rtl" id="یادداشتی_برای_Gecko-specific"><strong>یادداشتی برای Gecko-specific</strong></h3> +<p dir="rtl"><strong>قبل از نسخه Gecko 8.0 {{ geckoRelease("8.0") }} تابع test() مشکلاتی به همراه داشت ، زمانی که این تابع بدون پارامتر ورودی فراخوانی میشد الگو را با متن قبلی مطابقت میداد (RegExp.input property) در حالی که بایستی رشته "undefined" را قرار میداد. در حال حاضر این مشکل برطرف شده است و <code>این تابع به درستی کار میکند.</code></strong></p> +<p dir="rtl"> </p> +<p dir="rtl"> </p> +<h2 dir="rtl" id="همچنین_سری_بزنید_به">همچنین سری بزنید به :</h2> +<ul dir="rtl"> + <li><a href="/en-US/docs/Web/JavaScript/Guide/Regular_Expressions" title="JavaScript/Guide/Regular_Expressions">Regular Expressions</a> chapter in the <a href="/en-US/docs/Web/JavaScript/Guide" title="JavaScript/Guide">JavaScript Guide</a></li> + <li>{{jsxref("Global_Objects/RegExp", "RegExp")}}</li> +</ul> diff --git a/files/fa/web/javascript/reference/global_objects/set/index.html b/files/fa/web/javascript/reference/global_objects/set/index.html new file mode 100644 index 0000000000..c756b38195 --- /dev/null +++ b/files/fa/web/javascript/reference/global_objects/set/index.html @@ -0,0 +1,459 @@ +--- +title: مجموعه | Set +slug: Web/JavaScript/Reference/Global_Objects/Set +tags: + - جاوااسکریپت + - مجموعه +translation_of: Web/JavaScript/Reference/Global_Objects/Set +--- +<div dir="rtl" style="font-family: sahel,iransans,tahoma,sans-serif;"> +<div>{{JSRef}}</div> + +<div>شیء Set به شما اجازه میدهد مجموعهای از مقادیر منحصر به فرد را از هر نوعی که باشند ذخیره کنید، چه {{Glossary("Primitive", "مقادیر اوّلیّه (Primitive)")}} باشند، چه ارجاعهایی به اشیاء.</div> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">new Set([iterable]);</pre> + +<h3 id="پارامترها">پارامترها</h3> + +<dl> + <dt>iterable</dt> + <dd>اگر یک شیء <a href="/fa-IR/docs/Web/JavaScript/Reference/Statements/for...of">قابل شمارش</a> (iterable) باشد، همهی عناصر آن به مجموعهی جدید ما اضافه میشوند. null نیز در اینجا به منزلهی undefined است.</dd> +</dl> + +<h2 id="توضیح">توضیح</h2> + +<p>هر شیء Set مجموعهای از مقادیر است. این مقادیر به ترتیبی که به مجموعه اضافه شدند شمارش میشوند. یک مقدار در مجموعه فقط میتواند یک بار بیاید (مهمترین تفاوت مجموعه و آرایه در همین است که در مجموعه مقدار تکراری نداریم ولی در آرایه میتوانیم داشته باشیم).</p> + +<h3 id="برابر_بودن_مقدارها">برابر بودن مقدارها</h3> + +<p>از آن جایی که در هر مجموعه باید مقادیر منحصر به فرد داشته باشیم، به صورت خودکار هنگام اضافه شدن عضو جدید به مجموعه برابری مقدارها بررسی میشود. در نسخههای قبلی ECMAScript، الگوریتمی که این بررسی استفاده میکرد با الگوریتم عملگر === فرق داشت. مخصوصا برای مجموعهها عدد صفر مثبت <bdi>+0</bdi> با صفر منفی <bdi>-0</bdi> متفاوت در نظر گرفته میشدند. با این حال در مشخّصاتی که برای ECMAScript 2015 در نظر گرفته شد این مورد تغییر کرد. برای اطّلاعات بیشتر <a href="#Browser compatibility">جدول پشتیبانی مرورگرها</a> از برابری صفر مثبت و منفی را ببینید.</p> + +<p>ضمناً NaN و undefined نیز میتوانند در یک مجموعه ذخیره شوند. در این مورد NaN با NaN برابر در نظر گرفته میشود (در حالی که به صورت عادی NaN !== NaN است).</p> + +<h2 id="خصیصهها">خصیصهها</h2> + +<dl> + <dt><code>Set.length</code></dt> + <dd>مقدار خصیصهی length همیشه 0 است!</dd> + <dt><bdi>{{jsxref("Set.@@species", "get Set[@@species]")}}</bdi></dt> + <dd>تابع سازندهای است که برای اشیاء مشتق شده به کار میرود.</dd> + <dt>{{jsxref("Set.prototype")}}</dt> + <dd>نشاندهندهی prototype تابع سازندهی Set است که اجازه میدهد خصیصههای جدیدی را به تمام اشیائی که از نوع مجموعه هستند اضافه کنید.</dd> +</dl> + +<h2 id="Set_instances"><code>Set</code> instances</h2> + +<p>تمام نمونههای کلاس Set از {{jsxref("Set.prototype")}} ارثبری میکنند.</p> + +<h3 id="خصیصهها_2">خصیصهها</h3> + +<bdi><p>{{page('en-US/Web/JavaScript/Reference/Global_Objects/Set/prototype','Properties')}}</p></bdi> + +<h3 id="متُدها">متُدها</h3> + +<bdi><p>{{page('en-US/Web/JavaScript/Reference/Global_Objects/Set/prototype','Methods')}}</p></bdi> + +<h2 id="مثالها">مثالها</h2> + +<h3 id="استفاده_از_شیء_Set">استفاده از شیء Set</h3> + +<pre class="brush: js">var mySet = new Set(); + +mySet.add(1); +mySet.add(5); +mySet.add("some text"); +var o = {a: 1, b: 2}; +mySet.add(o); + +mySet.add({a: 1, b: 2}); // o is referencing a different object so this is okay + +mySet.has(1); // true +mySet.has(3); // false, 3 has not been added to the set +mySet.has(5); // true +mySet.has(Math.sqrt(25)); // true +mySet.has("Some Text".toLowerCase()); // true +mySet.has(o); // true + +mySet.size; // 4 + +mySet.delete(5); // removes 5 from the set +mySet.has(5); // false, 5 has been removed + +mySet.size; // 3, we just removed one value +</pre> + +<h3 id="شمارش_عناصر_مجموعه">شمارش عناصر مجموعه</h3> + +<pre class="brush: js">// iterate over items in set +// logs the items in the order: 1, "some text", {"a": 1, "b": 2} +for (let item of mySet) console.log(item); + +// logs the items in the order: 1, "some text", {"a": 1, "b": 2} +for (let item of mySet.keys()) console.log(item); + +// logs the items in the order: 1, "some text", {"a": 1, "b": 2} +for (let item of mySet.values()) console.log(item); + +// logs the items in the order: 1, "some text", {"a": 1, "b": 2} +//(key and value are the same here) +for (let [key, value] of mySet.entries()) console.log(key); + +// convert Set object to an Array object, with <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from">Array.from</a> +var myArr = Array.from(mySet); // [1, "some text", {"a": 1, "b": 2}] + +// the following will also work if run in an HTML document +mySet.add(document.body); +mySet.has(document.querySelector("body")); // true + +// converting between Set and Array +mySet2 = new Set([1,2,3,4]); +mySet2.size; // 4 +[...mySet2]; // [1,2,3,4] + +// intersect can be simulated via +var intersection = new Set([...set1].filter(x => set2.has(x))); + +// difference can be simulated via +var difference = new Set([...set1].filter(x => !set2.has(x))); + +// Iterate set entries with forEach +mySet.forEach(function(value) { + console.log(value); +}); + +// 1 +// 2 +// 3 +// 4</pre> + +<h3 id="پیادهسازی_عملهای_اصلی_در_مجموعهها">پیادهسازی عملهای اصلی در مجموعهها</h3> + +<pre class="brush: js">Set.prototype.isSuperset = function(subset) { + for (var elem of subset) { + if (!this.has(elem)) { + return false; + } + } + return true; +} + +Set.prototype.union = function(setB) { + var union = new Set(this); + for (var elem of setB) { + union.add(elem); + } + return union; +} + +Set.prototype.intersection = function(setB) { + var intersection = new Set(); + for (var elem of setB) { + if (this.has(elem)) { + intersection.add(elem); + } + } + return intersection; +} + +Set.prototype.difference = function(setB) { + var difference = new Set(this); + for (var elem of setB) { + difference.delete(elem); + } + return difference; +} + +//Examples +var setA = new Set([1,2,3,4]), + setB = new Set([2,3]), + setC = new Set([3,4,5,6]); + +setA.isSuperset(setB); // => true +setA.union(setC); // => Set [1, 2, 3, 4, 5, 6] +setA.intersection(setC); // => Set [3, 4] +setA.difference(setC); // => Set [1, 2] + +</pre> + +<h3 id="ارتباط_مجموعه_و_آرایه">ارتباط مجموعه و آرایه</h3> + +<pre class="brush: js">var myArray = ["value1", "value2", "value3"]; + +// Use the regular Set constructor to transform an Array into a Set +var mySet = new Set(myArray); + +mySet.has("value1"); // returns true + +// Use the spread operator to transform a set into an Array. +console.log([...mySet]); // Will show you exactly the same Array as myArray</pre> + +<h2 id="مشخّصات">مشخّصات</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-set-objects', 'Set')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-set-objects', 'Set')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="سازگاری_با_مرورگرها"><a id="سازگاری با مرورگرها" name="سازگاری با مرورگرها">سازگاری با مرورگرها</a></h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>ویژگی</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>پشتیبانی ساده</td> + <td> + <p>{{ CompatChrome(38) }} [1]</p> + </td> + <td>12</td> + <td>{{ CompatGeckoDesktop("13") }}</td> + <td>{{ CompatIE("11") }}</td> + <td>25</td> + <td>7.1</td> + </tr> + <tr> + <td>Constructor argument: <code>new Set(iterable)</code></td> + <td>{{ CompatChrome(38) }}</td> + <td>12</td> + <td>{{ CompatGeckoDesktop("13") }}</td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>9.0</td> + </tr> + <tr> + <td>iterable</td> + <td>{{ CompatChrome(38) }}</td> + <td>12</td> + <td>{{ CompatGeckoDesktop("17") }}</td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>7.1</td> + </tr> + <tr> + <td><code>Set.clear()</code></td> + <td>{{ CompatChrome(38) }}</td> + <td>12</td> + <td>{{CompatGeckoDesktop("19")}}</td> + <td>{{ CompatIE("11") }}</td> + <td>25</td> + <td>7.1</td> + </tr> + <tr> + <td><code>Set.keys(), Set.values(), Set.entries()</code></td> + <td>{{ CompatChrome(38) }}</td> + <td>12</td> + <td>{{CompatGeckoDesktop("24")}}</td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>7.1</td> + </tr> + <tr> + <td><code>Set.forEach()</code></td> + <td>{{ CompatChrome(38) }}</td> + <td>12</td> + <td>{{CompatGeckoDesktop("25")}}</td> + <td>{{ CompatIE("11") }}</td> + <td>25</td> + <td>7.1</td> + </tr> + <tr> + <td>Value equality for -0 and 0</td> + <td>{{ CompatChrome(38) }}</td> + <td>12</td> + <td>{{CompatGeckoDesktop("29")}}</td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>{{CompatSafari(9)}}</td> + </tr> + <tr> + <td>Constructor argument: <code>new Set(null)</code></td> + <td>{{CompatVersionUnknown}}</td> + <td>12</td> + <td>{{CompatGeckoDesktop("37")}}</td> + <td>{{CompatIE(11)}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatSafari(7.1)}}</td> + </tr> + <tr> + <td>Monkey-patched <code>add()</code> in Constructor</td> + <td>{{CompatVersionUnknown}}</td> + <td>12</td> + <td>{{CompatGeckoDesktop("37")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatSafari(9)}}</td> + </tr> + <tr> + <td><code>Set[@@species]</code></td> + <td>{{ CompatChrome(51) }}</td> + <td>13</td> + <td>{{CompatGeckoDesktop("41")}}</td> + <td>{{CompatNo}}</td> + <td>{{ CompatOpera(38) }}</td> + <td>{{CompatSafari(10)}}</td> + </tr> + <tr> + <td><code>Set()</code> without <code>new</code> throws</td> + <td>{{CompatVersionUnknown}}</td> + <td>12</td> + <td>{{CompatGeckoDesktop("42")}}</td> + <td>{{CompatIE(11)}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>9</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(38)}} [1]</td> + <td>{{ CompatGeckoMobile("13") }}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>8</td> + </tr> + <tr> + <td>Constructor argument: <code>new Set(iterable)</code></td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(38)}}</td> + <td>{{ CompatGeckoMobile("13") }}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>9</td> + </tr> + <tr> + <td>iterable</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{ CompatGeckoMobile("17") }}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>8</td> + </tr> + <tr> + <td><code>Set.clear()</code></td> + <td>{{CompatNo}}</td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoMobile("19")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>8</td> + </tr> + <tr> + <td><code>Set.keys(), Set.values(), Set.entries()</code></td> + <td>{{CompatNo}}</td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoMobile("24")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>8</td> + </tr> + <tr> + <td><code>Set.forEach()</code></td> + <td>{{CompatNo}}</td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoMobile("25")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>8</td> + </tr> + <tr> + <td>Value equality for -0 and 0</td> + <td>{{CompatNo}}</td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoMobile("29")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>9</td> + </tr> + <tr> + <td>Constructor argument: <code>new Set(null)</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("37")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>8</td> + </tr> + <tr> + <td>Monkey-patched <code>add()</code> in Constructor</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("37")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>9</td> + </tr> + <tr> + <td><code>Set[@@species]</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("41")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>10</td> + </tr> + <tr> + <td><code>Set()</code> without <code>new</code> throws</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("42")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>9</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] The feature was available behind a preference from Chrome 31. In <code>chrome://flags</code>, activate the entry “Enable Experimental JavaScript”.</p> + +<h2 id="مطالب_مرتبط">مطالب مرتبط</h2> + +<ul> + <li>{{jsxref("Map")}}</li> + <li>{{jsxref("WeakMap")}}</li> + <li>{{jsxref("WeakSet")}}</li> +</ul> +</div> diff --git a/files/fa/web/javascript/reference/index.html b/files/fa/web/javascript/reference/index.html new file mode 100644 index 0000000000..d78299497a --- /dev/null +++ b/files/fa/web/javascript/reference/index.html @@ -0,0 +1,50 @@ +--- +title: مرجع جاوا اسکریپت +slug: Web/JavaScript/Reference +tags: + - JavaScript + - NeedsTranslation + - TopicStub +translation_of: Web/JavaScript/Reference +--- +<div>{{JsSidebar}}</div> + +<p>This part of the JavaScript section on MDN serves as a repository of facts about the JavaScript language. Read more <a href="/en-US/docs/Web/JavaScript/Reference/About">about this reference</a>.</p> + +<h2 id="Global_Objects">Global Objects</h2> + +<p>This chapter documents all the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects">JavaScript standard built-in objects</a>, along with their methods and properties.</p> + +<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects', 'Standard objects (by category)')}}</div> + +<h2 id="Statements">Statements</h2> + +<p>This chapter documents all the <a href="/en-US/docs/Web/JavaScript/Reference/Statements">JavaScript statements and declarations</a>.</p> + +<div>{{page('/en-US/docs/Web/JavaScript/Reference/Statements', 'Statements_and_declarations_by_category')}}</div> + +<h2 id="Expressions_and_operators">Expressions and operators</h2> + +<p>This chapter documents all the <a href="/en-US/docs/Web/JavaScript/Reference/Operators">JavaScript expressions and operators</a>.</p> + +<div>{{page('/en-US/docs/Web/JavaScript/Reference/Operators', 'Expressions_and_operators_by_category')}}</div> + +<h2 id="Functions">Functions</h2> + +<p>This chapter documents how to work with <a href="/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope">JavaScript functions</a> to develop your applications.</p> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments"><code>arguments</code></a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/arrow_functions">Arrow functions</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/default_parameters">Default parameters</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters">Rest parameters</a></li> +</ul> + +<h2 id="Additional_reference_pages">Additional reference pages</h2> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar">Lexical grammar</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Data_structures">Data types and data structures</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">Strict mode</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features">Deprecated features</a></li> +</ul> diff --git a/files/fa/web/javascript/reference/operators/index.html b/files/fa/web/javascript/reference/operators/index.html new file mode 100644 index 0000000000..636cb3acca --- /dev/null +++ b/files/fa/web/javascript/reference/operators/index.html @@ -0,0 +1,302 @@ +--- +title: Expressions and operators +slug: Web/JavaScript/Reference/Operators +tags: + - بازبینی + - جاوااسکریپت + - عملوند + - منابع +translation_of: Web/JavaScript/Reference/Operators +--- +<div>{{jsSidebar("Operators")}}</div> + +<div>این بخش از سند شامل تمامی عمل ها و عبارت و کلمات کلیدی بکار رفته در زبان برنامه نویسی جاوااسکریپت می باشد.</div> + +<h2 id="دسته_بندی_عبارت_و_عمل_ها">دسته بندی عبارت و عمل ها</h2> + +<p>لیست زیر براساس الفابت انگلیسی مرتب شده است</p> + +<h3 id="عبارات_اصلی">عبارات اصلی</h3> + +<p>عبارت عمومی و کلمات کلیدی اصلی در جاوا اسکریپت.</p> + +<dl> + <dt>{{jsxref("Operators/this", "this")}}</dt> + <dd dir="rtl">کلمه کلیدی <code>this</code> به محتوایی در درون تابعی که در آن نوشته شده است اشاره می کند.</dd> + <dt>{{jsxref("Operators/function", "function")}}</dt> + <dd dir="rtl">کلمه کلیدی <code>function</code> ٫ تعریف کننده یک تابع است.</dd> + <dt>{{jsxref("Operators/class", "class")}}</dt> + <dd dir="rtl">کلمه کلیدی <code>class</code> ٫ تعریف کننده یک کلاس است.</dd> + <dt>{{jsxref("Operators/function*", "function*")}}</dt> + <dd dir="rtl">کلمه کلیدی <code>function*</code> تعریف کننده یک سازنده کلاس است.</dd> + <dt>{{jsxref("Operators/yield", "yield")}}</dt> + <dd style="direction: rtl;">مکث و از سرگیری می کند تابعی که تولید شده است.</dd> + <dt>{{jsxref("Operators/yield*", "yield*")}}</dt> + <dd dir="rtl">محول می کند به تابع یا آبجکت تولید شده دیگر.</dd> + <dt>{{experimental_inline}} {{jsxref("Operators/async_function", "async function*")}}</dt> + <dd dir="rtl"><code>async function</code> یک تابع async تعریف می کند</dd> + <dt>{{experimental_inline}} {{jsxref("Operators/await", "await")}}</dt> + <dd dir="rtl">مکث و از سرگیری می کند و تابع اسینک (async ) و منتظر اجازه برای تایید را رد می ماند</dd> + <dt>{{jsxref("Global_Objects/Array", "[]")}}</dt> + <dd style="direction: rtl;">تعریف کننده /سازنده یک آرایه .</dd> + <dt>{{jsxref("Operators/Object_initializer", "{}")}}</dt> + <dd dir="rtl">تعریف کننده / سازنده یک آبجکت ( شئی) .</dd> + <dt>{{jsxref("Global_Objects/RegExp", "/ab+c/i")}}</dt> + <dd dir="rtl">یک ترکیب صحیح از عبارتها</dd> + <dt>{{jsxref("Operators/Grouping", "( )")}}</dt> + <dd dir="rtl">دسته بندی عمل ها</dd> +</dl> + +<h3 dir="rtl" id="عبارت_های_سمت_چپ">عبارت های سمت چپ</h3> + +<p dir="rtl">مقدارهای سمت چپ مشخص کردن هدف هستند </p> + +<dl> + <dt>{{jsxref("Operators/Property_accessors", "Property accessors", "", 1)}}</dt> + <dd>عمل های شامل درستی به یک ویژگی یا متد از یک آبجکت(شئی) از قبل تعریف شده<br> + (<code>object.property</code> و <code>object["property"]</code>).</dd> + <dt>{{jsxref("Operators/new", "new")}}</dt> + <dd dir="rtl">عمل <code>new</code> یک سازنده از الگو یا موجودیت از قبل تعریف شده مثل آبجکت </dd> + <dt><a href="/en-US/docs/Web/JavaScript/Reference/Operators/new.target">new.target</a></dt> + <dd>In constructors, <code>new.target</code> refers to the constructor that was invoked by {{jsxref("Operators/new", "new")}}.</dd> + <dt>{{jsxref("Operators/super", "super")}}</dt> + <dd style="direction: rtl;">کلیدواژه <code>super</code> والد سازنده را صدا می زند</dd> + <dt>{{jsxref("Operators/Spread_operator", "...obj")}}</dt> + <dd>The spread operator allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected.</dd> +</dl> + +<h3 id="افزایش_و_کاهش">افزایش و کاهش</h3> + +<p>عملوند پیشوندی/ پسوندی افزایشی و عملوند پیشوندی/پسوندی کاهشی</p> + +<dl> + <dt>{{jsxref("Operators/Arithmetic_Operators", "A++", "#Increment")}}</dt> + <dd>عملوند پسوندی افزایشی.</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "A--", "#Decrement")}}</dt> + <dd>عملوند پسوندی کاهشی.</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "++A", "#Increment")}}</dt> + <dd>عملوند پیشوندی افزایشی.</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "--A", "#Decrement")}}</dt> + <dd>عملوند پیشوند کاهشی</dd> +</dl> + +<h3 id="عملوند_های_یکتا">عملوند های یکتا</h3> + +<p>A unary operation is operation with only one operand.</p> + +<dl> + <dt>{{jsxref("Operators/delete", "delete")}}</dt> + <dd dir="rtl">عملوند <code>delete</code> ویژگی /ها را از یک آبجکت حذف می کند.</dd> + <dt>{{jsxref("Operators/void", "void")}}</dt> + <dd dir="rtl">در عمل کننده <code>void</code> مقداری برای بازگشت از یک عبارت وجود ندارد.</dd> + <dt>{{jsxref("Operators/typeof", "typeof")}}</dt> + <dd dir="rtl"><code>typeof</code> نوع آبجکت (شئی )دریافتی را مشخص می کند.</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "+", "#Unary_plus")}}</dt> + <dd>The unary plus operator converts its operand to Number type.</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "-", "#Unary_negation")}}</dt> + <dd>The unary negation operator converts its operand to Number type and then negates it.</dd> + <dt>{{jsxref("Operators/Bitwise_Operators", "~", "#Bitwise_NOT")}}</dt> + <dd>Bitwise NOT operator.</dd> + <dt>{{jsxref("Operators/Logical_Operators", "!", "#Logical_NOT")}}</dt> + <dd>Logical NOT operator.</dd> +</dl> + +<h3 id="عملوند_های_منطقی">عملوند های منطقی</h3> + +<p>عملوندهای منطقی روی مقدار عددی اعمال می شوند و یک عدد به عنوان نتیجه منطقی عملوند منطقی خواهد بود</p> + +<dl> + <dt>{{jsxref("Operators/Arithmetic_Operators", "+", "#Addition")}}</dt> + <dd>عمل جمع.</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "-", "#Subtraction")}}</dt> + <dd>عمل تفریق/منها</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "/", "#Division")}}</dt> + <dd>عمل تقسیم</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "*", "#Multiplication")}}</dt> + <dd>عمل ضرب</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "%", "#Remainder")}}</dt> + <dd>عمل تقسیم / خروجی باقیماند تقسیم</dd> +</dl> + +<dl> + <dt>{{jsxref("Operators/Arithmetic_Operators", "**", "#Exponentiation")}}</dt> + <dd>عمل توان</dd> +</dl> + +<h3 id="Relational_operators">Relational operators</h3> + +<p>A comparison operator compares its operands and returns a <code>Boolean</code> value based on whether the comparison is true.</p> + +<dl> + <dt>{{jsxref("Operators/in", "in")}}</dt> + <dd>The <code>in</code> operator determines whether an object has a given property.</dd> + <dt>{{jsxref("Operators/instanceof", "instanceof")}}</dt> + <dd>The <code>instanceof</code> operator determines whether an object is an instance of another object.</dd> + <dt>{{jsxref("Operators/Comparison_Operators", "<", "#Less_than_operator")}}</dt> + <dd>Less than operator.</dd> + <dt>{{jsxref("Operators/Comparison_Operators", ">", "#Greater_than_operator")}}</dt> + <dd>Greater than operator.</dd> + <dt>{{jsxref("Operators/Comparison_Operators", "<=", "#Less_than_or_equal_operator")}}</dt> + <dd>Less than or equal operator.</dd> + <dt>{{jsxref("Operators/Comparison_Operators", ">=", "#Greater_than_or_equal_operator")}}</dt> + <dd>Greater than or equal operator.</dd> +</dl> + +<div class="note"> +<p><strong>Note: =></strong> is not an operator, but the notation for <a href="/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Arrow functions</a>.</p> +</div> + +<h3 id="Equality_operators">Equality operators</h3> + +<p>The result of evaluating an equality operator is always of type <code>Boolean</code> based on whether the comparison is true.</p> + +<dl> + <dt>{{jsxref("Operators/Comparison_Operators", "==", "#Equality")}}</dt> + <dd>Equality operator.</dd> + <dt>{{jsxref("Operators/Comparison_Operators", "!=", "#Inequality")}}</dt> + <dd>Inequality operator.</dd> + <dt>{{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}</dt> + <dd>Identity operator.</dd> + <dt>{{jsxref("Operators/Comparison_Operators", "!==", "#Nonidentity")}}</dt> + <dd>Nonidentity operator.</dd> +</dl> + +<h3 id="Bitwise_shift_operators">Bitwise shift operators</h3> + +<p>Operations to shift all bits of the operand.</p> + +<dl> + <dt>{{jsxref("Operators/Bitwise_Operators", "<<", "#Left_shift")}}</dt> + <dd>Bitwise left shift operator.</dd> + <dt>{{jsxref("Operators/Bitwise_Operators", ">>", "#Right_shift")}}</dt> + <dd>Bitwise right shift operator.</dd> + <dt>{{jsxref("Operators/Bitwise_Operators", ">>>", "#Unsigned_right_shift")}}</dt> + <dd>Bitwise unsigned right shift operator.</dd> +</dl> + +<h3 id="Binary_bitwise_operators">Binary bitwise operators</h3> + +<p>Bitwise operators treat their operands as a set of 32 bits (zeros and ones) and return standard JavaScript numerical values.</p> + +<dl> + <dt>{{jsxref("Operators/Bitwise_Operators", "&", "#Bitwise_AND")}}</dt> + <dd>Bitwise AND.</dd> + <dt>{{jsxref("Operators/Bitwise_Operators", "|", "#Bitwise_OR")}}</dt> + <dd>Bitwise OR.</dd> + <dt>{{jsxref("Operators/Bitwise_Operators", "^", "#Bitwise_XOR")}}</dt> + <dd>Bitwise XOR.</dd> +</dl> + +<h3 id="Binary_logical_operators">Binary logical operators</h3> + +<p>Logical operators are typically used with boolean (logical) values, and when they are, they return a boolean value.</p> + +<dl> + <dt>{{jsxref("Operators/Logical_Operators", "&&", "#Logical_AND")}}</dt> + <dd>Logical AND.</dd> + <dt>{{jsxref("Operators/Logical_Operators", "||", "#Logical_OR")}}</dt> + <dd>Logical OR.</dd> +</dl> + +<h3 id="Conditional_ternary_operator">Conditional (ternary) operator</h3> + +<dl> + <dt>{{jsxref("Operators/Conditional_Operator", "(condition ? ifTrue : ifFalse)")}}</dt> + <dd> + <p>The conditional operator returns one of two values based on the logical value of the condition.</p> + </dd> +</dl> + +<h3 id="Assignment_operators">Assignment operators</h3> + +<p>An assignment operator assigns a value to its left operand based on the value of its right operand.</p> + +<dl> + <dt>{{jsxref("Operators/Assignment_Operators", "=", "#Assignment")}}</dt> + <dd>Assignment operator.</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "*=", "#Multiplication_assignment")}}</dt> + <dd>Multiplication assignment.</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "/=", "#Division_assignment")}}</dt> + <dd>Division assignment.</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "%=", "#Remainder_assignment")}}</dt> + <dd>Remainder assignment.</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "+=", "#Addition_assignment")}}</dt> + <dd>Addition assignment.</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "-=", "#Subtraction_assignment")}}</dt> + <dd>Subtraction assignment</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "<<=", "#Left_shift_assignment")}}</dt> + <dd>Left shift assignment.</dd> + <dt>{{jsxref("Operators/Assignment_Operators", ">>=", "#Right_shift_assignment")}}</dt> + <dd>Right shift assignment.</dd> + <dt>{{jsxref("Operators/Assignment_Operators", ">>>=", "#Unsigned_right_shift_assignment")}}</dt> + <dd>Unsigned right shift assignment.</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "&=", "#Bitwise_AND_assignment")}}</dt> + <dd>Bitwise AND assignment.</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "^=", "#Bitwise_XOR_assignment")}}</dt> + <dd>Bitwise XOR assignment.</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "|=", "#Bitwise_OR_assignment")}}</dt> + <dd>Bitwise OR assignment.</dd> + <dt>{{jsxref("Operators/Destructuring_assignment", "[a, b] = [1, 2]")}}<br> + {{jsxref("Operators/Destructuring_assignment", "{a, b} = {a:1, b:2}")}}</dt> + <dd> + <p>Destructuring assignment allows you to assign the properties of an array or object to variables using syntax that looks similar to array or object literals.</p> + </dd> +</dl> + +<h3 id="Comma_operator">Comma operator</h3> + +<dl> + <dt>{{jsxref("Operators/Comma_Operator", ",")}}</dt> + <dd>The comma operator allows multiple expressions to be evaluated in a single statement and returns the result of the last expression.</dd> +</dl> + +<h3 id="Non-standard_features">Non-standard features</h3> + +<dl> + <dt>{{non-standard_inline}} {{jsxref("Operators/Legacy_generator_function", "Legacy generator function", "", 1)}}</dt> + <dd>The <code>function</code> keyword can be used to define a legacy generator function inside an expression. To make the function a legacy generator, the function body should contains at least one {{jsxref("Operators/yield", "yield")}} expression.</dd> + <dt>{{non-standard_inline}} {{jsxref("Operators/Expression_closures", "Expression closures", "", 1)}}</dt> + <dd>The expression closure syntax is a shorthand for writing simple function.</dd> + <dt>{{non-standard_inline}} {{jsxref("Operators/Array_comprehensions", "[for (x of y) x]")}}</dt> + <dd>Array comprehensions.</dd> + <dt>{{non-standard_inline}} {{jsxref("Operators/Generator_comprehensions", "(for (x of y) y)")}}</dt> + <dd>Generator comprehensions.</dd> +</dl> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES1', '#sec-11', 'Expressions')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Initial definition</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-11', 'Expressions')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-ecmascript-language-expressions', 'ECMAScript Language: Expressions')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>New: Spread operator, destructuring assignment, <code>super</code> keyword.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-ecmascript-language-expressions', 'ECMAScript Language: Expressions')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence">Operator precedence</a></li> +</ul> diff --git a/files/fa/web/javascript/reference/statements/index.html b/files/fa/web/javascript/reference/statements/index.html new file mode 100644 index 0000000000..368977efc8 --- /dev/null +++ b/files/fa/web/javascript/reference/statements/index.html @@ -0,0 +1,131 @@ +--- +title: Statements and declarations +slug: Web/JavaScript/Reference/Statements +tags: + - JavaScript + - NeedsTranslation + - Reference + - TopicStub + - statements +translation_of: Web/JavaScript/Reference/Statements +--- +<div>{{jsSidebar("Statements")}}</div> + +<p>JavaScript applications consist of statements with an appropriate syntax. A single statement may span multiple lines. Multiple statements may occur on a single line if each statement is separated by a semicolon. This isn't a keyword, but a group of keywords.</p> + +<h2 id="Statements_and_declarations_by_category">Statements and declarations by category</h2> + +<p>For an alphabetical listing see the sidebar on the left.</p> + +<h3 id="Control_flow">Control flow</h3> + +<dl> + <dt>{{jsxref("Statements/block", "Block")}}</dt> + <dd>A block statement is used to group zero or more statements. The block is delimited by a pair of curly brackets.</dd> + <dt>{{jsxref("Statements/break", "break")}}</dt> + <dd>Terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement.</dd> + <dt>{{jsxref("Statements/continue", "continue")}}</dt> + <dd>Terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration.</dd> + <dt>{{jsxref("Statements/Empty", "Empty")}}</dt> + <dd>An empty statement is used to provide no statement, although the JavaScript syntax would expect one.</dd> + <dt>{{jsxref("Statements/if...else", "if...else")}}</dt> + <dd>Executes a statement if a specified condition is true. If the condition is false, another statement can be executed.</dd> + <dt>{{jsxref("Statements/switch", "switch")}}</dt> + <dd>Evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.</dd> + <dt>{{jsxref("Statements/throw", "throw")}}</dt> + <dd>Throws a user-defined exception.</dd> + <dt>{{jsxref("Statements/try...catch", "try...catch")}}</dt> + <dd>Marks a block of statements to try, and specifies a response, should an exception be thrown.</dd> +</dl> + +<h3 id="Declarations">Declarations</h3> + +<dl> + <dt>{{jsxref("Statements/var", "var")}}</dt> + <dd>Declares a variable, optionally initializing it to a value.</dd> + <dt>{{experimental_inline}} {{jsxref("Statements/let", "let")}}</dt> + <dd>Declares a block scope local variable, optionally initializing it to a value.</dd> + <dt>{{experimental_inline}} {{jsxref("Statements/const", "const")}}</dt> + <dd>Declares a read-only named constant.</dd> +</dl> + +<h3 id="Functions_and_classes">Functions and classes</h3> + +<dl> + <dt>{{jsxref("Statements/function", "function")}}</dt> + <dd>Declares a function with the specified parameters.</dd> + <dt>{{experimental_inline}} {{jsxref("Statements/function*", "function*")}}</dt> + <dd>Generators functions enable writing <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">iterators</a> more easily.</dd> + <dt>{{jsxref("Statements/return", "return")}}</dt> + <dd>Specifies the value to be returned by a function.</dd> + <dt>{{experimental_inline}} {{jsxref("Statements/class", "class")}}</dt> + <dd>Declares a class.</dd> +</dl> + +<h3 id="Iterations">Iterations</h3> + +<dl> + <dt>{{jsxref("Statements/do...while", "do...while")}}</dt> + <dd>Creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.</dd> + <dt>{{jsxref("Statements/for", "for")}}</dt> + <dd>Creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a statement executed in the loop.</dd> + <dt>{{deprecated_inline}} {{non-standard_inline()}} {{jsxref("Statements/for_each...in", "for each...in")}}</dt> + <dd>Iterates a specified variable over all values of object's properties. For each distinct property, a specified statement is executed.</dd> + <dt>{{jsxref("Statements/for...in", "for...in")}}</dt> + <dd>Iterates over the enumerable properties of an object, in arbitrary order. For each distinct property, statements can be executed.</dd> + <dt>{{experimental_inline}} {{jsxref("Statements/for...of", "for...of")}}</dt> + <dd>Iterates over iterable objects (including <a href="https://developer.mozilla.org/en-US/docs/Core_JavaScript_1.5_Reference/Global_Objects/Array" title="Array">arrays</a>, array-like objects, <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Iterators_and_Generators" title="Iterators and generators">iterators and generators</a>), invoking a custom iteration hook with statements to be executed for the value of each distinct property.</dd> + <dt>{{jsxref("Statements/while", "while")}}</dt> + <dd>Creates a loop that executes a specified statement as long as the test condition evaluates to true. The condition is evaluated before executing the statement.</dd> +</dl> + +<h3 id="Others">Others</h3> + +<dl> + <dt>{{jsxref("Statements/debugger", "debugger")}}</dt> + <dd>Invokes any available debugging functionality. If no debugging functionality is available, this statement has no effect.</dd> + <dt>{{experimental_inline}} {{jsxref("Statements/export", "export")}}</dt> + <dd>Used to export functions to make them available for imports in external modules, another scripts.</dd> + <dt>{{experimental_inline}} {{jsxref("Statements/import", "import")}}</dt> + <dd>Used to import functions exported from an external module, another script.</dd> + <dt>{{jsxref("Statements/label", "label")}}</dt> + <dd>Provides a statement with an identifier that you can refer to using a <code>break</code> or <code>continue</code> statement.</dd> +</dl> + +<dl> + <dt>{{deprecated_inline}} {{jsxref("Statements/with", "with")}}</dt> + <dd>Extends the scope chain for a statement.</dd> +</dl> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>ECMAScript 1st Edition.</td> + <td>Standard</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-12', 'Statements')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-ecmascript-language-statements-and-declarations', 'ECMAScript Language: Statements and Declarations')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>New: function*, let, for...of, yield, class</td> + </tr> + </tbody> +</table> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators">Operators</a></li> +</ul> diff --git a/files/fa/web/javascript/راهنما/control_flow_and_error_handling/index.html b/files/fa/web/javascript/راهنما/control_flow_and_error_handling/index.html new file mode 100644 index 0000000000..1b3edc9c8a --- /dev/null +++ b/files/fa/web/javascript/راهنما/control_flow_and_error_handling/index.html @@ -0,0 +1,424 @@ +--- +title: Control flow and error handling +slug: Web/JavaScript/راهنما/Control_flow_and_error_handling +translation_of: Web/JavaScript/Guide/Control_flow_and_error_handling +--- +<pre>{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Grammar_and_types", "Web/JavaScript/Guide/Loops_and_iteration")}}</pre> + +<p class="summary">JavaScript supports a compact set of statements, specifically control flow statements, that you can use to incorporate a great deal of interactivity in your application. This chapter provides an overview of these statements.</p> + +<p>The <a href="/en-US/docs/Web/JavaScript/Reference/Statements">JavaScript reference</a> contains exhaustive details about the statements in this chapter. The semicolon (<code>;</code>) character is used to separate statements in JavaScript code.</p> + +<p>Any JavaScript expression is also a statement. See <a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators">Expressions and operators</a> for complete information about expressions.</p> + +<h2 id="Block_statement">Block statement</h2> + +<p>The most basic statement is a block statement that is used to group statements. The block is delimited by a pair of curly brackets:</p> + +<pre class="syntaxbox">{ + statement_1; + statement_2; + . + . + . + statement_n; +} +</pre> + +<h3 id="Example"><strong>Example</strong></h3> + +<p>Block statements are commonly used with control flow statements (e.g. <code>if</code>, <code>for</code>, <code>while</code>).</p> + +<pre class="brush: js">while (x < 10) { + x++; +} +</pre> + +<p>Here, <code>{ x++; }</code> is the block statement.</p> + +<p><strong>Important</strong>: JavaScript prior to ECMAScript2015 does <strong>not</strong> have block scope. Variables introduced within a block are scoped to the containing function or script, and the effects of setting them persist beyond the block itself. In other words, block statements do not define a scope. "Standalone" blocks in JavaScript can produce completely different results from what they would produce in C or Java. For example:</p> + +<pre class="brush: js">var x = 1; +{ + var x = 2; +} +console.log(x); // outputs 2 +</pre> + +<p>This outputs 2 because the <code>var x</code> statement within the block is in the same scope as the <code>var x</code> statement before the block. In C or Java, the equivalent code would have outputted 1.</p> + +<p>Starting with ECMAScript2015, the <code>let</code> variable declaration is block scoped. See the {{jsxref("Statements/let", "let")}} reference page for more information.</p> + +<h2 id="Conditional_statements">Conditional statements</h2> + +<p>A conditional statement is a set of commands that executes if a specified condition is true. JavaScript supports two conditional statements: <code>if...else</code> and <code>switch</code>.</p> + +<h3 id="if...else_statement"><code>if...else</code> statement</h3> + +<p>Use the <code>if</code> statement to execute a statement if a logical condition is true. Use the optional <code>else</code> clause to execute a statement if the condition is false. An <code>if</code> statement looks as follows:</p> + +<p>if (condition) {<br> + statement_1;<br> + } else {<br> + statement_2;<br> + }</p> + +<p>Here the<code> condition</code> can be any expression that evaluates to true or false. See <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean#Description">Boolean</a> for an explanation of what evaluates to <code>true</code> and <code>false</code>. If <code>condition</code> evaluates to true, <code>statement_1</code> is executed; otherwise, <code>statement_2</code> is executed. <code>statement_1</code> and <code>statement_2</code> can be any statement, including further nested <code>if</code> statements.</p> + +<p>You may also compound the statements using <code>else if</code> to have multiple conditions tested in sequence, as follows:</p> + +<pre class="syntaxbox">if (condition_1) { + statement_1; +} else if (condition_2) { + statement_2; +} else if (condition_n) { + statement_n; +} else { + statement_last; +} +</pre> + +<p>In the case of multiple conditions only the first logical condition which evaluates to true will be executed. To execute multiple statements, group them within a block statement (<code>{ ... }</code>) . In general, it's good practice to always use block statements, especially when nesting <code>if</code> statements:</p> + +<pre class="syntaxbox">if (condition) { + statement_1_runs_if_condition_is_true; + statement_2_runs_if_condition_is_true; +} else { + statement_3_runs_if_condition_is_false; + statement_4_runs_if_condition_is_false; +} +</pre> + +<div>It is advisable to not use simple assignments in a conditional expression, because the assignment can be confused with equality when glancing over the code. For example, do not use the following code:</div> + +<pre class="example-bad brush: js">if (x = y) { + /* statements here */ +} +</pre> + +<p>If you need to use an assignment in a conditional expression, a common practice is to put additional parentheses around the assignment. For example:</p> + +<pre class="brush: js">if ((x = y)) { + /* statements here */ +} +</pre> + +<h4 id="Falsy_values">Falsy values</h4> + +<p>The following values evaluate to false (also known as {{Glossary("Falsy")}} values):</p> + +<ul> + <li><code>false</code></li> + <li><code>undefined</code></li> + <li><code>null</code></li> + <li><code>0</code></li> + <li><code>NaN</code></li> + <li>the empty string (<code>""</code>)</li> +</ul> + +<p>All other values, including all objects, evaluate to true when passed to a conditional statement.</p> + +<p>Do not confuse the primitive boolean values <code>true</code> and <code>false</code> with the true and false values of the {{jsxref("Boolean")}} object. For example:</p> + +<pre class="brush: js">var b = new Boolean(false); +if (b) // this condition evaluates to true +if (b == true) // this condition evaluates to false +</pre> + +<h4 id="Example_2"><strong>Example</strong></h4> + +<p>In the following example, the function <code>checkData</code> returns <code>true</code> if the number of characters in a <code>Text</code> object is three; otherwise, it displays an alert and returns <code>false</code>.</p> + +<pre class="brush: js">function checkData() { + if (document.form1.threeChar.value.length == 3) { + return true; + } else { + alert("Enter exactly three characters. " + + document.form1.threeChar.value + " is not valid."); + return false; + } +} +</pre> + +<h3 id="switch_statement"><code>switch</code> statement</h3> + +<p>A <code>switch</code> statement allows a program to evaluate an expression and attempt to match the expression's value to a case label. If a match is found, the program executes the associated statement. A <code>switch</code> statement looks as follows:</p> + +<pre class="syntaxbox">switch (expression) { + case label_1: + statements_1 + [break;] + case label_2: + statements_2 + [break;] + ... + default: + statements_def + [break;] +} +</pre> + +<p>The program first looks for a <code>case</code> clause with a label matching the value of expression and then transfers control to that clause, executing the associated statements. If no matching label is found, the program looks for the optional <code>default</code> clause, and if found, transfers control to that clause, executing the associated statements. If no <code>default</code> clause is found, the program continues execution at the statement following the end of <code>switch</code>. By convention, the <code>default</code> clause is the last clause, but it does not need to be so.</p> + +<p>The optional <code>break</code> statement associated with each <code>case</code> clause ensures that the program breaks out of <code>switch</code> once the matched statement is executed and continues execution at the statement following switch. If <code>break</code> is omitted, the program continues execution at the next statement in the <code>switch</code> statement.</p> + +<h4 id="Example_3"><strong>Example</strong></h4> + +<p>In the following example, if <code>fruittype</code> evaluates to "Bananas", the program matches the value with case "Bananas" and executes the associated statement. When <code>break</code> is encountered, the program terminates <code>switch</code> and executes the statement following <code>switch</code>. If <code>break</code> were omitted, the statement for case "Cherries" would also be executed.</p> + +<pre class="brush: js">switch (fruittype) { + case "Oranges": + console.log("Oranges are $0.59 a pound."); + break; + case "Apples": + console.log("Apples are $0.32 a pound."); + break; + case "Bananas": + console.log("Bananas are $0.48 a pound."); + break; + case "Cherries": + console.log("Cherries are $3.00 a pound."); + break; + case "Mangoes": + console.log("Mangoes are $0.56 a pound."); + break; + case "Papayas": + console.log("Mangoes and papayas are $2.79 a pound."); + break; + default: + console.log("Sorry, we are out of " + fruittype + "."); +} +console.log("Is there anything else you'd like?");</pre> + +<h2 id="Exception_handling_statements">Exception handling statements</h2> + +<p>You can throw exceptions using the <code>throw</code> statement and handle them using the <code>try...catch</code> statements.</p> + +<ul> + <li><a href="#throw_statement"><code>throw</code> statement</a></li> + <li><a href="#try...catch_statement"><code>try...catch</code> statement</a></li> +</ul> + +<h3 id="Exception_types">Exception types</h3> + +<p>Just about any object can be thrown in JavaScript. Nevertheless, not all thrown objects are created equal. While it is fairly common to throw numbers or strings as errors it is frequently more effective to use one of the exception types specifically created for this purpose:</p> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects#Fundamental_objects">ECMAScript exceptions</a></li> + <li>{{domxref("DOMException")}} and {{domxref("DOMError")}}</li> +</ul> + +<h3 id="throw_statement"><code>throw</code> statement</h3> + +<p>Use the <code>throw</code> statement to throw an exception. When you throw an exception, you specify the expression containing the value to be thrown:</p> + +<pre class="syntaxbox">throw expression; +</pre> + +<p>You may throw any expression, not just expressions of a specific type. The following code throws several exceptions of varying types:</p> + +<pre class="brush: js">throw "Error2"; // String type +throw 42; // Number type +throw true; // Boolean type +throw {toString: function() { return "I'm an object!"; } }; +</pre> + +<div class="note"><strong>Note:</strong> You can specify an object when you throw an exception. You can then reference the object's properties in the <code>catch</code> block. The following example creates an object <code>myUserException</code> of type <code>UserException</code> and uses it in a throw statement.</div> + +<pre class="brush: js">// Create an object type UserException +function UserException(message) { + this.message = message; + this.name = "UserException"; +} + +// Make the exception convert to a pretty string when used as a string +// (e.g. by the error console) +UserException.prototype.toString = function() { + return this.name + ': "' + this.message + '"'; +} + +// Create an instance of the object type and throw it +throw new UserException("Value too high");</pre> + +<h3 id="try...catch_statement"><code>try...catch</code> statement</h3> + +<p>The <code>try...catch</code> statement marks a block of statements to try, and specifies one or more responses should an exception be thrown. If an exception is thrown, the <code>try...catch</code> statement catches it.</p> + +<p>The <code>try...catch</code> statement consists of a <code>try</code> block, which contains one or more statements, and a <code>catch</code> block, containing statements that specify what to do if an exception is thrown in the <code>try</code> block. That is, you want the <code>try</code> block to succeed, and if it does not succeed, you want control to pass to the <code>catch</code> block. If any statement within the <code>try</code> block (or in a function called from within the <code>try</code> block) throws an exception, control immediately shifts to the <code>catch</code> block. If no exception is thrown in the <code>try</code> block, the <code>catch</code> block is skipped. The <code>finally</code> block executes after the <code>try</code> and <code>catch</code> blocks execute but before the statements following the <code>try...catch</code> statement.</p> + +<p>The following example uses a <code>try...catch</code> statement. The example calls a function that retrieves a month name from an array based on the value passed to the function. If the value does not correspond to a month number (1-12), an exception is thrown with the value <code>"InvalidMonthNo"</code> and the statements in the <code>catch</code> block set the <code>monthName</code> variable to <code>unknown</code>.</p> + +<pre class="brush: js">function getMonthName(mo) { + mo = mo - 1; // Adjust month number for array index (1 = Jan, 12 = Dec) + var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul", + "Aug","Sep","Oct","Nov","Dec"]; + if (months[mo]) { + return months[mo]; + } else { + throw "InvalidMonthNo"; //throw keyword is used here + } +} + +try { // statements to try + monthName = getMonthName(myMonth); // function could throw exception +} +catch (e) { + monthName = "unknown"; + logMyErrors(e); // pass exception object to error handler -> your own function +} +</pre> + +<h4 id="The_catch_block">The <code>catch</code> block</h4> + +<p>You can use a <code>catch</code> block to handle all exceptions that may be generated in the <code>try</code> block.</p> + +<pre class="syntaxbox">catch (catchID) { + statements +} +</pre> + +<p>The <code>catch</code> block specifies an identifier (<code>catchID</code> in the preceding syntax) that holds the value specified by the <code>throw</code> statement; you can use this identifier to get information about the exception that was thrown. JavaScript creates this identifier when the <code>catch</code> block is entered; the identifier lasts only for the duration of the <code>catch</code> block; after the <code>catch</code> block finishes executing, the identifier is no longer available.</p> + +<p>For example, the following code throws an exception. When the exception occurs, control transfers to the <code>catch</code> block.</p> + +<pre class="brush: js">try { + throw "myException"; // generates an exception +} +catch (e) { + // statements to handle any exceptions + logMyErrors(e); // pass exception object to error handler +} +</pre> + +<h4 id="The_finally_block">The <code>finally</code> block</h4> + +<p>The <code>finally</code> block contains statements to execute after the <code>try</code> and <code>catch</code> blocks execute but before the statements following the <code>try...catch</code> statement. The <code>finally</code> block executes whether or not an exception is thrown. If an exception is thrown, the statements in the <code>finally</code> block execute even if no <code>catch</code> block handles the exception.</p> + +<p>You can use the <code>finally</code> block to make your script fail gracefully when an exception occurs; for example, you may need to release a resource that your script has tied up. The following example opens a file and then executes statements that use the file (server-side JavaScript allows you to access files). If an exception is thrown while the file is open, the <code>finally</code> block closes the file before the script fails.</p> + +<pre class="brush: js">openMyFile(); +try { + writeMyFile(theData); //This may throw a error +} catch(e) { + handleError(e); // If we got a error we handle it +} finally { + closeMyFile(); // always close the resource +} +</pre> + +<p>If the <code>finally</code> block returns a value, this value becomes the return value of the entire <code>try-catch-finally</code> production, regardless of any <code>return</code> statements in the <code>try</code> and <code>catch</code> blocks:</p> + +<pre class="brush: js">function f() { + try { + console.log(0); + throw "bogus"; + } catch(e) { + console.log(1); + return true; // this return statement is suspended + // until finally block has completed + console.log(2); // not reachable + } finally { + console.log(3); + return false; // overwrites the previous "return" + console.log(4); // not reachable + } + // "return false" is executed now + console.log(5); // not reachable +} +f(); // console 0, 1, 3; returns false +</pre> + +<p>Overwriting of return values by the <code>finally</code> block also applies to exceptions thrown or re-thrown inside of the <code>catch</code> block:</p> + +<pre class="brush: js">function f() { + try { + throw "bogus"; + } catch(e) { + console.log('caught inner "bogus"'); + throw e; // this throw statement is suspended until + // finally block has completed + } finally { + return false; // overwrites the previous "throw" + } + // "return false" is executed now +} + +try { + f(); +} catch(e) { + // this is never reached because the throw inside + // the catch is overwritten + // by the return in finally + console.log('caught outer "bogus"'); +} + +// OUTPUT +// caught inner "bogus"</pre> + +<h4 id="Nesting_try...catch_statements">Nesting try...catch statements</h4> + +<p>You can nest one or more <code>try...catch</code> statements. If an inner <code>try...catch</code> statement does not have a <code>catch</code> block, it needs to have a <code>finally</code> block and the enclosing <code>try...catch</code> statement's <code>catch</code> block is checked for a match. For more information, see <a href="/en-US/docs/Web/JavaScript/Reference/Statements/try...catch#Nested_try-blocks">nested try-blocks</a> on the <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/try...catch">try...catch</a></code> reference page.</p> + +<h3 id="Utilizing_Error_objects">Utilizing <code>Error</code> objects</h3> + +<p>Depending on the type of error, you may be able to use the 'name' and 'message' properties to get a more refined message. 'name' provides the general class of Error (e.g., 'DOMException' or 'Error'), while 'message' generally provides a more succinct message than one would get by converting the error object to a string.</p> + +<p>If you are throwing your own exceptions, in order to take advantage of these properties (such as if your catch block doesn't discriminate between your own exceptions and system ones), you can use the Error constructor. For example:</p> + +<pre class="brush: js">function doSomethingErrorProne () { + if (ourCodeMakesAMistake()) { + throw (new Error('The message')); + } else { + doSomethingToGetAJavascriptError(); + } +} +.... +try { + doSomethingErrorProne(); +} catch (e) { + console.log(e.name); // logs 'Error' + console.log(e.message); // logs 'The message' or a JavaScript error message) +}</pre> + +<h2 id="Promises">Promises</h2> + +<p>Starting with ECMAScript2015, JavaScript gains support for {{jsxref("Promise")}} objects allowing you to control the flow of deferred and asynchronous operations.</p> + +<p>A <code>Promise</code> is in one of these states:</p> + +<ul> + <li><em>pending</em>: initial state, not fulfilled or rejected.</li> + <li><em>fulfilled</em>: successful operation</li> + <li><em>rejected</em>: failed operation.</li> + <li><em>settled</em>: the Promise is either fulfilled or rejected, but not pending.</li> +</ul> + +<p><img alt="" src="https://mdn.mozillademos.org/files/8633/promises.png" style="height: 297px; width: 801px;"></p> + +<h3 id="Loading_an_image_with_XHR">Loading an image with XHR</h3> + +<p>A simple example using <code>Promise</code> and <code><a href="/en-US/docs/Web/API/XMLHttpRequest">XMLHttpRequest</a></code> to load an image is available at the MDN GitHub<a href="https://github.com/mdn/promises-test/blob/gh-pages/index.html"> promise-test</a> repository. You can also <a href="http://mdn.github.io/promises-test/">see it in action</a>. Each step is commented and allows you to follow the Promise and XHR architecture closely. Here is the uncommented version, showing the <code>Promise</code> flow so that you can get an idea:</p> + +<pre class="brush: js">function imgLoad(url) { + return new Promise(function(resolve, reject) { + var request = new XMLHttpRequest(); + request.open('GET', url); + request.responseType = 'blob'; + request.onload = function() { + if (request.status === 200) { + resolve(request.response); + } else { + reject(Error('Image didn\'t load successfully; error code:' + + request.statusText)); + } + }; + request.onerror = function() { + reject(Error('There was a network error.')); + }; + request.send(); + }); +}</pre> + +<p>For more detailed information, see the {{jsxref("Promise")}} reference page.</p> + +<div>{{PreviousNext("Web/JavaScript/Guide/Grammar_and_types", "Web/JavaScript/Guide/Loops_and_iteration")}}</div> diff --git a/files/fa/web/javascript/راهنما/details_of_the_object_model/index.html b/files/fa/web/javascript/راهنما/details_of_the_object_model/index.html new file mode 100644 index 0000000000..5e523e9124 --- /dev/null +++ b/files/fa/web/javascript/راهنما/details_of_the_object_model/index.html @@ -0,0 +1,718 @@ +--- +title: Details of the object model +slug: Web/JavaScript/راهنما/Details_of_the_Object_Model +translation_of: Web/JavaScript/Guide/Details_of_the_Object_Model +--- +<div>{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Working_with_Objects", "Web/JavaScript/Guide/Using_promises")}}</div> + +<p class="summary">JavaScript is an object-based language based on prototypes, rather than being class-based. Because of this different basis, it can be less apparent how JavaScript allows you to create hierarchies of objects and to have inheritance of properties and their values. This chapter attempts to clarify the situation.</p> + +<p>This chapter assumes that you are already somewhat familiar with JavaScript and that you have used JavaScript functions to create simple objects.</p> + +<h2 id="Class-based_vs._prototype-based_languages">Class-based vs. prototype-based languages</h2> + +<p>Class-based object-oriented languages, such as Java and C++, are founded on the concept of two distinct entities: classes and instances.</p> + +<ul> + <li>A <em>class</em> defines all of the properties that characterize a certain set of objects (considering methods and fields in Java, or members in C++, to be properties). A class is abstract rather than any particular member in a set of objects it describes. For example, the <code>Employee</code> class could represent the set of all employees.</li> + <li>An <em>instance</em>, on the other hand, is the instantiation of a class; that is. For example, <code>Victoria</code> could be an instance of the <code>Employee</code> class, representing a particular individual as an employee. An instance has exactly the same properties of its parent class (no more, no less).</li> +</ul> + +<p>A prototype-based language, such as JavaScript, does not make this distinction: it simply has objects. A prototype-based language has the notion of a <em>prototypical object</em>, an object used as a template from which to get the initial properties for a new object. Any object can specify its own properties, either when you create it or at run time. In addition, any object can be associated as the <em>prototype</em> for another object, allowing the second object to share the first object's properties.</p> + +<h3 dir="rtl" id="تعریف_یک_کلاس">تعریف یک کلاس</h3> + +<p>In class-based languages, you define a class in a separate <em>class definition</em>. In that definition you can specify special methods, called <em>constructors</em>, to create instances of the class. A constructor method can specify initial values for the instance's properties and perform other processing appropriate at creation time. You use the <code>new</code> operator in association with the constructor method to create class instances.</p> + +<p>JavaScript follows a similar model, but does not have a class definition separate from the constructor. Instead, you define a constructor function to create objects with a particular initial set of properties and values. Any JavaScript function can be used as a constructor. You use the <code>new</code> operator with a constructor function to create a new object.</p> + +<div class="blockIndicator note"> +<p>Note that ECMAScript 2015 introduces a <a href="/en-US/docs/Web/JavaScript/Reference/Classes">class declaration</a>:</p> + +<blockquote> +<p>JavaScript classes, introduced in ECMAScript 2015, are primarily syntactical sugar over JavaScript's existing prototype-based inheritance. The class syntax <em>does not</em> introduce a new object-oriented inheritance model to JavaScript.</p> +</blockquote> +</div> + +<h3 id="Subclasses_and_inheritance">Subclasses and inheritance</h3> + +<p>In a class-based language, you create a hierarchy of classes through the class definitions. In a class definition, you can specify that the new class is a <em>subclass</em> of an already existing class. The subclass inherits all the properties of the superclass and additionally can add new properties or modify the inherited ones. For example, assume the <code>Employee</code> class includes only the <code>name</code> and <code>dept</code> properties, and <code>Manager</code> is a subclass of <code>Employee</code> that adds the <code>reports</code> property. In this case, an instance of the <code>Manager</code> class would have all three properties: <code>name</code>, <code>dept</code>, and <code>reports</code>.</p> + +<p>JavaScript implements inheritance by allowing you to associate a prototypical object with any constructor function. So, you can create exactly the <code>Employee</code> — <code>Manager</code> example, but you use slightly different terminology. First you define the <code>Employee</code> constructor function, specifying the <code>name</code> and <code>dept</code> properties. Next, you define the <code>Manager</code> constructor function, calling the <code>Employee</code> constructor and specifying the <code>reports</code> property. Finally, you assign a new object derived from <code>Employee.prototype</code> as the <code>prototype</code> for the <code>Manager</code> constructor function. Then, when you create a new <code>Manager</code>, it inherits the <code>name</code> and <code>dept</code> properties from the <code>Employee</code> object.</p> + +<h3 id="Adding_and_removing_properties">Adding and removing properties</h3> + +<p>In class-based languages, you typically create a class at compile time and then you instantiate instances of the class either at compile time or at run time. You cannot change the number or the type of properties of a class after you define the class. In JavaScript, however, at run time you can add or remove properties of any object. If you add a property to an object that is used as the prototype for a set of objects, the objects for which it is the prototype also get the new property.</p> + +<h3 id="Summary_of_differences">Summary of differences</h3> + +<p>The following table gives a short summary of some of these differences. The rest of this chapter describes the details of using JavaScript constructors and prototypes to create an object hierarchy and compares this to how you would do it in Java.</p> + +<table class="standard-table"> + <caption>Comparison of class-based (Java) and prototype-based (JavaScript) object systems</caption> + <thead> + <tr> + <th scope="row">Category</th> + <th scope="col">Class-based (Java)</th> + <th scope="col">Prototype-based (JavaScript)</th> + </tr> + </thead> + <tbody> + <tr> + <th scope="row">Class vs. Instance</th> + <td>Class and instance are distinct entities.</td> + <td>All objects can inherit from another object.</td> + </tr> + <tr> + <th scope="row">Definition</th> + <td>Define a class with a class definition; instantiate a class with constructor methods.</td> + <td>Define and create a set of objects with constructor functions.</td> + </tr> + <tr> + <th scope="row">Creation of new object</th> + <td>Create a single object with the <code>new</code> operator.</td> + <td>Same.</td> + </tr> + <tr> + <th scope="row">Construction of object hierarchy</th> + <td>Construct an object hierarchy by using class definitions to define subclasses of existing classes.</td> + <td>Construct an object hierarchy by assigning an object as the prototype associated with a constructor function.</td> + </tr> + <tr> + <th scope="row">Inheritance model</th> + <td>Inherit properties by following the class chain.</td> + <td>Inherit properties by following the prototype chain.</td> + </tr> + <tr> + <th scope="row">Extension of properties</th> + <td>Class definition specifies <em>all</em> properties of all instances of a class. Cannot add properties dynamically at run time.</td> + <td>Constructor function or prototype specifies an <em>initial set</em> of properties. Can add or remove properties dynamically to individual objects or to the entire set of objects.</td> + </tr> + </tbody> +</table> + +<h2 id="The_employee_example">The employee example</h2> + +<p>The remainder of this chapter uses the employee hierarchy shown in the following figure.</p> + +<div style="display: table-row;"> +<div style="display: table-cell; width: 350px; text-align: center; vertical-align: middle; padding: 10px;"> +<p>A simple object hierarchy with the following objects:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/3060/figure8.1.png"></p> +</div> + +<div style="display: table-cell; vertical-align: middle; padding: 10px;"> +<ul> + <li><code>Employee</code> has the properties <code>name</code> (whose value defaults to the empty string) and <code>dept</code> (whose value defaults to "general").</li> + <li><code>Manager</code> is based on <code>Employee</code>. It adds the <code>reports</code> property (whose value defaults to an empty array, intended to have an array of <code>Employee</code> objects as its value).</li> + <li><code>WorkerBee</code> is also based on <code>Employee</code>. It adds the <code>projects</code> property (whose value defaults to an empty array, intended to have an array of strings as its value).</li> + <li><code>SalesPerson</code> is based on <code>WorkerBee</code>. It adds the <code>quota</code> property (whose value defaults to 100). It also overrides the <code>dept</code> property with the value "sales", indicating that all salespersons are in the same department.</li> + <li><code>Engineer</code> is based on <code>WorkerBee</code>. It adds the <code>machine</code> property (whose value defaults to the empty string) and also overrides the <code>dept</code> property with the value "engineering".</li> +</ul> +</div> +</div> + +<h2 id="Creating_the_hierarchy">Creating the hierarchy</h2> + +<p>There are several ways to define appropriate constructor functions to implement the Employee hierarchy. How you choose to define them depends largely on what you want to be able to do in your application.</p> + +<p>This section shows how to use very simple (and comparatively inflexible) definitions to demonstrate how to get the inheritance to work. In these definitions, you cannot specify any property values when you create an object. The newly-created object simply gets the default values, which you can change at a later time.</p> + +<p>In a real application, you would probably define constructors that allow you to provide property values at object creation time (see <a href="#More_flexible_constructors">More flexible constructors</a> for information). For now, these simple definitions demonstrate how the inheritance occurs.</p> + +<p>The following Java and JavaScript <code>Employee</code> definitions are similar. The only difference is that you need to specify the type for each property in Java but not in JavaScript (this is due to Java being a <a href="https://en.wikipedia.org/wiki/Strong_and_weak_typing">strongly typed language</a> while JavaScript is a weakly typed language).</p> + +<h4 id="JavaScript_using_this_may_cause_an_error_for_the_following_examples">JavaScript (using this may cause an error for the following examples)</h4> + +<pre class="brush: js notranslate">class Employee { + constructor() { + this.name = ''; + this.dept = 'general'; + } +} + +</pre> + +<h4 id="JavaScript_**_use_this_instead">JavaScript ** (use this instead)</h4> + +<pre class="brush: js notranslate">function Employee() { + this.name = ''; + this.dept = 'general'; +} + +</pre> + +<h4 id="Java">Java</h4> + +<pre class="brush: java notranslate">public class Employee { + public String name = ""; + public String dept = "general"; +} +</pre> + +<p>The <code>Manager</code> and <code>WorkerBee</code> definitions show the difference in how to specify the next object higher in the inheritance chain. In JavaScript, you add a prototypical instance as the value of the <code>prototype</code> property of the constructor function, then override the <code>prototype.constructor</code> to the constructor function. You can do so at any time after you define the constructor. In Java, you specify the superclass within the class definition. You cannot change the superclass outside the class definition.</p> + +<h4 id="JavaScript">JavaScript</h4> + +<pre class="brush: js notranslate">function Manager() { + Employee.call(this); + this.reports = []; +} +Manager.prototype = Object.create(Employee.prototype); +Manager.prototype.constructor = Manager; + +function WorkerBee() { + Employee.call(this); + this.projects = []; +} +WorkerBee.prototype = Object.create(Employee.prototype); +WorkerBee.prototype.constructor = WorkerBee; +</pre> + +<h4 id="Java_2">Java</h4> + +<pre class="brush: java notranslate">public class Manager extends Employee { + public Employee[] reports = + new Employee[0]; +} + + + +public class WorkerBee extends Employee { + public String[] projects = new String[0]; +} + + +</pre> + +<p>The <code>Engineer</code> and <code>SalesPerson</code> definitions create objects that descend from <code>WorkerBee</code> and hence from <code>Employee</code>. An object of these types has properties of all the objects above it in the chain. In addition, these definitions override the inherited value of the <code>dept</code> property with new values specific to these objects.</p> + +<h4 id="JavaScript_2">JavaScript</h4> + +<pre class="brush: js notranslate">function SalesPerson() { + WorkerBee.call(this); + this.dept = 'sales'; + this.quota = 100; +} +SalesPerson.prototype = Object.create(WorkerBee.prototype); +SalesPerson.prototype.constructor = SalesPerson; + +function Engineer() { + WorkerBee.call(this); + this.dept = 'engineering'; + this.machine = ''; +} +Engineer.prototype = Object.create(WorkerBee.prototype) +Engineer.prototype.constructor = Engineer; +</pre> + +<h4 id="Java_3">Java</h4> + +<pre class="brush: java notranslate">public class SalesPerson extends WorkerBee { + public String dept = "sales"; + public double quota = 100.0; +} + + +public class Engineer extends WorkerBee { + public String dept = "engineering"; + public String machine = ""; +} + +</pre> + +<p>Using these definitions, you can create instances of these objects that get the default values for their properties. The next figure illustrates using these JavaScript definitions to create new objects and shows the property values for the new objects.</p> + +<div class="note"> +<p><strong>Note:</strong> The term <em><em>instance</em></em> has a specific technical meaning in class-based languages. In these languages, an instance is an individual instantiation of a class and is fundamentally different from a class. In JavaScript, "instance" does not have this technical meaning because JavaScript does not have this difference between classes and instances. However, in talking about JavaScript, "instance" can be used informally to mean an object created using a particular constructor function. So, in this example, you could informally say that <code><code>jane</code></code> is an instance of <code><code>Engineer</code></code>. Similarly, although the terms <em><em>parent</em>, <em>child</em>, <em>ancestor</em></em>, and <em><em>descendant</em></em> do not have formal meanings in JavaScript; you can use them informally to refer to objects higher or lower in the prototype chain.</p> +</div> + +<h3 id="Creating_objects_with_simple_definitions">Creating objects with simple definitions</h3> + +<div class="twocolumns"> +<h4 id="Object_hierarchy">Object hierarchy</h4> + +<p>The following hierarchy is created using the code on the right side.</p> + +<p><img src="https://mdn.mozillademos.org/files/10412/=figure8.3.png"></p> + +<h4 id="Individual_objects_Jim_Sally_Mark_Fred_Jane_etc._Instances_created_from_constructor">Individual objects = Jim, Sally, Mark, Fred, Jane, etc.<br> + "Instances" created from constructor</h4> + +<pre class="brush: js notranslate">var jim = new Employee; +// Parentheses can be omitted if the +// constructor takes no arguments. +// jim.name is '' +// jim.dept is 'general' + +var sally = new Manager; +// sally.name is '' +// sally.dept is 'general' +// sally.reports is [] + +var mark = new WorkerBee; +// mark.name is '' +// mark.dept is 'general' +// mark.projects is [] + +var fred = new SalesPerson; +// fred.name is '' +// fred.dept is 'sales' +// fred.projects is [] +// fred.quota is 100 + +var jane = new Engineer; +// jane.name is '' +// jane.dept is 'engineering' +// jane.projects is [] +// jane.machine is '' +</pre> +</div> + +<h2 id="Object_properties">Object properties</h2> + +<p>This section discusses how objects inherit properties from other objects in the prototype chain and what happens when you add a property at run time.</p> + +<h3 id="Inheriting_properties">Inheriting properties</h3> + +<p>Suppose you create the <code>mark</code> object as a <code>WorkerBee</code> with the following statement:</p> + +<pre class="brush: js notranslate">var mark = new WorkerBee; +</pre> + +<p>When JavaScript sees the <code>new</code> operator, it creates a new generic object and implicitly sets the value of the internal property [[Prototype]] to the value of <code>WorkerBee.prototype</code> and passes this new object as the value of the <em><code>this</code></em> keyword to the <code>WorkerBee</code> constructor function. The internal [[Prototype]] property determines the prototype chain used to return property values. Once these properties are set, JavaScript returns the new object and the assignment statement sets the variable <code>mark</code> to that object.</p> + +<p>This process does not explicitly put values in the <code>mark</code> object (<em>local</em> values) for the properties that <code>mark</code> inherits from the prototype chain. When you ask for the value of a property, JavaScript first checks to see if the value exists in that object. If it does, that value is returned. If the value is not there locally, JavaScript checks the prototype chain (using the internal [[Prototype]] property). If an object in the prototype chain has a value for the property, that value is returned. If no such property is found, JavaScript says the object does not have the property. In this way, the <code>mark</code> object has the following properties and values:</p> + +<pre class="brush: js notranslate">mark.name = ''; +mark.dept = 'general'; +mark.projects = []; +</pre> + +<p>The <code>mark</code> object is assigned local values for the <code>name</code> and <code>dept</code> properties by the Employee constructor. It is assigned a local value for the <code>projects</code> property by the <code>WorkerBee</code> constructor. This gives you inheritance of properties and their values in JavaScript. Some subtleties of this process are discussed in <a href="#Property_inheritance_revisited">Property inheritance revisited</a>.</p> + +<p>Because these constructors do not let you supply instance-specific values, this information is generic. The property values are the default ones shared by all new objects created from <code>WorkerBee</code>. You can, of course, change the values of any of these properties. So, you could give specific information for <code>mark</code> as follows:</p> + +<pre class="brush: js notranslate">mark.name = 'Doe, Mark'; +mark.dept = 'admin'; +mark.projects = ['navigator'];</pre> + +<h3 id="Adding_properties">Adding properties</h3> + +<p>In JavaScript, you can add properties to any object at run time. You are not constrained to use only the properties provided by the constructor function. To add a property that is specific to a single object, you assign a value to the object, as follows:</p> + +<pre class="brush: js notranslate">mark.bonus = 3000; +</pre> + +<p>Now, the <code>mark</code> object has a <code>bonus</code> property, but no other <code>WorkerBee</code> has this property.</p> + +<p>If you add a new property to an object that is being used as the prototype for a constructor function, you add that property to all objects that inherit properties from the prototype. For example, you can add a <code>specialty</code> property to all employees with the following statement:</p> + +<pre class="brush: js notranslate">Employee.prototype.specialty = 'none'; +</pre> + +<p>As soon as JavaScript executes this statement, the <code>mark</code> object also has the <code>specialty</code> property with the value of <code>"none"</code>. The following figure shows the effect of adding this property to the <code>Employee</code> prototype and then overriding it for the <code>Engineer</code> prototype.</p> + +<p><img alt="" class="internal" src="/@api/deki/files/4422/=figure8.4.png" style="height: 519px; width: 833px;"><br> + <small><strong>Adding properties</strong></small></p> + +<h2 id="More_flexible_constructors">More flexible constructors</h2> + +<p>The constructor functions shown so far do not let you specify property values when you create an instance. As with Java, you can provide arguments to constructors to initialize property values for instances. The following figure shows one way to do this.</p> + +<p><img alt="" class="internal" id="figure8.5" src="/@api/deki/files/4423/=figure8.5.png" style="height: 481px; width: 1012px;"><br> + <small><strong>Specifying properties in a constructor, take 1</strong></small></p> + +<p>The following pairs of examples show the Java and JavaScript definitions for these objects.</p> + +<pre class="brush: js notranslate">function Employee(name, dept) { + this.name = name || ''; + this.dept = dept || 'general'; +} +</pre> + +<pre class="brush: java notranslate">public class Employee { + public String name; + public String dept; + public Employee () { + this("", "general"); + } + public Employee (String name) { + this(name, "general"); + } + public Employee (String name, String dept) { + this.name = name; + this.dept = dept; + } +} +</pre> + +<pre class="brush: js notranslate">function WorkerBee(projs) { + this.projects = projs || []; +} +WorkerBee.prototype = new Employee; +</pre> + +<pre class="brush: java notranslate">public class WorkerBee extends Employee { + public String[] projects; + public WorkerBee () { + this(new String[0]); + } + public WorkerBee (String[] projs) { + projects = projs; + } +} +</pre> + +<pre class="brush: js notranslate"> +function Engineer(mach) { + this.dept = 'engineering'; + this.machine = mach || ''; +} +Engineer.prototype = new WorkerBee; +</pre> + +<pre class="brush: java notranslate">public class Engineer extends WorkerBee { + public String machine; + public Engineer () { + dept = "engineering"; + machine = ""; + } + public Engineer (String mach) { + dept = "engineering"; + machine = mach; + } +} +</pre> + +<p>These JavaScript definitions use a special idiom for setting default values:</p> + +<pre class="brush: js notranslate">this.name = name || ''; +</pre> + +<p>The JavaScript logical OR operator (<code>||</code>) evaluates its first argument. If that argument converts to true, the operator returns it. Otherwise, the operator returns the value of the second argument. Therefore, this line of code tests to see if <code>name</code> has a useful value for the <code>name</code> property. If it does, it sets <code>this.name</code> to that value. Otherwise, it sets <code>this.name</code> to the empty string. This chapter uses this idiom for brevity; however, it can be puzzling at first glance.</p> + +<div class="note"> +<p><strong>Note:</strong> This may not work as expected if the constructor function is called with arguments which convert to <code><code>false</code></code> (like <code>0</code> (zero) and empty string (<code><code>""</code></code>). In this case the default value will be chosen.</p> +</div> + +<p>With these definitions, when you create an instance of an object, you can specify values for the locally defined properties. You can use the following statement to create a new <code>Engineer</code>:</p> + +<pre class="brush: js notranslate">var jane = new Engineer('belau'); +</pre> + +<p><code>Jane</code>'s properties are now:</p> + +<pre class="brush: js notranslate">jane.name == ''; +jane.dept == 'engineering'; +jane.projects == []; +jane.machine == 'belau'; +</pre> + +<p>Notice that with these definitions, you cannot specify an initial value for an inherited property such as <code>name</code>. If you want to specify an initial value for inherited properties in JavaScript, you need to add more code to the constructor function.</p> + +<p>So far, the constructor function has created a generic object and then specified local properties and values for the new object. You can have the constructor add more properties by directly calling the constructor function for an object higher in the prototype chain. The following figure shows these new definitions.</p> + +<p><img alt="" class="internal" src="/@api/deki/files/4430/=figure8.6.png" style="height: 534px; width: 1063px;"><br> + <small><strong>Specifying properties in a constructor, take 2</strong></small></p> + +<p>Let's look at one of these definitions in detail. Here's the new definition for the <code>Engineer</code> constructor:</p> + +<pre class="brush: js notranslate">function Engineer(name, projs, mach) { + this.base = WorkerBee; + this.base(name, 'engineering', projs); + this.machine = mach || ''; +} +</pre> + +<p>Suppose you create a new <code>Engineer</code> object as follows:</p> + +<pre class="brush: js notranslate">var jane = new Engineer('Doe, Jane', ['navigator', 'javascript'], 'belau'); +</pre> + +<p>JavaScript follows these steps:</p> + +<ol> + <li>The <code>new</code> operator creates a generic object and sets its <code>__proto__</code> property to <code>Engineer.prototype</code>.</li> + <li>The <code>new</code> operator passes the new object to the <code>Engineer</code> constructor as the value of the <code>this</code> keyword.</li> + <li>The constructor creates a new property called <code>base</code> for that object and assigns the value of the <code>WorkerBee</code> constructor to the <code>base</code> property. This makes the <code>WorkerBee</code> constructor a method of the <code>Engineer</code> object. The name of the <code>base</code> property is not special. You can use any legal property name; <code>base</code> is simply evocative of its purpose.</li> + <li>The constructor calls the <code>base</code> method, passing as its arguments two of the arguments passed to the constructor (<code>"Doe, Jane"</code> and <code>["navigator", "javascript"]</code>) and also the string <code>"engineering"</code>. Explicitly using <code>"engineering"</code> in the constructor indicates that all <code>Engineer</code> objects have the same value for the inherited <code>dept</code> property, and this value overrides the value inherited from <code>Employee</code>.</li> + <li>Because <code>base</code> is a method of <code>Engineer</code>, within the call to <code>base</code>, JavaScript binds the <code>this</code> keyword to the object created in Step 1. Thus, the <code>WorkerBee</code> function in turn passes the <code>"Doe, Jane"</code> and <code>"engineering"</code> arguments to the <code>Employee</code> constructor function. Upon return from the <code>Employee</code> constructor function, the <code>WorkerBee</code> function uses the remaining argument to set the <code>projects</code> property.</li> + <li>Upon return from the <code>base</code> method, the <code>Engineer</code> constructor initializes the object's <code>machine</code> property to <code>"belau"</code>.</li> + <li>Upon return from the constructor, JavaScript assigns the new object to the <code>jane</code> variable.</li> +</ol> + +<p>You might think that, having called the <code>WorkerBee</code> constructor from inside the <code>Engineer</code> constructor, you have set up inheritance appropriately for <code>Engineer</code> objects. This is not the case. Calling the <code>WorkerBee</code> constructor ensures that an <code>Engineer</code> object starts out with the properties specified in all constructor functions that are called. However, if you later add properties to the <code>Employee</code> or <code>WorkerBee</code> prototypes, those properties are not inherited by the <code>Engineer</code> object. For example, assume you have the following statements:</p> + +<pre class="brush: js notranslate">function Engineer(name, projs, mach) { + this.base = WorkerBee; + this.base(name, 'engineering', projs); + this.machine = mach || ''; +} +var jane = new Engineer('Doe, Jane', ['navigator', 'javascript'], 'belau'); +Employee.prototype.specialty = 'none'; +</pre> + +<p>The <code>jane</code> object does not inherit the <code>specialty</code> property. You still need to explicitly set up the prototype to ensure dynamic inheritance. Assume instead you have these statements:</p> + +<pre class="brush: js notranslate">function Engineer(name, projs, mach) { + this.base = WorkerBee; + this.base(name, 'engineering', projs); + this.machine = mach || ''; +} +Engineer.prototype = new WorkerBee; +var jane = new Engineer('Doe, Jane', ['navigator', 'javascript'], 'belau'); +Employee.prototype.specialty = 'none'; +</pre> + +<p>Now the value of the <code>jane</code> object's <code>specialty</code> property is "none".</p> + +<p>Another way of inheriting is by using the <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call" title="en-US/docs/JavaScript/Reference/Global Objects/Function/call">call()</a></code> / <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply" title="en-US/docs/JavaScript/Reference/Global Objects/Function/apply"><code>apply()</code></a> methods. Below are equivalent:</p> + +<pre class="brush: js notranslate">function Engineer(name, projs, mach) { + this.base = WorkerBee; + this.base(name, 'engineering', projs); + this.machine = mach || ''; +} +</pre> + +<pre class="brush: js notranslate">function Engineer(name, projs, mach) { + WorkerBee.call(this, name, 'engineering', projs); + this.machine = mach || ''; +} +</pre> + +<p>Using the javascript <code>call()</code> method makes a cleaner implementation because the <code>base</code> is not needed anymore.</p> + +<h2 id="Property_inheritance_revisited">Property inheritance revisited</h2> + +<p>The preceding sections described how JavaScript constructors and prototypes provide hierarchies and inheritance. This section discusses some subtleties that were not necessarily apparent in the earlier discussions.</p> + +<h3 id="Local_versus_inherited_values">Local versus inherited values</h3> + +<p>When you access an object property, JavaScript performs these steps, as described earlier in this chapter:</p> + +<ol> + <li>Check to see if the value exists locally. If it does, return that value.</li> + <li>If there is not a local value, check the prototype chain (using the <code>__proto__</code> property).</li> + <li>If an object in the prototype chain has a value for the specified property, return that value.</li> + <li>If no such property is found, the object does not have the property.</li> +</ol> + +<p>The outcome of these steps depends on how you define things along the way. The original example had these definitions:</p> + +<pre class="brush: js notranslate">function Employee() { + this.name = ''; + this.dept = 'general'; +} + +function WorkerBee() { + this.projects = []; +} +WorkerBee.prototype = new Employee; +</pre> + +<p>With these definitions, suppose you create <code>amy</code> as an instance of <code>WorkerBee</code> with the following statement:</p> + +<pre class="brush: js notranslate">var amy = new WorkerBee; +</pre> + +<p>The <code>amy</code> object has one local property, <code>projects</code>. The values for the <code>name</code> and <code>dept</code> properties are not local to <code>amy</code> and so derive from the <code>amy</code> object's <code>__proto__</code> property. Thus, <code>amy</code> has these property values:</p> + +<pre class="brush: js notranslate">amy.name == ''; +amy.dept == 'general'; +amy.projects == []; +</pre> + +<p>Now suppose you change the value of the <code>name</code> property in the prototype associated with <code>Employee</code>:</p> + +<pre class="brush: js notranslate">Employee.prototype.name = 'Unknown'; +</pre> + +<p>At first glance, you might expect that new value to propagate down to all the instances of <code>Employee</code>. However, it does not.</p> + +<p>When you create <em>any</em> instance of the <code>Employee</code> object, that instance gets a <strong>local value</strong> for the <code>name</code> property (the empty string). This means that when you set the <code>WorkerBee</code> prototype by creating a new <code>Employee</code> object, <code>WorkerBee.prototype</code> has a local value for the <code>name</code> property. Therefore, when JavaScript looks up the <code>name</code> property of the <code>amy</code> object (an instance of <code>WorkerBee</code>), JavaScript finds the local value for that property in <code>WorkerBee.prototype</code>. It therefore does not look further up the chain to <code>Employee.prototype</code>.</p> + +<p>If you want to change the value of an object property at run time and have the new value be inherited by all descendants of the object, you cannot define the property in the object's constructor function. Instead, you add it to the constructor's associated prototype. For example, assume you change the preceding code to the following:</p> + +<pre class="brush: js notranslate">function Employee() { + this.dept = 'general'; // Note that this.name (a local variable) does not appear here +} +Employee.prototype.name = ''; // A single copy + +function WorkerBee() { + this.projects = []; +} +WorkerBee.prototype = new Employee; + +var amy = new WorkerBee; + +Employee.prototype.name = 'Unknown'; +</pre> + +<p>In this case, the <code>name</code> property of <code>amy</code> becomes "Unknown".</p> + +<p>As these examples show, if you want to have default values for object properties and you want to be able to change the default values at run time, you should set the properties in the constructor's prototype, not in the constructor function itself.</p> + +<h3 id="Determining_instance_relationships">Determining instance relationships</h3> + +<p>Property lookup in JavaScript looks within an object's own properties and, if the property name is not found, it looks within the special object property <code>__proto__</code>. This continues recursively; the process is called "lookup in the prototype chain".</p> + +<p>The special property <code>__proto__</code> is set when an object is constructed; it is set to the value of the constructor's <code>prototype</code> property. So the expression <code>new Foo()</code> creates an object with <code>__proto__ == <code class="moz-txt-verticalline">Foo.prototype</code></code>. Consequently, changes to the properties of <code class="moz-txt-verticalline">Foo.prototype</code> alters the property lookup for all objects that were created by <code>new Foo()</code>.</p> + +<p>Every object has a <code>__proto__</code> object property (except <code>Object</code>); every function has a <code>prototype</code> object property. So objects can be related by 'prototype inheritance' to other objects. You can test for inheritance by comparing an object's <code>__proto__</code> to a function's <code>prototype</code> object. JavaScript provides a shortcut: the <code>instanceof</code> operator tests an object against a function and returns true if the object inherits from the function prototype. For example,</p> + +<pre class="brush: js notranslate">var f = new Foo(); +var isTrue = (f instanceof Foo);</pre> + +<p>For a more detailed example, suppose you have the same set of definitions shown in <a href="#Inheriting_properties">Inheriting properties</a>. Create an <code>Engineer</code> object as follows:</p> + +<pre class="brush: js notranslate">var chris = new Engineer('Pigman, Chris', ['jsd'], 'fiji'); +</pre> + +<p>With this object, the following statements are all true:</p> + +<pre class="brush: js notranslate">chris.__proto__ == Engineer.prototype; +chris.__proto__.__proto__ == WorkerBee.prototype; +chris.__proto__.__proto__.__proto__ == Employee.prototype; +chris.__proto__.__proto__.__proto__.__proto__ == Object.prototype; +chris.__proto__.__proto__.__proto__.__proto__.__proto__ == null; +</pre> + +<p>Given this, you could write an <code>instanceOf</code> function as follows:</p> + +<pre class="brush: js notranslate">function instanceOf(object, constructor) { + object = object.__proto__; + while (object != null) { + if (object == constructor.prototype) + return true; + if (typeof object == 'xml') { + return constructor.prototype == XML.prototype; + } + object = object.__proto__; + } + return false; +} +</pre> + +<div class="note"><strong>Note:</strong> The implementation above checks the type of the object against "xml" in order to work around a quirk of how XML objects are represented in recent versions of JavaScript. See <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=634150">bug 634150</a> if you want the nitty-gritty details.</div> + +<p>Using the instanceOf function defined above, these expressions are true:</p> + +<pre class="brush: js notranslate">instanceOf(chris, Engineer) +instanceOf(chris, WorkerBee) +instanceOf(chris, Employee) +instanceOf(chris, Object) +</pre> + +<p>But the following expression is false:</p> + +<pre class="brush: js notranslate">instanceOf(chris, SalesPerson) +</pre> + +<h3 id="Global_information_in_constructors">Global information in constructors</h3> + +<p>When you create constructors, you need to be careful if you set global information in the constructor. For example, assume that you want a unique ID to be automatically assigned to each new employee. You could use the following definition for <code>Employee</code>:</p> + +<pre class="brush: js notranslate">var idCounter = 1; + +function Employee(name, dept) { + this.name = name || ''; + this.dept = dept || 'general'; + this.id = idCounter++; +} +</pre> + +<p>With this definition, when you create a new <code>Employee</code>, the constructor assigns it the next ID in sequence and then increments the global ID counter. So, if your next statement is the following, <code>victoria.id</code> is 1 and <code>harry.id</code> is 2:</p> + +<pre class="brush: js notranslate">var victoria = new Employee('Pigbert, Victoria', 'pubs'); +var harry = new Employee('Tschopik, Harry', 'sales'); +</pre> + +<p>At first glance that seems fine. However, <code>idCounter</code> gets incremented every time an <code>Employee</code> object is created, for whatever purpose. If you create the entire <code>Employee</code> hierarchy shown in this chapter, the <code>Employee</code> constructor is called every time you set up a prototype. Suppose you have the following code:</p> + +<pre class="brush: js notranslate">var idCounter = 1; + +function Employee(name, dept) { + this.name = name || ''; + this.dept = dept || 'general'; + this.id = idCounter++; +} + +function Manager(name, dept, reports) {...} +Manager.prototype = new Employee; + +function WorkerBee(name, dept, projs) {...} +WorkerBee.prototype = new Employee; + +function Engineer(name, projs, mach) {...} +Engineer.prototype = new WorkerBee; + +function SalesPerson(name, projs, quota) {...} +SalesPerson.prototype = new WorkerBee; + +var mac = new Engineer('Wood, Mac'); +</pre> + +<p>Further assume that the definitions omitted here have the <code>base</code> property and call the constructor above them in the prototype chain. In this case, by the time the <code>mac</code> object is created, <code>mac.id</code> is 5.</p> + +<p>Depending on the application, it may or may not matter that the counter has been incremented these extra times. If you care about the exact value of this counter, one possible solution involves instead using the following constructor:</p> + +<pre class="brush: js notranslate">function Employee(name, dept) { + this.name = name || ''; + this.dept = dept || 'general'; + if (name) + this.id = idCounter++; +} +</pre> + +<p>When you create an instance of <code>Employee</code> to use as a prototype, you do not supply arguments to the constructor. Using this definition of the constructor, when you do not supply arguments, the constructor does not assign a value to the id and does not update the counter. Therefore, for an <code>Employee</code> to get an assigned id, you must specify a name for the employee. In this example, <code>mac.id</code> would be 1.</p> + +<p>Alternatively, you can create a copy of Employee's prototype object to assign to WorkerBee:</p> + +<pre class="brush: js notranslate">WorkerBee.prototype = Object.create(Employee.prototype); +// instead of WorkerBee.prototype = new Employee +</pre> + +<h3 id="No_multiple_inheritance">No multiple inheritance</h3> + +<p>Some object-oriented languages allow multiple inheritance. That is, an object can inherit the properties and values from unrelated parent objects. JavaScript does not support multiple inheritance.</p> + +<p>Inheritance of property values occurs at run time by JavaScript searching the prototype chain of an object to find a value. Because an object has a single associated prototype, JavaScript cannot dynamically inherit from more than one prototype chain.</p> + +<p>In JavaScript, you can have a constructor function call more than one other constructor function within it. This gives the illusion of multiple inheritance. For example, consider the following statements:</p> + +<pre class="brush: js notranslate">function Hobbyist(hobby) { + this.hobby = hobby || 'scuba'; +} + +function Engineer(name, projs, mach, hobby) { + this.base1 = WorkerBee; + this.base1(name, 'engineering', projs); + this.base2 = Hobbyist; + this.base2(hobby); + this.machine = mach || ''; +} +Engineer.prototype = new WorkerBee; + +var dennis = new Engineer('Doe, Dennis', ['collabra'], 'hugo'); +</pre> + +<p>Further assume that the definition of <code>WorkerBee</code> is as used earlier in this chapter. In this case, the <code>dennis</code> object has these properties:</p> + +<pre class="brush: js notranslate">dennis.name == 'Doe, Dennis'; +dennis.dept == 'engineering'; +dennis.projects == ['collabra']; +dennis.machine == 'hugo'; +dennis.hobby == 'scuba'; +</pre> + +<p>So <code>dennis</code> does get the <code>hobby</code> property from the <code>Hobbyist</code> constructor. However, assume you then add a property to the <code>Hobbyist</code> constructor's prototype:</p> + +<pre class="brush: js notranslate">Hobbyist.prototype.equipment = ['mask', 'fins', 'regulator', 'bcd']; +</pre> + +<p>The <code>dennis</code> object does not inherit this new property.</p> + +<div>{{PreviousNext("Web/JavaScript/Guide/Working_with_Objects", "Web/JavaScript/Guide/Using_promises")}}</div> diff --git a/files/fa/web/javascript/راهنما/functions/index.html b/files/fa/web/javascript/راهنما/functions/index.html new file mode 100644 index 0000000000..626ea544bf --- /dev/null +++ b/files/fa/web/javascript/راهنما/functions/index.html @@ -0,0 +1,648 @@ +--- +title: Functions +slug: Web/JavaScript/راهنما/Functions +translation_of: Web/JavaScript/Guide/Functions +--- +<div dir="rtl">{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Loops_and_iteration", "Web/JavaScript/Guide/Expressions_and_Operators")}}</div> + +<p class="summary">Functions are one of the fundamental building blocks in JavaScript. A function is a JavaScript procedure—a set of statements that performs a task or calculates a value. To use a function, you must define it somewhere in the scope from which you wish to call it.</p> + +<p>See also the <a href="/en-US/docs/Web/JavaScript/Reference/Functions">exhaustive reference chapter about JavaScript functions</a> to get to know the details.</p> + +<h2 id="Defining_functions">Defining functions</h2> + +<h3 id="Function_declarations">Function declarations</h3> + +<p>A <strong>function definition</strong> (also called a <strong>function declaration</strong>, or <strong>function statement</strong>) consists of the <a href="/en-US/docs/Web/JavaScript/Reference/Statements/function" title="function"><code>function</code></a> keyword, followed by:</p> + +<ul> + <li>The name of the function.</li> + <li>A list of parameters to the function, enclosed in parentheses and separated by commas.</li> + <li>The JavaScript statements that define the function, enclosed in curly brackets, <code>{ }</code>.</li> +</ul> + +<p>For example, the following code defines a simple function named <code> square</code>:</p> + +<pre class="brush: js">function square(number) { + return number * number; +} +</pre> + +<p>The function <code>square</code> takes one parameter, called <code>number</code>. The function consists of one statement that says to return the parameter of the function (that is, <code>number</code>) multiplied by itself. The <a href="/en-US/docs/Web/JavaScript/Reference/Statements/return" title="return"><code>return</code></a> statement specifies the value returned by the function.</p> + +<pre class="brush: js">return number * number; +</pre> + +<p>Primitive parameters (such as a number) are passed to functions <strong>by value</strong>; the value is passed to the function, but if the function changes the value of the parameter, this change is not reflected globally or in the calling function.</p> + +<p>If you pass an object (i.e. a non-primitive value, such as {{jsxref("Array")}} or a user-defined object) as a parameter and the function changes the object's properties, that change is visible outside the function, as shown in the following example:</p> + +<pre class="brush: js">function myFunc(theObject) { + theObject.make = 'Toyota'; +} + +var mycar = {make: 'Honda', model: 'Accord', year: 1998}; +var x, y; + +x = mycar.make; // x gets the value "Honda" + +myFunc(mycar); +y = mycar.make; // y gets the value "Toyota" + // (the make property was changed by the function) +</pre> + +<h3 id="Function_expressions">Function expressions</h3> + +<p>While the function declaration above is syntactically a statement, functions can also be created by a <a href="/en-US/docs/Web/JavaScript/Reference/Operators/function">function expression</a>. Such a function can be <strong>anonymous</strong>; it does not have to have a name. For example, the function <code>square</code> could have been defined as:</p> + +<pre class="brush: js">var square = function(number) { return number * number; }; +var x = square(4); // x gets the value 16</pre> + +<p>However, a name can be provided with a function expression and can be used inside the function to refer to itself, or in a debugger to identify the function in stack traces:</p> + +<pre class="brush: js">var factorial = function fac(n) { return n < 2 ? 1 : n * fac(n - 1); }; + +console.log(factorial(3)); +</pre> + +<p>Function expressions are convenient when passing a function as an argument to another function. The following example shows a <code>map</code> function being defined and then called with an expression function as its first parameter:</p> + +<pre class="brush: js">function map(f, a) { + var result = [], // Create a new Array + i; + for (i = 0; i != a.length; i++) + result[i] = f(a[i]); + return result; +} +</pre> + +<p>The following code:</p> + +<pre class="brush: js">var numbers = [0,1, 2, 5,10]; +var cube= numbers.map(function(x) { + return x * x * x; +}); +console.log(cube);</pre> + +<p>returns [0, 1, 8, 125, 1000].</p> + +<p>In JavaScript, a function can be defined based on a condition. For example, the following function definition defines <code>myFunc</code> only if <code>num</code> equals 0:</p> + +<pre class="brush: js">var myFunc; +if (num === 0) { + myFunc = function(theObject) { + theObject.make = 'Toyota'; + } +}</pre> + +<p>In addition to defining functions as described here, you can also use the {{jsxref("Function")}} constructor to create functions from a string at runtime, much like {{jsxref("eval", "eval()")}}.</p> + +<p>A <strong>method</strong> is a function that is a property of an object. Read more about objects and methods in <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_Objects" title="en-US/docs/JavaScript/Guide/Working with Objects">Working with objects</a>.</p> + +<h2 id="Calling_functions">Calling functions</h2> + +<p>Defining a function does not execute it. Defining the function simply names the function and specifies what to do when the function is called. <strong>Calling</strong> the function actually performs the specified actions with the indicated parameters. For example, if you define the function <code>square</code>, you could call it as follows:</p> + +<pre class="brush: js">square(5); +</pre> + +<p>The preceding statement calls the function with an argument of 5. The function executes its statements and returns the value 25.</p> + +<p>Functions must be in scope when they are called, but the function declaration can be hoisted (appear below the call in the code), as in this example:</p> + +<pre class="brush: js">console.log(square(5)); +/* ... */ +function square(n) { return n * n; } +</pre> + +<p>The scope of a function is the function in which it is declared, or the entire program if it is declared at the top level.</p> + +<div class="note"> +<p><strong>Note:</strong> This works only when defining the function using the above syntax (i.e. <code>function funcName(){}</code>). The code below will not work. That means, function hoisting only works with function declaration and not with function expression.</p> +</div> + +<pre class="brush: js example-bad">console.log(square); // square is hoisted with an initial value undefined. +console.log(square(5)); // TypeError: square is not a function +var square = function(n) { + return n * n; +} +</pre> + +<p>The arguments of a function are not limited to strings and numbers. You can pass whole objects to a function. The <code>show_props()</code> function (defined in <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Objects_and_Properties" title="https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Working_with_Objects#Objects_and_Properties">Working with objects</a>) is an example of a function that takes an object as an argument.</p> + +<p>A function can call itself. For example, here is a function that computes factorials recursively:</p> + +<pre class="brush: js">function factorial(n) { + if ((n === 0) || (n === 1)) + return 1; + else + return (n * factorial(n - 1)); +} +</pre> + +<p>You could then compute the factorials of one through five as follows:</p> + +<pre class="brush: js">var a, b, c, d, e; +a = factorial(1); // a gets the value 1 +b = factorial(2); // b gets the value 2 +c = factorial(3); // c gets the value 6 +d = factorial(4); // d gets the value 24 +e = factorial(5); // e gets the value 120 +</pre> + +<p>There are other ways to call functions. There are often cases where a function needs to be called dynamically, or the number of arguments to a function vary, or in which the context of the function call needs to be set to a specific object determined at runtime. It turns out that functions are, themselves, objects, and these objects in turn have methods (see the {{jsxref("Function")}} object). One of these, the {{jsxref("Function.apply", "apply()")}} method, can be used to achieve this goal.</p> + +<h2 class="deki-transform" id="Function_scope">Function scope</h2> + +<p>Variables defined inside a function cannot be accessed from anywhere outside the function, because the variable is defined only in the scope of the function. However, a function can access all variables and functions defined inside the scope in which it is defined. In other words, a function defined in the global scope can access all variables defined in the global scope. A function defined inside another function can also access all variables defined in its parent function and any other variable to which the parent function has access.</p> + +<pre class="brush: js">// The following variables are defined in the global scope +var num1 = 20, + num2 = 3, + name = 'Chamahk'; + +// This function is defined in the global scope +function multiply() { + return num1 * num2; +} + +multiply(); // Returns 60 + +// A nested function example +function getScore() { + var num1 = 2, + num2 = 3; + + function add() { + return name + ' scored ' + (num1 + num2); + } + + return add(); +} + +getScore(); // Returns "Chamahk scored 5" +</pre> + +<h2 id="Scope_and_the_function_stack">Scope and the function stack</h2> + +<h3 id="Recursion">Recursion</h3> + +<p>A function can refer to and call itself. There are three ways for a function to refer to itself:</p> + +<ol> + <li>the function's name</li> + <li><code><a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee">arguments.callee</a></code></li> + <li>an in-scope variable that refers to the function</li> +</ol> + +<p>For example, consider the following function definition:</p> + +<pre class="brush: js">var foo = function bar() { + // statements go here +}; +</pre> + +<p>Within the function body, the following are all equivalent:</p> + +<ol> + <li><code>bar()</code></li> + <li><code>arguments.callee()</code></li> + <li><code>foo()</code></li> +</ol> + +<p>A function that calls itself is called a <em>recursive function</em>. In some ways, recursion is analogous to a loop. Both execute the same code multiple times, and both require a condition (to avoid an infinite loop, or rather, infinite recursion in this case). For example, the following loop:</p> + +<pre class="brush: js">var x = 0; +while (x < 10) { // "x < 10" is the loop condition + // do stuff + x++; +} +</pre> + +<p>can be converted into a recursive function and a call to that function:</p> + +<pre class="brush: js">function loop(x) { + if (x >= 10) // "x >= 10" is the exit condition (equivalent to "!(x < 10)") + return; + // do stuff + loop(x + 1); // the recursive call +} +loop(0); +</pre> + +<p>However, some algorithms cannot be simple iterative loops. For example, getting all the nodes of a tree structure (e.g. the <a href="/en-US/docs/DOM">DOM</a>) is more easily done using recursion:</p> + +<pre class="brush: js">function walkTree(node) { + if (node == null) // + return; + // do something with node + for (var i = 0; i < node.childNodes.length; i++) { + walkTree(node.childNodes[i]); + } +} +</pre> + +<p>Compared to the function <code>loop</code>, each recursive call itself makes many recursive calls here.</p> + +<p>It is possible to convert any recursive algorithm to a non-recursive one, but often the logic is much more complex and doing so requires the use of a stack. In fact, recursion itself uses a stack: the function stack.</p> + +<p>The stack-like behavior can be seen in the following example:</p> + +<pre class="brush: js">function foo(i) { + if (i < 0) + return; + console.log('begin: ' + i); + foo(i - 1); + console.log('end: ' + i); +} +foo(3); + +// Output: + +// begin: 3 +// begin: 2 +// begin: 1 +// begin: 0 +// end: 0 +// end: 1 +// end: 2 +// end: 3</pre> + +<h3 id="Nested_functions_and_closures">Nested functions and closures</h3> + +<p>You can nest a function within a function. The nested (inner) function is private to its containing (outer) function. It also forms a <em>closure</em>. A closure is an expression (typically a function) that can have free variables together with an environment that binds those variables (that "closes" the expression).</p> + +<p>Since a nested function is a closure, this means that a nested function can "inherit" the arguments and variables of its containing function. In other words, the inner function contains the scope of the outer function.</p> + +<p>To summarize:</p> + +<ul> + <li>The inner function can be accessed only from statements in the outer function.</li> +</ul> + +<ul> + <li>The inner function forms a closure: the inner function can use the arguments and variables of the outer function, while the outer function cannot use the arguments and variables of the inner function.</li> +</ul> + +<p>The following example shows nested functions:</p> + +<pre class="brush: js">function addSquares(a, b) { + function square(x) { + return x * x; + } + return square(a) + square(b); +} +a = addSquares(2, 3); // returns 13 +b = addSquares(3, 4); // returns 25 +c = addSquares(4, 5); // returns 41 +</pre> + +<p>Since the inner function forms a closure, you can call the outer function and specify arguments for both the outer and inner function:</p> + +<pre class="brush: js">function outside(x) { + function inside(y) { + return x + y; + } + return inside; +} +fn_inside = outside(3); // Think of it like: give me a function that adds 3 to whatever you give it +result = fn_inside(5); // returns 8 + +result1 = outside(3)(5); // returns 8 +</pre> + +<h3 id="Preservation_of_variables">Preservation of variables</h3> + +<p>Notice how <code>x</code> is preserved when <code>inside</code> is returned. A closure must preserve the arguments and variables in all scopes it references. Since each call provides potentially different arguments, a new closure is created for each call to outside. The memory can be freed only when the returned <code>inside</code> is no longer accessible.</p> + +<p>This is not different from storing references in other objects, but is often less obvious because one does not set the references directly and cannot inspect them.</p> + +<h3 id="Multiply-nested_functions">Multiply-nested functions</h3> + +<p>Functions can be multiply-nested, i.e. a function (A) containing a function (B) containing a function (C). Both functions B and C form closures here, so B can access A and C can access B. In addition, since C can access B which can access A, C can also access A. Thus, the closures can contain multiple scopes; they recursively contain the scope of the functions containing it. This is called <em>scope chaining</em>. (Why it is called "chaining" will be explained later.)</p> + +<p>Consider the following example:</p> + +<pre class="brush: js">function A(x) { + function B(y) { + function C(z) { + console.log(x + y + z); + } + C(3); + } + B(2); +} +A(1); // logs 6 (1 + 2 + 3) +</pre> + +<p>In this example, <code>C</code> accesses <code>B</code>'s <code>y</code> and <code>A</code>'s <code>x</code>. This can be done because:</p> + +<ol> + <li><code>B</code> forms a closure including <code>A</code>, i.e. <code>B</code> can access <code>A</code>'s arguments and variables.</li> + <li><code>C</code> forms a closure including <code>B</code>.</li> + <li>Because <code>B</code>'s closure includes <code>A</code>, <code>C</code>'s closure includes <code>A</code>, <code>C</code> can access both <code>B</code> <em>and</em> <code>A</code>'s arguments and variables. In other words, <code>C</code> <em>chains</em> the scopes of <code>B</code> and <code>A</code> in that order.</li> +</ol> + +<p>The reverse, however, is not true. <code>A</code> cannot access <code>C</code>, because <code>A</code> cannot access any argument or variable of <code>B</code>, which <code>C</code> is a variable of. Thus, <code>C</code> remains private to only <code>B</code>.</p> + +<h3 id="Name_conflicts">Name conflicts</h3> + +<p>When two arguments or variables in the scopes of a closure have the same name, there is a <em>name conflict</em>. More inner scopes take precedence, so the inner-most scope takes the highest precedence, while the outer-most scope takes the lowest. This is the scope chain. The first on the chain is the inner-most scope, and the last is the outer-most scope. Consider the following:</p> + +<pre class="brush: js">function outside() { + var x = 5; + function inside(x) { + return x * 2; + } + return inside; +} + +outside()(10); // returns 20 instead of 10 +</pre> + +<p>The name conflict happens at the statement <code>return x</code> and is between <code>inside</code>'s parameter <code>x</code> and <code>outside</code>'s variable <code>x</code>. The scope chain here is {<code>inside</code>, <code>outside</code>, global object}. Therefore <code>inside</code>'s <code>x</code> takes precedences over <code>outside</code>'s <code>x</code>, and 20 (<code>inside</code>'s <code>x</code>) is returned instead of 10 (<code>outside</code>'s <code>x</code>).</p> + +<h2 id="Closures">Closures</h2> + +<p>Closures are one of the most powerful features of JavaScript. JavaScript allows for the nesting of functions and grants the inner function full access to all the variables and functions defined inside the outer function (and all other variables and functions that the outer function has access to). However, the outer function does not have access to the variables and functions defined inside the inner function. This provides a sort of security for the variables of the inner function. Also, since the inner function has access to the scope of the outer function, the variables and functions defined in the outer function will live longer than the duration of the inner function execution, if the inner function manages to survive beyond the life of the outer function. A closure is created when the inner function is somehow made available to any scope outside the outer function.</p> + +<pre class="brush: js">var pet = function(name) { // The outer function defines a variable called "name" + var getName = function() { + return name; // The inner function has access to the "name" variable of the outer function + } + return getName; // Return the inner function, thereby exposing it to outer scopes +} +myPet = pet('Vivie'); + +myPet(); // Returns "Vivie" +</pre> + +<p>It can be much more complex than the code above. An object containing methods for manipulating the inner variables of the outer function can be returned.</p> + +<pre class="brush: js">var createPet = function(name) { + var sex; + + return { + setName: function(newName) { + name = newName; + }, + + getName: function() { + return name; + }, + + getSex: function() { + return sex; + }, + + setSex: function(newSex) { + if(typeof newSex === 'string' && (newSex.toLowerCase() === 'male' || newSex.toLowerCase() === 'female')) { + sex = newSex; + } + } + } +} + +var pet = createPet('Vivie'); +pet.getName(); // Vivie + +pet.setName('Oliver'); +pet.setSex('male'); +pet.getSex(); // male +pet.getName(); // Oliver +</pre> + +<p>In the code above, the <code>name</code> variable of the outer function is accessible to the inner functions, and there is no other way to access the inner variables except through the inner functions. The inner variables of the inner functions act as safe stores for the outer arguments and variables. They hold "persistent", yet secure, data for the inner functions to work with. The functions do not even have to be assigned to a variable, or have a name.</p> + +<pre class="brush: js">var getCode = (function() { + var secureCode = '0]Eal(eh&2'; // A code we do not want outsiders to be able to modify... + + return function() { + return secureCode; + }; +}()); + +getCode(); // Returns the secureCode +</pre> + +<p>There are, however, a number of pitfalls to watch out for when using closures. If an enclosed function defines a variable with the same name as the name of a variable in the outer scope, there is no way to refer to the variable in the outer scope again.</p> + +<pre class="brush: js">var createPet = function(name) { // Outer function defines a variable called "name" + return { + setName: function(name) { // Enclosed function also defines a variable called "name" + name = name; // ??? How do we access the "name" defined by the outer function ??? + } + } +} +</pre> + +<h2 id="Using_the_arguments_object">Using the arguments object</h2> + +<p>The arguments of a function are maintained in an array-like object. Within a function, you can address the arguments passed to it as follows:</p> + +<pre class="brush: js">arguments[i] +</pre> + +<p>where <code>i</code> is the ordinal number of the argument, starting at zero. So, the first argument passed to a function would be <code>arguments[0]</code>. The total number of arguments is indicated by <code>arguments.length</code>.</p> + +<p>Using the <code>arguments</code> object, you can call a function with more arguments than it is formally declared to accept. This is often useful if you don't know in advance how many arguments will be passed to the function. You can use <code>arguments.length</code> to determine the number of arguments actually passed to the function, and then access each argument using the <code>arguments</code> object.</p> + +<p>For example, consider a function that concatenates several strings. The only formal argument for the function is a string that specifies the characters that separate the items to concatenate. The function is defined as follows:</p> + +<pre class="brush: js">function myConcat(separator) { + var result = ''; // initialize list + var i; + // iterate through arguments + for (i = 1; i < arguments.length; i++) { + result += arguments[i] + separator; + } + return result; +} +</pre> + +<p>You can pass any number of arguments to this function, and it concatenates each argument into a string "list":</p> + +<pre class="brush: js">// returns "red, orange, blue, " +myConcat(', ', 'red', 'orange', 'blue'); + +// returns "elephant; giraffe; lion; cheetah; " +myConcat('; ', 'elephant', 'giraffe', 'lion', 'cheetah'); + +// returns "sage. basil. oregano. pepper. parsley. " +myConcat('. ', 'sage', 'basil', 'oregano', 'pepper', 'parsley'); +</pre> + +<div class="note"> +<p><strong>Note:</strong> The <code>arguments</code> variable is "array-like", but not an array. It is array-like in that it has a numbered index and a <code>length</code> property. However, it does not possess all of the array-manipulation methods.</p> +</div> + +<p>See the {{jsxref("Function")}} object in the JavaScript reference for more information.</p> + +<h2 id="Function_parameters">Function parameters</h2> + +<p>Starting with ECMAScript 2015, there are two new kinds of parameters: default parameters and rest parameters.</p> + +<h3 id="Default_parameters">Default parameters</h3> + +<p>In JavaScript, parameters of functions default to <code>undefined</code>. However, in some situations it might be useful to set a different default value. This is where default parameters can help.</p> + +<p>In the past, the general strategy for setting defaults was to test parameter values in the body of the function and assign a value if they are <code>undefined</code>. If in the following example, no value is provided for <code>b</code> in the call, its value would be <code>undefined</code> when evaluating <code>a*b</code> and the call to <code>multiply</code> would have returned <code>NaN</code>. However, this is caught with the second line in this example:</p> + +<pre class="brush: js">function multiply(a, b) { + b = typeof b !== 'undefined' ? b : 1; + + return a * b; +} + +multiply(5); // 5 +</pre> + +<p>With default parameters, the check in the function body is no longer necessary. Now, you can simply put <code>1</code> as the default value for <code>b</code> in the function head:</p> + +<pre class="brush: js">function multiply(a, b = 1) { + return a * b; +} + +multiply(5); // 5</pre> + +<p>For more details, see <a href="/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters">default parameters</a> in the reference.</p> + +<h3 id="Rest_parameters">Rest parameters</h3> + +<p>The <a href="/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters">rest parameter</a> syntax allows us to represent an indefinite number of arguments as an array. In the example, we use the rest parameters to collect arguments from the second one to the end. We then multiply them by the first one. This example is using an arrow function, which is introduced in the next section.</p> + +<pre class="brush: js">function multiply(multiplier, ...theArgs) { + return theArgs.map(x => multiplier * x); +} + +var arr = multiply(2, 1, 2, 3); +console.log(arr); // [2, 4, 6]</pre> + +<h2 id="Arrow_functions">Arrow functions</h2> + +<p>An <a href="/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">arrow function expression</a> (previously, and now incorrectly known as <strong>fat arrow function</strong>) has a shorter syntax compared to function expressions and lexically binds the <code>this</code> value. Arrow functions are always anonymous. See also this hacks.mozilla.org blog post: "<a href="https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/">ES6 In Depth: Arrow functions</a>".</p> + +<p>Two factors influenced the introduction of arrow functions: shorter functions and lexical <code>this</code>.</p> + +<h3 id="Shorter_functions">Shorter functions</h3> + +<p>In some functional patterns, shorter functions are welcome. Compare:</p> + +<pre class="brush: js">var a = [ + 'Hydrogen', + 'Helium', + 'Lithium', + 'Beryllium' +]; + +var a2 = a.map(function(s) { return s.length; }); + +console.log(a2); // logs [8, 6, 7, 9] + +var a3 = a.map(s => s.length); + +console.log(a3); // logs [8, 6, 7, 9] +</pre> + +<h3 id="Lexical_this">Lexical <code>this</code></h3> + +<p>Until arrow functions, every new function defined its own <a href="/en-US/docs/Web/JavaScript/Reference/Operators/this">this</a> value (a new object in case of a constructor, undefined in strict mode function calls, the context object if the function is called as an "object method", etc.). This proved to be annoying with an object-oriented style of programming.</p> + +<pre class="brush: js">function Person() { + // The Person() constructor defines `this` as itself. + this.age = 0; + + setInterval(function growUp() { + // In nonstrict mode, the growUp() function defines `this` + // as the global object, which is different from the `this` + // defined by the Person() constructor. + this.age++; + }, 1000); +} + +var p = new Person();</pre> + +<p>In ECMAScript 3/5, this issue was fixed by assigning the value in <code>this</code> to a variable that could be closed over.</p> + +<pre class="brush: js">function Person() { + var self = this; // Some choose `that` instead of `self`. + // Choose one and be consistent. + self.age = 0; + + setInterval(function growUp() { + // The callback refers to the `self` variable of which + // the value is the expected object. + self.age++; + }, 1000); +}</pre> + +<p>Alternatively, a <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind">bound function</a> could be created so that the proper <code>this</code> value would be passed to the <code>growUp()</code> function.</p> + +<p>Arrow functions capture the <code>this</code> value of the enclosing context, so the following code works as expected.</p> + +<pre class="brush: js">function Person() { + this.age = 0; + + setInterval(() => { + this.age++; // |this| properly refers to the person object + }, 1000); +} + +var p = new Person();</pre> + +<h2 id="Predefined_functions">Predefined functions</h2> + +<p>JavaScript has several top-level, built-in functions:</p> + +<dl> + <dt>{{jsxref("Global_Objects/eval", "eval()")}}</dt> + <dd> + <p>The <code><strong>eval()</strong></code> method evaluates JavaScript code represented as a string.</p> + </dd> + <dt>{{jsxref("Global_Objects/uneval", "uneval()")}} {{non-standard_inline}}</dt> + <dd> + <p>The <code><strong>uneval()</strong></code> method creates a string representation of the source code of an {{jsxref("Object")}}.</p> + </dd> + <dt>{{jsxref("Global_Objects/isFinite", "isFinite()")}}</dt> + <dd> + <p>The global <code><strong>isFinite()</strong></code> function determines whether the passed value is a finite number. If needed, the parameter is first converted to a number.</p> + </dd> + <dt>{{jsxref("Global_Objects/isNaN", "isNaN()")}}</dt> + <dd> + <p>The <code><strong>isNaN()</strong></code> function determines whether a value is {{jsxref("Global_Objects/NaN", "NaN")}} or not. Note: coercion inside the <code>isNaN</code> function has <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN#Description">interesting</a> rules; you may alternatively want to use {{jsxref("Number.isNaN()")}}, as defined in ECMAScript 2015, or you can use <code><a href="/en-US/docs/Web/JavaScript/Reference/Operators/typeof">typeof</a></code> to determine if the value is Not-A-Number.</p> + </dd> + <dt>{{jsxref("Global_Objects/parseFloat", "parseFloat()")}}</dt> + <dd> + <p>The <code><strong>parseFloat()</strong></code> function parses a string argument and returns a floating point number.</p> + </dd> + <dt>{{jsxref("Global_Objects/parseInt", "parseInt()")}}</dt> + <dd> + <p>The <code><strong>parseInt()</strong></code> function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).</p> + </dd> + <dt>{{jsxref("Global_Objects/decodeURI", "decodeURI()")}}</dt> + <dd> + <p>The <code><strong>decodeURI()</strong></code> function decodes a Uniform Resource Identifier (URI) previously created by {{jsxref("Global_Objects/encodeURI", "encodeURI")}} or by a similar routine.</p> + </dd> + <dt>{{jsxref("Global_Objects/decodeURIComponent", "decodeURIComponent()")}}</dt> + <dd> + <p>The <code><strong>decodeURIComponent()</strong></code> method decodes a Uniform Resource Identifier (URI) component previously created by {{jsxref("Global_Objects/encodeURIComponent", "encodeURIComponent")}} or by a similar routine.</p> + </dd> + <dt>{{jsxref("Global_Objects/encodeURI", "encodeURI()")}}</dt> + <dd> + <p>The <code><strong>encodeURI()</strong></code> method encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).</p> + </dd> + <dt>{{jsxref("Global_Objects/encodeURIComponent", "encodeURIComponent()")}}</dt> + <dd> + <p>The <code><strong>encodeURIComponent()</strong></code> method encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).</p> + </dd> + <dt>{{jsxref("Global_Objects/escape", "escape()")}} {{deprecated_inline}}</dt> + <dd> + <p>The deprecated <code><strong>escape()</strong></code> method computes a new string in which certain characters have been replaced by a hexadecimal escape sequence. Use {{jsxref("Global_Objects/encodeURI", "encodeURI")}} or {{jsxref("Global_Objects/encodeURIComponent", "encodeURIComponent")}} instead.</p> + </dd> + <dt>{{jsxref("Global_Objects/unescape", "unescape()")}} {{deprecated_inline}}</dt> + <dd> + <p>The deprecated <code><strong>unescape()</strong></code> method computes a new string in which hexadecimal escape sequences are replaced with the character that it represents. The escape sequences might be introduced by a function like {{jsxref("Global_Objects/escape", "escape")}}. Because <code>unescape()</code> is deprecated, use {{jsxref("Global_Objects/decodeURI", "decodeURI()")}} or {{jsxref("Global_Objects/decodeURIComponent", "decodeURIComponent")}} instead.</p> + </dd> +</dl> + +<p>{{PreviousNext("Web/JavaScript/Guide/Loops_and_iteration", "Web/JavaScript/Guide/Expressions_and_Operators")}}</p> diff --git a/files/fa/web/javascript/راهنما/grammar_and_types/index.html b/files/fa/web/javascript/راهنما/grammar_and_types/index.html new file mode 100644 index 0000000000..7ccb432c33 --- /dev/null +++ b/files/fa/web/javascript/راهنما/grammar_and_types/index.html @@ -0,0 +1,673 @@ +--- +title: گرامر و انواع +slug: Web/JavaScript/راهنما/Grammar_and_types +translation_of: Web/JavaScript/Guide/Grammar_and_types +--- +<div>{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide/Introduction", "Web/JavaScript/Guide/Control_flow_and_error_handling")}}</div> + +<p class="summary" dir="rtl">این فصل در مورد گرامر اولیه جاوااسکریپت، اعلانهای متغیر، انواع داده و لیترالها است.</p> + +<h2 dir="rtl" id="مقدمه">مقدمه</h2> + +<p dir="rtl">جاوااسکریپت قسمت زیادی از نحو خود را از جاوا اقتباس کرده و همچنین از زبانهای پرل، پایتون و Awk تاثیر گرفته است.</p> + +<p dir="rtl">جاوااسکریپت <strong>حساس به</strong> <strong>کوچکی و بزرگی حروف (case-sensetive)</strong> است و از مجموعه کاراکترهای <strong>یونیکد (Unicode)</strong> استفاده میکند.</p> + +<p>In JavaScript, instructions are called {{Glossary("Statement", "statements")}} and are separated by a semicolon (;). Spaces, tabs and newline characters are called whitespace. The source text of JavaScript scripts gets scanned from left to right and is converted into a sequence of input elements which are tokens, control characters, line terminators, comments or whitespace. ECMAScript also defines certain keywords and literals and has rules for automatic insertion of semicolons (<a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Automatic_semicolon_insertion">ASI</a>) to end statements. However, it is recommended to always add semicolons to end your statements; it will avoid side effects. For more information, see the detailed reference about JavaScript's <a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar">lexical grammar</a>.</p> + +<h2 dir="rtl" id="توضیح_(comment)">توضیح (comment)</h2> + +<p dir="rtl">نحو (syntax) یک «توضیح» مشابه با زبان C++ و تعداد زیادی از زبانهای دیگر است.<br> + مثال اول: توضیح تکخطی<br> + مثال دوم: توضیح چندخطی (بلوک)<br> + مثال سوم: اگرچه، برخلاف c++ نمیتوان توضیح تو در تو ساخت. احتمالا خطای نحوی خواهد بود.</p> + +<pre class="brush: js">// a one line comment + +/* this is a longer, + multi-line comment + */ + +/* You can't, however, /* nest comments */ SyntaxError */</pre> + +<h2 dir="rtl" id="اعلانها_(Declarations)">اعلانها (Declarations)</h2> + +<p dir="rtl">سه نوع اعلان در جاوااسکریپت وجود دارد.</p> + +<dl> + <dt dir="rtl">{{jsxref("Statements/var", "var")}}</dt> + <dd dir="rtl">یک متغیر را اعلان میکند. مقداردهی اولیه اختیاری است.</dd> + <dt dir="rtl">{{jsxref("Statements/let", "let")}}</dt> + <dd dir="rtl">یک متغیر محلی را با قلمرو بلوک اعلان میکند. مقداردهی اولیه اختیاری است.</dd> + <dt dir="rtl">{{jsxref("Statements/const", "const")}}</dt> + <dd dir="rtl">یک ثابت «فقط خواندنی» را اعلان میکند.</dd> +</dl> + +<h3 dir="rtl" id="متغیرها">متغیرها</h3> + +<p dir="rtl">You use variables as symbolic names for values in your application. The names of variables, called {{Glossary("Identifier", "identifiers")}}, conform to certain rules.</p> + +<p dir="rtl">A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase).</p> + +<p dir="rtl">You can use most of ISO 8859-1 or Unicode letters such as å and ü in identifiers (for more details see <a href="https://mathiasbynens.be/notes/javascript-identifiers-es6">this blog post</a>). You can also use the <a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#String_literals">Unicode escape sequences</a> as characters in identifiers.</p> + +<p dir="rtl">نامهای روبرو مثالهایی معتبر برای نامگذاری هستند: <code>Number_hits</code>, <code>temp99</code>, <code>_name</code></p> + +<h3 dir="rtl" id="اعلان_متغیرها">اعلان متغیرها</h3> + +<p dir="rtl">شما به سه روش میتوانید یک متغیر را اعلان کنید:</p> + +<ul dir="rtl"> + <li>با کلمهکلیدی {{jsxref("Statements/var", "var")}}. برای مثال <code>var x = 42</code>. این نحو میتواند برای اعلان هر دو نوع متغیر محلی و سراسری استفاده شود.</li> + <li>به سادگی و با انتساب یک مقدار به آن. برای مثال <code>x = 42</code>. این شیوه همیشه یک متغیر را به صورت سراسری اعلان میکند. این روش یک هشدار سختگیرانه (strict warning) تولید میکند. بهتر است از این روش استفاده نکنید.</li> + <li>با کلمهکلیدی {{jsxref("Statements/let", "let")}}. برای مثال <code>let y = 13</code>. این نحو میتواند برای اعلان یک متغیر محلی با قلمرو بلوک استفاده شود. بخش <a href="#قلمرو_متغیر_(Variable_Scope)">قلمرو متغیر</a> را در زیر ببینید.</li> +</ul> + +<h3 dir="rtl" id="ارزیابی_متغیرها">ارزیابی متغیرها</h3> + +<p dir="rtl">A variable declared using the <code>var or let</code> statement with no initial value specified has the value {{jsxref("undefined")}}.</p> + +<p dir="rtl">An attempt to access an undeclared variable will result in a {{jsxref("ReferenceError")}} exception being thrown:</p> + +<pre dir="rtl">var a; +console.log("The value of a is " + a); // The value of a is undefined + +var b; +console.log("The value of b is " + b); // The value of b is undefined + +console.log("The value of c is " + c); // Uncaught ReferenceError: c is not defined + +let x; +console.log("The value of x is " + x); // The value of x is undefined + +console.log("The value of y is " + y); // Uncaught ReferenceError: y is not defined +let y; </pre> + +<p dir="rtl">شما میتوانید از <code>undefined</code> برای مشخص کردن اینکه آیا یک متغیر دارای مقدار است استفاده کنید. در کد زیر به متغیر <code>input</code> مقداری انتساب داده نشده است و عبارت منطقی <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/if...else">if</a></code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/if...else"> </a>برابر با <code>true</code> ارزیابی میشود.</p> + +<pre class="brush: js" dir="rtl">var input; +if(input === undefined){ + doThis(); +} else { + doThat(); +} +</pre> + +<p dir="rtl">رفتار مقدار <code>undefined</code> در ارزیابی عبارات منطقی مانند <code>false</code> است. برای مثال، در کد زیر تابع <code>myFunction</code> اجرا خواهد شد چون المان <code>myArray</code> تعریفنشده است:</p> + +<pre class="brush: js" dir="rtl">var myArray = []; +if (!myArray[0]) myFunction(); +</pre> + +<p dir="rtl">در یک عبارت عددی مقدار <code>undefined</code> به <code>NaN</code> تبدیل میشود.</p> + +<pre class="brush: js" dir="rtl">var a; +a + 2; // Evaluates to NaN</pre> + +<p dir="rtl">وقتی یک متغیر {{jsxref("null")}} را ارزیابی میکنید، در یک عبارت عددی دارای مقدارصفر و در یک عبارت منطقی دارای مقدار <code>false</code> خواهد بود. برای مثال:</p> + +<pre class="brush: js" dir="rtl">var n = null; +console.log(n * 32); // Will log 0 to the console +</pre> + +<h3 dir="rtl" id="قلمرو_متغیر_(Variable_Scope)">قلمرو متغیر (Variable Scope)</h3> + +<p dir="rtl">When you declare a variable outside of any function, it is called a <em>global</em> variable, because it is available to any other code in the current document. When you declare a variable within a function, it is called a <em>local</em> variable, because it is available only within that function.</p> + +<p dir="rtl">JavaScript before ECMAScript 2015 does not have <a href="/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling#Block_statement">block statement</a> scope; rather, a variable declared within a block is local to the <em>function (or global scope)</em> that the block resides within. For example the following code will log <code>5</code>, because the scope of <code>x</code> is the function (or global context) within which <code>x</code> is declared, not the block, which in this case is an <code>if</code> statement.</p> + +<pre class="brush: js" dir="rtl">if (true) { + var x = 5; +} +console.log(x); // x is 5 +</pre> + +<p dir="rtl">This behavior changes, when using the <code>let</code> declaration introduced in ECMAScript 2015.</p> + +<pre class="brush: js" dir="rtl">if (true) { + let y = 5; +} +console.log(y); // ReferenceError: y is not defined +</pre> + +<h3 dir="rtl" id="Variable_hoisting">Variable hoisting</h3> + +<p dir="rtl">Another unusual thing about variables in JavaScript is that you can refer to a variable declared later, without getting an exception. This concept is known as <strong>hoisting</strong>; variables in JavaScript are in a sense "hoisted" or lifted to the top of the function or statement. However, variables that are hoisted will return a value of <code>undefined</code>. So even if you declare and initialize after you use or refer to this variable, it will still return undefined.</p> + +<pre class="brush: js" dir="rtl">/** + * Example 1 + */ +console.log(x === undefined); // true +var x = 3; + +/** + * Example 2 + */ +// will return a value of undefined +var myvar = "my value"; + +(function() { + console.log(myvar); // undefined + var myvar = "local value"; +})(); +</pre> + +<p dir="rtl">The above examples will be interpreted the same as:</p> + +<pre class="brush: js" dir="rtl">/** + * Example 1 + */ +var x; +console.log(x === undefined); // true +x = 3; + +/** + * Example 2 + */ +var myvar = "my value"; + +(function() { + var myvar; + console.log(myvar); // undefined + myvar = "local value"; +})(); +</pre> + +<p dir="rtl">Because of hoisting, all <code>var</code> statements in a function should be placed as near to the top of the function as possible. This best practice increases the clarity of the code.</p> + +<p dir="rtl">In ECMAScript 2015, <code>let (const)</code> <strong>will not hoist</strong> the variable to the top of the block. However, referencing the variable in the block before the variable declaration results in a {{jsxref("ReferenceError")}}. The variable is in a "temporal dead zone" from the start of the block until the declaration is processed.</p> + +<pre class="brush: js" dir="rtl">console.log(x); // ReferenceError +let x = 3;</pre> + +<h3 dir="rtl" id="Function_hoisting">Function hoisting</h3> + +<p dir="rtl">For functions, only function declaration gets hoisted to the top and not the function expression.</p> + +<pre class="brush: js" dir="rtl">/* Function declaration */ + +foo(); // "bar" + +function foo() { + console.log("bar"); +} + + +/* Function expression */ + +baz(); // TypeError: baz is not a function + +var baz = function() { + console.log("bar2"); +}; +</pre> + +<h3 dir="rtl" id="Global_variables">Global variables</h3> + +<p dir="rtl">Global variables are in fact properties of the <em>global object</em>. In web pages the global object is {{domxref("window")}}, so you can set and access global variables using the <code>window.<em>variable</em></code> syntax.</p> + +<p dir="rtl">Consequently, you can access global variables declared in one window or frame from another window or frame by specifying the window or frame name. For example, if a variable called <code>phoneNumber</code> is declared in a document, you can refer to this variable from an iframe as <code>parent.phoneNumber</code>.</p> + +<h3 dir="rtl" id="Constants">Constants</h3> + +<p dir="rtl">You can create a read-only, named constant with the {{jsxref("Statements/const", "const")}} keyword. The syntax of a constant identifier is the same as for a variable identifier: it must start with a letter, underscore or dollar sign and can contain alphabetic, numeric, or underscore characters.</p> + +<pre class="brush: js" dir="rtl">const PI = 3.14; +</pre> + +<p dir="rtl">A constant cannot change value through assignment or be re-declared while the script is running. It has to be initialized to a value.</p> + +<p dir="rtl">The scope rules for constants are the same as those for <code>let</code> block scope variables. If the <code>const</code> keyword is omitted, the identifier is assumed to represent a variable.</p> + +<p dir="rtl">You cannot declare a constant with the same name as a function or variable in the same scope. For example:</p> + +<pre class="brush: js" dir="rtl">// THIS WILL CAUSE AN ERROR +function f() {}; +const f = 5; + +// THIS WILL CAUSE AN ERROR ALSO +function f() { + const g = 5; + var g; + + //statements +} +</pre> + +<p dir="rtl">However, the properties of objects assigned to constants are not protected, so the following statement is executed without problems.</p> + +<pre class="brush: js" dir="rtl">const MY_OBJECT = {"key": "value"}; +MY_OBJECT.key = "otherValue";</pre> + +<h2 dir="rtl" id="Data_structures_and_types">Data structures and types</h2> + +<h3 dir="rtl" id="Data_types">Data types</h3> + +<p dir="rtl">The latest ECMAScript standard defines seven data types:</p> + +<ul dir="rtl"> + <li>Six data types that are {{Glossary("Primitive", "primitives")}}: + <ul> + <li>{{Glossary("Boolean")}}. <code>true</code> and <code>false</code>.</li> + <li>{{Glossary("null")}}. A special keyword denoting a null value. Because JavaScript is case-sensitive, <code>null</code> is not the same as <code>Null</code>, <code>NULL</code>, or any other variant.</li> + <li>{{Glossary("undefined")}}. A top-level property whose value is undefined.</li> + <li>{{Glossary("Number")}}. <code>42</code> or <code>3.14159</code>.</li> + <li>{{Glossary("String")}}. "Howdy"</li> + <li>{{Glossary("Symbol")}} (new in ECMAScript 2015). A data type whose instances are unique and immutable.</li> + </ul> + </li> + <li>and {{Glossary("Object")}}</li> +</ul> + +<p dir="rtl">Although these data types are a relatively small amount, they enable you to perform useful functions with your applications. {{jsxref("Object", "Objects")}} and {{jsxref("Function", "functions")}} are the other fundamental elements in the language. You can think of objects as named containers for values, and functions as procedures that your application can perform.</p> + +<h3 dir="rtl" id="Data_type_conversion">Data type conversion</h3> + +<p dir="rtl">JavaScript is a dynamically typed language. That means you don't have to specify the data type of a variable when you declare it, and data types are converted automatically as needed during script execution. So, for example, you could define a variable as follows:</p> + +<pre class="brush: js" dir="rtl">var answer = 42; +</pre> + +<p dir="rtl">And later, you could assign the same variable a string value, for example:</p> + +<pre class="brush: js" dir="rtl">answer = "Thanks for all the fish..."; +</pre> + +<p dir="rtl">Because JavaScript is dynamically typed, this assignment does not cause an error message.</p> + +<p dir="rtl">In expressions involving numeric and string values with the + operator, JavaScript converts numeric values to strings. For example, consider the following statements:</p> + +<pre class="brush: js" dir="rtl">x = "The answer is " + 42 // "The answer is 42" +y = 42 + " is the answer" // "42 is the answer" +</pre> + +<p dir="rtl">In statements involving other operators, JavaScript does not convert numeric values to strings. For example:</p> + +<pre class="brush: js" dir="rtl">"37" - 7 // 30 +"37" + 7 // "377" +</pre> + +<h3 dir="rtl" id="Converting_strings_to_numbers">Converting strings to numbers</h3> + +<p dir="rtl">In the case that a value representing a number is in memory as a string, there are methods for conversion.</p> + +<ul dir="rtl"> + <li id="parseInt()_and_parseFloat()">{{jsxref("parseInt", "parseInt()")}}</li> + <li>{{jsxref("parseFloat", "parseFloat()")}}</li> +</ul> + +<p dir="rtl"><code>parseInt</code> will only return whole numbers, so its use is diminished for decimals. Additionally, a best practice for <code>parseInt</code> is to always include the radix parameter. The radix parameter is used to specify which numerical system is to be used.</p> + +<p dir="rtl">An alternative method of retrieving a number from a string is with the <code>+</code> (unary plus) operator:</p> + +<pre class="brush: js" dir="rtl">"1.1" + "1.1" = "1.11.1" +(+"1.1") + (+"1.1") = 2.2 +// Note: the parentheses are added for clarity, not required.</pre> + +<h2 dir="rtl" id="Literals">Literals</h2> + +<p dir="rtl">You use literals to represent values in JavaScript. These are fixed values, not variables, that you <em>literally</em> provide in your script. This section describes the following types of literals:</p> + +<ul dir="rtl"> + <li>{{anch("Array literals")}}</li> + <li>{{anch("Boolean literals")}}</li> + <li>{{anch("Floating-point literals")}}</li> + <li>{{anch("Integers")}}</li> + <li>{{anch("Object literals")}}</li> + <li>{{anch("RegExp literals")}}</li> + <li>{{anch("String literals")}}</li> +</ul> + +<h3 dir="rtl" id="Array_literals">Array literals</h3> + +<p dir="rtl">An array literal is a list of zero or more expressions, each of which represents an array element, enclosed in square brackets (<code>[]</code>). When you create an array using an array literal, it is initialized with the specified values as its elements, and its length is set to the number of arguments specified.</p> + +<p dir="rtl">The following example creates the <code>coffees</code> array with three elements and a length of three:</p> + +<pre class="brush: js" dir="rtl">var coffees = ["French Roast", "Colombian", "Kona"]; +</pre> + +<div class="note" dir="rtl"> +<p><strong>Note :</strong> An array literal is a type of object initializer. See <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Using_object_initializers">Using Object Initializers</a>.</p> +</div> + +<p dir="rtl">If an array is created using a literal in a top-level script, JavaScript interprets the array each time it evaluates the expression containing the array literal. In addition, a literal used in a function is created each time the function is called.</p> + +<p dir="rtl">Array literals are also <code>Array</code> objects. See {{jsxref("Array")}} and <a href="/en-US/docs/Web/JavaScript/Guide/Indexed_collections">Indexed collections</a> for details on <code>Array</code> objects.</p> + +<h4 dir="rtl" id="Extra_commas_in_array_literals">Extra commas in array literals</h4> + +<p dir="rtl">You do not have to specify all elements in an array literal. If you put two commas in a row, the array is created with <code>undefined</code> for the unspecified elements. The following example creates the <code>fish</code> array:</p> + +<pre class="brush: js" dir="rtl">var fish = ["Lion", , "Angel"]; +</pre> + +<p dir="rtl">This array has two elements with values and one empty element (<code>fish[0]</code> is "Lion", <code>fish[1]</code> is <code>undefined</code>, and <code>fish[2]</code> is "Angel").</p> + +<p dir="rtl">If you include a trailing comma at the end of the list of elements, the comma is ignored. In the following example, the length of the array is three. There is no <code>myList[3]</code>. All other commas in the list indicate a new element.</p> + +<div class="note" dir="rtl"> +<p><strong>Note :</strong> Trailing commas can create errors in older browser versions and it is a best practice to remove them.</p> +</div> + +<pre class="brush: js" dir="rtl">var myList = ['home', , 'school', ]; +</pre> + +<p dir="rtl">In the following example, the length of the array is four, and <code>myList[0]</code> and <code>myList[2]</code> are missing.</p> + +<pre class="brush: js" dir="rtl">var myList = [ , 'home', , 'school']; +</pre> + +<p dir="rtl">In the following example, the length of the array is four, and <code>myList[1]</code> and <code>myList[3]</code> are missing. Only the last comma is ignored.</p> + +<pre class="brush: js" dir="rtl">var myList = ['home', , 'school', , ]; +</pre> + +<p dir="rtl">Understanding the behavior of extra commas is important to understanding JavaScript as a language, however when writing your own code: explicitly declaring the missing elements as <code>undefined</code> will increase your code's clarity and maintainability.</p> + +<h3 dir="rtl" id="Boolean_literals">Boolean literals</h3> + +<p dir="rtl">The Boolean type has two literal values: <code>true</code> and <code>false</code>.</p> + +<p dir="rtl">Do not confuse the primitive Boolean values <code>true</code> and <code>false</code> with the true and false values of the Boolean object. The Boolean object is a wrapper around the primitive Boolean data type. See {{jsxref("Boolean")}} for more information.</p> + +<h3 dir="rtl" id="Integers">Integers</h3> + +<p dir="rtl">Integers can be expressed in decimal (base 10), hexadecimal (base 16), octal (base 8) and binary (base 2).</p> + +<ul dir="rtl"> + <li>Decimal integer literal consists of a sequence of digits without a leading 0 (zero).</li> + <li>Leading 0 (zero) on an integer literal, or leading 0o (or 0O) indicates it is in octal. Octal integers can include only the digits 0-7.</li> + <li>Leading 0x (or 0X) indicates hexadecimal. Hexadecimal integers can include digits (0-9) and the letters a-f and A-F.</li> + <li> + <p>Leading 0b (or 0B) indicates binary. Binary integers can include digits only 0 and 1.</p> + </li> +</ul> + +<p dir="rtl">Some examples of integer literals are:</p> + +<pre class="eval" dir="rtl">0, 117 and -345 (decimal, base 10) +015, 0001 and -0o77 (octal, base 8) +0x1123, 0x00111 and -0xF1A7 (hexadecimal, "hex" or base 16) +0b11, 0b0011 and -0b11 (binary, base 2) +</pre> + +<p dir="rtl">For more information, see <a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Numeric_literals">Numeric literals in the Lexical grammar reference</a>.</p> + +<h3 dir="rtl" id="Floating-point_literals">Floating-point literals</h3> + +<p dir="rtl">A floating-point literal can have the following parts:</p> + +<ul dir="rtl"> + <li>A decimal integer which can be signed (preceded by "+" or "-"),</li> + <li>A decimal point ("."),</li> + <li>A fraction (another decimal number),</li> + <li>An exponent.</li> +</ul> + +<p dir="rtl">The exponent part is an "e" or "E" followed by an integer, which can be signed (preceded by "+" or "-"). A floating-point literal must have at least one digit and either a decimal point or "e" (or "E").</p> + +<p dir="rtl">More succinctly, the syntax is:</p> + +<pre class="eval" dir="rtl">[(+|-)][digits][.digits][(E|e)[(+|-)]digits] +</pre> + +<p dir="rtl">For example:</p> + +<pre class="eval" dir="rtl">3.1415926 +-.123456789 +-3.1E+12 +.1e-23 +</pre> + +<h3 dir="rtl" id="Object_literals">Object literals</h3> + +<p dir="rtl">An object literal is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces (<code>{}</code>). You should not use an object literal at the beginning of a statement. This will lead to an error or not behave as you expect, because the { will be interpreted as the beginning of a block.</p> + +<p dir="rtl">The following is an example of an object literal. The first element of the <code>car</code> object defines a property, <code>myCar</code>, and assigns to it a new string, "<code>Saturn</code>"; the second element, the <code>getCar</code> property, is immediately assigned the result of invoking the function <code>(carTypes("Honda"));</code> the third element, the <code>special</code> property, uses an existing variable (<code>sales</code>).</p> + +<pre class="brush: js" dir="rtl">var sales = "Toyota"; + +function carTypes(name) { + if (name === "Honda") { + return name; + } else { + return "Sorry, we don't sell " + name + "."; + } +} + +var car = { myCar: "Saturn", getCar: carTypes("Honda"), special: sales }; + +console.log(car.myCar); // Saturn +console.log(car.getCar); // Honda +console.log(car.special); // Toyota +</pre> + +<p dir="rtl">Additionally, you can use a numeric or string literal for the name of a property or nest an object inside another. The following example uses these options.</p> + +<pre class="brush: js" dir="rtl">var car = { manyCars: {a: "Saab", "b": "Jeep"}, 7: "Mazda" }; + +console.log(car.manyCars.b); // Jeep +console.log(car[7]); // Mazda +</pre> + +<p dir="rtl">Object property names can be any string, including the empty string. If the property name would not be a valid JavaScript {{Glossary("Identifier","identifier")}} or number, it must be enclosed in quotes. Property names that are not valid identifiers also cannot be accessed as a dot (<code>.</code>) property, but can be accessed and set with the array-like notation("<code>[]</code>").</p> + +<pre class="brush: js" dir="rtl">var unusualPropertyNames = { + "": "An empty string", + "!": "Bang!" +} +console.log(unusualPropertyNames.""); // SyntaxError: Unexpected string +console.log(unusualPropertyNames[""]); // An empty string +console.log(unusualPropertyNames.!); // SyntaxError: Unexpected token ! +console.log(unusualPropertyNames["!"]); // Bang!</pre> + +<p dir="rtl">In ES2015, object literals are extended to support setting the prototype at construction, shorthand for <code>foo: foo</code> assignments, defining methods, making super calls, and computing property names with expressions. Together, these also bring object literals and class declarations closer together, and let object-based design benefit from some of the same conveniences.</p> + +<pre class="brush: js" dir="rtl">var obj = { + // __proto__ + __proto__: theProtoObj, + // Shorthand for ‘handler: handler’ + handler, + // Methods + toString() { + // Super calls + return "d " + super.toString(); + }, + // Computed (dynamic) property names + [ 'prop_' + (() => 42)() ]: 42 +};</pre> + +<p dir="rtl">Please note:</p> + +<pre class="brush: js" dir="rtl">var foo = {a: "alpha", 2: "two"}; +console.log(foo.a); // alpha +console.log(foo[2]); // two +//console.log(foo.2); // Error: missing ) after argument list +//console.log(foo[a]); // Error: a is not defined +console.log(foo["a"]); // alpha +console.log(foo["2"]); // two +</pre> + +<h3 dir="rtl" id="RegExp_literals">RegExp literals</h3> + +<p dir="rtl">A regex literal is a pattern enclosed between slashes. The following is an example of an regex literal.</p> + +<pre class="brush: js" dir="rtl">var re = /ab+c/;</pre> + +<h3 dir="rtl" id="String_literals">String literals</h3> + +<p dir="rtl">A string literal is zero or more characters enclosed in double (<code>"</code>) or single (<code>'</code>) quotation marks. A string must be delimited by quotation marks of the same type; that is, either both single quotation marks or both double quotation marks. The following are examples of string literals:</p> + +<pre class="brush: js" dir="rtl">"foo" +'bar' +"1234" +"one line \n another line" +"John's cat" +</pre> + +<p dir="rtl">You can call any of the methods of the String object on a string literal value—JavaScript automatically converts the string literal to a temporary String object, calls the method, then discards the temporary String object. You can also use the <code>String.length</code> property with a string literal:</p> + +<pre class="brush: js" dir="rtl">console.log("John's cat".length) +// Will print the number of symbols in the string including whitespace. +// In this case, 10. +</pre> + +<p dir="rtl">In ES2015, template literals are also available. Template strings provide syntactic sugar for constructing strings. This is similar to string interpolation features in Perl, Python and more. Optionally, a tag can be added to allow the string construction to be customized, avoiding injection attacks or constructing higher level data structures from string contents.</p> + +<pre class="brush: js" dir="rtl">// Basic literal string creation +`In JavaScript '\n' is a line-feed.` + +// Multiline strings +`In JavaScript template strings can run + over multiple lines, but double and single + quoted strings cannot.` + +// String interpolation +var name = "Bob", time = "today"; +`Hello ${name}, how are you ${time}?` + +// Construct an HTTP request prefix is used to interpret the replacements and construction +POST`http://foo.org/bar?a=${a}&b=${b} + Content-Type: application/json + X-Credentials: ${credentials} + { "foo": ${foo}, + "bar": ${bar}}`(myOnReadyStateChangeHandler);</pre> + +<p dir="rtl">You should use string literals unless you specifically need to use a String object. See {{jsxref("String")}} for details on <code>String</code> objects.</p> + +<h4 dir="rtl" id="Using_special_characters_in_strings">Using special characters in strings</h4> + +<p dir="rtl">In addition to ordinary characters, you can also include special characters in strings, as shown in the following example.</p> + +<pre class="brush: js" dir="rtl">"one line \n another line" +</pre> + +<p dir="rtl">The following table lists the special characters that you can use in JavaScript strings.</p> + +<table class="standard-table" dir="rtl"> + <caption> + <p>Table: JavaScript special characters</p> + </caption> + <thead> + <tr> + <th scope="col">Character</th> + <th scope="col">Meaning</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>\0</code></td> + <td>Null Byte</td> + </tr> + <tr> + <td><code>\b</code></td> + <td>Backspace</td> + </tr> + <tr> + <td><code>\f</code></td> + <td>Form feed</td> + </tr> + <tr> + <td><code>\n</code></td> + <td>New line</td> + </tr> + <tr> + <td><code>\r</code></td> + <td>Carriage return</td> + </tr> + <tr> + <td><code>\t</code></td> + <td>Tab</td> + </tr> + <tr> + <td><code>\v</code></td> + <td>Vertical tab</td> + </tr> + <tr> + <td><code>\'</code></td> + <td>Apostrophe or single quote</td> + </tr> + <tr> + <td><code>\"</code></td> + <td>Double quote</td> + </tr> + <tr> + <td><code>\\</code></td> + <td>Backslash character</td> + </tr> + <tr> + <td><code>\<em>XXX</em></code></td> + <td>The character with the Latin-1 encoding specified by up to three octal digits <em>XXX</em> between 0 and 377. For example, \251 is the octal sequence for the copyright symbol.</td> + </tr> + <tr> + </tr> + <tr> + <td><code>\x<em>XX</em></code></td> + <td>The character with the Latin-1 encoding specified by the two hexadecimal digits <em>XX</em> between 00 and FF. For example, \xA9 is the hexadecimal sequence for the copyright symbol.</td> + </tr> + <tr> + </tr> + <tr> + <td><code>\u<em>XXXX</em></code></td> + <td>The Unicode character specified by the four hexadecimal digits <em>XXXX</em>. For example, \u00A9 is the Unicode sequence for the copyright symbol. See <a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#String_literals">Unicode escape sequences</a>.</td> + </tr> + <tr> + <td><code>\u<em>{XXXXX}</em></code></td> + <td>Unicode code point escapes. For example, \u{2F804} is the same as the simple Unicode escapes \uD87E\uDC04.</td> + </tr> + </tbody> +</table> + +<h4 dir="rtl" id="Escaping_characters">Escaping characters</h4> + +<p dir="rtl">For characters not listed in the table, a preceding backslash is ignored, but this usage is deprecated and should be avoided.</p> + +<p dir="rtl">You can insert a quotation mark inside a string by preceding it with a backslash. This is known as <em>escaping</em> the quotation mark. For example:</p> + +<pre class="brush: js" dir="rtl">var quote = "He read \"The Cremation of Sam McGee\" by R.W. Service."; +console.log(quote); +</pre> + +<p dir="rtl">The result of this would be:</p> + +<pre class="eval" dir="rtl">He read "The Cremation of Sam McGee" by R.W. Service. +</pre> + +<p dir="rtl">To include a literal backslash inside a string, you must escape the backslash character. For example, to assign the file path <code>c:\temp</code> to a string, use the following:</p> + +<pre class="brush: js" dir="rtl">var home = "c:\\temp"; +</pre> + +<p dir="rtl">You can also escape line breaks by preceding them with backslash. The backslash and line break are both removed from the value of the string.</p> + +<pre class="brush: js" dir="rtl">var str = "this string \ +is broken \ +across multiple\ +lines." +console.log(str); // this string is broken across multiplelines. +</pre> + +<p dir="rtl">Although JavaScript does not have "heredoc" syntax, you can get close by adding a line break escape and an escaped line break at the end of each line:</p> + +<pre class="brush: js" dir="rtl">var poem = +"Roses are red,\n\ +Violets are blue.\n\ +Sugar is sweet,\n\ +and so is foo." +</pre> + +<h2 dir="rtl" id="More_information">More information</h2> + +<p dir="rtl">This chapter focuses on basic syntax for declarations and types. To learn more about JavaScript's language constructs, see also the following chapters in this guide:</p> + +<ul dir="rtl"> + <li><a href="/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling">Control flow and error handling</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration">Loops and iteration</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Guide/Functions">Functions</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators">Expressions and operators</a></li> +</ul> + +<p dir="rtl">In the next chapter, we will have a look at control flow constructs and error handling.</p> + +<p dir="rtl">{{PreviousNext("Web/JavaScript/Guide/Introduction", "Web/JavaScript/Guide/Control_flow_and_error_handling")}}</p> diff --git a/files/fa/web/javascript/راهنما/index.html b/files/fa/web/javascript/راهنما/index.html new file mode 100644 index 0000000000..6ebfec2533 --- /dev/null +++ b/files/fa/web/javascript/راهنما/index.html @@ -0,0 +1,107 @@ +--- +title: راهنمای جاوا اسکریپت +slug: Web/JavaScript/راهنما +translation_of: Web/JavaScript/Guide +--- +<p>{{jsSidebar("JavaScript Guide")}}</p> + +<div class="summary"> +<p style="direction: rtl;"><span class="seoSummary">راهنمای javascript یک مرور اجمالی بر روی این زبان داشته و به شما طریقه استفاده از<a href="/en-US/docs/Web/JavaScript"> جاوا اسکریپت</a> را نشان می دهد. اگر می خواهید به طور کلی برنامه نویسی یا جاوا اسکریپت را شروع کنید, از مقالات ما در <a href="/en-US/Learn">محیط آموزشی</a> کمک بگیرید. اگر به اطلاعات کامل درباره ویژگی های یک زبان نیاز دارید، نگاهی به<a href="/en-US/docs/Web/JavaScript/Reference"> مرجع جاوا اسکریپت</a> داشته باشید</span></p> +</div> + +<ul class="card-grid"> + <li><strong><a href="/en-US/docs/Web/JavaScript/Guide/Introduction">معرفی</a></strong> + + <p><a href="/en-US/docs/Web/JavaScript/Guide/Introduction#Where_to_find_JavaScript_information">درباره این راهنما</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Introduction#What_is_JavaScript.3F">درباره جاوا اسکریپت</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Introduction#JavaScript_and_Java">جاوا اسکریپت و جاوا</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Introduction#JavaScript_and_the_ECMAScript_Specification">ECMAScript</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Introduction#Getting_started_with_JavaScript">ابزارها</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Introduction#Hello_world">مثال Hello World</a> </p> + </li> + <li><strong><a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types">دستور زبان و نوع های داده ای</a></strong> + <p><a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Basics">syntax اولیه و commentها</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Declarations">تعاریف</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Variable_scope">Variable scope</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Variable_hoisting">Variable hoisting</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Data_structures_and_types">ساختار داده و نوع های داده ای</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Literals">Literals</a></p> + </li> + <li><strong><a href="/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling">روند کنترل و مدیریت خطا</a></strong> + <p><code><a href="/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling#if...else_statement">if...else</a></code><br> + <code><a href="/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling#switch_statement">switch</a></code><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling#Exception_handling_statements"><code>try</code>/<code>catch</code>/<code>throw</code></a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling#Utilizing_Error_objects">Error objects</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling#Promises">Promises</a></p> + </li> + <li><strong><a href="/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration">حلقه ها و تکرار</a></strong> + <p><code><a href="/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#for_statement">for</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#while_statement">while</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#do...while_statement">do...while</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#break_statement">break</a>/<a href="/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#continue_statement">continue</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#for...in_statement">for..in</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#for...of_statement">for..of</a></code></p> + </li> +</ul> + +<ul class="card-grid"> + <li><strong><a href="/en-US/docs/Web/JavaScript/Guide/Functions">توابع</a></strong> + + <p><a href="/en-US/docs/Web/JavaScript/Guide/Functions#Defining_functions">تعریف توابع</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Functions#Calling_functions">فراخوانی توابع</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Functions#Function_scope">Function scope</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Functions#Closures">Closures</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Functions#Using_the_arguments_object">Arguments</a> & <a href="/en-US/docs/Web/JavaScript/Guide/Functions#Function_parameters">parameters</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Functions#Arrow_functions">Arrow functions</a></p> + </li> + <li><strong><a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators">عبارات و عملگرها</a></strong> + <p><a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Assignment_operators">مقدار دهی</a> & <a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Comparison_operators">مقایسه</a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Arithmetic_operators">عملگرهای ریاضی</a><br> + <span style="background-color: rgba(234, 239, 242, 0.498039);">عملگرهای </span><a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Bitwise_operators">بیتی</a> و <a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Logical_operators">منطقی </a><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Conditional_(ternary)_operator">عملگرهای شرطی (سه تایی)</a></p> + </li> + <li><strong><a href="/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates">اعداد و تاریخ</a></strong><a href="/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#Numbers"> </a> + <p><code><a href="/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#Numbers">Number literals</a></code><br> + <code><a href="/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#Number_object">Number object</a></code><br> + <a href="/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#Math_object"><code>Math</code> object</a><br> + <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#Date_object"><code>Date</code> object</a></p> + </li> + <li><strong><a href="/en-US/docs/Web/JavaScript/Guide/Text_formatting">قالب بندی متن</a></strong> + <p>رشته ها<br> + Template strings<br> + Regular Expressions<br> + Internationalization<br> + </p> + </li> + <li><span><a href="/en-US/docs/Web/JavaScript/Guide/Indexed_collections">مجموعه های اندیس دار</a></span> + <p>آرایه ها<br> + آریه های نوع دار</p> + </li> + <li><span><a href="/en-US/docs/Web/JavaScript/Guide/Keyed_collections_and_structured_data">مجموعه های کلید دار و داده های ساخت یافته</a></span> + <p>Maps, WeakMaps<br> + Sets, WeakSets<br> + JSON</p> + </li> + <li><span><a href="/en-US/docs/Web/JavaScript/Guide/Working_with_Objects">کار با اشیا</a></span> + <p>ایجاد اشیا<br> + Object initializer<br> + وراثت<br> + Getter and setter</p> + </li> + <li><span><a href="/en-US/docs/Web/JavaScript/Guide/Details_of_the_Object_Model">جزئیات مدل شی</a></span> + <p>Prototype-based OOP<br> + Properties and methods<br> + وراثت</p> + </li> + <li><span><a href="/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators">Iterators and generators</a></span> + <p>Iterable protocol<br> + Iterator protocol<br> + Generators</p> + </li> + <li><span><a href="/en-US/docs/Web/JavaScript/Guide/Meta_programming">Meta programming</a></span> + <p>Proxy<br> + Reflect</p> + </li> +</ul> + +<p>{{Next("Web/JavaScript/Guide/Introduction")}}</p> diff --git a/files/fa/web/javascript/راهنما/مقدمه/index.html b/files/fa/web/javascript/راهنما/مقدمه/index.html new file mode 100644 index 0000000000..3e8b0f1cff --- /dev/null +++ b/files/fa/web/javascript/راهنما/مقدمه/index.html @@ -0,0 +1,138 @@ +--- +title: مقدمه +slug: Web/JavaScript/راهنما/مقدمه +tags: + - اکما اسکریپت + - جاوا اسکریپت +translation_of: Web/JavaScript/Guide/Introduction +--- +<div>{{jsSidebar("JavaScript Guide")}} {{PreviousNext("Web/JavaScript/Guide", "Web/JavaScript/Guide/Grammar_and_types")}}</div> + +<p class="summary" dir="rtl">در این فصل به مباحث مقدماتی جاوا اسکریپت پرداخته و برخی از مفاهیم اساسی آن را بیان می کنیم . </p> + +<h2 dir="rtl" id="آنچه_که_شما_باید_از_قبل_بدانید">آنچه که شما باید از قبل بدانید</h2> + +<p dir="rtl">این آموزش فرض را بر این گرفته که شما پیش زمینه های زیر را دارا هستید:</p> + +<ul dir="rtl"> + <li>یک درک عمومی از اینترنت و شبکه ی جهانی وب ({{Glossary("WWW")}}).</li> + <li>اطلاعاتی خوب و کارآمد در زمینه ی زبان نشانه گذاری فرا متن ({{Glossary("HTML")}}).</li> +</ul> + +<p dir="rtl">مقداری تجربه ی برنامه نویسی . اگر شما به تازگی وارد برنامه نویسی شده اید ، سعی کنید ابتدا از لینک های آموزشی که در صفحه ی اصلی هست به لینک درباره ی جاوا اسکریپت بروید.</p> + +<h2 dir="rtl" id="کجا_اطلاعات_جاوا_اسکریپت_را_پیدا_کنید">کجا اطلاعات جاوا اسکریپت را پیدا کنید</h2> + +<p dir="rtl">مستندات جاوا اسکریپت در MDN شامل موارد زیر است:</p> + +<ol dir="rtl"> + <li><a href="/en-US/Learn">یادگیری وب:</a> اطلاعاتی را برای افراد تازه کار فراهم می کند و همچنین مفاهیم پایه برنامه نویسی و اینترنت را معرفی می کند</li> + <li><a href="/en-US/docs/Web/JavaScript/Guide">راهنمای جاوا اسکریپت:</a> (این راهنمایی) یک دیدکلی را از زبان جاوا اسکریپت و اشیای آن ارائه می کند</li> + <li><a href="/en-US/docs/Web/JavaScript/Reference">مرجع جاوا اسکریپت:</a> یک مرجع همراه با جزئیات برای زبان جاوا اسکریپت فراهم می کند</li> +</ol> + +<h2 dir="rtl" id="جاوا_اسکریپت_چیست؟">جاوا اسکریپت چیست؟</h2> + +<p dir="rtl">جاوا اسکریپت یک زبان با بسترمتقاطع(چند پلتفرمی) و شی گرای اسکریپتی است. این زبان کوچک و سبک است. در محیط میزبان (برای مثال یک مرورگر) جاوا اسکریپت می تواند به اشیای محیط متصل شده و کنترل به وسیله برنامه نویسی را برای آن محیط فراهم می کند.</p> + +<p dir="rtl">جاوا اسکریپت شامل یک کتابخانه استاندارد اشیا است مانند Array، Date و Math، مجموعه پایه ای از عناصر زبان مثل عملگرها، ساختارهای کنترلی و عبارات. هسته ی زبان جاوا اسکریپت می تواند برای اهداف مختلفی توسعه داده شود. برای این منظور از جاوا اسکریپت به همراه اشیایی اضافی استفاده می شود برای مثال:</p> + +<ul> + <li dir="rtl">جاوا اسکریپت سمت مشتری(کلاینت): هسته زبان را با استفاده از اشیایی توسعه می دهد که مرورگر و ساختار DOM آن را کنترل می کند. برای مثال افزونه های سمت مشتری به برنامه اجازه می دهند تا عناصری را در یک فرم HTML قرار دهد و به رویدادهای کاربر مانند کلیک های موس، ورودی های فرم،... پاسخ دهد.</li> + <li dir="rtl">جاوا اسکریپت سمت خادم(سرور): هسته جاوا اسکریپت را با استفاده از اشیایی که به اجرا شدن جاوا اسکریپت بر روی سرور مربوط می شود توسعه می دهد. برای مثال افزونه های سمت سرور به برنامه اجازه می دهند تا با پایگاه داده ارتباط برقرار کند،</li> +</ul> + +<h2 dir="rtl" id="JavaScript_and_Java" name="JavaScript_and_Java">جاوا اسکریپت و جاوا</h2> + +<p dir="rtl">جاوااسکریپت و جاوا از بعضی جهات با هم مشابه</p> + +<p>In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based object model instead of the more common class-based object model. The prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without any special declarative requirements. Functions can be properties of objects, executing as loosely typed methods.</p> + +<p>JavaScript is a very free-form language compared to Java. You do not have to declare all variables, classes, and methods. You do not have to be concerned with whether methods are public, private, or protected, and you do not have to implement interfaces. Variables, parameters, and function return types are not explicitly typed.</p> + +<p>Java is a class-based programming language designed for fast execution and type safety. Type safety means, for instance, that you can't cast a Java integer into an object reference or access private memory by corrupting Java bytecodes. Java's class-based model means that programs consist exclusively of classes and their methods. Java's class inheritance and strong typing generally require tightly coupled object hierarchies. These requirements make Java programming more complex than JavaScript programming.</p> + +<p>In contrast, JavaScript descends in spirit from a line of smaller, dynamically typed languages such as HyperTalk and dBASE. These scripting languages offer programming tools to a much wider audience because of their easier syntax, specialized built-in functionality, and minimal requirements for object creation.</p> + +<table class="standard-table"> + <caption>JavaScript compared to Java</caption> + <thead> + <tr> + <th scope="col">JavaScript</th> + <th scope="col">Java</th> + </tr> + </thead> + <tbody> + <tr> + <td>Object-oriented. No distinction between types of objects. Inheritance is through the prototype mechanism, and properties and methods can be added to any object dynamically.</td> + <td>Class-based. Objects are divided into classes and instances with all inheritance through the class hierarchy. Classes and instances cannot have properties or methods added dynamically.</td> + </tr> + <tr> + <td>Variable data types are not declared (dynamic typing).</td> + <td>Variable data types must be declared (static typing).</td> + </tr> + <tr> + <td>Cannot automatically write to hard disk.</td> + <td>Can automatically write to hard disk.</td> + </tr> + </tbody> +</table> + +<p>For more information on the differences between JavaScript and Java, see the chapter <a href="/en-US/docs/Web/JavaScript/Guide/Details_of_the_Object_Model">Details of the object model</a>.</p> + +<h2 dir="rtl" id="JavaScript_and_the_ECMAScript_Specification" name="JavaScript_and_the_ECMAScript_Specification">مشخصات جاوا اسکریپت و اکما اسکریپت</h2> + +<p dir="rtl">جاوا اسکریپت در <a href="http://www.ecma-international.org/">Ecma International</a> استاندارد شده است —اتحادیه اروپا برای استاندارد سازی سیستم های اطلاعاتی و ارتباطی (ECMA مخفف انجمن سازندگان کامپیوتری اروپا) بود تا یک زبان برنامه نویسی استاندارد مبتنی بر جاوا اسکریپت را ارائه کند.</p> + +<p dir="rtl">این نسخه استاندارد از جاوا اسکریپت، به نام اکما اسکریپت ، در تمامی برنامه هایی که از استاندارد پشتیبانی می کنند، یکسان عمل می کند. شرکت ها می توانند از استاندارد زبان باز برای توسعه جاوا اسکریپت خود استفاده کنند. استاندارد اکما اسکریپت در مشخصات ECMA-262 مستند شده است. <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript">تازه ها</a> در جاوا اسکریپت را برای کسب اطلاعات بیشتر در مورد نسخه های مختلف نسخه های خاص جاوا اسکریپت و اکما اسکریپت مشاهده کنید.</p> + +<p dir="rtl">The ECMA-262 standard is also approved by the <a class="external" href="http://www.iso.ch/">ISO</a> (International Organization for Standardization) as ISO-16262. You can also find the specification on <a class="external" href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">the Ecma International website</a>. The ECMAScript specification does not describe the Document Object Model (DOM), which is standardized by the <a class="external" href="http://www.w3.org/">World Wide Web Consortium (W3C)</a> and/or <a href="https://whatwg.org">WHATWG (Web Hypertext Application Technology Working Group)</a>. The DOM defines the way in which HTML document objects are exposed to your script. To get a better idea about the different technologies that are used when programming with JavaScript, consult the article <a href="/en-US/docs/Web/JavaScript/JavaScript_technologies_overview">JavaScript technologies overview</a>.</p> + +<h3 dir="rtl" id="JavaScript_Documentation_versus_the_ECMAScript_Specification" name="JavaScript_Documentation_versus_the_ECMAScript_Specification">مستندات جاوا اسکریپت در مقایسه با مشخصات اکما اسکریپت</h3> + +<p dir="rtl">مشخصات اکما اسکریپت مجموعه ای از الزامات برای پیاده سازی اکما اسکریپت است؛ اگر شما می خواهید ویژگی های زبان سازگار با استاندارد را در پیاده سازی اکما اسکریپت یا موتور خود (مانند SpiderMonkey در فایرفاکس یا v8 در Chrome) پیاده سازی کنید، مفید است.</p> + +<p>The ECMAScript document is not intended to help script programmers; use the JavaScript documentation for information on writing scripts.</p> + +<p>The ECMAScript specification uses terminology and syntax that may be unfamiliar to a JavaScript programmer. Although the description of the language may differ in ECMAScript, the language itself remains the same. JavaScript supports all functionality outlined in the ECMAScript specification.</p> + +<p>The JavaScript documentation describes aspects of the language that are appropriate for a JavaScript programmer.</p> + +<h2 dir="rtl" id="شروع_با_جاوا_اسکریپت">شروع با جاوا اسکریپت</h2> + +<p>Getting started with JavaScript is easy: all you need is a modern Web browser. This guide includes some JavaScript features which are only currently available in the latest versions of Firefox, so using the most recent version of Firefox is recommended.</p> + +<p>There are two tools built into Firefox that are useful for experimenting with JavaScript: the Web Console and Scratchpad.</p> + +<h3 dir="rtl" id="کنسول_وب">کنسول وب</h3> + +<p>The <a href="/en-US/docs/Tools/Web_Console">Web Console</a> shows you information about the currently loaded Web page, and also includes a <a href="/en-US/docs/Tools/Web_Console#The_command_line_interpreter">command line</a> that you can use to execute JavaScript expressions in the current page.</p> + +<p>To open the Web Console (Ctrl+Shift+K), select "Web Console" from the "Developer" menu, which is under the "Tools" menu in Firefox. It appears at the bottom of the browser window. Along the bottom of the console is a command line that you can use to enter JavaScript, and the output appears in the pane above:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7363/web-console-commandline.png" style="display: block; margin-left: auto; margin-right: auto;"></p> + +<h3 id="Scratchpad">Scratchpad</h3> + +<p>The Web Console is great for executing single lines of JavaScript, but although you can execute multiple lines, it's not very convenient for that, and you can't save your code samples using the Web Console. So for more complex examples <a href="/en-US/docs/Tools/Scratchpad">Scratchpad</a> is a better tool.</p> + +<p>To open Scratchpad (Shift+F4), select "Scratchpad" from the "Developer" menu, which is under the menu in Firefox. It opens in a separate window and is an editor that you can use to write and execute JavaScript in the browser. You can also save scripts to disk and load them from disk.</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7365/scratchpad.png" style="display: block; margin-left: auto; margin-right: auto;"></p> + +<h3 id="Hello_world">Hello world</h3> + +<p>To get started with writing JavaScript, open the Scratchpad and write your first "Hello world" JavaScript code:</p> + +<pre class="brush: js">function greetMe(yourName) { + alert("Hello " + yourName); +} + +greetMe("World"); +</pre> + +<p>Select the code in the pad and hit Ctrl+R to watch it unfold in your browser!</p> + +<p>In the following pages, this guide will introduce you to the JavaScript syntax and language features, so that you will be able to write more complex applications.</p> + +<p>{{PreviousNext("Web/JavaScript/Guide", "Web/JavaScript/Guide/Grammar_and_types")}}</p> diff --git a/files/fa/web/mathml/index.html b/files/fa/web/mathml/index.html new file mode 100644 index 0000000000..1c286e0c7b --- /dev/null +++ b/files/fa/web/mathml/index.html @@ -0,0 +1,126 @@ +--- +title: MathML +slug: Web/MathML +translation_of: Web/MathML +--- +<p class="summary" dir="rtl"><strong>زبان نشانهگذاری ریاضی (MathML)</strong> گویشی از <a href="/fa/docs/XML" title="/en-US/docs/XML">XML</a> ، برای توصیف نمادها و ضبط هر دو مورد محتوی و ساختار ریاضی می باشد.</p> + +<p dir="rtl">در اینجا پیوندهایی به مستندات، مثالها و ابزارهایی را برای کمک به کارکردن شما با این تکنولوژی قوی خواهید یافت. برای یک مرور کلی، می توانید به لینک زیر مراجعه نمایید: </p> + +<p dir="rtl"> <a href="https://fred-wang.github.io/MozSummitMathML/index.html">slides for the innovation fairs at Mozilla Summit 2013</a></p> + +<div class="row topicpage-table" dir="rtl"> +<div class="section"> +<h2 class="Documentation" id="Documentation" name="Documentation">مراجع MathML</h2> + +<dl> + <dt><a href="/fa/docs/Web/MathML/Element" title="/en-US/docs/Web/MathML/Element">مرجع المان MathML</a></dt> + <dd>جزییاتی در مورد هر المان MathML و اطلاعات سازگار برای مرورگرهای میزکار و سیار.</dd> + <dt><a href="/fa/docs/Web/MathML/Attribute" title="/en-US/docs/Web/MathML/Attribute">مرجع خصوصیت MathML</a></dt> + <dd>اطلاعاتی در مورد خصوصیات MathML که رفتار و ظاهر المانها را تغییر میدهد.</dd> + <dt><a href="/fa/docs/Web/MathML/Examples" title="/en-US/docs/Web/MathML/Examples">مثالهای MathML</a></dt> + <dd>نمونهها و مثالهای MathML که به شما در فهمیدن چگونگی عملکرد آن کمک میکند.</dd> + <dt><a href="/fa/docs/Web/MathML/Authoring" title="/en-US/docs/Web/MathML/Authoring">نگارش MathML</a></dt> + <dd>پیشنهادها و نکاتی برای نوشتن MathML، شامل ویرایشگرهای پیشنهادی MathML و چگونگی گنجاندن آنها در داخل محتویات وب.</dd> +</dl> + +<p><span class="alllinks"><a href="/fa/docs/tag/MathML" title="/en-US/docs/tag/CSS">نمایش همه...</a></span></p> +</div> + +<div class="section"> +<h2 class="Community" id="کمک_گرفتن_از_جامعه">کمک گرفتن از جامعه</h2> + +<ul> + <li>دیدن انجمن های موزیلا...<br> + {{ DiscussionList("dev-tech-mathml", "mozilla.dev.tech.mathml") }}</li> + <li><a class="link-irc" href="irc://irc.mozilla.org/%23mathml" rel="external" title="irc://irc.mozilla.org/%23mathml">کانال IRC</a></li> + <li><a class="link-https" href="https://wiki.mozilla.org/MathML:Home_Page">Wiki مورد استفاده موزیلا</a></li> + <li><a href="http://www.w3.org/Math/" title="http://www.w3.org/Math/">خانه ریاضی W3C</a></li> + <li><a href="http://lists.w3.org/Archives/Public/www-math/" title="http://lists.w3.org/Archives/Public/www-math/">بایگانی پست www-math w3.org</a></li> +</ul> + +<h2 class="Tools" id="ابزارها">ابزارها</h2> + +<ul> + <li><a class="external" href="http://validator.w3.org">تایید کننده W3C</a></li> + <li><a class="link-https" href="https://addons.mozilla.org/de/firefox/addon/8969/">افزونه FireMath فایرفاکس</a></li> + <li><a href="https://addons.mozilla.org/firefox/collections/fred_wang/mathzilla/" title="https://addons.mozilla.org/firefox/collections/fred_wang/mathzilla/">مجموعه افزونه های Mathzilla فایرفاکس</a></li> + <li><a href="https://github.com/fred-wang/TeXZilla">TeXZilla</a> - مبدل Javascript LaTeX to MathML (<a href="http://fred-wang.github.io/TeXZilla/">live demo</a>، <a href="http://r-gaia-cs.github.io/TeXZilla-webapp/">Firefox OS webapp،</a> <a href="https://addons.mozilla.org/en-US/firefox/addon/texzilla/">Firefox add-on،</a> <a href="https://github.com/fred-wang/TeXZilla/wiki/Using-TeXZilla">using in a Web Page، JS program etc</a>)</li> + <li><a href="http://dlmf.nist.gov/LaTeXML/" title="http://dlmf.nist.gov/LaTeXML/">LaTeXML</a> - تبدیل اسناد LaTeX d به HTML+ صفحات وبMathML</li> + <li><a href="http://webdemo.visionobjects.com/home.html#equation" title="http://webdemo.visionobjects.com/equation.html">Web Equation</a> - برگرداندن معادلات دستنویس به MathML یا LaTeX</li> + <li><a href="http://www.mathjax.org/" title="http://www.mathjax.org/">MathJax</a> - میان مرورگر- موتور نمایش جاوا اسکریپت برای ریاضیات. جهت تقویت MathJax برای ;کار با MathML ساده، رجوع شود به: <a href="https://addons.mozilla.org/en-US/firefox/addon/mathjax-native-mathml/">this Mozilla add-on</a>, یا <a href="http://fred-wang.github.io/mathjax-native-mathml-safari/mathjax-native-mathml.safariextz">Safari extension </a>و یا <a href="https://openuserjs.org/scripts/fred.wang/MathJax_Native_MathML/">GreaseMonkey scrip</a>.</li> +</ul> + +<h2 class="Related_Topics" id="Related_Topics" name="Related_Topics">موضوعات مرتبط</h2> + +<ul> + <li><a href="/fa/docs/Web/CSS" title="/en-US/docs/Web/CSS">CSS</a></li> + <li><a href="/fa/docs/Web/HTML" title="/en-US/docs/Web/HTML">HTML</a></li> + <li><a href="/fa/docs/Web/SVG" title="/en-US/docs/Web/SVG">SVG</a></li> +</ul> +</div> +</div> + +<h2 dir="rtl" id="Browser_compatibility" name="Browser_compatibility">سازگاری با مرورگر</h2> + +<div class="hidden"> +<p dir="rtl">جدول سازگاری در این صفحه، از ساختمان داده ها تولید می شود. اگر مایل به کمک به این اطلاعات هستید، لطفا آدرس <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> را ملاحظه نموده و برای ما یک درخواست واکشی بفرستید.</p> + +<p dir="rtl">{{CompatibilityTable}}</p> +</div> + +<p> </p> + +<div dir="rtl" id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoDesktop("1.8")}}</td> + <td>With PlugIn(s)</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div dir="rtl" id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("1.8")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div dir="rtl"> +<h3 id="نکات_Gecko">نکات Gecko</h3> + +<p>شروع با فایرفاکس 1.5، بسیاری از نشانهگذاریهای <a class="external" href="http://www.w3.org/TR/MathML2/">MathML 2.0 W3C Recommendation</a> روی همه پلت فرمها پشتیبانی شده است. پشتیبانی برای <a class="external" href="http://www.w3.org/TR/MathML3/" title="http://www.w3.org/TR/MathML3/">MathML 3</a> <a href="/en-US/docs/Mozilla_MathML_Project/Status" title="/en-US/docs/Mozilla_MathML_Project/Status">در حال پیشرفت</a> است.</p> +</div> + +<p dir="rtl"> </p> diff --git a/files/fa/web/svg/index.html b/files/fa/web/svg/index.html new file mode 100644 index 0000000000..5230a881a5 --- /dev/null +++ b/files/fa/web/svg/index.html @@ -0,0 +1,94 @@ +--- +title: SVG +slug: Web/SVG +tags: + - 2D Graphics + - NeedsTranslation + - References + - SVG + - TopicStub +translation_of: Web/SVG +--- +<div class="callout-box"> + <strong><a href="/en-US/docs/SVG/Tutorial" title="SVG/Tutorial">Getting Started</a></strong><br> + This tutorial will help get you started using SVG.</div> +<p><strong>Scalable Vector Graphics (SVG)</strong> is an <a href="/en-US/docs/XML" title="XML">XML</a> markup language for describing two-dimensional vector graphics. SVG is essentially to graphics what XHTML is to text.</p> +<p>SVG is similar in scope to Adobe's proprietary Flash technology, but what distinguishes SVG from Flash is that it is a <a href="http://www.w3.org/Graphics/SVG/">W3C recommendation</a> (i.e., a standard) and that it is XML-based as opposed to a closed binary format. It is explicitly designed to work with other <a href="http://www.w3.org/">W3C</a> standards such as <a href="/en-US/docs/CSS" title="CSS">CSS</a>, <a href="/en-US/docs/DOM" title="DOM">DOM</a> and <a href="http://www.w3.org/AudioVideo/">SMIL</a>.</p> +<div class="cleared row topicpage-table"> + <div class="section"> + <h2 class="Documentation" id="Documentation">Documentation</h2> + <dl> + <dt> + <a href="/en-US/docs/Web/SVG/Element">SVG element reference</a></dt> + <dd> + Get details about each SVG element.</dd> + <dt> + <a href="/en-US/docs/Web/SVG/Attribute">SVG attribute reference</a></dt> + <dd> + Get details about each SVG attribute.</dd> + <dt> + <a href="/en-US/docs/DOM/DOM_Reference#SVG_interfaces">SVG DOM interface reference</a></dt> + <dd> + Get details about the whole SVG DOM API.</dd> + <dt> + Enhance HTML content</dt> + <dd> + SVG works together with HTML, CSS and JavaScript. Use SVG to enhance a regular HTML page or web application.</dd> + <dt> + SVG in Mozilla</dt> + <dd> + Notes and information on how SVG is implemented in Mozilla. + <ul> + <li><a href="/en-US/docs/SVG_in_Firefox">How much SVG is implemented in Firefox</a></li> + <li><a href="/en-US/docs/Web/SVG/Tutorial">Tutorial for how to use </a></li> + <li><a href="/en-US/docs/SVG_In_HTML_Introduction">SVG in XHTML</a></li> + </ul> + </dd> + </dl> + <p><span class="alllinks"><a href="/en-US/docs/tag/SVG">View All...</a></span></p> + <h2 class="Community" id="Community">Community</h2> + <ul> + <li>View Mozilla forums... {{DiscussionList("dev-tech-svg", "mozilla.dev.tech.svg")}}</li> + </ul> + <h2 class="Tools" id="Tools">Tools</h2> + <ul> + <li><a href="http://www.w3.org/Graphics/SVG/Test/">SVG Test Suite</a></li> + <li><a href="http://jiggles.w3.org/svgvalidator/">SVG Validator</a> (Discontinued)</li> + <li><a href="/en-US/docs/tag/SVG:Tools" title="tag/SVG:Tools">More Tools...</a></li> + <li>Other resources: <a href="/en-US/docs/XML">XML</a>, <a href="/en-US/docs/CSS">CSS</a>, <a href="/en-US/docs/DOM">DOM</a>, <a href="/en-US/docs/HTML/Canvas">Canvas</a></li> + </ul> + </div> + <div class="section"> + <h2 class="Related_Topics" id="Examples">Examples</h2> + <ul> + <li>Google <a href="http://maps.google.com">Maps</a> (route overlay) & <a href="http://docs.google.com">Docs</a> (spreadsheet charting)</li> + <li><a href="http://starkravingfinkle.org/projects/demo/svg-bubblemenu-in-html.xml">SVG bubble menus</a></li> + <li><a href="http://jwatt.org/svg/authoring/">SVG authoring guidelines</a></li> + <li>An overview of the <a href="/en-US/docs/Mozilla_SVG_Project">Mozilla SVG Project</a></li> + <li><a href="/en-US/docs/SVG/FAQ" title="SVG/FAQ">Frequently asked questions</a> regarding SVG and Mozilla</li> + <li>Slides and demos from talk on <a href="http://jwatt.org/svg-open-US/docs/2009/slides.xhtml">SVG and Mozilla</a> at SVG Open 2009</li> + <li><a href="/en-US/docs/SVG/SVG_as_an_Image">SVG as an image</a></li> + <li><a href="/en-US/docs/SVG/SVG_animation_with_SMIL">SVG animation with SMIL</a></li> + <li><a href="http://plurib.us/1shot/2007/svg_gallery/">SVG art gallery</a></li> + <li>More samples (<a href="http://croczilla.com/bits_and_pieces/svg/samples">SVG Samples croczilla.com</a>, <a href="http://www.carto.net/papers/svg/samples/">carto.net</a>)</li> + </ul> + <h3 id="Animation_and_interactions">Animation and interactions</h3> + <p>Like HTML, SVG has a document model (DOM), events and is accessible from JavaScript. This allows developers to create rich animations and interactive images.</p> + <ul> + <li>Some real eye-candy SVG at <a href="http://svg-wow.org/">svg-wow.org</a></li> + <li>Firefox extension (<a href="http://schepers.cc/grafox/">Grafox</a>) to add a subset of SMIL animation support</li> + <li>Interactive <a href="http://people.mozilla.com/~vladimir/demos/photos.svg">photos</a> manipulation</li> + <li><a href="http://starkravingfinkle.org/blog/2007/07/firefox-3-svg-foreignobject/">HTML transformations</a> using SVG's <code>foreignObject</code></li> + </ul> + <h3 id="Mapping_charting_games_3D_experiments">Mapping, charting, games & 3D experiments</h3> + <p>While a little SVG can go a long way to enhanced web content, here are some examples of heavy SVG usage.</p> + <ul> + <li><a href="http://www.codedread.com/yastframe.php">Tetris</a></li> + <li><a href="https://web.archive.org/web/20131019072450/http://www.treebuilder.de/svg/connect4.svg" title="Archive link provided because source now requires authentication.">Connect 4</a></li> + <li><a href="http://www.carto.net/papers/svg/us_population/index.html">US population map</a></li> + <li><a href="http://www.treebuilder.de/default.asp?file=441875.xml">3D box</a> & <a href="http://www.treebuilder.de/default.asp?file=206524.xml">3D boxes</a></li> + <li><a href="http://jvectormap.com/">jVectorMap</a> (interactive maps for data visualization)</li> + </ul> + </div> +</div> +<p> </p> diff --git a/files/fa/web/svg/tutorial/index.html b/files/fa/web/svg/tutorial/index.html new file mode 100644 index 0000000000..7767ffd448 --- /dev/null +++ b/files/fa/web/svg/tutorial/index.html @@ -0,0 +1,38 @@ +--- +title: SVG Tutorial +slug: Web/SVG/Tutorial +translation_of: Web/SVG/Tutorial +--- +<p dir="RTL">گرافیک برداری مقیاس پذیر <span dir="LTR">SVG</span> گویشی (نسخه خاصی از) <span dir="LTR">W3C XML</span> برای نشانه گذاری گرافیک (تصاویر) می باشد.</p> +<p>Scalable Vector Graphics, <a href="/en-US/Web/SVG" title="en-US/Web/SVG">SVG</a>, is a W3C XML dialect to mark up graphics. It is partially implemented in Firefox, Opera, WebKit browsers, Internet Explorer and other browsers.</p> +<p>This tutorial aims to explain the internals of SVG and is packed with technical details. If you just want to draw beautiful images, you might find more useful resources at <a class="external" href="http://inkscape.org/doc/" title="http://inkscape.org/doc/">Inkscape's documentation page</a>. Another good introduction to SVG is provided by the W3C's <a class="external" href="http://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html" title="http://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html">SVG Primer</a>.</p> +<div class="note"> + The tutorial is in an early stage of development. If you're able, please help out by chipping in and writing a paragraph or two. Extra points for writing a whole page!</div> +<h5 id="Introducing_SVG_from_Scratch">Introducing SVG from Scratch</h5> +<ul> + <li><a href="/en-US/Web/SVG/Tutorial/Introduction" title="en-US/Web/SVG/Tutorial/Introduction">Introduction</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Getting_Started" title="en-US/Web/SVG/Tutorial/Getting_Started">Getting Started</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Positions" title="en-US/Web/SVG/Tutorial/Positions">Positions</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Basic_Shapes" title="en-US/Web/SVG/Tutorial/Basic_Shapes">Basic Shapes</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Paths" title="en-US/Web/SVG/Tutorial/Paths">Paths</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Fills_and_Strokes" title="en-US/Web/SVG/Tutorial/Fills_and_Strokes">Fills and Strokes</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Gradients" title="en-US/Web/SVG/Tutorial/Gradients">Gradients</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Patterns" title="en-US/Web/SVG/Tutorial/Patterns">Patterns</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Texts" title="en-US/Web/SVG/Tutorial/Texts">Texts</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Basic_Transformations" title="en-US/Web/SVG/Tutorial/Basic_Transformations">Basic Transformations</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Clipping_and_masking" title="en-US/Web/SVG/Tutorial/Clipping_and_masking">Clipping and masking</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Other_content_in_SVG" title="en-US/Web/SVG/Tutorial/Other content in SVG">Other content in SVG</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Filter_effects" title="en-US/Web/SVG/Tutorial/Filter effects">Filter effects</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/SVG_fonts" title="en-US/Web/SVG/Tutorial/SVG fonts">SVG fonts</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/SVG_Image_Tag" title="en-US/Web/SVG/Tutorial/SVG Image Tag">SVG Image tag</a></li> + <li><a href="/en-US/Web/SVG/Tutorial/Tools_for_SVG" title="en-US/Web/SVG/Tutorial/Tools_for_SVG">Tools for SVG</a></li> +</ul> +<p>The following topics are more advanced and hence should get their own tutorials.</p> +<h5 id="Scripting_SVG_with_JavaScript">Scripting SVG with JavaScript</h5> +<p>TBD</p> +<h5 id="SVG_filters_tutorial">SVG filters tutorial</h5> +<p>TBD</p> +<h5 id="Animations_with_SMIL_in_SVG">Animations with SMIL in SVG</h5> +<p>TBD</p> +<h5 id="Creating_fonts_in_SVG">Creating fonts in SVG</h5> +<p>TBD</p> diff --git a/files/fa/web/svg/tutorial/introduction/index.html b/files/fa/web/svg/tutorial/introduction/index.html new file mode 100644 index 0000000000..609d506200 --- /dev/null +++ b/files/fa/web/svg/tutorial/introduction/index.html @@ -0,0 +1,45 @@ +--- +title: معرفی SVG +slug: Web/SVG/Tutorial/Introduction +translation_of: Web/SVG/Tutorial/Introduction +--- +<p>{{ PreviousNext("Web/SVG/Tutorial", "Web/SVG/Tutorial/Getting_Started") }}</p> + +<p><img alt="" class="internal" src="/@api/deki/files/348/=SVG_Overview.png" style="float: right;"></p> + +<p dir="rtl">SVG یگ زبان نشانه گذاری مبتنی بر XML و شبیه به XHTML است که برای طراحی گرافیکی استفاده میشود مانند تصاویری که سمت راست میبینید.با استفاده از آن هم می توان تصاویری متشکل از خطوط و اشکال هندسی متفاوت ساخت هم تصاویری که به اصطلاح <a href="https://fa.wikipedia.org/wiki/%DA%AF%D8%B1%D8%A7%D9%81%DB%8C%DA%A9_%D8%B4%D8%B7%D8%B1%D9%86%D8%AC%DB%8C">گرافیک شطرنجی</a> خوانده می شوند ویا حتی ترکیبی از هر دو. این نوع تصاویر و اجزایشان میتوانند تبدیل شوند یا با هم مخلوط شوند یا حتی فیلترسازی (فیلتر ها در فتوشاپ یا css) شده تا ظاهرشان به کلی تغییر کند.</p> + +<p dir="rtl">SVG حدود سال های 1999 بعد از چندین رقابت فرمت ها(زبان های دیگر مبتنی بر XML) به <a href="https://w3.org">W3C </a>ارسال شد و از تصویب رسمی و کامل باز ماند. با اینکه این وضع برای مدت کوتاهی بود باز هم پشتیبانی مرورگر ها به کندی صورت میگرفت به همین دلیل استفاده گسترده ای از SVG در فضای وب نمیشود(این آمار مربوط به سال 2009 است اکنون یعنی در سال 2016 از SVG برای ساخت وبسایت ها و وب اپلیکیشن ها استفاده فراوانی می شود).</p> + +<p>Even the implementations that are available often are not as fast as competing technologies like <a href="/en-US/HTML/Canvas" title="en-US/HTML/Canvas">HTML5 Canvas</a> or Adobe Flash as a full application interface. SVG does offer benefits over both implementations, some of which include having a <a href="/en-US/docs/Web/API">DOM interface</a> available for it, and not requiring third-party extensions. Whether or not to use it often depends on your specific use case.</p> + +<h3 id="Basic_ingredients">Basic ingredients</h3> + +<p><a href="/en-US/docs/Web/HTML">HTML</a> provides elements for defining headers, paragraphs, tables, and so on. In much the same way SVG provides elements for circles, rectangles, and simple and complex curves. A simple SVG document consists of nothing more than the {{ SVGElement('svg') }} root element and several basic shapes that build a graphic together. In addition there is the {{ SVGElement('g') }} element, which is used to group several basic shapes together.</p> + +<p>Starting from there, the SVG image can become arbitrarily complex. SVG supports gradients, rotations, filter effects, animations, interactivity with JavaScript, and so on. But all these extra features of the language rely on this relatively small set of elements to define the graphic area.</p> + +<h3 id="Before_you_start" name="Before_you_start">Before you start</h3> + +<p>There are a number of drawing applications available such as <a class="external" href="http://www.inkscape.org/">Inkscape</a> which are free and use SVG as their native file format. However, this tutorial will rely on the trusty XML or text editor (your choice). The idea is to teach the internals of SVG to those who want to understand it, and that is best done by dirtying your hands with a bit of markup. You should note your final goal though. Not all SVG viewers are equal and so there is a good chance that something written for one app will not display exactly the same in another, simply because they support different levels of the SVG specification or another specification that you are using along with SVG (that is, <a href="/en-US/JavaScript" title="en-US/JavaScript">JavaScript</a> or <a href="/en-US/CSS" title="en-US/CSS">CSS</a>).</p> + +<p>SVG is supported in all modern browsers and even a couple versions back in some cases. A fairly complete browser support table can be found on <a href="http://caniuse.com/svg">Can I use</a>. Firefox has supported some SVG content since version 1.5, and that support level has been growing with each release since. Hopefully, along with the tutorial here, MDN can help developers keep up with the differences between Gecko and some of the other major implementations.</p> + +<p>Before starting you should have a basic understanding of XML or another markup language such as <abbr title="HyperText Markup Language">HTML</abbr>. If you are not too familiar with XML, here are some guidelines to keep in mind:</p> + +<ul> + <li>SVG elements and attributes should all be entered in the case shown here since XML is case-sensitive (unlike HTML).</li> + <li>Attribute values in SVG must be placed inside quotes, even if they are numbers.</li> +</ul> + +<p>SVG is a huge specification. This tutorial attempts to cover the basics. Once you are familiar you should be able to use the <a href="/en-US/SVG/Element" title="en-US/SVG/Element">Element Reference</a> and the <a href="/en-US/docs/DOM/DOM_Reference#SVG_interfaces" title="en-US/SVG/Interface">Interface Reference</a> to find out anything else you need to know.</p> + +<h3 id="Flavors_of_SVG">Flavors of SVG</h3> + +<p>Since becoming a recommendation in 2003, the most recent "full" SVG version is 1.1. It builds on top of SVG 1.0, but adds more modularization to ease implementation. <a href="http://www.w3.org/TR/SVG/">The second edition of SVG 1.1</a> became a Recommendation in 2011. "Full" SVG 1.2 was meant to be the next major release of SVG. It was dropped for the upcoming <a href="http://www.w3.org/TR/SVG2/">SVG 2.0</a>, which is under heavy development right now and follows a similar approach to CSS 3 in that it splits components in several loosely coupled specifications.</p> + +<p>Apart from the full SVG recommendations, the working group at the W3C introduced SVG Tiny and SVG Basic in 2003. These two profiles are aimed mainly at mobile devices. The first, SVG Tiny, should yield graphic primitives for small devices with low capabilities. SVG Basic offers many features of full SVG, but doesn't include the ones which are hard to implement or heavy to render (like animations). In 2008, SVG Tiny 1.2 became a W3C Recommendation.</p> + +<p>There were plans for an SVG Print specification, which would add support for multiple pages and enhanced color management. This work was discontinued.</p> + +<p>{{ PreviousNext("Web/SVG/Tutorial", "Web/SVG/Tutorial/Getting_Started") }}</p> diff --git a/files/fa/web/tutorials/index.html b/files/fa/web/tutorials/index.html new file mode 100644 index 0000000000..0015a91882 --- /dev/null +++ b/files/fa/web/tutorials/index.html @@ -0,0 +1,161 @@ +--- +title: آموزش +slug: Web/Tutorials +translation_of: Web/Tutorials +--- +<div class="note"> +<ol> + <li><span style="display: none;"> </span><span style="display: none;"> </span>لینکها در این صفحه به آموزشها و مواد آموزشی متنوعی هدایت شده است. چه شما تازه شروع کرده باشید، در حال یادگیری اصول اولیه هستید، یا در توسعه وب قدیمی هستید، در اینجا منابع مفیدی را برای تمرین بهتر میتوانید پیدا کنید. این منابع توسط شرکتهای متفکر رو به جلو و توسعه دهندگان وبی که استانداردهای باز و بهترین تمرینها برای توسعه دهندگان وب را پذیرفتهاند ساخته شده است وآن منابع آماده یا برای ترجمه اجازه داده میشود، از طریق گواهینامه محتوای باز مانند Creative Commons.</li> +</ol> + +<dl> +</dl> +</div> + +<div class="row topicpage-table" dir="rtl"> +<div class="section"> +<h2 class="Documentation" id="Documentation" name="Documentation">آموزش HTML</h2> + +<h3 id="سطح_مقدماتی">سطح مقدماتی</h3> + +<dl> + <dt><a href="/en-US/docs/Web/Guide/HTML/Introduction">معرفی به HTML</a></dt> + <dd>HTML چی است، چه انجام میدهد، تاریخچه آن بهصورت خلاصه، ساختار یک سند HTML شبیه چی است. مقالاتی که در ادامه آمده است هر کدام در هر بخش خاص از HTML نگاهی عمیقتر به آن دارند.</dd> + <dt><a href="http://reference.sitepoint.com/html/page-structure" rel="external">ساختار بنیادی یک صفحه وب</a> (اطلاعیه)</dt> + <dd>یاد بگیرید چطور المانهای HTML با همدیگر مناسب هستند برای تصویری بزرگتر.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/HTML/Element">MDN HTML Element Reference</a></dt> + <dd>یک مرجع وسیع برای المانهای HTML، و مرورگرهای متفاوت چطور از آنها پشتیبانی میکنند.</dd> + <dt><a href="http://wikiversity.org/wiki/Web_Design/HTML_Challenges" rel="external">HTML Challenges</a> (Wikiversity)</dt> + <dd>این چالش را برای صاف کردن مهارتهای HTML خود بکار ببرید (برای مثال، "آیا من باید یک المان <h2> یا یک المان <strong> را بکار ببرم؟")، روی نشانه گذاری معنی دار تمرکز کنید.</dd> + <dt><a href="http://codeavengers.com/" title="http://codeavengers.com/">CodeAvengers</a> (CodeAvengers.com)</dt> + <dd>Code Avengers یک سرگرمی است، راه مؤثری برای یادگیری کد نرم افزارهای تحت وب و بازیها باHTML، CSS، و JavaScript.</dd> +</dl> + +<h3 id="سطح_پیشرفته">سطح پیشرفته</h3> + +<dl> + <dt><a href="https://developer.mozilla.org/en-US/docs/Tips_for_Authoring_Fast-loading_HTML_Pages">نکاتی برای نوشتن بارگذاری سریع صفحات HTML </a></dt> + <dd>بهینه سازی صفحات وب برای فراهم کردن پاسخگویی بیشتر سایت برای بازدید کنندگان و کاهش بارگذاری روی سرور وب و ارتباط اینترنت .</dd> + <dt><a href="http://www.html5rocks.com/tutorials/" rel="external">HTML5 Tutorials</a> (HTML5 Rocks)</dt> + <dd>یک تور راهنما از طریق کدی که از قابلیتهای HTML5 استفاده میکند.</dd> + <dt><a href="http://www.alistapart.com/articles/semanticsinhtml5/" rel="external">Semantics in HTML5</a> (A List Apart)</dt> + <dd>یادگیری نشانه گذاری معنی دار که قابل توسعه است و به عقب- و به جلو-همخوانی دارد.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/Canvas_tutorial">Canvas Tutorial</a></dt> + <dd>یاد بگیرید چطور گرافیک را با استفاده از اسکریپت نویسی المان canvas رسم کنید.</dd> + <dt><a href="http://html5doctor.com/" rel="external">HTML5 Doctor</a></dt> + <dd>مقالههایی در مورد استفاده HTML5 همین حالا.</dd> + <dt><a href="http://www.elated.com/articles/html5-audio/" rel="external">The Joy of HTML5 Audio</a> (Elated)</dt> + <dd>یادبگیرید چطور از المان صوتی HTML تا صداها را به سادگی در صفحات وب خود جایگذاری کنید. خیلی از نمونه کدها در آموزش گنجانده شده است.</dd> +</dl> + +<h2 class="Documentation" id="Documentation" name="Documentation">آموزش Javascript</h2> + +<h3 id="سطح_مقدماتی_2">سطح مقدماتی</h3> + +<dl> + <dt><a href="http://www.codecademy.com/">Codecademy</a> (Codecademy)</dt> + <dd>Codecademy یک راه ساده برای یادگیری چگونگی کد با جاوا اسکریپت است. این برنامه تعاملی است و شما میتوانید با دوستانتان آنرا انجام دهید.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Getting_Started">Getting Started with JavaScript</a></dt> + <dd>جاوا اسکریپت چی هست و چطور به شما کمک میکند؟</dd> + <dt><a href="http://docs.webplatform.org/wiki/tutorials/javascript_best_practices" rel="external">JavaScript Best Practices</a><a href="http://docs.webplatform.org/wiki/tutorials/javascript_best_practices" title="http://docs.webplatform.org/wiki/tutorials/javascript_best_practices"> </a>(WebPlatform.org)</dt> + <dd>در مورد برخی از واضح (یا نه خیلی) واضح از بهترین تمرینها یاد بگیرید وقتی که جاوا اسکریپت می نویسید.</dd> + <dt><a href="http://codeavengers.com/" title="http://codeavengers.com/">CodeAvengers</a> (CodeAvengers.com)</dt> + <dd>Code Avengers یک سرگرمی است، راه مؤثری برای یادگیری کد نرم افزارهای تحت وب و بازیها باHTML، CSS، و JavaScript.</dd> + <dt><a href="http://codecombat.com/#">CodeCombat</a> (codecombat.com)</dt> + <dd>CodeCombat یک بازی است تا به شما جاوا اسکریپت آموزش دهد. منبع باز است.</dd> +</dl> + +<h3 id="سطح_میانی">سطح میانی</h3> + +<dl> + <dt><a href="https://developer.mozilla.org/en-US/docs/A_re-introduction_to_JavaScript">A Re-Introduction to JavaScript</a></dt> + <dd>یک روکش از زبان برنامه نویسی جاوا اسکریپت که به توسعه دهندگان سطح میانی کمک میکند.</dd> + <dt><a href="http://eloquentjavascript.net/contents.html" rel="external">Eloquent JavaScript</a></dt> + <dd>یک راهنمای جامع برای متدولوژیهای پیشرفته و میانی جاوا اسکریپت.</dd> + <dt><a href="http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/" rel="external">Essential JavaScript Design Patterns</a> (Addy Osmani)</dt> + <dd>یک معرفی به اساس الگوهای طراحی جاوا اسکریپت.</dd> + <dt><a href="http://www.yuiblog.com/blog/2007/01/24/video-crockford-tjpl/" rel="external">The JavaScript Programming Language</a> (YUI Blog)</dt> + <dd>Douglas Crockford زبان را مانند چیزی که امروز است کاوش کرده است، و چگونه بهدست میآمد.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/Introduction_to_Object-Oriented_JavaScript">Introduction to Object-Oriented JavaScript</a></dt> + <dd>یادگیری در مورد مدل آبجکتی جاوا اسکریپت.</dd> +</dl> +</div> + +<div class="section"> +<h3 id="سطح_پیشرفته_2">سطح پیشرفته</h3> + +<dl> + <dt><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Guide">JavaScript Guide</a></dt> + <dd>یک راهنمای جامع، بهروز شده منظم از جاوا اسکریپت برای همه سطوح از آموزش از مبتدی تا پیشرفته.</dd> + <dt><a href="http://ejohn.org/apps/learn/" rel="external">Learning Advanced JavaScript</a> (John Resig)</dt> + <dd>راهنمای John Resig برای جاوا اسکریپت پیشرفته.</dd> + <dt><a href="http://www.elated.com/articles/javascript-dom-intro/" rel="external">Introducing the JavaScript DOM</a> (Elated)</dt> + <dd>مدل شیء سند چی است، و چرا مفید است؟ This article gives you a gentle introduction to this powerful JavaScript feature.</dd> + <dt><a href="http://yuiblog.com/blog/2006/10/20/video-crockford-domtheory/" rel="external">An Inconvenient API: The Theory of the DOM</a> (YUI Blog)</dt> + <dd>Douglas Crockford explains the Document Object Model.</dd> + <dt><a href="http://yuiblog.com/blog/2006/11/27/video-crockford-advjs/" rel="external">Advanced JavaScript</a> (YUI Blog)</dt> + <dd>Douglas Crockford looks closely at code patterns from which JavaScript programmers can choose in authoring their applications.</dd> + <dt><a href="http://bonsaiden.github.com/JavaScript-Garden/" rel="external">JavaScript Garden</a></dt> + <dd>Documentation of the most quirky parts of JavaScript.</dd> + <dt><a href="http://webcache.googleusercontent.com/search?q=cache:CJYRO48hw9EJ:stackoverflow.com/questions/394601/which-javascript-framework-jquery-vs-dojo-vs" rel="external">Which JavaScript Framework?</a> (StackOverflow)</dt> + <dd>Advice on choosing a JavaScript framework.</dd> + <dt><a href="http://yuiblog.com/blog/2008/07/22/non-blocking-scripts/" rel="external">Non-Blocking JavaScript Downloads</a> (YUI Blog)</dt> + <dd>Tips on improving the download performance of pages containing JavaScript.</dd> + <dt><a href="http://shichuan.github.io/javascript-patterns" rel="external">Javascipt Patterns</a></dt> + <dd>A JavaScript pattern and antipattern collection that covers function patterns, jQuery patterns, jQuery plugin patterns, design patterns, general patterns, literals and constructor patterns, object creation patterns, code reuse patterns, DOM.</dd> +</dl> + +<h2 class="Documentation" id="Documentation" name="Documentation">CSS tutorials</h2> + +<h3 id="Introductory_level">Introductory level</h3> + +<dl> + <dt><a href="https://developer.mozilla.org/en-US/docs/CSS/Getting_Started">CSS Getting Started</a></dt> + <dd>This tutorial introduces you to Cascading Style Sheets (CSS). It guides you through the basic features of CSS with practical examples that you can try for yourself on your own computer.</dd> + <dt><a href="http://en.wikiversity.org/wiki/Web_Design/CSS_Classes" rel="external">CSS Selector Classes</a> (Wikiversity)</dt> + <dd>What are classes in CSS?</dd> + <dt><a href="http://en.wikiversity.org/wiki/Web_Design/External_CSS" rel="external">External CSS</a> (Wikiversity)</dt> + <dd>Using CSS from an external style sheet.</dd> + <dt><a href="http://www.w3.org/MarkUp/Guide/Style" rel="external">Adding a Touch of Style</a> (W3C)</dt> + <dd>A brief beginner's guide to styling web pages with CSS.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/Common_CSS_Questions">Common CSS Questions</a></dt> + <dd>Common questions and answers for beginners.</dd> + <dt><a href="http://codeavengers.com/" title="http://codeavengers.com/">CodeAvengers</a> (CodeAvengers.com)</dt> + <dd>Code Avengers is the fun, effective way to learn to code web apps and games with HTML, CSS, and JavaScript.</dd> + <dt><a href="http://techstream.org/Web-Design/CSS-selectors" title="http://codeavengers.com/">CSS Selectors</a> (TechStream.org)</dt> + <dd>Quite nice and detailed overview of CSS selectors.</dd> +</dl> + +<h3 id="Intermediate_level">Intermediate level</h3> + +<dl> + <dt><a href="https://developer.mozilla.org/en-US/docs/CSS/CSS_Reference">CSS Reference</a></dt> + <dd>Complete reference to CSS, with details on support by Firefox and other browsers.</dd> + <dt><a href="http://en.wikiversity.org/wiki/Web_Design/CSS_challenges" rel="external">CSS Challenges</a> (Wikiversity)</dt> + <dd>Flex your CSS skills, and see where you need more practice.</dd> + <dt><a href="http://www.html.net/tutorials/css/" rel="external">Intermediate CSS Concepts</a> (HTML.net)</dt> + <dd>Grouping, pseudo-classes, and more.</dd> + <dt><a href="http://www.alistapart.com/articles/css-positioning-101/" rel="external">CSS Positioning 101</a> (A List Apart)</dt> + <dd>Using positioning for standards-compliant, table-free layout.</dd> + <dt><a href="http://www.alistapart.com/articles/progressiveenhancementwithcss/" rel="external">Progressive Enhancement with CSS</a> (A List Apart)</dt> + <dd>Integrate progressive enhancement into your web pages with CSS.</dd> + <dt><a href="http://www.alistapart.com/articles/fluidgrids/" rel="external">Fluid Grids</a> (A List Apart)</dt> + <dd>Design layouts that fluidly resize with the browser window, while still using a typographic grid.</dd> +</dl> + +<h3 id="Advanced_level">Advanced level</h3> + +<dl> + <dt><a href="https://developer.mozilla.org/en-US/docs/CSS/Using_CSS_transforms">Using CSS Transforms</a></dt> + <dd>Apply rotation, skewing, scaling, and translation using CSS.</dd> + <dt><a href="https://developer.mozilla.org/en-US/docs/CSS/CSS_transitions">CSS Transitions</a></dt> + <dd>CSS transitions, part of the draft CSS3 specification, provide a way to animate changes to CSS properties, instead of having the changes take effect instantly.</dd> + <dt><a href="http://www.html5rocks.com/tutorials/webfonts/quick/" rel="external">Quick Guide to Implement Web Fonts with @font-face</a> (HTML5 Rocks)</dt> + <dd>The @font-face feature from CSS3 allows you to use custom typefaces on the web in an accessible, manipulatable, and scalable way.</dd> + <dt><a href="http://davidwalsh.name/starting-css" rel="external">Starting to Write CSS</a> (David Walsh)</dt> + <dd>An introduction to tools and methodologies to write more succinct, maintainable, and scalable CSS.</dd> +</dl> +</div> +</div> + +<p dir="rtl"> </p> diff --git a/files/fa/web/جاوااسکریپت/index.html b/files/fa/web/جاوااسکریپت/index.html new file mode 100644 index 0000000000..1de3deb24e --- /dev/null +++ b/files/fa/web/جاوااسکریپت/index.html @@ -0,0 +1,129 @@ +--- +title: جاوااسکریپت +slug: Web/جاوااسکریپت +tags: + - JavaScript + - Landing + - NeedsTranslation + - TopicStub +--- +<div class="callout-box"><strong><a href="/fa/docs/Web/JavaScript/A_re-introduction_to_JavaScript">یک معرفی مجدد برای جاوااسکریپت</a></strong><br> +یک بررسی کلی برا آنهایی که <em>فکر میکنند</em> در مورد جاوااسکریپت میدانند</div> + +<p dir="rtl">{{JsSidebar}}</p> + +<p dir="rtl"><strong>JavaScript</strong><sup>®</sup> (اغلب به <strong>JS</strong> مخفف میشود) سبک، مفسر، زبان شیگرا شده با <a href="https://en.wikipedia.org/wiki/First-class_functions" title="https://en.wikipedia.org/wiki/First-class_functions">first-class functions</a>، به عنوان زبان اسکریپت نویسی برای صفحات وب شناخته شده است، اما <a class="external" href="http://en.wikipedia.org/wiki/JavaScript#Uses_outside_web_pages">در خیلی از محیطهای غیر مرورگری</a> مانند <a class="external" href="http://nodejs.org/">node.js</a> یا <a href="http://couchdb.apache.org">Apache CouchDB</a> نیز استفاده شده است. زبان اسکریت نویسی آن <a class="mw-redirect" href="https://en.wikipedia.org/wiki/Prototype-based" title="Prototype-based">مبتنی بر نمونه</a> است، <a href="/en-US/docs/multiparadigmlanguage.html" title="/en-US/docs/multiparadigmlanguage.html">چند نمونه</a> که پویا است،<span style="color: rgb(102, 102, 102); line-height: 21px;"> </span><a href="https://en.wikipedia.org/wiki/Type_safety" style="line-height: 21px;" title="Type safety">نوع امن</a><span style="line-height: 1.572;"> و از شی گرایی پشتیبانی میکند، سبک های برنامه نویسی تابعی را دارد. اطلاعات بیشتر را میتوانید از صفحه <a href="/fa/docs/docs/Web/JavaScript/About_JavaScript">درباره جاوااسکریپت</a></span><span style="line-height: 1.572;"> مشاهده نمایید.</span></p> + +<p dir="rtl">استاندارد جاوااسکریپت <a href="/fa/docs/JavaScript/Language_Resources">اکمااسکریپت</a> (<a href="/fa/docs/JavaScript/Language_Resources">ECMAScript</a>) است که از سال ۲۰۱۲ تمامی مرورگرهای مدرن استاندارد اکمااسکریپت نسخه ۵.۱ را به صورت کامل پشتیبانی میکنند، همچنین مرورگرهای قدیمیتر نسخه ۳ از اکمااسکریپت را پشتیبانی میکنند. از ماه June سال ۲۰۱۵ اکمااسکریپت ۶ (ES6) یا همان اکمااسکریپت ۲۰۱۵ (ES2015) مورد قبول واقع شده است. توضیحات تکمیلی در مورد اکمااسکریپت ۶ را می توانید در <a class="external" href="http://wiki.ecmascript.org/doku.php?id=harmony:proposals">dedicated wiki</a> مشاهده نمایید.</p> + +<p dir="rtl">این بخش از سایت به زبان جاوااسکریپت اختصاص داده شده است، قسمتهایی که مختص به صفحات وب، یا دیگر محیطهای میزبانی نیست. برای اطلاعات در مورد APIهای خاص برای صفحات وب، لطفا <a href="/fa/docs/DOM">DOM</a> را ببینید. در مورد اینکه چگونه DOM وJavaScript با همدیگر مناسب هستند در <a href="/fa/docs/Gecko_DOM_Reference/Introduction#DOM_and_JavaScript">مرجع DOM</a> اطلاعات بیشتری را بخوانید.</p> + +<p dir="rtl">JavaScript به صورت <strong>«جاواسکریپت»</strong> خوانده میشود، ولی در فارسی به صورت <strong>«جاوااسکریپت»</strong> ترجمه میشود و اگر به صورت «جاوا اسکریپت» ترجمه شود اشتباه است چون دو کلمه جدا از هم نیست و اگر به صورت دو کلمه جدا نوشته شود خطلاهای نگارشی ایجاد میشود، به طور مثال ممکن است کلمه جاوا در انتهای خط و کلمه اسکریپت در ابتدای خط بعدی نوشته شود.</p> + +<div class="row topicpage-table" dir="rtl"> +<div class="section"> +<h2 class="Documentation" id="مستندات">مستندات</h2> + +<dl> + <dt><a href="/fa/docs/Web/JavaScript/Guide">راهنمای جاوااسکریپت</a></dt> + <dd>اگر شما در جاوااسکریپت تازهکار هستید، باید این راهنما را بخوانید.</dd> + <dt><a href="/fa/docs/Web/JavaScript/Reference">مرجع جاوااسکریپت</a></dt> + <dd>این مرجع جاوااسکریپت شامل مستندات کاملی برای جاوااسکریپت نسخه ۱.۵ و بهروزرسانیهای آن است.</dd> +</dl> + +<h3 id="مقالات_معرفی">مقالات معرفی</h3> + +<dl> + <dt><a href="/fa/docs/Web/JavaScript/JavaScript_technologies_overview">نمای کلی تکنولوژیهای جاوااسکریپت</a></dt> + <dd>آشنایی با چشم انداز جاوااسکریپت برای مرورگر</dd> +</dl> + +<h3 id="مقالات_پیشرفته">مقالات پیشرفته</h3> + +<dl> + <dt><a href="/fa/docs/Web/JavaScript/Data_structures">ساختارهای دادهای جاوااسکریپت</a></dt> + <dd>نمای کلی ساختارهای دادهای قابل دسترس در جاپااسکریپت</dd> + <dt><a href="/fa/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain">وراثت و زنجیره نمونه</a></dt> + <dd>توضیح ارثبری مبتنی بر نمونه که بهصورت گستردهای اشتباده و ناچیز شمرده شده است</dd> +</dl> + +<h3 id="مقالات_دیگر">مقالات دیگر</h3> + +<dl> + <dt><a href="/fa/docs/Web/Guide/HTML/Canvas_tutorial">آموزش بوم نقاشی</a></dt> + <dd><canvas> یک المان HTML5 است که برای رسم گرافیکها با استفاده از اسکریپت نویسی استفاده میشود. آن میتواند، برای مثال برای رسم گرافیکها، ترکیب عکس و یا انجام ساده (و نه خیلی ساده) انیمیشنها استفاده شود.</dd> + <dt><a href="/fa/docs/Web/JavaScript/Language_Resources">مراجع زبان جاوااسکریپت</a></dt> + <dd>شرح زبان جاوااسکریپت استاندارد.</dd> + <dt><a class="external" href="http://msdn.microsoft.com/en-us/library/ff405926.aspx">مستندات پشتیبانی استانداردهای اینترنت اکسپلورر</a></dt> + <dd>مایکروسافت مستنداتی منتشر کرده است که "تغییرات، توضیحات، و الحاقیات برخی استانداردهای مورد تایید پشتیبانی شده توسط اینترنت اکسپلورر." را شرح میدهد، بعضی از آنها مربوط به جاوااسکریپت هستند:</dd> + <dd> + <ul> + <li><a class="external" href="http://msdn.microsoft.com/en-us/library/ff520996.aspx">[MS-ES3]: Internet Explorer ECMA-262 ECMAScript Language Specification Standards Support Document </a></li> + <li><a class="external" href="http://msdn.microsoft.com/en-us/library/ff521046.aspx">[MS-ES3EX]: Microsoft JScript Extensions to the ECMAScript Language Specification Third Edition </a></li> + <li><a class="external" href="http://msdn.microsoft.com/en-us/library/ff960769.aspx">[MS-ES5]: Internet Explorer ECMA-262 ECMAScript Language Specification (Fifth Edition) Standards Support Document </a></li> + <li><a class="external" href="http://msdn.microsoft.com/en-us/library/ff955363.aspx">[MS-ES5EX]: Internet Explorer Extensions to the ECMA-262 ECMAScript Language Specification (Fifth Edition)</a></li> + </ul> + </dd> +</dl> + +<p><span class="alllinks"><a href="/en-US/docs/tag/JavaScript">View All...</a></span></p> +</div> + +<div class="section"> +<h2 class="Tools" id="ابزارها_منابع_پیشرفته">ابزارها & منابع پیشرفته</h2> + +<ul> + <li><a href="/fa/docs/Tools">ابزارهای توسعه فایرفاکس</a> - ابزارهای عالی تعبیه شده در فایرفاکس.</li> + <li><a href="http://koding.com">Koding</a> پلت فرم توسعه آنلاین با پشتیبانی جاوااسکریپت</li> + <li><a href="http://www.learnstreet.com/">LearnStreet</a> - آموزشها و تمرینهای عملی رایگان آنلاین.</li> + <li><a href="http://www.codecademy.com/">Codecademy</a> - دوره جاوااسکریپت رایگان با مشکلات تعاملی</li> + <li><a href="http://codeschool.com">Code School </a>- یادگیری بوسیله انجام دادن، چندین دوره جاو.ا اسکریپت</li> + <li><a href="http://frontendmasters.com/" title="http://frontendmasters.com/">Frontend Masters</a> - فیلمهای کارگاه آموزشی جاوااسکریپت و توسعه وب نهایی</li> + <li><a href="http://www.letscodejavascript.com/" title="http://www.letscodejavascript.com/">Let’s Code: Test-Driven JavaScript</a> - سریهای ضبط خیلی دقیق صفحه، توسعه حرفهای جاوااسکریپت</li> + <li><a class="link-https" href="https://github.com/rwldrn/idiomatic.js">Idiomatic.js</a> - اصول نوشتن جاوااسکریپت استوار، اصطلاحی</li> + <li><a href="/en-US/docs/JavaScript/Memory_Management">Memory Management in JavaScript</a> . نمای کلی از چگونگی عملکرد حافظه در جاوااسکریپت</li> + <li><a class="external" href="http://www.getfirebug.com/">Firebug</a> - اشکالزدایی و پروفایلینگ جاوااسکریپت</li> + <li><a href="/en-US/docs/Venkman">Venkman</a> - دیباگر جاوااسکریپت</li> + <li><a href="/en-US/docs/JavaScript/Shells">JavaScript Shells</a> - تست قطعه کدهای کوچک</li> + <li><a class="external" href="http://jshint.com">JSHint</a> - ابزاری که در تشخیص خطا و مشکلات بالقوه در کد جاوااسکریپت شما کمک میکند</li> + <li><a class="external" href="http://www.jslint.com/lint.html">JSLint</a> - چک کننده نحو، در برابر اعمال بد هشدار میدهد</li> + <li><a class="external" href="http://usejsdoc.org/">JSDoc</a> - تولید مستندات از کد</li> + <li><a class="external" href="http://online-marketing-technologies.com/tools/javascript-redirection-generator.html" title="JavaScript Redirect">JavaScript Redirect</a> - ابزار تغییر مسیر پیشرفته جاوااسکریپت</li> + <li><a class="external" href="http://www.aptana.com">Aptana Studio</a> - <span id="result_box" lang="fa"><span class="hps">IDE</span> <span class="hps">متن باز</span> <span class="hps">با</span> پشتیبانی <span class="hps">آژاکس</span> <span class="hps">و</span> <span class="hps">جاوااسکریپت</span> <span class="atn hps">(</span><span>بر اساس</span> eclipse<span>)</span></span></li> + <li><a class="external" href="http://netbeans.org/features/javascript/">Netbeans</a> - IDE متن باز شامل پشتیبانی پیچیده از جاوااسکریپت</li> + <li><a class="external" href="http://www.eclipse.org/downloads/packages/eclipse-ide-javascript-web-developers/heliossr1">Eclipse</a> - IDE متن باز شامل جعبه ابزار توسعه جاوااسکریپت</li> + <li><a class="external" href="http://www.c9.io">Cloud9 IDE</a> - IDE متن باز که در مرورگر اجرا شده با قابلیت پشتیبانی از جاوااسکریپت و Node.js</li> + <li><a class="external" href="http://prettydiff.com/">Pretty Diff </a>- یک ابزار متفاوت برای مقایسه کد خرد شده با کد معمولی</li> + <li><a href="http://www.objectplayground.com/" title="http://www.objectplayground.com/">Object Playground</a> - ابزاری برای درک شیگرایی جاوااسکریپت</li> + <li><a class="link-https" href="https://addons.mozilla.org/en-US/firefox/addon/7434">Extension Developer's Extension</a> - محیط و شل JS را ارایه میدهد</li> + <li><a href="http://boilerplatejs.org/">BoilerplateJS</a> - مرجع معماری برای پروژههای جاوااسکریپت در مقیاس بزرگ</li> + <li><a href="http://www.jsfiddle.net/">JSFiddle</a> - مورد استفاده برای آزمایش و اصلاح وب سایت با جاوااسکریپت آنلاین. </li> + <li><a href="/fa/docs/JavaScript/Other_JavaScript_tools">دیگر ابزارهای جاوااسکریپت</a></li> +</ul> + +<p><span class="alllinks"><a href="/en-US/docs/tag/JavaScript:Tools">نمایش همه...</a></span></p> + +<h2 class="Community" id="Other resources" name="Other resources">دیگر منابع</h2> + +<dl> + <dt><a class="external" href="http://bonsaiden.github.com/JavaScript-Garden">JavaScript Garden</a></dt> + <dd>سایتی با اطلاعات مفید در مورد قطعات داخلیتر جاوااسکریپت.</dd> + <dt><a class="link-https" href="https://github.com/bebraw/jswiki/wiki">JSWiki</a></dt> + <dd>یک ویکی مبتنی بر Githubکه منابع و کتابخانهها را ایندکس گذاری کرده است.</dd> + <dt><a href="http://stackoverflow.com/questions/tagged/javascript">Stack Overflow</a></dt> + <dd>یک سایت همکاری ساخته و نگهداری شده Q&A و میتوانید برای جواب سوال خودرا در آن جستجو کنید. اگر جواب سوال خودرا پیدا نکردید میتوانید سوال خودرا در آنجا مطرح کنید.</dd> + <dt><a href="http://pineapple.io/resources/tagged/javascript?type=tutorials&sort=all_time">Pineapple · JavaScript</a></dt> + <dd>یک پایگاه داده بزرگ از آموزش و منابع حال حاضر جاوااسکریپت.</dd> + <dt><a href="http://lifeofjs.com">Life of JavaScript</a></dt> + <dd>منابع عالی در مورد جاوااسکریپت شامل کتاب، ارایهها، فیلمها، فیدها، سایتها، کتابخانهها، محیطهای کاری، ابزارها که در یکجا جمع آموری شده است.</dd> +</dl> + +<h2 class="Related_Topics" id="Related_Topics" name="Related_Topics">موضوعات مرتبط</h2> + +<ul> + <li><a href="/fa/docs/AJAX">AJAX</a>, <a href="/fa/docs/DOM">DOM</a>, <a class="internal" href="/fa/docs/JavaScript/Server-Side_JavaScript">Server-Side JavaScript</a>, <a href="/fa/docs/DHTML">DHTML</a>, <a href="/fa/docs/Mozilla/Projects/SpiderMonkey">SpiderMonkey</a>, <a href="/fa/docs/HTML/Canvas">Canvas</a>, <a href="/fa/docs/JavaScript/JQuery">JQuery</a></li> +</ul> +</div> +</div> + +<p dir="rtl" lang="en-US">*JavaScript is a trademark or registered trademark of Oracle in the U.S. and other countries.</p> |