PageSourceSearch

https://sakaiku.jp/common/js/rewrite.js

js sakaiku.jp collected 2026-09-24 20:24:23 UTC 1,420 bytes, 48 lines download raw bytes

1/**
2 * rewrite Contents
3 *
4 * usage:
5<script src="js/vendor/jquery.min.js"></script>
6<script src="js/rewritecontents.js"></script>
7
8<header class="rewrite-contents" data-contents="parts.html"></header>
9
10<script>
11$(function() {
12  // 全 class=rewrite-contents 要素に対して data-contents で指定したURLの内容を挿入する
13  rewriteContents.insert();
14});
15</script>
16 */
17
18var rewriteContents = {};
19rewriteContents.vars = {
20	isLoad : function(elm) { return true; }, // 読み込む必要があるかどうかを判定可能(必要ならオーバーライドして使う)
21	
22	dummy : "dummy"  // 最後の要素に , 付けないのが面倒なだけ:p
23};
24
25rewriteContents.init = function(options) {
26	this.vars = $.extend(this.vars, options);
27};
28rewriteContents.insert = function() {
29	var self = this;
30	
31	// 全rewriteに対して、判定が true なら実行する
32	$('.rewrite-contents').each( function() {
33		if (typeof self.vars.isLoad === "function" && self.vars.isLoad(this) === true) {
34			self.load(this);
35		}
36	});
37};
38rewriteContents.load = function(elm) {
39	var date = new Date();
40	var url = $(elm).data("contents");
41	if (!url) { return; }
42	url = url.replace(/\.\.\//, "", url); // ../ は削除
43	url += '?c='+ Math.floor(date.getTime() / 1000); // 拡張子後に ?YMD を追加
44	$.get(url, function(contents) {
45		$(elm).html(contents);
46		g_dispatcher.trigger('rewriteContents_loaded', elm); 
47	});
48};

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.