2 if (Drupal.jsEnabled) {
\r
3 $(document).ready(eventAutoAttach);
\r
7 * Attaches the block update behaviour to links tagged with 'updateblock' class.
\r
9 function eventAutoAttach() {
\r
10 $("#block-event-0 div.content a.updateblock").click(function() {
\r
11 this.blockUpdater = new blockUpdater( $(this).parents(".content"), $(this).attr("href").replace("month", "block"), eventAutoAttach);
\r
18 * create an instance of this object in the onClick handler for block update links.
\r
20 * could be separated into misc/blockupdater.js
\r
23 function blockUpdater(element,url,callback) {
\r
24 var blockUpdate = this;
\r
25 element.blockUpdate = this;
\r
27 this.element = element;
\r
28 this.callback = callback;
\r
30 this.oldHTML = this.element.html();
\r
32 // Keep block at it's current width/height to make the update less disruptive
\r
33 this.styleHeight = $(element).height();
\r
34 this.styleWidth = $(element).width();
\r
35 $(element).height(element[0].offsetHeight+"px");
\r
36 $(element).width(element[0].offsetWidth+"px");
\r
38 // Clear block contents
\r
39 $(element).html("");
\r
41 // Insert progressbar
\r
42 this.progress = new Drupal.progressBar('updateprogress');
\r
43 $(this.element).prepend(this.progress.element);
\r
46 var cancel = document.createElement("a");
\r
47 $(cancel).html("cancel").attr("alt","cancel").addClass("cancel-update")
\r
48 .attr("href", "#").bind("click", function() {
\r
49 rel.update("abort",undefined,blockUpdate);
\r
53 this.element.prepend($(cancel));
\r
55 this.dontUpdate = false;
\r
56 $.get(url,function(data){
\r
57 blockUpdate.update(data)});
\r
59 blockUpdater.prototype.update = function (xmlHttp) {
\r
60 var blockUpdate=this;
\r
61 if(!blockUpdate.dontUpdate) {
\r
62 if(xmlHttp == 'abort') {
\r
63 blockUpdate.element.html(this.oldHTML);
\r
64 blockUpdate.element.append("<p class='calendar-log'>Update aborted.</p>");
\r
66 blockUpdate.element.height(blockUpdate.styleHeight);
\r
67 blockUpdate.element.width(blockUpdate.styleWidth);
\r
68 blockUpdate.element.html(xmlHttp);
\r
69 blockUpdate.dontUpdate = true;
\r
71 blockUpdate.dontUpdate = true;
\r
72 if(blockUpdate.callback != undefined)
\r
73 blockUpdate.callback();
\r