Browse Source

阅读器中查字典初步完成

visuddhinanda 5 years ago
parent
commit
ef373352a8
3 changed files with 28 additions and 18 deletions
  1. 3 0
      app/public/js/comm.js
  2. 1 0
      app/reader/reader.js
  3. 24 18
      app/term/note.js

+ 3 - 0
app/public/js/comm.js

@@ -95,6 +95,9 @@ function com_xmlToString(elem) {
 }
 
 function com_getPaliReal(inStr) {
+	if (typeof inStr == "undefined") {
+		return "";
+	}
 	var paliletter = "abcdefghijklmnoprstuvyāīūṅñṭḍṇḷṃ";
 	var output = "";
 	inStr = inStr.toLowerCase();

+ 1 - 0
app/reader/reader.js

@@ -254,4 +254,5 @@ function edit_wbw(book, para) {
 function show_dict(obj) {
 	$("#main_view_shell").toggleClass("right_float_min");
 	$(obj).toggleClass("active");
+	gBuildinDictIsOpen = $(obj).hasClass("active");
 }

+ 24 - 18
app/term/note.js

@@ -9,6 +9,7 @@ var _channalData;
 
 var MAX_NOTE_NEST = 2;
 
+var gBuildinDictIsOpen = false;
 /*
 {{203-1654-23-45@11@en@*}}
 <note>203-1654-23-45@11@en@*</note>
@@ -232,6 +233,8 @@ function note_refresh_new() {
 						term_get_dict();
 						note_channal_list();
 						refresh_pali_script();
+						//把巴利语单词用<w>分隔用于点词查询等
+						splite_pali_word();
 					} catch (e) {
 						console.error(e);
 					}
@@ -987,27 +990,30 @@ function set_pali_script(pos, script) {
 		$("pl" + pos).html(function (index, oldcontent) {
 			return roman_to_my(oldcontent);
 		});
-		/*
-		$("pali")
-			.contents()
-			.filter(function () {
-				return this.nodeType != 1;
-			})
-			.wrap("<pl></pl>");
-			
-		$("pl").each(function () {
-			let html = $(this).html();
-			$(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
-		});
-		
-		$("w").click(function () {
-			let word = $(this).text();
-			window.open("../dict/index.php?buildin=true&key=" + word, "dict");
-		});
-		*/
 	}
 }
 
+function splite_pali_word() {
+	$("pali")
+		.contents()
+		.filter(function () {
+			return this.nodeType != 1;
+		})
+		.wrap("<pl></pl>");
+
+	$("pl").each(function () {
+		let html = $(this).html();
+		$(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
+	});
+
+	$("w").click(function () {
+		let word = com_getPaliReal($(this).text());
+		if (gBuildinDictIsOpen) {
+			window.open("../dict/index.php?builtin=true&key=" + word, "dict");
+		}
+	});
+}
+
 function refresh_pali_script() {
 	if (_display && _display == "para") {
 		//段落模式