Advertisement
Flyer

Untitled

Apr 5th, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($) {
  2.     var o = $.extend({
  3.         startYear : 1900,
  4.         container : '#timelines',
  5.         item : '.item',
  6.         block_head : 'givemeinfo',
  7.         loader_id : '.loader',
  8.         sniff : '#snifer',
  9.         loader_size : 1      
  10.     });
  11.     var state = $.extend({
  12.         is_ready : true,
  13.         current_year : o.startYear,
  14.         last_year : o.startYear + 1, // placebo
  15.         list_of_years : [],
  16.         carret : 0,
  17.         scrollPosition : 0,
  18.         is_left : 0,
  19.         is_right : 0,
  20.         is_query: true,
  21.         selected_filteredYear : '',
  22.         selected_filteredState: '',
  23.         reverse : []
  24.     });
  25.     var m = {
  26.         query : function(type) {
  27.             if (type) {
  28.                 state.current_year = state.list_of_years[state.carret];
  29.                 state.is_query = true;
  30.             }
  31.             else {
  32.                 state.current_year = state.list_of_years[state.carret];
  33.                 state.is_query = false;
  34.             }  
  35.             m.load(state.current_year);
  36.             if (state.carret > state.list_of_years.lenght) {
  37.                 state.carret = 0;  
  38.             }
  39.         },
  40.         sub_query : function($data) {
  41.                 m.load($data);
  42.         },
  43.         got_list : function() {
  44.             $.ajax({
  45.                 url: '/beta/ajax.php?list_of_years',
  46.                 dataType: "json",
  47.                 success: function(years){
  48.                     if (years["list_of"]) {
  49.                         state.list_of_years = years["list_of"];
  50.                         state.carret = 0;
  51.                         $html ='';
  52.                         for (var i = 0; i < years["list_of"].length; i++) {
  53.                             state.reverse[years["list_of"][i]] = i;
  54.                             $html += '<div class="button blue collapse-button">\
  55.                                 <p class="label filter_as" id="filter_is_year ' + m.converter(years["list_of"][i]) + '">' + years["list_of"][i] + '</p>\
  56.                                 </div>\
  57.                             ';
  58.                         }
  59.                         $("#yearlists").html($html);
  60.                         m.query(true);
  61.                     }
  62.                 }
  63.             });
  64.         },
  65.         load : function($year) {
  66.             $html = '';
  67.             $old = $year;
  68.             if (state.is_query) {
  69.             }
  70.             else {
  71.                 if (state.selected_filteredYear != '') {
  72.                     $year = state.selected_filteredYear;
  73.                 }
  74.                 else {
  75.                     $year = $old;
  76.                 }
  77.             }
  78.             $url = '/beta/ajax.php?query=true&curryear=' + $year;
  79.             console.log(state.selected_filteredState);
  80.             console.log($year);
  81.             if (state.is_query) {}
  82.             else {
  83.                 if (state.selected_filteredState != '') {
  84.                     $url = '/beta/ajax.php?query=true&curryear=' + $year + '&state=' + state.selected_filteredState;
  85.                 }
  86.             }
  87.             state.current_year = $year;
  88.             var $last_query;
  89.             if (state.is_ready) {
  90.             state.is_ready = false;
  91.             $.ajax({
  92.                 url: $url,
  93.                 dataType: "json",
  94.                 success: function(event){
  95.                     console.log(event.result);
  96.                     if (event.result == false) {
  97.                         $(".badquery").remove();
  98.                         $("#givemeinfo").remove();
  99.                         $(".timeline").hide();
  100.                         $(o.container).append("<h1 class='badquery'>В этом году ничего произошло :(</h1>");
  101.                         $last_query = state.last_year;
  102.                     }
  103.                     else {
  104.                     for (var sign in event) {
  105.                         if (sign == state.current_year) {
  106.                             if (event[state.current_year].length) {
  107.                                 $col_six = '\
  108.                                 <div class="col col_16">\
  109.                                 <article>\
  110.                                 <div id="container">\
  111.                                 <div class="timeline_container">\
  112.                                 <div class="timeline ' + m.converter(state.current_year) + '">\
  113.                                 <div class="plus"></div>\
  114.                                 </div></div>\
  115.                                 <div id="timelines">';                     
  116.                                 $html+='<div class="yereabl"><center><h1>' + state.current_year + ' год:</h1></center></div>';
  117.                                 $html+='<div id="givemeinfo">';                            
  118.                                 $html+='<div id="' + m.converter(state.current_year) + '"></div>';             
  119.                                 for (var i=0; i<event[state.current_year].length; i++) {
  120.                                     $html+='<div class="item">\
  121.                                         <div class="item_header">' + event[state.current_year][i]["header"] + '</div>\
  122.                                         <div class="item_top_info">\
  123.                                             <div class="item_avateur"><img src="' + event[state.current_year][i]["poster"] + '" /></div>\
  124.                                             <div class="item_quote">' + event[state.current_year][i]["quote"] + '</div>\
  125.                                         </div>\
  126.                                         <div class="clear"></div>\
  127.                                         <div class="item_bottom_info">';
  128.                                         if (event[state.current_year][i]["mp3"]) {
  129.                                         $html+= '<div class="item_photos"><strong>Вы можете прослушать аудио версию:</strong><br><audio src="' + event[state.current_year][i]["mp3"] + '" controls></audio></div>';
  130.                                         }                                  
  131.                                         if (event[state.current_year][i]["youtube"]) {
  132.                                         $html+= '<div class="item_videos"><a href="#" class="modalbox video video_box_player" id="' + event[state.current_year][i]["youtube"] + '"><b>Просмотреть видео-ролик</b></a></div>';
  133.                                         }
  134.                                         $html+='</div>\
  135.                                         <div class="clear"></div>\
  136.                                         <div class="item_comment_line">' + event[state.current_year][i]["comment"] + '</div>\
  137.                                     </div>';
  138.                                 }
  139.                                 $html+='</div>';
  140.                                 $(".badquery").remove();
  141.                                 $col_six += $html;
  142.                                 $col_six += '</div>\
  143.                                 <div id="popup" class="shade">\
  144.                                 <div class="Popup_rightCorner" ></div>\
  145.                                 <div id="box">\
  146.                                 <b>What"s Up?</b><br/>\
  147.                                 <textarea id="update"></textarea>\
  148.                                 <input type="submit" value="Update" id="update_button"/>\
  149.                                 </div>\
  150.                                 </div>\
  151.                                 </div>\
  152.                                 </article>\
  153.                                 </div>';
  154.                                 if (state.is_query) $(".positiondelta").append($col_six);
  155.                                 else $(".positiondelta").html($col_six);
  156.                                 $(".positiondelta").last(o.block_head).masonry({itemSelector : o.item,});
  157.                                 m.stability($(".positiondelta").last(o.block_head));
  158.                             }                        
  159.                         }
  160.                         if (state.is_query) state.carret += 1;
  161.                         else state.carret = state.reverse[sign] +1;
  162.                         $last_query = sign;
  163.                     }  
  164.                     //$(o.container).append("<div class='timeline'></div>");
  165.                     }
  166.                     state.last_year = $last_query;
  167.                     m.collapser(state.last_year);
  168.                     state.is_ready = true;
  169.                     $("#loader").hide();
  170.                     // ?? state.current_year ? event.state.current_year[object] //
  171.                 }
  172.             });
  173.             if (state.scrollPosition !== undefined && state.scrollPosition !== null) {
  174.             $(window).scrollTop(state.scrollPosition);
  175.             }          
  176.             }
  177.             //else $("#loader").show();
  178.         },
  179.         collapser : function($year) {
  180.             //$("#yearlists").find('.active').removeClass('active');
  181.             //$("p#" + m.converter($year) + "").parent().addClass('active');
  182.             $(o.sniff).html($year).animate({'opacity': 1}, 1000);
  183.         },
  184.         stability : function($filter) {
  185.             var s = $filter.find(o.item);
  186.             $.each(s,function(i,obj){
  187.                
  188.             var posLeft = $(obj).offset().left;
  189.             console.log(posLeft);
  190.             $(obj).addClass('borderClass');
  191.             if ($(obj).find(".rightCorner").hasClass("rightCorner") || $(obj).find(".leftCorner").hasClass("leftCorner")) {}
  192.             else {
  193.             if(posLeft <= 100)
  194.             {
  195.                 html = "<span class='rightCorner'></span>";
  196.                 $(obj).prepend(html);          
  197.             }
  198.             else
  199.             {
  200.                 html = "<span class='leftCorner'></span>";
  201.                 $(obj).prepend(html);
  202.             }
  203.             }
  204.             });
  205.         },
  206.         fixstability : function($container) {
  207.             var s = $container.find(o.item);
  208.             $string = '<div id="givemeinfo">';
  209.             $.each(s,function(i,obj){
  210.                 var posLeft = $(obj).css("left");
  211.                 if(posLeft == "0px") {
  212.                     html = "<span class='rightCorner'></span>";
  213.                 }
  214.                 else {
  215.                     html = "<span class='leftCorner'></span>";
  216.                 }
  217.                 $string += html;
  218.                 $string += $(obj).html();              
  219.             });
  220.             $string += "</div>";
  221.             return $string;
  222.         },
  223.         scroller : function($ready) {
  224.             // scroller pacthing && $ready? //
  225.             if($(document).height() - $(window).height() <= $(window).scrollTop() + 100 && $ready == "bind") {
  226.                 state.scrollPosition = $(window).scrollTop();
  227.                 m.query(true);
  228.             }
  229.         },
  230.         trace : function($string) {
  231.             console.log($string);
  232.         },
  233.         converter : function($int) {
  234.             var iter_str = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
  235.             str = '';
  236.             for (var i in $int) {
  237.                 str += iter_str[$int[i]];
  238.             }
  239.             return str;
  240.         }
  241.        
  242.     };
  243.    
  244.    
  245.  
  246.     $.fn.timeline = function(method) {
  247.         $(document).ready(function() {
  248.             m.got_list();
  249.         });
  250.         $(window).scroll(function(){
  251.             m.scroller("bind");
  252.         });
  253.         $("a.label.taggable").live("click", function () {
  254.             $("html, body").animate({
  255.                 scrollTop: $($(this).attr("href")).offset().top + "px"
  256.                 }, {
  257.                     duration: 500
  258.                 });
  259.         });
  260.         $("a#next_year").live("click", function() {
  261.             m.query(true);
  262.         });
  263.         $(".button-area .thisstate").live("click", function() {
  264.             $(this).parent().find(".selectable-button.active").removeClass("active");
  265.             $(this).addClass('active');
  266.             state.selected_filteredState = $(this).find(".label").text();
  267.             m.query(false);
  268.         });
  269.         $("#yearlists .collapse-button").live("click", function() {
  270.             $(this).parent().find(".collapse-button.active").removeClass("active");
  271.             $(this).addClass('active');
  272.             state.selected_filteredYear = $(this).find(".filter_as").text();
  273.             m.query(false);
  274.         });    
  275.     };
  276.  
  277. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement