/[drupal]/contributions/modules/shoutbox/shoutbox-form.js
ViewVC logotype

Contents of /contributions/modules/shoutbox/shoutbox-form.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (show annotations) (download) (as text)
Fri Apr 18 07:38:06 2008 UTC (19 months, 1 week ago) by disterics
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +40 -32 lines
File MIME type: text/javascript
Merge bug fixes from 6.x branch
#215450 by disterics:  Handle case of 1st shout.
#211424 by disterics: New shout no longer erases last shout.
#229104 by axlen: Fixed timezone for shout titles.
1 // $Id: shoutbox-form.js,v 1.9.2.2 2008/04/18 06:55:21 disterics Exp $
2
3 if (typeof(Drupal) == "undefined" || !Drupal.shoutbox) {
4 Drupal.shoutbox = {};
5 }
6
7 /*
8 * Submit shout with javascript.
9 *
10 */
11
12 Drupal.shoutbox.attachShoutAddForm = function () {
13 // initial color to use for first post
14 // tell server what color to use
15 $("input[@name='nextcolor']").val(Drupal.settings.shoutbox.color);
16 var options = {
17 resetForm: true,
18 beforeSubmit: Drupal.shoutbox.validate,
19 success: Drupal.shoutbox.success
20 };
21
22 $("#shoutbox-add-form").ajaxForm(options);
23 }
24
25 /**
26 * Display response text and update the color
27 * field. Remove top message if we are over
28 * the max count.
29 */
30
31 Drupal.shoutbox.success = function (responseText) {
32
33 if (Drupal.settings.shoutbox.shownAmount == 0) {
34 $('#shoutbox-posts').children().eq(0).remove();
35 Drupal.settings.shoutbox.shownAmount += 1;
36 }
37 else if(Drupal.settings.shoutbox.shownAmount >= Drupal.settings.shoutbox.showAmount) {
38 var indexToRemove = ((Drupal.settings.shoutbox.ascending) ? ($('#shoutbox-posts').children().length - 1)
39 : 0 );
40 $('#shoutbox-posts').children().eq(indexToRemove).remove();
41 }
42 else {
43 Drupal.settings.shoutbox.shownAmount += 1;
44 }
45 //update color
46 Drupal.settings.shoutbox.color = (Drupal.settings.shoutbox.color) ? 0 : 1;
47 if(Drupal.settings.shoutbox.ascending) {
48 $('#shoutbox-posts').prepend(responseText);
49 }
50 else {
51 $('#shoutbox-posts').append(responseText);
52 }
53
54 // tell server what color to use
55 $("input[@name='nextcolor']").val(Drupal.settings.shoutbox.color);
56
57 }
58
59 /**
60 * Attach focus handling code to the form
61 * fields
62 *
63 */
64 Drupal.shoutbox.attachForm = function() {
65 $('input#edit-nick').focus(
66 function() {
67 if( $(this).val() == Drupal.settings.shoutbox.defaultNick) {
68 $(this).val("");
69 }
70 }
71 );
72 $('input#edit-message').focus(
73 function() {
74 if( $(this).val() == Drupal.settings.shoutbox.defaultMsg) {
75 $(this).val("");
76 }
77 }
78 );
79 $('input#edit-url').focus(
80 function() {
81 if( $(this).val() == Drupal.settings.shoutbox.defaultUrl) {
82 $(this).val("");
83 }
84 }
85 );
86 }
87
88 /**
89 * Creates a timer that triggers every delay seconds.
90 */
91 Drupal.shoutbox.startTimer = function(delay) {
92 Drupal.shoutbox.interval = setInterval("Drupal.shoutbox.loadShouts()",delay);
93 }
94
95 /**
96 * Reloads all shouts from the server.
97 */
98 Drupal.shoutbox.loadShouts = function() {
99 $("#shoutbox-posts").load(Drupal.settings.shoutbox.refreshPath);
100 }
101
102 /**
103 * Validate input before submitting.
104 * Don't accept default values or empty strings.
105 */
106
107 Drupal.shoutbox.validate = function (formData, jqForm, options) {
108 var form = jqForm[0];
109 if ((form.nick.value == Drupal.settings.shoutbox.defaultNick) ||
110 (!form.nick.value)) {
111 alert('Enter a valid Name/Nick');
112 return false;
113 }
114 if ((!form.message.value) ||
115 (form.message.value == Drupal.settings.shoutbox.defaultMsg)) {
116 alert('Enter a valid Message');
117 return false;
118 }
119 // tell server we are using ajax
120 for (var i=0; i < formData.length; i++) {
121 if (formData[i].name == 'ajax') {
122 formData[i].value = 1;
123 }
124 }
125 return true;
126 }
127
128
129
130
131 if (Drupal.jsEnabled) {
132 $(document).ready(function() {
133 Drupal.settings.shoutbox.color = Drupal.settings.shoutbox.shownAmount%2;
134 Drupal.shoutbox.attachForm();
135 Drupal.shoutbox.attachShoutAddForm();
136 if( Drupal.settings.shoutbox.refreshDelay > 0) {
137 Drupal.shoutbox.startTimer(Drupal.settings.shoutbox.refreshDelay);
138 }
139 }
140 );
141
142 };

  ViewVC Help
Powered by ViewVC 1.1.2