Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added event trigger after content is set. #41

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions hinclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,30 @@ var hinclude;
hinclude = {
classprefix: "include_",

/**
* @param target can be any DOM Element or other EventTarget
* @param type Event type (i.e. 'click')
* @param event Placeholder for creating an Event
*/
trigger_event: function (target, type, event) {
var doc = document;
if (doc.createEvent) {
event = doc.createEvent("Event");
event.initEvent(type, true, true);
target.dispatchEvent(event);
} else {
event = doc.createEventObject();
target.fireEvent('on' + type, event);
}
},

set_content_async: function (element, req) {
if (req.readyState === 4) {
if (req.status === 200 || req.status === 304) {
element.innerHTML = req.responseText;
}
element.className = hinclude.classprefix + req.status;
hinclude.trigger_event(document, 'hinclude_content_set');
}
},

Expand All @@ -55,6 +73,7 @@ var hinclude;
if (hinclude.outstanding === 0) {
hinclude.show_buffered_content();
}
hinclude.trigger_event(document, 'hinclude_content_set');
}
},

Expand Down