Is there a way to make newpage plugin to check if document has changed before clearing the document?
This is to prevent losing all work if accidentally pressing newpage icon
editor1.on('beforeCommandExec', function(evt) {
if (evt.data.name == 'newpage') {
if (evt.editor.checkDirty()) {
return confirm('You have unsaved work. Do you want to start a new page anyway?');
}
}
});
editor1.on('afterCommandExec', function(evt) {
if (evt.data.name == 'newpage') {
evt.editor.resetDirty();
}
});
Related
In my addon I want to place image from my panel to page. All works fine, but when I try to make the same in new tab, the image inserted in old tab too. Please explain me, how do I remove listener from old tab?
var tabIs;
var thisTab;
tabs.on("ready", function(tab) {
tabIs = tab.id;
tab.on("load", function(tab) {
tabIs += 1;
});
});
function handleClick() {
function insertPic(pic) {
var abs_url = self.data.url(pic);
worker.port.emit("to-page", abs_url);
}
if (thisTab == tabIs) {
panel.show();
panel.port.on("from-panel", insertPic);
} else {
thisTab = tabIs;
panel.show();
var worker = tabs.activeTab.attach({
contentScriptFile: [self.data.url("jquery-2.1.1.min.js"), self.data.url("page.js")]
});
panel.port.on("from-panel", insertPic);
}
}
You need to call the destroy() method on the worker, see the docs for more info.
I have this code:
function getArea (){
var area1 = document.getElementById('first');
var area2 = document.getElementById('adart');
if (area1.style.display.match("none") && area2.style.display.match("none"))
{
area1.style.display = 'block';
}
else
{
area1.style.display = 'none';
}
}
function getArea1 (){
var addArticle = document.getElementById('adart');
var area1 = document.getElementById('first');
if (addArticle.style.display.match("none") && area1.style.display.match("none"))
{
addArticle.style.display = 'block';
}
else
{
addArticle.style.display = 'none';
}
}
Now, in my html page:
I have two text areas and two buttons.
Each button "activates" a different text area.
All that my code does is to make the property 'display' in each text area to be "block" or "none", also, to make sure that if one text is already visible, the others will not.
The problem is that the first button "edit article" is not working until I click on the second button "add article". The second button works properly.
Any thoughts?
I have an iframe with a differing domain, I have no trouble resizing the iframe by communicating with the parent or the child using jQuery postMessage plugin. However, I have a single page app that scrolls through some steps and then loads in a results page via ajax. On this results page there are product links that need to load in the parent window. This works fine too. My problem is when the user clicks the back button, I want to regenerate and show the results, not the initial state of the page. On Chrome, this works fine but on Firefox it doesn't (when it's in an iframe, otherwise the url directly worked). It seems that Firefox ignores the hashes, cookies, pushState, etc that I've set. I'm not sure how to fix this, and any help would be appreciated.
First, I wanted to see if history api was available, when I call app.getResults() I check if it's available, otherwise set location.hash = "results". app.resultPageSetup(currentState) loads nicely the way I'd prefer because it skips the ajax call used to get the object, since I already saved it in the state.
var isHistory = function() {
return !!(window.history && history.pushState);
};
//This "if" is for a different part of the app. Just ignore.
if ($('.not_container2').length) {
setTimeout(function() {
app.setFrameHeight("2500");
}, 1000);
} else {
if ( isHistory() === true ) {
var currentState = history.state;
history.pushState('', '', '#steps');
if (currentState !== null ) {
$('.container').hide();
$('.container2').show();
app.resultPageSetup(currentState);
app.resultPageComplete();
} else {
$('.container').show();
$('.container2').hide();
setTimeout(function() {
if ($('.container').length){
app.setFrameHeight("610");
} else if ($('.not_container2').length) {
app.setFrameHeight("2500");
}
}, 1000);
}
} else {
//Firefox ignores this stuff. Chrome works. Doing without a cookie at all would be nice
if (location.hash === "#results" && $.cookie("results") === "true") {
$('.container').hide();
$('.container2').show();
app.getResults();
} else if (location.hash === "") {
$('.container').show();
$('.container2').hide();
$.cookie("results", null);
setTimeout(function() {
if ($('.container').length){
app.setFrameHeight("610");
} else if ($('.not_container2').length) {
app.setFrameHeight("2500");
}
}, 1000);
}
}
}
Here are the links: The parent is http://www.hhgregg.com/productfinder/tv (choose the first option) and the iframe source is http://hhgregg-finders.gst.api.igodigital.com
I could also leverage $.postMessage by setting hashes on the parent, but I had trouble with this as well. Here is the general idea there:
$(function() {
var iframe = $('#baseFrame');
var h;
var saved_state = "igo_steps";
$.receiveMessage(function(e){
var data = e.data.split("|");
var height = data[0];
var state = data[1];
if (!isNaN(height)) {
h = height;
} else {
h = "610";
}
iframe.attr("height", h);
if (saved_state !== state) {
window.location.hash = state;
$.postMessage(window.location.hash, '*', document.getElementById("baseFrame").contentWindow);
}
}, 'http://hhgregg-finders.gst.api.igodigital.com');
});
I have this basic function for handling the key event, everything works great. However, in Firefox 9.0.1 it seems I can't prevent the default event which is showing of bookmarks.
Is there any solution to prevent the default behaviour in FF?
$(document).keydown(function(evt) {
if (evt.which == 66 && evt.ctrlKey) {
if (evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
alert("Ctrl+B pressed");
return false;
}
});
Seems like some sort of bug regarding alert. Try this:
$(document).keydown(function(evt) {
if (evt.which == 66 && evt.ctrlKey) {
if (evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
console.log("Ctrl+B pressed");
return false;
}
});
Doesn't open the Bookmarks Toolbar for me now. I assume you don't actually want to alert do you? I think you can just call your method as long as it doesn't contain an alert.
I have a wordpress theme in which i have to create a page that has a movie that goes loop.
it has 3 menu points which change the div text without reloading the page.
So far no problem.
Click here – put it in content box 2
But when im on a different page and i click for example the second link, it should go to the video page and change the text to the second one.
How can i do this?
Is there a way to do that with?
url/wordpressname/#1
Found a Solution: i found a solution here: http://www.deluxeblogtips.com/2010/05/how-to-ajaxify-wordpress-theme.html
which i changed to fit my needs:
jQuery(document).ready(function($) {
var $mainContent = $("#text"),
siteUrl = "http://" + top.location.host.toString(),
url = '';
$(document).delegate("a[href^='"+siteUrl+"']:not([href*=/wp-admin/]):not([href*=/wp-login.php]):not([href$=/feed/])", "click", function() {
//location.hash = this.pathname;
//return false;
});
$("#searchform").submit(function(e) {
location.hash = '?s=' + $("#s").val();
e.preventDefault();
});
$(window).bind('hashchange', function(){
url = window.location.hash.substring(1);
if (!url) {
return;
}
if (url=="1") {
$mainContent.html('<p>Text1</>');
}
if (url=="2") {
$mainContent.html('<p>Text2</>');
}
if (url=="3") {
$mainContent.html('<p>Text3</>');
}
if (url=="4") {
$mainContent.html('<p>Text4</>');
}
// url = url + "#content";
//$mainContent.animate({opacity: "0.1"}).html('<p>Please wait...</>').load(url, function() {
//$mainContent.animate({opacity: "1"});
//});
});
$(window).trigger('hashchange');
});