I have created the usercontrol with two ribbonitems but they were appearing in the disabled mode.
I tried to check by placing alert in my js file for isAvailable and isEnabled functions.
Extensions.DynamicControls.prototype.isAvailable =
function DynamicControls$isAvailable(selection)
{
alert('Inside DynamicControls isAvailable');
return true;
}
In this case i am not getting any alert in isAvailable function.
Extensions.DynamicControls.prototype.isEnabled =
function DynamicControls$isEnabled(selection)
{
alert('Inside DynamicControls isEnabled');
return true;
}
I am able to get the alert in isEnabled function.
Please let me know what i need to make them enabled.
Apart from this, i have seen page source using firebug- On selection of these two created buttons usercontrol buttons, i found
why is that class by default applied? If i try by removing it, the buttons are enabled.
As of now these are just visible as labels in the ribbon. Is any css also required to make these look like any other buttons?
Please suggest.
As indicated in my answer to your previous question, the methods are supposed to be called _isAvailableand _isEnabled with an underscore in front of them, that would be my guess as to why yours are not being fired.
So try to use the following code in your JavaScript:
Extensions.DynamicControls.prototype._isAvailable =
function DynamicControls$_isAvailable(selection, pipeline)
{
alert('Inside DynamicControls isAvailable');
if (pipeline) {
pipeline.stop = false;
}
return true;
}
Extensions.DynamicControls.prototype._isEnabled =
function DynamicControls$_isEnabled(selection, pipeline)
{
alert('Inside DynamicControls isEnabled');
if (pipeline) {
pipeline.stop = false;
}
return true;
}
By the way, looking at your namespace Extensions.DynamicControls I wonder if you are making the correct references, the Javascript is not for your ItemsGroup, it is supposed to be for the specific buttons, each command (or button if you will) will have its own bit of JavaScript which enables it and has an _execute method. See my answer to your other question for more details on that.
The CSS is just for the layout of the buttons, this will not actually enable or disable them. Although if you assign a disabled image to the enabled state, then looks might be deceiving.
The CSS for the buttons would look something like:
/* large ribbon button image */
.tridion .ribbontoolbar .button.MyBtn .image,
.tridion .ribbontoolbar .button.MyBtn.ribbonitem .image
{
background-image: url({ThemePath}Images/my-btn-img.32x32.png);
}
.tridion .ribbontoolbar .button.MyBtn.ribbonitem.disabled .image
{
background-image: url({ThemePath}Images/my-btn-img.32x32.gray.png);
}
/* small ribbon button image */
.tridion .contextmenu .item.MyBtn .image,
.tridion .ribbontoolbar.minimized .button.MyBtn .image,
.tridion .ribbontoolbar.minimized .button.MyBtn.ribbonitem .image
{
background-image: url({ThemePath}Images/my-btn-img.16x16.png);
}
.tridion .ribbontoolbar.minimized .button.MyBtn.ribbonitem.disabled .image
{
background-image: url({ThemePath}Images/my-btn-img.16x16.gray.png);
}
You just need to return true, which you are already doing. And of course your commands need to be associated with the button through the configuration.
The isAvailable function is only called for toolbar buttons on certain tabs such as Create. Most of them assumes that your buttons should always be available, but could be disabled (so they only call isEnabled).
For context menu options, though, isAvailable will be called every time you right-click. Ideally you would use the same command for the context menu option as the toolbar.
Related
It is showing warning that 'keymanweb.setKeyboardForControl' cannot set keyboard on iframes.
I want to manually set specific language of keyman on iframe element.
Please help me out to achieve the same.
While keymanweb.setKeyboardForControl cannot be used with iframes, you should be able to use a controlfocused event event to select a keyboard on entry to the control:
keyman.addEventListener('controlfocused', function(eventProperties) {
if(eventProperties.target == myIframe) {
keyman.setActiveKeyboard(...);
}
return true;
});
so i'm working on a meteor project and am trying to get a drop down menu to close when the user clicks outside of it. i've done this before using jquery and normal html but this time we're using velocity.js and meteor.
so on the link that opens the drop down div, i have this:
Template.layout.events({
'click #profile-btn': function () {
if (userTog == false) {
$('#user-menu').velocity("fadeIn", { duration: 150 });
userTog = true;
}
else if (userTog == true) {
$('#user-menu').velocity("fadeOut", { duration: 150 });
userTog = false;
}
},
.....
and then i use a meteor package to deal with events on the body as this isnt supported right now..
Template.body.events({
'click html': function(e, data, tpl) {
userTog = false;
$('#user-menu').velocity("fadeOut", { duration: 150 });
e.stopPropagation();
}});
however the above is just not working.. it basically just makes the menu appear then disappear straight away. is it something to do with velocity.js, meteor or am i just doing it plain wrong ?!?
any advice would be greatly appreciated!
I just had to make a material design select box, so I feel your pain :-). Here's how I solved it:
Normally, you can only focus an input or an anchor. A trick I stumbled upon is that using tabindex="0" in your element attributes allows it to gain focus, even if it's a div. What's this mean? Well, if you can focus() an element, that means you can blur() it. So, when you click the button for the dropdown, add a line at the end of the event handler like $('.dropdown-menu').focus(). Then, to escape that, just create an event handler like 'blur .dropdown-menu': function() {*..hide..*}. That way, you don't have these ugly global event watchers.
The downside is that you get a glowing blue outline (for accessibility reasons). You can get rid of this by having a line like outline: 0; in your css.
PS, the reason why yours wasn't working is because 'click #profile-btn' bubbles up to the body, so it executes both. To fix it, you need to stop that bubblin via e.stopPropagation();.
After a postback, I want my page to have focus on a child control of a gridview, but scroll the page to a different part.
the standard myGridView.Focus(), called on the Page_Load or Page_prerender, insert a
WebForm_AutoFocus('myGridViewClientID');
in the rendered html.
This function move also the scroll not to the required position
Any suggestion?
my try: use some function injected by Asp.NET:
function FocusWithoutScroll(focusId) {
var targetControl;
if (__nonMSDOMBrowser) {
targetControl = document.getElementById(focusId);
}
else {
targetControl = document.all[focusId];
}
var focused = targetControl;
if (targetControl && (!WebForm_CanFocus(targetControl))) {
focused = WebForm_FindFirstFocusableChild(targetControl);
}
if (focused) {
try {
focused.focus();
}
catch (e) {
}
}
}
but in order to use this code, I have to include some .axd resource files: it seems ASP.NET automatically include them when you set
someControl.Focus();
in your server side code. but this in turn insert the
WebForm_AutoFocus('myGridViewClientID');
which scroll the page to the wrong position
There's a client-side method scrollIntoView that scrolls page till the element is visible. You can issue server-side command:
ClientScript.RegisterStartupScript(this.GetType(), "MyScript","document.getElementById('SecondElementID').scrollIntoView();", true);
Where 'SecondElementID' is id of the element you want to scroll to.
Demo: http://jsfiddle.net/v8455c79/ this demo shows how focus can be set on one element and page scrolled to another
I am using a CSS hover trick to clean up my interface. Controls will only be shown when the cursor is hovering inside the element. I'm running into an issue when using the interface on a touch screen device. If the control button is not shown display:none and I touch where it should be, the event is still triggered for the button.
Try this fiddle both in your browser and on a touchscreen device to see what I mean...
http://jsfiddle.net/6PvCn/2/
On a touchscreen device, touch the red square and the alert should fire, without the button even showing up. I tested this on both the desktop Android Emulator and my real Android 2.3 phone.
The effect I'm going for is for the button to first be shown without firing, even if the user touches where the button "is".
I'd rather use a pure CSS solution before resorting to javascript.
Try pointer-events: none; along with display: none;
I just tested it on my real device, and it indeed executes the button's action.
You could maybe try to make the red box an image and change the image to a button by an onclick with Javascript. I would have provided you with some code if I wasn't short on time.
You can't do it with pure CSS, tapping the button will put the button into hover state and fire the click event. Instead you should fire the button off on active.
Here is the solution I came up with... http://jsfiddle.net/6PvCn/7/
On an Android touchscreen (don't know about IOS), the hover event for the hidden element is not fired if it is not shown. So basically I check to see if the element was hovered before it was clicked.
In a nutshell
$(".hidden").hover(function(e) {
if(e.type == "mouseenter") $(this).addClass("hovering");
else $(this).removeClass("hovering");
}).click(function(e) {
if(!$(this).hasClass("hovering") return false;
});
The fiddle explains the more complicated situation I had with form elements and dynamically added content. It provides a general solution as opposed to this element specific one.
I wrote a JS solution for you:
https://codepen.io/anon/pen/bmYROr
The trick is to prevent the button's click event getting fired for the first time the outer div is getting clicked because on touch devices click event has hover effect.
let isTouchDevice = true;
let isHovered = false;
document.getElementById('outer').addEventListener('click', (e) => {
if (isTouchDevice) {
if (!isHovered) {
e.stopPropagation();
}
isHovered = true;
}
}, true);
document.getElementById('outer').addEventListener('mouseleave', (e) => {
if (isTouchDevice) {
isHovered = false;
}
}, true);
document.getElementById('btn').addEventListener('click', () => {
alert("hi");
});
I need to disable delete button GLOBALLY based on some condition?
The following solutions will not work for me:
http://csharpbits.notaclue.net/2009/07/securing-dynamic-data-preview-4-refresh.html
http://csharpbits.notaclue.net/2008/05/dynamicdata-miscellaneous-bits-part-6.html
Again, I do not want to go into every list and detail page and disable it there.
Why not just extend/inherit from button. You could make your own button that "knows" how to check if it should be hidden:
public class MyButton : Button
{
public void HiddenCheck()
{
bool visible = true;
//Check to see if the button should be hidden
this.Visible = visible;
}
}
Then, just use this button instead of the "System.Web.UI.WebControls.Button" button wherever you need the delete button functionality.
-Make that "Enabled." I read the post again, and I guess you aren't trying to "hide" the button, but disable it. The idea is the same though.