Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.04 KB | None | 0 0
  1. $(function () {
  2. var img = $('img');
  3. img.each(function () {
  4. if ($(this).attr('src').length == 0) {
  5. $(this).hide();
  6. }
  7. });
  8.  
  9. // var templete = $('.simple-post').detach();
  10. var templete = '';
  11. var content = $('.content');
  12. var postsContainer = content.find('.posts');
  13. var detailpostContainer = content.find('.single-post');
  14. if (postsContainer.length > 0) {
  15. console.log('posts');
  16. postsContainer.append(columnCreator(posts, templete, 1));
  17. } else if (detailpostContainer.length > 0) {
  18. console.log('detailpost');
  19. detailpostContainer.append(fullPostCreator(templete, posts[0]));
  20. } else {
  21. contentCreator(content, posts, templete);
  22. $(window).resize(function () {
  23. content.empty();
  24. contentCreator(content, posts, templete);
  25. });
  26. }
  27. });
  28.  
  29. function contentCreator(content, posts, templete) {
  30. var columNumber = calcColumn($(document).width());
  31. content.append(columnCreator(posts, templete, columNumber));
  32. var contentHeight = $('.content').height();
  33. var columns = '.column-' + columNumber;
  34. appendMargin(columns, contentHeight, templete);
  35. }
  36.  
  37.  
  38. function columnCreator(postsCollection, templete, columNumber) {
  39. var frag = $('<div>');
  40. for (var i = 0; i < columNumber; i++) {
  41. var column = $('<div>').addClass('column-' + columNumber);
  42. var len = postsCollection.length;
  43. for (var k = i; k < len; k = k + columNumber) {
  44. var post = postCreator(templete, postsCollection[k]);
  45. // var style = postsCollection[k].style;
  46. // if (style != 'simple-post') {
  47. // post.removeClass('simple-post');
  48. // post.addClass(style);
  49. // }
  50. column.append(post);
  51. }
  52. if (i + 1 == columNumber) {
  53. column.css("margin-right", "0");
  54. }
  55. frag.append(column);
  56. }
  57. return frag;
  58. }
  59. function templeteCreator(style) {
  60. var post = $('<div>').addClass(style);
  61. var post_image = $('<div class="post-image">').append($('<img src="">'));
  62. var gallery_image = $('<div>').addClass('gallery-image').append($('<div>').addClass('gallery-image-4')).append($('<div>').addClass('gallery-image-4')).append($('<div>').addClass('gallery-image-4')).append($('<div>').addClass('gallery-image-4'));
  63. var top_post = $(' <div class="top-post">')
  64. .append($('<div class="blog-icon">')
  65. .append($('<i class="fa" aria-hidden="true"></i>')))
  66. .append($('<h3 class="post-type"></h3>'))
  67. .append($('<h2 class="post-header"><a></a></h2>'))
  68. .append($('<h3 class="post-author"></h3>'))
  69. .append($('<h3 class="post-date"></h3>'))
  70. .append($('<p class="post-body"></p>'))
  71. .append($('<div class="short-line-up"></div>'))
  72. .append($('<a class="post-link">read more</a>'))
  73. .append($('<div class="short-line-down"></div>'));
  74. var post_footer = $('<div class="post-footer">')
  75. .append($('<div class="post-comment">')
  76. .append($(' <div class="post-icon"><i class="fa fa-comments-o" aria-hidden="true"></i></div>'))
  77. .append($(' <span>NO COMMENT</span>')))
  78. .append($('<div class="post-likes">')
  79. .append('<div class="post-icon"><i class="fa fa-heart-o" aria-hidden="true"></i></div>')
  80. .append($('<span>LIKE 25</span>')))
  81. .append($('<div class="post-average">')
  82. .append($('<span>Average</span>'))
  83. .append($('<span>5%</span>'))
  84. .append($('<i class="fa fa-star" aria-hidden="true"></i>'))
  85. )
  86. .append($('<div class="post-icons">')
  87. .append($('<div class="post-icon"><i class="fa fa-pinterest" aria-hidden="true"></i></div>'))
  88. .append($('<div class="post-icon"><i class="fa fa-twitter" aria-hidden="true"></i></div>'))
  89. .append($('<div class="post-icon"><i class="fa fa-facebook" aria-hidden="true"></i></div>'))
  90. .append($('<div class="post-icon"><i class="fa fa-dribbble" aria-hidden="true"></i></div>'))
  91. );
  92. post.append(post_image).append(gallery_image).append(top_post).append(post_footer);
  93. return post;
  94. }
  95.  
  96. function postCreator(temp, content) {
  97. // var post = temp.clone();
  98. var post = templeteCreator(content.style);
  99. post.find('.blog-icon i').addClass(content.icon);
  100. post.find('.post-type').html(content.type);
  101. post.find('.post-author').html(content.author);
  102. post.find('.post-header a').html(content.header);
  103. post.find('.post-date').html(content.date);
  104. post.find('.post-body').html(content.body.substr(0, 250));
  105. if (content.dark_auth) {
  106. post.find('.post-link').html(content.dark_auth);
  107. }
  108. post.attr('id', content.id);
  109. return post;
  110. }
  111. function fullPostCreator(temp, content) {
  112. // var post = temp.clone();
  113. var post = templeteCreator(content.style);
  114. post.find('.blog-icon i').addClass(content.icon);
  115. post.find('.post-type').html(content.type);
  116. post.find('.post-author').html('<i class="fa fa-user" aria-hidden="true"></i>' + content.author);
  117. post.find('.post-header a').html(content.header);
  118. post.find('.post-date').html('<i class="fa fa-calendar" aria-hidden="true"></i>' + content.date);
  119. post.find('.post-body').html(content.body);
  120. if (content.dark_auth) {
  121. post.find('.post-link').html(content.dark_auth);
  122. }
  123. post.attr('id', content.id);
  124. return post;
  125. }
  126. function emptyPostCreator(temp) {
  127. var post = temp.clone();
  128. post.css('margin-bottom', '0 !important');
  129. return post;
  130. }
  131.  
  132. function appendMargin(columns, contentHeight, templete) {
  133. $(columns).each(function (el, i) {
  134. var column = $(this);
  135. var childrenHeight = 0;
  136. var childrenNumber = $(this).children().length;
  137. column.children().each(function (i) {
  138. childrenHeight = childrenHeight + $(this).height();
  139. });
  140. var margin = (contentHeight - childrenHeight - 30) / (childrenNumber - 1);
  141. //
  142. // if (margin > 300) {
  143. // // console.log('margin > 300');
  144. // var emptyPost = emptyPostCreator(templete);
  145. // emptyPost.height(300);
  146. // margin -= 300;
  147. // column.append(emptyPost);
  148. //
  149. // }
  150. $(this).children().each(function (i) {
  151. if (i != childrenNumber - 1) {
  152. $(this).css('margin-bottom', margin);
  153. }
  154. });
  155. });
  156. }
  157.  
  158. function calcColumn(width) {
  159. var columNumber = 4;
  160. if (width < 1600) {
  161. columNumber = 3;
  162. }
  163. if (width < 1150) {
  164. columNumber = 2;
  165. }
  166. if (width < 680) {
  167. columNumber = 1;
  168. }
  169. return columNumber;
  170. }
  171.  
  172.  
  173. var posts = [
  174. {
  175. id: 0,
  176. author: "JHONE ALBERT",
  177. icon: "fa-pencil",
  178. style: 'simple-post',
  179. type: 'travelling',
  180. header: "Travel besT Adventure",
  181. date: "January 25, 2016",
  182. body: "This is Photoshop's version now we’s of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor, nisi eiilit consequat ipsum, nec sagittis sem nibh id elit. Duis sed odio sit amet nibh vulputate cursus a sit amet mauris. Morbi accumsans ipsum velit. Nam nec tellus a odio tincidunt auctor a ornare odio. Sed non mauris vitae erat consequat auctor eu in elit. Class aptent taciti have a great is the best sociosqu ad litora torquent per conubia nostra.Exercitation photo booths stumptowns totes bag Banksy, elit small batchbit kale chips proident chillwave have a great work deep haves laborum.Proins gravida nibh vel velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagitgitis sem nibh id elit. Duis sed odio sit amet nibh vulputate cursus a sit amet mauris. Morbi accumsan ipsum velit. Nam nec terzllus a odio tincidunt auctor a ornare odio. Sed non mauris vitae erat consequat auctor eu in elit. Class aptent taciti Duis aute irure dolor in reprehenderit in voluptate velit. Qui officia deserunt mollit anim id est labosasirum. Corrupti quosalores et quas molestias excepturi sint occaecati. Facere possimus, omnis voluptas assumenda have esOmnis dolor repellendus. Ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis.Et harum quidem the odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque.sociosqu ad litora torquent per conubia nostra.What a crowded bazaar! There were large crowds of people at the shops. There were motor cars, rickshaws, scooters and taxies. The has buses, too, were plying up and own the bazaar. We kept to the foot-path. Soon we were at the Fountain. There we is th saw the Gurdwara Sis Ganj with its golden dome. A large number of devotees were going in or coming out.We moved on. There were shops dealing in all sorts of goods. There were the cloth merchants, chemists, jewellers, confectioners1, tobaccoonists, leather goods merchants, wine merchants, gramophone dealers, radio shops and shops dealing in general merchandise. The show cases exhibited the goods in style to great idea gave a so much tempt us."
  183. },
  184. {
  185. id: 1,
  186. author: "JHONE ALBERT",
  187. icon: "fa-picture-o",
  188. style: 'simple-post-image',
  189. type: 'travelling',
  190. header: "Standard Image Post ",
  191. date: "January 25, 2016",
  192. body: "Lorem ipsum doloirs sit amet, csatetur adipisicin, sed does eiusmod tehampor choice is the have great work."
  193. },
  194. {
  195. id: 2,
  196. author: "JHONE ALBERT",
  197. icon: "fa-pencil",
  198. style: 'simple-post',
  199. type: 'Fashion',
  200. header: "Simple post style ",
  201. date: "January 02, 2016",
  202. body: "Lorem ipsum doloirs sit amet, csatetur adipisicin, sed does eiusmod tehampor choice is the have great work."
  203. },
  204. {
  205. id: 3,
  206. author: "JHONE ALBERT",
  207. icon: "",
  208. style: 'simple-post-just-image',
  209. type: '',
  210. header: "",
  211. date: "",
  212. body: ""
  213. },
  214. {
  215. id: 4,
  216. author: "JHONE ALBERT",
  217. icon: "",
  218. style: 'simple-post-just-image',
  219. type: 'travelling',
  220. header: "Standard Image Post ",
  221. date: "January 25, 2016",
  222. body: ""
  223. },
  224. {
  225. id: 5,
  226. author: "JHONE ALBERT",
  227. icon: "fa-music",
  228. style: 'simple-post-dark',
  229. type: 'Fashion',
  230. header: "Simple post style ",
  231. dark_auth: 'Nathalia Alexy',
  232. date: "January 02, 2016",
  233.  
  234. body: "As per Lorm ipsum dolor sitamet, consectetur adipisicing elits, sed do Now eiusmod tempor havei ut labores et dolore magna aliqusa. Ut wenim ad minim veniam, quis its a snostrud now is the ullamco aliquip ex ea commodo ."
  235. },
  236. {
  237. id: 6,
  238. author: "JHONE ALBERT",
  239. style: 'simple-post-gallery',
  240. type: 'Adventures',
  241. header: "awesome Gallery Post",
  242. date: "January 19, 2016",
  243. body: ""
  244. },
  245. {
  246. id: 7,
  247. author: "JHONE ALBERT",
  248. style: 'simple-post',
  249. type: 'Fashion',
  250. header: "Simple post style ",
  251. date: "January 02, 2016",
  252. body: "Lorem ipsum doloirs sit amet, csatetur adipisicin, sed does eiusmod tehampor choice is the have great work."
  253. }
  254. ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement