diff options
| author | Scott Ostler <scottbot9000@gmail.com> | 2010-09-05 05:54:44 -0400 |
|---|---|---|
| committer | Scott Ostler <scottbot9000@gmail.com> | 2010-09-05 05:54:44 -0400 |
| commit | 6faebbd3c1e253bd6e5797decfd945a389ddc347 (patch) | |
| tree | a344840bd975ac7fac7aa4d4819e4b96154fbb58 /static/js | |
| parent | 40bc9c45fcc73edb126c5e04321afc5d175f0cd0 (diff) | |
Added Away and Log js modules
Diffstat (limited to 'static/js')
| -rw-r--r-- | static/js/pichat.js | 95 |
1 files changed, 64 insertions, 31 deletions
diff --git a/static/js/pichat.js b/static/js/pichat.js index 36e4087..dfb6148 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -60,6 +60,42 @@ function escapeHtml(txt) { return $("<span>").text(txt).html() } +var Log = { + "Levels": ['info', 'warn', 'error'], + "AjaxSubmitLevels": ['warn', 'error'], + "AjaxSubmitPath": "/logerror", + + "SupplementalInfo": function() { + return { 'user': UserInfo && UserInfo.nick }; + }, + + "ajaxSubmit": function(level, component, msg) { + var info = Log.SupplementalInfo(); + var data = { 'level': level, 'component': component, 'msg': msg }; + $.extend(info, data); + + $.ajax({type: 'POST', + timeout: 5000, + url: Log.AjaxSubmitPath, + data: info + }); + }, + + "initialize": function() { + $.each(Log.Levels, function(i, level) { + Log[level] = function(component, msg) { + if (window.console && window.console[level]) + window.console[level](args); + if (Log.AjaxSubmitLevels.indexOf(level) != -1) + Log.ajaxSubmit(level, args); + }; + }); + } +}; + +Log.initialize(); + + URLRegex = /((\b(http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi; PicRegex = /\.(jpg|jpeg|png|gif|bmp|svg|fid)$/i; @@ -1205,40 +1241,37 @@ function parseDomain(host){ return host.toLowerCase().replace(/^www\./, "") } -// Away notification +var Away = { + "UnseenMsgCounter": 0, + "OrigTitle": "", + "HasFocus": true, + "UpdateFrequency": 3000, -var UnseenMsgCounter = 0; -var OrigTitle = ""; -var HasFocus = true; + "onFocus": function() { + Away.HasFocus = true; + Away.UnseenMsgCounter = 0; + // Courtesy http://stackoverflow.com/questions/2952384/changing-the-window-title-when-focussing-the-window-doesnt-work-in-chrome + window.setTimeout(function () { $('title').text(Away.OrigTitle); }, 100); + }, + "onBlur": function() { + Away.HasFocus = false; + }, -function onFocus() { - HasFocus = true; - UnseenMsgCounter = 0; - // Courtesy http://stackoverflow.com/questions/2952384/changing-the-window-title-when-focussing-the-window-doesnt-work-in-chrome - window.setTimeout(function () { $('title').text(OrigTitle); }, 100); -} - -function onBlur() { - HasFocus = false; -} - -function titleUpdater() { - if (UnseenMsgCounter > 0) { - var plural = UnseenMsgCounter > 1 ? 's' : ''; - $('title').text(UnseenMsgCounter + ' new dump' + plural + '! | ' + OrigTitle); + "updateTitle": function () { + if (Away.UnseenMsgCounter > 0) { + var plural = Away.UnseenMsgCounter > 1 ? 's' : ''; + $('title').text(Away.UnseenMsgCounter + ' new dump' + plural + '! | ' + Away.OrigTitle); + } + setTimeout(Away.updateTitle, Away.UpdateFrequency); + + }, + "startTitleUpdater": function() { + Away.OrigTitle = $('title').text(); + $(window).blur(Away.onBlur); + $(window).focus(Away.onFocus); + setTimeout(Away.updateTitle, Away.UpdateFrequency); } - setTimeout(titleUpdater, 4000); -} - -function startTitleUpdater() { - $(window).blur(onBlur); - $(window).focus(onFocus); - setTimeout(titleUpdater, 2000); -} - -$(function() { - OrigTitle = $('title').text(); -}); +}; var imgZoomThreshhold = [125, 125]; |
