Jump to a specific location inside nested html - html

I have a parent search.html and inside that I am including another html search-form.html and attribute.html through ng-include.
Now the inner html search-form.html has another inner html searchresults.html which has a anchor tag onclick of that I want to point to attribute.html which is included in the parent search.html.
My search.html code :
<div class="panel panel-primary">
<!-- Search FORM + RESULTS Panels -->
<div ng-include="'modules/search/tp/search-form.html'">
</div>
<div ng-show="isAttributeResultExist()">
<!--Include ATTRIBUTES PANEL -->
<div ng-include="'modules/search/attribute.html'">
</div>
</div>
search-form.html code:
<!--Search RESULTS Tab: Individual-->
<div ng-show="isPersonSearch()">
<div ng-include="'modules/search/searchresults.html'">
</div>
</div>
searchresults.html anchor tag :
<a href="#" ng-click="buildDetails(searchResult.person.Id);">
<i class="fa fa-fw fa-search fa-lg"></i>
</a>
I want to click the anchor tag inside this searchresults.html and jump to start of attribute.html inside search.html.
How to do that?

Inside your search.html, add an id to the div that loads your attributes.
<div id="jumpHere" ng-include="'modules/search/attribute.html'">
Normally you could just add that id to an anchor tag on your page and you would jump to that section of the page.
Jump to section
However, it appears that you are using Angular and would need to work in the location into your buildDetails() method. You want to use the $location service.
$scope.buildDetails = function() {
//other functionality here
$location.path('jumpHere');
};

Related

Angular structural directive with CSS selector

I am creating a custom dropdown menu.
The menu contains some items and should remain open when a user clicks on any of these items.
To check if the user clicks inside the dropdown menu I check via window.onclick if event.target.matches('dropdown-content *'). See the snippet below for context.
<div id="myDropdown" class="dropdown-content">
<div class="dropdown-grid">
<div class="add-offset">
<div class="dd-header">
<div (click)="setupNewCol()"><i class="fas fa-plus plus-sign"></i></div>
</div>
</div>
</div>
</div>
This works, but when I add *ngIf to the div with the function call the CSS selector 'dropdown-content *' doesn't seem to work anymore.
This is the HTML with the *ngIf
<div id="myDropdown" class="dropdown-content">
<div class="dropdown-grid">
<div class="add-offset">
<div class="dd-header">
<div *ngIf="!settingNewOffset; else offsetSelection" (click)="setupNewCol()"><i class="fas fa-plus plus-sign"></i></div>
<ng-template #offsetSelection>
<div (click)="addCol()">
CLICK ME
</div>
</ng-template>
</div>
</div>
</div>
</div>
With the introduction of the *ngIf in combination with ng-template the CSS selector doesn't recognize the clicks to be part of '.dropdown-content *' anymore. Why is this and what is a solution to this problem?
Why it won't register the click on target 'dropdown-content' is probably because now the clicked target is a div, that does not have 'dropdown-content'. Probably the target parent has that class, but not the target.
To check if a user clicks on any of the items. You already have methods addCol() or setupNewCol(). If this method runs then user has clicked some of the item where the method was attached. You could also just attach another method to the item e.g (click)="addCol(); onItemClick($event)"
onItemClick(event:any) {
console.log(event)
}
I don't see where the menu closing part is but using onItemClick you could just cancel that or try to cancel the event from propagating at all.
(click)="addCol(); event.stopPropagation()"

how to hide vertical nav on click and display the corresponding content ( Navigation on mobile site with back button)

I have a mobile website, which is built as a single page application. I'm using angular to create a vertical menu, I want to hide the menu on menu item clicked and display its content container with a back button to go back to the menu.
first I have the main component with the menu and content container next to each other
main-component.html
<div class="container">
<div class="col-md-3 col-12 menu-container">
<app-menu-container></app-menu-container>
</div>
<div class="col-md-9 col-12">
<app-content-container></app-content-container>
</div>
</div>
menu.component.html to loop over menu items and display them
<div *ngFor="let menuItem of menu">
<app-menu-item [menuItem]="menuItem"> </app-menu-item>
</div>
menuItem.component that displays every menuItem. on item clicks, a subject will fire to open the corresponding content-container component
in the content-container component, I subscribed to get the item to open the content container
content-container.component.ts
subscribeToOpenContainer() {
this.subscriptionToOpenContainer = this.menuService.openMenuItemContainer.subscribe((menuItem) => {
this.menuItem = menuItem;
}
);
}
content-container.html
<ul>
<li>
<a class="document-type-icon"><i></i></a>
<div class="text-container">
<p class="document-name"></p>
<p class="last-update-date"> Last update date:</p>
<div class="line"></div>
</div>
<div class="action-icons-container">
<a class="delete-and-edit-icon"><i class="fa fa-trash"></i></a>
<a> <i class="fa fa-edit delete-and-edit-icon> </i>
</a>
</div>
</li>
<ul/>
I want the menu that is a single component to hide when a menu item is active and the content container is displayed with a back button to get back to the menu.
current approach
what I want to achieve on mobile screen size
This can be achieved using simple ngIf if you want to hide the sidebar using a click of button. If you want to hide the sidebar on clicking anywhere, you can use HostListener.
#HostListener('click', ['$event'])onClick(event) { });
You can get id of the element clicked using event.target.id. Use if logic to check which item was clicked and open the sidebar if not open already, and if it is open you can hide it by simply adding or remove css to the DOM.

Jade/PUG Insert tag a inside other a

This is my PUG/JADE code is below
a(href="#card")
div.tile
h1 open card
#card
a(href="#") click to close
But this code doesn't print correctly, the .tile has print out of <a>,
you can view the printed code below.
<div class="tile">
<a href="#card">
<h1>Open card</h1>
</a>
<div id="card">
click to close
</div>
</div>
i need this code so:
<a href="#card">
<div class="tile">
<h1>Open card</h1>
<div id="card">
click to close
</div>
</div>
</a>
Links within links is invalid HTML. Jade is presumably using a HTML builder internally which will correct the syntax. You should see the same result if you hand write the HTML you think you want and view it in a browser - it will move the second a tag outside the first.
I had a similar use case, where I needed a DOM Element with a click handler inside a div which was inside an anchor tag.
I used a span for the interior clickable element, and used the JavaScript function addEventListener. Remember to use event.preventDefault() on the interior clickable element, so you do not trigger the href on the enclosing anchor tag.

Angular fire ng-click on row but not on href

I've made a page with bootstrap, and i would like to have an action when the user clicks on the row. This is easy, I put ng-click on the div that is the row.
However, inside the row elements I've a link, and I would like to avoid the firing of the ng-click when the user clicks on the link (in that case it should open the url of the link)
this is a picture of the row. Bascially if the use clicks anywhere except the link simbol it should filre the ng-click, if it clicks on the link simbol it should open the url.
is this possible?
PS: I tried to put ng-click on each item except the href element, but the href element is inside a column within other things, and if I don't put the ng-click on the column it will not fire if the use clicks on the empty space of the column.
<div class="col-sm-8" >
</i> |
<span class="h5 small">{{club.description}}</span>
</div>
$event.stopPropagation() on ng-click of anchor tag to bubble up event.
Markup
<div class="col-sm-8" ng-click="myMethod()">
<i class="fa fa-link"></i> |
</div>
You have to stop the event propagation from anchor to its parent div which has the click event handler.
<div class="col-sm-8" ng-click="onRowClick()">
</i> |
<span class="h5 small">{{club.description}}</span>
</div>
JS
$scope.onLinkClick = function (e) {
e.stopPropagation();
}
Try adding ng-click="$event.stopPropagation();" to your anchor tag
<i class="fa fa-link"></i>

jQuery Mobile - Persistent Toolbars with backbutton

EDIT
Fiddle of that problem: https://jsfiddle.net/9k449qs2/ - debug the fiddle and try to select the header with your picker. You will not be able to do so, it will select you the whole page every time you click.
I'm just working on a project which has a persistent header and footer. Just the content changes by clicking through the application. Now i wanted to add a backbutton into the header which i did with:
<header id="headerMain" data-position="fixed" data-role="header">
<a href="#" data-rel="back">
<div class="backButton">GO BACK</div>
</a>
</header>
The rest of my code directly after the header looks like this:
<div data-role="page" id="pageMain">
<div class="content gray">
adfjsöalfjasödf
</div>
</div><!-- pageMain end -->
<footer id="footerMain" data-position="fixed" data-role="footer">
Footer
</footer>
<div data-role="page" id="checkConnection">
<div class="content gray">
<button id="checkConnectionState" class="button" onclick="CTFNetworkState()">Check your Connection</button>
<a href="#checkBattery">
<button id="checkBatteryState" class="button">Check your Battery</button>
</a>
</div>
</div> <!-- checkConnection end -->
<div data-role="page" id="checkBattery">
<div class="content gray">
<p>Just plug your device and you'll get information about your battery state.</p>
</div>
</div> <!-- checkBattery end -->
So all works fine, the transitions and so on. But i can't get the backbutton work. He is not clickable. The headers on each page are not clickable in any form. If i debug that with gapDebug and i click onto the header, GapDebug marks the Pagecontainer and not the header.
So, how can i make the backbutton inside the header clickable on each page?
EDIT
So the header doesn't care what kind of button i place inside it. No matter what button i choose, or what attribute i add to my <a></a> it is not clickable.
So i tried to run GapDebug again, pressing the "Inspect" Button and than clicked on my backbutton, it selects me the code from the page which is wrong.
So i found the solution. The problem was, that not the documentation for persistent toolbars helped me, instead the documentation for external toolbars did it then.
Simply add
$(function(){
$( "[data-role='header'], [data-role='footer']" ).toolbar();
});
inside your <script></script> tag and all works fine. This happens Because these toolbars are not within the page they will not auto initalize. You must call the toolbar plugin yourself.