aboutsummaryrefslogtreecommitdiff
path: root/mod/embed/views/default/js
diff options
context:
space:
mode:
authorcash <cash.costello@gmail.com>2011-06-19 15:08:02 -0400
committercash <cash.costello@gmail.com>2011-06-19 15:08:02 -0400
commitdfa2fc4e66463ea385dd90674585fb8e3514ba68 (patch)
treee70859f4e39ffbe9519ac222a34309e6594cd6af /mod/embed/views/default/js
parent6e05a5d7486ede1c8408144b823b895c6282f270 (diff)
downloadelgg-dfa2fc4e66463ea385dd90674585fb8e3514ba68.tar.gz
elgg-dfa2fc4e66463ea385dd90674585fb8e3514ba68.tar.bz2
File uploads working now. It is hard coded to only work with file plugin.
Diffstat (limited to 'mod/embed/views/default/js')
-rw-r--r--mod/embed/views/default/js/embed/embed.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/mod/embed/views/default/js/embed/embed.php b/mod/embed/views/default/js/embed/embed.php
index 3b398af3a..39d400715 100644
--- a/mod/embed/views/default/js/embed/embed.php
+++ b/mod/embed/views/default/js/embed/embed.php
@@ -17,6 +17,8 @@ elgg.embed.init = function() {
$('.embed-wrapper .elgg-pagination a').live('click', elgg.embed.pagination);
$('.embed-section').live('click', elgg.embed.loadTab);
+
+ $('.embed-upload .elgg-form').live('submit', elgg.embed.submit);
}
/**
@@ -42,6 +44,43 @@ elgg.embed.insert = function(event) {
}
/**
+ * Submit an upload form through Ajax
+ *
+ * Requires the jQuery Form Plugin. Because files cannot be uploaded with
+ * XMLHttpRequest, the plugin uses an invisible iframe. This results in the
+ * the X-Requested-With header not being set. To work around this, we are
+ * sending the header as a POST variable and Elgg's code checks for it in
+ * elgg_is_xhr().
+ *
+ * @param {Object} event
+ * @return bool
+ */
+elgg.embed.submit = function(event) {
+
+ $(this).ajaxSubmit({
+ dataType : 'json',
+ data : { 'X-Requested-With' : 'XMLHttpRequest'},
+ success : function(response) {
+ if (response) {
+ if (response.system_messages) {
+ elgg.register_error(response.system_messages.error);
+ elgg.system_message(response.system_messages.success);
+ }
+ if (response.status >= 0) {
+ // @todo - really this should forward to what the registered defined
+ // For example, forward to images tab if an image was uploaded
+ var url = elgg.config.wwwroot + 'embed/embed?active_section=file';
+ $('.embed-wrapper').parent().load(url);
+ }
+ }
+ }
+ });
+
+ // this is bubbling up the DOM and causing a submission so return false
+ return false;
+}
+
+/**
* Loads the next chunk of content within the lightbox
*
* @param {Object} event