Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.13 KB | None | 0 0
  1. $(function() {
  2. var currentProjects = [],
  3. projectItem = $('.project-item'),
  4. projectItemChild = projectItem.children('.project-item-container'),
  5. hash = window.location.hash;
  6.  
  7. isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  8. isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  9. //isSafari = /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);
  10.  
  11. if (isChrome || isFirefox) {
  12. breakpoint = window.innerWidth;
  13. } else {
  14. breakpoint = $(window).innerWidth();
  15. }
  16.  
  17. FastClick.attach(document.body);
  18.  
  19.  
  20. //Loop for Hashing
  21. projectItem.each(function() {
  22. var itemHash = $(this).attr('data-hash');
  23. if (itemHash === hash) {
  24. $(this).addClass('active');
  25. }
  26. });
  27.  
  28. (function(namespace) { // Closure to protect local variable "var hash"
  29. if ('replaceState' in history) { // Yay, supported!
  30. namespace.replaceHash = function(newhash) {
  31. if (newhash) {
  32. if (('' + newhash).charAt(0) !== '#') newhash = '#' + newhash;
  33. history.replaceState('', '', newhash);
  34. } else {
  35. history.pushState('', document.title, window.location.pathname);
  36. }
  37. };
  38. } else {
  39. var hash = location.hash;
  40. namespace.replaceHash = function(newhash) {
  41. if (newhash) {
  42. if (location.hash !== hash) history.back();
  43. location.hash = newhash;
  44. } else {
  45. document.location.href.replace(location.hash , '');
  46. }
  47. };
  48. }
  49. })(window);
  50.  
  51.  
  52.  
  53. //Click State/Animation for Project Page Item Grid
  54. projectItem.on('click', function() {
  55. var prevProject = $('.project-item.active'),
  56. activeProject = $(this),
  57. activeHero = $('.project-item.active .project-item-hero'),
  58. notActiveItem = $('.project-item:not(.active)').height();
  59.  
  60. calcDimensions(this); // sets projectContainerHeight
  61.  
  62. if($(window).scrollTop() > ($(document).height() - $(window).height()*2)) {
  63. smoothResize();
  64. }
  65.  
  66. if ($(this).hasClass('active')) { // Clicked an active project, close it
  67. $(this).find('.project-item-container').animate({
  68. height: 0
  69. }, 300);
  70.  
  71. $(this).animate({
  72. height: notActiveItem
  73. }, {
  74. duration: 300,
  75. complete: function() {
  76. $(this).removeClass('active');
  77. replaceHash();
  78. }
  79. });
  80.  
  81. } else if (projectItem.hasClass('active')) { // Clicked an inactive project, with another one already open
  82.  
  83. prevProject.find('.project-item-container').animate({
  84. height: 0
  85. }, 300);
  86.  
  87. prevProject.animate({
  88. height: notActiveItem
  89. },{
  90. duration: 300,
  91. complete: function() {
  92. activeProject.addClass('active');
  93. prevProject.removeClass('active');
  94.  
  95. activeProject.animate({
  96. height: projectContainerCombined
  97. },{
  98. duration: 300,
  99. complete: function() {
  100. scrollto(activeProject);
  101. //$('.active .project-item-hero').css('opacity', '0').css('opacity', '1');
  102.  
  103. }
  104. });
  105.  
  106. setTimeout(function() {
  107. $('.project-item-hero').css('height', '').css('height', 'inherit')
  108. }, 10) // fix for new chrome bug 44.0.2403.155
  109.  
  110. activeProject.find('.project-item-container').animate({
  111. height: projectContainerCombined - projectItemHeight
  112. }, 300, function() {
  113. setTimeout(function() { // hack for weird safari 5 bug
  114. $('.project-item-hero').css({
  115. 'transform': 'scale(1)',
  116. '-webkit-transform': 'scale(1)',
  117. '-moz-transform': 'scale(1)',
  118. '-ms-transform': 'scale(1)',
  119. '-o-transform': 'scale(1)',
  120. });
  121. }, 200);
  122. });
  123. }
  124. }).dequeue();
  125.  
  126. } else { // Clicked an inactive project, with all others closed
  127.  
  128. $(this).find('.project-item-container').animate({
  129. height: projectContainerCombined - projectItemHeight
  130. }, 300);
  131.  
  132. $(this).animate({
  133. height: projectContainerCombined
  134. }, {
  135. duration: 300,
  136. complete: function() {
  137. activeProject.addClass('active');
  138. scrollto(activeProject);
  139. setTimeout(function() { // hack for weird safari 5 bug
  140. $('.project-item-hero').css({
  141. 'transform': 'scale(1)',
  142. '-webkit-transform': 'scale(1)',
  143. '-moz-transform': 'scale(1)',
  144. '-ms-transform': 'scale(1)',
  145. '-o-transform': 'scale(1)',
  146. });
  147. }, 200);
  148. }
  149. });
  150.  
  151. projectItem.siblings().removeClass('active');
  152. $(this).toggleClass('active');
  153. }
  154.  
  155. //Animate scroll to top of page
  156. itemHash = activeProject.attr('data-hash');
  157. windowHasHash = window.location.hash;
  158. replaceHash(itemHash);
  159. });
  160.  
  161. //Prevent bubbling
  162. projectItemChild.on('click', function(event) {
  163. event.stopPropagation();
  164. });
  165.  
  166. }); //END Window onload query
  167.  
  168. //Filterbar Vars
  169. var itemWrapper = $('.wrapper'),
  170. filterSelector = $('.filter-bar.projects .largenav li'),
  171. filterSelectorAll = $('.filter-bar.projects .largenav li.all'),
  172. filterValue = $(this).attr('data-filter'),
  173. clientList = $('#client-list'),
  174. clientListToggle = $('#clients');
  175.  
  176. //Filter Prototype Function
  177. Array.prototype.contains = function(elem) {
  178. for (var i in this) {
  179. if (this[i] == elem) return true;
  180. }
  181. return false;
  182. };
  183.  
  184. //Filter
  185. var filterProjects = function(filter) {
  186. projectItem.stop(true, true).hide(); // kill fadeIn if that's still running
  187. currentProjects = []; // clear the array
  188. $.each(projectItem, function() {
  189. var itemFilters = $(this).attr('data-filter'),
  190. arrSplit = itemFilters.split(', ');
  191. if (filter == 'All') {
  192. currentProjects.push($(this));
  193. filterSelectorAll.addClass('active');
  194. } else if (arrSplit.contains(filter)) {
  195. currentProjects.push($(this));
  196. }
  197. });
  198. var count = 0;
  199. $.each(currentProjects, function() {
  200. $(this).delay((count) * 80).fadeIn(200);
  201. count++;
  202. });
  203. };
  204.  
  205. // Custom select menus
  206. var $selectOptions = $('.select li a'),
  207. $selectToggle = $('#select-toggle'),
  208. navText = $('.largenav li.active a').text();
  209.  
  210. var selectList = function(selection) {
  211. $.each($selectOptions, function() {
  212. var value = $(this).text();
  213.  
  214. if (value == selection) {
  215. $selectToggle.text(value);
  216. $(this).addClass('selected');
  217. } else {
  218. $(this).removeClass('selected');
  219. }
  220. });
  221. };
  222.  
  223. selectList(navText);
  224.  
  225. $selectToggle.on({
  226. click: function(event) {
  227. event.preventDefault();
  228. if ($(this).hasClass('open')) {
  229. $(this).blur();
  230. $(this).removeClass('open');
  231. } else {
  232. $(this).focus();
  233. $(this).addClass('open');
  234. }
  235. },
  236. mousedown: function(event) {
  237. event.preventDefault(); // Safari blurs on mousedown
  238. },
  239. blur: function() {
  240. $(this).removeClass('open');
  241. }
  242. });
  243.  
  244. $selectOptions.on('click', function(event) {
  245. event.preventDefault();
  246. $selectOptions.removeClass('selected');
  247. $(this).addClass('selected');
  248. //var selection = $(this).text();
  249.  
  250. $selectToggle.removeClass('open');
  251. });
  252.  
  253. $('.news .select li a').on('click', function(event) {
  254. event.preventDefault();
  255. var url = $(this).attr('data-value');
  256. window.location = url;
  257. });
  258.  
  259. $('.projects .select li a').on('click', function(event) {
  260. event.preventDefault();
  261. var filter = $(this).text();
  262. if ($(this).is(':visible')) {
  263. $('.filter-bar.projects li[data-filter="' + filter + '"]').click();
  264. }
  265. if ($('#client-list').is(':visible')) {
  266. $('#client-list').fadeOut(200);
  267. }
  268. });
  269.  
  270. filterSelector.on('click', function() {
  271. if (!$(this).hasClass('active')) {
  272. var active = $('.project-item.active'),
  273. filter = '';
  274.  
  275. itemHash = $(this).attr('data-hash');
  276. windowHasHash = window.location.hash;
  277. replaceHash(itemHash);
  278.  
  279. if (active.length) {
  280. active.removeClass('active').css('height', projectItemHeight);
  281. $('.project-item-container').css('height', '0')
  282. }
  283.  
  284. clientList.fadeOut(200);
  285. filter = $(this).attr('data-filter');
  286. filterProjects(filter);
  287. selectList(filter);
  288.  
  289. filterSelector.removeClass('active');
  290. clientListToggle.removeClass('active');
  291. $(this).toggleClass('active');
  292. }
  293. });
  294.  
  295. clientListToggle.on('click', function() {
  296. replaceHash();
  297.  
  298. var active = $('.project-item.active');
  299.  
  300. if (active.length) {
  301. active.removeClass('active').css('height', projectItemHeight)
  302. $('.project-item-container').css('height', '0');
  303. }
  304.  
  305. filterSelector.removeClass('active');
  306. $(this).toggleClass('active');
  307. projectItem.stop(true, true).hide();
  308. projectItem.fadeOut(200);
  309. clientList.fadeIn(200);
  310. $('.column-block').isotope({
  311. itemSelector: '.client-block',
  312. layoutMode: 'masonry',
  313. });
  314. });
  315. });
  316.  
  317. <div class="filter-bar projects">
  318. <div class="container">
  319. <ul class="left largenav">
  320. <li data-filter="All" class="active all">All</li><li data-filter="Identity" data-hash="Identity">Identity</li><li data-filter="Branding" data-hash="Branding">Branding</li><li data-filter="Event" data-hash="Event">Event</li><li data-filter="Print" data-hash="Print">Print</li><li data-filter="Website" data-hash="Website">Website</li>
  321. </ul>
  322. </div>
  323.  
  324. {% include 'projects/_components/clientList' ignore missing %}
  325. {% cache %}
  326. {% set projectsArray = craft.entries.section('projects').order('title').find() %}
  327. {% set featured = [] %}
  328. {% set normal = [] %}
  329. {% set all = [] %}
  330. {% for project in projectsArray %}
  331. {% if project.featuredItem | length %}
  332. {% set featured = featured | merge([project.id]) %}
  333. {% else %}
  334. {% set normal = normal | merge([project.id]) %}
  335. {% endif %}
  336. {% endfor %}
  337. {% set all = featured | merge(normal) %}
  338. {% set projectsList = craft.entries.section('projects').id(all).fixedOrder(true).find() %}
  339. {% for item in projectsList %}
  340.  
  341. <li data-filter="{% for category in item.projectCategories %}{{ category }}{% if not loop.last %}, {% endif %}{% endfor %}" data-hash="#{{ item.slug }}" class="project-item no-touch">
  342. <div class="project-item-thumb">
  343. <div class="project-item-hoverinfo">
  344. <div class="outerContainer">
  345. <div class="innerContainer">
  346. {% if item.shortTitle|length %}
  347. {{ item.shortTitle | smartdown }}
  348. {% else %}
  349. {{ item.title | smartdown }}
  350. {% endif %}
  351. </div>
  352. </div>
  353. </div>
  354. <div class="project-item-crop">
  355. {% for image in item.gridThumbnail %}
  356. <img src="{{ image.getUrl }}" alt="">
  357. {% endfor %}
  358. </div>
  359. </div>
  360. <div class="project-item-container">
  361. <div class="project-item-hero">
  362. {% for image in item.gridHero %}
  363. <div class="hero-image" style="background-image: url('{{ image.getUrl }}')"></div>
  364. {% endfor %}
  365. </div><div class="project-item-content">
  366. <h2>{{ item.title | smartdown }}</h2>
  367. <h4>
  368. {{ item.projectLabels }}
  369. </h4>
  370. <p>{{ item.shortInfo | smartdown }}</p>
  371. {% if item.longInfo|length %}
  372. <a href="{{ item.url }}" class="button">View Project</a>
  373. {% elseif item.siteLink|length %}
  374. {{ item.siteLink.link|raw }}
  375. {% endif %}
  376.  
  377. </div>
  378. </div>
  379.  
  380. {% endfor %}
  381.  
  382. {% endcache %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement