Only show download button when a gallery image has that tag? - fancybox

Is there a way to only show the download button for gallery images that have the data-download-src attribute?

You could use events to toggle download button, example:
Fancybox.bind('[data-fancybox="gallery"]', {
Toolbar: {
display: ["counter", "download", "thumbs", "close"],
},
on: {
"ready Carousel.change": function (fancybox) {
const src = fancybox.getSlide().$trigger.dataset.downloadSrc;
document
.querySelectorAll(".fancybox__button--download")
.forEach((node) => {
if (src) {
node.style.display = "";
} else {
node.style.display = "none";
}
});
},
},
});
Demo - https://fancyapps.com/playground/1mV

Related

flutter_inappwebview and stripe.js blank screen

When loading a webpage that has the stripe javascript on it the InAppWebView is just a blank page, onLoadStop reports the URI: https://m.stripe.network/inner.html?url=\*\*&title=\*\*&referrer=\*\*&muid=NA&sid=NA&version=6&preview=false
The flutter app is a simple InAppWebView that mirrors a laravel website using the cashier/stripe subscription combination. The page works in a browser and when launched using url_launcher, but this requires the user to re-login and navigate back to where they were.
Is there any way to allow this page to load in flutter_inappwebview? Or, create the card-element element without the JavaScript include (https://js.stripe.com/v3)?
JavaScript code:
<script src="https://js.stripe.com/v3/"></script> -- this is the culprit
<script>
var stripe = Stripe('{{ env('STRIPE_KEY') }}');
var elements = stripe.elements();
var style = {
base: {
color: '#32325d',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: 'antialiased',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4'
}
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a'
}
};
var card = elements.create('card', {
hidePostalCode: true,
style: style
});
card.mount('#card-element');
card.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
const cardHolderName = document.getElementById('card-holder-name');
const cardButton = document.getElementById('card-button');
const clientSecret = cardButton.dataset.secret;
cardButton.addEventListener('click', async (e) => {
console.log("attempting");
const { setupIntent, error } = await stripe.confirmCardSetup(
clientSecret, {
payment_method: {
card: card,
billing_details: { name: cardHolderName.value }
}
});
if (error) {
var errorElement = document.getElementById('card-errors');
errorElement.textContent = error.message;
} else {
paymentMethodHandler(setupIntent.payment_method);
}
});
function paymentMethodHandler(payment_method) {
var form = document.getElementById('subscribe-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'payment_method');
hiddenInput.setAttribute('value', payment_method);
form.appendChild(hiddenInput);
form.submit();
}
</script>
Solved.
Stripe doesn't like custom headers, so if you add a header to the request it will block it.

html2canvas - the screenshotted canvas is always empty/blank

I have a div that i want to screenshot and save,
here is my code
function _download(uri, filename)
{
var el = $('.sf-download-button');
if (el.length)
{
var link = document.createElement('a');
if (typeof link.download === 'string')
{
link.href = uri;
link.download = filename;
document.body.appendChild(link);
//simulate click // this causes page to download an empty html file not sure why
link.click();
//remove the link when done
document.body.removeChild(link);
}
else
{
window.open(uri);
}
}
}
function _save()
{
window.takeScreenShot = function ()
{
var a =document.getElementById("my-div");
html2canvas(document.getElementById("the-div-that-i-want-to-screenshot"), {
onrendered: function (canvas)
{
document.body.appendChild(canvas);
a.append(canvas);
},
width: 220,
height: 310
});
};
$("#btnSave2").click(function ()
{
html2canvas(document.getElementById("data"), {
onrendered: function (canvas)
{
_download_card(canvas.toDataURL(), 'save.png');
}
});
});
}
This is the code i got it from web and added some of my own stuff.code was working i believe but right now, when I click on the button show me the image, it creates the image i can see it but it is just blank.
I tried every possible code combination from jsfiddle and all that and couldn't get anything different as a result.
What could be going wrong here?
I solved the problem by simply changing the browser,
It was not working with Chrome but works perfectly on Mozilla.
Also i changed the code to this,
$("#btnSave").click(function() {
html2canvas($("#card"), {
onrendered: function(canvas) {
theCanvas = canvas;
document.body.appendChild(canvas);
// Convert and download as image
$("#img-out").append(canvas);
// Clean up
//document.body.removeChild(canvas);
}
});
});
Works perfect on Mozilla only.

Amchart annotations . Returning back to normal mode from annotations mode

I am using external buttons for am charts export. when i enter into annotations mode and do export, the chart gets exported with annotations. But when the chart gets reloaded , the annotations mode does not revert back.
Could somebody let me know how to go back from annotations to normal mode.
if (chart.export.drawing.buffer.enabled === true) {
// Exporting the annotated chart with out "
//chart.export.capture"
chart.export.toPNG({}, function (data) {
chartimage.postImageData(data, chart_image_name)
});
} else {
chart.export.capture({
// action: "draw"
}, function () {
this.toPNG({
}, function (data) {
images.push({
"image": data,
"fit": [523.28, 769.89]
});
pending--;
if (pending === 0) {
chart.export.toPNG({
content: images
}, function (data) {
chartimage.postImageData(data, chart_image_name)
});
}
});
});
}
}
To exit from Annotation mode, simply use Export plugin's internal API method done():
chart["export"].drawing.handler.done();
BTW, export keyword is reserved and will result in errors on some browsers. It's better to access Export instance via named key: chart["export"].toPNG() versus chart.export.toPNG().
Please find the workaround below..
First capture the events for set and cancel annotations using menu reviewer
menuReviver: function (item, li) {
if (item.format === "XLSX" || item.format === "JSON") {
li.style.display = "none";
}
$(li).click(function () {
if (item.action == "draw") {
$("#chart_annotations").val(1);
}
if (item.action == "cancel") {
$("#chart_annotations").val(0);
}
});
return li;
}
Now while exporting the chart image use $("#chart_annotations").val() value as a
flag whether to export annotated chart or a normal chart. Please find the code below...
if (window.fabric) {
if ($("#chart_annotations").val() == 1) {
chart.export.toPNG({}, function (data) {
chartimage.postImageData(data, chart_image_name)
});
} else {
chart.export.capture({
//action: "change"
}, function () {
this.toPNG({
}, function (data) {
images.push({
"image": data,
"fit": [523.28, 769.89]
});
pending--;
if (pending === 0) {
chart.export.toPNG({
content: images
}, function (data) {
//post the image data using ajax
chartimage.postImageData(data, chart_image_name)
});
}
});
});
}

Can we show adMob ads for particular DIV?

Can we show adMob ads for particular DIV in Android application?
If possible, Can you tell me how to implement?
install this plugin cordova plugin add https://github.com/floatinghotpot/cordova-plugin-admob.git
and past bellow code inside your controller
$(function () {
// alert('1');
if ((/(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent))) {
document.addEventListener('deviceready', initApp, false);
} else {
initApp()
// alert('2');
}
})
function initApp() {
// alert('3');
initAd()
// display the banner at startup
window.plugins.AdMob.createBannerView();
}
function initAd() {
// alert('4');
if (window.plugins && window.plugins.AdMob) {
var ad_units = {
ios: {
banner: 'ca-app-pub-6869992474017983/4806197152',
interstitial: 'ca-app-pub-6869992474017983/7563979554'
},
android: {
banner: 'ca-app-pub-6869992474017983/9375997553',
interstitial: 'ca-app-pub-6869992474017983/1657046752'
},
wp8: {
banner: 'ca-app-pub-6869992474017983/8878394753',
interstitial: 'ca-app-pub-6869992474017983/1355127956'
}
};
var admobid = "";
if (/(android)/i.test(navigator.userAgent)) {
admobid = ad_units.android;
} else if (/(iphone|ipad)/i.test(navigator.userAgent)) {
admobid = ad_units.ios;
} else {
admobid = ad_units.wp8;
}
window.plugins.AdMob.setOptions({
publisherId: admobid.banner,
interstitialAdId: admobid.interstitial,
bannerAtTop: false, // set to true, to put banner at top
overlap: false, // set to true, to allow banner overlap webview
offsetTopBar: false, // set to true to avoid ios7 status bar overlap
isTesting: true, // receiving test ad
autoShow: true // auto show interstitial ad when loaded
});
// alert('5');
registerAdEvents()
} else {
// alert( 'admob plugin not ready' );
}
}
// optional, in case respond to events
function registerAdEvents() {
document.addEventListener('onReceiveAd', function() {});
document.addEventListener('onFailedToReceiveAd', function(data) {});
document.addEventListener('onPresentAd', function() {});
document.addEventListener('onDismissAd', function() {});
document.addEventListener('onLeaveToAd', function() {});
document.addEventListener('onReceiveInterstitialAd', function() {});
document.addEventListener('onPresentInterstitialAd', function() {});
document.addEventListener('onDismissInterstitialAd', function() {});
// alert('6');
}
function onResize() {
// alert('7');
var msg = 'web view: ' + window.innerWidth + ' x ' + window.innerHeight;
document.getElementById('sizeinfo').innerHTML = msg;
}
// ADMob
})

BlackBerry10 cascades :cannot access control objects from QML in c++

In my project, I have two qml files viz. main.qml and DetailsPage.qml.
I am trying to change the text of a label of DetailsPage.qml from c++ using findChild() method.
This is the code in c++ file and DetailsPage.qml
Myfile.cpp code:
using namespace bb::cascades;
AbstractPane *root;
AbstractPane *root1;
Navigater::Navigater
(bb::cascades::Application *app):QObject(app)
{
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
QmlDocument *qml1 = QmlDocument::create("asset:///DetailsPage.qml").parent(this);
qml->setContextProperty("_app", this);
qml1->setContextProperty("_app", this);
root = qml->createRootObject<AbstractPane>();
root1 = qml1->createRootObject<AbstractPane>();
app->setScene(root);
}
void Navigater::tr1()
{
Label *tryLabel1 = root1->findChild<Label*>("labelObj");
if(tryLabel1)
{
qDebug()<<"tttt "<<tryLabel1->text(); //initial text
tryLabel1->setText("Hello!!!!!!!") ;
qDebug()<<"yyyy "<<tryLabel1->text(); //changedText gets reflected on DeviceLog but not on UI
}
else
{
qDebug()<<"Not Found";}
}
DetailsPage.qml code:
// Navigation pane project template
import
bb.cascades 1.0
Page
{
// page with a picture detail
id: pgDetail
actions: [
ActionItem {
title: qsTr("Break")
onTriggered: {
_app.tr1();
imgView.imageSource = "asset: //images/picture1br.png"
}
}
]
paneProperties: NavigationPaneProperties {
backButton: ActionItem {
onTriggered: {
navigationPane.pop()
}
}
}
onCreationCompleted: {
_app.tr1();
}
Container {
background: Color.Black
Label {
objectName: "labelObj" // control to be found
text: "Page 2"
horizontalAlignment: HorizontalAlignment.Center
textStyle {
base: SystemDefaults.TextStyles.TitleText
color: Color.Yellow
}
}
ImageView {
id: imgView
imageSource: "asset:///images/picture1.png"
horizontalAlignment: HorizontalAlignment.Center
}
Label {
text: qsTr("Picture description")
horizontalAlignment: HorizontalAlignment.Center
}
}
}
Change I have made is not getting reflected in simulator...but visible on device log.
Is there any way to access control objects from multiple pages i.e pages other than main.qml?
Could you please look into it.
You can use a navigation pane, add main.qml as page contents and details page as attachedObjects in the navigation pane like
attachedObjects: [
ComponentDefinition {
id: secondPageDefinition
source: "DetailsPage.qml"
}
in main page action add
onClicked: {
// show detail page when the button is clicked
var page = secondPageDefinition.createObject();
navigationPane.push(page);
}
i think this will solve your issue and in the main.cpp page change the content as follows
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
qml->setContextProperty("_app", this);
root = qml->createRootObject<AbstractPane>();
app->setScene(root);
and
void Navigater::tr1()
{
Label *tryLabel1 = root ->findChild<Label*>("labelObj");
if(tryLabel1)
{
qDebug()<<"tttt "<<tryLabel1->text(); /////////////intial text
tryLabel1->setText("Hello!!!!!!!") ;
qDebug()<<"yyyy "<<tryLabel1->text(); ////////////changedText gets reflected on DeviceLog but not on UI
}
else
{
qDebug()<<"Not Found";}
}
you can navigate in qml easily without using c++
1.page1.qml
Page {
id: rootPage
Container {
background: Color.LightGray
layout: DockLayout {
}
Label {
text: "First page"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
}
}
actions: [
ActionItem {
title: "Next page"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
var page = pageDefinition.createObject();
navigationPane.push(page);
}
attachedObjects: ComponentDefinition {
id: pageDefinition
source: "PageTwo.qml"
}
}
]
}
onPopTransitionEnded: {
page.destroy();
}