Commits

Dmitri Lebedev committed 20a3c41

added bind_update_handler to subscribe to init and update events

  • Participants
  • Parent commits 73477b2

Comments (0)

Files changed (1)

File example/media/js/partial.js

-define(['exports', 'jquery', '/m/js/3party/history.adapter.jquery.js', '/m/js/3party/history.js'], function(self) {
+define(['exports', 'jquery', '/s/js/3party/history.adapter.jquery.js', '/s/js/3party/history.js'], function(self) {
 	// these settings can be changed from an importing module
 	// example: define(['partial'], function (partial) { partial.default_selector = '#content'; });
 	
 	
 	self.set_data = function (data) {
 		$.extend(self.data, data);
+		$(document).trigger('partial_data_update', [data.data]);
 	};
 	
 	self.replace_all_blocks = function (data, status, xhr) {
 		janchors.filter(self.xhr_selector).click(self.update_partial_as_is);
 	};
 
+	self.bind_update_handler = function () {
+		var handlers = arguments,
+			jdoc = $(document);
+		$(function() {
+			$.each(handlers, function (k, handler) {
+				jdoc
+					.bind('partial_update', handler)
+					.one('partial_init', handler)
+					
+			});
+		});
+		jdoc.trigger('partial_init', [jdoc, self.data]);
+	};
+	
 	/* decorated in a function to avoid an infinite loop in jQuery */
-	$(function() {
-		$(document).bind('partial_update', self.install_handlers).trigger('partial_update', [$(document)]);
-	}); // executed on document.ready
+	self.bind_update_handler(self.install_handlers);
 });