Author: Jonathan.Wage
Date: 2010-01-31 20:35:41 +0100 (Sun, 31 Jan 2010)
New Revision: 27365

Added:
   plugins/sfSympalPlugin/trunk/web/js/shortcuts.js
Modified:
   plugins/sfSympalPlugin/trunk/config/app.yml
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/config/sfSympalAdminPluginConfiguration.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_admin/templates/_menu.php
   plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/web/js/menu.js
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/sfSympalAssetsPluginConfiguration.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/config/sfSympalEditorPluginConfiguration.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/helper/SympalContentSlotEditorHelper.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/menu/sfSympalMenuInlineEditBarButtons.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/web/js/editor.js
Log:
[1.4][sfSympalPlugin][1.0] Adding shortcuts js library and adding shortcuts for 
inline edit bar buttons, publish button and signout button


Modified: plugins/sfSympalPlugin/trunk/config/app.yml
===================================================================
--- plugins/sfSympalPlugin/trunk/config/app.yml 2010-01-31 18:24:42 UTC (rev 
27364)
+++ plugins/sfSympalPlugin/trunk/config/app.yml 2010-01-31 19:35:41 UTC (rev 
27365)
@@ -114,6 +114,7 @@
           - /sfSympalPlugin/js/jQuery.cookie.js
           - /sfSympalPlugin/fancybox/jquery.fancybox.js
           - /sfSympalAdminPlugin/js/admin.js
+          - /sfSympalPlugin/js/shortcuts.js
         stylesheets:
           - /sfSympalPlugin/fancybox/jquery.fancybox.css
           - /sfSympalAdminPlugin/css/global.css

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/config/sfSympalAdminPluginConfiguration.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/config/sfSympalAdminPluginConfiguration.class.php
      2010-01-31 18:24:42 UTC (rev 27364)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/config/sfSympalAdminPluginConfiguration.class.php
      2010-01-31 19:35:41 UTC (rev 27365)
@@ -17,6 +17,7 @@
 
     $menu->
       addChild('Dashboard', '@sympal_dashboard')->
+      setShortcut('Ctrl+D')->
       setInputClass('toggle_dashboard_menu')
     ;
   }

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_admin/templates/_menu.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_admin/templates/_menu.php
       2010-01-31 18:24:42 UTC (rev 27364)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_admin/templates/_menu.php
       2010-01-31 19:35:41 UTC (rev 27365)
@@ -1,7 +1,7 @@
 <div class="sympal_top_bar_background"></div>
 
 <div class="sympal_signout_icon">
-  <?php echo link_to(image_tag('/sfSympalPlugin/images/signout.png', 
'title='.__('Signout')), '@sympal_signout', 'confirm='.__('Are you sure you 
want to signout?')) ?>
+  <?php echo link_to(image_tag('/sfSympalPlugin/images/signout.png'), 
'@sympal_signout', 'title="Signout Shortcut: Ctrl+Q" confirm='.__('Are you sure 
you want to signout?')) ?>
 </div>
 
 <div class="sympal_admin_menu">

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/web/js/menu.js
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/web/js/menu.js 
2010-01-31 18:24:42 UTC (rev 27364)
+++ plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/web/js/menu.js 
2010-01-31 19:35:41 UTC (rev 27365)
@@ -1,4 +1,8 @@
 $(function() {
+  shortcut.add('Ctrl+Q', function() {
+    $('.sympal_signout_icon a').click();
+  });
+
   // Top admin menu bar mouseover and mouseout events for dropdown menus
   $('.sympal_admin_menu ul > li').bind('mouseover', sympalAdminMenuOpen);
   $('.sympal_admin_menu ul > li').bind('mouseout', sympalAdminMenuClose);

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/sfSympalAssetsPluginConfiguration.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/sfSympalAssetsPluginConfiguration.class.php
    2010-01-31 18:24:42 UTC (rev 27364)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/sfSympalAssetsPluginConfiguration.class.php
    2010-01-31 19:35:41 UTC (rev 27365)
@@ -17,6 +17,7 @@
       $menu->
         addChild('Assets', '@sympal_assets_select')->
         isEditModeButton(true)->
+        setShortcut('Ctrl+A')->
         setInputClass('toggle_sympal_assets')
       ;
     }

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/config/sfSympalEditorPluginConfiguration.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/config/sfSympalEditorPluginConfiguration.class.php
    2010-01-31 18:24:42 UTC (rev 27364)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/config/sfSympalEditorPluginConfiguration.class.php
    2010-01-31 19:35:41 UTC (rev 27365)
@@ -16,23 +16,27 @@
     
     $menu->addChild('Save')->
       isEditModeButton(true)->
+      setShortcut('Ctrl+S')->
       setInputClass('sympal_save_content_slots')
     ;
 
     $menu->
       addChild('Preview')->
       isEditModeButton(true)->
+      setShortcut('Ctrl+Shift+S')->
       setInputClass('sympal_preview_content_slots')
     ;
 
     $menu->
       addChild('Enable Edit Mode')->
+      setShortcut('Ctrl+E')->
       setInputClass('toggle_edit_mode')
     ;
 
     $menu->
       addChild('Disable Edit Mode')->
       isEditModeButton(true)->
+      setShortcut('Ctrl+X')->
       setInputClass('sympal_disable_edit_mode')
     ;
   }
@@ -96,6 +100,9 @@
       
$response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/fancybox/jquery.fancybox.js'));
       
$response->addStylesheet(sfSympalConfig::getAssetPath('/sfSympalPlugin/fancybox/jquery.fancybox.css'));
 
+      // Shortcuts
+      
$response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/js/shortcuts.js'));
+
       $this->_editorAssetsLoaded = true;
     }
   }

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/helper/SympalContentSlotEditorHelper.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/helper/SympalContentSlotEditorHelper.php
  2010-01-31 18:24:42 UTC (rev 27364)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/helper/SympalContentSlotEditorHelper.php
  2010-01-31 19:35:41 UTC (rev 27365)
@@ -46,6 +46,7 @@
   {
     $menu->addChild('Links', '@sympal_editor_links')->
       isEditModeButton(true)->
+      setShortcut('Ctrl+L')->
       setInputClass('toggle_sympal_links')
     ;
   }

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/menu/sfSympalMenuInlineEditBarButtons.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/menu/sfSympalMenuInlineEditBarButtons.class.php
   2010-01-31 18:24:42 UTC (rev 27364)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/menu/sfSympalMenuInlineEditBarButtons.class.php
   2010-01-31 19:35:41 UTC (rev 27365)
@@ -5,8 +5,15 @@
   protected
     $_isEditModeButton = false,
     $_inputClass,
-    $_isButton = true;
+    $_isButton = true,
+    $_shortcut;
 
+  public function setShortcut($shortcut)
+  {
+    $this->_shortcut = $shortcut;
+    return $this;
+  }
+
   public function setInputClass($class)
   {
     $this->_inputClass = $class;
@@ -39,10 +46,15 @@
       $class = $this->_isEditModeButton ? $this->_inputClass.' 
sympal_inline_edit_bar_edit_buttons' : $this->_inputClass;
       if ($this->_route)
       {
-        $html = '<input type="button" rel="'.url_for($this->_route).'" 
value="'.$this->renderLabel().'" class="'.$class.'" />';
+        $html = '<input title="'.$this->_shortcut.'" type="button" 
rel="'.url_for($this->_route).'" value="'.$this->renderLabel().'" 
class="'.$class.'" />';
       } else {
-        $html = '<input type="button" value="'.$this->renderLabel().'" 
class="'.$class.'" />';
+        $html = '<input title="'.$this->_shortcut.'" type="button" 
value="'.$this->renderLabel().'" class="'.$class.'" />';
       }
+      
+      if ($this->_shortcut)
+      {
+        $html .= '<script type="text/javascript">$(function() { 
shortcut.add("'.$this->_shortcut.'", function() { 
$(\'.'.$this->_inputClass.'\').click(); }); });</script>';
+      }
     } else {
       $html = parent::renderChildBody();
     }

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/web/js/editor.js
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/web/js/editor.js  
    2010-01-31 18:24:42 UTC (rev 27364)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/web/js/editor.js  
    2010-01-31 19:35:41 UTC (rev 27365)
@@ -2,6 +2,10 @@
 
 $(function()
 {
+  shortcut.add('Ctrl+P', function() {
+    $('.sympal_inline_edit_bar_publish a').click();
+  });
+
   // Content publishing fancybox
   $('#sympal_assets #sympal_ask_confirmation input.no').live('click', 
function() {
     $('#sympal_assets').load($('.toggle_sympal_assets').attr('rel'));

Added: plugins/sfSympalPlugin/trunk/web/js/shortcuts.js
===================================================================
--- plugins/sfSympalPlugin/trunk/web/js/shortcuts.js                            
(rev 0)
+++ plugins/sfSympalPlugin/trunk/web/js/shortcuts.js    2010-01-31 19:35:41 UTC 
(rev 27365)
@@ -0,0 +1,223 @@
+/**
+ * http://www.openjs.com/scripts/events/keyboard_shortcuts/
+ * Version : 2.01.B
+ * By Binny V A
+ * License : BSD
+ */
+shortcut = {
+       'all_shortcuts':{},//All the shortcuts are stored in this array
+       'add': function(shortcut_combination,callback,opt) {
+               //Provide a set of default options
+               var default_options = {
+                       'type':'keydown',
+                       'propagate':false,
+                       'disable_in_input':false,
+                       'target':document,
+                       'keycode':false
+               }
+               if(!opt) opt = default_options;
+               else {
+                       for(var dfo in default_options) {
+                               if(typeof opt[dfo] == 'undefined') opt[dfo] = 
default_options[dfo];
+                       }
+               }
+
+               var ele = opt.target;
+               if(typeof opt.target == 'string') ele = 
document.getElementById(opt.target);
+               var ths = this;
+               shortcut_combination = shortcut_combination.toLowerCase();
+
+               //The function to be called at keypress
+               var func = function(e) {
+                       e = e || window.event;
+                       
+                       if(opt['disable_in_input']) { //Don't enable shortcut 
keys in Input, Textarea fields
+                               var element;
+                               if(e.target) element=e.target;
+                               else if(e.srcElement) element=e.srcElement;
+                               if(element.nodeType==3) 
element=element.parentNode;
+
+                               if(element.tagName == 'INPUT' || 
element.tagName == 'TEXTAREA') return;
+                       }
+       
+                       //Find Which key is pressed
+                       if (e.keyCode) code = e.keyCode;
+                       else if (e.which) code = e.which;
+                       var character = String.fromCharCode(code).toLowerCase();
+                       
+                       if(code == 188) character=","; //If the user presses , 
when the type is onkeydown
+                       if(code == 190) character="."; //If the user presses , 
when the type is onkeydown
+
+                       var keys = shortcut_combination.split("+");
+                       //Key Pressed - counts the number of valid keypresses - 
if it is same as the number of keys, the shortcut function is invoked
+                       var kp = 0;
+                       
+                       //Work around for stupid Shift key bug created by using 
lowercase - as a result the shift+num combination was broken
+                       var shift_nums = {
+                               "`":"~",
+                               "1":"!",
+                               "2":"@",
+                               "3":"#",
+                               "4":"$",
+                               "5":"%",
+                               "6":"^",
+                               "7":"&",
+                               "8":"*",
+                               "9":"(",
+                               "0":")",
+                               "-":"_",
+                               "=":"+",
+                               ";":":",
+                               "'":"\"",
+                               ",":"<",
+                               ".":">",
+                               "/":"?",
+                               "\\":"|"
+                       }
+                       //Special Keys - and their codes
+                       var special_keys = {
+                               'esc':27,
+                               'escape':27,
+                               'tab':9,
+                               'space':32,
+                               'return':13,
+                               'enter':13,
+                               'backspace':8,
+       
+                               'scrolllock':145,
+                               'scroll_lock':145,
+                               'scroll':145,
+                               'capslock':20,
+                               'caps_lock':20,
+                               'caps':20,
+                               'numlock':144,
+                               'num_lock':144,
+                               'num':144,
+                               
+                               'pause':19,
+                               'break':19,
+                               
+                               'insert':45,
+                               'home':36,
+                               'delete':46,
+                               'end':35,
+                               
+                               'pageup':33,
+                               'page_up':33,
+                               'pu':33,
+       
+                               'pagedown':34,
+                               'page_down':34,
+                               'pd':34,
+       
+                               'left':37,
+                               'up':38,
+                               'right':39,
+                               'down':40,
+       
+                               'f1':112,
+                               'f2':113,
+                               'f3':114,
+                               'f4':115,
+                               'f5':116,
+                               'f6':117,
+                               'f7':118,
+                               'f8':119,
+                               'f9':120,
+                               'f10':121,
+                               'f11':122,
+                               'f12':123
+                       }
+       
+                       var modifiers = { 
+                               shift: { wanted:false, pressed:false},
+                               ctrl : { wanted:false, pressed:false},
+                               alt  : { wanted:false, pressed:false},
+                               meta : { wanted:false, pressed:false}   //Meta 
is Mac specific
+                       };
+                        
+                       if(e.ctrlKey)   modifiers.ctrl.pressed = true;
+                       if(e.shiftKey)  modifiers.shift.pressed = true;
+                       if(e.altKey)    modifiers.alt.pressed = true;
+                       if(e.metaKey)   modifiers.meta.pressed = true;
+                        
+                       for(var i=0; k=keys[i],i<keys.length; i++) {
+                               //Modifiers
+                               if(k == 'ctrl' || k == 'control') {
+                                       kp++;
+                                       modifiers.ctrl.wanted = true;
+
+                               } else if(k == 'shift') {
+                                       kp++;
+                                       modifiers.shift.wanted = true;
+
+                               } else if(k == 'alt') {
+                                       kp++;
+                                       modifiers.alt.wanted = true;
+                               } else if(k == 'meta') {
+                                       kp++;
+                                       modifiers.meta.wanted = true;
+                               } else if(k.length > 1) { //If it is a special 
key
+                                       if(special_keys[k] == code) kp++;
+                                       
+                               } else if(opt['keycode']) {
+                                       if(opt['keycode'] == code) kp++;
+
+                               } else { //The special keys did not match
+                                       if(character == k) kp++;
+                                       else {
+                                               if(shift_nums[character] && 
e.shiftKey) { //Stupid Shift key bug created by using lowercase
+                                                       character = 
shift_nums[character]; 
+                                                       if(character == k) kp++;
+                                               }
+                                       }
+                               }
+                       }
+                       
+                       if(kp == keys.length && 
+                                               modifiers.ctrl.pressed == 
modifiers.ctrl.wanted &&
+                                               modifiers.shift.pressed == 
modifiers.shift.wanted &&
+                                               modifiers.alt.pressed == 
modifiers.alt.wanted &&
+                                               modifiers.meta.pressed == 
modifiers.meta.wanted) {
+                               callback(e);
+       
+                               if(!opt['propagate']) { //Stop the event
+                                       //e.cancelBubble is supported by IE - 
this will kill the bubbling process.
+                                       e.cancelBubble = true;
+                                       e.returnValue = false;
+       
+                                       //e.stopPropagation works in Firefox.
+                                       if (e.stopPropagation) {
+                                               e.stopPropagation();
+                                               e.preventDefault();
+                                       }
+                                       return false;
+                               }
+                       }
+               }
+               this.all_shortcuts[shortcut_combination] = {
+                       'callback':func, 
+                       'target':ele, 
+                       'event': opt['type']
+               };
+               //Attach the function with the event
+               if(ele.addEventListener) ele.addEventListener(opt['type'], 
func, false);
+               else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], 
func);
+               else ele['on'+opt['type']] = func;
+       },
+
+       //Remove the shortcut - just specify the shortcut and I will remove the 
binding
+       'remove':function(shortcut_combination) {
+               shortcut_combination = shortcut_combination.toLowerCase();
+               var binding = this.all_shortcuts[shortcut_combination];
+               delete(this.all_shortcuts[shortcut_combination])
+               if(!binding) return;
+               var type = binding['event'];
+               var ele = binding['target'];
+               var callback = binding['callback'];
+
+               if(ele.detachEvent) ele.detachEvent('on'+type, callback);
+               else if(ele.removeEventListener) ele.removeEventListener(type, 
callback, false);
+               else ele['on'+type] = false;
+       }
+}
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to