How can I make this modal dialog open on page load? - html

I am installing this modal dialog on a client's website, with practically no modifications.
However, I could not find how to make the modal dialog display on page load in the documentation.
Right now it just says:
<!-- Link to open the modal -->
<p>Open Modal</p>
But I am sure there is a way to make it just open on load.
I am using a hosted version of jQuery (jquery.min.js, jquery.modal.min.js) so I'm not trying to add/edit code in the JS file.

http://github.com/kylefox/jquery-modal Method 2: Manually:
$(function() {
$('#login-form').modal();
});

You need to create on your html a div like this:
<div ng-include="'/Somepast/busyModal.html'" ng-show="isLoading"></div>
<div> after load</div>
Then in your javascript you create:
function init() {
$scope.isLoading = true;
SomeFunction().then(function (data) {
$scope.isLoading = false;
}, onError);
};
that's it.

Related

custom js code not getting applied in angular responsive view

I have angular project in which I have included custom js in index.html . I have following code in custom.js file for navigation menu open and close for mobile devices. active class not getting applied in mobile view. I searched but did not found reason/solution of it.
$(document).ready(function () {
// Navigation Toggle
$("#nav-icon").click(function () {
$(this).toggleClass("active");
$(".close_overlay").toggleClass("active");
$(".navigation").toggleClass("active");
});
$(".close_overlay").click(function () {
$("#nav-icon").removeClass("active");
$(".close_overlay").removeClass("active");
$(".navigation").removeClass("active");
});
$("header .singleMenu").click(function () {
$("#nav-icon").removeClass("active");
$(".close_overlay").removeClass("active");
$(".navigation").removeClass("active");
});
});
If above code is included in header component ts file. It works. But that's not correct way of doing this.
How can add active class in mobile view when click events as above?
please guide and help. thanks.

Event listener for button does not work unless page is refreshed in React

In my index.html, I have the following code:
<head>
...
<script type="text/javascript"
src="https://mysrc.com/something.js&collectorId=f8n0soi9"
</script>
<script type="text/javascript">window.ATL_JQ_PAGE_PROPS = {
'f8n0soi9': {
"triggerFunction": function (showCollectorDialog) {
document.getElementById("button1").addEventListener("click", function (e) {
e.preventDefault();
showCollectorDialog();
});
}
}
};</script>
</head>
and then in my myComponent.tsx file, I have a button somewhere on the page that looks like this:
function myComponent() {
return (
...
<button id="button1">
Button Text
</button>
...
);
}
export default myComponent;
It's probably also important to note that I'm using react-routing to navigate between various components, and the button above is just in one of those components
So the issue seems to be that if you load in to a site on any other webpage and later navigate to the page with the button on it, the button won't work unless you refresh that specific page, since presumably it wasn't on the first page loaded and perhaps no element with id "button1" was found to bind the event listener to. React-routing doesn't refresh the page by default when navigating through the site.
Putting the code I have in the index.html file into the myComponent.tsx file also does not work, since (I think) the index.html file allows for any raw html but the tsx file isn't truly html? Is there perhaps a way to define this as a function in the index.html file and then assign an onClick event to the button? Thank you all in advance!
Yes, it should be possible to bind the function that shows the dialog for later use and then use the recommended React event on the button.
In this example bound globally to the window object for simplicity:
"triggerFunction": function (showCollectorDialog) {
window.showCollectorDialog = showCollectorDialog;
}
// ...
<button id="button1" onClick={e => {e.preventDefault(); window.showCollectorDialog();}}>
If you run into Type errors with that, try (on the button):
=> {...; (window as any).showCollectorDialog();}
Or declare only the property (possible be more specific than any here if the signature is known):
declare global {
interface Window { showCollectorDialog: any; }
}
It should be fine to have this just somewhere in your TS source, your index.html without TS should just assign it.

angular-ui modal is not initially hidden

I'm following this angular recipes page for adding a modal dialog to my ui. It suggests the following markup, which I've added to one of my views.
... html for my view is here ...
<button class="btn" ng-click="open()">Open Modal</button>
<div modal="showModal" close="cancel()">
<div class="modal-header">
<h4>Modal Dialog</h4>
... etc, from the recipe doc
</div>
What I want to see is my view, plus an "Open Modal" button on the bottom and nothing else. What I see instead is the button and the content of the modal already visible on the page.
The very next words in the recipe doc are:
Note that even though we don’t specify it explicitly the modal dialog
is hidden initially via the modal attribute. The controller only
handles the button click and the showModal value used by the modal
attribute.
Why is my modal mark up initially visible on the page? I think I have installed angular-ui properly... in my index.html:
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
And in my app JS:
angular.module('MonteAdmin', [
...
'ui.bootstrap',
...
])
That recipes page is likely out of date. At the time of the writing it might have been possible to pass a variable showModal to the modal directive to reveal or hide it. In your controller, you would have been able to show the modal by setting the scope variable showModal to true or false:
$scope.showModal = false;
$scope.open = function() {
$scope.showModal = true;
}
The current version does not work that way. You will have much better experience if you read the official documentation for the library at Angular UI Bootstrap
If you are using the latest version of the library, the directive is no longer modal but uib-modal. In addition, you have a bit more work to do to implement your modal.
Modal markup should be in a script tag, with a type set to text/ng-template as per the official example:
<script type="text/ng-template" id="stackedModal.html">
<div class="modal-header">
<h3 class="modal-title" id="modal-title-{{name}}">The {{name}} modal!</h3>
</div>
<div class="modal-body" id="modal-body-{{name}}">
Having multiple modals open at once is probably bad UX but it's technically possible.
</div>
</script>
To actually open the modal, your button click should trigger the following example function:
var modalInstance = $uibModal.open({
animation: $ctrl.animationsEnabled,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
controllerAs: '$ctrl',
size: size,
appendTo: parentElem,
resolve: {
items: function () {
return $ctrl.items;
}
}
});
You must also define a controller for the modal, itself:
angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function ($uibModalInstance, items) {
var $ctrl = this;
$ctrl.items = items;
$ctrl.selected = {
item: $ctrl.items[0]
};
$ctrl.ok = function () {
$uibModalInstance.close($ctrl.selected.item);
};
$ctrl.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
});
All of this code is found on the official documentation for Angular UI Bootstrap

jquery mobile - URL being updated on preventdefault

Have a problem that is driving me insane! I suspect I am doing something wrong...
I am using jQuery mobile with multiple pages in the same HTML file.
I have a page #mainregister on which I check for any user changes. If they try to navigate away, I stop the navigation using this code (using info I found here on SO):
$(document).on("pageinit", '#mainregister', function(){
$(document).on('pagebeforechange', function(e, data){
ResetTimeOutTimer(); // Reset inactivity timer
if (typeof data.toPage != "string") {
if (isDirty) {
var to = data.toPage.attr('id');
to = '#' + to;
console.log(to);
if(to !== '#mainregister')
{
var confirmationMessage = 'It looks like you have been editing something. '
+ 'If you leave before saving, your changes will be lost.';
e.preventDefault();
e.stopPropagation();
isDirty = false;
console.log(to);
$("#leavebutton").on('click', function(){
changePage(to, false);
return false; // This is to prevent events bubbling up and causing double page flips
// See https://github.com/jquery/jquery-mobile/issues/2369#issuecomment-4830800
// and https://css-tricks.com/return-false-and-prevent-default/
});
$("#leavetext").html(confirmationMessage);
$('#confirmLeave').popup('open');
return false;
}
}
}
});
});
This brings up a popup asking the user if they wish to Save or Leave. This popup is defined as:
<!-- Leave Warning Popup -->
<div data-role="popup" id="confirmLeave" data-overlay-theme="a" data-theme="a" style="max-width:400px;" class="ui-corner-all">
<div data-role="header" data-theme="a" class="ui-corner-top">
<h1>Info</h1>
</div>
<div data-role="content" data-theme="d" class="ui-corner-bottom ui-content" id="leaveContent">
<h3 class="ui-title" id="leavetext"></h3>
<input type="button" value="Save" onclick="SaveRegister()"/>
<input type="button" value="Leave" id="leavebutton"/>
</div>
</div>
<!-- End Leave Warning Popup -->
Now, if the user goes 'back' from #mainregister the navigation is stopped and the popup is shown. If the user chooses save, the save occurs but the URL still changes even though we're still on `#mainregister' page.
So, user is on index.html/#mainregister, hits back button, popup comes up, user chooses to save, popup closes, page shown is still #mainregister but URL is now index.html but should be index.html/#mainregister.
So, now the URL and the actual page do not match; and navigation is a little broken from here.
Am I using the wrong page event? Or something else?
Also (perhaps related) I notice that if I go back after a popup (in other use cases) I get the same URL twice - e.g. `\index.html#\index.html (is this because I am testing from file:// or something else)?

Open modal popup from a modal popup in Flex?

Is it possible to open a modal popup from a modal popup? I have not been able to get the following to work by calling showDataEntry() from an open modal popup:
// at the top of the modal's mxml, inside <mx:TitleWindow>
import mx.managers.PopUpManager;
import views.windows.MyDataEntry;
...
private function showDataEntry():void {
var myDataEntry:MyDataEntry = MyDataEntry(PopUpManager.createPopUp(this,MyDataEntry,true));
PopUpManager.centerPopUp(myDataEntry);
}
...
<mx:Button id="btnDataEntry" label="Data Entry" click="showDataEntry();" />
Without knowing exactly what MyDataEntry does, it looks like that may be the problem. Try just creating the popup with and pass it a class to create the content.
var myDataEntry:MyDataEntry = PopUpManager.createPopUp(this,myDataEntry,true) as MyDataEntry;