Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($) {
- var o = $.extend({
- startYear : 1900,
- container : '#timelines',
- item : '.item',
- block_head : 'givemeinfo',
- loader_id : '.loader',
- sniff : '#snifer',
- loader_size : 1
- });
- var state = $.extend({
- is_ready : true,
- current_year : o.startYear,
- last_year : o.startYear + 1, // placebo
- list_of_years : [],
- carret : 0,
- scrollPosition : 0,
- is_left : 0,
- is_right : 0,
- is_query: true,
- selected_filteredYear : '',
- selected_filteredState: '',
- reverse : []
- });
- var m = {
- query : function(type) {
- if (type) {
- state.current_year = state.list_of_years[state.carret];
- state.is_query = true;
- }
- else {
- state.current_year = state.list_of_years[state.carret];
- state.is_query = false;
- }
- m.load(state.current_year);
- if (state.carret > state.list_of_years.lenght) {
- state.carret = 0;
- }
- },
- sub_query : function($data) {
- m.load($data);
- },
- got_list : function() {
- $.ajax({
- url: '/beta/ajax.php?list_of_years',
- dataType: "json",
- success: function(years){
- if (years["list_of"]) {
- state.list_of_years = years["list_of"];
- state.carret = 0;
- $html ='';
- for (var i = 0; i < years["list_of"].length; i++) {
- state.reverse[years["list_of"][i]] = i;
- $html += '<div class="button blue collapse-button">\
- <p class="label filter_as" id="filter_is_year ' + m.converter(years["list_of"][i]) + '">' + years["list_of"][i] + '</p>\
- </div>\
- ';
- }
- $("#yearlists").html($html);
- m.query(true);
- }
- }
- });
- },
- load : function($year) {
- $html = '';
- $old = $year;
- if (state.is_query) {
- }
- else {
- if (state.selected_filteredYear != '') {
- $year = state.selected_filteredYear;
- }
- else {
- $year = $old;
- }
- }
- $url = '/beta/ajax.php?query=true&curryear=' + $year;
- console.log(state.selected_filteredState);
- console.log($year);
- if (state.is_query) {}
- else {
- if (state.selected_filteredState != '') {
- $url = '/beta/ajax.php?query=true&curryear=' + $year + '&state=' + state.selected_filteredState;
- }
- }
- state.current_year = $year;
- var $last_query;
- if (state.is_ready) {
- state.is_ready = false;
- $.ajax({
- url: $url,
- dataType: "json",
- success: function(event){
- console.log(event.result);
- if (event.result == false) {
- $(".badquery").remove();
- $("#givemeinfo").remove();
- $(".timeline").hide();
- $(o.container).append("<h1 class='badquery'>В этом году ничего произошло :(</h1>");
- $last_query = state.last_year;
- }
- else {
- for (var sign in event) {
- if (sign == state.current_year) {
- if (event[state.current_year].length) {
- $col_six = '\
- <div class="col col_16">\
- <article>\
- <div id="container">\
- <div class="timeline_container">\
- <div class="timeline ' + m.converter(state.current_year) + '">\
- <div class="plus"></div>\
- </div></div>\
- <div id="timelines">';
- $html+='<div class="yereabl"><center><h1>' + state.current_year + ' год:</h1></center></div>';
- $html+='<div id="givemeinfo">';
- $html+='<div id="' + m.converter(state.current_year) + '"></div>';
- for (var i=0; i<event[state.current_year].length; i++) {
- $html+='<div class="item">\
- <div class="item_header">' + event[state.current_year][i]["header"] + '</div>\
- <div class="item_top_info">\
- <div class="item_avateur"><img src="' + event[state.current_year][i]["poster"] + '" /></div>\
- <div class="item_quote">' + event[state.current_year][i]["quote"] + '</div>\
- </div>\
- <div class="clear"></div>\
- <div class="item_bottom_info">';
- if (event[state.current_year][i]["mp3"]) {
- $html+= '<div class="item_photos"><strong>Вы можете прослушать аудио версию:</strong><br><audio src="' + event[state.current_year][i]["mp3"] + '" controls></audio></div>';
- }
- if (event[state.current_year][i]["youtube"]) {
- $html+= '<div class="item_videos"><a href="#" class="modalbox video video_box_player" id="' + event[state.current_year][i]["youtube"] + '"><b>Просмотреть видео-ролик</b></a></div>';
- }
- $html+='</div>\
- <div class="clear"></div>\
- <div class="item_comment_line">' + event[state.current_year][i]["comment"] + '</div>\
- </div>';
- }
- $html+='</div>';
- $(".badquery").remove();
- $col_six += $html;
- $col_six += '</div>\
- <div id="popup" class="shade">\
- <div class="Popup_rightCorner" ></div>\
- <div id="box">\
- <b>What"s Up?</b><br/>\
- <textarea id="update"></textarea>\
- <input type="submit" value="Update" id="update_button"/>\
- </div>\
- </div>\
- </div>\
- </article>\
- </div>';
- if (state.is_query) $(".positiondelta").append($col_six);
- else $(".positiondelta").html($col_six);
- $(".positiondelta").last(o.block_head).masonry({itemSelector : o.item,});
- m.stability($(".positiondelta").last(o.block_head));
- }
- }
- if (state.is_query) state.carret += 1;
- else state.carret = state.reverse[sign] +1;
- $last_query = sign;
- }
- //$(o.container).append("<div class='timeline'></div>");
- }
- state.last_year = $last_query;
- m.collapser(state.last_year);
- state.is_ready = true;
- $("#loader").hide();
- // ?? state.current_year ? event.state.current_year[object] //
- }
- });
- if (state.scrollPosition !== undefined && state.scrollPosition !== null) {
- $(window).scrollTop(state.scrollPosition);
- }
- }
- //else $("#loader").show();
- },
- collapser : function($year) {
- //$("#yearlists").find('.active').removeClass('active');
- //$("p#" + m.converter($year) + "").parent().addClass('active');
- $(o.sniff).html($year).animate({'opacity': 1}, 1000);
- },
- stability : function($filter) {
- var s = $filter.find(o.item);
- $.each(s,function(i,obj){
- var posLeft = $(obj).offset().left;
- console.log(posLeft);
- $(obj).addClass('borderClass');
- if ($(obj).find(".rightCorner").hasClass("rightCorner") || $(obj).find(".leftCorner").hasClass("leftCorner")) {}
- else {
- if(posLeft <= 100)
- {
- html = "<span class='rightCorner'></span>";
- $(obj).prepend(html);
- }
- else
- {
- html = "<span class='leftCorner'></span>";
- $(obj).prepend(html);
- }
- }
- });
- },
- fixstability : function($container) {
- var s = $container.find(o.item);
- $string = '<div id="givemeinfo">';
- $.each(s,function(i,obj){
- var posLeft = $(obj).css("left");
- if(posLeft == "0px") {
- html = "<span class='rightCorner'></span>";
- }
- else {
- html = "<span class='leftCorner'></span>";
- }
- $string += html;
- $string += $(obj).html();
- });
- $string += "</div>";
- return $string;
- },
- scroller : function($ready) {
- // scroller pacthing && $ready? //
- if($(document).height() - $(window).height() <= $(window).scrollTop() + 100 && $ready == "bind") {
- state.scrollPosition = $(window).scrollTop();
- m.query(true);
- }
- },
- trace : function($string) {
- console.log($string);
- },
- converter : function($int) {
- var iter_str = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
- str = '';
- for (var i in $int) {
- str += iter_str[$int[i]];
- }
- return str;
- }
- };
- $.fn.timeline = function(method) {
- $(document).ready(function() {
- m.got_list();
- });
- $(window).scroll(function(){
- m.scroller("bind");
- });
- $("a.label.taggable").live("click", function () {
- $("html, body").animate({
- scrollTop: $($(this).attr("href")).offset().top + "px"
- }, {
- duration: 500
- });
- });
- $("a#next_year").live("click", function() {
- m.query(true);
- });
- $(".button-area .thisstate").live("click", function() {
- $(this).parent().find(".selectable-button.active").removeClass("active");
- $(this).addClass('active');
- state.selected_filteredState = $(this).find(".label").text();
- m.query(false);
- });
- $("#yearlists .collapse-button").live("click", function() {
- $(this).parent().find(".collapse-button.active").removeClass("active");
- $(this).addClass('active');
- state.selected_filteredYear = $(this).find(".filter_as").text();
- m.query(false);
- });
- };
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement