|
@@ -2,14 +2,14 @@ var event = function (obj, eventType, callback) {
|
|
|
obj.live(eventType, callback);
|
|
|
};
|
|
|
var Verification = function () {
|
|
|
- this.isEmpty = function (objVal,msg) {
|
|
|
+ this.isEmpty = function (objVal, msg) {
|
|
|
if (!objVal) {
|
|
|
- this.alert("empty",msg);
|
|
|
+ this.alert("empty", msg);
|
|
|
return false;
|
|
|
}
|
|
|
return objVal;
|
|
|
};
|
|
|
- this.alert = function (type,msg) {
|
|
|
+ this.alert = function (type, msg) {
|
|
|
switch (type) {
|
|
|
case "empty" : {
|
|
|
alert(msg);
|
|
@@ -22,50 +22,86 @@ var Verification = function () {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-var ajax = function (url,callback) {
|
|
|
+var ajax = function (url, callback) {
|
|
|
$.ajax({
|
|
|
type: "get",
|
|
|
async: false,
|
|
|
url: url,
|
|
|
dataType: "jsonp",
|
|
|
- jsonp: "callback",//传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(一般默认为:callback)
|
|
|
- jsonpCallback:"flightHandler",//自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名,也可以写"?",jQuery会自动为你处理数据
|
|
|
- success:callback,
|
|
|
- error: function(){
|
|
|
+ jsonp: "callback",
|
|
|
+ jsonpCallback: "flightHandler",
|
|
|
+ success: callback,
|
|
|
+ error: function () {
|
|
|
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-var Vote = function () {
|
|
|
+
|
|
|
+var Vote = function (type) {
|
|
|
+ var _self = this;
|
|
|
+ this.type = type;
|
|
|
+ this.answer = [];
|
|
|
+ this.obj = $('input[name="submit_vote"]');
|
|
|
this.M = function () {
|
|
|
- var _self = this;
|
|
|
+ var options = function () {
|
|
|
+ var options = [];
|
|
|
+ for (var i = 0; i < $('.vote_options label').length; i++) {
|
|
|
+ var option = $.trim($('.vote_options label').eq(i).text());
|
|
|
+ options.push(option);
|
|
|
+ }
|
|
|
+ return options;
|
|
|
+ };
|
|
|
+ var sum_num = function (datas) {
|
|
|
+ var sum = 0;
|
|
|
+ for (var i = 0; i < datas['vote_result'].length; i++) {
|
|
|
+ sum += parseFloat(datas['vote_result'][i]);
|
|
|
+ }
|
|
|
+ return sum;
|
|
|
+ };
|
|
|
+ var result = function (data) {
|
|
|
+ var option_items = options();
|
|
|
+ var sum = sum_num(data);
|
|
|
+ var vote_res = [];
|
|
|
+ for (var i = 0; i < data['vote_result'].length; i++) {
|
|
|
+ var g = {};
|
|
|
+ g.name = option_items[i];
|
|
|
+ g.num = parseInt(data['vote_result'][i]);
|
|
|
+ g.percentage = data['vote_result'][i] ? Math.round(data['vote_result'][i] / sum * 100) : 0;
|
|
|
+ vote_res.push(g);
|
|
|
+ }
|
|
|
+ return vote_res;
|
|
|
+ };
|
|
|
return {
|
|
|
- voteRes:function(datas){
|
|
|
+ voteRes: function (datas, callback) {
|
|
|
+ console.log(datas);
|
|
|
var special_id = $('.vote').attr('data-special_id');
|
|
|
- var url = document.location.protocol+"//"+document.location.host+'/mobile/index.php?act=special&op=vote&client_type=ajax&special_id='+special_id+'&options='+datas;
|
|
|
- // var url = 'http://192.168.0.200/mobile/index.php?act=special&op=vote&client_type=ajax&special_id='+special_id+'&options='+datas;
|
|
|
- ajax(url,function(data){
|
|
|
- console.log(data);
|
|
|
- $('.vote_pro').after(_self.V(data));
|
|
|
+ // var url = document.location.protocol+"//"+document.location.host+'/mobile/index.php?act=special&op=vote&client_type=ajax&special_id='+special_id+'&options='+datas;
|
|
|
+ var url = 'http://192.168.0.200/mobile/index.php?act=special&op=vote&client_type=ajax&special_id=' + special_id + '&options=' + datas;
|
|
|
+ ajax(url, function (data) {
|
|
|
+ if (data.code !== 200) {
|
|
|
+ alert(data.message);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var res = result(data.datas);
|
|
|
+ callback(res);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
};
|
|
|
this.V = function (datas) {
|
|
|
var resData = datas;
|
|
|
var html = '<div class="results">';
|
|
|
- for (var i = 0; i < datas.length; i++) {
|
|
|
+ for (var i = 0; i < resData.length; i++) {
|
|
|
html += '<div class="result">' +
|
|
|
- '<div class="result_option">' + datas[i].name + '</div>' +
|
|
|
+ '<div class="result_option">' + resData[i].name + '</div>' +
|
|
|
'<div class="status">' +
|
|
|
'<div class="status_line">' +
|
|
|
'<div class="stat"></div>' +
|
|
|
'<div class="status_bg"></div>' +
|
|
|
'</div>' +
|
|
|
- '<span class="num">' + datas[i].num + '票</span>' +
|
|
|
- '<span class="percentage">' + datas[i].percentage + '%</span>' +
|
|
|
+ '<span class="num">' + resData[i].num + '票</span>' +
|
|
|
+ '<span class="percentage">' + resData[i].percentage + '%</span>' +
|
|
|
'</div>' +
|
|
|
'</div>';
|
|
|
}
|
|
@@ -73,40 +109,187 @@ var Vote = function () {
|
|
|
return html;
|
|
|
};
|
|
|
this.C = function () {
|
|
|
- var _self = this;
|
|
|
+ var statShow = function () {
|
|
|
+ if ($('.percentage').length > 0) {
|
|
|
+ setTimeout(function () {
|
|
|
+ for (var i = 0; i < $('.percentage').length; i++) {
|
|
|
+ var num = $('.percentage')[i].innerHTML;
|
|
|
+ $('.stat')[i].style.width = num;
|
|
|
+ }
|
|
|
+ }, 300);
|
|
|
+ clearInterval(a);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ var a = setInterval(statShow, 10);
|
|
|
+ event(_self.obj, 'change', function () {
|
|
|
+ switch (_self.type) {
|
|
|
+ case 0:
|
|
|
+ case 1 : {
|
|
|
+ _self.answer = [];
|
|
|
+ $.each(_self.obj, function () {
|
|
|
+ if (this.checked) {
|
|
|
+ _self.answer.push($(this).val());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 2: {
|
|
|
+ var val = $(this).val();
|
|
|
+ if ($(this).prop('checked')) {
|
|
|
+ if (_self.answer.length >= 2) {
|
|
|
+ for (var g = 0; g < _self.obj.length; g++) {
|
|
|
+ if (_self.obj.eq(g).val() == _self.answer[0]) {
|
|
|
+ _self.obj.eq(g).prop('checked', false);
|
|
|
+ _self.answer.splice(0, 1);
|
|
|
+ _self.answer.push(val);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _self.answer = [];
|
|
|
+ $.each(_self.obj, function () {
|
|
|
+ if (this.checked) {
|
|
|
+ _self.answer.push($(this).val());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _self.answer = [];
|
|
|
+ $.each(_self.obj, function () {
|
|
|
+ if (this.checked) {
|
|
|
+ _self.answer.push($(this).val());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
event($('#submit_btn'), 'click', function () {
|
|
|
- if($(this).hasClass('button_null')) {
|
|
|
+ if ($(this).hasClass('button_null')) {
|
|
|
return;
|
|
|
}
|
|
|
- var verification = new Verification();
|
|
|
- var checkbox = $('input[name="submit_vote"]:checked').val();
|
|
|
- var vateVal = verification.isEmpty(checkbox,'亲,请投票!');
|
|
|
- var checkedArray = [];
|
|
|
- $.each($('input[name="submit_vote"]'),function(){
|
|
|
- if(this.checked) {
|
|
|
- checkedArray.push($(this).val());
|
|
|
- }
|
|
|
+ if (_self.answer.length == '') {
|
|
|
+ alert('亲,请投票!');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ _self.M().voteRes(_self.answer, function (res) {
|
|
|
+ $('.vote_pro').after(_self.V(res));
|
|
|
});
|
|
|
- if (vateVal) {
|
|
|
- _self.M().voteRes(checkedArray);
|
|
|
- $('.vote_options').css('display', 'none');
|
|
|
- $(this).addClass('button_null').html('已完成投票');
|
|
|
- if ($('.percentage').length > 0) {
|
|
|
- setTimeout(function () {
|
|
|
- for (var i = 0; i < $('.percentage').length; i++) {
|
|
|
- var num = $('.percentage')[i].innerHTML;
|
|
|
- $('.stat')[i].style.width = num;
|
|
|
+ $('.vote_options').css('display', 'none');
|
|
|
+ $(this).addClass('button_null').html('已完成投票');
|
|
|
+ statShow();
|
|
|
+ })
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+var Question = function (obj, handleType) {
|
|
|
+ this.obj = obj;
|
|
|
+ this.handleType = handleType;
|
|
|
+ this.answer = [];
|
|
|
+ this.getAnswer = function () {
|
|
|
+ return this.answer;
|
|
|
+ };
|
|
|
+ this.C = function () {
|
|
|
+ var _self = this;
|
|
|
+ _self.obj.on('change', function () {
|
|
|
+ switch (_self.handleType) {
|
|
|
+ case 0:
|
|
|
+ case 1 : {
|
|
|
+ _self.answer = [];
|
|
|
+ $.each(_self.obj, function () {
|
|
|
+ if (this.checked) {
|
|
|
+ _self.answer.push($(this).val());
|
|
|
}
|
|
|
- }, 300);
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 2: {
|
|
|
+ var val = $(this).val();
|
|
|
+ if ($(this).prop('checked')) {
|
|
|
+ if (_self.answer.length >= 2) {
|
|
|
+ for (var g = 0; g < _self.obj.length; g++) {
|
|
|
+ if (obj.eq(g).val() == _self.answer[0]) {
|
|
|
+ obj.eq(g).prop('checked', false);
|
|
|
+ _self.answer.splice(0, 1);
|
|
|
+ _self.answer.push(val);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _self.answer = [];
|
|
|
+ $.each(_self.obj, function () {
|
|
|
+ if (this.checked) {
|
|
|
+ _self.answer.push($(this).val());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _self.answer = [];
|
|
|
+ $.each(_self.obj, function () {
|
|
|
+ if (this.checked) {
|
|
|
+ _self.answer.push($(this).val());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
+ });
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+var QuestionList = function () {
|
|
|
+ var question_items = [];
|
|
|
+ (function (question_items) {
|
|
|
+ var questions = $('.question').length;
|
|
|
+ var num = 1;
|
|
|
+ var question_nums = 'q' + num;
|
|
|
+ for (var j = 0; j < questions; j++) {
|
|
|
+ question_nums = new Question($('input[name="question' + num + '"]'), parseInt($('.question_type').eq(j).attr('data-type')));
|
|
|
+ question_items.push(question_nums);
|
|
|
+ question_nums.C();
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ })(question_items);
|
|
|
+ var answers = function () {
|
|
|
+ var answers = {};
|
|
|
+ answers.type = 'question';
|
|
|
+ answers['answers'] = [];
|
|
|
+ for (var i = 0; i < question_items.length; i++) {
|
|
|
+ answers['answers'].push(question_items[i].getAnswer());
|
|
|
+ }
|
|
|
+ return answers;
|
|
|
+ };
|
|
|
+ this.submit = function () {
|
|
|
+ $('#submit_question').on('click', function () {
|
|
|
+ var resAnswers = answers();
|
|
|
+ console.log(resAnswers);
|
|
|
+ for(var i = 0;i < resAnswers['answers'].length;i++) {
|
|
|
+ if(resAnswers['answers'][i].length == 0) {
|
|
|
+ var noQuestion = $('input[name="question'+(i+1)+'"]').offset().top;
|
|
|
+ window.scrollTo(0,noQuestion-120);
|
|
|
+ alert('请回答第'+(i+1)+'题');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
})
|
|
|
};
|
|
|
};
|
|
|
|
|
|
+
|
|
|
var CommentsBox = function () {
|
|
|
this.V = function () {
|
|
|
var html = '<div class="pop">' +
|
|
|
+ '<a href="javascript:void(0)" class="bonus_page"></a>' +
|
|
|
+ '<a href="javascript:void(0)" class="close_icon"></a>' +
|
|
|
'<div class="answer_comments">' +
|
|
|
'<div class="handle">' +
|
|
|
'<div><a href="javascript:void(0)" class="close">取消</a></div>' +
|
|
@@ -130,20 +313,17 @@ var CommentsBox = function () {
|
|
|
var _self = this;
|
|
|
var maxSize = 250;
|
|
|
return {
|
|
|
- appendHtml:function(){
|
|
|
+ appendHtml: function () {
|
|
|
$('body').append(_self.V());
|
|
|
},
|
|
|
show: function () {
|
|
|
- event($('.msg_btn'),'touchstart',function(){
|
|
|
- $(this).addClass('active');
|
|
|
- $('.msg_icon_null').addClass('msg_icon');
|
|
|
- });
|
|
|
- event($('.msg_btn'),'touchend',function(){
|
|
|
+ event($('.msg_btn'), 'touchend', function () {
|
|
|
$(this).removeClass('active');
|
|
|
$('.msg_icon_null').removeClass('msg_icon');
|
|
|
- $('.pop').css('display', 'block');
|
|
|
+ $('.pop').show();
|
|
|
+ $('.answer_comments').show();
|
|
|
$('#comments').focus();
|
|
|
- $("body").on("touchmove",function(event){
|
|
|
+ $("body").on("touchmove", function (event) {
|
|
|
event.preventDefault;
|
|
|
}, false)
|
|
|
});
|
|
@@ -152,7 +332,8 @@ var CommentsBox = function () {
|
|
|
event($('.close'), 'click', function () {
|
|
|
$('#comments').val('');
|
|
|
$('.surplus').html(maxSize);
|
|
|
- $('.pop').css('display', 'none');
|
|
|
+ $('.pop').hide();
|
|
|
+ $('.answer_comments').hide();
|
|
|
$("body").off("touchmove");
|
|
|
})
|
|
|
},
|
|
@@ -160,19 +341,19 @@ var CommentsBox = function () {
|
|
|
event($('#comments'), 'input', function () {
|
|
|
var val = $(this).val().length;
|
|
|
var surplus = 0;
|
|
|
- if(val <= maxSize){
|
|
|
+ if (val <= maxSize) {
|
|
|
surplus = maxSize - val;
|
|
|
}
|
|
|
else {
|
|
|
- $(this).val($(this).val().substring(0,maxSize));
|
|
|
+ $(this).val($(this).val().substring(0, maxSize));
|
|
|
}
|
|
|
$('.surplus').html(surplus);
|
|
|
})
|
|
|
},
|
|
|
- submit:function(){
|
|
|
- event($('.submit'),"click",function(){
|
|
|
+ submit: function () {
|
|
|
+ event($('.submit'), "click", function () {
|
|
|
var verification = new Verification();
|
|
|
- verification.isEmpty($('#comments').val(),'亲,内容不能为空哦');
|
|
|
+ verification.isEmpty($('#comments').val(), '亲,内容不能为空哦');
|
|
|
$('.pop').css('display', 'none');
|
|
|
$('#comments').val('');
|
|
|
$("body").off("touchmove");
|
|
@@ -184,45 +365,53 @@ var CommentsBox = function () {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-
|
|
|
-var ua = navigator.userAgent.toLowerCase();
|
|
|
-if(!/iphone|ipad|ipod/.test(ua)){
|
|
|
- $('video').after('<span class="play_icon"></span>');
|
|
|
- var videoLength = document.getElementsByTagName('video').length;
|
|
|
- for(var i = 0;i < videoLength;i++) {
|
|
|
- document.getElementsByClassName('play_icon')[i].addEventListener('click',function(){
|
|
|
- document.getElementsByTagName('video')[i].play();
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- // document.getElementsByClassName('play_icon')[0].addEventListener('click',function(){
|
|
|
- // document.getElementsByTagName('video')[0].play();
|
|
|
- // })
|
|
|
- // event($('.play_icon'),'click',function(){
|
|
|
- // document.getElementsByTagName('video')[0].play();
|
|
|
- // $(this).css('display','none');
|
|
|
- // // document.getElementById('video').play();
|
|
|
- // // $('#video').trigger('play');
|
|
|
- // })
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+var PageVideo = function(){
|
|
|
+ var createDom = function(videosrc){
|
|
|
+ var a = document.createElement('video');
|
|
|
+ a.poster = './images/image01.png';
|
|
|
+ a.src = videosrc;
|
|
|
+ return a;
|
|
|
+ };
|
|
|
+ this.append = function(){
|
|
|
+ for(var i = 0;i<$('.video_box').length;i++) {
|
|
|
+ var videosrc = $('.video_box').eq(i).attr('data-src');
|
|
|
+ $('.video_box').eq(i).append(createDom(videosrc));
|
|
|
+ }
|
|
|
+ };
|
|
|
+};
|
|
|
|
|
|
|
|
|
+var Pagevideo = new PageVideo();
|
|
|
+Pagevideo.append();
|
|
|
|
|
|
-var vote = new Vote();
|
|
|
+var vote = new Vote(parseInt($('.vote_type').attr('data-type')));
|
|
|
vote.C();
|
|
|
|
|
|
+var questionList = new QuestionList();
|
|
|
+questionList.submit();
|
|
|
+
|
|
|
var commentsBox = new CommentsBox();
|
|
|
for (var i in commentsBox.C()) {
|
|
|
commentsBox.C()[i]();
|
|
|
}
|
|
|
-event($('.like_btn'),'click',function(){
|
|
|
+event($('.like_btn'), 'click', function () {
|
|
|
$(this).toggleClass('active');
|
|
|
$(this).find('.like_icon_null').toggleClass('like_icon');
|
|
|
});
|
|
|
|
|
|
+event($('.close_icon'), 'click', function () {
|
|
|
+ $('.pop').hide();
|
|
|
+ $('.bonus_page').hide();
|
|
|
+ $('.close_icon').hide();
|
|
|
+});
|
|
|
+
|
|
|
+event($('.comment_label'), 'click', function () {
|
|
|
+ $('.pop').show();
|
|
|
+ $('.bonus_page').addClass('fade-in').show();
|
|
|
+ $('.close_icon').addClass('rotate').show();
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|