main.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. $('html').css('height','100%');
  2. $('body').css('height','100%');
  3. $.fn.autoTextarea = function(options) {
  4. var defaults={
  5. maxHeight:null,
  6. minHeight:24
  7. };
  8. var opts = $.extend({},defaults,options);
  9. return $(this).each(function() {
  10. $(this).bind("paste cut keydown keyup focus blur",function(){
  11. var height,style=this.style;
  12. this.style.height = opts.minHeight + 'px';
  13. if (this.scrollHeight > opts.minHeight) {
  14. if (opts.maxHeight && this.scrollHeight > opts.maxHeight) {
  15. height = opts.maxHeight;
  16. style.overflowY = 'scroll';
  17. } else {
  18. height = this.scrollHeight;
  19. style.overflowY = 'hidden';
  20. }
  21. style.height = height + 'px';
  22. }
  23. });
  24. });
  25. };
  26. $('.thumbnail img').picLazyLoad();
  27. var specialId = (function () {
  28. var special_id = $('body').attr('data-special_id');
  29. return special_id;
  30. })();
  31. var Comment_type = '';
  32. var need_scroll = true;
  33. var event = function (obj, eventType, callback) {
  34. obj.live(eventType, callback);
  35. };
  36. var ajax = function (url, callback, error) {
  37. $.ajax({
  38. type: "get",
  39. async: false,
  40. url: url,
  41. dataType: "jsonp",
  42. jsonp: "callback",
  43. jsonpCallback: "flightHandler",
  44. success: callback,
  45. error: error || function () {
  46. $('.loader').hide();
  47. alert('网络错误');
  48. }
  49. });
  50. };
  51. var GetQueryString = function(name) {
  52. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  53. var r = window.location.search.substr(1).match(reg);
  54. if (r != null)return unescape(r[2]);
  55. return null;
  56. };
  57. var statShow = function () {
  58. if ($('.percentage').length > 0) {
  59. setTimeout(function () {
  60. for (var i = 0; i < $('.percentage').length; i++) {
  61. var num = $('.percentage')[i].innerHTML;
  62. $('.stat')[i].style.width = num;
  63. }
  64. }, 300);
  65. clearInterval(a);
  66. }
  67. };
  68. var a = setInterval(statShow, 10);
  69. var Vote = function (type) {
  70. var _self = this;
  71. this.type = type;
  72. this.answer = [];
  73. this.getAnswers = function () {
  74. return this.answer;
  75. };
  76. this.obj = $('input[name="submit_vote"]');
  77. this.M = function () {
  78. var options = function () {
  79. var options = [];
  80. for (var i = 0; i < $('.vote_options label').length; i++) {
  81. var option = $.trim($('.vote_options label').eq(i).text());
  82. options.push(option);
  83. }
  84. return options;
  85. };
  86. var sum_num = function (datas) {
  87. var sum = 0;
  88. for (var i = 0; i < datas.length; i++) {
  89. sum += parseFloat(datas[i]);
  90. }
  91. return sum;
  92. };
  93. return {
  94. result: function (data) {
  95. var option_items = options();
  96. var sum = sum_num(data);
  97. var vote_res = [];
  98. for (var i = 0; i < data.length; i++) {
  99. var g = {};
  100. g.name = option_items[i];
  101. g.num = parseInt(data[i]);
  102. g.percentage = data[i] ? Math.round(data[i] / sum * 100) : 0;
  103. vote_res.push(g);
  104. }
  105. return vote_res;
  106. }
  107. }
  108. };
  109. this.V = function (datas) {
  110. var resData = datas;
  111. var html = '<div class="results">';
  112. for (var i = 0; i < resData.length; i++) {
  113. html += '<div class="result">' +
  114. '<div class="result_option">' + resData[i].name + '</div>' +
  115. '<div class="status">' +
  116. '<div class="status_line">' +
  117. '<div class="stat"></div>' +
  118. '<div class="status_bg"></div>' +
  119. '</div>' +
  120. '<span class="num">' + resData[i].num + '票</span>' +
  121. '<span class="percentage">' + resData[i].percentage + '%</span>' +
  122. '</div>' +
  123. '</div>';
  124. }
  125. html += '</div>';
  126. return html;
  127. };
  128. this.C = function () {
  129. event(_self.obj, 'change', function () {
  130. switch (_self.type) {
  131. case 0:
  132. case 1 : {
  133. _self.answer = [];
  134. $.each(_self.obj, function () {
  135. if (this.checked) {
  136. _self.answer.push($(this).val());
  137. }
  138. });
  139. break;
  140. }
  141. case 2: {
  142. var val = $(this).val();
  143. if ($(this).prop('checked')) {
  144. if (_self.answer.length >= 2) {
  145. for (var g = 0; g < _self.obj.length; g++) {
  146. if (_self.obj.eq(g).val() == _self.answer[0]) {
  147. _self.obj.eq(g).prop('checked', false);
  148. _self.answer.splice(0, 1);
  149. _self.answer.push(val);
  150. break;
  151. }
  152. }
  153. }
  154. else {
  155. _self.answer = [];
  156. $.each(_self.obj, function () {
  157. if (this.checked) {
  158. _self.answer.push($(this).val());
  159. }
  160. });
  161. }
  162. }
  163. else {
  164. _self.answer = [];
  165. $.each(_self.obj, function () {
  166. if (this.checked) {
  167. _self.answer.push($(this).val());
  168. }
  169. });
  170. }
  171. }
  172. }
  173. });
  174. };
  175. };
  176. var Question = function (obj, handleType) {
  177. this.obj = obj;
  178. this.handleType = handleType;
  179. this.answer = [];
  180. this.getAnswer = function () {
  181. return this.answer;
  182. };
  183. this.C = function () {
  184. var _self = this;
  185. _self.obj.on('change', function () {
  186. switch (_self.handleType) {
  187. case 0:
  188. case 1 : {
  189. _self.answer = [];
  190. $.each(_self.obj, function () {
  191. if (this.checked) {
  192. _self.answer.push($(this).val());
  193. }
  194. });
  195. break;
  196. }
  197. case 2: {
  198. var val = $(this).val();
  199. if ($(this).prop('checked')) {
  200. if (_self.answer.length >= 2) {
  201. for (var g = 0; g < _self.obj.length; g++) {
  202. if (_self.obj.eq(g).val() == _self.answer[0]) {
  203. _self.obj.eq(g).prop('checked', false);
  204. _self.answer.splice(0, 1);
  205. _self.answer.push(val);
  206. break;
  207. }
  208. }
  209. }
  210. else {
  211. _self.answer = [];
  212. $.each(_self.obj, function () {
  213. if (this.checked) {
  214. _self.answer.push($(this).val());
  215. }
  216. });
  217. }
  218. }
  219. else {
  220. _self.answer = [];
  221. $.each(_self.obj, function () {
  222. if (this.checked) {
  223. _self.answer.push($(this).val());
  224. }
  225. });
  226. }
  227. break;
  228. }
  229. }
  230. });
  231. }
  232. };
  233. var QuestionList = function () {
  234. var question_items = [];
  235. (function (question_items) {
  236. var questions = $('.question').length;
  237. var num = 0;
  238. var question_nums = 'q' + num;
  239. for (var j = 0; j < questions; j++) {
  240. question_nums = new Question($('input[name="question' + num + '"]'), parseInt($('.question_type').eq(j).attr('data-type')));
  241. question_items.push(question_nums);
  242. question_nums.C();
  243. num++;
  244. }
  245. })(question_items);
  246. this.getAnswers = function () {
  247. var answers = [];
  248. for (var i = 0; i < question_items.length; i++) {
  249. if (question_items[i].getAnswer().length == 0) {
  250. continue;
  251. }
  252. var question = {};
  253. question.index = i;
  254. question.answer = question_items[i].getAnswer();
  255. answers.push(question);
  256. }
  257. return answers;
  258. };
  259. };
  260. var ReplyItem = function (comment, members) {
  261. var proxy = function () {
  262. var getNickName = function (userId) {
  263. for (var i = 0; i < members.length; i++) {
  264. if (members[i]['member_id'] == userId) {
  265. return members[i]['nickname'];
  266. }
  267. }
  268. };
  269. var getAvatar = function (userId) {
  270. for (var i = 0; i < members.length; i++) {
  271. if (members[i]['member_id'] == userId) {
  272. return members[i]['avatar'];
  273. }
  274. }
  275. };
  276. var getTime = function (time) {
  277. var date = '';
  278. var location = parseInt(new Date().getTime()/1000);
  279. var diffHour = parseInt((location - time)/60/60);
  280. var diffMinutes = parseInt((location - time)/60);
  281. if(diffHour <= 0){
  282. if(diffMinutes >= 0 && diffMinutes < 5) {
  283. date = "刚刚";
  284. }
  285. else {
  286. date = diffMinutes + "分钟前";
  287. }
  288. }
  289. if(diffHour < 24 && diffHour > 0){
  290. date = diffHour + '小时前';
  291. }
  292. if(diffHour > 24){
  293. var milliseconds = time * 1000;//秒变微秒
  294. var dat = new Date(milliseconds);//生成日期
  295. var month = dat.getMonth() + 1; //取得月
  296. var date1 = dat.getDate(); //取得天
  297. var hour = dat.getHours();//取得小时
  298. var minutes = dat.getMinutes();//取得分钟
  299. if (hour < 10) {
  300. hour = '0' + dat.getHours();
  301. }
  302. if (minutes < 10) {
  303. minutes = '0' + dat.getMinutes();
  304. }
  305. date = month + '月' + date1 + '日' + hour + ':' + minutes;
  306. }
  307. return date;
  308. };
  309. return {
  310. getNickName: getNickName,
  311. getAvatar: getAvatar,
  312. getTime: getTime
  313. }
  314. };
  315. var commentdata = comment;
  316. var sub = '';
  317. var subnum = 0;
  318. if(comment) {
  319. var defaultSubNum = comment['sub_comments'];
  320. }
  321. var load_btn = '';
  322. var loadpage = 2;
  323. var isLike = function () {
  324. var like = '';
  325. if (commentdata['supported'] == false) {
  326. like = '<a href="javascript:void(0)" class="like_btn" data-comment_id="' + commentdata['comment_id'] + '">' +
  327. '<span class="like_num">' + commentdata['likes'] + '</span><span class="like_icon_null"></span></a>';
  328. }
  329. else {
  330. like = '<a href="javascript:void(0)" class="like_btn active" data-comment_id="' + commentdata['comment_id'] + '">' +
  331. '<span class="like_num">' + commentdata['likes'] + '</span><span class="like_icon_null like_icon"></span></a>';
  332. }
  333. return like;
  334. };
  335. var parentHTML = function () {
  336. var html = '<div class="comment_item parent_reply" data-comment_id="' + commentdata['comment_id'] + '">' +
  337. '<div class="subject">' +
  338. '<div class="subject_box">' +
  339. '<div class="subject_image">' +
  340. '<img src="' + proxy().getAvatar(commentdata['user_id']) + '" alt="熊猫美妆">' +
  341. '</div>' +
  342. '<div class="subject_name">' +
  343. '<p class="name reply_people" data-parent="true" data-comment_id="' + commentdata['comment_id'] + '">' + proxy().getNickName(commentdata['user_id']) + '</p>' +
  344. '<p class="time">' + proxy().getTime(commentdata['addtime']) + '</p>' +
  345. '</div>' +
  346. '</div>' +
  347. '<div class="like">' + isLike() +
  348. '</div>' +
  349. '</div>' +
  350. '<p class="msg">' + commentdata['content'] + sub +
  351. '</p>' + load_btn +
  352. '</div>';
  353. return html;
  354. };
  355. var subHTML = function (comment) {
  356. var subHtml = '<p class="reply">' +
  357. '<span class="reply_people" data-comment_id="' + comment['comment_id'] + '">' + proxy().getNickName(comment['user_id']) + '</span>' +
  358. '回复' +
  359. '<span class="reply_people" data-comment_id="' + comment['comment_id'] + '" data-response_id="' + comment['response_id'] + '">' +
  360. proxy().getNickName(comment['to_user']) + '</span>:' + comment['content'] + '</p>';
  361. return subHtml;
  362. };
  363. var empty = function () {
  364. var empty = '<p class="reply_empty">精彩评论虚位以待</p>';
  365. return empty;
  366. };
  367. return {
  368. exportHTML: function () {
  369. return parentHTML();
  370. },
  371. addSub: function (comment) {
  372. sub += subHTML(comment);
  373. },
  374. insert: function (comment) {
  375. return subHTML(comment);
  376. },
  377. empty: function () {
  378. $('.comment_list').append(empty());
  379. },
  380. addSubnum: function () {
  381. subnum++;
  382. },
  383. addLoadBtn: function () {
  384. load_btn = '<div class="button_load_more" data-page="' + loadpage + '">查看更多评论</div>';
  385. },
  386. getLoadMore: function () {
  387. return defaultSubNum > subnum;
  388. }
  389. }
  390. };
  391. var ReplyList = function () {
  392. var created = function (replys) {
  393. var replyList = [];
  394. var replyIndex = replyList.length;
  395. if (!replys || replys['comments'].length == 0) {
  396. return;
  397. }
  398. for (var i = 0; i < replys['comments'].length; i++) {
  399. if (replys['comments'][i]['to_user'] == 0) {
  400. replyList.push(new ReplyItem(replys['comments'][i], replys['members']));
  401. replyIndex++;
  402. }
  403. else {
  404. replyList[replyIndex - 1].addSub(replys['comments'][i]);
  405. replyList[replyIndex - 1].addSubnum();
  406. }
  407. }
  408. return replyList;
  409. };
  410. var exportHTML = function (replyItem) {
  411. var datas = created(replyItem);
  412. if ($('.reply_empty').length > 0) {
  413. $('.reply_empty').css('display', 'none');
  414. }
  415. for (var i = 0; i < datas.length; i++) {
  416. if (datas[i].getLoadMore()) {
  417. datas[i].addLoadBtn();
  418. }
  419. $('.comment_list').append(datas[i].exportHTML());
  420. }
  421. };
  422. var specialReply = function (replyItem) {
  423. var datas = created(replyItem);
  424. if ($('.reply_empty').length > 0) {
  425. $('.reply_empty').css('display', 'none');
  426. }
  427. for (var i = 0; i < datas.length; i++) {
  428. $('.comment_list').prepend(datas[i].exportHTML());
  429. }
  430. };
  431. var curpage = 1;
  432. var isLoad = false;
  433. var getDate = function () {
  434. // window.location.protocol + "//" + window.location.host +'/mobile/index.php?act=member_ugc&op=comments&client_type=ajax&special_id='+specialId
  435. isLoad = true;
  436. $('.loader').show();
  437. ajax(window.location.protocol + "//" + window.location.host +'/mobile/index.php?act=member_ugc&op=comments&client_type=ajax&special_id=' + specialId + '&curpage=' + curpage, function (data) {
  438. $('.loader').hide();
  439. isLoad = false;
  440. if (data.code !== 200) {
  441. alert(data.message);
  442. }
  443. else {
  444. var replyDatas = data.datas;
  445. if (replyDatas['comments'].length == 0) {
  446. $('.comment_list').append(new ReplyItem().empty());
  447. return;
  448. }
  449. exportHTML(replyDatas);
  450. if(need_scroll && GetQueryString('need_scroll')) {
  451. need_scroll = false;
  452. $('.comment_label').trigger('click');
  453. }
  454. if (replyDatas.mobile_page['hasmore'] == true) {
  455. curpage++;
  456. document.getElementsByClassName('wrapper')[0].addEventListener('scroll',loadEvent);
  457. }
  458. else {
  459. document.getElementsByClassName('wrapper')[0].removeEventListener('scroll',loadEvent);
  460. }
  461. }
  462. }, function () {
  463. $('.loader').hide();
  464. $('.comment_list').append(new ReplyItem().empty());
  465. })
  466. };
  467. var loadEvent = function () {
  468. var scrollTop = $(this).scrollTop();
  469. var scrollHeight = $('.content').height();
  470. var windowHeight = $(this).offset().height;
  471. if ((scrollTop + windowHeight) - scrollHeight > 40 && isLoad == false) {
  472. getDate();
  473. }
  474. };
  475. (function () {
  476. getDate();
  477. })();
  478. return {
  479. exportHTML: exportHTML,
  480. specialReply: specialReply
  481. }
  482. };
  483. var CommentsBox = function () {
  484. var maxSize = 150;
  485. var show = function () {
  486. $('.pop').show();
  487. $('.answer_comments').show();
  488. $('#comments').focus();
  489. $(document).on("touchmove", function (event) {
  490. event.preventDefault();
  491. });
  492. };
  493. var inputFocus = function(){
  494. $('#comments').focus(function(){
  495. interval = setInterval(function() {
  496. document.body.scrollTop = document.body.scrollHeight;
  497. }, 100);
  498. }).blur(function(){
  499. clearInterval(interval);
  500. })
  501. };
  502. var close = function () {
  503. $('.pop').hide();
  504. $('.answer_comments').hide();
  505. $('#comments').blur().val('');
  506. $('.surplus').html(maxSize);
  507. $(document).off("touchmove");
  508. };
  509. var surplusInput = function () {
  510. event($('#comments'), 'input', function () {
  511. var val = $(this).val().length;
  512. var surplus = 0;
  513. if (val <= maxSize) {
  514. surplus = maxSize - val;
  515. }
  516. else {
  517. $(this).val($(this).val().substring(0, maxSize));
  518. }
  519. $('.surplus').html(surplus);
  520. })
  521. };
  522. var res = {
  523. comment_id: '',
  524. response_id: ''
  525. };
  526. event($('.reply_people'), 'click', function () {
  527. if ($(this).hasClass('name')) {
  528. $(this).parents('.comment_item').addClass('insert');
  529. }
  530. else {
  531. $(this).parent('p').addClass('insert');
  532. }
  533. res.response_id = '';
  534. res.comment_id = '';
  535. var to_user_name = $(this).text();
  536. commentsBox.setPlaceHolder('回复' + to_user_name).show();
  537. Comment_type = 'res_people';
  538. if ($(this).attr('data-response_id') !== '' || $(this).attr('data-response_id')) {
  539. res.response_id = $(this).attr('data-response_id');
  540. res.comment_id = $(this).attr('data-comment_id');
  541. }
  542. else {
  543. res.comment_id = $(this).attr('data-comment_id');
  544. }
  545. });
  546. var submitComments = function () {
  547. var url = '';
  548. event($('.comments_submit'), 'click', function () {
  549. if ($('#comments').val() == '') {
  550. $('#comments').focus();
  551. return;
  552. }
  553. $('.loader').show();
  554. var textVal = $('#comments').val();
  555. if (Comment_type == 'special_id') {
  556. url = window.location.protocol + "//" + window.location.host +'/mobile/index.php?act=member_ugc&op=comment&client_type=ajax&special_id=' + specialId + '&content=' + encodeURI(textVal);
  557. ajax(url, function (data) {
  558. $('.loader').hide();
  559. if (data.code !== 200) {
  560. alert(data.message);
  561. return;
  562. }
  563. replyList.specialReply(data.datas);
  564. commentsBox.close();
  565. })
  566. }
  567. else {
  568. if (res.response_id) {
  569. url = window.location.protocol + "//" + window.location.host +'/mobile/index.php?act=member_ugc&op=comment&client_type=ajax&special_id=' + specialId + '&content=' + encodeURI(textVal) + '&response_id=' + res.response_id + '&comment_id=' + res.comment_id;
  570. }
  571. else {
  572. url = window.location.protocol + "//" + window.location.host +'/mobile/index.php?act=member_ugc&op=comment&client_type=ajax&special_id=' + specialId + '&content=' + encodeURI(textVal) + '&comment_id=' + res.comment_id;
  573. }
  574. ajax(url, function (data) {
  575. $('.loader').hide();
  576. if (data.code !== 200) {
  577. alert(data.message);
  578. return;
  579. }
  580. var insertData = data.datas;
  581. var sub = new ReplyItem(insertData['comments'][0], insertData['members']);
  582. if ($('.insert').hasClass('comment_item')) {
  583. if ($('.insert .reply').length > 0) {
  584. $('.insert .reply').last().after(sub.insert(insertData['comments'][0], insertData['members']));
  585. }
  586. else {
  587. $('.insert .msg').after(sub.insert(insertData['comments'][0], insertData['members']));
  588. }
  589. }
  590. else {
  591. $('.insert').after(sub.insert(insertData['comments'][0], insertData['members']));
  592. }
  593. $('.insert').removeClass('insert');
  594. commentsBox.close();
  595. })
  596. }
  597. });
  598. };
  599. var setPlaceHolder = function (content) {
  600. $('#comments').attr('placeholder', content);
  601. return this;
  602. };
  603. (function () {
  604. // close();
  605. surplusInput();
  606. submitComments();
  607. inputFocus();
  608. })();
  609. return {
  610. show: show,
  611. setPlaceHolder: setPlaceHolder,
  612. close:close
  613. }
  614. };
  615. var PageVideo = function () {
  616. var createDom = function (videosrc, videoposter) {
  617. var a = document.createElement('video');
  618. a.poster = videoposter;
  619. a.src = videosrc;
  620. a.controls = true;
  621. return a;
  622. };
  623. this.append = function () {
  624. for (var i = 0; i < $('.video_box').length; i++) {
  625. var videoSrc = $('.video_box').eq(i).attr('data-src');
  626. var videoVideoposter = $('.video_box').eq(i).attr('data-poster');
  627. $('.video_box').eq(i).append(createDom(videoSrc, videoVideoposter));
  628. }
  629. };
  630. };
  631. var vote = new Vote(parseInt($('.vote_type').attr('data-type')));
  632. vote.C();
  633. var Pagevideo = new PageVideo();
  634. Pagevideo.append();
  635. var questionList = new QuestionList();
  636. var commentsBox = new CommentsBox();
  637. var replyList = new ReplyList();
  638. event($('.msg_btn'), 'click', function ()
  639. {
  640. if(from_app && !logined)
  641. {
  642. call_native_handler('on_native_click','{"action":"login"}',function(data)
  643. {
  644. var jsdata = JSON.parse(data);
  645. if(!jsdata.login) {
  646. return;
  647. }
  648. else {
  649. logined = true;
  650. commentsBox.setPlaceHolder('我来说两句').show();
  651. Comment_type = 'special_id';
  652. }
  653. });
  654. }
  655. else {
  656. commentsBox.setPlaceHolder('我来说两句').show();
  657. Comment_type = 'special_id';
  658. }
  659. });
  660. $('#submit_btn').on('click', function () {
  661. var _self = $(this);
  662. $('.loader').show();
  663. $(this).addClass('button_null');
  664. var allAnswers = {};
  665. var voteAnswers = vote.getAnswers() || [];
  666. var resAnswers = questionList.getAnswers() || [];
  667. if ($('.vote').length > 0 && voteAnswers.length == 0) {
  668. $(this).removeClass('button_null');
  669. $('.loader').hide();
  670. alert('亲!请完成投票');
  671. return;
  672. }
  673. if ($('.vote').length > 0) {
  674. allAnswers.vote = voteAnswers;
  675. }
  676. if ($('.question_list').length > 0) {
  677. allAnswers.question = resAnswers;
  678. }
  679. var url = window.location.protocol + "//" + window.location.host + "/mobile/index.php?act=special&op=submit&client_type=ajax&special_id=" + specialId + '&content=' + encodeURI(JSON.stringify(allAnswers));
  680. // var url = 'http://192.168.0.200/mobile/index.php?act=special&op=submit&client_type=ajax&special_id=' + special_id + '&content=' + encodeURI(JSON.stringify(allAnswers));
  681. ajax(url, function (data) {
  682. $('.loader').hide();
  683. if (data.code !== 200) {
  684. alert(data.message);
  685. $('.loader').hide();
  686. return;
  687. }
  688. _self.css('display', 'none');
  689. if ($('.vote').length > 0) {
  690. $('.vote_options').css('display', 'none');
  691. var voteRes = vote.M().result(data.datas['vote_result']);
  692. $('.vote_pro').after(vote.V(voteRes));
  693. statShow();
  694. }
  695. var answerDiff = data.datas['answer_diff'];
  696. if ($('.question_list').length > 0) {
  697. for (var i = 0; i < answerDiff.length; i++) {
  698. if (answerDiff[i]['correct']) {
  699. for (var j = 0; j < answerDiff[i]['origin'].length; j++) {
  700. $('.question_options').eq(answerDiff[i]['index']).find('.label').eq(answerDiff[i]['origin'][j]).css('color', 'green');
  701. }
  702. }
  703. else {
  704. for (var u = 0; u < answerDiff[i]['origin'].length; u++) {
  705. for (var g = 0; g < answerDiff[i]['submit'].length; g++) {
  706. if (answerDiff[i]['origin'][u] == answerDiff[i]['submit'][g]) {
  707. $('.question_options').eq(answerDiff[i]['index']).find('.label').eq(answerDiff[i]['origin'][u]).css('color', 'green');
  708. }
  709. else {
  710. $('.question_options').eq(answerDiff[i]['index']).find('.label').eq(answerDiff[i]['origin'][u]).css('color', 'green');
  711. $('.question_options').eq(answerDiff[i]['index']).find('.label').eq(answerDiff[i]['submit'][g]).css('color', 'red');
  712. }
  713. }
  714. }
  715. }
  716. }
  717. }
  718. if (data.datas['bonus_url'] !== "") {
  719. $('.pop').show();
  720. $('.bonus_page').attr('href', data.datas["bonus_url"]).addClass('fade-in').show();
  721. $('.close_icon').addClass('rotate').show();
  722. $('.bonus_page img').attr('src',data.datas["sender_avatar"]);
  723. }
  724. $('input[type="radio"]').attr('disabled', 'disabled');
  725. $('input[type="checkbox"]').attr('disabled', 'disabled');
  726. });
  727. });
  728. event($('.like_btn'), 'click', function () {
  729. $('.loader').show();
  730. var url = '';
  731. var $this = $(this);
  732. if ($(this).attr('data-comment_id')) {
  733. var comment_id = $(this).attr('data-comment_id');
  734. // window.location.protocol + "//" + window.location.host
  735. url = window.location.protocol + "//" + window.location.host + '/mobile/index.php?act=member_ugc&op=support&client_type=ajax&special_id=' + specialId + '&comment_id=' + comment_id;
  736. ajax(url, function (data) {
  737. $('.loader').hide();
  738. if (data.code !== 200) {
  739. alert(data.message);
  740. $('.loader').hide();
  741. return;
  742. }
  743. var localLike = $this.find('.like_num').text();
  744. if (data.datas['supported'] == true) {
  745. $this.find('.like_num').text(parseInt(localLike) + 1);
  746. }
  747. else {
  748. $this.find('.like_num').text(parseInt(localLike) - 1);
  749. }
  750. $this.toggleClass('active');
  751. $this.find('.like_icon_null').toggleClass('like_icon');
  752. });
  753. }
  754. else {
  755. //window.location.protocol + "//" + window.location.host
  756. url = window.location.protocol + "//" + window.location.host + '/mobile/index.php?act=member_ugc&op=support&client_type=ajax&special_id=' + specialId;
  757. ajax(url, function (data) {
  758. $('.loader').hide();
  759. if (data.code !== 200) {
  760. alert(data.message);
  761. $('.loader').hide();
  762. return;
  763. }
  764. $this.find('.like_icon_null').toggleClass('like_icon');
  765. })
  766. }
  767. });
  768. $('.close_icon').on('click',function(){
  769. $('.pop').hide();
  770. $('.bonus_page').hide();
  771. $('.close_icon').hide();
  772. });
  773. event($('.button_load_more'), 'click', function () {
  774. var comment_id = $(this).parent('.comment_item').attr('data-comment_id');
  775. var curpage = $(this).attr('data-page');
  776. console.log(comment_id);
  777. var url = window.location.protocol + "//" + window.location.host + '/mobile/index.php?act=member_ugc&op=comments&client_type=ajax&special_id=' + specialId + '&comment_id=' + comment_id + '&curpage=' + curpage;
  778. ajax(url, function (data) {
  779. $('.loader').hide();
  780. if (data.code !== 200) {
  781. alert(data.message);
  782. return;
  783. }
  784. console.log(data);
  785. })
  786. });
  787. event($('.comment_label'),'click',function(){
  788. var container = $('.wrapper'),
  789. scrollTo = $('.comment');
  790. container.scrollTop(
  791. scrollTo.offset().top - container.offset().top + container.scrollTop() - 50
  792. );
  793. });
  794. event($('.pop'),'click',function(){
  795. commentsBox.close();
  796. $('.close_icon').trigger('click');
  797. });
  798. event($('.share_icon_null'),'touchend',function(){
  799. call_native_handler('on_native_click','{"action":"share_page","params":{"title":"' + title + '","sub_title":"'+sub_title + '","img_url":"' +img_url +'","url":"' +url + '"}}');
  800. });
  801. register_js_hander('onKeyboardClose',function(data,callback) {
  802. commentsBox.close();
  803. });
  804. $("#comments").autoTextarea({
  805. maxHeight:300
  806. });
  807. function app()
  808. {
  809. var app=navigator.userAgent.toLowerCase(),//判断设备
  810. app_nav=navigator.appVersion.toLowerCase(),
  811. href='';
  812. if (app_nav.indexOf('iphone')>-1&&app.indexOf('iphone')){
  813. href='http://a.app.qq.com/o/simple.jsp?pkgname=com.lrlz.beautyshop';
  814. } else if (app.indexOf('micromessenger')>-1 && app_nav.indexOf('android')>-1) {
  815. href = "http://p.lrlz.com/hfive/android_down/index.html";
  816. }
  817. else {
  818. href="javascript:void(0)";
  819. }
  820. return href;
  821. }
  822. var open_href = app();
  823. $('.open_app_btn').attr('href',open_href);