Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[feature] dom: add html5 notification

  • Loading branch information...
commit 3aae2c004e6737b6600e546cb411d49d01a8872f 1 parent 986a59d
Jessica Castejon authored
View
16 opabsl/jsbsl/bslDom.js
@@ -896,3 +896,19 @@ function bsldom_do_slide_out(dom, maybe_duration, maybe_easing, maybe_cb)
}
(new $(window)).bind('beforeunload', f);
}
+
+##register notification: string,string,string -> void
+##args(img_url,title,body)
+{
+ if(window.webkitNotifications){
+ function RequestPermission (callback) { window.webkitNotifications.requestPermission(callback); }
+ function showNotification(){
+ if (window.webkitNotifications.checkPermission() > 0) {
+ RequestPermission(showNotification);
+ } else {
+ window.webkitNotifications.createNotification(img_url,title,body).show();
+ }
+ }
+ showNotification()
+ };
+}
View
8 opabsl/jsbsl/bslDomSupport.js
@@ -25,3 +25,11 @@
{
return document.createElement('input').placeholder !== undefined
}
+
+##register support_notification: -> bool
+##args()
+{
+ if(window.webkitNotifications)
+ return true;
+ else return false;
+}
View
26 stdlib/core/xhtml/dom.opa
@@ -1968,12 +1968,36 @@ Dom = {{
do store_insertion_handlers(dom, ins)
wrap_as_dom(dom)
-
+ /**
+ * Check functionality supported by the client's browser.
+ */
Support = {{
placeholder() : bool =
%% BslDomSupport.support_placeholder %%()
+ notification():bool =
+ %% BslDomSupport.support_notification %%()
}}
+
+
+ /**
+ * Allow to use Html5 notification system.
+ */
+ Notification = {{
+ /**
+ *Displays a notification on the clients screen
+ *
+ *@param img Url of the notification icon, put empty string for no icon
+ *@param title Title of the notification
+ *@param body Text of the notification
+ */
+ show(img : string, title : string, body : string):void =(
+ if Support.notification()
+ then %% BslDom.notification %%(img,title,body)
+ else Log.warning("Notification","Your browser doesn't support Html5 notification")
+ )
+ }}
+
}}
Please sign in to comment.
Something went wrong with that request. Please try again.