diff options
Diffstat (limited to 'files/zh-cn/扩展')
-rw-r--r-- | files/zh-cn/扩展/using_the_dom_file_api_in_chrome_code/index.html | 42 | ||||
-rw-r--r-- | files/zh-cn/扩展/内嵌选项/index.html | 169 | ||||
-rw-r--r-- | files/zh-cn/扩展/社区/index.html | 10 |
3 files changed, 0 insertions, 221 deletions
diff --git a/files/zh-cn/扩展/using_the_dom_file_api_in_chrome_code/index.html b/files/zh-cn/扩展/using_the_dom_file_api_in_chrome_code/index.html deleted file mode 100644 index 9198b4b544..0000000000 --- a/files/zh-cn/扩展/using_the_dom_file_api_in_chrome_code/index.html +++ /dev/null @@ -1,42 +0,0 @@ ---- -title: 在chrome代码中使用DOM File API -slug: 扩展/Using_the_DOM_File_API_in_chrome_code -translation_of: Extensions/Using_the_DOM_File_API_in_chrome_code ---- -<p>{{ gecko_minversion_header("6.0") }}</p> -<p>如果你想在chrome代码中使用<a href="/zh-CN/Using_files_from_web_applications" title="zh-CN/Using files from web applications">DOM File API</a>,可以使用,且没有任何限制.事实上,你还获得了一个额外的特性:你可以通过传入文件的本地路径来创建一个 {{ domxref("File") }}对象.这个特性只在特权代码中可用,web页面中不可用.很明显,这是因为安全问题,否则网页可以读取到用户计算机中任意的本地文件.如果你在非特权代码(比如普通的web页面)中向{{ domxref("File") }}构造函数传入了一个路径字符串,则会抛出异常.</p> -<h2 id="通过文件路径访问文件">通过文件路径访问文件</h2> -<p>想要通过文件路径引用到某个文件,你只需要传入一个路径字符串:</p> -<pre>var file = File("path/to/some/file"); -</pre> -<p>注: 由于windows和linux系统上使用的路径分隔符不同(这里使用了"/"),所以这样写会产生无法跨平台的问题.而且我们没有一个类似于Java中的<code>File.pathSeparator</code>来动态的获取到适合用户操作系统的路径分隔符<code>.</code>所以如果你的扩展程序需要跨平台,更好的做法是避免把路径写死(字符串形式),而是使用 nsIFile::append()方法来指定某个目录中所需要的文件,具体看下一节.</p> -<h2 id="访问特殊目录中的文件">访问特殊目录中的文件</h2> -<p>你也可以通过directory服务来获取到所需访问文件的路径.例如,你的附加组件需要访问用户的profile目录中的一个文件.你可以这样做:</p> -<pre class="brush: js">var dsFile = Components.classes["@mozilla.org/file/directory_service;1"] - .getService(Components.interfaces.nsIProperties) - .get("ProfD", Components.interfaces.nsIFile); - -dsFile.append("myfilename.txt"); - -var file = File(dsFile.path); -</pre> -<p>这个例子中使用到了directory服务获取到了用户的profile目录(使用键"ProfD"),然后通过调用{{ ifmethod("nsIFile", "append") }}方法获取到了所需访问的文件.最后,我们通过将{{ ifmethod("nsIFile", "path") }} 属性传入{{ domxref("File") }}构造函数来生成一个{{ domxref("File") }}对象.</p> -<p>还有更方便的方法,就是直接把一个{{ interface("nsIFile") }}对象传入<code>File</code>构造函数:</p> -<pre class="brush: js">var dsFile = Components.classes["@mozilla.org/file/directory_service;1"] - .getService(Components.interfaces.nsIProperties) - .get("ProfD", Components.interfaces.nsIFile); - -dsFile.append("myfilename.txt"); - -var file = File(dsFile);</pre> -<p>还有其他很多类似"ProfD"的键,请查看<a href="/zh-CN/Using_nsIDirectoryService#Known_Locations" title="https://developer.mozilla.org/zh-CN/Using_nsIDirectoryService#Known_Locations">directory服务</a>.</p> -<p>译者注:{{ interface("nsIFile") }}对象比{{ domxref("File") }}对象强大多了,在扩展程序中,我们不可能需要将一个{{ interface("nsIFile") }}对象转换成一个{{ domxref("File") }}对象.</p> -<h2 id="备注">备注</h2> -<p>从Gecko 8.0 {{ geckoRelease("8.0") }}开始, 你也可以在组件代码中使用上面这些代码.</p> -<h2 id="相关链接">相关链接</h2> -<ul> - <li><a href="/zh-CN/Using_files_from_web_applications" title="zh-CN/Using files from web applications">如何在web应用程序中使用文件</a></li> - <li>{{ domxref("File") }}</li> - <li>{{ interface("nsIDirectoryService") }}</li> - <li>{{ interface("nsIFile") }}</li> -</ul> diff --git a/files/zh-cn/扩展/内嵌选项/index.html b/files/zh-cn/扩展/内嵌选项/index.html deleted file mode 100644 index d6aeadcf43..0000000000 --- a/files/zh-cn/扩展/内嵌选项/index.html +++ /dev/null @@ -1,169 +0,0 @@ ---- -title: 内嵌选项 -slug: 扩展/内嵌选项 -tags: - - inline options - - 内嵌选项 -translation_of: Archive/Add-ons/Inline_Options ---- -<p>{{ gecko_minversion_header("7.0") }}</p> -<p>Firefox 7 支持新的定义扩展首选项的语法,同时适用于无需启动(<a href="/en-US/docs/Extensions/Bootstrapped_extensions">bootstrapped</a>)扩展和传统扩展。该新语法定义的首选项用户界面会出现在<a href="/zh-CN/docs/Addons/Add-on_Manager" title="/zh-CN/docs/Addons/Add-on_Manager">附加组件管理器</a>的扩展详细视图里。该功能最初出现在 Firefox 移动版,现在已经可以在 Firefox 桌面版使用了。</p> -<h2 id="选项文件">选项文件</h2> -<p>The XUL allowed for the inline options is limited to a <a class="external" href="http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/content/setting.xml">few new tags</a>. Here is an example of an <code>options.xul</code> file:</p> -<pre class="brush: xml"><?xml version="1.0"?> - -<!DOCTYPE mydialog SYSTEM "chrome://myaddon/locale/mydialog.dtd"> - -<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> - <setting type="bool" pref="extensions.myaddon.bool" title="Boolean" desc="Stored as a boolean preference" /> -</vbox> -</pre> -<p>Note that it's limited to <code><setting></code> tags. The root <code><vbox></code> just acts as a container, it isn't merged into the main window. If you need script support, see the <a href="#Display_notifications">display notifications</a> section.</p> -<h2 id="设置类型">设置类型</h2> -<p>There are several types of <code><setting></code>s, each with a different <code>type</code> attribute:</p> -<table class="standard-table"> - <tbody> - <tr> - <td class="header">type attribute</td> - <td class="header">displayed as</td> - <td class="header">preference stored as</td> - </tr> - <tr> - <td><code>bool</code></td> - <td>{{ XULElem("checkbox") }}</td> - <td>boolean</td> - </tr> - <tr> - <td><code>boolint</code></td> - <td>{{ XULElem("checkbox") }}</td> - <td>integer (use the attributes <code>on</code> and <code>off</code> to specify what values to store)</td> - </tr> - <tr> - <td><code>integer</code></td> - <td>{{ XULElem("textbox") }}</td> - <td>integer</td> - </tr> - <tr> - <td><code>string</code></td> - <td>{{ XULElem("textbox") }}</td> - <td>string</td> - </tr> - <tr> - <td><code>color</code></td> - <td>{{ XULElem("colorpicker") }}</td> - <td>string (in the <code>#123456</code> format)</td> - </tr> - <tr> - <td><code>file</code></td> - <td>browse button and label</td> - <td>string</td> - </tr> - <tr> - <td><code>directory</code></td> - <td>browse button and label</td> - <td>string</td> - </tr> - <tr> - <td><code>menulist</code> {{ gecko_minversion_inline("8.0") }}</td> - <td>{{ XULElem("menulist") }}</td> - <td>dependent on the menu item values</td> - </tr> - <tr> - <td><code>radio</code> {{ gecko_minversion_inline("8.0") }}</td> - <td>{{ XULElem("radio") }} buttons</td> - <td>dependent on the radio values</td> - </tr> - <tr> - <td><code>control</code></td> - <td>{{ XULElem("button") }}</td> - <td>no pref stored</td> - </tr> - </tbody> -</table> -<p>The <code>pref</code> attribute should have the full name of the preference to be stored. The <code>title</code> attribute is used as a label for the controls. To set a description, either use the <code>desc</code> attribute, or a text node as a child of the <code><setting></code> tag.</p> -<p>Settings are tied to actual preferences, except the button setting, which is designed more for actions.</p> -<p>Some examples:</p> -<pre class="brush: xml"><!-- Boolean examples --> -<setting pref="extensions.myaddon.bool1" type="bool" title="Boolean 1"/> -<setting pref="extensions.myaddon.bool2" type="bool" title="Boolean 2"> - Description of Boolean 2 -</setting> - -<!-- Boolean stored as an integer --> -<setting pref="extensions.myaddon.boolInt" type="boolint" title="Boolean 3" on="1" off="2"/> - -<!-- Integer example --> -<setting pref="extensions.myaddon.int" type="integer" title="Integer"/> - -<!-- String examples --> -<setting pref="extensions.myaddon.text" type="string" title="Text"/> -<setting pref="extensions.myaddon.password" type="string" title="Password" inputtype="password"/> - -<!-- Color example --> -<setting pref="extensions.myaddon.color" type="color" title="Color"/> - -<!-- File and directory examples --> -<setting pref="extensions.myaddon.file" type="file" title="File"/> -<setting pref="extensions.myaddon.directory" type="directory" title="Directory"/> - -<!-- List example (this example would be stored as an integer) --> -<setting pref="extensions.myaddon.options1" type="menulist" title="Options 1"> - <menulist> - <menupopup> - <menuitem value="500" label="small"/> - <menuitem value="800" label="medium"/> - <menuitem value="1200" label="large"/> - </menupopup> - </menulist> -</setting> - -<!-- Radio Button example (this example would be stored as a boolean) --> -<setting pref="extensions.myaddon.options2" type="radio" title="Options 2"> - <radiogroup> - <radio value="false" label="disabled"/> - <radio value="true" label="enabled"/> - </radiogroup> -</setting> - -<!-- Button example - not tied to a preference, but attached to a command --> -<setting title="Do Something" type="control"> - <button id="myaddon-button" label="Click Me" oncommand="alert('Thank you!');"/> -</setting> -</pre> -<h2 id="显示通知">显示通知</h2> -<p>If you want to use the settings UI for anything more than storing preferences, then you will probably need to initialize them when they first appear. You can't do this until your options XUL has been loaded into the Add-on Manager window, so you should listen for the <code>addon-options-displayed</code> notification to initialize your settings. For example:</p> -<pre class="brush: js">var observer = { - observe: function(aSubject, aTopic, aData) { - if (aTopic == "addon-options-displayed" && aData == "MY_ADDON@MY_DOMAIN") { - var doc = aSubject; - var control = doc.getElementById("myaddon-pref-control"); - control.value = "test"; - } - } -}; - -Services.obs.addObserver(observer, "addon-options-displayed", false); -// Don't forget to remove your observer when your add-on is shut down. -</pre> -<p>This code should be in <code>bootstrap.js</code> (within the <code>startup()</code> function) for restartless extensions or in an XPCOM component or a <a href="/en-US/docs/JavaScript_code_modules">JavaScript code module</a> (not an overlay!) for traditional extensions.</p> -<div class="geckoVersionNote" style=""> - <p>{{ gecko_callout_heading("13.0") }}</p> - <p>Starting in Gecko 13.0 {{ geckoRelease("13.0") }}, you can also listen for the <code>addon-options-hidden</code> notification, which has the same subject and data as above, to find out when the UI is about to be removed. Use this notification to remove event listeners, or any other references that might otherwise be leaked.</p> -</div> -<h2 id="Locating_the_options_file">Locating the options file</h2> -<p>There are two ways to let the Add-on Manager find your options file:</p> -<ul> - <li>Name the file <code>options.xul</code> and put it in the extension's root folder (alongside <code>install.rdf</code>).</li> - <li>Use <a href="/en-US/docs/Install_Manifests"><code>install.rdf</code></a> to identify the XUL used for displaying the options. For inline options, you must also specify the <code>optionsType</code> as <code>2</code>: - <pre class="deki-transform"><em:optionsURL><span class="plain">chrome://myaddon/content/options.xul</span></em:optionsURL> -<em:optionsType>2</em:optionsType> -</pre> - You can maintain compatibility with previous versions of Firefox by adding an override to your <a href="/en-US/docs/Chrome_Registration"><code>chrome.manifest</code></a>: - <pre class="deki-transform"><span class="plain">override chrome://myaddon/content/options.xul chrome://myaddon/content/oldOptions.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} appversion<=6.*</span> -</pre> - </li> -</ul> -<h2 id="See_also">See also</h2> -<ul> - <li><a class="link-https" href="https://wiki.mozilla.org/Mobile/Fennec/Extensions/Options">https://wiki.mozilla.org/Mobile/Fennec/Extensions/Options</a></li> -</ul> diff --git a/files/zh-cn/扩展/社区/index.html b/files/zh-cn/扩展/社区/index.html deleted file mode 100644 index 6505d6f33d..0000000000 --- a/files/zh-cn/扩展/社区/index.html +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: 扩展/社区 -slug: 扩展/社区 -translation_of: Extensions/Community ---- -<p> </p> -<p>如果你知道与<a class="internal" href="/cn/%E6%89%A9%E5%B1%95" title="cn/扩展">扩展开发</a>相关的邮件列表、新闻组、论坛或者其他社区,请链接到这里。</p> -<ul> <li><a class="external" href="http://www.xulplanet.com">XULPlanet - XUL参考</a></li> <li><a class="external" href="http://www.xulplanet.com/forum2/">XULPlanet 论坛</a></li> <li><a class="external" href="http://forums.mozillazine.org/?c=11">MozillaZine 扩展和主题论坛</a></li> <li><a class="link-irc" href="irc://moznet/%23extdev">#extdev channel on moznet IRC network - extension development questions</a></li> <li><a class="link-irc" href="irc://moznet/%23addons">#addons channel on moznet IRC network - questions about http://addons.mozilla.org</a></li> <li><a class="external" href="http://mozdev.org/mailman/listinfo/project_owners">mozdev 项目所有者邮件列表</a></li> <li><a class="external" href="http://kb.mozillazine.org/Extension_development">Mozillazine 知识库</a></li> <li><a class="external" href="http://allyourideas.com/index.php?title=Category:Firefox_extension">AllYourIdeas</a> - ideas for extensions ((REALLY needs a unique CAPTCHA))</li> <li><a class="external" href="http://babelzilla.org/">BabelZilla</a> - 一个Mozilla产品扩展开发者和翻译者的社区</li> <li><a class="external" href="http://www.shangducms.com/category/Firefox-Addon.aspx">GuoJing's Blog</a> - 一个博客作者写的关于Firefox extension开发的心得和体验</li> -</ul> -<p>{{ languages( { "en": "en/Extensions/Community","fr": "fr/Extensions/Communaut\u00e9", "ja": "ja/Extensions/Community", "pl": "pl/Rozszerzenia/Spo\u0142eczno\u015b\u0107" } ) }}</p> |