Glouton

Glouton : animal à fourrure ressemblant à un ours et muni de griffes en adamantium.

Sinon je viens de (re)découvrir qu’on avait une API REST prête à l’emploi dans Dotclear et que je pense que je vais m’amuser un peu à coder un petit plugin qui s’appuiera dessus histoire de mettre en œuvre la fonction de notification que j’ai développée et testée hier :

Le code PHP :

public static function displayBrowserNotification($message)
{
	echo '<script type="text/javascript">'.
		'notifyBrowser("'.html::escapeJS(str_replace("\n",'. ',$message)).'");'.
		'</script>';
}

Et le code Javascript qui va avec :

/* Browser notification
   (adpated from https://developer.mozilla.org/fr/docs/Web/API/Notification)
-------------------------------------------------------*/
function notifyBrowser(msg) {
	var notify_options = {
		body: msg,
		icon: "images/favicon.ico"
	};

	if ("Notification" in window) {
		// Check if user has already granted notification for this session
		if (Notification.permission === "granted") {
			// Notifications granted, push it
			var notification = new Notification("Dotclear",notify_options);
		}

		// Else, check if notification has not already been denied
		else if (Notification.permission !== 'denied') {
			// Ask permission for notification for this session
			Notification.requestPermission(function (permission) {

				// Store user's answer
				if(!('permission' in Notification)) {
					Notification.permission = permission;
				}

				// If notification granted, push it
				if (permission === "granted") {
					var notification = new Notification("Dotclear",notify_options);
				}
			});
		}
	}
}

Reste à emballer tout ça et trouver sur quel événement déclencher l’ensemble. Va falloir que je me documente un peu, je n’ai jamais (ou très rarement) exploré ce côté de la force :-)

Ajouter un commentaire

Les champs suivis d'un * sont obligatoires

Les commentaires peuvent être formatés en utilisant la syntaxe Markdown Extra.

Ajouter un rétrolien

URL de rétrolien : https://open-time.net/trackback/12392

Haut de page