PageSourceSearch

https://www.jpcert.or.jp/common/js/common.js

js jpcert.or.jp collected 2026-10-01 08:57:21 UTC 4,445 bytes, 148 lines download raw bytes

1"use strict";
2
3window.document.observe('dom:loaded', function(){
4  setupButtons();
5  setupGuidance();
6  setupGlobalMenu();
7  setupPageLayoutUtility();
8  setupTopPageListBoxHeight();
9  setupPageScroll();
10});
11
12var swapImage = function (img, flg) {
13    img.src = img.src.replace(/^(.*)(on|off)(\.\w+)$/, "$1" + flg + "$3");
14}
15var isSmartPhone = function () {
16  var agent = navigator.userAgent;
17  return (agent.search(/(iPhone|Android|IEMobile)/) != -1);
18}
19
20/*
21 * setupGuidance
22 * スマホ用のガイダンスを表示
23 */
24var setupGuidance = function() {
25  if(!$("guidance_sp")) return;
26
27  if(!isSmartPhone()) return;
28
29  // チェックONのイメージを先読み
30  var img = new Image();
31  img.src = '/common/image/g_check_on.png';
32
33  $("guidance_sp").show();
34
35  var checkImg = $("check_no_message").down("img");
36  var checked = false;
37  $("check_no_message").observe("click", function() {
38    checked = !checked;
39    if( checked) swapImage(checkImg, 'on');
40    if(!checked) swapImage(checkImg, 'off');
41  });
42  $("show_sp_site").observe("click", function() {
43    var value = checked ? "sp" : "";
44    Cookie.set("viewmode", value, 24 * 30);
45  });
46}
47
48/*
49 * setupPageScroll
50 * ページ内ジャンプをスクロールに変更
51 */
52var setupPageScroll = function() {
53  $$('a[href^=#]:not([href=#])').each(function(element) {
54    element.observe('click', function(event) {
55      new Effect.ScrollTo(this.hash.substr(1), { duration: 0.5 });
56      Event.stop(event);
57      return false;
58    }.bindAsEventListener(element))
59  });
60};
61
62/*
63 * setupButtons
64 * a > img ボタンの画像切り替え
65 */
66var setupButtons = function() {
67  $$('a.button').each(function(anchor){
68    var img = anchor.down('img');
69    anchor
70      .observe('mouseover', function(){
71        if(anchor.hasClassName('nochange')) return;
72        img.src = img.src.replace(/_off\./,'_on.');
73      })
74      .observe('mouseout', function(){
75        if(anchor.hasClassName('nochange')) return;
76        img.src = img.src.replace(/_on\./,'_off.');
77      })
78    ;
79  });
80};
81
82/*
83 * setupGlobalMenu
84 * ドロップダウンメニューを有効化
85 */
86var setupGlobalMenu = function() {
87  $$("nav ul").each(function(ul){
88    ul.addClassName("dropdown_menu");
89  });
90};
91
92/*
93 * setupPageLayoutUtility
94 * 印刷レイアウトと通常レイアウトの切り替え
95 */
96var setupPageLayoutUtility = function() {
97  var $pageLayoutUtility = $("page_layout_utility");
98  if(!$pageLayoutUtility) return;
99  $pageLayoutUtility.show();
100  var $body = $(window.document.body);
101  var helper = {
102    changeLayoutPrint: function() {
103      $body.addClassName("page_layout_for_print");
104      Cookie.set("keep_layout_print", "1");
105    },
106    changeLayoutNormal: function() {
107      $body.removeClassName("page_layout_for_print");
108      Cookie.set("keep_layout_print", "0");
109    },
110    print: function() {
111      window.print();
112    }
113  };
114  var keep_layout_print = Cookie.get("keep_layout_print") || "0";
115  if(keep_layout_print == "1") helper.changeLayoutPrint();
116  $pageLayoutUtility.down("a.icon_print_layout").observe("click", helper.changeLayoutPrint);
117  $pageLayoutUtility.down("a.icon_normal_layout").observe("click", helper.changeLayoutNormal);
118  $pageLayoutUtility.down("a.icon_print").observe("click", helper.print);
119};
120
121/*
122 *
123 */
124var setupTopPageListBoxHeight = function() {
125  var arrangeListBoxHeight = function($a, $b, adjust) {
126    if(!$a || !$b) return;
127    $a.setStyle({ 'height': null });
128    $b.setStyle({ 'height': null });
129
130    var height = Math.max($a.getHeight(), $b.getHeight());
131    $a.setStyle({ 'height': (height - adjust) + "px" });
132    $b.setStyle({ 'height': (height - adjust) + "px" });
133  };
134  var arrangeListBoxHeightAll = function() {
135    var left_list = $$(".contents_list_box_left");
136    var right_list = $$(".contents_list_box_right");
137    left_list.each(function($element, index) {
138      arrangeListBoxHeight($element.down(".list"), right_list[index].down(".list"), 3);
139    });
140    left_list = $$(".contents_list_box_left > .container > h3 + p");
141    right_list = $$(".contents_list_box_right > .container > h3 + p");
142    left_list.each(function($element, index) {
143      arrangeListBoxHeight($element, right_list[index], 0);
144    });
145  };
146  arrangeListBoxHeightAll();
147  Event.observe(window, "resize", arrangeListBoxHeightAll);
148};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.