This file is a concatenation of [Learn X in Y minutes](https://github.com/adambard/learnxinyminutes-docs) for testing purposes. It is published under the original project license ([Creative Commons Attribution-ShareAlike 3.0 Unported](http://creativecommons.org/licenses/by-sa/3.0/deed.en_US)). ------ category: tool tool: amd contributors: - ["Frederik Ring", "https://github.com/m90"] filename: learnamd.js --- ## Getting Started with AMD The **Asynchronous Module Definition** API specifies a mechanism for defining JavaScript modules such that the module and its dependencies can be asynchronously loaded. This is particularly well suited for the browser environment where synchronous loading of modules incurs performance, usability, debugging, and cross-domain access problems. ### Basic concept ```javascript // The basic AMD API consists of nothing but two methods: `define` and `require` // and is all about module definition and consumption: // `define(id?, dependencies?, factory)` defines a module // `require(dependencies, callback)` imports a set of dependencies and // consumes them in the passed callback // Let's start by using define to define a new named module // that has no dependencies. We'll do so by passing a name // and a factory function to define: define('awesomeAMD', function(){ var isAMDAwesome = function(){ return true; }; // The return value of a module's factory function is // what other modules or require calls will receive when // requiring our `awesomeAMD` module. // The exported value can be anything, (constructor) functions, // objects, primitives, even undefined (although that won't help too much). return isAMDAwesome; }); // Now, let's define another module that depends upon our `awesomeAMD` module. // Notice that there's an additional argument defining our // module's dependencies now: define('loudmouth', ['awesomeAMD'], function(awesomeAMD){ // dependencies will be passed to the factory's arguments // in the order they are specified var tellEveryone = function(){ if (awesomeAMD()){ alert('This is sOoOo rad!'); } else { alert('Pretty dull, isn\'t it?'); } }; return tellEveryone; }); // As we do know how to use define now, let's use `require` to // kick off our program. `require`'s signature is `(arrayOfDependencies, callback)`. require(['loudmouth'], function(loudmouth){ loudmouth(); }); // To make this tutorial run code, let's implement a very basic // (non-asynchronous) version of AMD right here on the spot: function define(name, deps, factory){ // notice how modules without dependencies are handled define[name] = require(factory ? deps : [], factory || deps); } function require(deps, callback){ var args = []; // first let's retrieve all the dependencies needed // by the require call for (var i = 0; i < deps.length; i++){ args[i] = define[deps[i]]; } // satisfy all the callback's dependencies return callback.apply(null, args); } // you can see this code in action here: http://jsfiddle.net/qap949pd/ ``` ### Real-world usage with require.js In contrast to the introductory example, `require.js` (the most popular AMD library) actually implements the **A** in **AMD**, enabling you to load modules and their dependencies asynchronously via XHR: ```javascript /* file: app/main.js */ require(['modules/someClass'], function(SomeClass){ // the callback is deferred until the dependency is loaded var thing = new SomeClass(); }); console.log('So here we are, waiting!'); // this will run first ``` By convention, you usually store one module in one file. `require.js` can resolve module names based on file paths, so you don't have to name your modules, but can simply reference them using their location. In the example `someClass` is assumed to be in the `modules` folder, relative to your configuration's `baseUrl`: * app/ * main.js * modules/ * someClass.js * someHelpers.js * ... * daos/ * things.js * ... This means we can define `someClass` without specifying a module id: ```javascript /* file: app/modules/someClass.js */ define(['daos/things', 'modules/someHelpers'], function(thingsDao, helpers){ // module definition, of course, will also happen asynchronously function SomeClass(){ this.method = function(){/**/}; // ... } return SomeClass; }); ``` To alter the default path mapping behavior use `requirejs.config(configObj)` in your `main.js`: ```javascript /* file: main.js */ requirejs.config({ baseUrl : 'app', paths : { // you can also load modules from other locations jquery : '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min', coolLibFromBower : '../bower_components/cool-lib/coollib' } }); require(['jquery', 'coolLibFromBower', 'modules/someHelpers'], function($, coolLib, helpers){ // a `main` file needs to call require at least once, // otherwise no code will ever run coolLib.doFancyStuffWith(helpers.transform($('#foo'))); }); ``` `require.js`-based apps will usually have a single entry point (`main.js`) that is passed to the `require.js` script tag as a data-attribute. It will be automatically loaded and executed on pageload: ```html A hundred script tags? Never again! ``` ### Optimizing a whole project using r.js Many people prefer using AMD for sane code organization during development, but still want to ship a single script file in production instead of performing hundreds of XHRs on page load. `require.js` comes with a script called `r.js` (that you will probably run in node.js, although Rhino is supported too) that can analyse your project's dependency graph, and build a single file containing all your modules (properly named), minified and ready for consumption. Install it using `npm`: ```shell $ npm install requirejs -g ``` Now you can feed it with a configuration file: ```shell $ r.js -o app.build.js ``` For our above example the configuration might look like: ```javascript /* file : app.build.js */ ({ name : 'main', // name of the entry point out : 'main-built.js', // name of the file to write the output to baseUrl : 'app', paths : { // `empty:` tells r.js that this should still be loaded from the CDN, using // the location specified in `main.js` jquery : 'empty:', coolLibFromBower : '../bower_components/cool-lib/coollib' } }) ``` To use the built file in production, simply swap `data-main`: ```html ``` An incredibly detailed [overview of build options](https://github.com/jrburke/r.js/blob/master/build/example.build.js) is available in the GitHub repo. ### Topics not covered in this tutorial * [Loader plugins / transforms](http://requirejs.org/docs/plugins.html) * [CommonJS style loading and exporting](http://requirejs.org/docs/commonjs.html) * [Advanced configuration](http://requirejs.org/docs/api.html#config) * [Shim configuration (loading non-AMD modules)](http://requirejs.org/docs/api.html#config-shim) * [CSS loading and optimizing with require.js](http://requirejs.org/docs/optimization.html#onecss) * [Using almond.js for builds](https://github.com/jrburke/almond) ### Further reading: * [Official Spec](https://github.com/amdjs/amdjs-api/wiki/AMD) * [Why AMD?](http://requirejs.org/docs/whyamd.html) * [Universal Module Definition](https://github.com/umdjs/umd) ### Implementations: * [require.js](http://requirejs.org) * [dojo toolkit](http://dojotoolkit.org/documentation/tutorials/1.9/modules/) * [cujo.js](http://cujojs.com/) * [curl.js](https://github.com/cujojs/curl) * [lsjs](https://github.com/zazl/lsjs) * [mmd](https://github.com/alexlawrence/mmd) --- category: tool tool: AngularJS contributors: - ["Walter Cordero", "http://waltercordero.com"] filename: learnangular.html --- ## AngularJS Tutorial. AngularJS version 1.0 was released in 2012. Miško Hevery, a Google employee, started to work with AngularJS in 2009. The idea turned out very well, and the project is now officially supported by Google. AngularJS is a JavaScript framework. It can be added to an HTML page with a "script" tag. AngularJS extends HTML attributes with Directives, and binds data to HTML with Expressions. ##What You Should Already Know Before you study AngularJS, you should have a basic understanding of: - HTML - CSS - JavaScript ```html // AngularJS is a JavaScript framework. It is a library written in JavaScript. // AngularJS is distributed as a JavaScript file, and can be added to a web page with a script tag: // /////////////////////////////////// // AngularJS Extends HTML //AngularJS extends HTML with ng-directives. //The ng-app directive defines an AngularJS application. //The ng-model directive binds the value of HTML controls (input, select, textarea) to application data. //The ng-bind directive binds application data to the HTML view.

Name:

/* * Example explained: * AngularJS starts automatically when the web page has loaded. * The ng-app directive tells AngularJS that the
element is the "owner" of an AngularJS application. * The ng-model directive binds the value of the input field to the application variable name. * The ng-bind directive binds the innerHTML of the

element to the application variable name. */ Here are content to be interpreted /////////////////////////////////// // AngularJS Expressions // AngularJS expressions are written inside double braces: {{ expression }}. // AngularJS expressions binds data to HTML the same way as the ng-bind directive. // AngularJS will "output" data exactly where the expression is written. // AngularJS expressions are much like JavaScript expressions: They can contain literals, operators, and variables. // Example {{ 5 + 5 }} or {{ firstName + " " + lastName }}

My first expression: {{ 5 + 5 }}

//If you remove the ng-app directive, HTML will display the expression as it is, without solving it:

My first expression: {{ 5 + 5 }}

// AngularJS expressions bind AngularJS data to HTML the same way as the ng-bind directive.

Name:

{{name}}

// AngularJS numbers are like JavaScript numbers:

Total in dollar: {{ quantity * cost }}

//AngularJS strings are like JavaScript strings:

The name is

//AngularJS objects are like JavaScript objects:

The name is {{ person.lastName }}

//AngularJS arrays are like JavaScript arrays:

The third result is {{ points[2] }}

// Like JavaScript expressions, AngularJS expressions can contain literals, operators, and variables. // Unlike JavaScript expressions, AngularJS expressions can be written inside HTML. // AngularJS expressions do not support conditionals, loops, and exceptions, while JavaScript expressions do. // AngularJS expressions support filters, while JavaScript expressions do not. /////////////////////////////////// // AngularJS Directives //AngularJS directives are extended HTML attributes with the prefix ng-. //The ng-app directive initializes an AngularJS application. //The ng-init directive initializes application data. //The ng-model directive binds the value of HTML controls (input, select, textarea) to application data.

Name:

You wrote: {{ firstName }}

//Using ng-init is not very common. You will learn how to initialize data in the chapter about controllers. //The ng-repeat directive repeats an HTML element:
//The ng-repeat directive used on an array of objects:
// AngularJS is perfect for database CRUD (Create Read Update Delete) applications. // Just imagine if these objects were records from a database. // The ng-app directive defines the root element of an AngularJS application. // The ng-app directive will auto-bootstrap (automatically initialize) the application when a web page is loaded. // Later you will learn how ng-app can have a value (like ng-app="myModule"), to connect code modules. // The ng-init directive defines initial values for an AngularJS application. // Normally, you will not use ng-init. You will use a controller or module instead. // You will learn more about controllers and modules later. //The ng-model directive binds the value of HTML controls (input, select, textarea) to application data. //The ng-model directive can also: //Provide type validation for application data (number, email, required). //Provide status for application data (invalid, dirty, touched, error). //Provide CSS classes for HTML elements. //Bind HTML elements to HTML forms. //The ng-repeat directive clones HTML elements once for each item in a collection (in an array). /////////////////////////////////// // AngularJS Controllers // AngularJS controllers control the data of AngularJS applications. // AngularJS controllers are regular JavaScript Objects. // AngularJS applications are controlled by controllers. // The ng-controller directive defines the application controller. // A controller is a JavaScript Object, created by a standard JavaScript object constructor.
First Name:
Last Name:

Full Name: {{firstName + " " + lastName}}
//Application explained: //The AngularJS application is defined by ng-app="myApp". The application runs inside the
. //The ng-controller="myCtrl" attribute is an AngularJS directive. It defines a controller. //The myCtrl function is a JavaScript function. //AngularJS will invoke the controller with a $scope object. //In AngularJS, $scope is the application object (the owner of application variables and functions). //The controller creates two properties (variables) in the scope (firstName and lastName). //The ng-model directives bind the input fields to the controller properties (firstName and lastName). //The example above demonstrated a controller object with two properties: lastName and firstName. //A controller can also have methods (variables as functions):
First Name:
Last Name:

Full Name: {{fullName()}}
//In larger applications, it is common to store controllers in external files. //Just copy the code between the tags into an external file named personController.js:
First Name:
Last Name:

Full Name: {{firstName + " " + lastName}}
// For the next example we will create a new controller file: angular.module('myApp', []).controller('namesCtrl', function($scope) { $scope.names = [ {name:'Jani',country:'Norway'}, {name:'Hege',country:'Sweden'}, {name:'Kai',country:'Denmark'} ]; }); //Save the file as namesController.js: //And then use the controller file in an application:
  • {{ x.name + ', ' + x.country }}
/////////////////////////////////// // AngularJS Filters // Filters can be added to expressions and directives using a pipe character. // AngularJS filters can be used to transform data: - **currency**: Format a number to a currency format. - **filter**: Select a subset of items from an array. - **lowercase**: Format a string to lower case. - **orderBy**: Orders an array by an expression. - **uppercase**: Format a string to upper case. //A filter can be added to an expression with a pipe character (|) and a filter. //(For the next two examples we will use the person controller from the previous chapter) //The uppercase filter format strings to upper case:

The name is {{ lastName | uppercase }}

//The lowercase filter format strings to lower case:

The name is {{ lastName | lowercase }}

//The currency filter formats a number as currency:

Total = {{ (quantity * price) | currency }}

//A filter can be added to a directive with a pipe character (|) and a filter. //The orderBy filter orders an array by an expression:
  • {{ x.name + ', ' + x.country }}
//An input filter can be added to a directive with a pipe character (|) //and filter followed by a colon and a model name. //The filter selects a subset of an array:

  • {{ (x.name | uppercase) + ', ' + x.country }}
/////////////////////////////////// // AngularJS AJAX - $http //$http is an AngularJS service for reading data from remote servers. // The following data can be provided by a web server: // http://www.w3schools.com/angular/customers.php // **Check the URL to see the data format** // AngularJS $http is a core service for reading data from web servers. // $http.get(url) is the function to use for reading server data.
  • {{ x.Name + ', ' + x.Country }}
Application explained: // The AngularJS application is defined by ng-app. The application runs inside a
. // The ng-controller directive names the controller object. // The customersCtrl function is a standard JavaScript object constructor. // AngularJS will invoke customersCtrl with a $scope and $http object. // $scope is the application object (the owner of application variables and functions). // $http is an XMLHttpRequest object for requesting external data. // $http.get() reads JSON data from http://www.w3schools.com/angular/customers.php. // If success, the controller creates a property (names) in the scope, with JSON data from the server. // Requests for data from a different server (than the requesting page), are called cross-site HTTP requests. // Cross-site requests are common on the web. Many pages load CSS, images, and scripts from different servers. // In modern browsers, cross-site HTTP requests from scripts are restricted to same site for security reasons. // The following line, in our PHP examples, has been added to allow cross-site access. header("Access-Control-Allow-Origin: *"); /////////////////////////////////// // AngularJS Tables // Displaying tables with angular is very simple:
{{ x.Name }} {{ x.Country }}
// To sort the table, add an orderBy filter:
{{ x.Name }} {{ x.Country }}
// To display the table index, add a with $index:
{{ $index + 1 }} {{ x.Name }} {{ x.Country }}
// Using $even and $odd
{{ x.Name }} {{ x.Name }} {{ x.Country }} {{ x.Country }}
/////////////////////////////////// // AngularJS HTML DOM //AngularJS has directives for binding application data to the attributes of HTML DOM elements. // The ng-disabled directive binds AngularJS application data to the disabled attribute of HTML elements.

Button

//Application explained: // The ng-disabled directive binds the application data mySwitch to the HTML button's disabled attribute. // The ng-model directive binds the value of the HTML checkbox element to the value of mySwitch. // If the value of mySwitch evaluates to true, the button will be disabled:

// If the value of mySwitch evaluates to false, the button will not be disabled:

// The ng-show directive shows or hides an HTML element.

I am visible.

I am not visible.

// The ng-show directive shows (or hides) an HTML element based on the value of ng-show. // You can use any expression that evaluates to true or false:

I am visible.

/////////////////////////////////// // AngularJS Events // AngularJS has its own HTML events directives. // The ng-click directive defines an AngularJS click event.

{{ count }}

// The ng-hide directive can be used to set the visibility of a part of an application. // The value ng-hide="true" makes an HTML element invisible. // The value ng-hide="false" makes the element visible.

First Name:
Last Name:

Full Name: {{firstName + " " + lastName}}

//Application explained: // The first part of the personController is the same as in the chapter about controllers. // The application has a default property (a variable): $scope.myVar = false; // The ng-hide directive sets the visibility, of a

element with two input fields, // according to the value (true or false) of myVar. // The function toggle() toggles myVar between true and false. // The value ng-hide="true" makes the element invisible. // The ng-show directive can also be used to set the visibility of a part of an application. // The value ng-show="false" makes an HTML element invisible. // The value ng-show="true" makes the element visible. // Here is the same example as above, using ng-show instead of ng-hide:

First Name:
Last Name:

Full Name: {{firstName + " " + lastName}}

/////////////////////////////////// // AngularJS Modules // An AngularJS module defines an application. // The module is a container for the different parts of an application. // The module is a container for the application controllers. // Controllers always belong to a module. // This application ("myApp") has one controller ("myCtrl"):
{{ firstName + " " + lastName }}
// It is common in AngularJS applications to put the module and the controllers in JavaScript files. // In this example, "myApp.js" contains an application module definition, while "myCtrl.js" contains the controller:
{{ firstName + " " + lastName }}
//myApp.js var app = angular.module("myApp", []); // The [] parameter in the module definition can be used to define dependent modules. // myCtrl.js app.controller("myCtrl", function($scope) { $scope.firstName = "John"; $scope.lastName= "Doe"; }); // Global functions should be avoided in JavaScript. They can easily be overwritten // or destroyed by other scripts. // AngularJS modules reduces this problem, by keeping all functions local to the module. // While it is common in HTML applications to place scripts at the end of the // element, it is recommended that you load the AngularJS library either // in the or at the start of the . // This is because calls to angular.module can only be compiled after the library has been loaded.
{{ firstName + " " + lastName }}
/////////////////////////////////// // AngularJS Applications // AngularJS modules define AngularJS applications. // AngularJS controllers control AngularJS applications. // The ng-app directive defines the application, the ng-controller directive defines the controller.
First Name:
Last Name:

Full Name: {{firstName + " " + lastName}}
// AngularJS modules define applications: var app = angular.module('myApp', []); // AngularJS controllers control applications: app.controller('myCtrl', function($scope) { $scope.firstName= "John"; $scope.lastName= "Doe"; }); ``` ## Source & References **Examples** - [http://www.w3schools.com/angular/angular_examples.asp](http://www.w3schools.com/angular/angular_examples.asp) **References** - [http://www.w3schools.com/angular/angular_ref_directives.asp](http://www.w3schools.com/angular/angular_ref_directives.asp) - [http://www.w3schools.com/angular/default.asp](http://www.w3schools.com/angular/default.asp) - [https://teamtreehouse.com/library/angular-basics/](https://teamtreehouse.com/library/angular-basics/) --- language: html lang: ar-ar filename: learnhtml-tf.html contributors: - ["Christophe THOMAS", "https://github.com/WinChris"] translators: - ["Ader", "https://github.com/y1n0"] --- HTML اختصار ل HyperText Markup Language، أي "لغة ترميز النص التشعبي". هي لغة تمكننا من كتابة صفحات موجهة لشبكة الويب العالمي. هي لغة توصيف للنص، تسمح بكتابة صفحات ويب عن طريق تحديد كيفية عرض النصوص والمعلومات. في الحقيقة، ملفات html هي ملفات تحتوي على نصوص بسيطة. ما هو توصيف النص هذا؟ هو طريقة لتنظيم معلومات النص عن طريق إحاطته بوُسوم فتح ووسوم غلق. هذه الوسوم تعطي معاني محددة للنص الذي تحيطه. كباقي لغات الحاسوب، هناك الكثير من إصدارات HTML. سنتحدث هنا عن HTLM5. **ملاحظة:** يمكنك تجريب مختلف الوسوم والعناصر بينما تقرأ الدرس عبر موقع كـ [codepen](http://codepen.io/pen/) حتى ترى تأثيرها وتعرف كيف تعمل وتتعود على استعمالها. هذه المادة تُعنى أساسا بتركيب HTML .وبعض النصائح المفيدة ```html موقعي

مرحبا بالعالم!

الق نظرة كيف يبدو هذا من هنا

هذه فقرة.

هذه فقرة أخرى.

  • هذا عنصر من لائحة غير مرقمة. (لائحة بالعرائض)
  • هذا عنصر آخر
  • وهذا آخر عنصر في اللائحة