Ver código fonte

improved stability, changed className to `ds-thread-ua`

Signed-off-by: Gerald <gera2ld@163.com>
Gerald 10 anos atrás
pai
commit
7a46147c60
4 arquivos alterados com 17 adições e 12 exclusões
  1. 9 5
      README.md
  2. 1 1
      dist/duoshuo-ua.min.js
  3. 5 4
      src/duoshuo-ua.js
  4. 2 2
      test/example.html

+ 9 - 5
README.md

@@ -8,7 +8,7 @@
 使用方法
 ---
 duoshuoQuery中可以定义`myId`和`getUAString`函数:
-* myId:是站长自己的多说数字id,用于区分站长的回复,并可在`getUAString`中加上不同的标记,如不定义则不会对站长回复进行区分。
+* myIds:是站长自己的多说数字id,可以有多个,用于区分站长的回复,并可在`getUAString`中加上不同的标记,如不定义则不会对站长回复进行区分。
 * getUAString:是对每条留言显示内容进行处理的函数,默认将加上操作系统和浏览器的显示。
 
 ``` HTML
@@ -16,7 +16,7 @@ duoshuoQuery中可以定义`myId`和`getUAString`函数:
 <head>
 
 <!-- 第1部分:必须写在后2部分的前面 -->
-<script>var duoshuoQuery={short_name:'test',myId:1234567};</script>
+<script>var duoshuoQuery={short_name:'test',myIds:[1234567]};</script>
 
 <!-- 第2部分:加载duoshuo-ua.min.js -->
 <script src=dist/duoshuo-ua.min.js></script>
@@ -24,15 +24,19 @@ duoshuoQuery中可以定义`myId`和`getUAString`函数:
 <!-- 第3部分:也可写成异步加载,请写在第2部分后面 -->
 <script src=http://static.duoshuo.com/embed.js></script>
 
-...
 </head>
 <body>
-...
+
+<!-- 第4部分:注意class是“ds-thread-ua”! -->
+<div class="ds-thread-ua" data-thread-key="example"></div>
+
 </body>
 </html>
 ```
 
-注:dist/duoshuo-ua.min.js是压缩后的代码,集成了CSS,无需单独加载CSS文件,如需自定义,请使用未压缩版本。
+注:
+1. dist/duoshuo-ua.min.js是压缩后的代码,集成了CSS,无需单独加载CSS文件,如需自定义,请使用未压缩版本。
+1. 第4部分中`class="ds-thread-ua"`,将被duoshuo-ua进行识别,确保duoshuo-ua完成初始化以后再显示评论,如果是duoshuo-ua初始化以后的动态加载则应写成`class="ds-thread"`。
 
 效果可参见:<http://geraldl.net/about>
 

Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 1
dist/duoshuo-ua.min.js


+ 5 - 4
src/duoshuo-ua.js

@@ -87,7 +87,7 @@
 					return 'Internet Explorer '+m[1];
 				}],
 				[/Trident\/(\d+)\.0/i,function(m){
-					return 'Internet Explorer '+(m[1]+4);
+					return 'Internet Explorer '+(parseInt(m[1])+4);
 				}],
 			]],
 		],result={os:'山寨系统',os_cls:'other',br:'山寨浏览器',br_cls:'other'},r;
@@ -102,13 +102,13 @@
 			(local.webmaster?'<div class=ds-webmaster>站长</div>':'');
 	}
 	function callBefore(local,args){
-		var e=args[0],id,myId=duoshuoQuery.myId||[];
+		var e=args[0],id,myIds=duoshuoQuery.myIds||duoshuoQuery.myId||[];
 		if(args.length==1)	// embed.unstable.js
 			e=e.post;
 		local.agent=parseAgent(e.agent);
 		id=e.author_id;
-		if(!myId.indexOf) myId=[myId];
-		local.webmaster=myId.indexOf(id)<0?0:id;
+		if(!myIds.indexOf) myIds=[myIds];
+		local.webmaster=myIds.indexOf(id)<0?0:id;
 	}
 	function callAfter(local,args){
 		var r=local.result,
@@ -126,6 +126,7 @@
 			callAfter.call(this,local,args);
 			return local.result;
 		}
+		DUOSHUO.jQuery('.ds-thread-ua').removeClass('ds-thread-ua').addClass('ds-thread');
 	}
 	var ondomready=duoshuoQuery.ondomready;
 	duoshuoQuery.ondomready=function(){

+ 2 - 2
test/example.html

@@ -3,11 +3,11 @@
 	<head>
 		<meta charset=utf-8 />
 		<title>Test DUOSHUO</title>
-		<script>var duoshuoQuery={short_name:'your_short_name',myId:1234567};</script>
+		<script>var duoshuoQuery={short_name:'your_short_name',myIds:[1234567]};</script>
 		<script src=../dist/duoshuo-ua.min.js></script>
 		<script src=http://static.duoshuo.com/embed.unstable.js></script>
 	</head>
 	<body>
-		<div class=ds-thread data-thread-key="your_key"></div>
+		<div class=ds-thread-ua data-thread-key="your_key"></div>
 	</body>
 </html>