Blank Space at bottom of Polymer Paper Dialog - dialog

I have a custom polymer dialog that I use for login, this is what I want it to look like:
This is the code I'm using to achieve that:
<polymer-element name="login-dialog">
<template>
<paper-dialog heading="XYZ Login" vertical autoCloseDisabled="true" transition="paper-transition-center" opened="true">
<p>{{feedback}}</p>
<paper-input floatingLabel label="Username" inputValue="{{username}}" type="text"></paper-input>
<paper-input floatingLabel label="Password" inputValue="{{password}}" type="password"></paper-input>
<paper-button role="button" on-click="{{reset}}" class="noink" affirmative>
Reset Password
</paper-button>
<paper-button role="button" on-click="{{login}}" class="ink" affirmative>
Login
</paper-button>
</paper-dialog>
</template>
<script type="application/dart" src="login-dialog.dart"></script>
</polymer-element>
I don't want the buttons to close the dialog, so I remove the affirmative from the paper buttons so that I can close the dialog myself if the correct login details were filled in.
As soon as I remove affirmative, a big white space appears at the bottom of the dialog:
Inside the dart code, I have the following for now:
login(event, detail, target) {
print("Clicked Login");
return false;
}
reset(event, detail, target) {
print("Clicked Reset");
return false;
}
I was hoping that returning false would stop the dialog from closing if I use affirmative, but it does nothing. Any ideas on how to get the buttons to no close the dialog unless I tell it to do so in the dart code and not have that white space at the bottom? (not keen on hacking it with css)

Returning false doesn't do anything. You need to call preventDefault() on the event.
login(event, detail, target) {
print("Clicked Login");
event.preventDefault();
// event.stopPropagation();
}
reset(event, detail, target) {
print("Clicked Reset");
event.preventDefault();
// event.stopPropagation();
}
<paper-dialog> has a specific option to disable automatic closing so you can affirmative for layout only.
<paper-dialog closeSelector="" ....
see also Prevent paper-dialog from automatically closing

Related

Scroll options_ui into view, Firefox webextension

I'm updating my extension with an options_ui and when the user updates the extension I call browser.runtime.openOptionspage() to make them aware of the new options page, but for some screen sizes the options_ui is not visible so for a better user experience I want to scroll my form with radio buttons into view, I've tried .scrollIntoView() on an input element but it does not appear to work.
I have a feeling this might not be possible in the context of about:addons is this possible?
Here's an image of what I mean, https://i.imgur.com/2bZx7d1.png
my options page/code:
<body>
<form>
<label>Enable for:</label><br>
<input type="radio" name="setting" id="global" value="global"> All tabs<br>
<input type="radio" name="setting" id="tabs" value="tabs"> Only tabs I click the icon in
</form>
<script src="options.js"></script>
</body>
function restoreOptions() {
document.getElementById("tabs").scrollIntoView(); //nada
var mode_getter = browser.storage.local.get("tab_mode");
mode_getter.then((obj) => {
switch (obj.tab_mode) {
case "tabs":
document.getElementById("tabs").checked = true;
break;
default:
document.getElementById("global").checked = true;
}
});
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelector("form").addEventListener("change", saveOptions);

How to enable toolbars in a rendered aui dialog

I am rendering the Aui dialog by setting toolbars : false in the configuration to disable close button(X) at corner of Aui dialog.
How to enable toolbars in a rendered aui dialog. i.e I want show (X)close icon after checking certain condition.
I think simply hiding and showing the toolbar will do what you want. You can hide and show the toolbar of a modal like so:
modal.getToolbar(Y.WidgetStdMod.HEADER).hide();
modal.getToolbar(Y.WidgetStdMod.HEADER).show();
In order to satisfy your use case, you should hide the toolbar, show the modal, then when your condition is met, show the toolbar:
modal.getToolbar(Y.WidgetStdMod.HEADER).hide();
modal.show();
// Once your condition is met:
modal.getToolbar(Y.WidgetStdMod.HEADER).show();
If you need more information, check out the Toolbar API Docs.
You can also select other toolbars besides the HEADER toolbar when using Modal.getToolbar(). Check out the list of the other toolbar sections for more details.
Here's a runnable example:
YUI().use('aui-modal', function(Y) {
var modal = new Y.Modal({
bodyContent: 'Modal body',
headerContent: '<h3>Modal header</h3>',
modal: false,
render: '#modal',
width: 450,
visible: false
}).render();
modal.getToolbar(Y.WidgetStdMod.HEADER).hide();
modal.show();
Y.one('#button').on('click', function(event) {
modal.getToolbar(Y.WidgetStdMod.HEADER).enable();
modal.getToolbar(Y.WidgetStdMod.HEADER).show();
});
});
<script src="http://cdn.alloyui.com/3.0.1/aui/aui-min.js"></script>
<link href="http://cdn.alloyui.com/3.0.1/aui-css/css/bootstrap.min.css" rel="stylesheet"></link>
<div class="yui3-skin-sam">
<button id="button">Show Toolbar</button>
<div id="modal"></div>
</div>
Note: Hiding the toolbar does not disable it, so if you need to ensure that the user cannot access the toolbar, you will need to call Toolbar.disable() and you will need to disable all the inputs and buttons within the toolbar programmatically.

How to simulate a click to open a tab after auto scroll

I have a problem , i have a script for mobile version of page that will scroll down the page to a specific div tag, it works fine but I would like the script to also open this section (open a tab)
This is what i got so far
The script
<asp:PlaceHolder ID="plhAnimatedScroll" visible="false" runat="server">
<script type="text/javascript">
var navHeight = $('#gecko-sub-navigation').outerHeight();
var buffer = (navHeight * 2) + 70;
$("html, body").animate({ scrollTop: $('#' + '<%=SelectedPage%>').offset().top - buffer }, 1000);
</script>
</asp:PlaceHolder>
One of the sections of the page
<section class="help_section">
Box title
<div class="help_details">
<div class="help_btm_msg"> some text </div>
</div>
</section>
The opening of the tab is triggered by click on anchor tag so the class changes from class="link help_switch closed" to class="link help_switch open" , is there any way to adjust the script so that it will change the class from closed to open or emulate the click ?
Thanks
Since you are using jquery, you can simulate a mouseclick, or trigger a click on a certain element using the trigger function.
jQuery documentation:
.trigger()
The idea is that you can first setup a click handler, and then call that click handler any time by triggering the "click" function in your code:
$( ".help_switch" ).on( "click", function() {
alert("help_switch has been clicked, or triggered.");
// now toggle the open/closed class
var isOpen = !$(this).hasClass("closed");
if(isOpen){
$(this).removeClass("open");
$(this).addClass("closed");
} else {
$(this).removeClass("closed");
$(this).addClass("open");
}
});
// trigger the "click" event on .help_switch when the page loads
// to show an example of how to call it:
$( ".help_switch" ).trigger( "click" );
Hope this helps.
You can see a working example of this code on jsfiddle: http://jsfiddle.net/8cvkm7y3/3/, if you load this code in jsfiddle, then you can watch how the closed and open class toggles on your help_switch class as you click the "Box Title" link by "Inspect Element" in Chrome Developer Tools or your web inspector of choice.

jQuery Mobile Alert/Confirmation dialogs

Is there a nice Sencha-like jQuery Mobile solution for Alerts and Confirmation dialogs?
Yes, the plugin is nice. However, if you don't need the full functionality, it's still much lighter in weight to roll your own simple dialogs. I use this:
<div data-role="dialog" id="sure" data-title="Are you sure?">
<div data-role="content">
<h3 class="sure-1">???</h3>
<p class="sure-2">???</p>
Yes
No
</div>
</div>
And this:
function areYouSure(text1, text2, button, callback) {
$("#sure .sure-1").text(text1);
$("#sure .sure-2").text(text2);
$("#sure .sure-do").text(button).on("click.sure", function() {
callback();
$(this).off("click.sure");
});
$.mobile.changePage("#sure");
}
You can use these wherever you need the confirmation dialog:
areYouSure("Are you sure?", "---description---", "Exit", function() {
// user has confirmed, do stuff
});
This plugin for jQM will style the confirmation box with jQM styling
http://dev.jtsage.com/jQM-SimpleDialog/
EDIT : This plugin has now been supserseeded by SimpleDialog2 which can be found here:
http://dev.jtsage.com/jQM-SimpleDialog/demos2/
Excellent code # Peter, but not to be generating consecutive events, it might be better to use unbind (), like this:
function areYouSure(text1, text2, button, callback) {
$("#sure .sure-1").text(text1);
$("#sure .sure-2").text(text2);
$("#sure .sure-do").text(button).unbind("click.sure").on("click.sure", function() {
callback(false);
$(this).off("click.sure");
});
$.mobile.changePage("#sure");
}
Thanks!
I had similar problem. I wanted to have easy to use function like standard confirm().
Since dialogs are deprecated in jquery mobile 1.4 (documentation), I decided to create my own fiddle:
function confirmDialog(text, callback) {
var popupDialogId = 'popupDialog';
$('<div data-role="popup" id="' + popupDialogId + '" data-confirmed="no" data-transition="pop" data-overlay-theme="b" data-theme="b" data-dismissible="false" style="max-width:500px;"> \
<div data-role="header" data-theme="a">\
<h1>Question</h1>\
</div>\
<div role="main" class="ui-content">\
<h3 class="ui-title">' + text + '</h3>\
Yes\
No\
</div>\
</div>')
.appendTo($.mobile.pageContainer);
var popupDialogObj = $('#' + popupDialogId);
popupDialogObj.trigger('create');
popupDialogObj.popup({
afterclose: function (event, ui) {
popupDialogObj.find(".optionConfirm").first().off('click');
var isConfirmed = popupDialogObj.attr('data-confirmed') === 'yes' ? true : false;
$(event.target).remove();
if (isConfirmed && callback) {
callback();
}
}
});
popupDialogObj.popup('open');
popupDialogObj.find(".optionConfirm").first().on('click', function () {
popupDialogObj.attr('data-confirmed', 'yes');
});
}
I noticed strange behavior, when redirecting/clearing window was done on "Yes" button click. It started working in afterClose event, so that's why it's a bit complicated.
Here is a jsfiddle demo
This plugin
craftpip/jquery-confirm
was designed for mobile initially, is based on the bootstrap3 framework.
Supports alerts, confirms, modals, dialogs, and many options.
Simple to use.
$.alert({
title: 'title here',
content: 'content here',
confirm: function(){
//on confirm
},
cancel: function(){
// on cancel
}
})
Supports ajax loading, CSS3 animations, Responsive, etc.
[EDIT]
Detailed documentation can be found here
Features list:
Themes (android themes included)
Ajax loading content.
CSS3 animations (2D & 3D animations)
Animation Bounce options
Auto close (triggers a action after timeout)
Icons
background dismiss (closes the modal on clicking outside the modal)
Keyboard actions (ENTER/SPACE triggers confirm, ESC triggers cancel)
Detailed API for programmically changing content in modal.
I'm actively developing the plugin, please do suggest improvements and features.
I haven't seen anything with alerts as I think it uses the native look and feel for them. You should be able to customize them through another jQuery plugin and/or CSS.
Here is a jQuery Example
UPDATE:
Well the link is a 404 now and jQM 1.2 is out and offers popups:
http://jquerymobile.com/demos/1.2.0/docs/pages/popup/index.html
Try,
if (confirm("Are you sure?"))
{
/*code to execute when 'Ok' bttn selected*/
}

Prevent onbeforeunload from being called when clicking on mailto link

Is there anyway to prevent onbeforeunload from being called when clicking on mailto link in chrome.
In FF, Safari, IE it is working fine.
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
google.load("jquery", "1.3.2");
</script>
<script type="text/javascript">
$(document).ready(function(){
window.onbeforeunload = confirmExit;
});
function confirmExit() {
return "Are you sure?";
}
</script>
</head>
<body>
Mail Link
</body>
</html>
What about a workaround?
$(document).ready(function(){
mailtoClicked = false;
window.onbeforeunload = confirmExit;
//Test if browser is Chrome
if (/chrom(e|ium)/.test(navigator.userAgent.toLowerCase())) {
$('a[href^=mailto]').click(function() {mailtoClicked = true;});
}
});
function confirmExit() {
if (!mailtoClicked) {
return "Are you sure?";
} else {
mailtoClicked = false;
}
}
Demo.
Here is a proposed solutions that looks reasonable
http://www.ilovebonnie.net/2009/09/23/how-to-use-onbeforeunload-with-form-submit-buttons/
UPDATE (link is dead) - Copied contents from Google Cache
How to Use onbeforeunload with Form Submit Buttons
September 23rd, 2009 — Geekery
While doing some programming I came across an interesting predicament. While I understand it’s evil to make it hard for a user to leave a page, I’m not here to argue the merits (or lack thereof) of onbeforeunload.
On a particular form, we are forcing the browser to not cache the information to avoid potential AJAX/JavaScript problems if they should leave the form and come back as browsers don’t all act the same (eg IE leaves checkboxes checked but doesn’t remember changes that have occurred to the page due to JavaScript). As such, we warn our users when they’re about to leave the order form to let them know they’ll need to fill it in again.
The function was simple enough:
window.onbeforeunload = function () {
return "You are about to leave this order form. You will lose any information...";
}
Unfortunately, this would also be triggered if the user submitted the form which, is obviously not what we want. After searching around on the Internet I came across a simple solution that I thought I would share:
// Create a variable that can be set upon form submission
var submitFormOkay = false;
window.onbeforeunload = function () {
if (!submitFormOkay) {
return "You are about to leave this order form. You will lose any information...";
}
}
Since onclick appears to register before onsubmit when clicking a submit button, we can add a little variable declaration to our submit button so that submitFormOkay will be set to true before the form submission happens:
<input type="submit" id="submit_button" onclick="submitFormOkay = true;">

Resources