Team:Cambridge/static/introduction.js
From 2011.igem.org
(14 intermediate revisions not shown) | |||
Line 1: | Line 1: | ||
/* | /* | ||
- | * A jQuery widget to fetch and display page introductions. | + | This file is part of the cambridge 2011 igem team's wiki. nothing is guaranteed. |
+ | |||
+ | DO WHAT THE F*CK YOU WANT TO PUBLIC LICENSE | ||
+ | Version 2, December 2004 | ||
+ | |||
+ | Copyright (C) 2011 Haydn King hjking734@gmail.com | ||
+ | |||
+ | DO WHAT THE F*CK YOU WANT TO PUBLIC LICENSE | ||
+ | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
+ | |||
+ | 0. You just DO WHAT THE F*CK YOU WANT TO. | ||
+ | */ | ||
+ | |||
+ | /* | ||
+ | * A jQuery UI widget to fetch and display page introductions. | ||
* | * | ||
* */ | * */ | ||
Line 7: | Line 21: | ||
$.widget("ui.introduction", { | $.widget("ui.introduction", { | ||
+ | options: { | ||
+ | 'baseUrl': '/Team:Cambridge/desc/', | ||
+ | }, | ||
_create: function() { | _create: function() { | ||
this.$el = $(this.element[0]); | this.$el = $(this.element[0]); | ||
Line 13: | Line 30: | ||
this.$subarea = this.$el.find('#cam_desc_subarea'); | this.$subarea = this.$el.find('#cam_desc_subarea'); | ||
this.$color = this.$el.find('#cam_desc_color'); | this.$color = this.$el.find('#cam_desc_color'); | ||
- | this.area = ' | + | this.area = ''; |
- | this.subarea = ' | + | this.subarea = ''; |
- | + | ||
}, | }, | ||
setArea: function(area, subarea) | setArea: function(area, subarea) | ||
{ | { | ||
+ | //check if we're already displaying this area/subarea | ||
+ | if((this.area == area) && (this.subarea == subarea)) return; | ||
+ | |||
this._display_content(area, subarea); | this._display_content(area, subarea); | ||
this.$area.text(area.toUpperCase()); | this.$area.text(area.toUpperCase()); | ||
Line 29: | Line 48: | ||
{ | { | ||
var self = this; | var self = this; | ||
- | var url = | + | var url = this.options.baseUrl + area.toLowerCase() + '/' + subarea.toLowerCase() + '?action=raw'; |
+ | |||
$.ajax({ | $.ajax({ | ||
'url': url, | 'url': url, | ||
Line 37: | Line 57: | ||
}, | }, | ||
'success': function(data){ | 'success': function(data){ | ||
- | self.$content.fadeOut(' | + | var $data = $(data); |
+ | colorize_links($data); | ||
+ | self.$content.fadeOut('fast', function() {$(this).html($data).fadeIn('fast');}); | ||
}, | }, | ||
}); | }); | ||
Line 44: | Line 66: | ||
{ | { | ||
var self = this; | var self = this; | ||
- | var url = ' | + | var url = this.options.baseUrl + 'default/default?action=raw'; |
$.ajax({ | $.ajax({ | ||
'url': url, | 'url': url, | ||
'dataType': 'html', | 'dataType': 'html', | ||
'error': function(jqXHR, textStatus, errorThrown) { | 'error': function(jqXHR, textStatus, errorThrown) { | ||
- | var err = '<p | + | var err = '<p style="color:red;">Description for ' + area + '/' + subarea + 'does not exist. Also, the default page returned "' + errorThrown + '"</p>'; |
- | self.$content.fadeOut(' | + | self.$content.fadeOut('fast', function() {$(this).html(err).fadeIn('fast');}); |
}, | }, | ||
'success': function(data){ | 'success': function(data){ | ||
- | var $d = $(data); | + | var $d = $('<p style="color:red;">Could not load description for "' + area + '/' + subarea + '"</p>' + data); |
- | $d.find('#add-desc-link').attr('href', | + | $d.find('#add-desc-link').attr('href', self.options.baseUrl + area + '/' + subarea + '?action=edit'); |
- | self.$content.fadeOut(' | + | self.$content.fadeOut('fast', function() {$(this).html($d).fadeIn('fast');}); |
}, | }, | ||
}); | }); |
Latest revision as of 03:25, 22 September 2011
/*
This file is part of the cambridge 2011 igem team's wiki. nothing is guaranteed.
DO WHAT THE F*CK YOU WANT TO PUBLIC LICENSE Version 2, December 2004
Copyright (C) 2011 Haydn King hjking734@gmail.com
DO WHAT THE F*CK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE F*CK YOU WANT TO.
- /
/*
* A jQuery UI 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 = ; this.subarea = ; }, setArea: function(area, subarea) {
//check if we're already displaying this area/subarea if((this.area == area) && (this.subarea == subarea)) return;
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){
var $data = $(data); colorize_links($data);
self.$content.fadeOut('fast', function() {$(this).html($data).fadeIn('fast');}); }, }); }, _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('fast', function() {$(this).html(err).fadeIn('fast');}); }, 'success': function(data){
var $d = $('Could not load description for "' + area + '/' + subarea + '"
' + data);$d.find('#add-desc-link').attr('href', self.options.baseUrl + area + '/' + subarea + '?action=edit'); self.$content.fadeOut('fast', function() {$(this).html($d).fadeIn('fast');}); }, }); }, });
})(jQuery);
$(window).ready( function() { $('#cam_desc').introduction(); });