i am creating extension using crossrider i am using this simple code which showing image on browser
$('<img style="position:fixed; z-index:999;margin-top:40%" />')
.attr('src',('https://lh4.ggpht.com/9qGc5-maR10Fh1IpRlCuGSmge9Zzm8VQdPMNqjJkhZjtCvAQYX55MRoo4AYnYUdZhj7i=w300'))
.prependTo('body');
now i want to add simple x button on image to close image and also want to add link on that image like when user click on image will open new window.
You can use standard jQuery to handle the click events and the Crossrider appAPI.openURL to open a new window.
So, for example, using the following based on your code in your extension.js file, will create the elements you require and provide the functionality you seek. I'll leave the CSS design for you to tidy up as you require:
// Add div to contain the image and X button to the body element
$('<div id="my-wrapper" style="position:fixed; z-index:999;margin-top:40%"><img /><span>X</span></div>')
.prependTo('body');
// Configure the img src and add a click event handler that opens a new window
$('#my-wrapper img')
.attr('src',('https://lh4.ggpht.com/9qGc5-maR10Fh1IpRlCuGSmge9Zzm8VQdPMNqjJkhZjtCvAQYX55MRoo4AYnYUdZhj7i=w300'))
.click(function() {
appAPI.openURL({
url: 'http://example.com',
where: 'window'
});
});
// Add an event handler to the X button that closes/hides the image
$('#my-wrapper span')
.click(function() {
$('#my-wrapper').hide();
});
[Disclosure: I am a Crossrider employee]
Related
When I go full screen on an element and then try to display angular bootstrap's modal in front, it won't appear in front.
To test it:
1 - Click on this link http://plnkr.co/edit/oKZHZZebyNMwpG114Jyy?p=preview
2 - Click on the "launch the preview in separate window" icon (image shown below)
3 - Click on Go Full Screen Button (you will then be in full screen on the element with id fullable)
4 - Then click on any of the buttons to try to show a modal.
Here is how to "launch the preview in separate window" on plnkr:
Solution to this problem required modal window to be appended to the element of my choice (in this case, element that goes full screen).
To accomplish this, I updated the angular bootstrap modal's code so that options object we pass to the $modal.open() function now accepts an appendTo property which is a css selector that will be used by document.querySelector.
In modal code (version 0.12.1), I changed from these:
var body = $document.find('body').eq(0),
currBackdropIndex = backdropIndex();
...
$modalStack.open(modalInstance, {
scope: modalScope,
deferred: modalResultDeferred,
content: tplAndVars[0],
backdrop: modalOptions.backdrop,
keyboard: modalOptions.keyboard,
backdropClass: modalOptions.backdropClass,
windowClass: modalOptions.windowClass,
windowTemplateUrl: modalOptions.windowTemplateUrl,
size: modalOptions.size
});
to these:
var body = angular.element(document.querySelector(modal.appendTo)),
currBackdropIndex = backdropIndex();
...
$modalStack.open(modalInstance, {
scope: modalScope,
deferred: modalResultDeferred,
content: tplAndVars[0],
backdrop: modalOptions.backdrop,
keyboard: modalOptions.keyboard,
backdropClass: modalOptions.backdropClass,
windowClass: modalOptions.windowClass,
windowTemplateUrl: modalOptions.windowTemplateUrl,
size: modalOptions.size,
appendTo: modalOptions.appendTo || 'body'
});
I opened an issue for this on github but it was closed without resolution so I had to update my local copy. Github issue is here: https://github.com/angular-ui/bootstrap/issues/3686
Please note: Since I am using document.querySelector for this, fix will work on browsers that support document.querySelector (almost all plus IE >= 9) http://caniuse.com/#feat=queryselector
In my jQM - Backbone app I add a dialog programmatically if a certain condition is true, like this
$('body').append('<div data-role="dialog" id="interlink" data-theme="b" data-close-btn="none" data-url="insignificant"></div> ');
// remove dialog from DOM on pagehide
$("#interlink").on('pagehide', function () {
$(this).remove();
// remove this views popup-containers
$('#interlink-video-popup-popup').remove();
});
Beside other content in the dialog there is a button to open a popup widget to play a video clip and a close button to close the dialog. The code for closing the dialog looks like this:
backBtnHandler: function(e) {
e.preventDefault();
$('#interlink').dialog('close');
$(this).remove(); // all DOM listeners get removed as well by jQuery
}
This works all well if the video clip is watched in full length, the popup widget closes on ended and the user clicks the dialog close button to close it.
A requirement is when the video clip is playing and the user scans another NFC tag the video should stop, trigger an ended event and close the popup. This is also working, however the dialog should also close. Here is a simplified code snippet with a timeout to simulate a NFC scan:
INTERPRETOUR.interlinkVideoPlayer = $('#interlink-video-player')[0];
// bind onended event to close the popup
$(INTERPRETOUR.interlinkVideoPlayer).on('ended', function() {
$('#interlink-video-popup').popup('close');
INTERPRETOUR.interlinkVideoPlayer = 'undefined';
$('#interlink-back-btn').trigger('click');
});
// play video
INTERPRETOUR.interlinkVideoPlayer.src = 'http://mydomain.ca' + this.model.get('video')[0].url;
INTERPRETOUR.interlinkVideoPlayer.play();
setTimeout(function() {
$.publish('item', '2479');
}, 5000);
The issue is that $('#interlink-back-btn').trigger('click'); invokes the backBtnHandler but pagehide is never triggered and so the dialog doesn't close.
Any help to resolve this issue would be much appreciated.
Instead of invoking a button using .trigger('click'), bind closing when popupafterclose event triggers.
Demo 1 / Demo 2
Static Popup
$('#popupID').on('popupafterclose', function () {
$('#dialogID').dialog('close');
});
Dynamically generated Popup
$(document).on('popupafterclose', '#popupID', function () {
$('#dialogID').dialog('close');
});
I have two pages .I am able to show page on clicking the button but i need to show same content as a dialog box on same screen without changing the screen. I need to show dialog box having same field in page .Here is my code in fiddle. on clicking the add button new page is open but i need the dialog box.
http://fiddle.jshell.net/ravi1989/nLJR7/
Are you looking for this?
$.mobile.changePage($("#UserSettingScreen"), {
transition: "slide",
reverse: false,
changeHash: false,
role: 'dialog' // you can use role: 'dialog' to open a dialog
});
Here is jsFiddle demo.
UPDATE
1) You can close a dialog programmatically by calling dialog('close') method like so
$("#case_dialog_cancel").on("click", function(){
$("#CaseInformationScreen").dialog('close');
});
Here is updated jsFiddle.
2) You can theme an overlay. Read more about overlayTHeme. If you for some reason want to get rid of the overlay completely or make it transparent - google for hakish ways. Here is one link Transparent jQuery mobile dialogs
I just want that when i click on <a> tag it open new window instead of opening new tab. I already use different code but it open in new tab every time.
U COULD USE POPUP WINDOW--->
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
Open a popup window
I am using jQuery mobile popups as context menu fired on right click on desktops and taphold on mobile devices.
My problem: when I right click, the popup appears - it works fine. But when the popup is open and i right click outside of popup, the popup is closed and the standard browser context menu appears instead of new popup.
The popup create a new layer (its class is ".ui-popup-screen" ) under itself to catch events, but something like
$(".ui-popup-screen").on("click", function(event) {
event.preventDefault();
$('#myElementWithPopupContextMenu').contextmenu();
return false;
});
does not work.
Any ideas how to fix it?
i like to write like follow pattern.
// prevent default contextmenu and trigger as 'custom-contextmenu'
$(".ui-popup-screen")
.bind("contextmenu",function(e) {
e.preventDefault();
// create and show menu
$("#myElementWithPopupContextMenu").trigger( "custom-contextmenu" );
});
// context menu handler
$("#myElementWithPopupContextMenu").bind( "custom-contextmenu", function(e) {
// my context menu
}