Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c6525a5d05
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 353 lines (321 sloc) 11.394 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <meta charset="utf-8"/>
    <script>
    
// 1. edit & draft button.
  
var editor = {};
editor.editing = false;
editor.END_EDIT = "End";
editor.BEGIN_EDIT = "Edit";

function change(obj) {
  /* Switch from editing mode to browsing mode and back again. */
  chrome.tabs.getSelected(null, function(tab) {
    if (editor.editing == false) {
      obj.textContent = editor.END_EDIT;
    } else {
      obj.textContent = editor.BEGIN_EDIT;
    }
    editor.editing = !editor.editing;

    chrome.tabs.sendRequest(tab.id, {edit:editor.editing, name:true},
      function(response) {
        if (!response.ok) { console.log("iDoc communication error"); }
        if (response.save) {
          /* We save the file on end edit. */
          localStorage['iDoc-'+response.save] = response.content;
        }
      }
    );
  });
}

function draft() {
  /* Make a copy of the current work in draft space. */
  chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.sendRequest(tab.id, {edit:'draft'}, function(response) {
      if (!response.ok) { console.log("iDoc communication error"); }
      if (response.save) {
        localStorage['iDoc-'+response.save] = response.content;
      }
    });
  });
}
  
  
// 2. controls.
  
editor.command = "";

function InitToolbarButtons() {
  var kids = document.getElementsByTagName('div');
  
  for (var i=0; i < kids.length; i++) {
    if (kids[i].className == "imagebutton") {
      kids[i].onmouseover = tbmouseover;
      kids[i].onmouseout = tbmouseout;
      kids[i].onmousedown = tbmousedown;
      kids[i].onmouseup = tbmouseup;
      kids[i].onclick = tbclick;
      kids[i].style.border="solid 1px #ebeff9";
      kids[i].style.borderRadius="2px";
    }
  }
}

function tbmousedown(evt) {
  this.firstChild.style.left = 1;
  this.firstChild.style.top = 1;
  this.style.backgroundColor="#d2dbed";
  evt.preventDefault( );
}

function tbmouseup() {
  this.firstChild.style.left = 1;
  this.firstChild.style.top = 1;
  this.style.backgroundColor="#ebeff9";
}

function tbmouseout() {
  this.style.border="solid 1px #ebeff9";
}

function tbmouseover() {
  this.style.border="solid 1px #d2dbed";
}

function getOffsetTop(elm) {
  var mOffsetTop = elm.offsetTop;
  var mOffsetParent = elm.offsetParent;
  
  while(mOffsetParent){
    mOffsetTop += mOffsetParent.offsetTop;
    mOffsetParent = mOffsetParent.offsetParent;
  }
  
  return mOffsetTop;
}

function getOffsetLeft(elm) {
  var mOffsetLeft = elm.offsetLeft;
  var mOffsetParent = elm.offsetParent;
  
  while(mOffsetParent){
    mOffsetLeft += mOffsetParent.offsetLeft;
    mOffsetParent = mOffsetParent.offsetParent;
  }
  
  return mOffsetLeft;
}

function tbclick() {
  if(!editor.editing) { change(document.getElementById('ed')); }
  var act = this.id;
  if(act == "mail") { // sending mail.
    // special info.
    chrome.tabs.getSelected(null, function(tab) {
      chrome.tabs.sendRequest(tab.id, {edit:"askName"},
        function(r) {
          var subject = r.name;
          var body = r.content;
          // mailto
          var action_url = 'mailto:?';
          if(subject.length > 0)
            action_url += "subject="+encodeURIComponent(subject)+'&';
          if(body.length > 0)
            action_url += "body="+encodeURIComponent(body);
          chrome.tabs.update(tab.id, {url:action_url});
        })
    });
  } else if ((act == "forecolor") || (act == "hilitecolor")) {
    editor.command = act;
    buttonElement = document.getElementById(act);
    var colorpalette = document.getElementById("colorpalette");
    colorpalette.style.left = getOffsetLeft(buttonElement);
    colorpalette.style.top = getOffsetTop(buttonElement) +
        buttonElement.offsetHeight;
    document.body.style.height = "255px";
    colorpalette.style.display = "block";
    colorpalette.style.visibility="visible";
  } else {
    chrome.tabs.getSelected(null, function(tab) {
      chrome.tabs.sendRequest(tab.id, {edit:"do",action:act},
        function(response) {
          if(!response.ok) { console.log("iDoc communication error"); }
        });
    });
  }
}

function Select(selectname) {
  var cursel = document.getElementById(selectname).selectedIndex;
  /* First one is always a label */
  if (cursel != 0) {
    var selected= document.getElementById(selectname).options[cursel].value;
    chrome.tabs.getSelected(null, function(tab) {
      chrome.tabs.sendRequest(tab.id, {edit:"do",action:selectname,
          arg:selected}, function(response) {
        if(!response.ok) console.log("iDoc communication error");
        document.getElementById(selectname).selectedIndex = 0;
      });
    });
  }
}

function dismisscolorpalette() {
  var colorpalette = document.getElementById("colorpalette");
  colorpalette.style.visibility = "hidden";
  colorpalette.style.display = "none";
}

/* here be the css button call */
function cssbut() {
  chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.sendRequest(tab.id, {edit:"css"}, function(r) {});
  });
}

function newFile() {
  chrome.tabs.create({url:"./new.html",selected:false}, function(tab2) {
    chrome.tabs.sendRequest(tab2.id, {edit:true}, function(r) {
      if(!r.ok) console.log('iDoc communication error.');
    });
  });
}

function init() {
  chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.sendRequest(tab.id, {edit:"ask"}, function(response) {
      editor.editing = response.editing;
      document.getElementById('ed').textContent = editor.editing?
          editor.END_EDIT: editor.BEGIN_EDIT; // Edit on.
      document.getElementById('new').style.display = 'none';
      var tables = document.getElementsByTagName('table');
      for(var i=0; i<tables.length; i++)
        tables[i].style.display = "table";
    });
  });
  chrome.extension.onRequest.addListener(
    function(request, sender, sendResponse) {
      if(request.save) // It comes from the content script.
        localStorage['iDoc-'+request.save] = request.content;
      sendResponse({});
    }
  );
  InitToolbarButtons();
  document.addEventListener("mousedown", dismisscolorpalette, true);
}
    </script>
  </head>

  <body onload="init();">
    <style>
      body { width: 400px; margin:0px; padding:0px; }
      table { width:100%; background-color: #ebeff9; display: none; }
      table td { text-align: center; }
    </style>
    <button id="new" onclick="newFile();" style="width:100%">New</button>

<table id="toolbar1">
  <tr>
    <td>
      <button id="ed" onclick="change(this);"></button>
    </td>
    <td>
      <button id="new2" onclick="newFile();">New</button>
    </td>
    <td>
      <div class="imagebutton" id="mail"><img class="image" src="mail.png" alt="Mail" title="Mail"></div>
    </td>
    <td>
      <div class="imagebutton" id="cut"><img class="image" src="cut.png" alt="Cut" title="Cut"></div>
    </td>
    <td>
      <div class="imagebutton" id="copy"><img class="image" src="copy.png" alt="Copy" title="Copy"></div>
    </td>
    <td>
      <div class="imagebutton" id="paste"><img class="image" src="paste.png" alt="Paste" title="Paste"></div>
    </td>
    <td>
      <div class="imagebutton" id="undo"><img class="image" src="undo.png" alt="Undo" title="Undo"></div>
    </td>
    <td>
      <div class="imagebutton" id="redo"><img class="image" src="redo.png" alt="Redo" title="Redo"></div>
    </td>
    <td>
      <div style="left: 10;" class="imagebutton" id="createlink"><img class="image" src="link.png" alt="Insert Link" title="Insert Link"></div>
    </td>
    <td>
      <div style="left: 10;" class="imagebutton" id="insertimage"><img class="image" src="image.png" alt="Insert Image" title="Insert Image"></div>
    </td>
    <td>
      <div style="left: 10;" class="imagebutton" id="createtable"><img class="image" src="table.png" alt="Insert Table" title="Insert Table"></div>
    </td>
  </tr>
</table>

<table id="toolbar2">
  <tr>
    <td>
      <button id="draft" onclick="draft();">Draft</button>
    </td>
    <td>
      <select id="formatblock" onchange="Select(this.id);">
        <option value="<p>">Normal</option>
        <option value="<p>">Paragraph</option>
        <option value="<h1>">Heading 1</option>
          <option value="<h2>">Heading 2</option>
            <option value="<h3>">Heading 3</option>
              <option value="<h4>">Heading 4</option>
                <option value="<h5>">Heading 5</option>
                  <option value="<h6>">Heading 6</option>
                    <option value="<address>">Address</option>
                      <option value="<pre>">Formatted</option>
</select>
</td>
<td>
<select id="fontname" onchange="Select(this.id);">
  <option value="Font">Font</option>
  <option value="Arial">Arial</option>
  <option value="Courier">Courier</option>
  <option value="Times New Roman">Times</option>
</select>
</td>
<td>
<select unselectable="on" id="fontsize" onchange="Select(this.id);">
  <option value="Size">Size</option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>

  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
</select>
</td>
<td>
<div class="imagebutton" id="bold"><img class="image" src="bold.png" alt="Bold" title="Bold"></div>
</td>
<td>
<div class="imagebutton" id="italic"><img class="image" src="italic.png" alt="Italic" title="Italic"></div>
</td>
<td>
<div class="imagebutton" id="underline"><img class="image" src="underline.png" alt="Underline" title="Underline"></div>
</td>
</tr>
</table>

<table id="toolbar3">
<tr>
<td>
  <button id="css" onclick="cssbut(this);">css</button>
</td>
<td>
<div style="left: 10;" class="imagebutton" id="forecolor"><img class="image" src="forecolor.png" alt="Text Color" title="Text Color"></div>
</td>
<td>
<div style="left: 40;" class="imagebutton" id="hilitecolor"><img class="image" src="backcolor.png" alt="Background Color" title="Background Color"></div>
</td>
<td>
<div style="left: 10;" class="imagebutton" id="justifyleft"><img class="image" src="textleft.png" alt="Align Left" title="Align Left"></div>
</td>
<td>
<div style="left: 40;" class="imagebutton" id="justifycenter"><img class="image" src="textcenter.png" alt="Center" title="Center"></div>
</td>
<td>
<div style="left: 70;" class="imagebutton" id="justifyright"><img class="image" src="textright.png" alt="Align Right" title="Align Right"></div>
</td>
<td>
<div style="left: 70;" class="imagebutton" id="justifyfull"><img class="image" src="textjustify.png" alt="Justify" title="Justify"></div>
</td>
<td>
<div style="left: 10;" class="imagebutton" id="insertorderedlist"><img class="image" src="orderedlist.png" alt="Ordered List" title="Ordered List"></div>
</td>
<td>
<div style="left: 40;" class="imagebutton" id="insertunorderedlist"><img class="image" src="unorderedlist.png" alt="Unordered List" title="Unordered List"></div>
</td>
<td>
<div style="left: 10;" class="imagebutton" id="outdent"><img class="image" src="outdent.png" alt="Outdent" title="Outdent"></div>
</td>
<td>
<div style="left: 40;" class="imagebutton" id="indent"><img class="image" src="indent.png" alt="Indent" title="Indent"></div>
</td>
</tr>
</table>
<iframe width="250" height="170" id="colorpalette" src="colors.html" style="visibility:hidden; display: none; position: absolute;"></iframe>
  </body>
</html>
Something went wrong with that request. Please try again.