「Common.js」の版間の差分
提供: WikiArc
153行目: | 153行目: | ||
+ '<a href="https://www.kanjipedia.jp/search?k=' | + '<a href="https://www.kanjipedia.jp/search?k=' | ||
+ encodeURIComponent(str) +'&kt=1&sk=leftHand' + '" target="_blank">' | + encodeURIComponent(str) +'&kt=1&sk=leftHand' + '" target="_blank">' | ||
− | + ' | + | + ' 漢字1文字Pedia</a><br />' |
+ '<a href="http://ja.wikipedia.org/wiki/' | + '<a href="http://ja.wikipedia.org/wiki/' | ||
+ encodeURIComponent(str) + '" target="_blank">' | + encodeURIComponent(str) + '" target="_blank">' |
2019年5月8日 (水) 12:34時点における版
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */ // pageNo.の表示 function Seiten_PageNo_Disp() { var hash = location.hash; //var ck = hash.lastIndexOf('#P--'); //if ( -1 != hash.lastIndexOf('#P--')) if (( -1 != hash.lastIndexOf('#P--')) || ( -1 != hash.lastIndexOf('#no'))) { var spanTag = document.getElementsByTagName("span"); for (var i=0; i< spanTag.length; i++){ if ('P--' == spanTag[i].id.substr(0, 3)){ spanTag[i].innerHTML=spanTag[i].id; spanTag[i].style.color ="black"; spanTag[i].style.backgroundColor = "#00FF00"; } } } } // 読み込みが完了した時に処理を行う $(window).load(function () { Seiten_PageNo_Disp(); }); // 表示 非表示 $(function() { // 初期表示は、非表示にする $('.showhide1').toggle(); // ボタン1を押したとき $(".shbutton1").click(function() { // 表示のときは、非表示にします。 // 非表示の時、表示します。 var id = $(this).attr('id'); id ='#' + id + 'div'; $(id).toggle(1000); // $(".showhide1").toggle(1000); }); }); // スクロール $(function() { var topBtn = $('#page-top'); topBtn.hide(); //スクロールが100に達したらボタン表示 $(window).scroll(function () { if ($(this).scrollTop() > 100) { topBtn.fadeIn(); } else { topBtn.fadeOut(); } }); //スクロールしてトップ topBtn.click(function () { $('body,html').animate({ scrollTop: 0 }, 500); return false; }); }); // initalize TXT_m = new TXT_mouse(); TXT_id = "__searchBoxWiki"; TXT_str = ""; TXT_timeout = null; document.onmouseup = TXT_main; // main function TXT_main(e) { TXT_getMousePosition(e); if ( !e ) { e = event; } // left button ? var button; if ( e.button ) { button = e.button; } else { button = e.which; } if ( button != 1 ) { return; } // element check if ( TXT_elementCheck(e) ) { TXT_closeSearchBox(); return; } // get word var str = String(TXT_getSelectedText(window)); str = str.replace(/^\s+|\s+$/g, ""); if ( str.match(/\r|\n/) ) { TXT_closeSearchBox(); return; } str = str.replace(/[\r\n\s ]/g, " ").substr(0, 100); // same word ? if ( TXT_str == str ) { return; } // show search box TXT_closeSearchBox(); if ( str != '' ) { TXT_openSearchBox(str, TXT_m.x - 20, TXT_m.y + 15); TXT_str = str; } } // set search box function TXT_openSearchBox(str, x, y) { if ( TXT_timeout ) { clearTimeout(TXT_timeout); } // count bytes var num = 0; for(i = 0; i < str.length; i++) { (escape(str.charAt(i)).length > 4) ? (num += 2) : num++; } // set html var div = document.createElement("div"); div.id = TXT_id; with(div.style) { border = "1px solid #666666"; backgroundColor = "#FFFFCC"; padding = "0px"; position = "absolute"; top = "-100px"; left = "0px"; visibility = "visible"; } div.innerHTML = '<div id="searchlayer" style="margin:4px 4px 4px 12px;padding:0px;font-size:16px;">' + str + ' を<br />' + '<a href="http://www.google.co.jp/search' + '?hl=ja&q=' + encodeURIComponent(str) + '" target="_blank">' + ' Googleで検索</a><br />' + '<a href="http://dic.search.yahoo.co.jp/search' + '?ei=UTF-8&p=' + encodeURIComponent(str) + '&stype=prefix&fr=dic' + '" target="_blank">' + ' NET辞書で引く</a><br />' + '<a href="https://www.kanjipedia.jp/search?k=' + encodeURIComponent(str) +'&kt=1&sk=leftHand' + '" target="_blank">' + ' 漢字1文字Pedia</a><br />' + '<a href="http://ja.wikipedia.org/wiki/' + encodeURIComponent(str) + '" target="_blank">' + ' Wikipediaで引く</a><br />' + '<a href="http://jodoshuzensho.jp/daijiten/index.php/特別:Search?search=' + encodeURIComponent(str) + '" target="_blank">' + ' 浄土宗大辞典で引く</a><br />' + '<a href="http://labo.wikidharma.org/index.php/特別:Search?search=' + encodeURIComponent(str) + '" target="_blank">' + ' 聖典(WikiArc)で引く</a></div>'; //bodyContent document.body.appendChild(div); // flow check var pageWidth = TXT_getBrowserWidth() - 60; var w = (div.offsetWidth > pageWidth ? pageWidth : div.offsetWidth); if ( x + w > pageWidth ) { x = pageWidth - w + 30; } /* // appear with(div.style) { width = w + "px"; top = y + "px"; left = x + "px"; } */ div.style.width = width = w + "px"; div.style.top = y + "px"; div.style.left = left = x + "px"; div.style.zIndex = 4; // alert(document.getElementById(TXT_id).style.zIndex); //document.getElementById(TXT_id).focus(); // set timer TXT_timeout = setTimeout(TXT_closeSearchBox, 5000); } // close search box function TXT_closeSearchBox() { if ( TXT_timeout ) { clearTimeout(TXT_timeout); } var obj = document.getElementById(TXT_id); if ( obj ) { document.body.removeChild(obj); } TXT_str = ""; } // get mouse position function TXT_getMousePosition(e) { var brw = new TXT_checkBrowser(); // alert(brw.chr); TXT_m.scrollX = (document.body.scrollLeft || document.documentElement.scrollLeft); TXT_m.scrollY = (document.body.scrollTop || document.documentElement.scrollTop); if ( brw.ie || brw.chr) { // IE TXT_m.x = event.clientX + TXT_m.scrollX; TXT_m.y = event.clientY + TXT_m.scrollY; } else if ( brw.ff || brw.moz ) { // Firefox & Mozilla TXT_m.x = e.pageX; TXT_m.y = e.pageY; } else if ( brw.saf ) { // Safari TXT_m.x = e.x; TXT_m.y = e.y; } } // get selected strings function TXT_getSelectedText(obj) { var txt = '', i; try { if ( obj.document.selection ) { txt = obj.document.selection.createRange().text; } else if ( obj.getSelection ) { txt = obj.getSelection(); } else if ( obj.document.getSelection ) { txt = obj.document.getSelection(); } else { txt = ''; } } catch(e) {} // search frames if ( txt == '' && obj.frames.length ) { for(i = 0; i < obj.frames.length; i++) { if ( (txt = TXT_getSelectedText(obj.frames[i])) != '' ) { break; } } } if ( txt == null ) { txt = ''; } return txt; } // mouse object function TXT_mouse() { this.x = 0; this.y = 0; this.scrollX = 0; this.scrollY = 0; } // check browser object function TXT_checkBrowser() { this.ie = 0; this.ff = 0; this.saf = 0; this.moz = 0; this.chr = 0; var ua = navigator.userAgent; // document.write(ua); if ( ( ua.indexOf("MSIE") > -1 ) ) { this.ie = 1; } else if ( ( ua.indexOf("Firefox") > -1 ) ) { this.ff = 1; } else if ( ( ua.indexOf("Chrome") > -1 ) ) { this.chr = 1; } else if ( ( ua.indexOf("Mozilla") > -1 ) ) { this.moz = 1; } else if ( ( ua.indexOf("Safari") > -1 ) ) { this.saf = 1; } try { if ( event ) { this.ie = 1; } } catch(e) {} } // browser width function TXT_getBrowserWidth() { if ( window.innerWidth ) { return window.innerWidth; } else if ( document.documentElement && document.documentElement.clientWidth ) { return document.documentElement.clientWidth; } else if ( document.body ) { return document.body.clientWidth; } return 0; } // element check function TXT_elementCheck(e) { var tag; if ( e.srcElement ) { tag = e.srcElement.tagName; } else { tag = e.target.tagName; } var forbidden = new Array('INPUT', 'TEXTAREA', 'BUTTON'); for(var i = 0; i < forbidden.length; i++) { if ( tag == forbidden[i] ) { return 1; } } }