how to keep toggle state after page refresh - html

I have expandable menu, you can see the code in this link..
my question is how can I keep toggle state after page refresh.
Thanks for your helps.

How about save it in a session variable?
Session("TopMenuState") = XYZ
where XYZ is your state info
Update
Mmmmm I will try and explain best I can with my limited amount of Javascript skills.
To check if local storage/session storage is available as follows
if(typeof(Storage)!=="undefined")
{
// localStorage and sessionStorage supported
}
else
{
// localStorage and sessionStorage NOT supported
}
Once your satisfied that local storage will be available then you can continue with coding the actual scripts, otherwise, one would assume that maybe the code will not work?
Further more when the user clicks on a link in your sliding menu, the idea is to persist the NAME of the menu he/she clicked on, and when the page loads, or when you render your menu's you can check the session/local storage to see what menu item (if any) was clicked on
So in the links in sliding menu you may end up with something along the lines of :
<div class="menuContent">
<a class="slider"><img alt="" id="bot" src="images/arrow_bottom.png"></a>
<ul id="nav">
<li><img src="images/t1.png" /> Home</li>
<li>
<ul id="1">
<li><img src="images/empty.gif" />Link 1</li>
<li><img src="images/empty.gif" />Link 2</li>
<li><img src="images/empty.gif" />Link 2</li>
<li><img src="images/empty.gif" />Link 3</li>
<li><img src="images/empty.gif" />Link 4</li>
</ul>
// THIS LINE MODIFIED
<span onclick="ProcessMenuLink('MenuItem1')" class="sub" tabindex="1"><img src="images/t2.png" />HTML/CSS</span>
</li>
<li>
<ul id="2">
<li><img src="images/empty.gif" />Link 6</li>
<li><img src="images/empty.gif" />Link 7</li>
<li><img src="images/empty.gif" />Link 8</li>
<li><img src="images/empty.gif" />Link 9</li>
<li><img src="images/empty.gif" />Link 10</li>
</ul>
// THIS LINE MODIFIED
<span onclick="ProcessMenuLink('MenuItem2')" class="sub" tabindex="1"><img src="images/t3.png" />jQuery/JS</span>
</li>
<li><img src="images/t2.png" />PHP</li>
</ul>
</div>
PLEASE NOTE: My javascript skills arelimited so you may need to check this code!
It is most likely missing a semicolon here and there.
And then in the subroutine or function you may have something along the lines of:
Void ProcessMenuLink(MenuItemId){
if(typeof(Storage)!=="undefined")
{
// localStorage and sessionStorage supported
//If the menuitem selected is valid
if (MenuItemId == 1) Then
{
//Save the selected menu ID/Name
localStorage.MySelectedMenuItem=MenuItemId;
// OPTIONAL - Call the toggle subroutine to toggle the selected menuitems
// Code to call sliding routine if its not executed via the CLASS parameter
}
}
else
{
// localStorage and sessionStorage NOT supported
}
}
Now at this point you have saved the SELECTED MENU ITEM in the local storage and I assume the page reloads.
So when your page loads you will want to call the subroutine which performs the menu animation or SLIDING and pass it relevant value based upon the locally-stored selected menuitem value.
Sub Window.OnLoad
//load locally stored data
if (localStorage.MySelectedMenuItem == 'MenuItem1')
{
// menu item with id 'MenuItem1' was selected so call the sliding routine
// using whatever value you used to identify your first sliding menu
}
else
{
if (localStorage.MySelectedMenuItem == 'MenuItem2')
{
// menu item with id 'MenuItem2' was selected so call the sliding routine
// using whatever value you used to identify your first sliding menu
}
else
{
// nothing was selected or an invalid selection was specified
// show the menu items in their DEFAULT state
}
}
End Sub
I'm not completely sure how to call/execute the function as its all in Javascript
Well I can only apologise for my weak Java skills coming from a VB background,
but i hope you got the gist of my meaning and that it helps you address your issue.

Related

Regex open Li tag inside ul tag

Hi I am try to amke regexp which extract only li tags in ul tags (no ol)
Text:
<ul><li>some text</li></ul>
<ol><li>some text</li></lo>
Extracted
<ul>**<li>**some text</li></ul>
<ol><li>some text</li></lo>
Could you help me ?
Solution 1
Regex solution
/(?<=<ul>\s*(?:<li>.*?<\/li>\s*)*)<li>.*?<\/li>/gi
Demo
If you work in a team and someone else may read your code I advise you to use Solution 2. It's more simple and easy to understand by code reading.
Solution 2
Do it in 2 steps:
Delete all <ol>...</ol> nodes;
Take all <li>...</li> nodes.
*I assume your html is valid and you have no <li> outside <ul> or <ol>.
Code example in JavaScript:
let html = `
<ul>
<li>take this node 1</li>
<li>take this node 2</li>
</ul>
<ol>
<li>exclude this node</li>
<li>exclude this node</li>
</ol>
<ul>
<li>take this node 3</li>
<li>take this node 4</li>
</ul>
<ol>
<li>exclude this node</li>
<li>exclude this node</li>
</ol>
`;
let htmlWithoutOl = html.replace(/<ol>.*?<\/ol>/gis, '');
let matches = htmlWithoutOl.matchAll(/<li>.*?<\/li>/gis);
for (const match of matches) {
console.log(match[0]);
}

Build HTML popup with packages [duplicate]

This question already has answers here:
Property does not exist on type 'DetailedHTMLProps, HTMLDivElement>' with React 16
(4 answers)
Closed 3 years ago.
I have to build an html popup inside a react component but I get errors
from this code
<div>
<button class="toggle">Button</button>
<div id="link-box">
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
</ul>
</div>
</div>
error:
Type '{ children: string; class: string; }' is not assignable to type 'DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>'.
Property 'class' does not exist on type 'DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>'.
I'd like to accomplish this without a react npm package for dropdown menus.
If I have to do some really rudimentary html with later css styling that okay. But I need some insight into what are the issues I'm facing how to best proceed.
More of File code:
export class Header extends React.Component<IHeaderProps, IHeaderState> {
public handleChange() {
console.log('handling');
}
public render() {
return (
<div>
<button class="toggle">Button</button>
<div id="link-box">
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
</ul>
</div>
</div>
);
}
}
About the error you are facing, if you could provide the typescript code of the component then we could look for a solution.
By the way since you are using React you could set a Modal to popup when certain buttons are clicked.
These are some Modal examples .
And this is a Modal tutorial that doesn't require to install any npm package, which may be what you are looking for.

Ng-click not working dragula drag-drop elements

Using dragula plugin (Angular 1) link
ng-click not working moved (drag and drop to another ul) on li element
<ul dragula='"second-bag"'>
<li ng-click="fun()">Item One </li>
<li ng-click="fun()">Item Two</li>
<li ng-click="fun()">Item Three</li>
<li ng-click="fun()">Item Four</li>
</ul>
<ul dragula='"second-bag"'>
<li ng-click="fun()">Item One </li>
<li ng-click="fun()">Item Two</li>
<li ng-click="fun()">Item Three</li>
<li ng-click="fun()">Item Four</li>
</ul>
app.controller('ExampleCtrl', ['$scope', function ($scope) {
$scope.fun = function(){
alert('test');
}
}]);
It is probably the expected behaviour of dragula, becouse in order to drag the element you are actually clicking it.
The important part is why do you want to listen the clicking event of an dragula list element? If the answer is to manipulate that particular element or do another operation, dragula gives you a set of opportunities.
<div dragula='"sixth-bag"'></div>
<div dragula='"sixth-bag"'></div>
app.controller('MuchExampleCtrl', ['$scope', 'dragulaService',
function ($scope, dragulaService) {
dragulaService.options($scope, 'sixth-bag', {
moves: function (el, container, handle) {
return handle.className === 'handle';
}
});
}
]);
In this example, you are changing the className of the "handled" element. Similar to this, you can use this approach for other possible outcomes.
Links:
http://bevacqua.github.io/angular-dragula/
https://github.com/bevacqua/dragula#optionsmoves
Also as an alternative you might want to checkout the service ngDraggable for more "Angular1 style" syntax.
ngDraggable: https://github.com/fatlinesofcode/ngDraggable

Thymeleaf recursion not working

I'm trying to create a recursive list using Thymeleaf. I'm using a simple Java object to model a node which has has two fields, a description and then an array list of child nodes. I'm using the following HTML/Thymeleaf to process the structure but it isn't recursively iterating through to the next level down.
My Java code looks as follows:
public class Node {
public String description;
public ArrayList<Node> children;
}
My Thymeleaf/HTML code is as follows:
<html>
...
<body>
<div th:fragment="fragment_node" th:remove="tag">
<ul th:if="${not #lists.isEmpty(node.children)}" >
<li th:each="child : ${node.children}"
th:text="${child.description}"
th:with="node = ${child}"
th:include="this::fragment_node">List Item</li>
</ul>
</div>
</body>
</html>
If my data structure looks as follows:
Main node 1
Child node 1
Child node 2
Main node 2
Child node 3
Child node 4
I'd expect to get:
<ul>
<li>Main Node 1</li>
<li>
<ul>
<li>Child node 1</li>
<li>Child node 2</li>
</ul>
</li>
<li>Main Node 2</li>
<li>
<ul>
<li>Child node 3</li>
<li>Child node 4</li>
</ul>
</li>
</ul>
However, I only get:
<ul>
<li>Main Node 1</li>
<li>Main Node 2</li>
</ul>
Can anyone spot why this may not be working?
The cause of the problem is
You are trying to th:text and trying to add the description to a <li> as well as you are trying to th:include the fragment inside the same tag <li>.
Your th:include is replaced by the th:text as th:text is processed with priority by default.
Direct solution to your source code
.....
<li th:each="child : ${node.children}" th:inline="text" th:with="node = ${child}">
[[${child.description}]]
<ul th:replace="this::fragment_node">List Item</ul>
</li>
.....
Even thought the above will work as you want, personally I find some design issues in your thymeleaf page.
Better solution using fragment parameters
...
<ul th:fragment="fragment_node(node)" th:unless="${#lists.isEmpty(node.children)}" >
<li th:each="child : ${node.children}" th:inline="text">
[[${child.description}]]
<ul th:replace="this::fragment_node(${child})"></ul>
</li>
</ul>
...

Opening jsp pages in an iframe from a drop-down menu

I'm creating an application in jsp & servlet. So I have created a home.jsp page it is a main page of an application and it contains a menu bar . When user clicks on menu item the following page should appear in my iframe and if user clicks on another menu item the selected page should appear in the same iframe.
I need a help.... The following code is creating a menu bar and menu item
<li>Master
<ul>
<li>Customer</li>
<li>Suplier</li>
<li>Item</li>
</ul>
</li>
<li>Transaction
<ul>
<li>Purchase</li>
<li>Sales</li>
</ul>
</li>
<li>Contact</li>
After menu bar I have a iframe in which I want to show a menu item.
I don't know how do i do this. please help me out
You will need to bind a function onclick of your <a> tag. Then using jQuery find the href of the <a> which is clicked, finally assign that href as src of your iframe
HTML
<li>Master
<ul>
<li>Customer</li>
<li>Suplier</li>
<li>Item</li>
</ul>
</li>
<li>Transaction
<ul>
<li>Purchase</li>
<li>Sales</li>
</ul>
</li>
<li>Contact</li>
<br />
<iframe src="" height="300" width="500"></iframe>
jQuery
$(document).ready(function () {
$('a').click(function () {
var target = $(this).attr('href');
$('iframe').attr('src', target);
return false;
});
});
Here's a working DEMO. I just changed the href of first two items as example.