Skip to content

Node.js based forum software built for the modern web

feat: #8734, move tinycon to package.json

Barış Soner Uşaklı9c157de05d61
diff --git a/install/package.json b/install/package.json
index d3577a785d..dd91f0d3d6 100644
--- a/install/package.json
+++ b/install/package.json
@@ -126,6 +126,7 @@
"spider-detector": "2.0.0",
"textcomplete": "^0.17.1",
"textcomplete.contenteditable": "^0.1.1",
+ "tinycon": "0.6.8",
"toobusy-js": "^0.5.1",
"uglify-es": "^3.3.9",
"validator": "13.1.17",
diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js
index 5a329104f7..bca396147d 100644
--- a/public/src/modules/notifications.js
+++ b/public/src/modules/notifications.js
@@ -1,7 +1,13 @@
'use strict';
-define('notifications', ['translator', 'components', 'navigator', 'benchpress'], function (translator, components, navigator, Benchpress) {
+define('notifications', [
+ 'translator',
+ 'components',
+ 'navigator',
+ 'benchpress',
+ 'tinycon',
+], function (translator, components, navigator, Benchpress, Tinycon) {
var Notifications = {};
var unreadNotifs = {};
diff --git a/public/vendor/tinycon/tinycon.js b/public/vendor/tinycon/tinycon.js
deleted file mode 100644
index 8c516bc2e4..0000000000
--- a/public/vendor/tinycon/tinycon.js
+++ /dev/null
@@ -1,286 +0,0 @@
-/*!
- * Tinycon - A small library for manipulating the Favicon
- * Tom Moor, http://tommoor.com
- * Copyright (c) 2015 Tom Moor
- * @license MIT Licensed
- */
-
-(function(){
-
- var Tinycon = {};
- var currentFavicon = null;
- var originalFavicon = null;
- var faviconImage = null;
- var canvas = null;
- var options = {};
- // Chrome browsers with nonstandard zoom report fractional devicePixelRatio.
- var r = Math.ceil(window.devicePixelRatio) || 1;
- var size = 16 * r;
- var defaults = {
- width: 7,
- height: 9,
- font: 10 * r + 'px arial',
- color: '#ffffff',
- background: '#F03D25',
- fallback: true,
- crossOrigin: true,
- abbreviate: true
- };
-
- var ua = (function () {
- var agent = navigator.userAgent.toLowerCase();
- // New function has access to 'agent' via closure
- return function (browser) {
- return agent.indexOf(browser) !== -1;
- };
- }());
-
- var browser = {
- ie: ua('trident'),
- chrome: ua('chrome'),
- webkit: ua('chrome') || ua('safari'),
- safari: ua('safari') && !ua('chrome'),
- mozilla: ua('mozilla') && !ua('chrome') && !ua('safari')
- };
-
- // private methods
- var getFaviconTag = function(){
-
- var links = document.getElementsByTagName('link');
-
- for(var i=0, len=links.length; i < len; i++) {
- if ((links[i].getAttribute('rel') || '').match(/\bicon\b/i)) {
- return links[i];
- }
- }
-
- return false;
- };
-
- var removeFaviconTag = function(){
-
- var links = document.getElementsByTagName('link');
-
- for(var i=0, len=links.length; i < len; i++) {
- var exists = (typeof(links[i]) !== 'undefined');
- if (exists && (links[i].getAttribute('rel') || '').match(/\bicon\b/i)) {
- links[i].parentNode.removeChild(links[i]);
- }
- }
- };
-
- var getCurrentFavicon = function(){
-
- if (!originalFavicon || !currentFavicon) {
- var tag = getFaviconTag();
- currentFavicon = tag ? tag.getAttribute('href') : '/favicon.ico';
- if (!originalFavicon) {
- originalFavicon = currentFavicon;
- }
- }
-
- return currentFavicon;
- };
-
- var getCanvas = function (){
-
- if (!canvas) {
- canvas = document.createElement("canvas");
- canvas.width = size;
- canvas.height = size;
- }
-
- return canvas;
- };
-
- var setFaviconTag = function(url){
- if(url){
- removeFaviconTag();
-
- var link = document.createElement('link');
- link.type = 'image/x-icon';
- link.rel = 'icon';
- link.href = url;
- document.getElementsByTagName('head')[0].appendChild(link);
- }
- };
-
- var log = function(message){
- if (window.console) window.console.log(message);
- };
-
- var drawFavicon = function(label, color) {
-
- // fallback to updating the browser title if unsupported
- if (!getCanvas().getContext || browser.ie || browser.safari || options.fallback === 'force') {
- return updateTitle(label);
- }
-
- var context = getCanvas().getContext("2d");
- var color = color || '#000000';
- var src = getCurrentFavicon();
-
- faviconImage = document.createElement('img');
- faviconImage.onload = function() {
-
- // clear canvas
- context.clearRect(0, 0, size, size);
-
- // draw the favicon
- context.drawImage(faviconImage, 0, 0, faviconImage.width, faviconImage.height, 0, 0, size, size);
-
- // draw bubble over the top
- if ((label + '').length > 0) drawBubble(context, label, color);
-
- // refresh tag in page
- refreshFavicon();
- };
-
- // allow cross origin resource requests if the image is not a data:uri
- // as detailed here: https://github.com/mrdoob/three.js/issues/1305
- if (!src.match(/^data/) && options.crossOrigin) {
- faviconImage.crossOrigin = 'anonymous';
- }
-
- faviconImage.src = src;
- };
-
- var updateTitle = function(label) {
-
- if (options.fallback) {
- // Grab the current title that we can prefix with the label
- var originalTitle = document.title;
-
- // Strip out the old label if there is one
- if (originalTitle[0] === '(') {
- originalTitle = originalTitle.slice(originalTitle.indexOf(' '));
- }
-
- if ((label + '').length > 0) {
- document.title = '(' + label + ') ' + originalTitle;
- } else {
- document.title = originalTitle;
- }
- }
- };
-
- var drawBubble = function(context, label, color) {
-
- // automatic abbreviation for long (>2 digits) numbers
- if (typeof label == 'number' && label > 99 && options.abbreviate) {
- label = abbreviateNumber(label);
- }
-
- // bubble needs to be larger for double digits
- var len = (label + '').length-1;
-
- var width = options.width * r + (6 * r * len),
- height = options.height * r;
-
- var top = size - height,
- left = size - width - r,
- bottom = 16 * r,
- right = 16 * r,
- radius = 2 * r;
-
- // webkit seems to render fonts lighter than firefox
- context.font = (browser.webkit ? 'bold ' : '') + options.font;
- context.fillStyle = options.background;
- context.strokeStyle = options.background;
- context.lineWidth = r;
-
- // bubble
- context.beginPath();
- context.moveTo(left + radius, top);
- context.quadraticCurveTo(left, top, left, top + radius);
- context.lineTo(left, bottom - radius);
- context.quadraticCurveTo(left, bottom, left + radius, bottom);
- context.lineTo(right - radius, bottom);
- context.quadraticCurveTo(right, bottom, right, bottom - radius);
- context.lineTo(right, top + radius);
- context.quadraticCurveTo(right, top, right - radius, top);
- context.closePath();
- context.fill();
-
- // bottom shadow
- context.beginPath();
- context.strokeStyle = "rgba(0,0,0,0.3)";
- context.moveTo(left + radius / 2.0, bottom);
- context.lineTo(right - radius / 2.0, bottom);
- context.stroke();
-
- // label
- context.fillStyle = options.color;
- context.textAlign = "right";
- context.textBaseline = "top";
-
- // unfortunately webkit/mozilla are a pixel different in text positioning
- context.fillText(label, r === 2 ? 29 : 15, browser.mozilla ? 7*r : 6*r);
- };
-
- var refreshFavicon = function(){
- // check support
- if (!getCanvas().getContext) return;
-
- setFaviconTag(getCanvas().toDataURL());
- };
-
- var abbreviateNumber = function(label) {
- var metricPrefixes = [
- ['G', 1000000000],
- ['M', 1000000],
- ['k', 1000]
- ];
-
- for(var i = 0; i < metricPrefixes.length; ++i) {
- if (label >= metricPrefixes[i][1]) {
- label = round(label / metricPrefixes[i][1]) + metricPrefixes[i][0];
- break;
- }
- }
-
- return label;
- };
-
- var round = function (value, precision) {
- var number = new Number(value);
- return number.toFixed(precision);
- };
-
- // public methods
- Tinycon.setOptions = function(custom){
- options = {};
-
- // account for deprecated UK English spelling
- if (custom.colour) {
- custom.color = custom.colour;
- }
-
- for(var key in defaults){
- options[key] = custom.hasOwnProperty(key) ? custom[key] : defaults[key];
- }
- return this;
- };
-
- Tinycon.setImage = function(url){
- currentFavicon = url;
- refreshFavicon();
- return this;
- };
-
- Tinycon.setBubble = function(label, color) {
- label = label || '';
- drawFavicon(label, color);
- return this;
- };
-
- Tinycon.reset = function(){
- currentFavicon = originalFavicon;
- setFaviconTag(originalFavicon);
- };
-
- Tinycon.setOptions(defaults);
-
- window.Tinycon = Tinycon;
-
-})();
diff --git a/src/meta/js.js b/src/meta/js.js
index 3652878d7d..c42efcd783 100644
--- a/src/meta/js.js
+++ b/src/meta/js.js
@@ -37,7 +37,6 @@ JS.scripts = {
'public/src/require-config.js',
'public/vendor/bootbox/bootbox.js',
'public/vendor/bootbox/wrapper.js',
- 'public/vendor/tinycon/tinycon.js',
'public/vendor/xregexp/xregexp.js',
'public/vendor/xregexp/unicode/unicode-base.js',
'node_modules/benchpressjs/build/benchpress.js',
@@ -106,6 +105,7 @@ JS.scripts = {
ace: 'node_modules/ace-builds/src-min',
'clipboard.js': 'node_modules/clipboard/dist/clipboard.min.js',
'nprogress.js': 'node_modules/nprogress/nprogress.js',
+ 'tinycon.js': 'node_modules/tinycon/tinycon.js',
},
};