Shoutbox Javascript

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Shoutbox Javascript

    Hallo,

    was muß ich ändern, wenn eine userID null ist kein : angeben wird nach dem Username?

    Gruß camiyo

    Quellcode

    1. /**
    2. * @author Sebastian Oettl
    3. * @copyright 2009 WCF Solutions <http://www.wcfsolutions.com/index.php>
    4. * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
    5. */
    6. var Shoutbox = Class.create({
    7. /**
    8. * Inits Shoutbox.
    9. */
    10. initialize: function(entries, lastUpdateTime) {
    11. this.entries = entries;
    12. this.lastUpdateTime = lastUpdateTime;
    13. this.options = Object.extend({
    14. langDeleteEntry: '',
    15. langDeleteEntrySure: '',
    16. imgDeleteEntrySrc: '',
    17. entryReloadInterval: 0,
    18. entrySortOrder: 'ASC'
    19. }, arguments[2] || { });
    20. // set entries
    21. this.setEntries(this.entries);
    22. // start entry update
    23. this.startEntryUpdate();
    24. },
    25. /**
    26. * Starts the entry update.
    27. */
    28. startEntryUpdate: function() {
    29. if (this.options.entryReloadInterval != 0) {
    30. this.executer = new PeriodicalExecuter(this.updateEntries.bind(this), this.options.entryReloadInterval);
    31. }
    32. },
    33. /**
    34. * Stops the entry update.
    35. */
    36. stopEntryUpdate: function() {
    37. if (this.options.entryReloadInterval != 0) {
    38. this.executer.stop();
    39. }
    40. },
    41. /**
    42. * Inserts a smiley.
    43. */
    44. insertSmiley: function(code) {
    45. var shoutboxMessage = $('shoutboxMessage');
    46. shoutboxMessage.value = shoutboxMessage.value+' '+code+' ';
    47. shoutboxMessage.focus();
    48. },
    49. /**
    50. * Adds a new entry.
    51. */
    52. addEntry: function() {
    53. // stop update
    54. this.stopEntryUpdate();
    55. // get message
    56. var message = $('shoutboxMessage').value;
    57. // reset message
    58. $('shoutboxMessage').value = '';
    59. $('shoutboxMessage').focus();
    60. // get username
    61. var username = '';
    62. if ($('shoutboxUsername')) username = $('shoutboxUsername').value;
    63. // add entry
    64. new Ajax.Request('index.php?page=ShoutboxAction&action=add'+SID_ARG_2ND, {
    65. method: 'post',
    66. parameters: {
    67. message: message,
    68. username: username
    69. },
    70. onSuccess: function() {
    71. // update entries
    72. this.updateEntries();
    73. // restart entry update
    74. this.startEntryUpdate();
    75. }.bind(this)
    76. });
    77. },
    78. /**
    79. * Deletes an entry.
    80. */
    81. deleteEntry: function(id) {
    82. new Ajax.Request('index.php?page=ShoutboxAction&action=delete'+SID_ARG_2ND, {
    83. method: 'post',
    84. parameters: {
    85. entryID: id
    86. },
    87. onSuccess: function() {
    88. // unset entry
    89. this.entries.unset(id);
    90. // set entries
    91. this.setEntries(this.entries);
    92. }.bind(this)
    93. });
    94. },
    95. /**
    96. * Updates the entries.
    97. */
    98. updateEntries: function() {
    99. new Ajax.Request('index.php?page=ShoutboxAction&action=getEntries'+SID_ARG_2ND, {
    100. method: 'post',
    101. parameters: {
    102. startTime: this.lastUpdateTime
    103. },
    104. onSuccess: function(response) {
    105. // get entries
    106. var entries = response.responseXML.getElementsByTagName('entries');
    107. if (entries.length > 0) {
    108. for (var i = 0; i < entries[0].childNodes.length; i++) {
    109. this.entries.set(entries[0].childNodes[i].childNodes[0].childNodes[0].nodeValue, {
    110. userID: entries[0].childNodes[i].childNodes[1].childNodes[0].nodeValue,
    111. username: entries[0].childNodes[i].childNodes[2].childNodes[0].nodeValue,
    112. time: entries[0].childNodes[i].childNodes[4].childNodes[0].nodeValue,
    113. message: entries[0].childNodes[i].childNodes[5].childNodes[0].nodeValue,
    114. canDelete: entries[0].childNodes[i].childNodes[6].childNodes[0].nodeValue
    115. });
    116. // set last update time
    117. if (i == entries[0].childNodes.length - 1) {
    118. this.lastUpdateTime = entries[0].childNodes[i].childNodes[3].childNodes[0].nodeValue;
    119. }
    120. }
    121. this.setEntries(this.entries);
    122. }
    123. }.bind(this)
    124. });
    125. },
    126. /**
    127. * Sets the given entries in the shoutbox.
    128. */
    129. setEntries: function(entries) {
    130. var shoutboxMessageDiv = $('shoutboxContent');
    131. if (shoutboxMessageDiv) {
    132. // update shoutbox content
    133. var newEntryString = '';
    134. var idArray = entries.keys();
    135. if (this.options.entrySortOrder == 'DESC') {
    136. idArray.reverse();
    137. }
    138. for (var i = 0; i < idArray.length; i++) {
    139. var id = idArray[i];
    140. var entry = this.entries.get(id);
    141. // update entry string
    142. newEntryString += '<p id="shoutboxEntry'+id+'"><span class="light">['+entry.time+']</span>'+(entry.canDelete != 0 ? ' <a href="javascript:shoutbox.deleteEntry('+id+')" onclick="return confirm(\''+this.options.langDeleteEntrySure+'\')" title="'+this.options.langDeleteEntry+'"><img src="'+this.options.imgDeleteEntrySrc+'" alt="" /></a>' : '')+' '+(entry.userID != 0 ? '<a href="'+'index.php?page=User&userID='+entry.userID+SID_ARG_2ND+'">'+entry.username+'</a>' : entry.username)+': '+entry.message+'</p>';
    143. }
    144. shoutboxMessageDiv.update(newEntryString);
    145. // focus last entry
    146. if (this.options.entrySortOrder == 'ASC') {
    147. shoutboxMessageDiv.scrollTop = shoutboxMessageDiv.scrollHeight - shoutboxMessageDiv.offsetHeight + 100;
    148. }
    149. }
    150. }
    151. });
    Alles anzeigen
  • Ändere Zeile 159 deines Codes in folgendes:

    Quellcode

    1. newEntryString += '<p id="shoutboxEntry'+id+'"><span class="light">['+entry.time+']</span>'+(entry.canDelete != 0 ? ' <a href="javascript:shoutbox.deleteEntry('+id+')" onclick="return confirm(\''+this.options.langDeleteEntrySure+'\')" title="'+this.options.langDeleteEntry+'"><img src="'+this.options.imgDeleteEntrySrc+'" alt="" /></a>' : '')+' '+(entry.userID != 0 ? '<a href="'+'index.php?page=User&userID='+entry.userID+SID_ARG_2ND+'">'+entry.username+':</a>' : entry.username)+' '+entry.message+'</p>';
    Open Source --> Programmieren aus Leidenschaft :!:

    Ich stehe weder für privaten Support per PM noch über einen IM zur Verfügung. Danke.