bobing.js 32.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772

if ($.os.webkit ? false : true && $.os.fennec ? false : true && $.os.ie ? false : true && $.os.opera ? false : true) {
    $.os.webkit = true;
    $.feat.cssPrefix = $.os.webkit ? "Webkit" : "";
}


(function ($) {

    $.fn.popupbobing = function (opts) {
        return new popupbobing(this[0], opts);
    };
    var queue = [];
    var popupbobing = (function () {
        var popupbobing = function (containerEl, opts) {

            if (typeof containerEl === "string" || containerEl instanceof String) {
                this.container = document.getElementById(containerEl);
            } else {
                this.container = containerEl;
            }
            if (!this.container) {
                alert("Error finding container for popupbobing " + containerEl);
                return;
            }

            try {
                if (typeof (opts) === "string" || typeof (opts) === "number")
                    opts = {
                        message: opts,
                        cancelOnly: "true",
                        cancelText: "OK"
                    };
                this.id = id = opts.id = opts.id || $.uuid();
                var self = this;
                this.title = opts.suppressTitle ? "" : (opts.title || "Alert");
                this.message = opts.message || "";
                this.cancelText = opts.cancelText || "Cancel";
                this.cancelCallback = opts.cancelCallback || function () { };
                this.cancelClass = opts.cancelClass || "button";
                this.doneText = opts.doneText || "Done";
                this.doneCallback = opts.doneCallback || function (self) {

                };
                this.doneClass = opts.doneClass || "button";
                this.cancelOnly = opts.cancelOnly || false;
                this.onShow = opts.onShow || function () { };
                this.autoCloseDone = opts.autoCloseDone !== undefined ? opts.autoCloseDone : true;

                queue.push(this);
                if (queue.length == 1)
                    this.show();
            } catch (e) {
                console.log("error adding popupbobing " + e);
            }

        };

        popupbobing.prototype = {
            id: null,
            title: null,
            message: null,
            cancelText: null,
            cancelCallback: null,
            cancelClass: null,
            doneText: null,
            doneCallback: null,
            doneClass: null,
            cancelOnly: false,
            onShow: null,
            autoCloseDone: true,
            supressTitle: false,
            show: function () {
                var self = this;
                var markup = '<div id="' + this.id + '" class="afpopupbobing hidden">' +
                            '<header>' + this.title + '</header>' +
                             '<div>' + this.message + '</div>' +
                             '<footer style="clear:both;">' +
                                 '<a href="javascript:;" class="' + this.cancelClass + '" id="cancel">' + this.cancelText + '</a>' +
                                 '<a href="javascript:;" class="' + this.doneClass + '" id="action">' + this.doneText + '</a>' +
                            ' </footer>' +
                         '</div></div>';
                $(this.container).append($(markup));

                var $el = $.query("#" + this.id);
                $el.bind("close", function () {
                    self.hide();
                });

                if (this.cancelOnly) {
                    $el.find('A#action').hide();
                    $el.find('A#cancel').addClass('center');
                }
                $el.find('A').each(function () {
                    var button = $(this);
                    button.bind('click', function (e) {
                        if (button.attr('id') == 'cancel') {
                            self.cancelCallback.call(self.cancelCallback, self);
                            self.hide();
                        } else {
                            self.doneCallback.call(self.doneCallback, self);
                            if (self.autoCloseDone)
                                self.hide();
                        }
                        e.preventDefault();
                    });
                });
                self.positionpopupbobing();
                $.blockUI(0.5);

                $el.bind("orientationchange", function () {
                    self.positionpopupbobing();
                });


                $el.find("header").show();
                $el.find("footer").show();
                setTimeout(function () {
                    $el.removeClass('hidden');
                    self.onShow(self);
                }, 50);
            },

            hide: function () {
                var self = this;
                $.query('#' + self.id).addClass('hidden');
                $.unblockUI();
                if (!$.os.ie && !$.os.android) {
                    setTimeout(function () {
                        self.remove();
                    }, 250);
                }
                else
                    self.remove();
            },

            remove: function () {
                var self = this;
                var $el = $.query("#" + self.id);
                $el.unbind("close");
                $el.find('BUTTON#action').unbind('click');
                $el.find('BUTTON#cancel').unbind('click');
                $el.unbind("orientationchange").remove();
                queue.splice(0, 1);
                if (queue.length > 0)
                    queue[0].show();
            },

            positionpopupbobing: function () {
                var popupbobing = $.query('#' + this.id);
                popupbobing.css("top", ((window.innerHeight / 2.5) + window.pageYOffset) - (popupbobing[0].clientHeight / 2) + "px");
                popupbobing.css("left", (window.innerWidth / 2) - (popupbobing[0].clientWidth / 2) + "px");
            }
        };

        return popupbobing;
    })();
    var uiBlocked = false;
    $.blockUI = function (opacity) {
        if (uiBlocked)
            return;
        opacity = opacity ? " style='opacity:" + opacity + ";'" : "";
        $.query('BODY').prepend($("<div id='mask'" + opacity + "></div>"));
        $.query('BODY DIV#mask').bind("touchstart", function (e) {
            e.preventDefault();
        });
        $.query('BODY DIV#mask').bind("touchmove", function (e) {
            e.preventDefault();
        });
        uiBlocked = true;
    };

    $.unblockUI = function () {
        uiBlocked = false;
        $.query('BODY DIV#mask').unbind("touchstart");
        $.query('BODY DIV#mask').unbind("touchmove");
        $("BODY DIV#mask").remove();
    };

})(af);

var bobing = [];
bobing.remainder = null;
bobing.level = null;
bobing.status = 0;
bobing.num = new Array(6)
bobing.flagtime;


bobing.moveStart = function () {
    that = this;
    document.getElementById('bobigaudio').play()
    function animQueue1(num) {
        var pic = $("#pic" + num);
		pic.css("display",'block');
        pic.css3Animate({
            x: 150,
            y: 50,
            previous: false,
            time: "200ms",
            callback: function () {
                pic.css3Animate({
                    x: 20,
                    y: 50,
                    previous: false,
                    time: "250ms",
                    callback: function () {
                        pic.css3Animate({
                            x: 50,
                            y: 0,
                            previous: false,
                            time: "300ms",
                            callback: function () {
                                pic.css3Animate({
                                    x: 70,
                                    y: 40,
                                    previous: false,
                                    time: "350ms",
                                    callback: function () {
                                        pic.css3Animate({
                                            x: 80,
                                            y: 10,
                                            previous: false,
                                            time: "350ms",
                                            callback: function () {
                                                pic.css3Animate({
                                                    x: 80,
                                                    y: 0,
                                                    previous: false,
                                                    time: "400ms",
                                                    callback: function () {
                                                        pic.css3Animate({
                                                            x: 20,
                                                            y: 70,
                                                            previous: false,
                                                            time: "400ms",
                                                            callback: function () {
                                                                pic.css3Animate({
                                                                    x: 0,
                                                                    y: 0,
                                                                    previous: false,
                                                                    time: "500ms",
                                                                    callback: function () {

                                                                    }
                                                                });
                                                            }
                                                        });
                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    };
    function animQueue2(num) {
        var pic = $("#pic" + num);
		pic.css("display",'block');
        pic.css3Animate({
            x: 0,
            y: 130,
            previous: false,
            time: "200ms",
            callback: function () {
                pic.css3Animate({
                    x: -100,
                    y: 30,
                    previous: false,
                    time: "200ms",
                    callback: function () {
                        pic.css3Animate({
                            x: 20,
                            y: 30,
                            previous: false,
                            time: "250ms",
                            callback: function () {
                                pic.css3Animate({
                                    x: 40,
                                    y: 80,
                                    previous: false,
                                    time: "50ms",
                                    callback: function () {
                                        pic.css3Animate({
                                            x: -90,
                                            y: 80,
                                            previous: false,
                                            time: "400ms",
                                            callback: function () {
                                                pic.css3Animate({
                                                    x: -30,
                                                    y: 130,
                                                    previous: false,
                                                    time: "500ms",
                                                    callback: function () {
                                                        pic.css3Animate({
                                                            x: 0,
                                                            y: 0,
                                                            previous: false,
                                                            time: "600ms",
                                                            callback: function () {

                                                            }
                                                        });
                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    };
    function animQueue3(num) {
        var pic = $("#pic" + num);
		pic.css("display",'block');
        pic.css3Animate({
            x: -50,
            y: 20,
            previous: false,
            time: "200ms",
            callback: function () {
                pic.css3Animate({
                    x: -50,
                    y: -130,
                    previous: false,
                    time: "200ms",
                    callback: function () {
                        pic.css3Animate({
                            x: 40,
                            y: -100,
                            previous: false,
                            time: "300ms",
                            callback: function () {
                                pic.css3Animate({
                                    x: -70,
                                    y: 10,
                                    previous: false,
                                    time: "350ms",
                                    callback: function () {
                                        pic.css3Animate({
                                            x: -110,
                                            y: -60,
                                            previous: false,
                                            time: "350ms",
                                            callback: function () {
                                                pic.css3Animate({
                                                    x: 50,
                                                    y: -60,
                                                    previous: false,
                                                    time: "500ms",
                                                    callback: function () {
                                                        pic.css3Animate({
                                                            x: 0,
                                                            y: 0,
                                                            previous: false,
                                                            time: "450ms",
                                                            callback: function () {
                                                            }
                                                        });
                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    };
    function animQueue4(num) {
        var pic = $("#pic" + num);
		pic.css("display",'block');
        pic.css3Animate({
            x: -150,
            y: -50,
            previous: false,
            time: "300ms",
            callback: function () {
                pic.css3Animate({
                    x: -120,
                    y: 80,
                    previous: false,
                    time: "300ms",
                    callback: function () {
                        pic.css3Animate({
                            x: -20,
                            y: 80,
                            previous: false,
                            time: "400ms",
                            callback: function () {
                                pic.css3Animate({
                                    x: -50,
                                    y: -60,
                                    previous: false,
                                    time: "400ms",
                                    callback: function () {
                                        pic.css3Animate({
                                            x: -90,
                                            y: 80,
                                            previous: false,
                                            time: "500ms",
                                            callback: function () {
                                                pic.css3Animate({
                                                    x: 0,
                                                    y: 0,
                                                    previous: false,
                                                    time: "550ms",
                                                    callback: function () {

                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    };
    function animQueue5(num) {
        var pic = $("#pic" + num);
		pic.css("display",'block');
        pic.css3Animate({
            x: 30,
            y: 80,
            previous: false,
            time: "100ms",
            callback: function () {
                pic.css3Animate({
                    x: 80,
                    y: 20,
                    previous: false,
                    time: "200ms",
                    callback: function () {
                        pic.css3Animate({
                            x: 80,
                            y: -30,
                            previous: false,
                            time: "300ms",
                            callback: function () {
                                pic.css3Animate({
                                    x: 60,
                                    y: -60,
                                    previous: false,
                                    time: "300ms",
                                    callback: function () {
                                        pic.css3Animate({
                                            x: 40,
                                            y: -80,
                                            previous: false,
                                            time: "300ms",
                                            callback: function () {
                                                pic.css3Animate({
                                                    x: -10,
                                                    y: -80,
                                                    previous: false,
                                                    time: "300ms",
                                                    callback: function () {
                                                        pic.css3Animate({
                                                            x: -30,
                                                            y: -50,
                                                            previous: false,
                                                            time: "300ms",
                                                            callback: function () {
                                                                pic.css3Animate({
                                                                    x: -50,
                                                                    y: -20,
                                                                    previous: false,
                                                                    time: "300ms",
                                                                    callback: function () {
                                                                        pic.css3Animate({
                                                                            x: 0,
                                                                            y: 0,
                                                                            previous: false,
                                                                            time: "350ms",
                                                                            callback: function () {

                                                                            }
                                                                        });
                                                                    }
                                                                });
                                                            }
                                                        });
                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    };
    function animQueue6(num) {
        var pic = $("#pic" + num);
		pic.css("display",'block');
        pic.css3Animate({
            x: 0,
            y: 50,
            previous: false,
            time: "150ms",
            callback: function () {
                pic.css3Animate({
                    x: 30,
                    y: 80,
                    previous: false,
                    time: "150ms",
                    callback: function () {
                        pic.css3Animate({
                            x: 80,
                            y: 80,
                            previous: false,
                            time: "200ms",
                            callback: function () {
                                pic.css3Animate({
                                    x: 110,
                                    y: 50,
                                    previous: false,
                                    time: "200ms",
                                    callback: function () {
                                        pic.css3Animate({
                                            x: 130,
                                            y: 20,
                                            previous: false,
                                            time: "200ms",
                                            callback: function () {
                                                pic.css3Animate({
                                                    x: 130,
                                                    y: -20,
                                                    previous: false,
                                                    time: "250ms",
                                                    callback: function () {
                                                        pic.css3Animate({
                                                            x: 90,
                                                            y: -60,
                                                            previous: false,
                                                            time: "350ms",
                                                            callback: function () {
                                                                pic.css3Animate({
                                                                    x: 60,
                                                                    y: -60,
                                                                    previous: false,
                                                                    time: "350ms",
                                                                    callback: function () {
                                                                        pic.css3Animate({
                                                                            x: 30,
                                                                            y: -30,
                                                                            previous: false,
                                                                            time: "400ms",
                                                                            callback: function () {
                                                                                pic.css3Animate({
                                                                                    x: 0,
                                                                                    y: 0,
                                                                                    previous: false,
                                                                                    time: "400ms",
                                                                                    callback: function () {

                                                                                    }
                                                                                });
                                                                            }
                                                                        });
                                                                    }
                                                                });
                                                            }
                                                        });
                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    };

    var pic = function (time) {
       time = parseInt(time) + 100;
        var arr = new Array(6);
        for (var i = 0; i < 6; i++) {
            arr[i] = Math.floor(Math.random() * 6 + 1);
        }
		pic1.style.backgroundImage = "url("+image_path+"template/images/g1.png)";
        pic2.style.backgroundImage = "url("+image_path+"template/images/g1.png)";
        pic3.style.backgroundImage = "url("+image_path+"template/images/g1.png)";
        pic4.style.backgroundImage = "url("+image_path+"template/images/g1.png)";
        pic5.style.backgroundImage = "url("+image_path+"template/images/g1.png)";
        pic6.style.backgroundImage = "url("+image_path+"template/images/g1.png)";

        that.flagtime = setTimeout(function () { pic(time) }, time);
    }
    pic("400")

    $el = $("#bobigwan>div");
    $el.attr("style", "animation:rotate 3s;-moz-animation:rotate 3s;-webkit-animation:rotate 3s; -o-animation:rotate 3s;");
    window.setTimeout(function () {


        $el.removeAttr("style");
    }, 3000);

    animQueue1(1)
    animQueue2(2)
    animQueue3(3)
    animQueue4(4)
    animQueue5(5)
    animQueue6(6)
};
bobing.moveEnd = function () {
    window.clearTimeout(this.flagtime);
    for (var i = 0; i < 6; i++) {
        var id = "pic" + (1 + i);
        document.getElementById(id).style.backgroundImage = "url("+image_path+"template/images/d" + this.num[i] + ".png)";
    }
    window.setTimeout(function () { that.ending(); }, 500);

};
bobing.ending = function () {
    that = this;
    if (this.level>5) {
      $.query('body').popupbobing({
			id: "resultpopup",
			message: '恭喜,得到' + this.level + '点数',
		});
		$("#resultpopup").bind("click", function () { $("#resultpopup").trigger("close"); that.status == 0 });
    } else {
		$.query('body').popupbobing({
            id: "promptoutpopup",
            message: this.errmessage,
        });
		$("#resultpopup").bind("click", function () { $("#resultpopup").trigger("close"); that.status == 0 });
    };

    this.theRemaining.innerHTML = this.remainder;
	this.mytotals.innerHTML = this.mytotal;
	this.userconts.innerHTML = this.usercont;



}


bobing.binding = function () {


    that = this;
	if (this.remainder > 0) {
		}else{
		 $.query('body').popupbobing({
                id: "promptnopopup",
                message: '今天次数已用完, 赶快叫朋友来为你助威吧!'
            });
		$("#promptnopopup").bind("click", function () { $("#promptnopopup").trigger("close"); that.status == 0 });
		return;
	}

    if (window.DeviceMotionEvent) {
        var speed = 10;
        var x = y = lastX = lastY = 0;
        window.addEventListener('devicemotion', function (e) {
            var acceleration = e.accelerationIncludingGravity;
            x = parseInt(acceleration.x);
            y = parseInt(acceleration.y);
            if (Math.abs(x - lastX) > speed && Math.abs(y - lastY) > speed && this.status == 0) {
                bobing.start();
                $(".afpopupbobing").trigger("close");
                lastX = lastY = 0;
            };
        });


    } else {

    }


}

bobing.start = function () {
    that = this;

        if (this.remainder > 0) {
            if (this.status == 0) {
                this.status = 1;
                this.level = null;
                form_data = eval('[{ username:"' + this.username + '"}]');
                $.post(bburl, form_data[0],
                      function (data) {
                          var queryString = data
                          arr = eval('(' + queryString + ')');
                          that.level = arr.level.key;
                          that.username = arr.user.name;
                          that.num = [arr.level.a, arr.level.b, arr.level.c, arr.level.d, arr.level.e, arr.level.f];
                          that.remainder = arr.user.num;
						  that.mytotal = arr.user.mytotal;
						  that.usercont = arr.user.usercont;

						  that.errmessage = arr.errmessage;
                      })
                this.moveStart();
                window.setTimeout(function () {
                    if (that.level && that.username) {
                        that.status = 2;
                        that.moveEnd();
                        window.setTimeout(function () { that.status = 0; }, 1500);
                    } else if (that.username == null || that.username == "") {
                        that.status = 0;
                       that.num = [2, 3, 6, 1, 5, 2];
                        that.moveEnd();
                        $.query('body').popupbobing({
                            id: "promptoutpopup",
                            message: '登录超时'
                        });
                        $("#promptoutpopup").bind("click", function () { $("#promptoutpopup").trigger("close"); });
                    }else {
                        that.status = 0;
                       that.num = [2, 3, 6, 1, 5, 2];
                        that.moveEnd();
                        $.query('body').popupbobing({
                            id: "promptwwwpopup",
                            message: '网络出问题啦!'
                        });
                        $("#promptwwwpopup").bind("click", function () { $("#promptwwwpopup").trigger("close"); });
                    };

                }, 3000);
            }

        } else {
			var wannei = $("#wannei");
			wannei.css("display",'none');
            $.query('body').popupbobing({
                id: "promptnopopup",
                message: '今天次数用完,点右上角分享到朋友圈或发送给朋友,叫朋友来为你助威吧!'
            });
			$("#promptnopopup").bind("click", function () { $("#promptnopopup").trigger("close"); });

        };


};


var initializebobing = function () {
    bobing.theRemaining = document.getElementById("theRemaining");
	bobing.mytotals = document.getElementById("mytotals");
	bobing.userconts = document.getElementById("usercont");
    bobing.binding();

}