CKEditor preventing PrintArea.js working - ruby-on-rails-3

I have two divs. In one div (the "show" div) is some html. Hidden in front of that div is a form to edit that div with a CKEditor instance. I have a button to toggle between the two of them hiding one while revealing the other.
Now, I have a print button that fires PrintArea.js. It's supposed to print the div with the class 'printarea' from the "show" div and it does this very reliably when there is no CKEditor instance on the page.
The CKEditor instance is definitely the problem because when I remove that part of the form it's fine.
The problem code on PrintArea.js is this:
.filter(function(){ // this filter contributed by "mindinquiring"
var media = $(this).attr("media");
return (media.toLowerCase() == "all" || media.toLowerCase() == "print")
The error message in dev tools is this:
Uncaught TypeError:Cannot call method 'toLowerCase' of undefined

Upgrading PrintArea to 2.2.2 fixed the problem. I do not know how unfortunately.

Related

Make a page scroll to the bottom of a certain div tag when using Nuxt, Apollo, and fetchMore method

I used the fetchMore method for pagination in Nuxt, which loads more posts. I got the posts to load properly but I noticed the page reloads and starts back at the top of the page. How do I get the page to scroll automatically to a specific div tag after clicking my button (which uses the fetchMore method on click)?
I tried this inside the method but it didnt' work for me:
var container = this.$el.querySelector("#container");
container.scrollTop = container.scrollHeight;

Reloading a page in WinJS fails to attach event handlers

I have a WinJS application (a Windows 8.1 app using HTML/JS, not C#/XAML).
I've implemented a custom navbar in my default.html, with some buttons that have click event listeners attached to them. Each handler calls nav.navigate() with the url of the page corresponding to the nav button.
One of my pages (call it /pages/myPage/myPage.html) has several buttons on it. Each button has a click event listener bound to it in the page's ready function. This works fine when navigating between several pages.
However, if I'm on myPage (with working button click handlers) and click the navbar button for myPage again, the page looks like it reloads. The ready function seems to be called (i.e. it console.log statements in it are executed), but the buttons on the page seem to completely lose their click handlers!
If I navigate to another page, then navigate back, the buttons work fine again. But no matter what I do, "reloading" the page by navigating to itself (nav.navigate("/pages/myPage/myPage.html") while on myPage) causes my click handlers to be lost.
Why does this happen? My ready function is called, but somehow the click handlers are never re-attached.
Here's what the ready function for myPage looks like:
ready: function (element, options) {
document.getElementById("myButton").addEventListener("click", this.myButtonClicked);
},
Here's what the click event listener for the myPage nav button looks like (this code is in default.js):
myPageNavButton.addEventListener("click", function () {
nav.navigate('/pages/myPage/myPage.html');
});
Page nav in WinJS is just a matter of DOM replacement. When you do a nav, the target “page” contents are loaded into the DOM and then the previous “page’s” contents are unloaded. You can see this in navigator.js in the _navigating method. It creates a new element for the page being loaded, renders that fragment therein, and then unloads the old page.
The ready method for the new page, however, is called before the old page is unloaded (this was a change in WinJS 2.0, as WinJS 1.0 unloaded the old page before calling ready). The upshot of this is that when you navigate to the same page that’s already loaded, myPage.html(A) is in the DOM when you load myPage.html(B). When you execute the code in your ready method, then, getElementById will find the buttons in myPage.html(A) and so you're attaching handlers to that element. But then after you return from ready, myPage.html(A) is unloaded, so you lose the handlers. And because you never attached handlers to the buttons in myPage.html(B), they're just inert.
So what can you do about it? The best solution, in my mind, is to avoid navigating to the same page in the first place, because it's just fraught with other peril in the long run. To do this, wrap your call to nav.navigate with a check for whether you're already on the target page. Here's an implementation of a function that does that:
function navigateIfDifferent(target) {
var page = document.getElementById("contenthost").winControl.pageControl;
var fullTarget = "ms-appx://" + Windows.ApplicationModel.Package.current.id.name + target;
if (fullTarget !== page.uri) {
WinJS.Navigation.navigate(target);
}
}
This assumes that the PageControlNavigator control that you're using is in a div called "contenthost" in default.html (which is what the VS template gives you). What I'm then doing is building the full in-package URI for the target page and comparing that to the uri of the current page control, which is also a full in-package URI. You could also strip off the ms-appx:// part from the current page URI and compare to the target URI. Either way.
Anyway, with this function, replace your calls to nav.navigate with navigateIfDifferent, and you should be good.

Twitter Bootstrap 3 accordion with show / hide button

I am working with twitter bootstrap 3 and the accordion module and I want to do as follows: a button that says 'show', and when it's shown, a button saying 'collapse'.
I have tried with data attributes but it didn't work.
The accordions are inside a loop with django.
Thanks
I am using this js
$('a.accordion-toggle').click(function() {
if ( $(this).next('.accordion-body').hasClass('in') ) {
$(this).text('Close');
} else {
$(this).text('Open');
}
});
I have managed to make it work but it only switches the button once: all collapsed, button 'Open'. On shown, button 'Close'. But if I hide the accordion, the button doesn't change to 'Open' again.
You can do it using just CSS. I used the 'folder open' and 'folder closed' glyphicons. This is the Bootstrap example, I've just added the collapse class to the closed header anchors.
Here's an example:
http://jsfiddle.net/rTw7D/7/

Dynamic menu button items in TinyMCE

I have a custom menubutton in my tinyMCE editor that uses specific HTML elements elsewhere on the page as the menu items. I use a jQuery selector to get the list of elements and then add one each as a menu item:
c.onRenderMenu.add(function(c,m) {
m.add({ title: 'Pick One:', 'class': 'mceMenuItemTitle' }).setDisabled(1);
$('span[data-menuitem]').each(function() {
var val = $(this).html();
m.add({
title: $(this).attr("data-menuitem"),
onclick: function () { tinyMCE.activeEditor.execCommand('mceInsertContent', false, val) }
});
});
});
My problem is that this only happens once when the button is first clicked and the menu is first rendered. The HTML elements on the current page will change occasionally based on user clicks and some AJAX, so I need this selector code to run each time the menu is rendered to make sure the menu is fully up-to-date. Is that possible?
Failing that, is it possible to dynamically update the control from the end of my AJAX call elsewhere in the page? I'm not sure how to access the menu item and to update it. Something using tinyMCE.activeEditor.controlManager...?
Thanks!
I found a solution to this problem, though I'm not sure it's the best path.
It doesn't look like I can make tinyMCE re-render the menu, so instead I've added some code at the end of my AJAX call: after it has updated the DOM then it manually updates the tinymce drop menu.
The menu object is accessible using:
tinyMCE.activeEditor.controlManager.get('editor_mybutton_menu')
where mybutton is the name of my custom control. My quick-and-dirty solution is to call removeAll() on this menu object (to remove all the current menu items) and then to re-execute my selector code to find the matching elements in the (new) DOM and to add the menu items back based on the new state.
It seems to work just fine, though tweaks & ideas are always welcome!

How do I set the zIndex on a dijit.TooltipDialog?

I've created a dijit.TooltipDialog and everything works as it should. However, if another dialog is produced from within the tooltip dialog it shows up behind the tooltip dialog instead of on top of it. I checked the zIndex on the 2 dialogs and the tooltip dialog is 1000 and the other dialog is 950.
I've tried setting the zIndex on the respective container node and the tooltip dialog's "domNode" both with no luck. So does anyone know how to set the zIndex on the tooltip dialog?
as you will find if you inspect the dom after creating a programmatic tooltip - the tooltip is placed in an overlay container beneath <body>.
As mentioned, seek alternative methods for this.. But the answer is as follows; For you to successfully set a z-index you must find the correct node - which is not the domNode since the dialog has a 'layer' of its own via the dijit.popup design.
Here's the fiddle for it: http://jsfiddle.net/rQHSP/
In short, this is what you could do.
myDialog.onShow = function() {
node = this.domNode
// loop upwards untill we hit a wall or nodes class mathes popup
while (node
&& (!node.className || !node.className.match("dijitTooltipDialogPopup")))
node = node.parentNode
console.log(dojo.style(node, "zIndex")
}
Following mschr's answer I couldn't find the underlayAttrs property of dijit.TooltipDialog. But that did lead me to finding _popupWrapper which is the wrapper node of the entire popup. This node had a zIndex of 1000. The below code corrected the issue:
var dij = dijit.byId(dojo.query("[id*='_TooltipDialog_']")[0].id);
dij.onShow = function() {
dojo.style(dij._popupWrapper,"zIndex",900);
}