Current New Badge Alert Script (Beta 1)

Tags
alert, alerting system, badging system, bootstrap, current, forum development, javascript, jquery, php, scrip, script, web programming

 
Thread Tools Search this Thread
# 1  
Old 1 Week Ago
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;
}


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

More UNIX and Linux Forum Topics You Might Find Helpful
Badging System: UNIX.COM Bug Hunter Badge (New) Neo What is on Your Mind? 0 2 Days Ago 08:29 AM
Color a Badge Based on the Weeks the Member is Active in the Latest Sequence Neo Web Programming 6 3 Days Ago 09:29 AM
Current Array of Badges (Beta 1) Neo What is on Your Mind? 4 1 Week Ago 01:01 AM
Ravinder Singh Just Earned His Green Web Dev Ops Badge Neo What is on Your Mind? 6 2 Weeks Ago 02:12 PM
Two Forum Discussions with Over 1 Million Views and a Special Badge Award to vgersh99 Neo What is on Your Mind? 7 2 Weeks Ago 12:00 PM
'Hats Off' badge of honour to Neo... wisecracker What is on Your Mind? 1 2 Weeks Ago 09:10 AM
Update to Posts - Member Info Icon and Badge Neo What is on Your Mind? 22 07-24-2018 12:23 AM
Finish current script and execute next script R0H0N Shell Programming and Scripting 1 02-13-2015 11:57 AM
Shell script to capture Current day ORA errors from Alert Log Veera_V Shell Programming and Scripting 1 09-02-2014 02:32 PM
Get current and parent script name ysrini Shell Programming and Scripting 6 08-10-2010 09:30 AM
shell script not getting current error messages with time from alert.log a1_win Shell Programming and Scripting 2 10-22-2008 01:42 PM
Trigger Shell Script from Current Script mmignot Shell Programming and Scripting 1 11-06-2006 02:13 PM