main.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. $('html').css('height', '100%');
  2. var host = (function () {
  3. return window.location.protocol + "//" + window.location.host;
  4. })();
  5. var Expression = {
  6. utf16toEntities:function(str)
  7. {
  8. var patt=/[\ud800-\udbff][\udc00-\udfff]/g;
  9. // 检测utf16字符正则
  10. str = str.replace(patt, function(char)
  11. {
  12. var H, L, code;
  13. if (char.length===2) {
  14. H = char.charCodeAt(0);
  15. // 取出高位
  16. L = char.charCodeAt(1);
  17. // 取出低位
  18. code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00;
  19. // 转换算法
  20. return "!XMMZ!" + code + ";";
  21. } else {
  22. return char;
  23. }
  24. });
  25. return str;
  26. },
  27. entitiestoUtf16:function(str)
  28. {
  29. // 检测出形如〹形式的字符串
  30. var strObj=this.utf16toEntities(str);
  31. var patt = /!XMMZ!\d+;/g;
  32. var H,L,code;
  33. var arr = strObj.match(patt)||[];
  34. for (var i=0;i<arr.length;i++)
  35. {
  36. code = arr[i];
  37. code=code.replace('!XMMZ!','').replace(';','');
  38. // 高位
  39. H = Math.floor((code-0x10000) / 0x400)+0xD800;
  40. // 低位
  41. L = (code - 0x10000) % 0x400 + 0xDC00;
  42. code = "!XMMZ!"+code+";";
  43. var semojj = String.fromCharCode(H,L);
  44. strObj = strObj.replace(code,semojj);
  45. }
  46. return strObj;
  47. }
  48. };
  49. (function(){
  50. if($('.button_null.button_vote').length >0 && $('.button_null.button_vote').text().indexOf('已经')) {
  51. $('input[type="radio"]').attr('disabled', 'disabled');
  52. $('input[type="checkbox"]').attr('disabled', 'disabled');
  53. }
  54. })();
  55. $('.thumbnail img').picLazyLoad({
  56. threshold:100
  57. });
  58. var specialId = (function () {
  59. var special_id = $('body').attr('data-special_id');
  60. return special_id;
  61. })();
  62. var Comment_type = '';
  63. var need_scroll = true;
  64. var event = function (obj, eventType, callback) {
  65. obj.live(eventType, callback);
  66. };
  67. var get_ajax = function (url, callback) {
  68. $.ajax({
  69. type: "get",
  70. async: false,
  71. url: url,
  72. dataType: "jsonp",
  73. jsonp: "callback",
  74. jsonpCallback: "flightHandler",
  75. success: callback
  76. });
  77. };
  78. var GetQueryString = function (name) {
  79. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  80. var r = window.location.search.substr(1).match(reg);
  81. if (r != null)return unescape(r[2]);
  82. return null;
  83. };
  84. var statShow = function () {
  85. if ($('.percentage').length > 0) {
  86. setTimeout(function () {
  87. for (var i = 0; i < $('.percentage').length; i++) {
  88. var num = $('.percentage')[i].innerHTML;
  89. $('.stat')[i].style.width = num;
  90. }
  91. }, 300);
  92. clearInterval(a);
  93. }
  94. };
  95. var a = setInterval(statShow, 10);
  96. var Vote = function (type) {
  97. var _self = this;
  98. this.type = type;
  99. this.answer = [];
  100. this.getAnswers = function () {
  101. return this.answer;
  102. };
  103. this.obj = $('input[name="submit_vote"]');
  104. this.M = function () {
  105. var options = function () {
  106. var options = [];
  107. for (var i = 0; i < $('.vote_options label').length; i++) {
  108. var option = $.trim($('.vote_options label').eq(i).text());
  109. options.push(option);
  110. }
  111. return options;
  112. };
  113. var sum_num = function (datas) {
  114. var sum = 0;
  115. for (var i = 0; i < datas.length; i++) {
  116. sum += parseFloat(datas[i]);
  117. }
  118. return sum;
  119. };
  120. return {
  121. result: function (data) {
  122. var option_items = options();
  123. var sum = sum_num(data);
  124. var vote_res = [];
  125. for (var i = 0; i < data.length; i++) {
  126. var g = {};
  127. g.name = option_items[i];
  128. g.num = parseInt(data[i]);
  129. g.percentage = data[i] ? Math.round(data[i] / sum * 100) : 0;
  130. vote_res.push(g);
  131. }
  132. return vote_res;
  133. }
  134. }
  135. };
  136. this.V = function (datas) {
  137. var resData = datas;
  138. var html = '<div class="results">';
  139. for (var i = 0; i < resData.length; i++) {
  140. html += '<div class="result">' +
  141. '<div class="result_option">' + resData[i].name + '</div>' +
  142. '<div class="status">' +
  143. '<div class="status_line">' +
  144. '<div class="stat"></div>' +
  145. '<div class="status_bg"></div>' +
  146. '</div>' +
  147. '<span class="num">' + resData[i].num + '票</span>' +
  148. '<span class="percentage">' + resData[i].percentage + '%</span>' +
  149. '</div>' +
  150. '</div>';
  151. }
  152. html += '</div>';
  153. return html;
  154. };
  155. this.C = function () {
  156. event(_self.obj, 'change', function () {
  157. switch (_self.type) {
  158. case 0:
  159. case 1 : {
  160. _self.answer = [];
  161. $.each(_self.obj, function () {
  162. if (this.checked) {
  163. _self.answer.push($(this).val());
  164. }
  165. });
  166. break;
  167. }
  168. case 2: {
  169. var val = $(this).val();
  170. if ($(this).prop('checked')) {
  171. if (_self.answer.length >= 2) {
  172. for (var g = 0; g < _self.obj.length; g++) {
  173. if (_self.obj.eq(g).val() == _self.answer[0]) {
  174. _self.obj.eq(g).prop('checked', false);
  175. _self.answer.splice(0, 1);
  176. _self.answer.push(val);
  177. break;
  178. }
  179. }
  180. }
  181. else {
  182. _self.answer = [];
  183. $.each(_self.obj, function () {
  184. if (this.checked) {
  185. _self.answer.push($(this).val());
  186. }
  187. });
  188. }
  189. }
  190. else {
  191. _self.answer = [];
  192. $.each(_self.obj, function () {
  193. if (this.checked) {
  194. _self.answer.push($(this).val());
  195. }
  196. });
  197. }
  198. }
  199. }
  200. });
  201. };
  202. };
  203. var Question = function (obj, handleType) {
  204. this.obj = obj;
  205. this.handleType = handleType;
  206. this.answer = [];
  207. this.getAnswer = function () {
  208. return this.answer;
  209. };
  210. this.C = function () {
  211. var _self = this;
  212. _self.obj.on('change', function () {
  213. switch (_self.handleType) {
  214. case 0:
  215. case 1 : {
  216. _self.answer = [];
  217. $.each(_self.obj, function () {
  218. if (this.checked) {
  219. _self.answer.push($(this).val());
  220. }
  221. });
  222. break;
  223. }
  224. case 2: {
  225. var val = $(this).val();
  226. if ($(this).prop('checked')) {
  227. if (_self.answer.length >= 2) {
  228. for (var g = 0; g < _self.obj.length; g++) {
  229. if (_self.obj.eq(g).val() == _self.answer[0]) {
  230. _self.obj.eq(g).prop('checked', false);
  231. _self.answer.splice(0, 1);
  232. _self.answer.push(val);
  233. break;
  234. }
  235. }
  236. }
  237. else {
  238. _self.answer = [];
  239. $.each(_self.obj, function () {
  240. if (this.checked) {
  241. _self.answer.push($(this).val());
  242. }
  243. });
  244. }
  245. }
  246. else {
  247. _self.answer = [];
  248. $.each(_self.obj, function () {
  249. if (this.checked) {
  250. _self.answer.push($(this).val());
  251. }
  252. });
  253. }
  254. break;
  255. }
  256. }
  257. });
  258. }
  259. };
  260. var QuestionList = function () {
  261. var question_items = [];
  262. (function (question_items) {
  263. var questions = $('.question').length;
  264. var num = 0;
  265. var question_nums = 'q' + num;
  266. for (var j = 0; j < questions; j++) {
  267. question_nums = new Question($('input[name="question' + num + '"]'), parseInt($('.question_type').eq(j).attr('data-type')));
  268. question_items.push(question_nums);
  269. question_nums.C();
  270. num++;
  271. }
  272. })(question_items);
  273. this.getAnswers = function () {
  274. var answers = [];
  275. for (var i = 0; i < question_items.length; i++) {
  276. if (question_items[i].getAnswer().length == 0) {
  277. continue;
  278. }
  279. var question = {};
  280. question.index = i;
  281. question.answer = question_items[i].getAnswer();
  282. answers.push(question);
  283. }
  284. return answers;
  285. };
  286. };
  287. var ReplyItem = function (comment, members) {
  288. var proxy = function () {
  289. var getNickName = function (userId) {
  290. for (var i = 0; i < members.length; i++) {
  291. if (members[i]['member_id'] == userId) {
  292. return members[i]['nickname'];
  293. }
  294. }
  295. };
  296. var getAvatar = function (userId) {
  297. for (var i = 0; i < members.length; i++) {
  298. if (members[i]['member_id'] == userId) {
  299. return members[i]['avatar'];
  300. }
  301. }
  302. };
  303. var getTime = function (time) {
  304. var date = '';
  305. var location = parseInt(new Date().getTime() / 1000);
  306. var diffHour = parseInt((location - time) / 60 / 60);
  307. var diffMinutes = parseInt((location - time) / 60);
  308. if (diffHour <= 0) {
  309. if (diffMinutes >= 0 && diffMinutes < 5) {
  310. date = "刚刚";
  311. }
  312. else {
  313. date = diffMinutes + "分钟前";
  314. }
  315. }
  316. if (diffHour < 24 && diffHour > 0) {
  317. date = diffHour + '小时前';
  318. }
  319. if (diffHour >= 24) {
  320. var milliseconds = time * 1000;//秒变微秒
  321. var dat = new Date(milliseconds);//生成日期
  322. var month = dat.getMonth() + 1; //取得月
  323. var date1 = dat.getDate(); //取得天
  324. var hour = dat.getHours();//取得小时
  325. var minutes = dat.getMinutes();//取得分钟
  326. if (hour < 10) {
  327. hour = '0' + dat.getHours();
  328. }
  329. if (minutes < 10) {
  330. minutes = '0' + dat.getMinutes();
  331. }
  332. date = month + '月' + date1 + '日' + hour + ':' + minutes;
  333. }
  334. return date;
  335. };
  336. return {
  337. getNickName: getNickName,
  338. getAvatar: getAvatar,
  339. getTime: getTime
  340. }
  341. };
  342. var commentdata = comment;
  343. var sub = '';
  344. var subnum = 10;
  345. if (comment) {
  346. var defaultSubNum = comment['sub_count'];
  347. }
  348. var load_btn = '';
  349. var loadpage = 2;
  350. var isLike = function () {
  351. var like = '';
  352. if (commentdata['supported'] == false) {
  353. like = '<a href="javascript:void(0)" class="like_btn" data-comment_id="' + commentdata['comment_id'] + '">' +
  354. '<span class="like_num">' + commentdata['likes'] + '</span><span class="like_icon_null"></span></a>';
  355. }
  356. else {
  357. like = '<a href="javascript:void(0)" class="like_btn active" data-comment_id="' + commentdata['comment_id'] + '">' +
  358. '<span class="like_num">' + commentdata['likes'] + '</span><span class="like_icon_null like_icon"></span></a>';
  359. }
  360. return like;
  361. };
  362. var parentHTML = function () {
  363. var html = '<div class="comment_item parent_reply" data-comment_id="' + commentdata['comment_id'] + '">' +
  364. '<div class="subject">' +
  365. '<div class="subject_box">' +
  366. '<div class="subject_image">' +
  367. '<img src="' + proxy().getAvatar(commentdata['user_id']) + '" alt="熊猫美妆">' +
  368. '</div>' +
  369. '<div class="subject_name">' +
  370. '<p class="name reply_people" data-parent="true" data-comment_id="' + commentdata['comment_id'] + '">' + proxy().getNickName(commentdata['user_id']) + '</p>' +
  371. '<p class="time">' + proxy().getTime(commentdata['addtime']) + '</p>' +
  372. '</div>' +
  373. '</div>' +
  374. '<div class="like">' + isLike() +
  375. '</div>' +
  376. '</div>' +
  377. '<p class="msg">' + Expression.entitiestoUtf16(commentdata['content']) + sub +
  378. '</p>' + load_btn +
  379. '</div>';
  380. return html;
  381. };
  382. var subHTML = function (comment) {
  383. var subHtml = '<p class="reply">' +
  384. '<span class="reply_people" data-comment_id="' + comment['comment_id'] + '">' + proxy().getNickName(comment['user_id']) + '</span>' +
  385. '回复' +
  386. '<span class="reply_people" data-comment_id="' + comment['comment_id'] + '" data-response_id="' + comment['response_id'] + '">' +
  387. proxy().getNickName(comment['to_user']) + '</span>:' + Expression.entitiestoUtf16(comment['content']) + '</p>';
  388. return subHtml;
  389. };
  390. var empty = function () {
  391. var empty = '<p class="reply_empty">精彩评论虚位以待</p>';
  392. return empty;
  393. };
  394. return {
  395. exportHTML: function () {
  396. return parentHTML();
  397. },
  398. addSub: function (comment) {
  399. sub += subHTML(comment);
  400. },
  401. insert: function (comment) {
  402. return subHTML(comment);
  403. },
  404. empty: function () {
  405. $('.comment_list').append(empty());
  406. },
  407. addLoadBtn: function () {
  408. load_btn = '<div class="button_load_more" data-page="' + loadpage + '">查看更多评论</div>';
  409. },
  410. getLoadMore: function () {
  411. return defaultSubNum > subnum;
  412. },
  413. oneItem: subHTML
  414. }
  415. };
  416. var ReplyList = function () {
  417. var created = function (replys) {
  418. var replyList = [];
  419. var replyIndex = replyList.length;
  420. if (!replys || replys['comments'].length == 0) {
  421. return;
  422. }
  423. for (var i = 0; i < replys['comments'].length; i++) {
  424. if (replys['comments'][i]['response_id'] == 0) {
  425. replyList.push(new ReplyItem(replys['comments'][i], replys['members']));
  426. replyIndex++;
  427. }
  428. else {
  429. replyList[replyIndex - 1].addSub(replys['comments'][i]);
  430. }
  431. }
  432. return replyList;
  433. };
  434. var exportHTML = function (replyItem) {
  435. var datas = created(replyItem);
  436. if ($('.reply_empty').length > 0) {
  437. $('.reply_empty').css('display', 'none');
  438. }
  439. for (var i = 0; i < datas.length; i++) {
  440. if (datas[i].getLoadMore()) {
  441. datas[i].addLoadBtn();
  442. }
  443. $('.comment_list').append(datas[i].exportHTML());
  444. }
  445. };
  446. var specialReply = function (replyItem) {
  447. var datas = created(replyItem);
  448. if ($('.reply_empty').length > 0) {
  449. $('.reply_empty').css('display', 'none');
  450. }
  451. for (var i = 0; i < datas.length; i++) {
  452. $('.comment_list').prepend(datas[i].exportHTML());
  453. }
  454. };
  455. var curpage = 1;
  456. var isLoad = false;
  457. var getData = function () {
  458. isLoad = true;
  459. var url = host + '/mobile/index.php?act=member_ugc&op=comments&client_type=ajax&special_id=' + specialId + '&curpage=' + curpage;
  460. get_ajax(url, function (data) {
  461. isLoad = false;
  462. if (data.code !== 200) {
  463. alert(data.message);
  464. }
  465. else {
  466. var replyDatas = data.datas;
  467. if (replyDatas['comments'].length == 0) {
  468. $('.comment_list').append(new ReplyItem().empty());
  469. return;
  470. }
  471. exportHTML(replyDatas);
  472. if (need_scroll && GetQueryString('need_scroll')) {
  473. need_scroll = false;
  474. $('.comment_label').trigger('click');
  475. }
  476. if (replyDatas.mobile_page['hasmore'] == true) {
  477. curpage++;
  478. $(window).on('scroll', loadEvent);
  479. }
  480. else {
  481. $(window).unbind('scroll',loadEvent);
  482. }
  483. }
  484. });
  485. };
  486. var loadEvent = function () {
  487. var scrollTop = $(this).scrollTop();
  488. var scrollHeight = $(document).height();
  489. var windowHeight = $(this).height();
  490. if ((scrollTop + windowHeight) - scrollHeight > -1000 && isLoad == false) {
  491. getData();
  492. }
  493. };
  494. (function () {
  495. getData();
  496. })();
  497. return {
  498. exportHTML: exportHTML,
  499. specialReply: specialReply
  500. }
  501. };
  502. var CommentsBox = function () {
  503. var maxSize = 150;
  504. var show = function () {
  505. $('.pop').show();
  506. $('.answer_comments').show();
  507. $('#comments').focus();
  508. $('.bottom_flex').css('opacity','0');
  509. $(document).on("touchmove", function (event) {
  510. event.preventDefault();
  511. });
  512. };
  513. var close = function () {
  514. $('.pop').hide();
  515. $('.answer_comments').hide();
  516. $('#comments').blur().val('');
  517. $('.surplus').html(maxSize);
  518. $(document).off("touchmove");
  519. setTimeout(function(){
  520. $('.bottom_flex').css('opacity','1');
  521. },500);
  522. };
  523. var surplusInput = function () {
  524. event($('#comments'), 'input', function () {
  525. var val = $(this).val().length;
  526. var surplus = 0;
  527. if (val <= maxSize) {
  528. surplus = maxSize - val;
  529. }
  530. else {
  531. $(this).val($(this).val().substring(0, maxSize));
  532. }
  533. $('.surplus').html(surplus);
  534. })
  535. };
  536. var res = {
  537. comment_id: '',
  538. response_id: ''
  539. };
  540. event($('.reply_people'), 'click', function () {
  541. if ($(this).hasClass('name')) {
  542. $(this).parents('.comment_item').addClass('insert');
  543. }
  544. else {
  545. $(this).parent('p').addClass('insert');
  546. }
  547. res.response_id = '';
  548. res.comment_id = '';
  549. var to_user_name = $(this).text();
  550. commentsBox.setPlaceHolder('回复' + to_user_name).show();
  551. Comment_type = 'res_people';
  552. if ($(this).attr('data-response_id') !== '' || $(this).attr('data-response_id')) {
  553. res.response_id = $(this).attr('data-response_id');
  554. res.comment_id = $(this).attr('data-comment_id');
  555. }
  556. else {
  557. res.comment_id = $(this).attr('data-comment_id');
  558. }
  559. });
  560. var submitComments = function () {
  561. var url = '';
  562. event($('.comments_submit'), 'click', function () {
  563. if ($('#comments').val() == '') {
  564. $('#comments').focus();
  565. return;
  566. }
  567. $('.loader').show();
  568. var textVal = Expression.utf16toEntities($('#comments').val());
  569. if (Comment_type == 'special_id') {
  570. url = host + '/mobile/index.php?act=member_ugc&op=comment&client_type=ajax&special_id=' + specialId + '&content=' + encodeURI(textVal);
  571. get_ajax(url, function (data) {
  572. $('.loader').hide();
  573. if (data.code !== 200) {
  574. alert(data.message);
  575. return;
  576. }
  577. replyList.specialReply(data.datas);
  578. commentsBox.close();
  579. $('.handle_result').text('评论成功').addClass('show');
  580. setTimeout(function () {
  581. $('.handle_result').removeClass('show');
  582. }, 1500);
  583. })
  584. }
  585. else {
  586. if (res.response_id) {
  587. url = 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;
  588. }
  589. else {
  590. url = host + '/mobile/index.php?act=member_ugc&op=comment&client_type=ajax&special_id=' + specialId + '&content=' + encodeURI(textVal) + '&comment_id=' + res.comment_id;
  591. }
  592. get_ajax(url, function (data) {
  593. $('.loader').hide();
  594. if (data.code !== 200) {
  595. alert(data.message);
  596. return;
  597. }
  598. var insertData = data.datas;
  599. var sub = new ReplyItem(insertData['comments'][0], insertData['members']);
  600. if ($('.insert').hasClass('comment_item')) {
  601. if ($('.insert .reply').length > 0) {
  602. $('.insert .reply').last().after(sub.insert(insertData['comments'][0], insertData['members']));
  603. }
  604. else {
  605. $('.insert .msg').after(sub.insert(insertData['comments'][0], insertData['members']));
  606. }
  607. }
  608. else {
  609. $('.insert').after(sub.insert(insertData['comments'][0], insertData['members']));
  610. }
  611. $('.insert').removeClass('insert');
  612. commentsBox.close();
  613. $('.handle_result').text('评论成功').addClass('show');
  614. setTimeout(function () {
  615. $('.handle_result').removeClass('show');
  616. }, 1500);
  617. })
  618. }
  619. });
  620. };
  621. var setPlaceHolder = function (content) {
  622. $('#comments').attr('placeholder', content);
  623. return this;
  624. };
  625. (function () {
  626. // close();
  627. surplusInput();
  628. submitComments();
  629. // inputFocus();
  630. })();
  631. return {
  632. show: show,
  633. setPlaceHolder: setPlaceHolder,
  634. close: close
  635. }
  636. };
  637. var PageVideo = function () {
  638. var createDom = function (videosrc, videoposter,is_iphone) {
  639. var a = document.createElement('video');
  640. a.poster = videoposter;
  641. a.src = videosrc;
  642. // a.setAttribute('x5-video-player-type','h5');
  643. // a.setAttribute('x5-video-orientation','portraint');
  644. // a.setAttribute('x5-video-player-fullscreen','true');
  645. a.setAttribute('webkit-playsinline',true);
  646. a.setAttribute('playsinline',true);
  647. if(is_iphone) {
  648. a.setAttribute('controls',true);
  649. }
  650. a.className = 'video_play';
  651. return a;
  652. };
  653. this.append = function () {
  654. var play_icon = '';
  655. if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
  656. for (var i = 0; i < $('.video_box').length; i++) {
  657. var videoSrc = $('.video_box').eq(i).attr('data-src');
  658. var videoVideoposter = $('.video_box').eq(i).attr('data-poster');
  659. $('.video_box').eq(i).append(createDom(videoSrc, videoVideoposter,true)).append(play_icon);
  660. }
  661. } else if (/(Android)/i.test(navigator.userAgent)) {
  662. play_icon = '<span class="play_icon"></span>';
  663. for (var i = 0; i < $('.video_box').length; i++) {
  664. var videoSrc = $('.video_box').eq(i).attr('data-src');
  665. var videoVideoposter = $('.video_box').eq(i).attr('data-poster');
  666. $('.video_box').eq(i).append(createDom(videoSrc, videoVideoposter)).append(play_icon);
  667. }
  668. } else {}
  669. };
  670. };
  671. event($('.play_icon'),'touchstart',function(){
  672. var _self = $(this);
  673. var index = $('.play_icon').index(this);
  674. document.getElementsByClassName('video_play')[index].addEventListener('play',function(){
  675. $('.bottom_flex').hide();
  676. _self.hide();
  677. },false);
  678. document.getElementsByClassName('video_play')[index].addEventListener('pause',function(){
  679. $('.bottom_flex').show();
  680. _self.show();
  681. },false);
  682. $('.video_play').get(index).play();
  683. // var fullscreen = function(elem) {
  684. // var prefix = 'webkit';
  685. // if ( elem[prefix + 'EnterFullScreen'] ) {
  686. // return prefix + 'EnterFullScreen';
  687. // } else if( elem[prefix + 'RequestFullScreen'] ) {
  688. // return prefix + 'RequestFullScreen';
  689. // }
  690. // return false;
  691. // };
  692. //
  693. // function autoFullScrenn(v){
  694. // var ua = navigator.userAgent.toLowerCase();
  695. // var Android = String(ua.match(/android/i)) == "android";
  696. // if(!Android) return;//非android系统不使用;
  697. // var video = v,doc = document;
  698. // var fullscreenvideo = fullscreen(doc.createElement("video"));
  699. // if(!fullscreen) {
  700. // alert("不支持全屏模式");
  701. // return;
  702. // }
  703. // video.addEventListener("webkitfullscreenchange",function(e){
  704. // if(!doc.webkitIsFullScreen){//退出全屏暂停视频
  705. // this.pause();
  706. // }
  707. // }, false);
  708. // video.addEventListener("click", function(){
  709. // this.play();
  710. // video[fullscreenvideo]();
  711. // }, false);
  712. //
  713. // video.addEventListener('ended',function(){
  714. // doc.webkitCancelFullScreen(); //播放完毕自动退出全屏
  715. // },false);
  716. // }
  717. // autoFullScrenn(document.getElementsByClassName('video_play')[index]);
  718. });
  719. var vote = new Vote(parseInt($('.vote_type').attr('data-type')));
  720. vote.C();
  721. var Pagevideo = new PageVideo();
  722. Pagevideo.append();
  723. var questionList = new QuestionList();
  724. var commentsBox = new CommentsBox();
  725. var replyList = new ReplyList();
  726. $(window).on('scroll',function(){
  727. var top = $(this).scrollTop();
  728. $('.answer_comments').css('top',top+360);
  729. $('.pop').css('top',top);
  730. });
  731. event($('.bonus_item'), 'click', function () {
  732. if ($(this).hasClass('dis')) {
  733. return;
  734. }
  735. for (var i = 0; i < $('.bonus_item').length; i++) {
  736. if ($('.bonus_item').eq(i).hasClass('dis')) {
  737. continue;
  738. }
  739. else {
  740. $('.bonus_item').eq(i).removeClass('active');
  741. }
  742. }
  743. $(this).addClass('active');
  744. });
  745. event($('#discount'), 'change', function () {
  746. var val = $(this).val();
  747. var select_option = 0;
  748. $('.bonus_item').removeClass('dis').removeClass('active');
  749. for (var i = 0; i < $('#discount option').length; i++) {
  750. if ($('#discount option').eq(i).attr('value') == val) {
  751. select_option = i;
  752. break;
  753. }
  754. }
  755. for (var j = 0; j < $('.bonus_box .money').length; j++) {
  756. if (parseFloat($('.bonus_box .money').eq(j).text()) > parseFloat($('#discount option').eq(select_option).attr('data-money'))) {
  757. $('.bonus_item').eq(j).addClass('dis');
  758. }
  759. }
  760. });
  761. event($('.btn_appreciate'), 'click', function () {
  762. $('.loader').show();
  763. if (from_app && !logined) {
  764. call_native_handler('on_native_click', '{"action":"login"}', function (data) {
  765. $('.loader').hide();
  766. var jsdata = JSON.parse(data);
  767. if (!jsdata.login) {
  768. return;
  769. }
  770. else {
  771. logined = true;
  772. var url = host + '/mobile/index.php?act=member_ugc&op=mine_bonus&client_type=ajax';
  773. get_ajax(url, function (data) {
  774. $('.loader').hide();
  775. if (data.code !== 200) {
  776. alert(data.message);
  777. return;
  778. }
  779. var datas = data.datas['bonus_rate'];
  780. var html = '';
  781. for (var i = 0; i < datas.length; i++) {
  782. html += '<option value="' + datas[i].rate + '" data-money="' + datas[i].total + '">' + datas[i].rate + '%</option>';
  783. };
  784. $('.appreciate_pop').removeClass('close').addClass('show');
  785. $('#discount').append(html).trigger('change');
  786. });
  787. }
  788. });
  789. }
  790. else {
  791. $('.loader').hide();
  792. var url = host + '/mobile/index.php?act=member_ugc&op=mine_bonus&client_type=ajax';
  793. get_ajax(url, function (data) {
  794. $('.loader').hide();
  795. if (data.code !== 200) {
  796. alert(data.message);
  797. return;
  798. }
  799. var datas = data.datas['bonus_rate'];
  800. var html = '';
  801. for (var i = 0; i < datas.length; i++) {
  802. for (var i = 0; i < datas.length; i++) {
  803. html += '<option value="' + datas[i].rate + '" data-money="' + datas[i].total + '">' + datas[i].rate + '%(余额: '+datas[i].total+'元)</option>';
  804. };
  805. };
  806. $('.appreciate_pop').removeClass('close').addClass('show');
  807. $('#discount').append(html).trigger('change');
  808. });
  809. }
  810. });
  811. event($('#close_appreciate'), 'click', function () {
  812. $('#discount').empty();
  813. $('.bonus_item').removeClass('active').removeClass('dis');
  814. $('.live_msg').val('');
  815. $('.appreciate_pop').removeClass('show').addClass('close');
  816. $('.pop').hide();
  817. });
  818. event($('#submit_appreciate'), 'click', function () {
  819. var rate = $('#discount').val();
  820. var money = $('.bonus_item.active .money').text();
  821. var content = $('#live_msg').val();
  822. var url = host + '/mobile/index.php?act=member_ugc&op=appreciate&client_type=ajax&rate=' + rate + '&money=' + money + '&content=' + encodeURI(content) + '&special_id=' + specialId;
  823. get_ajax(url, function (data) {
  824. console.log(data);
  825. if (data.code !== 200) {
  826. alert(data.message);
  827. return;
  828. }
  829. $('.handle_result').text('打赏成功').addClass('show');
  830. $('#close_appreciate').trigger('click');
  831. setTimeout(function () {
  832. $('.handle_result').removeClass('show');
  833. window.location.reload();
  834. }, 1500);
  835. })
  836. });
  837. event($('.msg_btn'), 'click', function () {
  838. if (from_app && !logined) {
  839. call_native_handler('on_native_click', '{"action":"login"}', function (data) {
  840. var jsdata = JSON.parse(data);
  841. if (!jsdata.login) {
  842. return;
  843. }
  844. else {
  845. logined = true;
  846. commentsBox.setPlaceHolder('我来说两句').show();
  847. Comment_type = 'special_id';
  848. }
  849. });
  850. }
  851. else {
  852. commentsBox.setPlaceHolder('我来说两句').show();
  853. Comment_type = 'special_id';
  854. }
  855. });
  856. event($('.focus'),'touchstart',function(){
  857. var _self = $(this);
  858. if(_self.hasClass('active')) {
  859. return;
  860. }
  861. if (from_app && !logined) {
  862. call_native_handler('on_native_click', '{"action":"login"}', function (data) {
  863. var jsdata = JSON.parse(data);
  864. if (!jsdata.login) {
  865. return;
  866. }
  867. else {
  868. logined = true;
  869. var url = host + "/mobile/index.php?act=member_ugc&op=subscribe_author&client_type=ajax&special_id=" + specialId;
  870. get_ajax(url,function(data){
  871. if (data.code !== 200) {
  872. alert(data.message);
  873. return;
  874. }
  875. _self.addClass('active').text('已关注');
  876. });
  877. }
  878. });
  879. }
  880. else {
  881. var url = host + "/mobile/index.php?act=member_ugc&op=subscribe_author&client_type=ajax&special_id=" + specialId;
  882. get_ajax(url,function(data){
  883. if (data.code !== 200) {
  884. alert(data.message);
  885. return;
  886. }
  887. _self.addClass('active').text('已关注');
  888. });
  889. }
  890. });
  891. $('#submit_btn').on('click', function () {
  892. var _self = $(this);
  893. $('.loader').show();
  894. $(this).addClass('button_null');
  895. var allAnswers = {};
  896. var voteAnswers = vote.getAnswers() || [];
  897. var resAnswers = questionList.getAnswers() || [];
  898. if ($('.vote').length > 0 && voteAnswers.length == 0) {
  899. $(this).removeClass('button_null');
  900. $('.loader').hide();
  901. alert('亲!请完成投票');
  902. return;
  903. }
  904. if ($('.vote').length > 0) {
  905. allAnswers.vote = voteAnswers;
  906. }
  907. if ($('.question_list').length > 0) {
  908. allAnswers.question = resAnswers;
  909. }
  910. var url = host + "/mobile/index.php?act=special&op=submit&client_type=ajax&special_id=" + specialId + '&content=' + encodeURI(JSON.stringify(allAnswers));
  911. get_ajax(url, function (data) {
  912. console.log(data);
  913. $('.loader').hide();
  914. if (data.code !== 200) {
  915. alert(data.message);
  916. $('.loader').hide();
  917. return;
  918. }
  919. _self.css('display', 'none');
  920. if ($('.vote').length <= 0 && $('.question_list').length <= 0) {
  921. if (data.datas['bonus_url'] !== "") {
  922. $('.pop').show();
  923. $('.bonus_label').html('感谢您的参与<br/>恭喜获得'+data.datas['amount']+'元红包');
  924. $('.bonus_page').attr('href', data.datas["bonus_url"]).addClass('fade-in').show();
  925. $('.close_icon').addClass('rotate').show();
  926. $('.bonus_page img').attr('src', data.datas["sender_avatar"]);
  927. }
  928. }
  929. if ($('.vote').length > 0 && $('.question_list').length <= 0) {
  930. $('.vote_options').css('display', 'none');
  931. var voteRes = vote.M().result(data.datas['vote_result']);
  932. $('.vote_pro').after(vote.V(voteRes));
  933. statShow();
  934. if (data.datas['bonus_url'] !== "") {
  935. $('.pop').show();
  936. $('.bonus_label').html('感谢您的参与<br/>恭喜获得'+data.datas['amount']+'元红包');
  937. $('.bonus_page').attr('href', data.datas["bonus_url"]).addClass('fade-in').show();
  938. $('.close_icon').addClass('rotate').show();
  939. $('.bonus_page img').attr('src', data.datas["sender_avatar"]);
  940. }
  941. }
  942. if ($('.question_list').length > 0) {
  943. if($('.vote').length > 0) {
  944. $('.vote_options').css('display', 'none');
  945. var voteRes = vote.M().result(data.datas['vote_result']);
  946. $('.vote_pro').after(vote.V(voteRes));
  947. statShow();
  948. }
  949. var answerDiff = data.datas['answer_diff'];
  950. var correct = 0;
  951. var error = 0;
  952. var result_msg = '';
  953. for (var i = 0; i < answerDiff.length; i++) {
  954. var diff_correct = answerDiff[i]['origin'];
  955. var correct_answers = [];
  956. for(var j=0;j<diff_correct.length;j++) {
  957. var answer_num = String.fromCharCode(diff_correct[j]+65);
  958. correct_answers.push(answer_num);
  959. }
  960. $('.question_options').eq(i).after('<div class="right_answer">正确答案:'+correct_answers.join('')+'</div>');
  961. if (answerDiff[i]['correct']) {
  962. $('.question_options').eq(i).addClass('state_right');
  963. correct++;
  964. }
  965. else {
  966. $('.question_options').eq(i).addClass('state_error');
  967. error++;
  968. }
  969. }
  970. if(correct == 0) {
  971. result_msg = '很抱歉!您全答错了,您需要加把劲哦!';
  972. $('.question_result p').text(result_msg);
  973. $('.question_result').addClass('show');
  974. $('.question_result .close').on('click',function(){
  975. $('.question_result').removeClass('show');
  976. });
  977. return;
  978. }
  979. if (error == 0 && correct == answerDiff.length) {
  980. result_msg = '恭喜您!您全答对了!<br />获得'+data.datas['amount']+'元红包';
  981. }
  982. if (error !== 0 && correct > 0 && correct < answerDiff.length){
  983. result_msg = '恭喜你,答对了'+correct+'道题<br/>获得'+data.datas['amount']+'元红包';
  984. }
  985. if (data.datas['bonus_url'] !== "") {
  986. $('.pop').show();
  987. $('.bonus_label').html(result_msg);
  988. $('.bonus_page').attr('href', data.datas["bonus_url"]).addClass('fade-in').show();
  989. $('.close_icon').addClass('rotate').show();
  990. $('.bonus_page img').attr('src', data.datas["sender_avatar"]);
  991. }
  992. }
  993. $('.bonus_page').on('click',function () {
  994. });
  995. $('input[type="radio"]').attr('disabled', 'disabled');
  996. $('input[type="checkbox"]').attr('disabled', 'disabled');
  997. });
  998. });
  999. event($('.like_btn'), 'click', function () {
  1000. $('.loader').show();
  1001. var url = '';
  1002. var $this = $(this);
  1003. if ($(this).attr('data-comment_id')) {
  1004. var comment_id = $(this).attr('data-comment_id');
  1005. url = host + '/mobile/index.php?act=member_ugc&op=support&client_type=ajax&special_id=' + specialId + '&comment_id=' + comment_id;
  1006. get_ajax(url, function (data) {
  1007. $('.loader').hide();
  1008. if (data.code !== 200) {
  1009. alert(data.message);
  1010. $('.loader').hide();
  1011. return;
  1012. }
  1013. var localLike = $this.find('.like_num').text();
  1014. if (data.datas['supported'] == true) {
  1015. $this.find('.like_num').text(parseInt(localLike) + 1);
  1016. }
  1017. else {
  1018. $this.find('.like_num').text(parseInt(localLike) - 1);
  1019. }
  1020. $this.toggleClass('active');
  1021. $this.find('.like_icon_null').toggleClass('like_icon');
  1022. });
  1023. }
  1024. else {
  1025. url = host + '/mobile/index.php?act=member_ugc&op=support&client_type=ajax&special_id=' + specialId;
  1026. get_ajax(url, function (data) {
  1027. $('.loader').hide();
  1028. if (data.code !== 200) {
  1029. alert(data.message);
  1030. $('.loader').hide();
  1031. return;
  1032. }
  1033. $this.find('.like_icon_null').toggleClass('like_icon');
  1034. })
  1035. }
  1036. });
  1037. $('.close_icon').on('click', function () {
  1038. $('.pop').hide();
  1039. $('.bonus_page').hide();
  1040. $('.close_icon').hide();
  1041. });
  1042. event($('.button_load_more'), 'click', function () {
  1043. var _self = $(this);
  1044. $('.loader').show();
  1045. var comment_id = $(this).parent('.comment_item').attr('data-comment_id');
  1046. var curpage = $(this).attr('data-page');
  1047. var url = host + '/mobile/index.php?act=member_ugc&op=comments&client_type=ajax&special_id=' + specialId + '&comment_id=' + comment_id + '&curpage=' + curpage + '&page=4';
  1048. get_ajax(url, function (data) {
  1049. $('.loader').hide();
  1050. if (data.code !== 200) {
  1051. alert(data.message);
  1052. return;
  1053. }
  1054. var items = '';
  1055. var datas = data.datas['comments'];
  1056. for (var i = 0; i < datas.length; i++) {
  1057. items += new ReplyItem([], data.datas['members']).oneItem(datas[i]);
  1058. }
  1059. _self.before(items);
  1060. if (!data['datas'].mobile_page['hasmore']) {
  1061. _self.css('display', 'none');
  1062. }
  1063. else {
  1064. _self.attr('data-page', parseInt(curpage) + 1);
  1065. }
  1066. })
  1067. });
  1068. event($('.comment_label'), 'click', function () {
  1069. // var container = $(window).offset().top,
  1070. var scrollTo = $('.comment').offset().top;
  1071. $(window).scrollTop(scrollTo);
  1072. });
  1073. event($('.pop'), 'click', function () {
  1074. commentsBox.close();
  1075. });
  1076. event($('.share_icon_null'), 'touchend', function ()
  1077. {
  1078. function addslashes (str) {
  1079. return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
  1080. }
  1081. var share_title = addslashes(title);
  1082. var share_sub_title = addslashes(sub_title);
  1083. var jsonobject = {
  1084. action:"share_page",
  1085. params: {
  1086. title:share_title,
  1087. sub_title:share_sub_title,
  1088. img_url:img_url,
  1089. url:url
  1090. }
  1091. }
  1092. call_native_handler('on_native_click',JSON.stringify(jsonobject));
  1093. });
  1094. register_js_hander('onKeyboardClose', function (data, callback) {
  1095. commentsBox.close();
  1096. });
  1097. function app() {
  1098. var app = navigator.userAgent.toLowerCase(),//判断设备
  1099. app_nav = navigator.appVersion.toLowerCase(),
  1100. href = '';
  1101. if (app_nav.indexOf('iphone') > -1 && app.indexOf('iphone')) {
  1102. href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.lrlz.beautyshop';
  1103. } else if (app.indexOf('micromessenger') > -1 && app_nav.indexOf('android') > -1) {
  1104. href = "http://p.lrlz.com/hfive/android_down/index.html";
  1105. }
  1106. else {
  1107. href = "javascript:void(0)";
  1108. }
  1109. return href;
  1110. }
  1111. var open_href = app();
  1112. $('.open_app_btn').attr('href', open_href);