Mercurial > defr > drupal > scald > dnd
changeset 47:cbfe386cb51b
Add a function to refresh opened libraries.
The source URL of each libraries is now tracked, which allows for auto
refreshing the libraries based on various events. The obvious use
case is to refresh the library when an atom has been added to Scald,
for example via a Popups dialog.
author | Franck Deroche <defr@ows.fr> |
---|---|
date | Mon, 15 Feb 2010 14:08:04 +0000 |
parents | 2ba96288fbea |
children | f817d2a5cc0a |
files | js/dnd-library.js |
diffstat | 1 files changed, 23 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/js/dnd-library.js Thu Jan 14 15:42:39 2010 +0000 +++ b/js/dnd-library.js Mon Feb 15 14:08:04 2010 +0000 @@ -82,8 +82,10 @@ } // Initialize the library + var wrapper = $this.get(0); + wrapper.library_url = Drupal.settings.basePath + settings.url; $.getJSON(Drupal.settings.basePath + settings.url, function(data) { - Drupal.behaviors.dndLibrary.renderLibrary.call($this.get(0), data, $editor); + Drupal.behaviors.dndLibrary.renderLibrary.call(wrapper, data, $editor); }); }); @@ -132,6 +134,7 @@ $('.pager a', $this).click(function() { // At page switching, close all opened BeautyTips. $('.editor-item.bt-active').btOff(); + $this.get(0).library_url = this.href; $.getJSON(this.href, function(data) { Drupal.behaviors.dndLibrary.renderLibrary.call($this.get(0), data, $(editor)); }); @@ -143,7 +146,8 @@ 'url' : Drupal.settings.basePath + settings.url, 'dataType' : 'json', 'success' : function(data) { - var target = submit.parents('div.dnd-library-wrapper'); + var target = submit.parents('div.dnd-library-wrapper').get(0); + target.library_url = this.url; Drupal.behaviors.dndLibrary.renderLibrary.call(target, data, $(editor)); } }); @@ -155,7 +159,8 @@ 'url' : Drupal.settings.basePath + settings.url, 'dataType' : 'json', 'success' : function(data) { - var target = reset.parents('div.dnd-library-wrapper'); + var target = reset.parents('div.dnd-library-wrapper').get(0); + target.library_url = Drupal.dndEnabledLibraries[editor].url; Drupal.behaviors.dndLibrary.renderLibrary.call(target, data, $(editor)); }, 'beforeSubmit': function (data, form, options) { @@ -359,3 +364,18 @@ $(target).data('dnd_representation_counter', counter); return counter[representation_id]; } + +/** + * Refresh the library. + */ +Drupal.dnd = {} +Drupal.dnd.refreshLibraries = function() { + var settings = Drupal.settings.dndEnabledLibraries; + for (editor_id in settings) { + var elem = $("#" + settings[editor_id].library_id).get(0); + var $editor = $("#" + editor_id); + $.getJSON(elem.library_url, function (data) { + Drupal.behaviors.dndLibrary.renderLibrary.call(elem, data, $editor); + }); + } +}