parent

Swift find superview of given class with generics

天大地大妈咪最大 提交于 2019-12-05 01:31:46
I guess I'm struggling with generics. I want to create simple UIView extension to find recursively a superview of class passed in the function param. I want the function to return optional containing obviously either nil, or object visible as instance of provided class. extension UIView { func superviewOfClass<T>(ofClass: T.Type) -> T? { var currentView: UIView? = self while currentView != nil { if currentView is T { break } else { currentView = currentView?.superview } } return currentView as? T } } Any help much appreciated. Swift 3/4 This is a more concise way: extension UIView { func

WPF Get parent window

丶灬走出姿态 提交于 2019-12-04 17:11:47
问题 Hy, In my MainWindow.xaml.cs file I made a getter to get the reference to my listbox. public ListBox LoggerList { get { return Logger; } } Now I want to access the LoggerList from a normal class but I don't work. I tried the following: MainWindow parentWindow = Window.GetWindow(this) as MainWindow; object selectedItem = parentWindow.LoggerList; But this only works in a *xaml.cs file and not in a normal *.cs file. Best regards 回答1: There are a number of ways of accessing Window s in WPF. If

jQuery - How to determine if a parent element exists?

强颜欢笑 提交于 2019-12-04 17:10:58
问题 I'm trying to dynamically and a link to an image, however I cannot correctly determine is the parent link already exists. This is what I have, if (element.parent('a'.length) > 0) { element.parent('a').attr('href', link); } else { element.wrap('<a></a>'); element.parent('a').attr('href', link); } Where element refers to my img element and link refers to the url to use. Every time the code runs, the else clause is performed, regardless of whether or not the img tag is wrapped in an a tag. Can

calling child class method from parent class file in python

假如想象 提交于 2019-12-04 16:19:50
问题 parent.py : class A(object): def methodA(self): print("in methodA") child.py : from parent import A class B(A): def methodb(self): print("am in methodb") Is there anyway to call methodb() in parent.py ? 回答1: Doing this would only make sense if A is an abstract base class, meaning that A is only meant to be used as a base for other classes, not instantiated directly. If that were the case, you would define methodB on class A, but leave it unimplemented: class A(object): def methodA(self):

ExpandableListView - How to set divider only between parent elements

会有一股神秘感。 提交于 2019-12-04 15:55:43
问题 I want to put divider only between parent elements. When i set android:divider="@drawable/divider" android creates divider between parent elements, but creates divider between child elements too. When i add android:childDivider="@color/transparent" android removes the divider between child elements, but the free space between them remains. Why? I have tried to android:dividerHeight="0dp" but nothing happened. At all i want to set divider between parent elements, but i do not want any divider

Parallax effect - calculate child offset to parent on scroll

旧巷老猫 提交于 2019-12-04 15:17:06
I'm trying to create a parallax effect whereby an absolutely positioned child element should move at a rate slower than it's parent on scroll. The child will always be 130% height of the parent but the parent can be any height: HTML: <div class="parallax-window lg"> <div class="parallax-image image-1"></div> <div class="parallax-content">Hello World</div> </div> <div class="parallax-window"> <div class="parallax-image image-2"></div> <div class="parallax-content">Hello World</div> </div> CSS: .parallax-window { min-height: 300px; position: relative; overflow: hidden; } .parallax-window.lg {

jQuery - fade out when clicking on parent element (and not the parents children)?

别来无恙 提交于 2019-12-04 14:32:54
I've got the following code on my page, and what i'm trying to do is that when a user clicks outside the #loginBox, i want the entire #loginOverlay to fadeout. But i can't achieve this effect without having the fadeout triggered by clicking on #loginBox... It's placed on the bottom of the page, and i have a link on the page that triggers the fadein. But the fadeout is a bit struggling now tbh. I tried doing this: $("#loginOverlay").click(function() { ...fadeout... }); but it gives me the same result. So any suggestions? Thanks in advance! <div id="loginOverlay"> <div id="loginBox"> <img class=

How to get the text of parent element using jquery?

六眼飞鱼酱① 提交于 2019-12-04 11:51:45
问题 I have a div which contains a delete hyperlink, onlick of it, I want the text of the div tag. How is it possible in jquery?! <div>sometext<a href="#">delete</a></div> I want to get the text of div tag 'sometext' and if possible the id of that div too. Any ideas?! 回答1: The problem with doing: $(this).parent().text(); is that it will get ALL the text within the div (sometext AND delete). I'm assuming you only want the text in the div and not the link. I've knocked up an example on jsFiddle:

Change target of all links inside an iframe to “_parent” jquery

女生的网名这么多〃 提交于 2019-12-04 09:51:37
im trying to set the target to all links inside an iframe to "_parent" using jquery but im not sure how to do it, can anyone help me? <script src="jquery-1.5.2.min.js"> $('a').target("_parent"); </script> <iframe src="http://google.com" frameborder="0"></iframe> Im doing this because I want to customize my firefox 4 homepage to show me the Google's start page with the restore session button near the "Sign in" link, and I almost do it but i don't wanna open the new links or searches inside the iframe. Thanks P.S. If is there another way without using jquery it would be great. It's $('a').attr(

get parentNode of clicked element in plain JS

天大地大妈咪最大 提交于 2019-12-04 09:14:51
I need to get the parentNode of a clicked element in plain JS (no jQuery or other frameworks) I am currently using document.getElementById("item_click") but I want to change id="item_click" to class="item_click" so I can use multiple boxes. I just don't know how to integrate this in the script Here's a Fiddle <<< play with it HTML <div class="item"> <div class="item-tester" > <div class="item-icon"></div> <div class="item-title">Item Title</div> </div> <div id="item_click" onmousedown="new_class(event)" onmouseup="revert_class(event)" onmouseout="revert_class(event)"></div> </div> JS function