Commits

Rune Halvorsen  committed d90915d

Added some button tests

  • Participants
  • Parent commits b154539

Comments (0)

Files changed (2)

File extension/index.html

 <!doctype html>
 <script>
 window.addEventListener("load", setupConnection, false);
+window.g_button = null;
 
 function s2b(s) {
     return s=="true" ? true : false;
 {
     opera.extension.onconnect = onConnectHandler;
     opera.extension.onmessage = onMessageHandler;
+
+    window.g_button = createButton();
+    
+    window.addEventListener("storage", onPrefsChange, false);
 }
 
+function onPrefsChange(evt) {
+    if (evt.key == "show_button") {
+        var show = s2b(evt.newValue)
+        setButtonState(show);
+    }
+}
+
+function setButtonState(show) { 
+    opera.postError("asdf " + show);
+    
+    if (show) {
+        opera.contexts.toolbar.addItem(window.g_button);
+    }
+    else {
+        opera.contexts.toolbar.removeItem(window.g_button);
+    }
+}
+
+function createButton() {
+    var UIItemProperties = {
+        disabled: false, // The button is enabled.
+        title: "Button example", // The tooltip title.
+        icon: "unshorten_18.png", // The icon (18x18) to use for the button.
+        onclick: function() {
+            // Let's output a message to the error console.
+            window.opera.postError('"Button example" clicked.');
+            widget.showNotification("hallaballa", "aavvdd");
+        }
+    };
+    return opera.contexts.toolbar.createItem(UIItemProperties);
+}
+
+
+
 function transmissionCommand(url, method, args, optargs) {
     var conn = new XMLHttpRequest();
     conn.open("POST", url, false);
     return JSON.parse(data);
 }
 
+
 </script>

File extension/options.html

 <!doctype html>
-<script src="includes/unshortinator.js"></script>
 <script>
 
 window.onload = function() {
 //    setOptions();
-  //  document.querySelector("#clear_cache").addEventListener("click", clearCache, false);
+    document.querySelector("#show_button").addEventListener("click", saveOptions, false);
 }
 
 function s2b(s) {
 }
 
 function setOptions() {
+return
     document.querySelector("#use_cache").checked = s2b(widget.preferences["use_cache"]);
     document.querySelector("#rewrite_href").checked = s2b(widget.preferences["rewrite_href"]);
     document.querySelector("#rewrite_textcontent").checked = s2b(widget.preferences["rewrite_textcontent"]);
 }
 
 function saveOptions() {
-    var options = getOptions();
+    widget.preferences["show_button"] = document.querySelector("#show_button").checked;
+
+return;
+var options = getOptions();
     widget.preferences["use_cache"] = options.use_cache;
     widget.preferences["rewrite_href"] = options.rewrite_href;
     widget.preferences["rewrite_textcontent"] = options.rewrite_textcontent;
 <label for="api_url">API url</label><input id="api_url">
 <button type="button">save</button>
 <button type="button">test</button>
+<input type="checkbox" id="show_button">
 <br>
 <br>
 <br>