# HG changeset patch # User Franck Deroche # Date 1266242884 0 # Node ID cbfe386cb51ba21f022089e80a033accd94f4329 # Parent 2ba96288fbea4f963a642dd31a82d3297c40ed7c 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. diff -r 2ba96288fbea -r cbfe386cb51b js/dnd-library.js --- 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); + }); + } +}