Team:Cambridge/static/introduction.js

From 2011.igem.org

(Difference between revisions)
Line 32: Line 32:
var self = this;
var self = this;
var url = this.options.baseUrl + area.toLowerCase() + '/' + subarea.toLowerCase() + '?action=raw';
var url = this.options.baseUrl + area.toLowerCase() + '/' + subarea.toLowerCase() + '?action=raw';
-
self.$content.fadeOut('slow');
+
$.ajax({
$.ajax({
'url': url,
'url': url,
Line 40: Line 40:
},
},
'success': function(data){
'success': function(data){
-
  self.$content.html(data).fadeIn('slow');
+
  self.$content.fadeOut('slow', function() {$(this).html(data).fadeIn('slow');});
},
},
  });
  });
Line 53: Line 53:
'error': function(jqXHR, textStatus, errorThrown) {
'error': function(jqXHR, textStatus, errorThrown) {
var err = '<p class="error">Description for ' + area + '/' + subarea + 'does not exist. Also, the default page returned "' + errorThrown + '"</p>';
var err = '<p class="error">Description for ' + area + '/' + subarea + 'does not exist. Also, the default page returned "' + errorThrown + '"</p>';
-
self.$content.html(err).fadeIn('slow');
+
self.$content.fadeOut('slow', function() {$(this).html(err).fadeIn('slow');});
},
},
'success': function(data){
'success': function(data){
var $d = $(data);
var $d = $(data);
$d.find('#add-desc-link').attr('href', self.options.baseUrl + area + '/' + subarea + '?action=edit');
$d.find('#add-desc-link').attr('href', self.options.baseUrl + area + '/' + subarea + '?action=edit');
-
self.$content.html($d).fadeIn('slow');
+
self.$content.fadeOut('slow', function() {$(this).html($d).fadeIn('slow');});
},
},
  });
  });

Revision as of 15:14, 11 September 2011

/*

* A jQuery widget to fetch and display page introductions.
* 
* */

(function( $, undefined ) {

$.widget("ui.introduction", { options: { 'baseUrl': '/Team:Cambridge/desc/', }, _create: function() { this.$el = $(this.element[0]); this.$content = this.$el.find('#cam_desc_content'); this.$area = this.$el.find('#cam_desc_area'); this.$subarea = this.$el.find('#cam_desc_subarea'); this.$color = this.$el.find('#cam_desc_color'); this.area = 'overview'; this.subarea = 'home'; }, setArea: function(area, subarea) { this._display_content(area, subarea); this.$area.text(area.toUpperCase()); this.$subarea.text(subarea.toLowerCase()); this.$color.removeClass('cam-desc-' + this.area).addClass('cam-desc-' + area); this.area = area; this.subarea = subarea; }, _display_content: function(area, subarea) { var self = this; var url = this.options.baseUrl + area.toLowerCase() + '/' + subarea.toLowerCase() + '?action=raw';

$.ajax({ 'url': url, 'dataType': 'html', 'error': function(jqXHR, textStatus, errorThrown) { self._display_default(area,subarea); }, 'success': function(data){ self.$content.fadeOut('slow', function() {$(this).html(data).fadeIn('slow');}); }, }); }, _display_default: function(area, subarea) { var self = this; var url = this.options.baseUrl + 'default/default?action=raw'; $.ajax({ 'url': url, 'dataType': 'html', 'error': function(jqXHR, textStatus, errorThrown) {

var err = '

Description for ' + area + '/' + subarea + 'does not exist. Also, the default page returned "' + errorThrown + '"

';

self.$content.fadeOut('slow', function() {$(this).html(err).fadeIn('slow');}); }, 'success': function(data){ var $d = $(data); $d.find('#add-desc-link').attr('href', self.options.baseUrl + area + '/' + subarea + '?action=edit'); self.$content.fadeOut('slow', function() {$(this).html($d).fadeIn('slow');}); }, }); }, });

})(jQuery);

$(window).ready( function() { $('#cam_desc').introduction(); });