Current New Badge Alert Script (Beta 1)


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Current New Badge Alert Script (Beta 1)

Here is the JS I wrote and am now testing live for alerting a member when they have received a new badge (seems to be working OK so far, still testing live):

Code:
var badgeChange = readCookie("badgestatechange");
$(function() {
  if (badgeChange == "1") {
    if (vbuserId > 0) {
      var alertText = "";
      var badgeAlert = "";
      var alertMsg = "";
      var defaultMsg =
        '<a href="#" class="close">&times;</a>' +
        '<span><strong>New Badge!</strong> Click <a href="/member_modal.php?u=' +
        vbuserId +
        '">Here</a> to See Your New Badge(s)</span> ';
      if (localStorage.getItem("badgeCount") != null) {
        var badgeCount = localStorage.getItem("badgeCount");
      }
      if (localStorage.getItem("alertMsg") != null) {
        alertMsg = localStorage.getItem("alertMsg");
        alertText =
          '<a href="#" class="close">&times;</a>' +
          '<span><strong>New Badge!</strong> Click <a href="/member_modal.php?u=' +
          vbuserId +
          '"> Here</a > to See Your ' +
          badgeCount +
          " New " +
          alertMsg +
          " Badge(s)</span > ";
      }
      if (alertText.length > 10) {
        badgeAlert = alertText;
      } else {
        badgeAlert = defaultMsg;
      }
      $("#newBadge").html(badgeAlert);
    }
    $("#newBadge").show();
  }
  $(".close").click(function() {
    $("#newBadge").alert("close");
    document.cookie = "badgestatechange=0";
    if (localStorage.getItem("badgeCount") != null) {
      localStorage.removeItem("badgeCount");
    }
    if (localStorage.getItem("alertMsg") != null) {
      localStorage.removeItem("alertMsg");
    }
  });
});
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(";");
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == " ") c = c.substring(1, c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  }
  return null;
}

Based, partially, on this HTML code which sets the vars:

Code:
<if condition="$alert_vars_js">
$alert_vars_js
</if>

Created by this PHP, partially:

Code:
<?php

 // code omitted for this post ...

if ($hashmatch == false) {
  
            $alert_vars_js = create_badge_var_js($countDiff, $diffy);
            // code omitted for this post ...
}

 // code omitted for this post ...


function create_badge_var_js($diffCount, $diffy, $_DEBUG = true, $_LOCAL = true)
{
    if ($_LOCAL) {
        $badge_alert_js = "<SCRIPT> localStorage.setItem('badgeCount','" . $diffCount . "'); localStorage.setItem('alertMsg','" . $diffy . "'); </SCRIPT>";
    } else {
        $badge_alert_js = "<SCRIPT> var badgeCount = " . $diffCount . "; var alertMsg = '" . $diffy . "'; </SCRIPT>";
    }
    if ($_DEBUG) {
        global $vbulletin;
        error_log(date(DATE_RFC822) . " User " . $vbulletin->userinfo['username'] .
            ' Diff Count: ' . $diffCount .
            ' Diffy String: ' . $badge_alert_js .
            "\n", 3, '/var/log/apache2/debug/neo_global_js_diffy.log');
    }
    return $badge_alert_js;
}

Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Current Array of Badges (Beta 1)
Neo
Here is the current array of the short description of badges for the new prototype badging system (Beta 1) with 42 icons allocated (prototype logic written) and 6 reserved (for future use); <?php $badges_desc = array( "fauser" => "Total Post Count", "faaward" => "First Post", ...... What is on Your Mind?
6
What is on Your Mind?
Shell script to capture Current day ORA errors from Alert Log
Veera_V
Please provide Shell script to capture ORA errors from Alert Log for a given date or Current date. -Veera... Shell Programming and Scripting
1
Shell Programming and Scripting
shell script not getting current error messages with time from alert.log
a1_win
Hi All, I need to get current error messages with time from alert.log.Below is my shell script but it's not working to meet this objective. could anyone pls share on the above issue for resolution: #################################################################### ## ckalertlog.sh ##...... Shell Programming and Scripting
2
Shell Programming and Scripting
Linux and UNIX

Linux is a family of open source Unix-like operating systems based on the Linux kernel. The Linux kernel is an operating system kernel first released by Linus Torvalds on 17 September 1991. Linux distributions include the Linux kernel, system software and libraries. Popular free open source Linux distributions include Debian, Fedora, and Ubuntu. Commercial Linux distributions include Red Hat Enterprise Linux and SUSE Linux Enterprise Server. Linux may be freely modified and redistributed. Anyone on the planet may create a Linux distribution for any purpose.
Unix (trademarked as the UNIX certification mark) is a very mature family of multitasking, multiuser computer operating systems that evolved from the original AT&T Unix. Unix development starting in the 1970s by legendary Bell Labs programmers Ken Thompson, Dennis Ritchie, and others. Unix was first targeted for the Bell System and AT&T licensed Unix to outside parties. In the 1970s time period, this lead to a variety of for-profit as well as not-for-profit Unix variants.
In the early days, this included the University of California, Berkeley (BSD), Microsoft (Xenix), IBM (AIX), and Sun Microsystems (Solaris). In the early 1990s, AT&T sold their Unix rights to Novell. In 1995 Novell sold their Unix business to the Santa Cruz Operation (SCO). The UNIX trademark was passed to The Open Group, a "neutral" industry consortium. The Open Group promoted the use of the UNIX trademark for certified operating systems that comply with the Single UNIX Specification (SUS). In 2014 Apple's macOS became the Unix version with the largest global install base and macOS remains the largest Unix-user base today.
Please enjoy and help our forum community by "showing your work" and posting your code, even when your code is not working as expected. To help others help you, please wrap your code blocks, sample input, sample output, error messages, and other data in CODE tags and wrap your short commands and short data objects in ICODE tags. We were all beginners in the beginning. If you have any questions about how to register or how to post, please contact us in Live Chat. Thank you and enjoy this "forever free" technical support community for UNIX, Linux and computer information technology in general.