| 
									
										
										
										
											2014-03-28 14:18:42 -04:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2014-10-04 18:56:33 -04:00
										 |  |  | /*global ajaxify, templates, config, RELATIVE_PATH*/ | 
					
						
							| 
									
										
										
										
											2014-03-28 14:18:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | (function(ajaxify) { | 
					
						
							| 
									
										
										
										
											2014-03-28 15:35:07 -04:00
										 |  |  | 	ajaxify.widgets = {}; | 
					
						
							| 
									
										
										
										
											2014-04-03 17:27:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-31 12:54:27 -04:00
										 |  |  | 	ajaxify.widgets.reposition = function(location) { | 
					
						
							| 
									
										
										
										
											2014-03-28 14:18:42 -04:00
										 |  |  | 		$('body [no-widget-class]').each(function() { | 
					
						
							|  |  |  | 			var $this = $(this); | 
					
						
							| 
									
										
										
										
											2014-03-31 12:54:27 -04:00
										 |  |  | 			if ($this.attr('no-widget-target') === location) { | 
					
						
							|  |  |  | 				$this.removeClass(); | 
					
						
							| 
									
										
										
										
											2014-04-03 17:27:26 -04:00
										 |  |  | 				$this.addClass($this.attr('no-widget-class')); | 
					
						
							| 
									
										
										
										
											2014-03-31 12:54:27 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-03-28 14:18:42 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-09 19:23:03 -04:00
										 |  |  | 	ajaxify.widgets.render = function(template, url, callback) { | 
					
						
							| 
									
										
										
										
											2015-06-29 15:16:36 -04:00
										 |  |  | 		if (template.match(/^admin/)) { | 
					
						
							| 
									
										
										
										
											2015-07-08 17:12:06 -04:00
										 |  |  | 			return callback(); | 
					
						
							| 
									
										
										
										
											2015-06-29 15:16:36 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-10 17:13:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 16:30:16 -04:00
										 |  |  | 		var widgetLocations = ['sidebar', 'footer', 'header'], numLocations; | 
					
						
							| 
									
										
										
										
											2014-03-28 14:18:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$('#content [widget-area]').each(function() { | 
					
						
							| 
									
										
										
										
											2014-04-09 16:35:51 -04:00
										 |  |  | 			var location = $(this).attr('widget-area'); | 
					
						
							|  |  |  | 			if ($.inArray(location, widgetLocations) === -1) { | 
					
						
							|  |  |  | 				widgetLocations.push(location); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-03-28 14:18:42 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		numLocations = widgetLocations.length; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!numLocations) { | 
					
						
							|  |  |  | 			ajaxify.widgets.reposition(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-07-20 14:35:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 		function renderWidgets(locations) { | 
					
						
							|  |  |  | 			var areaDatas = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-04 18:30:21 -04:00
										 |  |  | 			$.get(RELATIVE_PATH + '/api/widgets/render' + (config['cache-buster'] ? '?v=' + config['cache-buster'] : ''), { | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 				locations: locations, | 
					
						
							|  |  |  | 				template: template + '.tpl', | 
					
						
							|  |  |  | 				url: url | 
					
						
							|  |  |  | 			}, function(renderedAreas) { | 
					
						
							|  |  |  | 				for (var x=0; x<renderedAreas.length; ++x) { | 
					
						
							|  |  |  | 					var renderedWidgets = renderedAreas[x].widgets, | 
					
						
							|  |  |  | 						location = renderedAreas[x].location, | 
					
						
							|  |  |  | 						html = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					for (var i=0; i<renderedWidgets.length; ++i) { | 
					
						
							|  |  |  | 						html += templates.parse(renderedWidgets[i].html, {}); | 
					
						
							| 
									
										
										
										
											2014-04-01 11:22:03 -04:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 					var area = $('#content [widget-area="' + location + '"]'); | 
					
						
							| 
									
										
										
										
											2014-04-01 11:22:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 					if (!area.length && window.location.pathname.indexOf('/admin') === -1 && renderedWidgets.length) { | 
					
						
							|  |  |  | 						if (location === 'footer' && !$('#content [widget-area="footer"]').length) { | 
					
						
							| 
									
										
										
										
											2014-12-23 23:49:15 +01:00
										 |  |  | 							$('#content').append($('<div class="row"><div widget-area="footer" class="col-xs-12"></div></div>')); | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 						} else if (location === 'sidebar' && !$('#content [widget-area="sidebar"]').length) { | 
					
						
							| 
									
										
										
										
											2015-11-10 14:40:11 -05:00
										 |  |  | 							if ($('[component="account/cover"]').length) { | 
					
						
							|  |  |  | 								$('[component="account/cover"]').nextAll().wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>')); | 
					
						
							|  |  |  | 							} else if ($('[component="groups/cover"]').length) { | 
					
						
							|  |  |  | 								$('[component="groups/cover"]').nextAll().wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>')); | 
					
						
							|  |  |  | 							} else { | 
					
						
							|  |  |  | 								$('#content > *').wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>')); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 						} else if (location === 'header' && !$('#content [widget-area="header"]').length) { | 
					
						
							| 
									
										
										
										
											2014-12-23 23:49:15 +01:00
										 |  |  | 							$('#content').prepend($('<div class="row"><div widget-area="header" class="col-xs-12"></div></div>')); | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2014-06-22 17:08:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 						area = $('#content [widget-area="' + location + '"]'); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-03-28 16:01:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 					area.html(html); | 
					
						
							| 
									
										
										
										
											2014-03-28 14:18:42 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 					if (!renderedWidgets.length) { | 
					
						
							|  |  |  | 						area.addClass('hidden'); | 
					
						
							|  |  |  | 						ajaxify.widgets.reposition(location); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-03-12 17:46:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-23 12:55:44 -05:00
										 |  |  | 				var widgetAreas = $('#content [widget-area]'); | 
					
						
							| 
									
										
										
										
											2015-09-10 17:13:36 -04:00
										 |  |  | 				widgetAreas.find('img:not(.not-responsive)').addClass('img-responsive'); | 
					
						
							| 
									
										
										
										
											2015-03-16 17:22:44 -04:00
										 |  |  | 				widgetAreas.find('.timeago').timeago(); | 
					
						
							| 
									
										
										
										
											2015-03-12 17:46:49 -04:00
										 |  |  | 				widgetAreas.find('img[title].teaser-pic,img[title].user-img').each(function() { | 
					
						
							|  |  |  | 					$(this).tooltip({ | 
					
						
							|  |  |  | 						placement: 'top', | 
					
						
							|  |  |  | 						title: $(this).attr('title') | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2014-05-26 11:37:50 -04:00
										 |  |  | 				$(window).trigger('action:widgets.loaded', {}); | 
					
						
							| 
									
										
										
										
											2015-02-11 21:09:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 12:26:41 -04:00
										 |  |  | 				if (typeof callback === 'function') { | 
					
						
							|  |  |  | 					callback(); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2014-03-28 14:18:42 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-16 10:12:12 -04:00
										 |  |  | 		renderWidgets(widgetLocations); | 
					
						
							| 
									
										
										
										
											2014-03-28 14:18:42 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-04-10 20:31:57 +01:00
										 |  |  | }(ajaxify || {})); |