diff --git a/src/administrator/components/com_weblinks/models/fields/modal/weblink.php b/src/administrator/components/com_weblinks/models/fields/modal/weblink.php
new file mode 100644
index 0000000..708ae98
--- /dev/null
+++ b/src/administrator/components/com_weblinks/models/fields/modal/weblink.php
@@ -0,0 +1,272 @@
+element['new'] == 'true');
+ $allowEdit = ((string) $this->element['edit'] == 'true');
+ $allowClear = ((string) $this->element['clear'] != 'false');
+ $allowSelect = ((string) $this->element['select'] != 'false');
+
+ // Load language
+ JFactory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
+
+ // The active weblink id field.
+ $value = (int) $this->value > 0 ? (int) $this->value : '';
+
+ // Create the modal id.
+ $modalId = 'Weblink_' . $this->id;
+
+ // Add the modal field script to the document head.
+ JHtml::_('jquery.framework');
+ JHtml::_('script', 'system/modal-fields.js', array('version' => 'auto', 'relative' => true));
+
+ // Script to proxy the select modal function to the modal-fields.js file.
+ if ($allowSelect)
+ {
+ static $scriptSelect = null;
+
+ if (is_null($scriptSelect))
+ {
+ $scriptSelect = array();
+ }
+
+ if (!isset($scriptSelect[$this->id]))
+ {
+ JFactory::getDocument()->addScriptDeclaration("
+ function jSelectWeblink_" . $this->id . "(id, title, catid, object, url, language) {
+ window.processModalSelect('Weblink', '" . $this->id . "', id, title, catid, object, url, language);
+ }
+ ");
+
+ $scriptSelect[$this->id] = true;
+ }
+ }
+
+ // Setup variables for display.
+ $linkWeblinks = 'index.php?option=com_weblinks&view=weblinks&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1';
+ $linkWeblink = 'index.php?option=com_weblinks&view=weblink&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1';
+
+ if (isset($this->element['language']))
+ {
+ $linkWeblinks .= '&forcedLanguage=' . $this->element['language'];
+ $linkWeblink .= '&forcedLanguage=' . $this->element['language'];
+ $modalTitle = JText::_('COM_WEBLINKS_CHANGE_WEBLINK') . ' — ' . $this->element['label'];
+ }
+ else
+ {
+ $modalTitle = JText::_('COM_WEBLINKS_CHANGE_WEBLINK');
+ }
+
+ $urlSelect = $linkWeblinks . '&function=jSelectWeblink_' . $this->id;
+ $urlEdit = $linkWeblink . '&task=weblink.edit&id=\' + document.getElementById("' . $this->id . '_id").value + \'';
+ $urlNew = $linkWeblink . '&task=weblink.add';
+
+ if ($value)
+ {
+ $db = JFactory::getDbo();
+ $query = $db->getQuery(true)
+ ->select($db->quoteName('title'))
+ ->from($db->quoteName('#__weblinks'))
+ ->where($db->quoteName('id') . ' = ' . (int) $value);
+ $db->setQuery($query);
+
+ try
+ {
+ $title = $db->loadResult();
+ }
+ catch (RuntimeException $e)
+ {
+ JError::raiseWarning(500, $e->getMessage());
+ }
+ }
+
+ $title = empty($title) ? JText::_('COM_WEBLINKS_SELECT_AN_WEBLINK') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
+
+ // The current weblink display field.
+ $html = '';
+ $html .= '';
+
+ // Select weblink button
+ if ($allowSelect)
+ {
+ $html .= ''
+ . ' ' . JText::_('JSELECT')
+ . '';
+ }
+
+ // New weblink button
+ if ($allowNew)
+ {
+ $html .= ''
+ . ' ' . JText::_('JACTION_CREATE')
+ . '';
+ }
+
+ // Edit weblink button
+ if ($allowEdit)
+ {
+ $html .= ''
+ . ' ' . JText::_('JACTION_EDIT')
+ . '';
+ }
+
+ // Clear weblink button
+ if ($allowClear)
+ {
+ $html .= ''
+ . '' . JText::_('JCLEAR')
+ . '';
+ }
+
+ $html .= '';
+
+ // Select weblink modal
+ if ($allowSelect)
+ {
+ $html .= JHtml::_(
+ 'bootstrap.renderModal',
+ 'ModalSelect' . $modalId,
+ array(
+ 'title' => $modalTitle,
+ 'url' => $urlSelect,
+ 'height' => '400px',
+ 'width' => '800px',
+ 'bodyHeight' => '70',
+ 'modalWidth' => '80',
+ 'footer' => '' . JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . '',
+ )
+ );
+ }
+
+ // New weblink modal
+ if ($allowNew)
+ {
+ $html .= JHtml::_(
+ 'bootstrap.renderModal',
+ 'ModalNew' . $modalId,
+ array(
+ 'title' => JText::_('COM_WEBLINKS_NEW_WEBLINK'),
+ 'backdrop' => 'static',
+ 'keyboard' => false,
+ 'closeButton' => false,
+ 'url' => $urlNew,
+ 'height' => '400px',
+ 'width' => '800px',
+ 'bodyHeight' => '70',
+ 'modalWidth' => '80',
+ 'footer' => ''
+ . JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . ''
+ . ''
+ . JText::_('JSAVE') . ''
+ . ''
+ . JText::_('JAPPLY') . '',
+ )
+ );
+ }
+
+ // Edit weblink modal
+ if ($allowEdit)
+ {
+ $html .= JHtml::_(
+ 'bootstrap.renderModal',
+ 'ModalEdit' . $modalId,
+ array(
+ 'title' => JText::_('COM_WEBLINKS_EDIT_WEBLINK'),
+ 'backdrop' => 'static',
+ 'keyboard' => false,
+ 'closeButton' => false,
+ 'url' => $urlEdit,
+ 'height' => '400px',
+ 'width' => '800px',
+ 'bodyHeight' => '70',
+ 'modalWidth' => '80',
+ 'footer' => ''
+ . JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . ''
+ . ''
+ . JText::_('JSAVE') . ''
+ . ''
+ . JText::_('JAPPLY') . '',
+ )
+ );
+ }
+
+ // Note: class='required' for client side validation.
+ $class = $this->required ? ' class="required modal-value"' : '';
+
+ $html .= '';
+
+ return $html;
+ }
+
+ /**
+ * Method to get the field label markup.
+ *
+ * @return string The field label markup.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ protected function getLabel()
+ {
+ return str_replace($this->id, $this->id . '_id', parent::getLabel());
+ }
+}
diff --git a/src/administrator/components/com_weblinks/views/weblink/tmpl/modal.php b/src/administrator/components/com_weblinks/views/weblink/tmpl/modal.php
new file mode 100644
index 0000000..0542a95
--- /dev/null
+++ b/src/administrator/components/com_weblinks/views/weblink/tmpl/modal.php
@@ -0,0 +1,33 @@
+ 'bottom'));
+
+// @deprecated 4.0 the function parameter, the inline js and the buttons are not needed since 3.7.0.
+$function = JFactory::getApplication()->input->getCmd('function', 'jEditWeblink_' . (int) $this->item->id);
+
+// Function to update input title when changed
+JFactory::getDocument()->addScriptDeclaration('
+ function jEditWeblinkModal() {
+ if (window.parent && document.formvalidator.isValid(document.getElementById("item-form"))) {
+ return window.parent.' . $this->escape($function) . '(document.getElementById("jform_title").value);
+ }
+ }
+');
+?>
+
+
+
+
+
diff --git a/src/administrator/components/com_weblinks/views/weblinks/tmpl/modal.php b/src/administrator/components/com_weblinks/views/weblinks/tmpl/modal.php
new file mode 100644
index 0000000..87b71e7
--- /dev/null
+++ b/src/administrator/components/com_weblinks/views/weblinks/tmpl/modal.php
@@ -0,0 +1,163 @@
+isClient('site'))
+{
+ JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN'));
+}
+
+JLoader::register('WeblinksHelperRoute', JPATH_ROOT . '/components/com_weblinks/helpers/route.php');
+
+// Include the component HTML helpers.
+JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
+
+JHtml::_('behavior.core');
+JHtml::_('behavior.polyfill', array('event'), 'lt IE 9');
+JHtml::_('script', 'com_weblinks/admin-weblinks-modal.js', array('version' => 'auto', 'relative' => true));
+JHtml::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom'));
+JHtml::_('formbehavior.chosen', 'select');
+
+// Special case for the search field tooltip.
+$searchFilterDesc = $this->filterForm->getFieldAttribute('search', 'description', null, 'filter');
+JHtml::_('bootstrap.tooltip', '#filter_search', array('title' => JText::_($searchFilterDesc), 'placement' => 'bottom'));
+
+$function = $app->input->getCmd('function', 'jSelectWeblink');
+$editor = $app->input->getCmd('editor', '');
+$listOrder = $this->escape($this->state->get('list.ordering'));
+$listDirn = $this->escape($this->state->get('list.direction'));
+$onclick = $this->escape($function);
+
+if (!empty($editor))
+{
+ // This view is used also in com_menus. Load the xtd script only if the editor is set!
+ JFactory::getDocument()->addScriptOptions('xtd-weblinks', array('editor' => $editor));
+ $onclick = "jSelectWeblink";
+}
+?>
+
diff --git a/src/administrator/components/com_weblinks/weblinks.xml b/src/administrator/components/com_weblinks/weblinks.xml
index 524d131..af18a97 100644
--- a/src/administrator/components/com_weblinks/weblinks.xml
+++ b/src/administrator/components/com_weblinks/weblinks.xml
@@ -33,6 +33,9 @@
+
+ js
+
##FRONTEND_COMPONENT_FILES##
diff --git a/src/administrator/language/en-GB/en-GB.com_weblinks.sys.ini b/src/administrator/language/en-GB/en-GB.com_weblinks.sys.ini
index bbc0da1..10b1fce 100644
--- a/src/administrator/language/en-GB/en-GB.com_weblinks.sys.ini
+++ b/src/administrator/language/en-GB/en-GB.com_weblinks.sys.ini
@@ -22,4 +22,10 @@ COM_WEBLINKS_LINKS="Links"
COM_WEBLINKS_TAGS_WEBLINK="Web Link"
COM_WEBLINKS_TAGS_CATEGORY="Web Link Category"
COM_WEBLINKS_XML_DESCRIPTION="Component for web links management."
-
+; menu item
+COM_WEBLINKS_WEBLINK_VIEW_DEFAULT_DESC="Display a single weblink"
+COM_WEBLINKS_WEBLINK_VIEW_DEFAULT_TITLE="Single Weblink"
+COM_WEBLINKS_FIELD_SELECT_WEBLINK_DESC="Select the desired weblink from the list."
+COM_WEBLINKS_FIELD_SELECT_WEBLINK_LABEL="Select Weblink"
+COM_WEBLINKS_CHANGE_WEBLINK="Select or Change weblink"
+COM_WEBLINKS_SELECT_AN_WEBLINK="Select Weblink"
diff --git a/src/components/com_weblinks/views/weblink/tmpl/default.php b/src/components/com_weblinks/views/weblink/tmpl/default.php
new file mode 100644
index 0000000..0fafd5f
--- /dev/null
+++ b/src/components/com_weblinks/views/weblink/tmpl/default.php
@@ -0,0 +1,38 @@
+item->params;
+
+?>
+
+
+
+
+
+ item->event->afterDisplayTitle; ?>
+
+
+ item->event->beforeDisplayContent; ?>
+
+
+
+
+ item->event->afterDisplayContent; ?>
+
diff --git a/src/components/com_weblinks/views/weblink/tmpl/default.xml b/src/components/com_weblinks/views/weblink/tmpl/default.xml
new file mode 100644
index 0000000..cbb8586
--- /dev/null
+++ b/src/components/com_weblinks/views/weblink/tmpl/default.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/com_weblinks/views/weblink/view.html.php b/src/components/com_weblinks/views/weblink/view.html.php
index ea1d1fd..c43fb0e 100644
--- a/src/components/com_weblinks/views/weblink/view.html.php
+++ b/src/components/com_weblinks/views/weblink/view.html.php
@@ -1,7 +1,7 @@
get('Item');
+ $dispatcher = JEventDispatcher::getInstance();
- if ($this->getLayout() == 'edit')
- {
- $this->_displayEdit($tpl);
+ $this->item = $this->get('Item');
+ $this->state = $this->get('State');
+ $this->params = $this->state->get('params');
- return;
- }
+ // Create a shortcut for $item.
+ $item = $this->item;
- if ($item->url)
- {
- // Redirects to url if matching id found
- JFactory::getApplication()->redirect($item->url);
- }
- else
- {
- // @TODO create proper error handling
- JFactory::getApplication()->redirect(JRoute::_('index.php'), JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 'notice');
- }
+ $offset = $this->state->get('list.offset');
+
+ $dispatcher->trigger('onWeblinksPrepare', array ('com_weblinks.weblink', &$item, &$item->params, $offset));
+
+ $item->event = new stdClass;
+
+ $results = $dispatcher->trigger('onWeblinksAfterTitle', array('com_weblinks.weblink', &$item, &$item->params, $offset));
+ $item->event->afterDisplayTitle = trim(implode("\n", $results));
+
+ $results = $dispatcher->trigger('onWeblinksBeforeDisplay', array('com_weblinks.weblink', &$item, &$item->params, $offset));
+ $item->event->beforeDisplayContent = trim(implode("\n", $results));
+
+ $results = $dispatcher->trigger('onWeblinksAfterDisplay', array('com_weblinks.weblink', &$item, &$item->params, $offset));
+ $item->event->afterDisplayContent = trim(implode("\n", $results));
+
+ parent::display($tpl);
}
}
diff --git a/src/media/js/admin-weblinks-modal.js b/src/media/js/admin-weblinks-modal.js
new file mode 100644
index 0000000..76ce4ca
--- /dev/null
+++ b/src/media/js/admin-weblinks-modal.js
@@ -0,0 +1,61 @@
+/**
+ * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+(function() {
+ "use strict";
+ /**
+ * Javascript to insert the link
+ * View element calls jSelectWeblink when an weblink is clicked
+ * jSelectWeblink creates the link tag, sends it to the editor,
+ * and closes the select frame.
+ **/
+ window.jSelectWeblink = function (id, title, catid, object, link, lang) {
+ var hreflang = '', editor, tag;
+
+ if (!Joomla.getOptions('xtd-weblinks')) {
+ // Something went wrong!
+ window.parent.jModalClose();
+ return false;
+ }
+
+ editor = Joomla.getOptions('xtd-weblinks').editor;
+
+ if (lang !== '')
+ {
+ hreflang = ' hreflang="' + lang + '"';
+ }
+
+ tag = '' + title + '';
+
+ /** Use the API, if editor supports it **/
+ if (window.Joomla && window.Joomla.editors && Joomla.editors.instances && Joomla.editors.instances.hasOwnProperty(editor)) {
+ Joomla.editors.instances[editor].replaceSelection(tag)
+ } else {
+ window.parent.jInsertEditorText(tag, editor);
+ }
+
+ window.parent.jModalClose();
+ };
+
+ document.addEventListener('DOMContentLoaded', function(){
+ // Get the elements
+ var elements = document.querySelectorAll('.select-link');
+
+ for(var i = 0, l = elements.length; l>i; i++) {
+ // Listen for click event
+ elements[i].addEventListener('click', function (event) {
+ event.preventDefault();
+ var functionName = event.target.getAttribute('data-function');
+
+ if (functionName === 'jSelectWeblink') {
+ // Used in xtd_contacts
+ window[functionName](event.target.getAttribute('data-id'), event.target.getAttribute('data-title'), event.target.getAttribute('data-cat-id'), null, event.target.getAttribute('data-uri'), event.target.getAttribute('data-language'));
+ } else {
+ // Used in com_menus
+ window.parent[functionName](event.target.getAttribute('data-id'), event.target.getAttribute('data-title'), event.target.getAttribute('data-cat-id'), null, event.target.getAttribute('data-uri'), event.target.getAttribute('data-language'));
+ }
+ })
+ }
+ });
+})();