- 
          
- 
        Couldn't load subscription status. 
- Fork 3.7k
[JUX2] [07] Added front-end hover icon to modules to edit module in backend (with tooltip showing module position) #2125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
21f792d
              2a63ef8
              874b687
              15c564d
              6ad383f
              24761ff
              666b573
              eb6ad80
              089783d
              f19b7a7
              b456d87
              0a61974
              1c3bdfb
              63c2f3b
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Site | ||
| * @subpackage Layout | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|  | ||
| defined('_JEXEC') or die; | ||
|  | ||
| // JLayout for standard handling of the edit modules: | ||
|  | ||
| $moduleHtml =& $displayData['moduleHtml']; | ||
| $mod = $displayData['module']; | ||
| $position = $displayData['position']; | ||
|  | ||
| static $jsNotOut =true; | ||
|  | ||
| $app = JFactory::getApplication(); | ||
|  | ||
| $cannotEditFrontend = $app->isAdmin() || !JFactory::getUser()->authorise('core.manage', 'com_modules'); | ||
|  | ||
|  | ||
| if (!$moduleHtml) | ||
| { | ||
| return; | ||
| } | ||
|  | ||
| if ($cannotEditFrontend | ||
| || preg_match('/<(?:div|span|nav|ul) [^>]*class="[^"]* jmoddiv"/', $moduleHtml)) | ||
| { | ||
| // Module isn't enclosing in a div with class or handles already module edit button: | ||
| return; | ||
| } | ||
|  | ||
| // Add css class jmoddiv and data attributes for module-editing URL and for the tooltip: | ||
| $editUrl = JURI::base() . 'administrator/' . 'index.php?option=com_modules&view=module&layout=edit&id=' . (int) $mod->id; | ||
|  | ||
| // Add class, editing URL and tooltip, and if module of type menu, also the tooltip for editing the menu item: | ||
| $moduleHtml = preg_replace('/^(<(?:div|span|nav|ul) [^>]*class="[^"]*)"/', | ||
| '\\1 jmoddiv" data-jmodediturl="' . $editUrl. '"' | ||
| . ' data-jmodtip="' | ||
| . JHtml::tooltipText(JText::_('JLIB_HTML_EDIT_MODULE'), htmlspecialchars($mod->title) . '<br />' . sprintf(JText::_('JLIB_HTML_EDIT_MODULE_IN_POSITION'), htmlspecialchars($position)), 0) | ||
| . '"' | ||
| . ($mod->module == 'mod_menu' ? '" data-jmenuedittip="' . JHtml::tooltipText('JLIB_HTML_EDIT_MENU_ITEM', 'JLIB_HTML_EDIT_MENU_ITEM_ID') . '"' : ''), | ||
| $moduleHtml); | ||
|  | ||
| if ($jsNotOut) | ||
| { | ||
| // Load once booststrap tooltip and add stylesheet and javascript to head: | ||
| $jsNotOut = false; | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this for? JHtml already caches assets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catching early instead of late code that does not need to be executed most of the time is good CS practice. I don't see your issue here, sorry. | ||
| JHtml::_('bootstrap.tooltip'); | ||
| JHtml::_('bootstrap.popover'); | ||
|  | ||
| JFactory::getDocument()->addStyleSheet('media/system/css/frontediting.css') | ||
| ->addScript('media/system/js/frontediting.js'); | ||
| } | ||
|  | ||
| ?> | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -36,7 +36,11 @@ public function render($position, $params = array(), $content = null) | |
|  | ||
| foreach (JModuleHelper::getModules($position) as $mod) | ||
| { | ||
| $buffer .= $renderer->render($mod, $params, $content); | ||
| $moduleHtml = trim($renderer->render($mod, $params, $content)); | ||
|  | ||
| JLayoutHelper::render('joomla.edit.frontediting_modules', array('moduleHtml' => &$moduleHtml, 'module' => $mod, 'position' => $position)); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is a good place for the permission check. Something like: if (JFactory::getApplication()->isAdmin() || JFactory::getUser()->authorise('core.manage', 'com_modules'))
{
    JLayoutHelper::render('joomla.edit.frontediting_modules', array('moduleHtml' => &$moduleHtml, 'module' => $mod, 'position' => $position));
}There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the layout already returns HTML so why add it as param? Wouldn't be the same: $buffer .= JLayoutHelper::render('joomla.edit.frontediting_modules', array('module' => $mod, 'position' => $position));Doing the enclosing div check outside the layout? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 Not really, as the JLayout does adjust the passed HTML (and as it's a JLayout, other templates can have their own override for their own markup if needed). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core.manage is the incorrect permission here. It should be core.edit at miniumum if not also core.edit.state. | ||
|  | ||
| $buffer .= $moduleHtml; | ||
| } | ||
| return $buffer; | ||
| } | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|  | ||
| /* Module edit in front-end */ | ||
|  | ||
| .jmoddiv.jmodinside { | ||
| position: relative; | ||
| top: 0; | ||
| left: 0; | ||
| } | ||
| .btn.jmodedit | ||
| { | ||
| z-index: 1001; | ||
| display: block; | ||
| position: absolute; | ||
| top: 0; | ||
| right: 0; | ||
| } | ||
| html[dir=rtl] .btn.jmodedit | ||
| { | ||
| right: auto; | ||
| left: 0; | ||
| } | ||
|  | ||
| /* Menu edit in front-end */ | ||
|  | ||
| .btn.jfedit-menu | ||
| { | ||
| z-index: 1002; | ||
| display: block; | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this check should be done outside the layout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it could. The idea was to completely "outsource" to the JLayout class that task, but if you prefer we can do it in another "outsourced" way ;-)