1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8//this script may only be included - so its better to die if called directly. 9if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) !== false) { 10 header('location: index.php'); 11 exit; 12} 13 14/** 15 * Function to load jQuery code to insert an iconset icon into an element 16 * Useful for when there's no other way to make 3rd party code consistent with the Tiki iconsets 17 * 18 * type - determines the js string that will be returned 19 * iconname - set the icon to override the default 20 * return - return the js code rather than add to the header 21 * @param $params 22 * @param $smarty 23 * @return string 24 * @throws Exception 25 */ 26function smarty_function_js_insert_icon($params, $smarty) 27{ 28 if (! empty($params['type'])) { 29 //set icon 30 $iconmap = [ 31 'jscalendar' => 'calendar' 32 ]; 33 $iconname = ! empty($params['iconname']) ? $params['iconname'] : $iconmap[$params['type']]; 34 $smarty->loadPlugin('smarty_function_icon'); 35 $icon = smarty_function_icon(['name' => $iconname], $smarty); 36 //set js 37 switch ($params['type']) { 38 case 'jscalendar': 39 $js = "$('div.jscal > button.ui-datepicker-trigger').empty().append('$icon').addClass('btn btn-sm btn-link').css({'padding' : '0px', 'font-size': '16px'});"; 40 break; 41 } 42 //load js 43 if (! empty($js)) { 44 if (isset($params['return']) && $params['return'] === 'y') { 45 return $js; 46 } else { 47 $headerlib = TikiLib::lib('header'); 48 $headerlib->add_jq_onready($js); 49 } 50 } 51 } 52} 53