Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Main {
  2.  
  3.     constructor () {
  4.         this.setImageTemplate = ::this.setImageTemplate;
  5.         this.openTemplate = ::this.openTemplate;
  6.  
  7.         // El
  8.         this.testBtn = document.querySelector('.btn-test-overlay');
  9.         this.overlayImageTemplate = document.querySelector('#overlay-image');
  10.  
  11.         // Get all posts
  12.         this.getAllposts();
  13.  
  14.         // Set custom Binder for style
  15.         this.setCustomBinding();
  16.     }
  17.  
  18.     getAllposts(){
  19.         const posts = new wp.api.collections.Posts();
  20.         posts.fetch().done((posts)=>{
  21.             this.posts = posts;
  22.             this.testBtn.addEventListener('click',this.openTemplate);
  23.         });
  24.     }
  25.  
  26.     openTemplate(e){
  27.         const postId = e.target.getAttribute('data-id');
  28.         const postOverlayType = e.target.getAttribute('data-overlay-type');
  29.         const postOverlayColor = e.target.getAttribute('data-color');
  30.  
  31.         if(postOverlayType == 'image'){
  32.             this.setImageTemplate(this.posts[postId],postOverlayColor);
  33.         }else if(postOverlayType == 'content'){
  34.             this.setContentTemplate(this.posts[postId],postOverlayColor);
  35.         }
  36.     }
  37.  
  38.     setImageTemplate(post,postOverlayColor){
  39.         var data = {
  40.             title: post.title.rendered,
  41.             color: postOverlayColor
  42.         };
  43.  
  44.         rivets.bind( this.overlayImageTemplate , { data : data });
  45.  
  46.         TweenMax.to(this.overlayImageTemplate,1,{opacity:1});
  47.     }
  48.  
  49.     setContentTemplate(post,postOverlayColor){
  50.  
  51.     }
  52.  
  53.     setCustomBinding(){
  54.         rivets.binders['style-*'] = function(el, value){
  55.             el.style.setProperty(this.args[0], value);
  56.         };
  57.     }
  58. }
  59.  
  60. new Main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement