Current Path :
/
home
/
develito
/
httpdocs
/
modules
/
mod_otminitabs
/
elements
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/develito/httpdocs/modules/mod_otminitabs/elements/tabs.php
<?php /** * @package OT Mini Tabs for Joomla! 3.x * @version $Id: tabs.php - May 2014 00:00:00Z OmegaTheme * @author OmegaTheme Extensions (services@omegatheme.com) - http://omegatheme.com * @copyright Copyright(C) 2012 - OmegaTheme Extensions * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL **/ // no direct access // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); jimport('joomla.html.html'); jimport('joomla.form.formfield'); class JFormFieldTabs extends JFormField { protected $type = 'Tabs'; protected function getInput() { // Initialize variables. JFactory::getDocument()->addStyleSheet(JURI::root().'modules/mod_otminitabs/assets/css/mod_minitabs_admin.css'); JHtml::_('behavior.framework'); JHtml::_('behavior.modal'); $html = array(); $class = !empty($this->class) ? ' class="' . $this->class . '"' : ''; $disabled = $this->disabled ? ' disabled' : ''; // Initialize JavaScript field attributes. $onchange = $this->onchange ? ' onchange="' . $this->onchange . '"' : ''; $html[] = ' <div class="tabs">'.$this->getTabsInput().'</div> <div id="tabs-template" class="hidden">'.$this->getTabsInput(true).'</div> <div class="clearfix"></div> <a class="tabAdd btn button btn-success" href="#"><span class="icon-plus"></span> </a> '; JFactory::getDocument()->addScriptDeclaration($this->getScript()); return implode($html); } protected function getTabsInput($is_template = false) { $tabtypes = array( array('value' => 'module', 'text' => JText::_('MOD_OTMINITABS_FIELD_OPTION_MODULE')), array('value' => 'category', 'text' => JText::_('MOD_OTMINITABS_FIELD_OPTION_CATEGORY')), array('value' => 'article', 'text' => JText::_('MOD_OTMINITABS_FIELD_OPTION_ARTICLE')) ); $html = array(); if ($is_template){ $html[] = ' <div class="tab"> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_TITLE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_TITLE_LABEL').'</label> '.$this->getInputText($this->name.'[REPLACE][title]', $this->id.'_REPLACE_title', '').' </div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_USE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_USE_LABEL').'</label> '.$this->getInputSelect($this->name.'[REPLACE][use]', $this->id.'_REPLACE_use', $tabtypes, '').' </div> <div class="clearfix"></div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_MODULE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_MODULE_LABEL').'</label> '.$this->getInputModuleSelect($this->name.'[REPLACE][module]', $this->id.'_REPLACE_module', '').' </div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_CATEGORY_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_CATEGORY_LABEL').'</label> '.$this->getInputCategorySelect($this->name.'[REPLACE][category]', $this->id.'_REPLACE_category', '').' </div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_ARTICLE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_ARTICLE_LABEL').'</label> '.$this->getInputArticleSelect($this->name.'[REPLACE][article]', $this->id.'_REPLACE_article', '').' </div> <div class="clearfix"></div> <a class="tabRemove btn btn-small" href="#"><span class="icon-cancel"></span> </a> </div> <div class="clearfix"></div> '; } else { if (!empty($this->value)){ for ($i = 0; $i < count($this->value); $i++){ if (!empty($this->value[$i]['title'])) $html[] = ' <div class="tab"> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_TITLE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_TITLE_LABEL').'</label> '.$this->getInputText($this->name.'['.$i.'][title]', $this->id .'_'.$i.'_title', $this->value[$i]['title']).' </div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_USE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_USE_LABEL').'</label> '.$this->getInputSelect($this->name.'['.$i.'][use]', $this->id .'_'.$i.'_use', $tabtypes, $this->value[$i]['use']).' </div> <div class="clearfix"></div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_MODULE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_MODULE_LABEL').'</label> '.$this->getInputModuleSelect($this->name.'['.$i.'][module]', $this->id. '_'.$i.'_module', $this->value[$i]['module']).' </div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_CATEGORY_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_CATEGORY_LABEL').'</label> '.$this->getInputCategorySelect($this->name.'['.$i.'][category]', $this->id. '_'.$i.'_category', $this->value[$i]['category']).' </div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_ARTICLE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_ARTICLE_LABEL').'</label> '.$this->getInputArticleSelect($this->name.'['.$i.'][article]', $this->id. '_'.$i.'_article', $this->value[$i]['article']).' </div> <div class="clearfix"></div> <a class="tabRemove btn btn-small" href="#"><span class="icon-cancel"></span> </a> </div> <div class="clearfix"></div> '; } } else { $html[] = ' <div class="tab"> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_TITLE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_TITLE_LABEL').'</label> '.$this->getInputText($this->name.'[0][title]', $this->id.'_0_title', '').' </div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_USE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_USE_LABEL').'</label> '.$this->getInputSelect($this->name.'[0][use]', $this->id.'_0_use', $tabtypes, '').' </div> <div class="clearfix"></div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_MODULE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_MODULE_LABEL').'</label> '.$this->getInputModuleSelect($this->name.'[0][module]', $this->id.'_0_module', '').' </div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_CATEGORY_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_CATEGORY_LABEL').'</label> '.$this->getInputCategorySelect($this->name.'[0][category]', $this->id.'_0_category', '').' </div> <div class="col"> <label class="hasTooltip" title="'.JHtml::tooltipText('MOD_OTMINITABS_FIELD_ARTICLE_DESC').'">'.JText::_('MOD_OTMINITABS_FIELD_ARTICLE_LABEL').'</label> '.$this->getInputArticleSelect($this->name.'[0][article]', $this->id.'_0_article', '').' </div> <div class="clearfix"></div> <a class="tabRemove btn btn-small" href="#"><span class="icon-cancel"></span> </a> </div> <div class="clearfix"></div> '; } } return implode($html); } protected function getInputSelect($name, $id, $values = array(), $value = '') { if (empty($values)) return ''; foreach($values as $v){ $options[] = JHtml::_('select.option', $v['value'], $v['text']); } return JHtml::_('select.genericlist', $options, $name, null, 'value', 'text', $value, $id); } protected function getInputText($name, $id, $value = '') { return '<input type="text" value="'.htmlspecialchars($value, ENT_COMPAT, 'UTF-8').'" id="'.$id.'" name="'.$name.'" class="" aria-required="true" />'; } protected function getInputTextare($name, $id, $value = '') { return '<textarea id="'.$id.'" name="'.$name.'" class="">'.htmlspecialchars($value, ENT_COMPAT, 'UTF-8').'</textarea>'; } protected function getInputMedia($name, $id, $value = '') { $html = array(); $html[] = '<div class="input-prepend input-append">'; // The Preview. $showPreview = true; $showAsTooltip = true; $options = array( 'onShow' => 'jMediaRefreshPreviewTip', ); JHtml::_('behavior.tooltip', '.hasTipPreview', $options); if ($showPreview) { if ($value && file_exists(JPATH_ROOT . '/' . $value)) { $src = JUri::root() . $value; } else { $src = ''; } $width = 300; $height = 200; $style = ''; $style .= ($width > 0) ? 'max-width:' . $width . 'px;' : ''; $style .= ($height > 0) ? 'max-height:' . $height . 'px;' : ''; $imgattr = array( 'id' => $id . '_preview', 'class' => 'media-preview', 'style' => $style, ); $img = JHtml::image($src, JText::_('JLIB_FORM_MEDIA_PREVIEW_ALT'), $imgattr); $previewImg = '<div id="' . $id . '_preview_img"' . ($src ? '' : ' style="display:none"') . '>' . $img . '</div>'; $previewImgEmpty = '<div id="' . $id . '_preview_empty"' . ($src ? ' style="display:none"' : '') . '>' . JText::_('JLIB_FORM_MEDIA_PREVIEW_EMPTY') . '</div>'; if ($showAsTooltip) { $html[] = '<div class="media-preview add-on">'; $tooltip = $previewImgEmpty . $previewImg; $options = array( 'title' => JText::_('JLIB_FORM_MEDIA_PREVIEW_SELECTED_IMAGE'), 'text' => '<i class="icon-eye"></i>', 'class' => 'hasTipPreview' ); $html[] = JHtml::tooltip($tooltip, $options); $html[] = '</div>'; } else { $html[] = '<div class="media-preview add-on" style="height:auto">'; $html[] = ' ' . $previewImgEmpty; $html[] = ' ' . $previewImg; $html[] = '</div>'; } } $html[] = ' <input class="" type="text" name="' . $name . '" id="' . $id . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" readonly="readonly" />'; $html[] = '<a class="modal btn" title="' . JText::_('JLIB_FORM_BUTTON_SELECT') . '" href="index.php?option=com_media&view=images&tmpl=component&fieldid=' . $id . '"' . ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">'; $html[] = JText::_('JLIB_FORM_BUTTON_SELECT') . '</a><a class="btn hasTooltip" title="' . JText::_('JLIB_FORM_BUTTON_CLEAR') . '" href="#" onclick="'; $html[] = 'jInsertFieldValue(\'\', \'' . $id . '\');'; $html[] = 'return false;'; $html[] = '">'; $html[] = '<i class="icon-remove"></i></a>'; $html[] = '</div>'; return implode("\n", $html); } protected function getInputArticleSelect($name, $id, $value = '') { $options = array(); $db = JFactory::getDbo(); $db->setQuery( 'SELECT `id` as value, `title` as text FROM #__content;' ); try { $articles = $db->loadObjectList(); } catch (RuntimeException $e) { JError::raiseWarning(500, $e->getMessage()); } if (empty($articles)) $articles = array(); return JHtml::_('select.genericlist', $articles, $name, '', 'value', 'text', $value, $id); } protected function getInputCategorySelect($name, $id, $value = '') { $options = JHtml::_('category.options', 'com_content'); return JHtml::_('select.genericlist', $options, $name, '', 'value', 'text', $value, $id); } protected function getInputModuleSelect($name, $id, $value = '') { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('id, title, module, position'); $query->from('#__modules AS m'); $query->where('m.client_id = 0 AND m.published = 1 AND m.module <> "mod_otminitabs"'); $query->order('position, ordering'); $db->setQuery($query); if (!($modules = $db->loadObjectList())) { JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $db->getErrorMsg())); return array(); } foreach($modules as $module){ $options[] = JHtml::_('select.option', $module->id, $module->title . ' (' . $module->module . ')'); } return JHtml::_('select.genericlist', $options, $name, '', 'value', 'text', $value, $id); } protected function getScript() { $html = array(); $html[] = ' jQuery(document).ready(function($){ reloadValidator = function () { if(document.formvalidator == null) { document.formvalidator = new JFormValidator(jQuery.noConflict()); } //document.formvalidator.initialize(); } resetSelectChosen = function (clone) { // Chosen reset $(clone).find("select").removeClass("chzn-done").show(); // Assign random id //$.each($(clone).find("select"), function (index, c) { // c.id = c.id + "_" + (Math.random() * 10000000).toInt(); //}); $(clone).find(".chzn-container").remove(); $("select").chosen({ disable_search_threshold : 10, allow_single_deselect : true }); }; addTab = function () { var container = $(".tabs")[0]; var count = $(container).children(".tab").length; var clone = $("#tabs-template").find(".tab").clone(true, true); clone.appendTo(container); var contentClone = $(clone).html(); contentClone = contentClone.replace(/REPLACE/ig, count); $(clone).html(contentClone); resetSelectChosen(clone); reloadValidator(); reInitModal(); $(".hasTooltip").tooltip({"html": true,"container": "body"}); } removeTab = function (el) { $(el).remove(); updateTabs(); } updateTabs = function () { $(".tabs .tab").each(function(index, element){ // method 1: replace all of the string //var originalContent = $(element).html(); //originalContent = originalContent.replace(/\[[0-9]\]/g, "[" + index + "]"); //originalContent = originalContent.replace(/\_[0-9]/g, "_" + index); //$(element).html(originalContent); // method 2: replace name and id of element $(element).find("input, select").each(function(id, el){ el.name = el.name.replace(/\[[0-9]\]/, "[" + index + "]"); el.id = el.id.replace(/_[0-9]/, "_" + index); }); resetSelectChosen(element); }); reloadValidator(); } $("#tabs-template").appendTo($("body")); $(document).on( "click", "a.tabAdd", function(e){ e.preventDefault(); addTab(); }); $(document).on( "click", "a.tabRemove", function(e){ e.preventDefault(); removeTab($(this).parent(".tab")); }); }); function reInitModal(){ SqueezeBox.initialize({}); SqueezeBox.assign($$("a.modal"), { parse: "rel" }); } function jInsertFieldValue(value, id) { var old_value = document.id(id).value; if (old_value != value) { var elem = document.id(id); elem.value = value; elem.fireEvent("change"); if (typeof(elem.onchange) === "function") { elem.onchange(); } jMediaRefreshPreview(id); } } function jMediaRefreshPreview(id) { var value = document.id(id).value; var img = document.id(id + "_preview"); if (img) { if (value) { img.src = "' . JUri::root() . '" + value; document.id(id + "_preview_empty").setStyle("display", "none"); document.id(id + "_preview_img").setStyle("display", ""); } else { img.src = "" document.id(id + "_preview_empty").setStyle("display", ""); document.id(id + "_preview_img").setStyle("display", "none"); } } } function jMediaRefreshPreviewTip(tip) { var img = tip.getElement("img.media-preview"); tip.getElement("div.tip").setStyle("max-width", "none"); var id = img.getProperty("id"); id = id.substring(0, id.length - "_preview".length); jMediaRefreshPreview(id); tip.setStyle("display", "block"); } '; return implode("\n", $html); } }