Permalink
Browse files

add headings support to pad editbar

  • Loading branch information...
1 parent 05d5ac7 commit 15428fd8f99b2a4371f98b42b945c32c43dd044d @polotek committed Sep 19, 2011
Showing with 43 additions and 1 deletion.
  1. +4 −0 static/css/pad.css
  2. +7 −0 static/js/pad2.js
  3. +23 −1 static/js/pad_editbar.js
  4. +9 −0 static/pad.html
View
4 static/css/pad.css
@@ -68,6 +68,10 @@ a img
width: 18px;
}
+#editbar ul .select
+{
+ width:auto;
+}
#editbar ul li a
{
text-decoration: none;
View
7 static/js/pad2.js
@@ -600,6 +600,13 @@ var pad = {
padeditbar.toolbarClick(cmd);
}
},
+ editbarFormatChange: function(select) {
+ if(padeditbar && select) {
+ var val = select.options[select.selectedIndex];
+ val = val ? val.value : '';
+ padeditbar.formatChange(val);
+ }
+ },
dmesg: function(m)
{
if (pad.getIsDebugEnabled())
View
24 static/js/pad_editbar.js
@@ -90,6 +90,25 @@ var padeditbar = (function()
{
$("#editbar").addClass('disabledtoolbar').removeClass("enabledtoolbar");
},
+ formatChange: function(selection) {
+ if(!self.isEnabled()) { return; }
+
+ selection = selection.split(':');
+ var attr = selection.shift();
+ var val = selection.join('');
+
+ padeditor.ace.callWithAce(function(ace) {
+ var attrTable = ace.ace_getAttributeLookup();
+ if(!attrTable[attr]) { return; }
+
+ if(val) {
+ ace.ace_setAttributeOnSelection(attr, val);
+ } else {
+ ace.ace_setAttributeOnSelection(attr, '');
+ }
+ }, attr, true);
+ padeditor.ace.focus();
+ },
toolbarClick: function(cmd)
{
if (self.isEnabled())
@@ -127,7 +146,10 @@ var padeditbar = (function()
{
padeditor.ace.callWithAce(function(ace)
{
- if (cmd == 'bold' || cmd == 'italic' || cmd == 'underline' || cmd == 'strikethrough') ace.ace_toggleAttributeOnSelection(cmd);
+ var attrTable = ace.ace_getAttributeLookup();
+ if (attrTable[cmd]) {
+ if(attrTable[cmd] == 'inline') ace.ace_toggleAttributeOnSelection(cmd);
+ }
else if (cmd == 'undo' || cmd == 'redo') ace.ace_doUndoRedo(cmd);
else if (cmd == 'insertunorderedlist') ace.ace_doInsertUnorderedList();
else if (cmd == 'indent')
View
9 static/pad.html
@@ -23,6 +23,15 @@
<div id="editbar">
<ul id="menu_left">
+<li class="select">
+ <select onChange="window.pad&&pad.editbarFormatChange(this);">
+ <option value="heading">paragraph</option>
+ <option value="heading:1">Heading 1</option>
+ <option value="heading:2">Heading 2</option>
+ <option value="heading:3">Heading 3</option>
+ <option value="heading:4">Heading 4</option>
+ </select>
+</li>
<li onClick="window.pad&&pad.editbarClick('bold');return false" >
<a title="Bold (ctrl-B)">
<div class="buttonicon" style="background-position:0px -116px"></div>

0 comments on commit 15428fd

Please sign in to comment.