Mercurial > defr > drupal > scald > dnd
comparison js/dnd-library.js @ 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 | 5cf2b262b9e4 |
comparison
equal
deleted
inserted
replaced
46:2ba96288fbea | 47:cbfe386cb51b |
---|---|
80 if (settings.url instanceof Object) { | 80 if (settings.url instanceof Object) { |
81 settings.url = settings.url[0]; | 81 settings.url = settings.url[0]; |
82 } | 82 } |
83 | 83 |
84 // Initialize the library | 84 // Initialize the library |
85 var wrapper = $this.get(0); | |
86 wrapper.library_url = Drupal.settings.basePath + settings.url; | |
85 $.getJSON(Drupal.settings.basePath + settings.url, function(data) { | 87 $.getJSON(Drupal.settings.basePath + settings.url, function(data) { |
86 Drupal.behaviors.dndLibrary.renderLibrary.call($this.get(0), data, $editor); | 88 Drupal.behaviors.dndLibrary.renderLibrary.call(wrapper, data, $editor); |
87 }); | 89 }); |
88 | 90 |
89 }); | 91 }); |
90 } | 92 } |
91 | 93 |
130 $.data($(editor), 'dnd_preload', cached); | 132 $.data($(editor), 'dnd_preload', cached); |
131 | 133 |
132 $('.pager a', $this).click(function() { | 134 $('.pager a', $this).click(function() { |
133 // At page switching, close all opened BeautyTips. | 135 // At page switching, close all opened BeautyTips. |
134 $('.editor-item.bt-active').btOff(); | 136 $('.editor-item.bt-active').btOff(); |
137 $this.get(0).library_url = this.href; | |
135 $.getJSON(this.href, function(data) { | 138 $.getJSON(this.href, function(data) { |
136 Drupal.behaviors.dndLibrary.renderLibrary.call($this.get(0), data, $(editor)); | 139 Drupal.behaviors.dndLibrary.renderLibrary.call($this.get(0), data, $(editor)); |
137 }); | 140 }); |
138 return false; | 141 return false; |
139 }); | 142 }); |
141 var submit = $(this); | 144 var submit = $(this); |
142 $('.view-filters form', $this).ajaxSubmit({ | 145 $('.view-filters form', $this).ajaxSubmit({ |
143 'url' : Drupal.settings.basePath + settings.url, | 146 'url' : Drupal.settings.basePath + settings.url, |
144 'dataType' : 'json', | 147 'dataType' : 'json', |
145 'success' : function(data) { | 148 'success' : function(data) { |
146 var target = submit.parents('div.dnd-library-wrapper'); | 149 var target = submit.parents('div.dnd-library-wrapper').get(0); |
150 target.library_url = this.url; | |
147 Drupal.behaviors.dndLibrary.renderLibrary.call(target, data, $(editor)); | 151 Drupal.behaviors.dndLibrary.renderLibrary.call(target, data, $(editor)); |
148 } | 152 } |
149 }); | 153 }); |
150 return false; | 154 return false; |
151 }); | 155 }); |
153 var reset = $(this); | 157 var reset = $(this); |
154 $('.view-filters form', $this).ajaxSubmit({ | 158 $('.view-filters form', $this).ajaxSubmit({ |
155 'url' : Drupal.settings.basePath + settings.url, | 159 'url' : Drupal.settings.basePath + settings.url, |
156 'dataType' : 'json', | 160 'dataType' : 'json', |
157 'success' : function(data) { | 161 'success' : function(data) { |
158 var target = reset.parents('div.dnd-library-wrapper'); | 162 var target = reset.parents('div.dnd-library-wrapper').get(0); |
163 target.library_url = Drupal.dndEnabledLibraries[editor].url; | |
159 Drupal.behaviors.dndLibrary.renderLibrary.call(target, data, $(editor)); | 164 Drupal.behaviors.dndLibrary.renderLibrary.call(target, data, $(editor)); |
160 }, | 165 }, |
161 'beforeSubmit': function (data, form, options) { | 166 'beforeSubmit': function (data, form, options) { |
162 // Can't use data = [], otherwise we're creating a new array | 167 // Can't use data = [], otherwise we're creating a new array |
163 // instead of modifying the existing one. | 168 // instead of modifying the existing one. |
357 counter[representation_id] = counter[representation_id] + ((decrement) ? -1 : 1); | 362 counter[representation_id] = counter[representation_id] + ((decrement) ? -1 : 1); |
358 } | 363 } |
359 $(target).data('dnd_representation_counter', counter); | 364 $(target).data('dnd_representation_counter', counter); |
360 return counter[representation_id]; | 365 return counter[representation_id]; |
361 } | 366 } |
367 | |
368 /** | |
369 * Refresh the library. | |
370 */ | |
371 Drupal.dnd = {} | |
372 Drupal.dnd.refreshLibraries = function() { | |
373 var settings = Drupal.settings.dndEnabledLibraries; | |
374 for (editor_id in settings) { | |
375 var elem = $("#" + settings[editor_id].library_id).get(0); | |
376 var $editor = $("#" + editor_id); | |
377 $.getJSON(elem.library_url, function (data) { | |
378 Drupal.behaviors.dndLibrary.renderLibrary.call(elem, data, $editor); | |
379 }); | |
380 } | |
381 } |