main.js 31 KB

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