<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AJavaScript_usage_guide</id>
	<title>Development:JavaScript usage guide - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AJavaScript_usage_guide"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:JavaScript_usage_guide&amp;action=history"/>
	<updated>2026-05-07T18:26:51Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:JavaScript_usage_guide&amp;diff=11272&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:JavaScript_usage_guide&amp;diff=11272&amp;oldid=prev"/>
		<updated>2024-10-21T08:51:22Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:51, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:JavaScript_usage_guide&amp;diff=11271&amp;oldid=prev</id>
		<title>1&gt;Skodak: /* Links */</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:JavaScript_usage_guide&amp;diff=11271&amp;oldid=prev"/>
		<updated>2010-01-27T15:55:21Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Links&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Work in progress}}&lt;br /&gt;
{{Infobox Project&lt;br /&gt;
|name = Javascript usage guide&lt;br /&gt;
|state = Work in progress&lt;br /&gt;
|tracker = MDL-21240&lt;br /&gt;
|discussion = n/a, developer chat only&lt;br /&gt;
|assignee = [[User:Petr Škoda (škoďák)|Petr Škoda (škoďák)]] + feedback and ideas from Sam and Dongsheng, based on previous work of Nicolas and Tim&lt;br /&gt;
}}&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Goals=&lt;br /&gt;
* standardise usage of Javascript code in Moodle&lt;br /&gt;
* improve performance&lt;br /&gt;
* improve and simplify JS related APIs&lt;br /&gt;
&lt;br /&gt;
=API overview=&lt;br /&gt;
&lt;br /&gt;
Types of JS code in 1.9:&lt;br /&gt;
* JS scripts linked from page head&lt;br /&gt;
* JS linked and executed from page head&lt;br /&gt;
* inline Javascript&lt;br /&gt;
* global JS variables&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Overview of JavaScript usage in 2.0&lt;br /&gt;
* all JS stored in one global M namespace&lt;br /&gt;
* majority of JS logic moved into page footer&lt;br /&gt;
* loading of javascript modules handled by YUI3 loader&lt;br /&gt;
* all plugins support module.js files&lt;br /&gt;
* most JS is initialised through $PAGE-&amp;gt;requires-&amp;gt;js_init_call()&lt;br /&gt;
* full migration to YUI3, YUI2 modules are loaded on demand only&lt;br /&gt;
&lt;br /&gt;
=Sample usage of JavaScript in module=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Description of M namespace=&lt;br /&gt;
&lt;br /&gt;
Since Moodle 2.0 all JavaScript code, configuration data and runtime data are available through the global M object. All plugins register themselves in the M namespace, this namespace may be divided into three parts:&lt;br /&gt;
# basic structures and utility methods, string support, etc. - &amp;#039;&amp;#039;&amp;#039;M.util.*&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;M.cfg&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;M.yui.*&amp;#039;&amp;#039;&amp;#039; (defined inline or in /lib/javascript-static.js)&lt;br /&gt;
# core subsystems such as groups, roles, blocks - &amp;#039;&amp;#039;&amp;#039;M.core_group.*&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;M.core_role.*&amp;#039;&amp;#039;&amp;#039; (defined in various JS files or module.js in each core subsystem)&lt;br /&gt;
# plugin modules such as forum, spamcleaner report, etc. - &amp;#039;&amp;#039;&amp;#039;M.mod_forum.*&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;M.report_spamcleaner.*&amp;#039;&amp;#039;&amp;#039; (defined in /mod/forum/module.js, /admin/report/spamcleaner/module.js)&lt;br /&gt;
&lt;br /&gt;
The recommended strategy is to define one or more &amp;#039;&amp;#039;init&amp;#039;&amp;#039; functions in the plugin namespace such as &amp;#039;&amp;#039;&amp;#039;M.mod_forum.init_view_page()&amp;#039;&amp;#039;&amp;#039; and use it as the interaction point between PHP and JS code. The init function is called via: &amp;lt;code php&amp;gt;$PAGE-&amp;gt;requires-&amp;gt;js_init_call(&amp;#039;M.mod_forum.init_view_page&amp;#039;, $options);&amp;lt;/code&amp;gt; This function makes sure the appropriate JavaScript files are loaded and the init method is executed from the page footer after full initialisation of YUI library.&lt;br /&gt;
&lt;br /&gt;
=Performance improvements=&lt;br /&gt;
&lt;br /&gt;
New script serving similar to themes framework significantly improves caching (elimination of a large number of HTTP requests) and enables compression. Developers will need to disable caching or manually purge server caches. (Note: this feature is not in CVS yet, but the API is finished.)&lt;br /&gt;
&lt;br /&gt;
=Migration and code upgrade steps=&lt;br /&gt;
# study how to use YUI3&lt;br /&gt;
# go through old plugin code and migrate all inline JS code to new file module.js in your plugin directory&lt;br /&gt;
# convert YUI2 calls to YUI3 (some modules are not available in YUI3, fortunately YUI2 modules are usable from YUI3)&lt;br /&gt;
# use $PAGE-&amp;gt;requires-&amp;gt;js_init_call() to integrate JS with your html markup generated from PHP&lt;br /&gt;
&lt;br /&gt;
==Migration to YUI3==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Deprecated coding style==&lt;br /&gt;
# do not add JavaScript code directly to the markup - instead create &amp;#039;&amp;#039;init&amp;#039;&amp;#039; function that adds all necessary event handlers and DOM modifications&lt;br /&gt;
# do not use general JS files - instead use new YUI3 modules stored in module.js files&lt;br /&gt;
# do not create global variables to pass data from PHP to JS code - instead use parameters of &amp;#039;&amp;#039;init&amp;#039;&amp;#039; functions&lt;br /&gt;
# do not add extra script links from PHP - instead use YUI3 loading of modules from JS code&lt;br /&gt;
# do not use YUI2 modules if equivalent YUI3 modules already exit&lt;br /&gt;
# instead of direct DOM modifications use YUI3 methods&lt;br /&gt;
&lt;br /&gt;
=Links=&lt;br /&gt;
* [[Development:JavaScript FAQ]]&lt;br /&gt;
* [[Development:Create YUI3 Module For Moodle]]&lt;/div&gt;</summary>
		<author><name>1&gt;Skodak</name></author>
	</entry>
</feed>