I have a third party control ClientPeoplePicker. The problem is that this control cannot be disabled. To disable it, I put the control inside a div with position:relative ("1") and add another with position:absolute and high z-index ("2"). So the aspx structure is:
<div id="1">
<div id=2/>
<clientpeoplepicker/>
</div>
Now, I want to create a user control which will render all of the above and also inherit from ClientPeoplePicker, so I can use inheritance and not have to map properties of ClientPeoplePicker created inside onto the control wrapper. How can I achive this (the best way)? If I merely create an instance inside the user control, to create it in CreateChildControls, I will lose inheritance. Or should I override rendering?
OK, so i went with overriding RenderControl
EDIT:
whole code:
private bool _enabled = true;
public new bool Enabled
{
get
{
return _enabled;
}
set
{
_enabled = value;
}
}
Panel divWrapper;
Panel divBlocker;
public override void RenderControl(HtmlTextWriter writer)
{
divWrapper = new Panel();
divWrapper.ID = base.ClientID + "_divWrapper";
divWrapper.CssClass = this.CssWraper;
divBlocker = new Panel();
divBlocker.ID = base.ClientID + "_divBlocker";
divBlocker.CssClass = this.CssBlocker;
if(this.Enabled)
{
divBlocker.Style.Add("display", "none");
}
divWrapper.RenderBeginTag(writer);
divBlocker.RenderControl(writer);
base.RenderControl(writer);
divWrapper.RenderEndTag(writer);
}
CSS
.cpp_blockdiv
{
z-index: 1000;
margin: 0px;
width: 100%;
height: 100%;
background-color: #000;
opacity: 0.1;
position: absolute;
}
.cpp_container
{
position:relative;
}
Related
I want to hide a section and show another section in one click.... is there any way to do that in elementor.
I searched on google but I get the result that only hide a section and show it again on another click.
But I want to hide a section and show a hidden section in one click....
please, help me with the solution.
thank you.
make sure to set a classname/id for each of your sections and also for your button.
eg. let's say i have set .sc1 and .sc2 for sections and .btn for the button.
drag and drop HTML widget to your header template or the page/template you want the results in.
copy the following javascript code to your html, make sure to put it between script tag:
var btn = document.querySelector('.btn');
var sc1 = document.querySelector('.sc1');
var sc2 = document.querySelector('.sc2');
btn.addEventListener("click", function() {
if (sc1.style.display === "none") {
sc1.style.display = "block";
sc2.style.display = "none";
} else {
sc1.style.display = "none";
sc2.style.display = "block";
}
});
.sc1, .sc2 {
width: 50px;
height: 50px;
}
.sc1 {
background: #000;
display: block;
}
.sc2 {
background: #e2062c;
display: none;
}
<div>
<div class="sc1"></div>
<div class="sc2"></div>
</div>
<button class="btn">click</button>
The Microsoft documentation mentions the #ontouchenter and #ontouchleave events.
I would like to utilize these to enable drag and drop in my Blazor app, but it doesn't seem like these events are firing. There is not a lot of examples of other mentions on the web.
Does anyone know whether they are supposed to work? Do I need to do any special to make them work?
UPDATE
I think it is because the element position is not changed, as the normal draggable ensures via mouse drag.
Is it possible to change/update the elements position (x,y) via c# in Blazor?
Example
The following is a minimal example
Index.razor
#page "/"
<h1>Hello, world!</h1>
Welcome to your new app.
<div style="height: 300px;width: 300px;background-color: cornflowerblue;touch-action: none; border: medium;"
ondragover="event.preventDefault();"
#ontouchenter="OnTouch"
#ontouchleave="OnTouch"
#ondragenter="OnDrag"
#ondragleave="OnDrag"
#ondrop="OnDrop">
Drag to Me
</div>
<DragItem></DragItem>
<DragItem></DragItem>
<DragItem></DragItem>
<DragItem></DragItem>
#code{
private void OnTouch(TouchEventArgs args)
{
Console.WriteLine("Index:OnTouch:" + args.Type);
}
void OnDrag(DragEventArgs args)
{
Console.WriteLine("Index:OnDrag:" + args.Type);
}
void OnDrop(DragEventArgs args)
{
Console.WriteLine("Index:OnDrop:" + args.Type);
}
}
DragItem.razor
<div
draggable="true"
#ontouchmove="OnTouchMove"
style=" cursor: move;
background-color: cornflowerblue;
touch-action: none;
user-select: none;
border: medium;
min-height: 100px;
min-width: 100px">
DragMe
</div>
#code {
private void OnTouch(TouchEventArgs args)
{
Console.WriteLine("OnTouch:" + args.Type);
}
private void OnTouchMove(TouchEventArgs args)
{
//double x = args.ChangedTouches[0].ClientX;
//double y = args.ChangedTouches[0].ClientY;
//--> I guess this is where I should update my dragitem position
//--> Normal drag via mouse automatically updates position, but not touchMove
}
void OnDrag(DragEventArgs args)
{
Console.WriteLine("OnDrag:" + args.Type);
}
void OnDrop(DragEventArgs args)
{
Console.WriteLine("OnDrop:" + args.Type);
}
void StoryClicked()
{
Console.WriteLine("StoryClicked");
}
}
I have a custom progress bar in angular. I'd like to bind to have a selector for the [value]. However if I bind the attribute in Angular it is no longer possible to select.
<progress-bar value="50"> works
<progress-bar [value]="value"> fails
The attribute doesn't exist in the second case it's just there as one of the ng-reflect-* attributes. Is this expected behavior?
component:
ProgressBar {
private currentValue;
#Input() set value(value: number) { this.currentValue = value; }
get value() { return this.currentValue; }
...
}
scss:
progress-bar {
display: block;
height: 4px;
width: 100%;
// determinate
&[value] {
background: map_get($color-palette, progress-bar-background);
.progress {
height: 100%;
background: map_get($color-palette, progress-bar-color);
animation: none;
transform-origin: top left;
transition: transform 250ms ease;
}
}
// indeterminate
&:not([value]) {
background: transparent;
}
}
Instead of property binding, you can use attribute binding:
<progress-bar [attr.value]="value">
export class ProgressBar {
constructor(private elementRef: ElementRef<HTMLElement>) {}
get value() {
const element = this.elementRef.nativeElement;
return element.getAttribute("value");
}
}
See this stackblitz for a demo.
A simpler solution is to set a class conditionally on the component with HostBinding:
export class ProgressBar {
private currentValue;
#Input()
get value() { return this.currentValue; }
set value(value: number) { this.currentValue = value; }
#HostBinding("class.has-value") get hasValue(): boolean {
return !!this.currentValue;
}
}
and to apply the styling according to the class selector:
progress-bar {
...
&.has-value {
...
}
&:not(.has-value) {
...
}
}
See this stackblitz for a demo.
You are trying to use a one way property binding between a object and method. Remove your getter and setter methods. They are kinda of useless since javascript doesn't have real private properties or methods.
ProgressBar {
#Input() public value: number
...
}
I have a Native V1 component that is not using shadowDOM so I place my CSS in the <head>. But when someone else uses my component my CSS no longer works.
This only happens if their component does use shadowDOM.
Example Code for my component:
class MyEl extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
this.innerHTML = `<div class="spaced"><button class="happy-btn">I'm Happy</button></div>
<div class="spaced"><button class="sad-btn">I'm Sad</button></div>`;
}
}
// Define our web component
customElements.define('my-el', MyEl);
button {
padding: 8px 20px;
}
.happy-btn {
background-color: pink;
}
.sad-btn {
background-color: #007;
color: white;
}
<my-el></my-el>
My CSS is loaded into the <head> tag since I am not using shadowDOM. But once the outer element includes me in their shadowDOM then things fall apart.
If you are creating a component that does NOT use ShadowDOM that you may still need to add your CSS into a shadowRoot. If someone else places your component into their shadowDOM, then you must add your CSS to their shadowRoot. You can do this with the following code:
const myStyle = document.createElement('style');
myStyle.setAttribute('component', 'my-el');
myStyle.textContent = ` button {
padding: 8px 20px;
}
.happy-btn {
background-color: pink;
}
.sad-btn {
background-color: #007;
color: white;
}`;
function addCss(el, selector, styleEl) {
// Check to see if we have been placed into a shadow root.
// If we have then add our CSS into that shadow root.
let doc;
try {
doc = el.getRootNode();
if (doc === document) {
doc = document.head;
}
}
catch(_ex) { doc = document.head; } // Shadow DOM isn't supported.
if (!doc.querySelector(selector)) {
doc.appendChild(styleEl.cloneNode(true));
}
}
class MyEl extends HTMLElement {
constructor() {
super();
addCss(this, 'style[component="my-el"]', myStyle);
}
connectedCallback() {
this.innerHTML = `<div class="spaced"><button class="happy-btn">I'm Happy</button></div>
<div class="spaced"><button class="sad-btn">I'm Sad</button></div>`;
}
}
customElements.define('my-el', MyEl);
class TheirEl extends HTMLElement {
constructor() {
super();
this.attachShadow({mode:'open'});
this.shadowRoot.innerHTML = `<hr/><my-el></my-el><hr/><my-el></my-el><hr/>`;
}
}
customElements.define('their-el', TheirEl);
<their-el></their-el>
The function addCss will place your CSS into the correct shadowRoot, or into document.head if there is no shadowRoot.
You must call addCss within your constructor to place the CSS in the correct location. This routine will also make sure you don't add it twice as long as you have a unique selector to identify your <style> tag.
In mine you see the <style> tag adds an attribute called component with a value of the component name. In my case component="my-el".
Then I use the selector 'style[component="my-el"]' to see if that tag is already in the shadowRoot, or document.head if there is no shadowRoot, and only add the styles if it does not already exist.
You can not assume that your component will not be in shadow DOM just because you are not using it. Use the example above to protect yourself.
Side Note
If you are using shadow DOM then this problem goes away since your have to place your CSS into your own shadowRoot.
I would like to highlight a div when it's clicked.
Heres the example: www.spidex.org
On this website if you hover any of the navigation buttons a div on the top of the page is highlighted.
You may use jQuery for achieving this.
get jQuery here.
now consider that you have a div that you want to highlight on mouseover called item.
do this by adding an overlay div.
div.overlay{
opacity:0;
background:#000;
width:100%;
height:100%;
position:absolute;
top:50px;left:0;
}
then use jquery
jQuery(document).ready(function($){
$('.item').mouseover(function(){
$('.overlay').css({opacity:0.3});
});
});
You can change the appearance of elements when hovered using the :hover pseudo-class.
For example
div:hover {
color: red;
}
Secondly, you can change the text color via using the color property and the background color using the background-color property.
Both are shown below:
div:hover {
color: black;
background-color: white;
}
In your given example, when you hover over the primary navigation items in the super-header, then the body dims. I agree with your analysis that this is managed with some cover div of the body.
One cross-browser approach (using jQuery in this example) you might consider would be the following:
EXAMPLE HTML:
<div class="header">
Some Link
</div>
<div class="body">
<div class="body-content">
[ CONTENT HTML ]
</div>
<div class="body-cover"></div>
</div>
EXAMPLE CSS:
.body {
position: relative; /* container needs position */
}
.body-cover {
position: absolute;
top: 0px;
left: 0px;
background-color: blue;
/*
you could use a sligtly transparent background here,
or tween your opacity in your javascript
*/
}
EXAMPLE JavaScript:
// on dom ready
jQuery(function ($) {
// closures
var $links = $('.header a');
var $body = $('.body');
var $content = $body.find('.body-content');
var $cover = $body.find('.body-cover');
var sCoverHiddenCssClassName = 'body-cover-hidden';
var sCoverTweeningCssClassName = 'body-cover-tweening';
var sCoverShowingCssClassName = 'body-cover-showing';
// closure methods
var fMouseOver = function () {
// check to see if hidden (not already tweening or showing)
if ($cover.hasClass(sCoverHiddenCssClassName)) {
// check content, may have changed.
$cover.css({
height: $content.outerHeight(),
width: $content.outerWidth()
});
// animate or tween cover (do this however you want)
$cover
.removeClass(sCoverHiddenCssClassName)
.addClass(sCoverTweeningCssClassName)
.fadeIn(function () {
// when completed, mark as showing/visible
$cover
.removeClass(sCoverTweeningCssClassName)
.addClass(sCoverShowingCssClassName);
});
}
};
var fMouseOut = function () {
// check to see if visible (not already tweening or hidden)
if ($cover.hasClass(sCoverShowingCssClassName)) {
// animate or tween cover (do this however you want)
$cover
.removeClass(sCoverShowingCssClassName)
.addClass(sCoverTweeningCssClassName)
.fadeOut(function () {
// when completed, mark as showing/visible
$cover
.removeClass(sCoverTweeningCssClassName)
.addClass(sCoverHiddenCssClassName);
});
}
};
var fClick = function (e) {
// prevent default if needed for anchors or submit buttons
// e.preventDefault();
if ($cover.hasClass(sCoverHiddenCssClassName)) {
fMouseOver();
}
else if ($cover.hasClass(sCoverShowingCssClassName)) {
fMouseOut();
}
};
// init interaction
$cover.hide().addClass(sCoverHiddenCssClassName);
$links.each(function () {
// wire links
jQuery(this)
.mouseover(fMouseOver)
.mouseout(fMouseOut);//
//.click(fClick); // use click event if desired
});
});
JQuery UI is also gives an good option to quickly highlight div .
https://jqueryui.com/effect/
$( "#divId" ).effect( "highlight", 500 );