Habari\FormControlTree::pre_out PHP Method

pre_out() public method

Return the HTML/script required for this control. Do it only once.
public pre_out ( ) : string
return string The HTML/javascript required for this control.
    public function pre_out()
    {
        $out = '';
        if (!FormControlTree::$outpre) {
            FormControlTree::$outpre = true;
            $out = <<<CUSTOM_TREE_JS
\t\t\t\t<script type="text/javascript">
\$(function(){
\t\$('ol.tree').nestedSortable({
\t\tdisableNesting: 'no-nest',
\t\tforcePlaceholderSize: true,
\t\thandle: '.handle',
\t\titems: 'li.treeitem',
\t\topacity: .6,
\t\tplaceholder: 'placeholder',
\t\ttabSize: 25,
\t\ttolerance: 'pointer',
\t\ttoleranceElement: '> div'
\t});

\t\$('.tree_control').closest('form').submit(function(){
\t\tvar tree_input = \$('.tree_control input[type=hidden]', this);
\t\ttree_input.each(function(){
\t\t\tvar tree_input = \$(this);
\t\t\tvar data = tree_input.siblings().nestedSortable('toArray', {startDepthCount: 1});
\t\t\tvar comma = '';
\t\t\tvar v = '';
\t\t\tfor(var i in data) {
\t\t\t\tif(data[i].item_id != 'root') {
\t\t\t\t\tv += comma + '{"id":"' + parseInt(data[i].item_id) + '","left":"' + (parseInt(data[i].left)-1) + '","right":"' + (parseInt(data[i].right)-1) + '"}';
\t\t\t\t\tcomma = ',';
\t\t\t\t}
\t\t\t}
\t\t\tv = '[' + v + ']';
\t\t\ttree_input.val(v);
\t\t});
\t});
});
\t\t\t\t</script>
CUSTOM_TREE_JS;
        }
        return $this->controls_js($out);
    }