Permalink
Browse files

Initial commit. Skeleton working with desktop notifications.

  • Loading branch information...
sethmcl committed May 28, 2012
1 parent 449b176 commit 6fd2137aa656451ed1e09568d6abfd03a852842d
View
@@ -0,0 +1,4 @@
+node_modules/
+*.swp
+*.swo
+.DS_Store
View
@@ -0,0 +1,87 @@
+body {
+ margin: 40px;
+ background: #333;
+ font-family: Georgia, Serif;
+ font-size: 44px;
+}
+
+.logo {
+ background: url(/img/icon128-min.png) no-repeat;
+ width: 128px;
+ height: 128px;
+ float: left;
+}
+
+.content {
+ float: left;
+ background: #fff;
+ padding: 0 30px 30px 30px;
+ position: relative;
+ overflow: hidden;
+}
+
+h1 {
+ font-size: 100%;
+ height: 128px;
+ padding-top: 0px;
+ text-shadow: 1px 1px 1px rgba(0, 0, 0, .3);
+ position: relative;
+}
+
+h1 ul {
+ list-style-type: none;
+ padding: 0;
+ bottom: 0;
+ position: absolute;
+}
+
+h1 ul li:first-child {
+ opacity: .4;
+ font-size: 50%;
+}
+
+form {
+ font-size: 60%;
+}
+
+input[type=text] {
+ border: 1px solid #999;
+ height: 25px;
+ padding-left: 5px;
+ font-size: 70%;
+}
+
+input[type=submit] {
+ height: 25px;
+ font-size: 70%;
+ color: #555;
+ padding: 0 15px;
+}
+
+label {
+ color: green;
+}
+
+.notification {
+ position: absolute;
+ top: -20%;
+ left: 0;
+ width: 100%;
+ color: #fff;
+ font-size: 35%;
+ padding: 10px 20px;
+ box-shadow: 0px 1px 3px rgba(0, 0, 0, .4);
+
+ background: #b4e391;
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b4e391), color-stop(50%,#61c419), color-stop(100%,#b4e391));
+ background: -webkit-linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);
+ background: linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);
+
+ -webkit-transition-property: top;
+ -webkit-transition-duration: 200ms;
+ -webkit-transition-timing-function: ease-out;
+}
+
+.notification.active {
+ top: 0%;
+}
View
@@ -0,0 +1,7 @@
+#say-my-name-widget .placeholder {
+ display: inline-block;
+ width: 16px;
+ height: 16px;
+ background: #fff;
+ border-radius: 3px;
+}
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,24 @@
+// listen for requests from content scripts
+chrome.extension.onRequest.addListener( function(request, sender, sendResponse) {
+ if( request.method === 'getOptions' ) {
+ sendResponse( loadOptions() );
+ } else {
+ sendResponse( {} );
+ }
+});
+
+/**
+ * Load options from localStorage
+ * @return {Object} extension options
+ */
+function loadOptions() {
+ var options = {};
+
+ try {
+ options = JSON.parse(localStorage.options);
+ } catch(e) {
+ // unable to load options. too bad, so sad.
+ }
+
+ return options;
+}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,32 @@
+$(document).ready(init);
+var socket, host, port, $events;
+
+function init() {
+ host = 'http://localhost:2012';
+ socket = io.connect(host);
+
+ socket.on('connection', onServerConnected);
+ socket.on('disconnect', onServerDisconnected);
+ socket.on('all', onEvent);
+
+ $events = $('#events');
+}
+
+function onServerConnected(e) {
+ log('Connected to server', 'info');
+}
+
+function onServerDisconnected(e) {
+ log('Disconnected from server', 'info');
+}
+
+function onEvent(e) {
+ log('New event ' + e.eventName + ' on ' + e.channel, 'status');
+
+ var note = webkitNotifications.createNotification('/img/icon128-min.png', 'New Event', e.data.toString());
+ note.show();
+}
+
+function log(str, type) {
+ $events.append('<li class="'+type+'">' + str + '</li>');
+}
View
@@ -0,0 +1,111 @@
+(function() {
+ // def
+ var $els,
+ hideNotification,
+ options;
+
+ // Hook up to page load event
+ window.addEventListener( 'load', init );
+
+ // define default options
+ options = {
+ 'host': 'http://localhost:9000'
+ };
+
+ /**
+ * Initial options
+ */
+ function init() {
+ restore();
+ updateUI();
+
+ $('#options-form').submit( onFormSubmit );
+ }
+
+ /**
+ * Cached select
+ * @param {String} selector the selector string
+ * @param {Object} jquery object
+ */
+ function c$( selector ) {
+ var $el;
+
+ $els = $els || {};
+ $el = $els[selector];
+
+ if(!$el) {
+ $el = $els[selector] = $(selector);
+ console.log('selecting');
+ } else {
+ console.log('cached selecting');
+ }
+
+ return $el;
+ }
+
+ /**
+ * Handle options form submit
+ * @parm {Object} e event object
+ */
+ function onFormSubmit( e ) {
+ options.host = c$('#options-host').val();
+ save();
+ e.preventDefault();
+ }
+
+ /**
+ * Load options from local storage
+ */
+ function restore() {
+ var persisted = localStorage.options,
+ restoredOptions,
+ prop;
+
+ if( !persisted ) {
+ return;
+ }
+
+ try {
+ restoredOptions = JSON.parse(persisted);
+ for( prop in restoredOptions ) {
+ if( restoredOptions.hasOwnProperty(prop) ) {
+ options[prop] = restoredOptions[prop];
+ }
+ }
+ } catch(e) {
+ // could not load options from local storage, that's fine.
+ // save the default options to local storage
+ save();
+ }
+ }
+
+ /**
+ * Update UI with current options
+ */
+ function updateUI() {
+ c$('#options-host').val( options.host );
+ }
+
+ /**
+ * Save options to local storage
+ * @param {Boolean} silent save changes without notifyign user
+ */
+ function save( silent ) {
+ var notify$El = c$('.notification');
+
+ localStorage.options = JSON.stringify( options );
+
+ if( !silent ) {
+ notify$El.html(notify$El.attr('data-save-msg'));
+ notify$El.addClass('active');
+
+ if( hideNotification ) {
+ clearTimeout( hideNotification );
+ }
+
+ hideNotification = setTimeout( function() {
+ notify$El.removeClass('active');
+ }, 5000);
+ }
+ }
+}());
Oops, something went wrong.

0 comments on commit 6fd2137

Please sign in to comment.