Firefox Addon with toolbar, access object from browser.xul - firefox

I am developing a Firefox addon which will be primarily a toolbar but will have some dialog/windows for things like preferences.
In browser.xul I declare my global variable which I will store all variables within:
var coolAddon = {};
Then in my toolbar I want to be able to call methods of coolAddon, for example on button clicks.
If I open a dialog from browser.xul, in the dialog I can access coolAddon using window.opener.coolAddon, which works well. The problem is this does not work on the toolbar - only on windows/dialogs. What happens in the toolbar is window.opener is null/undefined.
How can I access coolAddon that is declared in browser.xul, from within the toolbar? I don't want to redeclare it because I need to keep it's current property values (I realise my example does not currently have any properties or methods).

You should be able to access coolAddon directly from your toolbar. It is in the browser context.
Window.opener is only needed when you are in a completely different window.

Related

WixCode controlling view of element on mobile / desktop

I'm learning the new Wix Code online development IDE and want to understand how to control the visibility of an item on mobile or desktop. How should I approach this?
If you're just trying to hide things from mobile, there's an easier way to do it (go to the mobile editor and click the element's hide button).
But assuming you're asking about WixCode because you need custom behavior:
Check out the formFactor API
https://www.wix.com/code/reference/wix-window.html#formFactor
And the properties panel
https://support.wix.com/en/article/working-with-the-properties-panel-6441151
The properties panel is where you'll set the element's default visibility.
Then check the formFactor using that API above
And finally use $w('#elementname).show() or hide() to change its visibility.
You have two options -
If you only want to control what appears on mobile vs desktop, you have a toggle to hide elements on mobile.
If you want to change dynamically visibility of elements on each or both, use the formFactor and hide/show/collapse/expand APIs.
For instance, on a button click you may want to show element1 on desktop and element 2 on mobile. The code will look something like the following -
import wixWindow from 'wix-window';
export function button1_onClick() {
if (wixWindow.formFactor === 'Mobile') {
$w('#element2').show();
}
else {
$w('#element1').show();
}
}

How do I prevent users from dragging windows around?

I've inherited a project that presents users a set of tabs, each of which contains a view that displays multiple components. In some of these tabs, we want to prevent users from moving the components displayed in the tab.
We have an object that inherits from CMFCTabCtrl to manage our tabs, which contains a collection of CWnd objects that represent each of our tabs. We also have an object that manages the views associated with each of these tabs, and activates those views when the relevant tab is activated.
The components all share a base object which inherits from CWnd, which defines the various handlers for the messages defined in the inherited message map.
What would be the correct/best way to prevent a user from dragging those components around?
Thanks!
One solution is to remove the titlebar style from the component CWnds. Without a titlebar the user cannot drag the window.
Another approach is to handle the WM_NCHITEST message in the component CWnds. If you return appropriate values the user's mouse will not be recognized as on the titlebar when they click.
Moving of the components is not a feature of Windows that is turned on by default. The code for moving the components exists in your project. That code has to be disabled in those cases where you want it disabled.
I assume that by components you mean controls and some such, and not child windows, like in MDI type of applications.
Try and set CMFCTabCtrl::m_bActivateOnBtnUp to TRUE.
This might deactive the Drag&Droip stuff.

How do I run Firefox inspector within an iFrame?

I know Chrome's inspector has a selector to choose which frame to use with the console. Firebug has a similar command, cd(window.frames[number]). Is there anything similar in Firefox Devtools? I suppose frame.window.eval could work, but only if it isn't cross-domain.
I was also wondering if there is a highlighter to inspect results of Web-console commands, for example document.getElementsByClassName(...). but you can at least change style of an element programmatically to 'see' it.
DOMNode objects do highlight in the page on hover in the web console and what is called the "variables view". The "variables view" is used in the web console too when you click on an object to see its properties (it's the sidebar that appears), and is also used in the debugger when paused at a breakpoint (right sidebar that contains the various scopes variables).
So, anytime a DOMNode appears in there, if you hover over it, it will be highlighted in the page.
When it comes to iframes, the webconsole does support the cd() command, see working with iframes.
We are also actively working on a bug that will add a drop-down to the toolbox whenever there are frames/iframes in the current page and allow you to easily switch from one to the other.
You can click to inspect a node in the console and debugger starting in Firefox 29, currently on the Aurora channel.

Ordering issue in modal window

I have a problem with a component that loads in to a modal window. I am using the Alpha User Points system and it has a component that gives you a full list of yous site's users. It also gives you the ability to order by username, by points etc. If I use it outside of modal window it works fine. If I use it in to modal window, ordering don't work!!! When I put my mouse over table's headers, outside of modal window gives this...javascript:tableOrdering('aup.referreid','asc','');In to modal window I see this...javascript:tableOrdering('aup.referreid','asc','');?ml=1 Using Firebug, I remove this ?ml=1 and it works into modal also!!! So the question is, why in to modal window gives this ?ml=1, what is this? And how will I remove it?
Well here is the answer... I use the Modalizer extension of nonumber.nl. I was loading my component through modalizer's modal box, this is why I had this issue. So, if anyone use Modalizer to popup components and have the same problem with me, just go to modalizer's Plugin Manager, find the option Convert Links inside Window and disable it!!! But, after this, if you want to add link in to modal window and you don't want to show-up the whole front page but only the component or what ever this is, you have to add at the end of the link this &ml=1.

Adding controls to a Property Sheet at runtime (without Dialog Templates)

As far as I can see, the way you normally create Property Sheets in Win32 (I am using the API, not MFC) programming is you have a bunch of dialog templates for each tab page, and you make the property sheet out of them. I have read about creating Dialog Templates 'in memory' but I would prefer not to do it this way. How do you add controls to a Property Sheet programatically at runtime, just like you can create a BUTTON and add it to a Window at runtime?
I suggest that you create a blank template and link that to your app. You can then create the property sheet with CreatePropertySheetPage and then add and remove controls to that property sheet as you please.
If you absolutely have to use a template built on the fly in memory, and you can't bring yourself to link a resource to your app, then you need the DLGTEMPLATE structure.

Resources