├── LICENSE ├── README.markdown ├── example └── index.html └── jquery.titlealert.js /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 ESN | http://esn.me 2 | Jonatan Heyman | http://heyman.info 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | jquery-titlealert 2 | ================= 3 | 4 | Flashes the page title with a custom message. 5 | 6 | Example usage 7 | ------------- 8 | 9 |
10 | $.titleAlert("Hello World!", {
11 |     requireBlur:true,
12 |     stopOnFocus:true,
13 |     duration:10000,
14 |     interval:500
15 | });
16 | 
17 | 18 | Flash title bar with text "Hello World!", if the window doesn't have focus, for 10 seconds or until window gets focused, with an interval of 500ms 19 | 20 | Parameters and Options 21 | ---------------------- 22 | 23 |
jQuery.titleAlert(message, options)
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 73 | 74 |
messageA string the message that should be flashed in the browser title.
options 33 | JavaScript object containing options 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
namedefaultdescription
interval500The flashing interval in milliseconds.
originalTitleIntervalnullTime in milliseconds that the original title is diplayed for. If null the time is the same as interval.
duration0The total lenght of the flashing before it is automatically stopped. Zero means infinite.
stopOnFocustrueIf true, the flashing will stop when the window gets focus.
stopOnMouseMovefalseIf true, the flashing will stop when the document recieves a mousemove event (i.e. when the user moves the mouse over the document area, regardless of what window is active).
requireBlurfalseExperimental. If true, the call will be ignored unless the window is out of focus. Known issues: Firefox doesn't recognize tab switching as blur, and there are some minor IE problems as well.
71 | 72 |
75 | 76 | 77 | License 78 | ------- 79 | MIT License 80 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Example page for jQuery-titlealert 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /jquery.titlealert.js: -------------------------------------------------------------------------------- 1 | /*!! 2 | * Title Alert 0.7 3 | * 4 | * Copyright (c) 2009 ESN | http://esn.me 5 | * Jonatan Heyman | http://heyman.info 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | */ 17 | 18 | /* 19 | * @name jQuery.titleAlert 20 | * @projectDescription Show alert message in the browser title bar 21 | * @author Jonatan Heyman | http://heyman.info 22 | * @version 0.7.0 23 | * @license MIT License 24 | * 25 | * @id jQuery.titleAlert 26 | * @param {String} text The text that should be flashed in the browser title 27 | * @param {Object} settings Optional set of settings. 28 | * @option {Number} interval The flashing interval in milliseconds (default: 500). 29 | * @option {Number} originalTitleInterval Time in milliseconds that the original title is diplayed for. If null the time is the same as interval (default: null). 30 | * @option {Number} duration The total lenght of the flashing before it is automatically stopped. Zero means infinite (default: 0). 31 | * @option {Boolean} stopOnFocus If true, the flashing will stop when the window gets focus (default: true). 32 | * @option {Boolean} stopOnMouseMove If true, the flashing will stop when the browser window recieves a mousemove event. (default:false). 33 | * @option {Boolean} requireBlur Experimental. If true, the call will be ignored unless the window is out of focus (default: false). 34 | * Known issues: Firefox doesn't recognize tab switching as blur, and there are some minor IE problems as well. 35 | * 36 | * @example $.titleAlert("Hello World!", {requireBlur:true, stopOnFocus:true, duration:10000, interval:500}); 37 | * @desc Flash title bar with text "Hello World!", if the window doesn't have focus, for 10 seconds or until window gets focused, with an interval of 500ms 38 | */ 39 | ;(function($){ 40 | $.titleAlert = function(text, settings) { 41 | // check if it currently flashing something, if so reset it 42 | if ($.titleAlert._running) 43 | $.titleAlert.stop(); 44 | 45 | // override default settings with specified settings 46 | $.titleAlert._settings = settings = $.extend( {}, $.titleAlert.defaults, settings); 47 | 48 | // if it's required that the window doesn't have focus, and it has, just return 49 | if (settings.requireBlur && $.titleAlert.hasFocus) 50 | return; 51 | 52 | // originalTitleInterval defaults to interval if not set 53 | settings.originalTitleInterval = settings.originalTitleInterval || settings.interval; 54 | 55 | $.titleAlert._running = true; 56 | $.titleAlert._initialText = document.title; 57 | document.title = text; 58 | var showingAlertTitle = true; 59 | var switchTitle = function() { 60 | // WTF! Sometimes Internet Explorer 6 calls the interval function an extra time! 61 | if (!$.titleAlert._running) 62 | return; 63 | 64 | showingAlertTitle = !showingAlertTitle; 65 | document.title = (showingAlertTitle ? text : $.titleAlert._initialText); 66 | $.titleAlert._intervalToken = setTimeout(switchTitle, (showingAlertTitle ? settings.interval : settings.originalTitleInterval)); 67 | } 68 | $.titleAlert._intervalToken = setTimeout(switchTitle, settings.interval); 69 | 70 | if (settings.stopOnMouseMove) { 71 | $(document).mousemove(function(event) { 72 | $(this).unbind(event); 73 | $.titleAlert.stop(); 74 | }); 75 | } 76 | 77 | // check if a duration is specified 78 | if (settings.duration > 0) { 79 | $.titleAlert._timeoutToken = setTimeout(function() { 80 | $.titleAlert.stop(); 81 | }, settings.duration); 82 | } 83 | }; 84 | 85 | // default settings 86 | $.titleAlert.defaults = { 87 | interval: 500, 88 | originalTitleInterval: null, 89 | duration:0, 90 | stopOnFocus: true, 91 | requireBlur: false, 92 | stopOnMouseMove: false 93 | }; 94 | 95 | // stop current title flash 96 | $.titleAlert.stop = function() { 97 | if (!$.titleAlert._running) 98 | return; 99 | 100 | clearTimeout($.titleAlert._intervalToken); 101 | clearTimeout($.titleAlert._timeoutToken); 102 | document.title = $.titleAlert._initialText; 103 | 104 | $.titleAlert._timeoutToken = null; 105 | $.titleAlert._intervalToken = null; 106 | $.titleAlert._initialText = null; 107 | $.titleAlert._running = false; 108 | $.titleAlert._settings = null; 109 | } 110 | 111 | $.titleAlert.hasFocus = true; 112 | $.titleAlert._running = false; 113 | $.titleAlert._intervalToken = null; 114 | $.titleAlert._timeoutToken = null; 115 | $.titleAlert._initialText = null; 116 | $.titleAlert._settings = null; 117 | 118 | 119 | $.titleAlert._focus = function () { 120 | $.titleAlert.hasFocus = true; 121 | 122 | if ($.titleAlert._running && $.titleAlert._settings.stopOnFocus) { 123 | var initialText = $.titleAlert._initialText; 124 | $.titleAlert.stop(); 125 | 126 | // ugly hack because of a bug in Chrome which causes a change of document.title immediately after tab switch 127 | // to have no effect on the browser title 128 | setTimeout(function() { 129 | if ($.titleAlert._running) 130 | return; 131 | document.title = "."; 132 | document.title = initialText; 133 | }, 1000); 134 | } 135 | }; 136 | $.titleAlert._blur = function () { 137 | $.titleAlert.hasFocus = false; 138 | }; 139 | 140 | // bind focus and blur event handlers 141 | $(window).bind("focus", $.titleAlert._focus); 142 | $(window).bind("blur", $.titleAlert._blur); 143 | })(jQuery); 144 | --------------------------------------------------------------------------------