Index: branches/unlabeled/unlabeled-1.11.10/kernel/admin_templates/incs/script.js =================================================================== diff -u -N -r4039 -r4066 --- branches/unlabeled/unlabeled-1.11.10/kernel/admin_templates/incs/script.js (.../script.js) (revision 4039) +++ branches/unlabeled/unlabeled-1.11.10/kernel/admin_templates/incs/script.js (.../script.js) (revision 4066) @@ -10,8 +10,64 @@ var $env = ''; var submitted = false; var $init_made = true; // in case of double inclusion of script.js :) + + // hook processing + const hBEFORE = 1; + const hAFTER = 2; + var $hooks = new Array(); } +function getArrayValue() +{ + var $value = arguments[0]; + var $current_key = 0; + $i = 1; + while ($i < arguments.length) { + $current_key = arguments[$i]; + if (isset($value[$current_key])) { + $value = $value[$current_key]; + } + else { + return false; + } + $i++; + } + return $value; +} + +function setArrayValue() +{ + // first argument - array, other arguments - keys (arrays too), last argument - value + var $array = arguments[0]; + var $current_key = 0; + $i = 1; + while ($i < arguments.length - 1) { + $current_key = arguments[$i]; + if (!isset($array[$current_key])) { + $array[$current_key] = new Array(); + } + $array = $array[$current_key]; + $i++; + } + $array[$array.length] = arguments[arguments.length - 1]; +} + +function processHooks($function_name, $hook_type) +{ + var $i = 0; + var $local_hooks = getArrayValue($hooks, $function_name, $hook_type); + + while($i < $local_hooks.length) { + $local_hooks[$i]($function_name); + $i++; + } +} + +function registerHook($function_name, $hook_type, $hook_body) +{ + setArrayValue($hooks, $function_name, $hook_type, $hook_body); +} + function resort_grid(prefix_special,field,form_action) { set_hidden_field(prefix_special+'_Sort1', field); @@ -254,7 +310,7 @@ if(!isset($width)) $width=750; if(!isset($height)) $height=400; if(!isset($event)) $event=''; - + processHooks('openSelector', hBEFORE); cur_opener = get_hidden_field('m_opener'); set_hidden_field('m_opener','p'); @@ -264,6 +320,7 @@ var old_action = document.kernel_form.action; document.kernel_form.action = $url; submit_event($prefix,$event,$t); + processHooks('openSelector', hAFTER); document.kernel_form.action = old_action; set_hidden_field('m_opener',cur_opener); }