Advertisement
BEmanuel87

Untitled

Feb 21st, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Keep some reference pointers
  2. var pointer = p = {
  3.     window: $(window),
  4.     windowW: $(window).width(),
  5.     windowH: $(window).height(),
  6.     document: $(document),
  7.     container: $('.container'),
  8.     topSlider: {
  9.         container: $('#topSlider'),
  10.         intCont: $('#topSlider #intCont')
  11.     },
  12.     navbar: $('#navbar'),
  13.     filter: $('#filter'),
  14.     grid: $('#grid'),
  15.     press: $('#guttenberg')
  16. };
  17.  
  18. // Create some defaults
  19. var defaults = d = {
  20.     // Slider specifics
  21.     sliderW: p.windowW,
  22.     sliderH: p.windowH,
  23.     sliderImages: [
  24.         'homepage-slider-1.jpg',
  25.         'homepage-slider-2.jpg',
  26.         'homepage-slider-3.jpg'
  27.     ],
  28.     sliderMainText: 'babywalker',
  29.     sliderText: [
  30.         'the eternal collection',
  31.         'the greeks collection',
  32.         'the eternal collection'
  33.     ],
  34.     sliderStar: 'star.png',
  35.     sliderZigZag: 'zigzag-line.png',
  36.     sliderDownArrow: 'down-arrow.png',
  37.     firstSlide: 1, // 1-based (starts with 1, not with 0)
  38.     sliderAnimationSpeed: 1000, // Miliseconds
  39.  
  40.     // Navbar specifics
  41.     navbarMenu: [
  42.         'products',
  43.         'press',
  44.         'about us',
  45.         'catalogues',
  46.         'contact',
  47.         'limba'
  48.     ],
  49.  
  50.     // Filter specifics
  51.     filterOptions: {
  52.         defaultExtension: 'jpg',
  53.         defaultDescription: function(filename) {
  54.             var fNE = filename.replace(/.jpg$|.jpeg$|.png$|.gif$|.bmp$/, '').split('-'),
  55.                 alphaRegex = /^[a-zA-Z]/,
  56.                 returnName = [];
  57.  
  58.             for (var i = 0, len = fNE.length; i < len; i++) {
  59.                 if (fNE[i].match(alphaRegex)) {
  60.                     returnName.push(fNE[i].charAt(0).toUpperCase() + fNE[i].slice(1));
  61.                 } else {
  62.                     returnName.push(fNE[i]);
  63.                 }
  64.             }
  65.  
  66.             return returnName.join(' ');
  67.         },
  68.         formatSource: function(filename) {
  69.             return (filename.match(/.jpg$|.jpeg$|.png$|.gif$|.bmp$/))
  70.                 ? filename : filename + '.' + this.defaultExtension;
  71.         },
  72.         itemsPerRow: 3
  73.     },
  74.     filterData: {
  75.         'babywalker': [
  76.             ['babywalker-boy-4013.jpg', 'Demonstratie de forta'],
  77.             ['babywalker-boy-4019.jpg'],
  78.             ['babywalker-boy-4020.jpg']
  79.         ],
  80.         'exclusive': [
  81.             ['exclusive-boy-5003.jpg'],
  82.             ['exclusive-boy-5007', 'Alta demonstratie'],
  83.             ['exclusive-boy-5013']
  84.         ],
  85.         'luminosa': [
  86.             ['luminosa-girl-6007']
  87.         ]
  88.     },
  89.     filterBuildGridImageData: null,
  90.     pressPictures: [
  91.         'madamefigaro-babywalker-shoes-240x240',
  92.         'marie1-240x160',
  93.         'marieclaire1-240x160',
  94.         'vaftisi5-240x160',
  95.         'vogue4-240x160'
  96.     ],
  97.     picturesPerRow: 4
  98. };
  99.  
  100. // Create a custom object
  101. var custom = c = {
  102.  
  103. };
  104.  
  105. // Merge the defaults with the custom object (if there is one)
  106. (function() {
  107.  
  108.     if (!$.isEmptyObject(custom)) {
  109.         window.defaults = $.extend(true, defaults, custom);
  110.     }
  111.  
  112. })();
  113.  
  114. // Build and initialize the slider
  115. (function() {
  116.  
  117.     // Define needed functions (in closure)
  118.     function createSlide(index) {
  119.         var slide = $('<div></div>');
  120.  
  121.         slide.prop('id', 'slide'+(index+1)).addClass('slide fib').css({
  122.             width: p.windowW,
  123.             height: p.windowH
  124.         });
  125.         slider.intCont.append(slide);
  126.         slider['slide'+(index+1)] = slider.intCont.find('.slide').eq(index);
  127.     }
  128.  
  129.     function addImageToSlide(index) {
  130.         slider['slide'+(index+1)].css({
  131.             backgroundImage: 'url("images/slider/'+d.sliderImages[index]+'")'
  132.         });
  133.     }
  134.  
  135.     function addControlButton() {
  136.         var div = $('<div></div>');
  137.  
  138.         div.addClass('control-button');
  139.         slider.control.append(div);
  140.     }
  141.  
  142.     function addTextContainer(index) {
  143.         var div = $('<div></div>'),
  144.             leftStar = $('<img>'),
  145.             header = $('<h2></h2>'),
  146.             rightStar = $('<img>'),
  147.             zigzag = $('<img>'),
  148.             p = $('<p></p>');
  149.  
  150.         div.addClass('text-container five columns');
  151.         leftStar.prop('src', 'images/slider/'+d.sliderStar).addClass('image-star');
  152.         header.text(d.sliderMainText);
  153.         rightStar.prop('src', 'images/slider/'+d.sliderStar).addClass('image-star');
  154.         zigzag.prop('src', 'images/slider/'+d.sliderZigZag).addClass('image-zigzag');
  155.         p.text(d.sliderText[index]);
  156.  
  157.         slider['slide'+(index+1)].append(
  158.             div.append(leftStar).append(header).append(rightStar).append(zigzag).append(p)
  159.         );
  160.     }
  161.  
  162.     function addBottomLink(index) {
  163.         var downArrow = $('<img>');
  164.  
  165.         downArrow.prop('src', 'images/slider/'+d.sliderDownArrow).addClass('image-down-arrow');
  166.         slider['slide'+(index+1)].append(downArrow);
  167.     }
  168.  
  169.     // Keep slider object as reference
  170.     var slider = p.topSlider;
  171.  
  172.     // Add the control
  173.     slider.control = slider.container.find('div.control');
  174.  
  175.     // Resize all slides to fill the entire height of the screen
  176.     slider.intCont.find('.slide').css('height', d.sliderH);
  177.  
  178.     // Add image, text, bottomLink and control references
  179.     for (var i = 0, len = d.sliderImages.length; i < len; i++) {
  180.         // Create the slide
  181.         createSlide(i);
  182.  
  183.         // Add the image
  184.         addImageToSlide(i);
  185.  
  186.         // Add the control button
  187.         addControlButton();
  188.  
  189.         // Add text container
  190.         addTextContainer(i);
  191.  
  192.         // Add bottom link
  193.         addBottomLink(i);
  194.     }
  195.  
  196.     // Reticulate parent slider to contain his absolute positioned children
  197.     slider.container.css('height', p.windowH);
  198.  
  199.     // Reticulate intermediate container to withold all slides
  200.     slider.intCont.css({
  201.         width: d.sliderImages.length * p.windowW,
  202.         height: p.windowH
  203.     });
  204.  
  205.     // Reticulate control div to be set on vertical middle
  206.     slider.control.css('top', (p.windowH - slider.control.height()) / 2);
  207.  
  208.     // Add some function to the slider
  209.     slider.moveTo = function(slideNumber) {
  210.         this.intCont.animate({
  211.             marginLeft: slideNumber * -p.windowW
  212.         }, d.sliderAnimationSpeed);
  213.     }
  214.  
  215.     slider.control.on('click', 'div', function() {
  216.         var self = $(this),
  217.             index = self.index();
  218.  
  219.         // Deactivate all other buttons
  220.         slider.control.find('div').removeClass('active');
  221.         // Active current button
  222.         self.addClass('active');
  223.  
  224.         // Move slider to target slide
  225.         slider.moveTo(index);
  226.     });
  227.  
  228.     // Set the first slide as active
  229.     slider.control.find('.control-button').eq(d.firstSlide - 1).click();
  230.  
  231.     // Add behaviour for down arrow within the slides
  232.     slider.intCont.on('click', '.image-down-arrow', function() {
  233.         $('html, body').animate({
  234.             scrollTop: p.navbar.offset().top
  235.         });
  236.     });
  237.  
  238. })();
  239.  
  240. // Build and initialize navbar
  241. (function() {
  242.  
  243.     // Define needed functions (in closure)
  244.     function addMenuItem(item) {
  245.         var li = $('<li></li>'),
  246.             a = $('<a></a>');
  247.  
  248.         a.prop('href', '#'+item.replace(/ /g, '')).text(item);
  249.         ul.append(li.append(a));
  250.     }
  251.  
  252.     function addMenuBanner() {
  253.         var li = $('<li></li>'),
  254.             a = $('<a></a>');
  255.  
  256.         a.prop('href', '#').text(d.sliderMainText).addClass('navlogo');
  257.         ul.find('li').eq(itemsLength / 2 - 1).after(li.append(a));
  258.     }
  259.  
  260.     var ul = p.navbar.find('nav ul'),
  261.         itemsLength = d.navbarMenu.length;
  262.  
  263.     // Build menu
  264.     for (var i = 0; i < itemsLength; i++) {
  265.         addMenuItem(d.navbarMenu[i]);
  266.     }
  267.     addMenuBanner();
  268.  
  269.     p.window.on('scroll', function() {
  270.         var scrollTop = p.window.scrollTop(),
  271.             navbarIsSticky = p.navbar.hasClass('sticky');
  272.  
  273.         if (scrollTop > p.windowH && !navbarIsSticky) {
  274.             p.navbar.addClass('sticky');
  275.             $('body').addClass('with-padding');
  276.         } else if (scrollTop <= p.windowH && navbarIsSticky) {
  277.             p.navbar.removeClass('sticky');
  278.             $('body').removeClass('with-padding');
  279.         }
  280.     });
  281.  
  282. })();
  283.  
  284. // Build and initialize the filters
  285. (function() {
  286.  
  287.     // Define needed functions (in closure)
  288.     function createFilterSection(section) {
  289.         var li = $('<li></li>'),
  290.             a = $('<a></a>');
  291.  
  292.         a.prop('href', '#'+section).text(section);
  293.         p.filter.find('ul').append(li.append(a));
  294.     }
  295.  
  296.     d.filterBuildGridImageData = function(section) {
  297.         var sections = (section === 'all') ? [] : [section],
  298.             fo = d.filterOptions,
  299.             fd = d.filterData,
  300.             iPR = fo.itemsPerRow,
  301.             divRow = $('<div class="row"></div>');
  302.  
  303.         if (typeof sections[0] === 'undefined') {
  304.             for (category in fd) {
  305.                 if (fd.hasOwnProperty(category)) {
  306.                     sections.push(category);
  307.                 }
  308.             }
  309.         }
  310.  
  311.         // Empty the grid
  312.         p.grid.find('div.row').remove();
  313.  
  314.         for (var i = 0, len = sections.length; i < len; i++) {
  315.             if (fd.hasOwnProperty(sections[i])) {
  316.                 for (var j = 0, len2 = fd[sections[i]].length; j < len2; j++) {
  317.                     // Commit the row
  318.                     if (divRow.children().size() >= iPR) {
  319.                         p.grid.append(divRow);
  320.                         divRow = $('<div class="row"></div>');
  321.                     }
  322.  
  323.                     var div = $('<div></div>'),
  324.                         img = $('<img>'),
  325.                         a = $('<a></a>'),
  326.                         divInfo = $('<div></div>'),
  327.                         h3 = $('<h3></h3>'),
  328.                         h5 = $('<h5></h5'),
  329.                         formalName,
  330.                         description;
  331.  
  332.                     div.addClass('four columns');
  333.                     formalName = fo.formatSource(fd[sections[i]][j][0]);
  334.                     img.prop('src', 'images/products/' + formalName);
  335.                     a.prop('href', formalName).addClass('semiopaque');
  336.                     divInfo.addClass('info');
  337.                     description = (typeof fd[sections[i]][j][1] === 'undefined')
  338.                         ? fo.defaultDescription(formalName) : fd[sections[i]][j][1];
  339.                     h3.text(description);
  340.                     h5.text(sections[i]);
  341.  
  342.                     a.append(divInfo.append(h3).append(h5));
  343.                     divRow.append(div.append(img).append(a));
  344.                 }
  345.             }
  346.         }
  347.  
  348.         // Collect garbage if needed
  349.         if (divRow.children().size()) {
  350.             p.grid.append(divRow);
  351.             divRow = $('<div class="row"></div>');
  352.         }
  353.  
  354.         // Bind the hover event for the div.row > div
  355.         p.grid.find('.row > div').hover(function() {
  356.             $(this).find('a').animate({
  357.                 opacity: '.5'
  358.             }, 500);
  359.         }, function() {
  360.             $(this).find('a').animate({
  361.                 opacity: 0
  362.             }, 500);
  363.         });
  364.  
  365.         // Bind the onmouseover event behavior for all the a elements
  366.         p.grid.find('a.semiopaque').hover(function() {
  367.             $(this).find('.info').animate({
  368.                 left: '0%'
  369.             }, 400);
  370.         }, function() {
  371.             $(this).find('.info').animate({
  372.                 left: '150%'
  373.             }, 400);
  374.         });
  375.  
  376.         // Reticulate the height of the #products div
  377.         var rowNumber = p.grid.find('.row').size();
  378.         $('#products').animate({
  379.             height: (rowNumber * 500 + 242) + 'px'
  380.         }, 500);
  381.     }
  382.  
  383.     // Build the filters
  384.     for (section in d.filterData) {
  385.         if (d.filterData.hasOwnProperty(section)) {
  386.             createFilterSection(section);
  387.         }
  388.     }
  389.  
  390.     // Bind all filter section links
  391.     p.filter.find('a').click(function(evt) {
  392.         evt.preventDefault();
  393.  
  394.         var self = $(this);
  395.  
  396.         p.filter.find('a').removeClass('active');
  397.         self.addClass('active');
  398.         d.filterBuildGridImageData(self.prop('href').split('#')[1]);
  399.     });
  400.  
  401.     // Autoset on the first key collection
  402.     p.filter.find('a').eq(0).click();
  403.  
  404. })();
  405.  
  406. // Build and initialize press section
  407. (function() {
  408.  
  409.     var divRow = $('<div class="row ten columns offset-by-one"></div>'),
  410.         pPR = d.picturesPerRow;
  411.  
  412.     for (var i = 0, len = d.pressPictures.length; i < len; i++) {
  413.         if (divRow.children().size() >= pPR) {
  414.             p.press.append(divRow);
  415.             divRow = $('<div class="row ten columns offset-by-one"></div>');
  416.         }
  417.  
  418.         var div = $('<div></div>'),
  419.             a = $('<a></a>'),
  420.             img = $('<img>'),
  421.             formalName;
  422.  
  423.         formalName = d.filterOptions.formatSource(d.pressPictures[i]);
  424.         div.addClass('three columns');
  425.         img.prop('src', 'images/press/' + formalName);
  426.         a.prop('href', formalName);
  427.         divRow.append(div.append(a.append(img)));
  428.     }
  429.  
  430.     // Garbage collection
  431.     if (divRow.children().size()) {
  432.         p.press.append(divRow);
  433.     }
  434.  
  435. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement