|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @package Joomla.Site |
| 4 | + * @subpackage Layout |
| 5 | + * |
| 6 | + * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. |
| 7 | + * @license GNU General Public License version 2 or later; see LICENSE.txt |
| 8 | + */ |
| 9 | + |
| 10 | +defined('_JEXEC') or die; |
| 11 | + |
| 12 | +// JLayout for standard handling of the edit modules: |
| 13 | + |
| 14 | +$moduleHtml =& $displayData['moduleHtml']; |
| 15 | +$mod = $displayData['module']; |
| 16 | +$position = $displayData['position']; |
| 17 | +$menusEditing = $displayData['menusediting']; |
| 18 | + |
| 19 | + |
| 20 | +if (preg_match('/<(?:div|span|nav|ul|ol|h\d) [^>]*class="[^"]* jmoddiv"/', $moduleHtml)) |
| 21 | +{ |
| 22 | + // Module has already module edit button: |
| 23 | + return; |
| 24 | +} |
| 25 | + |
| 26 | +// Add css class jmoddiv and data attributes for module-editing URL and for the tooltip: |
| 27 | +$editUrl = JURI::base() . 'administrator/index.php?option=com_modules&view=module&layout=edit&id=' . (int) $mod->id; |
| 28 | + |
| 29 | +// Add class, editing URL and tooltip, and if module of type menu, also the tooltip for editing the menu item: |
| 30 | +$count = 0; |
| 31 | +$moduleHtml = preg_replace( |
| 32 | + // Replace first tag of module with a class |
| 33 | + '/^(\s*<(?:div|span|nav|ul|ol|h\d) [^>]*class="[^"]*)"/', |
| 34 | + // By itself, adding class jmoddiv and data attributes for the url and tooltip: |
| 35 | + '\\1 jmoddiv" data-jmodediturl="' . $editUrl . '" data-jmodtip="' |
| 36 | + . JHtml::tooltipText( |
| 37 | + JText::_('JLIB_HTML_EDIT_MODULE'), |
| 38 | + htmlspecialchars($mod->title) . '<br />' . sprintf(JText::_('JLIB_HTML_EDIT_MODULE_IN_POSITION'), htmlspecialchars($position)), |
| 39 | + 0 |
| 40 | + ) |
| 41 | + . '"' |
| 42 | + // And if menu editing is enabled and allowed and it's a menu module, add data attributes for menu editing: |
| 43 | + . ($menusEditing && $mod->module == 'mod_menu' ? |
| 44 | + '" data-jmenuedittip="' . JHtml::tooltipText('JLIB_HTML_EDIT_MENU_ITEM', 'JLIB_HTML_EDIT_MENU_ITEM_ID') . '"' |
| 45 | + : |
| 46 | + '' |
| 47 | + ), |
| 48 | + $moduleHtml, |
| 49 | + 1, |
| 50 | + $count |
| 51 | +); |
| 52 | + |
| 53 | +if ($count) |
| 54 | +{ |
| 55 | + // Load once booststrap tooltip and add stylesheet and javascript to head: |
| 56 | + JHtml::_('bootstrap.loadCss', true, JFactory::getDocument()->getDirection()); |
| 57 | + JHtml::_('bootstrap.tooltip'); |
| 58 | + JHtml::_('bootstrap.popover'); |
| 59 | + |
| 60 | + JFactory::getDocument()->addStyleSheet('media/system/css/frontediting.css') |
| 61 | + ->addScript('media/system/js/frontediting.js'); |
| 62 | +} |
0 commit comments