From 3b93bab16dfd3a66abd82b7da42fc7e7b820db40 Mon Sep 17 00:00:00 2001 From: yosef langer Date: Sun, 15 Mar 2020 19:56:18 +0200 Subject: [PATCH] just added the minimum to push to NPM --- jquery.titlealert.js | 144 +-------------------------------------- jquery.titlealert.min.js | 143 ++++++++++++++++++++++++++++++++++++++ package.json | 22 ++++++ 3 files changed, 166 insertions(+), 143 deletions(-) create mode 100644 jquery.titlealert.min.js create mode 100644 package.json diff --git a/jquery.titlealert.js b/jquery.titlealert.js index 69276f6..8cc0bad 100644 --- a/jquery.titlealert.js +++ b/jquery.titlealert.js @@ -1,143 +1 @@ -/*!! - * Title Alert 0.7 - * - * Copyright (c) 2009 ESN | http://esn.me - * Jonatan Heyman | http://heyman.info - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -/* - * @name jQuery.titleAlert - * @projectDescription Show alert message in the browser title bar - * @author Jonatan Heyman | http://heyman.info - * @version 0.7.0 - * @license MIT License - * - * @id jQuery.titleAlert - * @param {String} text The text that should be flashed in the browser title - * @param {Object} settings Optional set of settings. - * @option {Number} interval The flashing interval in milliseconds (default: 500). - * @option {Number} originalTitleInterval Time in milliseconds that the original title is diplayed for. If null the time is the same as interval (default: null). - * @option {Number} duration The total lenght of the flashing before it is automatically stopped. Zero means infinite (default: 0). - * @option {Boolean} stopOnFocus If true, the flashing will stop when the window gets focus (default: true). - * @option {Boolean} stopOnMouseMove If true, the flashing will stop when the browser window recieves a mousemove event. (default:false). - * @option {Boolean} requireBlur Experimental. If true, the call will be ignored unless the window is out of focus (default: false). - * Known issues: Firefox doesn't recognize tab switching as blur, and there are some minor IE problems as well. - * - * @example $.titleAlert("Hello World!", {requireBlur:true, stopOnFocus:true, duration:10000, interval:500}); - * @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 - */ -;(function($){ - $.titleAlert = function(text, settings) { - // check if it currently flashing something, if so reset it - if ($.titleAlert._running) - $.titleAlert.stop(); - - // override default settings with specified settings - $.titleAlert._settings = settings = $.extend( {}, $.titleAlert.defaults, settings); - - // if it's required that the window doesn't have focus, and it has, just return - if (settings.requireBlur && $.titleAlert.hasFocus) - return; - - // originalTitleInterval defaults to interval if not set - settings.originalTitleInterval = settings.originalTitleInterval || settings.interval; - - $.titleAlert._running = true; - $.titleAlert._initialText = document.title; - document.title = text; - var showingAlertTitle = true; - var switchTitle = function() { - // WTF! Sometimes Internet Explorer 6 calls the interval function an extra time! - if (!$.titleAlert._running) - return; - - showingAlertTitle = !showingAlertTitle; - document.title = (showingAlertTitle ? text : $.titleAlert._initialText); - $.titleAlert._intervalToken = setTimeout(switchTitle, (showingAlertTitle ? settings.interval : settings.originalTitleInterval)); - } - $.titleAlert._intervalToken = setTimeout(switchTitle, settings.interval); - - if (settings.stopOnMouseMove) { - $(document).mousemove(function(event) { - $(this).unbind(event); - $.titleAlert.stop(); - }); - } - - // check if a duration is specified - if (settings.duration > 0) { - $.titleAlert._timeoutToken = setTimeout(function() { - $.titleAlert.stop(); - }, settings.duration); - } - }; - - // default settings - $.titleAlert.defaults = { - interval: 500, - originalTitleInterval: null, - duration:0, - stopOnFocus: true, - requireBlur: false, - stopOnMouseMove: false - }; - - // stop current title flash - $.titleAlert.stop = function() { - if (!$.titleAlert._running) - return; - - clearTimeout($.titleAlert._intervalToken); - clearTimeout($.titleAlert._timeoutToken); - document.title = $.titleAlert._initialText; - - $.titleAlert._timeoutToken = null; - $.titleAlert._intervalToken = null; - $.titleAlert._initialText = null; - $.titleAlert._running = false; - $.titleAlert._settings = null; - } - - $.titleAlert.hasFocus = true; - $.titleAlert._running = false; - $.titleAlert._intervalToken = null; - $.titleAlert._timeoutToken = null; - $.titleAlert._initialText = null; - $.titleAlert._settings = null; - - - $.titleAlert._focus = function () { - $.titleAlert.hasFocus = true; - - if ($.titleAlert._running && $.titleAlert._settings.stopOnFocus) { - var initialText = $.titleAlert._initialText; - $.titleAlert.stop(); - - // ugly hack because of a bug in Chrome which causes a change of document.title immediately after tab switch - // to have no effect on the browser title - setTimeout(function() { - if ($.titleAlert._running) - return; - document.title = "."; - document.title = initialText; - }, 1000); - } - }; - $.titleAlert._blur = function () { - $.titleAlert.hasFocus = false; - }; - - // bind focus and blur event handlers - $(window).bind("focus", $.titleAlert._focus); - $(window).bind("blur", $.titleAlert._blur); -})(jQuery); +!function(t){t.titleAlert=function(e,l){if(t.titleAlert._running&&t.titleAlert.stop(),t.titleAlert._settings=l=t.extend({},t.titleAlert.defaults,l),!l.requireBlur||!t.titleAlert.hasFocus){l.originalTitleInterval=l.originalTitleInterval||l.interval,t.titleAlert._running=!0,t.titleAlert._initialText=document.title,document.title=e;var i=!0,n=function(){t.titleAlert._running&&(i=!i,document.title=i?e:t.titleAlert._initialText,t.titleAlert._intervalToken=setTimeout(n,i?l.interval:l.originalTitleInterval))};t.titleAlert._intervalToken=setTimeout(n,l.interval),l.stopOnMouseMove&&t(document).mousemove(function(e){t(this).unbind(e),t.titleAlert.stop()}),l.duration>0&&(t.titleAlert._timeoutToken=setTimeout(function(){t.titleAlert.stop()},l.duration))}},t.titleAlert.defaults={interval:500,originalTitleInterval:null,duration:0,stopOnFocus:!0,requireBlur:!1,stopOnMouseMove:!1},t.titleAlert.stop=function(){t.titleAlert._running&&(clearTimeout(t.titleAlert._intervalToken),clearTimeout(t.titleAlert._timeoutToken),document.title=t.titleAlert._initialText,t.titleAlert._timeoutToken=null,t.titleAlert._intervalToken=null,t.titleAlert._initialText=null,t.titleAlert._running=!1,t.titleAlert._settings=null)},t.titleAlert.hasFocus=!0,t.titleAlert._running=!1,t.titleAlert._intervalToken=null,t.titleAlert._timeoutToken=null,t.titleAlert._initialText=null,t.titleAlert._settings=null,t.titleAlert._focus=function(){if(t.titleAlert.hasFocus=!0,t.titleAlert._running&&t.titleAlert._settings.stopOnFocus){var e=t.titleAlert._initialText;t.titleAlert.stop(),setTimeout(function(){t.titleAlert._running||(document.title=".",document.title=e)},1e3)}},t.titleAlert._blur=function(){t.titleAlert.hasFocus=!1},t(window).bind("focus",t.titleAlert._focus),t(window).bind("blur",t.titleAlert._blur)}(jQuery); \ No newline at end of file diff --git a/jquery.titlealert.min.js b/jquery.titlealert.min.js new file mode 100644 index 0000000..69276f6 --- /dev/null +++ b/jquery.titlealert.min.js @@ -0,0 +1,143 @@ +/*!! + * Title Alert 0.7 + * + * Copyright (c) 2009 ESN | http://esn.me + * Jonatan Heyman | http://heyman.info + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +/* + * @name jQuery.titleAlert + * @projectDescription Show alert message in the browser title bar + * @author Jonatan Heyman | http://heyman.info + * @version 0.7.0 + * @license MIT License + * + * @id jQuery.titleAlert + * @param {String} text The text that should be flashed in the browser title + * @param {Object} settings Optional set of settings. + * @option {Number} interval The flashing interval in milliseconds (default: 500). + * @option {Number} originalTitleInterval Time in milliseconds that the original title is diplayed for. If null the time is the same as interval (default: null). + * @option {Number} duration The total lenght of the flashing before it is automatically stopped. Zero means infinite (default: 0). + * @option {Boolean} stopOnFocus If true, the flashing will stop when the window gets focus (default: true). + * @option {Boolean} stopOnMouseMove If true, the flashing will stop when the browser window recieves a mousemove event. (default:false). + * @option {Boolean} requireBlur Experimental. If true, the call will be ignored unless the window is out of focus (default: false). + * Known issues: Firefox doesn't recognize tab switching as blur, and there are some minor IE problems as well. + * + * @example $.titleAlert("Hello World!", {requireBlur:true, stopOnFocus:true, duration:10000, interval:500}); + * @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 + */ +;(function($){ + $.titleAlert = function(text, settings) { + // check if it currently flashing something, if so reset it + if ($.titleAlert._running) + $.titleAlert.stop(); + + // override default settings with specified settings + $.titleAlert._settings = settings = $.extend( {}, $.titleAlert.defaults, settings); + + // if it's required that the window doesn't have focus, and it has, just return + if (settings.requireBlur && $.titleAlert.hasFocus) + return; + + // originalTitleInterval defaults to interval if not set + settings.originalTitleInterval = settings.originalTitleInterval || settings.interval; + + $.titleAlert._running = true; + $.titleAlert._initialText = document.title; + document.title = text; + var showingAlertTitle = true; + var switchTitle = function() { + // WTF! Sometimes Internet Explorer 6 calls the interval function an extra time! + if (!$.titleAlert._running) + return; + + showingAlertTitle = !showingAlertTitle; + document.title = (showingAlertTitle ? text : $.titleAlert._initialText); + $.titleAlert._intervalToken = setTimeout(switchTitle, (showingAlertTitle ? settings.interval : settings.originalTitleInterval)); + } + $.titleAlert._intervalToken = setTimeout(switchTitle, settings.interval); + + if (settings.stopOnMouseMove) { + $(document).mousemove(function(event) { + $(this).unbind(event); + $.titleAlert.stop(); + }); + } + + // check if a duration is specified + if (settings.duration > 0) { + $.titleAlert._timeoutToken = setTimeout(function() { + $.titleAlert.stop(); + }, settings.duration); + } + }; + + // default settings + $.titleAlert.defaults = { + interval: 500, + originalTitleInterval: null, + duration:0, + stopOnFocus: true, + requireBlur: false, + stopOnMouseMove: false + }; + + // stop current title flash + $.titleAlert.stop = function() { + if (!$.titleAlert._running) + return; + + clearTimeout($.titleAlert._intervalToken); + clearTimeout($.titleAlert._timeoutToken); + document.title = $.titleAlert._initialText; + + $.titleAlert._timeoutToken = null; + $.titleAlert._intervalToken = null; + $.titleAlert._initialText = null; + $.titleAlert._running = false; + $.titleAlert._settings = null; + } + + $.titleAlert.hasFocus = true; + $.titleAlert._running = false; + $.titleAlert._intervalToken = null; + $.titleAlert._timeoutToken = null; + $.titleAlert._initialText = null; + $.titleAlert._settings = null; + + + $.titleAlert._focus = function () { + $.titleAlert.hasFocus = true; + + if ($.titleAlert._running && $.titleAlert._settings.stopOnFocus) { + var initialText = $.titleAlert._initialText; + $.titleAlert.stop(); + + // ugly hack because of a bug in Chrome which causes a change of document.title immediately after tab switch + // to have no effect on the browser title + setTimeout(function() { + if ($.titleAlert._running) + return; + document.title = "."; + document.title = initialText; + }, 1000); + } + }; + $.titleAlert._blur = function () { + $.titleAlert.hasFocus = false; + }; + + // bind focus and blur event handlers + $(window).bind("focus", $.titleAlert._focus); + $(window).bind("blur", $.titleAlert._blur); +})(jQuery); diff --git a/package.json b/package.json new file mode 100644 index 0000000..be3781a --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "jquery-titlealert", + "version": "1.0.0", + "description": "Flashes the page title with a custom message.", + "main": "jquery.titlealert.js", + "directories": { + "example": "example" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/heyman/jquery-titlealert.git" + }, + "author": "Jonatan Heyman", + "license": "MIT", + "bugs": { + "url": "https://github.com/heyman/jquery-titlealert/issues" + }, + "homepage": "https://github.com/heyman/jquery-titlealert#readme" +}