2009-09-14
HTML5 のセクションアウトラインを取得する JavaScript
id:vantguarde さんが HTML5 のセクション 3 箇条を書かれて紹介しています
sectionの使い方とセクション三箇条 - vantguarde - web:g
- スタイルシートやスクリプトの都合には使わないこと。それらにはdivを使うこと。
- article, aside, navが適切な場合には、そちらを使こと。
- セクションの先頭に見出しが自然に存在してない場合には使わないこと。
すばらしいですね!
便乗して
セクションのアウトラインを求める JavaScript(YAPC 前夜祭で紹介したやつ)を公開します
http://amachang.sakura.ne.jp/misc/outliner.js
この JavaScript は
以下のアルゴリズムをそのまま JavaScript で実装したものになっています
また
以下のように、仕様との対応関係を記述してありますのでそちらも見てみてくださいね!
// http://amachang.sakura.ne.jp/misc/outliner.js function createOutline(document) { // Let current outlinee be null. (It holds the element whose outline is being created.) var outlinee = null; // Let current section be null. (It holds a pointer to a section, so that elements in the DOM can all be associated with a section.) var section = null; // Create a stack to hold elements, which is used to handle nesting. Initialize this stack to empty. var stack = []; var nextSectionId = 1; // As you walk over the DOM in tree order, trigger the first relevant step below for each element as you enter and exit it. (function (element) { var elementInfo = { element: element, outline: null }; if (trigger(elementInfo, true)) { return true; (snip)
トラックバック - http://d.hatena.ne.jp/amachang/20090914/1252897184
リンク元
- 1011 http://hato-style.chu.jp/note/htmlcss.html
- 137 http://reader.livedoor.com/reader/
- 48 http://www.google.co.jp/reader/view/
- 48 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&hs=wpi&q=processing.js&btnG=検索&lr=lang_ja
- 47 http://www.google.co.jp/search?sourceid=navclient&hl=ja&ie=UTF-8&rlz=1T4GGLL_ja___JP342&q=javascript+for
- 42 http://www.nobodyplace.com/mutter/2009/03/20/140902.php
- 36 http://www.google.com/reader/view/
- 33 http://d.hatena.ne.jp/HolyGrail/20070717/1184690284
- 29 http://twitter.com/
- 27 http://www.google.co.jp/search?q=javascript+連想配列&lr=lang_ja&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja:official&client=firefox-a
