noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 67/162: Create lib for Tabs


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 67/162: Create lib for Tabs
Date: Sat, 11 Jul 2020 13:23:39 -0400 (EDT)

sparkyx pushed a commit to annotated tag E-4
in repository noalyss.

commit 9b6bf6c1f9a46e82d515c18c43d8c7bd68010863
Author: Dany De Bontridder <danydb@noalyss.eu>
AuthorDate: Sun Jul 1 16:43:09 2018 +0200

    Create lib for Tabs
---
 html/style-classic.css                |   1 +
 html/style-classic7.css               |   2 +-
 html/style-light.css                  |   2 +-
 include/lib/html_tab.class.php        | 105 ++++++++++++++++++++++++++
 include/lib/output_html_tab.class.php | 135 ++++++++++++++++++++++++++++++++++
 scenario/html_tab.test.php            |  75 +++++++++++++++++++
 6 files changed, 318 insertions(+), 2 deletions(-)

diff --git a/html/style-classic.css b/html/style-classic.css
index d26b251..359afcf 100644
--- a/html/style-classic.css
+++ b/html/style-classic.css
@@ -1759,6 +1759,7 @@ ul.tabs a {
     color:inherit;
     display:inline;
     white-space: nowrap;
+    cursor:pointer;
     
 }
 ul.tabs a:hover {
diff --git a/html/style-classic7.css b/html/style-classic7.css
index 4ff1af0..80fbd12 100644
--- a/html/style-classic7.css
+++ b/html/style-classic7.css
@@ -1627,7 +1627,7 @@ ul.tabs a {
     white-space: nowrap;
     width: 100%;
     height: 100%;
-    
+    cursor :pointer;    
 }
 ul.tabs a:hover {
     text-decoration: none;
diff --git a/html/style-light.css b/html/style-light.css
index 13e1468..a7b2e40 100644
--- a/html/style-light.css
+++ b/html/style-light.css
@@ -1713,7 +1713,7 @@ ul.tabs a {
     color:inherit;
     display:inline;
     white-space: nowrap;
-    
+    cursor: pointer;
 }
 ul.tabs a:hover {
     text-decoration: none;
diff --git a/include/lib/html_tab.class.php b/include/lib/html_tab.class.php
new file mode 100644
index 0000000..ee3304a
--- /dev/null
+++ b/include/lib/html_tab.class.php
@@ -0,0 +1,105 @@
+<?php
+
+/*
+ * Copyright (C) 2018 Dany De Bontridder <dany@alchimerys.be>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+ * @file 
+ * @brief Tab element
+ *
+ */
+
+/**
+ * Tab Element
+ * @see Output_Html_Tab
+ */
+class Html_Tab
+{
+    private $id; //<! DOM ID of the tabs (used for the tab and the DIV)
+    private $title; //!< Title of the tab
+    private $content ; //!< static content of the tab
+    private $mode ; //!< possible values are static if the content is static, 
ajax for calling an ajax, link for a html link, default static
+    private $link; //!<  the javascript or an html link, depending of the $mode
+    
+    /**
+     *@example html_tab.test.php
+     */
+    function __construct($p_id,$p_title)
+    {
+        $this->id=$p_id;
+        $this->title=$p_title;
+        $this->mode='static';
+    }
+    public function get_id()
+    {
+        return $this->id;
+    }
+
+    public function get_title()
+    {
+        return $this->title;
+    }
+
+    public function get_content()
+    {
+        return $this->content;
+    }
+
+    public function set_id($id)
+    {
+        $this->id=$id;
+        return $this;
+    }
+
+    public function set_title($title)
+    {
+        $this->title=$title;
+        return $this;
+    }
+
+    public function set_content($content)
+    {
+        $this->content=$content;
+        return $this;
+    }
+    public function get_link()
+    {
+        return $this->link;
+    }
+
+    public function set_link($link)
+    {
+        $this->link=$link;
+        return $this;
+    }
+
+    public function get_mode()
+    {
+        return $this->mode;
+    }
+
+    public function set_mode($mode)
+    {
+        if ( $mode != 'static' && $mode != 'ajax' && $mode != 'link') {
+            throw new Exception(_("Mode invalide"));
+        }
+        $this->mode=$mode;
+        return $this;
+    }
+    
+}
diff --git a/include/lib/output_html_tab.class.php 
b/include/lib/output_html_tab.class.php
new file mode 100644
index 0000000..943faa4
--- /dev/null
+++ b/include/lib/output_html_tab.class.php
@@ -0,0 +1,135 @@
+<?php
+
+
+/*
+ * Copyright (C) 2018 Dany De Bontridder <dany@alchimerys.be>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+require_once NOALYSS_INCLUDE.'/lib/html_tab.class.php';
+
+/**
+ * @file 
+ * @brief Display the tabs 
+ * 
+ */
+
+/**
+ * @brief Display the tabs 
+ * @see Html_Tab
+ * 
+ */
+
+class Output_Html_Tab
+{
+
+    private $a_tabs; //!< array of html tabs
+
+    /**
+     *@example html_tab.test.php
+     */
+    function __construct()
+    {
+        $this->a_tabs=[];
+    }
+
+    /**
+     * Add Html_Tab 
+     * @param Html_Tab $p_html_tab
+     */
+    function add(Html_Tab $p_html_tab)
+    {
+        $this->a_tabs[]=clone $p_html_tab;
+    }
+    
+    /**
+     * Build the javascript to change the class name of the selected tab, hide 
other div and show the selected one
+     * @param string $p_not_hidden id of the showed tab
+     * @return javascript string
+     */
+    function build_js ($p_not_hidden)
+    {
+        $r="";
+        $nb=count($this->a_tabs);
+        for ($i =0 ; $i < $nb;$i++)
+        {
+            if ( $this->a_tabs[$i]->get_id() != $p_not_hidden) {
+                $r .= sprintf("$('div%s').hide();",$this->a_tabs[$i]->get_id() 
);
+                $r .= 
sprintf("$('tab%s').className='tabs';",$this->a_tabs[$i]->get_id() );
+            } else {
+                $r .= sprintf("$('div%s').show();",$p_not_hidden );
+                $r .= 
sprintf("$('tab%s').className='tabs_selected';",$p_not_hidden );
+                
+            }
+        }
+        return $r;
+    }
+    /**
+     * print the html + javascript code of the tabs and the div
+     * 
+     */
+    function output()
+    {
+        $nb=count($this->a_tabs);
+        if ($nb==0)
+        {
+            return;
+        }
+        echo '<ul class="tabs">';
+        for ($i=0; $i<$nb; $i++)
+        {
+            printf ('<li id="tab%s" class="tabs">',
+                    $this->a_tabs[$i]->get_id());
+            switch ($this->a_tabs[$i]->get_mode())
+            {
+                case 'link':
+                    printf ('<a id="%s" href="%s">',
+                            $this->a_tabs[$i]->get_id(),
+                            $this->a_tabs[$i]->get_link());
+                    echo $this->a_tabs[$i]->get_title();
+                    echo '</a>';
+
+                    break;
+                case 'ajax':
+                    printf('<a id="%s" onclick="%s">', 
+                            $this->a_tabs[$i]->get_id(),
+                            $this->a_tabs[$i]->get_link());
+                    echo $this->a_tabs[$i]->get_title();
+                    echo '</a>';
+                    break;
+                case 'static':
+                    // show one , hide other
+                    $script=$this->build_js($this->a_tabs[$i]->get_id());
+                    printf('<a onclick="%s">', $script);
+                    echo $this->a_tabs[$i]->get_title();
+                    echo '</a>';
+                    
+                    break;
+                default:
+                    break;
+            }
+            echo '</li>';
+        }
+        echo '</ul>';
+        for ($i=0;$i<$nb;$i++)
+        {
+            printf('<div id="div%s" 
style="display:none;clear:both">',$this->a_tabs[$i]->get_id());
+            echo $this->a_tabs[$i]->get_content();
+            echo '</div>';
+        }
+    }
+
+}
diff --git a/scenario/html_tab.test.php b/scenario/html_tab.test.php
new file mode 100644
index 0000000..13de211
--- /dev/null
+++ b/scenario/html_tab.test.php
@@ -0,0 +1,75 @@
+<?php
+//@description:Test of Html_Tab and Output_Html_Tab
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2018) Author Dany De Bontridder <dany@alchimerys.be>
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+
+/**
+ * @file
+ * @brief  Test of Html_Tab and Output_Html_Tab
+ */
+require_once NOALYSS_INCLUDE.'/lib/html_tab.class.php';
+require_once NOALYSS_INCLUDE.'/lib/output_html_tab.class.php';
+
+$tab = new Html_Tab('tab1',_("Titre 1"));
+$tab->set_mode('link');
+$tab->set_link(http_build_query([ "a"=>1,"b"=>2]));
+$tab2 = new Html_Tab('tab2',_("Titre 2"));
+$tab2->set_content(""
+        . "<br> Très longue chaine HTML pour 2"
+        . "<br> Très longue chaine HTML pour 2"
+        . "<br> Très longue chaine HTML pour 2"
+        . "<br> Très longue chaine HTML pour 2"
+        . "<br> Très longue chaine HTML pour 2"
+        . "<br> Très longue chaine HTML pour 2"
+        . "<br> Très longue chaine HTML pour 2"
+        . "<br> Très longue chaine HTML pour 2"
+        . "<br> Très longue chaine HTML pour 2"
+        . "<br> Très longue chaine HTML pour 2"
+        . "<br> Très longue chaine HTML pour 2"
+        . "<br> Très longue chaine HTML pour 2");
+$tab3 = new Html_Tab('tab3',_("Titre 3"));
+$tab3->set_content('<p >'
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        . "<br> Très longue chaine HTML pour 3"
+        .'</p>'
+        );
+
+$output = new Output_Html_Tab; 
+
+$output->add($tab);
+$output->add($tab2);
+$output->add($tab3);
+
+
+$output->output();



reply via email to

[Prev in Thread] Current Thread [Next in Thread]