Reply.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. Namespace.register("U.MD.R");
  2. /**
  3. * 评论控件全局变量
  4. * PID // 项目id,请查看api文档说明,找到你所在项目的id。
  5. * AID // 对应的文章id,获取url网址的主机,加上url网址的目录,形成的文章id。
  6. * URL // 文章对应的url地址。
  7. * PageIndex // 当前页数
  8. * PageSize // 一页请求数
  9. * AllCount // 此文章对应的有多少数据
  10. * */
  11. U.MD.R.data = {
  12. PID: "",
  13. AID: "",
  14. URL: "",
  15. PageIndex: 1,
  16. PageSize: 20,
  17. AllCount: "",
  18. CB: null
  19. }
  20. /**
  21. * 评论控件初始化函数,调用函数
  22. * @param {object} 参数。
  23. * obj={
  24. * pid // 项目id,请查看api文档说明,找到你所在项目的id。
  25. * type //引用方式为弹窗还是嵌入式,true 为嵌入式方式,false 为窗体。
  26. * el // 评论控件追加的元素。注意:当控件为嵌入式时,才需要填写此参数,如果为弹窗时,不需要填写此参数。
  27. * }
  28. */
  29. U.MD.R.reply = function (obj) {
  30. //alert();
  31. //定义变量,获取调用方式、控件追加的元素、以及项目id。
  32. var _type = obj.type,
  33. _el = obj.el,
  34. _cb = obj.cb;
  35. U.MD.R.data.PID = obj.pid; //项目id全局设置
  36. U.MD.R.data.AID = U.MD.R.reply.getUrlHash(); //文章id全局设置
  37. U.MD.R.data.URL = U.MD.R.reply.getUrl(); //文章url全局设置
  38. U.MD.R.data.CB = _cb;
  39. //调用类型判断
  40. if (!_type) {//如果调用方式是窗体,那么先创建一个窗体,并且重新更新变量_el的值。
  41. _el = new U.UF.UI.form('', $$("div"), {
  42. "style": {
  43. "width": "800px",
  44. "height": "800px"
  45. }
  46. }).content;
  47. }
  48. U.MD.R.reply.init(_el); //控件初始化
  49. U.MD.R.login.cookieLogin(); //cookie自动登录
  50. U.UF.DL.asynLoadCss({
  51. "href": "/css/Controls/Basic/Picture.css",
  52. type: "text/css",
  53. rel: "stylesheet"
  54. }); //动态添加css文件
  55. U.UF.DL.asynLoadJs({ type: "text/javascript", src: "/js/Controls/Basic/Picture.js" });
  56. }
  57. /**
  58. * 评论控件初始化函数,调用函数
  59. * @param {element} 追加元素
  60. */
  61. U.MD.R.reply.init = function (el) {
  62. var _pageindex = U.MD.R.data.PageIndex, //当前页数
  63. _pagesize = U.MD.R.data.PageSize; //一页请求数
  64. U.MD.R.initPrintHtml(el); //创建基础html
  65. U.MD.R.getReplyData(_pageindex, _pagesize, function (data) {//获取评论数据
  66. U.MD.R.data.AllCount = data[0][0] ? Math.ceil(data[0][0].allcount / U.MD.R.data.PageSize) : ""; //取数完成之后进行将页数全局赋值给id。
  67. U.MD.R.printComment($("#U_MD_R_content_user_comment")[0], 1, data, false, false, false); //打印数据
  68. U.MD.R.initLoadMoreBtn(data[0]); //创建
  69. });
  70. }
  71. /**
  72. * 获取url地址
  73. */
  74. U.MD.R.reply.getUrl = function () {
  75. return window.location.href;
  76. }
  77. /**
  78. * 获取url网址的主机,加上url网址的目录
  79. */
  80. U.MD.R.reply.getUrlHash = function () {
  81. return U.UF.EC.SparkMD5.hash(window.location.href);
  82. }
  83. /**
  84. * 获取评论数据
  85. * @param {number} 页码数
  86. * @param {number} 一页的请求量
  87. * @param {function} 回调函数
  88. */
  89. U.MD.R.getReplyData = function (pageindex, pagesize, cb) {
  90. U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "test", U.MD.R.data.AID, "1", "", pageindex, pagesize], function (r) {//获取数据
  91. cb && cb(r.value); //执行回调函数,并且返回数据。
  92. });
  93. }
  94. /**
  95. * 初始化创建回复元素
  96. * @param {element} 追加元素
  97. */
  98. U.MD.R.initPrintHtml = function (el) {
  99. var _el = el,
  100. _comment,
  101. _content,
  102. _content_operation,
  103. _userhead,
  104. _headimg,
  105. _operation,
  106. _username,
  107. _editorbox,
  108. _bottom,
  109. _picturewarp,
  110. _picture,
  111. _clear,
  112. _emoji_frame,
  113. _input,
  114. _button,
  115. _img_warp,
  116. _box;
  117. _comment = $$("div", { "className": "U_MD_R_comment" }, _el); //创建最外成元素
  118. _content = $$("div", { "className": "U_MD_R_content" }, _comment); //创建评论内容元素最外元素
  119. _content_operation = $$("div", { "className": "U_MD_R_content_operation" }, _content); //创建用户评论区域最外成元素
  120. _userhead = $$("div", { className: "U_MD_R_content_operation_userhead U_MD_R_Reply_Header" }, _content_operation); //创建头像最外成元素
  121. _headimg = $$("img", {//创建头像img元素
  122. "className": "img",
  123. "src": "/img/UserHead/UseHead.jpg",
  124. "onerror": function () { this.src='/img/UserHead/UseHead.jpg' }
  125. }, _userhead);
  126. _operation = $$("div", {
  127. "className": "U_MD_R_content_operation_right",
  128. style: { width: "calc(100% - 40px - 20px )" }
  129. }, _content_operation); //创建内容框架div
  130. U.selectEl(_operation).attr({
  131. "data-RPID": null,
  132. "data-RD": 1,
  133. "data-RPUID": null
  134. });
  135. _username = $$("div", {//创建用户名元素
  136. "innerHTML": "登录/注册",
  137. "className": "U_MD_R_content_operation_userlogin U_MD_R_Reply_Name"
  138. }, _operation);
  139. //判断是否登录
  140. if (US.userInfo.userid) {//已登录
  141. _username.innerHTML = US.userInfo.UserName; //设置用户名
  142. _headimg.src = 'http://fs.1473.cn/' + US.userInfo.UserThumbnailImageHead; //设置头像
  143. }
  144. else {//未登录
  145. _username.onclick = function () {
  146. U.MD.R.login();
  147. }
  148. }
  149. _editorbox = $$("div", {
  150. "id": "editorbox",
  151. "className": "U_MD_R_Reply_Content",
  152. "contenteditable": "true",
  153. "style": { "min-height": "100px", "background": "#fff", "border": "1px solid black" }
  154. }, _operation)//创建编辑器容器
  155. var _scrolltop = document.documentElement.scrollTop;
  156. U.UF.E.initEditor(_editorbox); //调用函数
  157. document.documentElement.scrollTop = _scrolltop;
  158. _bottom = $$("div", { "className": "U_MD_R_content_operation_right_bottom" }, _operation); //创建用户评论底部区域
  159. $$("div", {//创建表情包按钮
  160. "className": "U_MD_R_content_operation_right_bottom_emoji",
  161. "onclick": function () {
  162. U.UF.EV.stopBubble();
  163. U.MD.UI.face(this, U.selectEl('#editorbox')[0]);
  164. //$(this)[0].append($("#U_MD_UI_face")[0]);
  165. //$(this)[0].append($("#U_MD_UI_face")[0]);
  166. U.selectEl("#U_MD_UI_face").css({ "position": "relative", "height": "140px", "overflow-y": "scroll", "top": "-150px", "width": "450px", "display": "block" });
  167. }
  168. }, _bottom);
  169. _picturewarp = $$("div", { "className": "U_MD_R_content_operation_right_bottom_picturewarp" }, _bottom); //图片最外成
  170. _picture = $$("img", { src: "/img/reply/img.png" }, _picturewarp);
  171. _input = $$("input", { "type": "file" }, _picturewarp); //上传
  172. _button = $$("div", {
  173. "className": "U_MD_R_content_operation_right_bottom_release",
  174. "innerHTML": "发表评论"
  175. }, _bottom); //内容发布
  176. _button.onclick = function () {
  177. if ($(".U_MD_R_Reply_Content")[0].textContent != '' || U.selectEl(".U_MD_R_Reply_Content")[0].innerHTML != '') {
  178. U.MD.R.release(_operation, 1, false, 1);
  179. } else {
  180. U.alert("评论不能为空!");
  181. }
  182. }
  183. _img_warp = $$("div", { "className": "U_MD_R_content_operation_right_bottom_imgloadbox U_MD_R_Reply_Image" }, _operation); //图片加载
  184. _box = $$("div", { "className": "U_MD_R_content_comment", "id": "U_MD_R_content_user_comment" }, _content); //内容盒子
  185. _input.onchange = function () {
  186. U.MD.R.uploadImages(this, _img_warp);
  187. }
  188. U.MD.R.data.CB && U.MD.R.data.CB();
  189. }
  190. /**
  191. * 创建加载更多按钮
  192. */
  193. U.MD.R.initLoadMoreBtn = function (data) {
  194. var _btn = $$("div", { "className": "U_MD_R_content_loading" }, U.selectEl(".U_MD_R_comment")[0]);
  195. if (data.length > 0) {
  196. if (U.MD.R.data.PageIndex < U.MD.R.data.AllCount) {
  197. _btn.innerHTML = "点击加载更多评论";
  198. _btn.onclick = function () {
  199. var _pageindex = ++U.MD.R.data.PageIndex,
  200. _pagesize = U.MD.R.data.PageSize;
  201. if (U.MD.R.data.PageIndex <= U.MD.R.data.AllCount) {
  202. U.MD.R.getReplyData(_pageindex, _pagesize, function (data) {//获取评论数据
  203. U.MD.R.data.AllCount = Math.ceil(data[0][0].allcount / U.MD.R.data.PageSize);
  204. U.MD.R.printComment($("#U_MD_R_content_user_comment")[0], 1, data, false, false, false); //打印数据
  205. });
  206. }
  207. else {
  208. U.selectEl(_btn).hide();
  209. }
  210. }
  211. }
  212. }
  213. else {
  214. // _btn.innerHTML = "还没有人评论";
  215. }
  216. }
  217. /**
  218. * 打印一级评论
  219. * @param {object} 评论数据
  220. * @param {element} 追加元素
  221. * @param {number} 用于判断层级而显示指定内容
  222. * @param {boolean}元素插入类型
  223. * @param {boolean} 是否需要回复功能,默认为false
  224. * @param {boolean} 是否需要查看更多,用于区分设置查看更多类型
  225. */
  226. U.MD.R.printComment = function (el, type, data, appendtype, isreply, readmore) {
  227. var _count = U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Reply_SelectTypeReplyEnable", U.MD.R.data.PID]);
  228. if (_count.value[0].ProjectReplyEnable == 1) {
  229. var _el = el,
  230. _type = type,
  231. _data = data,
  232. _appendtype = appendtype,
  233. _isreply = isreply,
  234. _readmore = readmore,
  235. _shownum;
  236. for (var i = 0; i < data[0].length; i++) {//遍历评论数据
  237. if (readmore) {
  238. _shownum = data[0][i].TopReplyNum;
  239. }
  240. else {
  241. _shownum = U.Json.select(_data[2], { ReplyID: _data[0][i].ReplyID }).length > 0 ? U.Json.select(_data[2], { ReplyID: _data[0][i].ReplyID })[0].AllReplyNum : "0"; //评论子集(所有子集)的评论数
  242. }
  243. U.MD.R.printCommentHtml(_el, _type, {
  244. rid: _data[0][i].ReplyID, //评论id
  245. rpid: _data[0][i].ReplyParentID, //评论父级id
  246. deep: _data[0][i].ReplyDeep, //评论深度
  247. topid: _data[0][i].ReplyID, //评论顶级id
  248. uid: _data[0][i].UserID, //评论用户id
  249. un: _data[0][i].UserName, //评论用户名
  250. tx: _data[0][i].ReplyUserThumbnailImageHead, //评论用户头像
  251. time: _data[0][i].ReplyAddTime, //评论时间
  252. content: _data[0][i].ReplyContent, //评论内容
  253. likesnum: U.Json.select(_data[1], { ReplyID: _data[0][i].ReplyID })[0], //评论点赞数
  254. shownum: _shownum
  255. }, _appendtype, _isreply, _readmore);
  256. }
  257. } else {
  258. var _btn = $$("div", { "className": "U_MD_R_content_loading" }, U.selectEl(".U_MD_R_comment")[0]);
  259. _btn.innerHTML = "该评论系统已关闭";
  260. U.selectEl("#U_MD_R_content_loading")[0].innerHTML = '';
  261. }
  262. }
  263. /**
  264. * 打印二级评论,用于区分用户点击回复或者查看更多。
  265. * @param {sring} 评论id
  266. * @param {boolean} 是否需要查看更多,用于区分设置查看更多类型
  267. */
  268. U.MD.R.viewComment = function (rid, type) {
  269. if (US.userInfo.userid) {
  270. var
  271. _rid = rid, //父级id
  272. _form, //窗体变量
  273. _data, //数据
  274. _firstbox, //一级评论内容区域
  275. _secondbox, //二级评论内容区域
  276. _thirdbox, //三级评论内容区域
  277. _type = type;
  278. _form = new U.UF.UI.form('', $$("div", { "style": { "padding": "20px"} }), {
  279. "style": {
  280. "width": "800px",
  281. "height": "600px"
  282. }
  283. });
  284. U.A.Request("http://cd.1473.cn/net", ["db.1473.cn", "UseStudio_Reply", "Reply_SelectThisReply", _rid], function (r) {//根据评论id,获取此评论,此评论点赞数,以及子目录下所有的评论还有点赞数
  285. _data = r.value;
  286. U.MD.R.printComment(_form.content, 1, _data, true, true, true); //打印一级目录
  287. if (_type) {
  288. U.selectEl(_form.content).find(".U_MD_R_content_box_content_edit").show();
  289. }
  290. _firstbox = $$("div", { "className": "U_MD_R_content_warp_box" }, _form.content);
  291. //创建二级目录
  292. for (var i = 0; i < _data[1].length; i++) {
  293. _secondbox = U.MD.R.printCommentHtml(_firstbox, 2, {
  294. rid: _data[1][i].ReplyID,
  295. rpid: _data[1][i].ReplyParentID,
  296. deep: _data[1][i].ReplyDeep,
  297. topid: _data[1][i].ReplyTopID,
  298. uid: _data[1][i].UserID,
  299. tx: _data[1][i].ReplyUserThumbnailImageHead,
  300. un: _data[1][i].UserName,
  301. time: _data[1][i].ReplyAddTime,
  302. content: _data[1][i].ReplyContent,
  303. likesnum: U.Json.select(_data[3], { ReplyID: _data[1][i].ReplyID })[0]
  304. }, false, true, true);
  305. //创建三级以下目录(包括三级)
  306. _thirdbox = $$("div", { "className": "U_MD_R_content_warp_box" }, _secondbox);
  307. U.selectEl(_thirdbox).attr({ "data-replyid": _data[1][i].ReplyID });
  308. for (var j = 0; j < _data[2].length; j++) {
  309. if (_data[1][i].ReplyID == _data[2][j].ReplyParentID) {
  310. U.MD.R.printCommentHtml(_thirdbox, 3, {
  311. rid: _data[2][j].ReplyID,
  312. rpid: _data[2][j].ReplyParentID,
  313. deep: _data[2][j].ReplyDeep,
  314. topid: _data[2][j].ReplyTopID,
  315. uid: _data[2][j].UserID,
  316. tx: _data[2][j].ReplyUserThumbnailImageHead,
  317. un: _data[2][j].UserName,
  318. time: _data[2][j].ReplyAddTime,
  319. content: _data[2][j].ReplyContent,
  320. likesnum: U.Json.select(_data[3], { ReplyID: _data[2][j].ReplyID })[0],
  321. replyinfo: {
  322. uid: _data[2][j].uid, //评论的用户id
  323. un: _data[2][j].un, //评论的用户名
  324. tx: _data[2][j].tx//评论的头像
  325. }
  326. }, false, true, true);
  327. }
  328. }
  329. }
  330. });
  331. }
  332. else {
  333. U.Alert("请先登录");
  334. }
  335. }
  336. /**
  337. * 打印评论数据内容
  338. * @param {object} 评论数据
  339. * @param {element} 追加元素
  340. * @param {object} 用于判断层级而显示指定内容
  341. * object={
  342. * rid,//评论id
  343. * rpid,//评论父级id
  344. * deep,//评论深度
  345. * topid,//评论顶级id
  346. * uid,//评论用户id
  347. * un,//评论用户名
  348. * tx,//评论用户头像
  349. * time,//评论时间
  350. * content,//评论内容
  351. * likesnum,//评论点赞数
  352. * shownum,//评论子集(所有子集)的评论数
  353. * }
  354. * @param {boolean} 元素插入类型
  355. * @param {boolean} 是否需要回复功能,默认为false
  356. * @param {boolean} 是否需要查看更多,用于区分设置查看更多类型
  357. */
  358. U.MD.R.printCommentHtml = function (el, type, data, appendtype, isreply, readmore) {
  359. var _data = data,
  360. _el = el,
  361. _type = type,
  362. // _eltype = obj.eltype ? obj.eltype : false,
  363. // _showmore = obj.showmore,
  364. _rid = _data.rid, //评论id
  365. _rpid = _data.rpid, //评论父级id
  366. _deep = _data.deep, //评论顶级id
  367. _topid = _data.topid, //评论顶级id
  368. _uid = _data.uid, //评论用户id
  369. _tx = _data.tx, //评论用户名
  370. _un = _data.un, //评论用户头像
  371. _time = _data.time, //评论时间
  372. _datacontent = _data.content, //评论内容
  373. _likesnumjson = _data.likesnum, //点赞数
  374. _showmoretxtjson = _data.shownum, //评论子集(所有子集)的评论数
  375. _replyinfo_uid = _data.replyinfo ? _data.replyinfo.uid : "", //评论的用户id
  376. _replyinfo_un = _data.replyinfo ? _data.replyinfo.un : "", //评论的用户名
  377. _replyinfo_tx = _data.replyinfo ? _data.replyinfo.tx : "", //评论的头像
  378. _appendtype = appendtype, //评论插入的方式,如果为true,那么就插入到所有评论的第一个(用于以及评论和二级评论),如果为false,那么就插入到最后一个
  379. _isreply = isreply, //点击回复按钮,是否是弹出回复框,还是弹出查看更多,默认为false,
  380. _readmore = readmore, //点击获取是
  381. _box, //评论最外层元素
  382. _info, //评论内层元素
  383. _head, //评论用户头像最外层
  384. _headimg, //评论用户头像
  385. _content, //评论头像右侧内容
  386. _content_top, //评论右侧内容-头部用户名区域
  387. _username, //评论右侧内容-头部用户名区域-用户名
  388. _commenttime, //评论右侧内容-头部用户名区域-评论时间
  389. _text,
  390. _content_bottom, //评论右侧内容-底部区域
  391. _likeswarp, //评论右侧内容-底部区域-点赞最外层
  392. _likesimg, //评论右侧内容-底部区域-点赞图片
  393. _likesnum, //评论右侧内容-底部区域-点赞数
  394. _replywarp, //评论右侧内容-底部区域-回复最外层
  395. _showmorewarp, //评论右侧内容-底部区域-查看更多最外层
  396. _showmoretext, //评论右侧内容-底部区域-查看更多文字元素
  397. _position,
  398. _contenteditable, //创建子集评论-评论操作区域最外层
  399. _bottom, //创建子集评论-评论操作区域内层
  400. _picturewarp, //创建子集评论-评论操作区域-图片最外层
  401. _picture, //创建子集评论-评论操作区域-图片元素
  402. _input, //创建子集评论-评论操作区域-上传input
  403. _button, //创建子集评论-评论操作区域-发布按钮
  404. _img_warp, //创建子集评论-评论操作区域-图片显示区域
  405. _childrenbox; //用于存放子集评论
  406. _box = $$("div", { "className": "U_MD_R_content_box" }); //创建内容盒子
  407. if (_appendtype) { //判断插入类型是否为true,如果为true,那么就插入到所有评论的第一个(用于以及评论和二级评论),如果为false,那么就插入到最后一个
  408. U.selectEl(_el).append(_box, 0, U.selectEl(_el)[0].firstChild);
  409. }
  410. else {//如果为false,那么就插入到最后一个
  411. U.selectEl(_el).append(_box);
  412. }
  413. _info = $$("div", { "className": "U_MD_R_content_box_warp" }, _box); //创建信息div
  414. U.selectEl(_info).attr({//给评论内层设置评论id、评论父级id、评论深度、评论顶级id、评论用户id。用于回复时获取信息。
  415. "data-rid": _rid, //评论id
  416. "data-RPID": _rpid, //评论父级id
  417. "data-RD": _deep, //评论深度
  418. "data-RBID": _topid, //评论顶级id
  419. "data-RPUID": _uid//评论用户id
  420. });
  421. _head = $$("div", { "className": "U_MD_R_content_box_userhead" }, _info); //评论用户头像最外层
  422. _headimg = $$("img", {//评论用户头像
  423. "src": _tx,
  424. onerror: "U.MD.R.imgError(this)"
  425. }, _head);
  426. _content = $$("div", {//评论头像右侧内容
  427. "className": "U_MD_R_content_box_content",
  428. style: { width: "calc(100% - 40px - 20px )" }
  429. }, _info); //创建右侧div
  430. _content_top = $$("div", { "className": "U_MD_R_content_box_content_top" }, _content); //评论右侧内容-头部用户名区域
  431. _username = $$("div", {//评论右侧内容-头部用户名区域-用户名
  432. "className": "U_MD_R_content_box_content_top_name",
  433. "innerHTML": _un
  434. }, _content_top);
  435. if (_type == 3) {//如果为三级目录以下,那么就修改显示的用户名
  436. _username.innerHTML = _un + '回复@' + _replyinfo_un;
  437. }
  438. _commenttime = $$("div", {//评论右侧内容-头部用户名区域-评论时间
  439. "className": "U_MD_R_content_box_content_top_time",
  440. "innerHTML": _time
  441. }, _content_top);
  442. _text = $$("div", { "className": "U_MD_R_content_box_content_text", "innerHTML": _datacontent }, _content); //创建内容区域
  443. if ($(_text).find("img").length > 0) {
  444. U.selectEl(_text).find("img")[0].onclick = function () {
  445. // U.MD.UI.picture([this.src, this.src, this.src], 2);
  446. U.MD.UI.picture([this.src], 0);
  447. U.selectEl("#U_MD_UI_PictureForm").css("position", "fixed");
  448. U.UF.F.topWindow($('#U_MD_UI_PictureForm')[0], true);
  449. }
  450. }
  451. _content_bottom = $$("div", { "className": "U_MD_R_content_box_content_bottom" }, _content); //评论右侧内容-底部区域
  452. _likeswarp = $$("div", { "className": "U_MD_R_content_box_content_bottom_likeswarp" }, _content_bottom); //评论右侧内容-底部区域-点赞最外层
  453. _likeswarp.onclick = function () {//设置点赞事件
  454. U.MD.R.like(this, _rid, US.userInfo.userid);
  455. }
  456. _likesimg = $$("img", { "src": "/img/reply/NOFabulous.png" }, _likeswarp); //评论右侧内容-底部区域-点赞图片
  457. _likesnum = $$("div", {//评论右侧内容-底部区域-点赞数
  458. "className": "U_MD_R_content_box_content_bottom_likeswarp_text",
  459. "innerHTML": 0
  460. }, _likeswarp);
  461. if (_likesnumjson) {//如果有点赞数据,那么修改点赞数,并且修改图片。
  462. _likesnum.innerHTML = _likesnumjson.ReplyNum;
  463. _likesimg.src = "/img/reply/Fabulous.png";
  464. }
  465. _replywarp = $$("div", { "className": "U_MD_R_content_box_content_bottom_replywarp" }, _content_bottom); //评论右侧内容-底部区域-回复最外层
  466. if (_readmore) {//点击回复按钮,是否是弹出回复框,还是弹出查看更多,默认为false。如果为true,在元素下方显示出评论操作元素。
  467. _replywarp.onclick = function () {
  468. U.MD.R.subsetReply(this);
  469. }
  470. }
  471. else {
  472. _replywarp.onclick = function () {//如果为false,弹出一个窗体。
  473. U.MD.R.viewComment(_rid, true);
  474. }
  475. }
  476. $$("img", {//创建回复图片
  477. "src": "/img/reply/reply.png"
  478. }, _replywarp);
  479. $$("div", {//创建回复按钮
  480. "innerHTML": "回复",
  481. "className": "U_MD_R_content_box_content_bottom_replywarp_text"
  482. }, _replywarp);
  483. if (_type == 1) {//如果类型为1,并且点击回复后弹出窗体的,那么显示查看更多。
  484. _showmorewarp = $$("div", { "className": "U_MD_R_content_box_content_bottom_showmorewarp" }, _content_bottom);
  485. $$("img", {
  486. "src": "/img/reply/list.png"
  487. }, _showmorewarp);
  488. _showmoretext = $$("div", {
  489. "className": "U_MD_R_content_box_content_bottom_showmore_text"
  490. }, _showmorewarp);
  491. if (_readmore) {
  492. _showmoretext.className = "U_MD_R_content_box_content_bottom_showmore_text U_MD_R_content_box_content_bottom_showmore_text_secondary"
  493. _showmoretext.innerHTML = _showmoretxtjson ? "共有(" + "<span>" + _showmoretxtjson + "</span>" + ")条评论" : "没有评论(" + "<span>0</span>" + ")";
  494. }
  495. else {
  496. _showmoretext.className = "U_MD_R_content_box_content_bottom_showmore_text U_MD_R_content_box_content_bottom_showmore_text_important"
  497. _showmoretext.innerHTML = _showmoretxtjson ? "查看更多(" + "<span>" + _showmoretxtjson + "</span>" + ")" : "查看更多(" + "<span>" + 0 + "</span>" + ")";
  498. _showmorewarp.onclick = function () {
  499. U.MD.R.viewComment(_rid, false);
  500. }
  501. }
  502. }
  503. if (_type == 1 && !readmore && U.selectEl(".U_MD_R_content_loading")[0]) {
  504. if (U.MD.R.data.PageIndex < U.MD.R.data.AllCount) {
  505. U.selectEl(".U_MD_R_content_loading")[0].innerHTML = "点击加载更多评论";
  506. }
  507. else {
  508. U.selectEl(".U_MD_R_content_loading").hide();
  509. }
  510. }
  511. if (_type == 2 || _type == 3 || (_type == 1 && readmore)) {//如果是2级和3级以下,那么就创建操作区域。
  512. _contenteditable = $$("div", {//创建子集评论-评论操作区域最外层
  513. "className": "U_MD_R_content_box_content_edit",
  514. "style": { "display": "none" }
  515. }, _content);
  516. _replyinput = $$("div", { "className": "U_MD_R_Reply_Content", "contenteditable": "true" }, _contenteditable); //创建回复元素
  517. _bottom = $$("div", { "className": "U_MD_R_content_operation_right_bottom" }, _contenteditable); //创建子集评论-评论操作区域内层
  518. $$("div", {//创建表情包按钮
  519. "className": "U_MD_R_content_operation_right_bottom_emoji",
  520. "onclick": function () {
  521. U.UF.EV.stopBubble();
  522. U.MD.UI.face(this, _replyinput);
  523. U.selectEl(this)[0].append($("#U_MD_UI_face")[0]);
  524. U.selectEl("#U_MD_UI_face").css({ "position": "relative", "height": "140px", "overflow-y": "scroll", "top": "-150px", "width": "450px", "display": "block" });
  525. }
  526. }, _bottom);
  527. _picturewarp = $$("div", { "className": "U_MD_R_content_operation_right_bottom_picturewarp" }, _bottom); //创建子集评论-评论操作区域-图片最外层
  528. _picture = $$("img", { src: "/img/reply/img.png" }, _picturewarp); //创建子集评论-评论操作区域-图片元素
  529. _input = $$("input", { "type": "file" }, _picturewarp); //创建子集评论-评论操作区域-上传input
  530. _input.onchange = function () {//赋予上传事件
  531. U.MD.R.uploadImages(this, _img_warp);
  532. }
  533. _button = $$("div", {////创建子集评论-评论操作区域-发布按钮
  534. "className": "U_MD_R_content_operation_right_bottom_release",
  535. "innerHTML": "发表评论"
  536. }, _bottom); //内容发布
  537. _button.onclick = function () {//赋予时间
  538. if (_type == 1) {
  539. _position = 2;
  540. }
  541. else if (_type == 2) {
  542. _position = 3;
  543. }
  544. else if (_type == 3) {
  545. _position = 4;
  546. }
  547. U.MD.R.release(_info, _type, false, _position);
  548. }
  549. _img_warp = $$("div", { "className": "U_MD_R_content_operation_right_bottom_imgloadbox U_MD_R_Reply_Image" }, _contenteditable); //创建子集评论-评论操作区域-图片显示区域
  550. if (_type != 3) {
  551. _childrenbox = $$("div", { "className": "U_MD_R_content_comment" }, _box); //内容盒子
  552. }
  553. return _childrenbox; //返回元素
  554. }
  555. }
  556. /**
  557. * 图片上传函数
  558. * @param {element} input 元素
  559. * @param {element} 上传成功后,图片插入的位置。
  560. */
  561. U.MD.R.uploadImages = function (input, el) {
  562. var _el = el, _imgwarp, _img, _filetype, _imgtype = /.*(jpg|png|gif|jpeg|JPG|PNG|GIF|JPEG)$/;
  563. U.selectEl(_el)[0].innerHTML = "";
  564. _imgwarp = $$("div", {}, _el);
  565. _img = $$("img", {//创建img
  566. "src": "/img/Reply/loading.gif",
  567. "style": { "width": "100px", "height": "100px", "margin-right": "10px" }
  568. }, _imgwarp);
  569. U.UF.UP.inputUpload([input], "http://disk.1473.cn/USUpfile.ashx?typename=UseStudioEditor&UserId=FA92AAC5-4134-449F-9659-0DC12F4F68E9", function (r) {
  570. _filetype = r.value[0].split(".")[1];
  571. if (_filetype.match(_imgtype)) {//如果获取的文件是符合的文件类型进行上传
  572. U.selectEl(_imgwarp).remove();
  573. _imgwarp = $$("div", { "className": "U_MD_R_content_operation_right_bottom_imgloadbox_warp" }, _el);
  574. $$("img", { "src": "http://fs.1473.cn/" + r.value[0] }, _imgwarp); //创建img
  575. $$("div", { "className": "closebtn", "onclick": "U.MD.R.uploadImages.close(this)" }, _imgwarp);
  576. U.alert("上传成功");
  577. } else {//否则提醒用户选择上传图片文件
  578. U.alert("请上传图片文件");
  579. return;
  580. }
  581. }, []);
  582. }
  583. /**
  584. * 图片关闭函数
  585. * @param {element} 事件源
  586. */
  587. U.MD.R.uploadImages.close = function (el) {
  588. U.selectEl(el).Parent().remove();
  589. }
  590. /**
  591. * 二级以下(包括二级、三级等等)评论点击回复后显示隐藏操作区域
  592. * @param {element} 事件源
  593. */
  594. U.MD.R.subsetReply = function (el) {
  595. // U.selectEl(el)
  596. var _el = U.selectEl($(el).Parent(2)).find(".U_MD_R_content_box_content_edit");
  597. if (_el[0].style.display == "block") {
  598. _el.hide();
  599. }
  600. else {
  601. _el.show();
  602. }
  603. }
  604. /**
  605. * 发表评论插入函数
  606. */
  607. U.MD.R.release = function (el, type, isreply, position) {//发表评论函数
  608. if (US.userInfo.userid) {
  609. var _el = el,
  610. _type = type,
  611. _isreply = isreply,
  612. _position = position,
  613. _content = U.selectEl(_el).find(".U_MD_R_Reply_Content")[0],
  614. _imgwarp = U.selectEl(_el).find(".U_MD_R_Reply_Image"),
  615. _uid = US.userInfo.userid,
  616. _un = US.userInfo.UserName,
  617. _utx = "http://fs.1473.cn/" + US.userInfo.UserImageHead,
  618. _box;
  619. if (_content.innerHTML.trim() != "" || _imgwarp.find("img").length > 0) {
  620. var _rid = Guid.newGuid(),
  621. _rpid = U.selectEl(el).attr("data-rid"),
  622. _pid = U.MD.R.data.PID,
  623. _aid = U.MD.R.data.AID,
  624. _rc = "",
  625. _rip = US.userInfo.RegisterIP,
  626. _url = U.MD.R.data.URL,
  627. _ra = null,
  628. _rd = U.selectEl(el).attr("data-rd"),
  629. _rbid = U.selectEl(el).attr("data-rbid"),
  630. _rpuid = U.selectEl(el).attr("data-rpuid"),
  631. _re = 1;
  632. if (position == 1) {
  633. _rd = 1;
  634. }
  635. else if (position == 2 || position == 3) {
  636. _rd = parseInt($(el).attr("data-rd")) + 1;
  637. }
  638. else {
  639. _rd = 3;
  640. _rpid = U.selectEl(el).attr("data-rpid");
  641. }
  642. if ($(_imgwarp).find("img").length > 0) {
  643. _rc = _content.innerHTML.trim() + _imgwarp.find("img")[0].outerHTML;
  644. }
  645. else {
  646. _rc = _content.innerHTML;
  647. }
  648. U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Reply_InsertReply", _rid, _rpid, _pid, _aid, _uid, _un, _utx, _rc, _rip, _url, _ra, _rd, _rpuid, _re,U.MD.R.getNowFormatDate()], function (r) {
  649. var _data = r.value[0], _appendtype, _readmore,
  650. _more = U.selectEl("div[data-rid='" + _data.ReplyTopID + "']").find(".U_MD_R_content_box_content_bottom_showmore_text_important span")[0],
  651. _more1 = U.selectEl("div[data-rid='" + _data.ReplyTopID + "']").find(".U_MD_R_content_box_content_bottom_showmore_text_secondary span")[0];
  652. U.selectEl(_el).find(".U_MD_R_Reply_Content")[0].innerHTML = "";
  653. U.UF.E.initEditor($(_el).find(".U_MD_R_Reply_Content")[0]); //调用函数
  654. U.selectEl(_el).find(".U_MD_R_Reply_Image")[0].innerHTML = "";
  655. if (_position == 1) {
  656. _readmore = false;
  657. _appendtype = true;
  658. _el = U.selectEl("#U_MD_R_content_user_comment")[0];
  659. }
  660. else {
  661. _readmore = true;
  662. _val = _more.innerText;
  663. _val1 = _more1.innerText;
  664. if (_position == 2) {
  665. _el = U.selectEl(_el).Parent().nextSibling;
  666. _type = 2;
  667. _appendtype = true;
  668. }
  669. if (_position == 3) {
  670. if ($($(_el)[0].nextSibling).find(".U_MD_R_content_warp_box").length > 0) {
  671. _el = U.selectEl($(_el)[0].nextSibling).find(".U_MD_R_content_warp_box");
  672. }
  673. else {
  674. _el = $$("div", { "className": "U_MD_R_content_warp_box" }, U.selectEl($(_el)[0].nextSibling)[0]);
  675. //$(_el).attr({"data-replyid": _data[1][i].ReplyID});
  676. }
  677. _type = 3;
  678. }
  679. if (_position == 4) {
  680. _el = U.selectEl($(_el).Parent()).Parent();
  681. _type = 3;
  682. }
  683. _more.innerText = ++_val;
  684. _more1.innerText = ++_val1;
  685. U.selectEl($(_content).Parent()).hide();
  686. }
  687. var _box = U.MD.R.printCommentHtml(_el, _type, {
  688. rid: _data.ReplyID,
  689. rpid: _data.ReplyParentID,
  690. deep: _data.ReplyDeep,
  691. topid: _data.ReplyTopID,
  692. uid: _data.UserID,
  693. tx: _data.ReplyUserThumbnailImageHead,
  694. un: _data.UserName,
  695. time: _data.ReplyAddTime,
  696. content: _data.ReplyContent,
  697. replyinfo: {
  698. uid: _data.uid, //评论的用户id
  699. un: _data.un, //评论的用户名
  700. tx: _data.tx//评论的头像
  701. }
  702. }, _appendtype, _isreply, _readmore);
  703. // if (_position == 3) {
  704. // var _box1 = $$("div", {"className": "U_MD_R_content_warp_box"}, _box);
  705. // U.selectEl(_box1).attr({"data-replyid": _data[1][i].ReplyID});
  706. // }
  707. U.alert("评论成功");
  708. }
  709. );
  710. }
  711. else {
  712. U.alert("请输入评论内容");
  713. }
  714. }
  715. else {
  716. U.Alert("请先登录");
  717. }
  718. }
  719. /**
  720. * 点赞函数
  721. * @param {element} 事件源
  722. * @param {string} 评论id
  723. * @param {string} 用户id
  724. */
  725. U.MD.R.like = function (e, rid, uid) {
  726. if (US.userInfo.userid) {
  727. var _el = e, _rid = rid, _uid = uid;
  728. U.A.Request("http://cd.1473.cn/net", ["db.1473.cn", "UseStudio_Reply", "Reply_SelectRepeatLikes", _rid, _uid], function (r) {
  729. var _img = U.selectEl(_el).find("img")[0],
  730. _text = U.selectEl(_el).find(".U_MD_R_content_box_content_bottom_likeswarp_text")[0],
  731. _val = parseInt(_text.innerHTML);
  732. if (r.value[0].mode == 0) {
  733. _img.src = "/img/reply/NOFabulous.png";
  734. _text.innerHTML = --_val;
  735. }
  736. else {
  737. _img.src = "/img/reply/Fabulous.png";
  738. _text.innerHTML = ++_val;
  739. }
  740. });
  741. }
  742. else {
  743. U.Alert("请先登录");
  744. }
  745. }
  746. /**
  747. * 图片错误所执行的函数
  748. * @param {element} 事件源
  749. */
  750. U.MD.R.imgError = function (el) {
  751. U.selectEl(el)[0].src = "/img/UserHead/UseHead.jpg";
  752. }
  753. /**
  754. * 函数作用:调用登录函数
  755. */
  756. U.MD.R.login = function () {
  757. if ($("#U_MD_HomeC_Pop")[0]) {
  758. U.UF.F.windowTopCenter($("#U_MD_HomeC_Pop")[0]);
  759. }
  760. else {
  761. U.UF.CD.loadPageCrossDomain(function () { });
  762. U.MD.U.L.setLoginCallBack(function () {
  763. U.MD.R.login.cb();
  764. });
  765. }
  766. }
  767. /**
  768. * cookie登录,如果登录成功,则修改头像以及用户名
  769. */
  770. U.MD.R.login.cookieLogin = function () {
  771. if (U.UF.Cookie.get("usestudiosso") && U.UF.Cookie.get("usestudiosso", "userid")[0]) {
  772. U.UF.CD.loadPageCrossDomain(function () {
  773. U.MD.U.L.loginCallBack = function () {
  774. U.MD.R.login.cb();
  775. }
  776. });
  777. }
  778. }
  779. /**
  780. * 登录之后的回调函数
  781. */
  782. U.MD.R.login.cb = function () {
  783. U.selectEl(".U_MD_R_content_operation_userhead img")[0].src = 'http://fs.1473.cn/' + US.userInfo.UserThumbnailImageHead; //用户登录后的操作
  784. U.selectEl(".U_MD_R_content_operation_userlogin")[0].innerHTML = US.userInfo.UserName; //设置登录用户头像,登录用户名等操作
  785. }
  786. //获取当前时间
  787. U.MD.R.getNowFormatDate = function () {
  788. var date = new Date();
  789. var seperator1 = "-";
  790. var seperator2 = ":";
  791. var month = date.getMonth() + 1;
  792. var strDate = date.getDate();
  793. if (month >= 1 && month <= 9) {
  794. month = "0" + month;
  795. }
  796. if (strDate >= 0 && strDate <= 9) {
  797. strDate = "0" + strDate;
  798. }
  799. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
  800. + " " + date.getHours() + seperator2 + date.getMinutes()
  801. + seperator2 + date.getSeconds();
  802. return currentdate;
  803. }