fancybox-3 downloading link for hi res version of the image that is displayed - fancybox-3

How can I set up the download link in fancybox-3 in that way, that it will not link to the displayed image but to a hi res-version of the displayed image?
How can I set this up? Any help here? (I know there must be something with 'afterload' and a 'download attribute'.) Thx!

Simply use afterShow callback and then tweak the download link to suit your needs, for example:
$('[data-fancybox="images"]').fancybox({
buttons : [
'download',
'close'
],
afterShow : function(instance, current) {
var src = current.src.replace('1500x1000', '5000x2000');
console.info('current.src: ' + current.src + '; download src: ' + src);
$("[data-fancybox-download]").attr('href', src);
}
});
Demo - https://codepen.io/anon/pen/EdGNdX?editors=1010

Related

Can't click on mobile menu when using anchor link directly on URL

I have an anchor link in my main menu to a contact form on my home page, when you go there from another page the "hamburger" icon becomes unclickable.
I'm using the "Shapely" theme for wordpress and I believe that there is a bug on it. I had already asked on their support forum but with no answer.
You can see what I'm talking about if you go to the demo site and add an anchor link to the URL on mobile view and try to click on the menu (it doesn't work).
https://colorlib.com/shapely/#any-id
I need a workaround for this. What can I do?
You have javascript error in file, named shapely-scr‌​ipts.js. javascript stopes executing code located after error in one file/<script></script> tags.
In your case, the ways to save all theme js functions and fixing errors, are:
1. First way:
Modify .js file of theme. Even after modification, if you'll update your theme, you'll lose all changes you made. Here is what you need to change:
Go to {your-website-folder}/wp-content/themes/shapely/assets/js/ using file manager/ftp connection and find shapely-scr‌​ipts.js file. After find this code in that file
// Smooth scroll
if ( '' !== window.location.hash ) {
element = $( '#site-navigation #menu a[href=' + window.location.hash + ']' );
if ( element ) {
scrollToID = '#' + element.data( 'scroll' );
$( 'html,body' ).animate( {
scrollTop: $( scrollToID ).offset().top
}, 2000 );
newURL = window.location.href.replace( window.location.hash, '' );
window.history.replaceState( {}, document.title, newURL );
}
}
It's starts on line 24 and endes on line 36, and replace with this one:
if ('' !== window.location.hash) {
element = $('#site-navigation #menu a[href=' + window.location.hash + ']');
if (element.length > 0) {
scrollToID = '#' + element.data('scroll');
$('html,body').animate({
scrollTop: $(scrollToID).offset().top
}, 2000);
}else {
element = $(window.location.hash);
if (element.length > 0) {
$('html,body').animate({
scrollTop: $(element).offset().top
}, 2000);
}
}
newURL = window.location.href.replace(window.location.hash, '');
window.history.replaceState({}, document.title, newURL);
}
After this changes your theme js file will work without any errors, which mean that hamburger menu will work, too.
2. Second way ( if you're using child theme ):
Copy file named shapely-scr‌​ipts.js ( mentioned in option 1 ) in some folder of your child theme. Make changes described in option 1 with copied file shapely-scr‌​ipts.js( in your child theme ). After this you'll need to prevent file in your parent theme from loading, and instead of it load file from child theme. This will always load your changed file, even when you update your parent theme

How to include caption for gallery using magnific popup?

I am trying to include a caption on the actual webpage under the image while using the magnificence popup gallery. Using a div and class caption or carousel-caption, I am unable to do so without the images in the gallery stacking vertically one by one. How can I do this?
<a href="img/base/ggg.PNG" title="HELLO" class="chicken">
<img src="img/base/pop.PNG" alt="remember your alt tag" />
</a>
$(document).ready(function() {
$('.chicken').magnificPopup({
type: 'image',
gallery:{enabled:true}
// other options here
// end each line (except the last) with a comma
});
});
js fiddle: https://jsfiddle.net/sb4btox7/
Since I don't yet have enough reputation points to comment, I'm commenting here, in addition to providing a solution.
Comment: JSFiddle isn't working with your http:// images because JSFiddle is trying to serve them from https://
Solution:
You are halfway there. There are 2 parts to making the captions work.
You correctly have put the link in the anchor tag and not the
image tag
You must specify your title source in your
initialization script like this.
$(document).ready(function() {
$('.chicken').magnificPopup({
type: 'image',
gallery:{enabled:true},
type: 'image',
image: {
titleSrc: 'title'
// this tells the script which attribute has your caption
}
});
});
The script then automatically writes your caption to its div labeled class="mfp-title"
BONUS Solution: I needed my lightbox image to open in a new window for users on their phones to zoom in, so I added this after the first titleSrc declaration:
titleSrc: 'title',
titleSrc: function(item) {
return '' + item.el.attr('title') + '';
}
This information is in the documentation: http://dimsemenov.com/plugins/magnific-popup/documentation.html in the "Image Type" section
I tried to use the selected answer, but even using the documentation, the examples wouldn't work for me. What I ended up using was:
$('.elements').magnificPopup({
type: 'image',
gallery: {
enabled: true
},
image: {
titleSrc: function(item) {
return item.el.find('img').attr('title');
}
}
});
This probably has something to do with the version I was using, but it wasn't clear what version the documentation was for. Hopefully this is useful to someone.

How to add stylesheet to toolbar

Using the Firefox Addon SDK, I am creating a toolbar with several buttons and I want to create a mouseover effect for the buttons.
At first I thought to use a mouseover event, but then I would have to create a mouseout event to return it to normal, so I figured the best way would be to use css
In my old XUL version of my addon I was able to attach the stylesheet by linking to it in the XUL code and just add css for my #buttonID, which worked perfectly.
But how do I add the css stylesheet for my toolbar using the Addon SDK?
Here's what I've tried so far (which does not produce any errors), but I think this is just for content; if this is correct, then I'm not sure how to bind to the element:
const { browserWindows } = require("sdk/windows");
const { loadSheet } = require("sdk/stylesheet/utils");
//This is how to load an external stylesheet
for(let w of browserWindows){
loadSheet(viewFor(w), "./myStyleSheet.css","author" );
}
I've also tried this:
var Style = require("sdk/stylesheet/style").Style;
let myStyle = Style({source:'./myStyleSheet.css'});
for(let w of browserWindows){
attachTo(myStyle, viewFor(w))
};
And this:
var { attach, detach } = require('sdk/content/mod');
const { browserWindows } = require("sdk/windows");
var { Style } = require('sdk/stylesheet/style');
var stylesheet = Style({
uri: self.data.url('myStyleSheet.css')
});
for(let w of browserWindows){
attach(stylesheet, viewFor(w))
};
And here is my css:
#myButton:hover{list-style-image(url("./icon-16b.png")!important; }
Tested this in Browser Toolbox:
const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js"); // skip this in SDK
const { browserWindows: windows } = require("sdk/windows");
const { viewFor } = require("sdk/view/core");
const { attachTo } = require("sdk/content/mod");
const { Style } = require("sdk/stylesheet/style");
let style = Style({ source: "#my-button{ display: none!important; }" });
// let self = require("sdk/self");
// let style = Style({ uri: self.data.url("style.css") });
for (let w of windows)
attachTo(style, viewFor(w));
The commented part allows to load from a stylesheet file in the addon data directory.
Notice that you need to import SDK loader to use it in the toolbox.
When in an SDK addon, just use require directly.
NB: there is a difference in spelling: self.data.url vs { uri }
See self/data documentation.
NB2: SDK uses a custom widget ID scheme for toggle and action buttons so your button ID might not be what you expect:
const toWidgetId = id =>
('toggle-button--' + addonID.toLowerCase()+ '-' + id).replace(/[^a-z0-9_-]/g, '');
OR
const toWidgetId = id =>
('action-button--' + addonID.toLowerCase()+ '-' + id).replace(/[^a-z0-9_-]/g, '');
using this code, you should be able to use the mouse over or hover to change how it looks.
#buttonID {
//Normal state css here
}
#buttonID:hover {
//insert css stuff here
}
This goes in the javascript file:
const { browserWindows } = require("sdk/windows");
const { viewFor } = require("sdk/view/core");
const { loadSheet } = require("sdk/stylesheet/utils");
const { ActionButton } = require("sdk/ui/button/action");
var StyleUtils = require('sdk/stylesheet/utils');
var myButton = ActionButton({
id: "mybutton",
label: "My Button",
icon: { "16": "./icon-16.png", "32":"./icon-32.png", "64": "./icon-64.png" },
onClick: function(state) {
console.log("mybutton '" + state.label + "' was clicked");
}
});
//this is how you attach the stylesheet to the browser window
function styleWindow(aWindow) {
let domWin = viewFor(aWindow);
StyleUtils.loadSheet(domWin, "chrome://myaddonname/content/myCSSfile.css", "agent");
}
windows.on("open", function(aWindow) {
styleWindow(aWindow);
});
styleWindow(windows.activeWindow);
And here is the css for that
//don't forget to add the .toolbarbutton-icon class at the end
#action-button--mystrippedadonid-mybuttonid .toolbarbutton-icon,{
background-color: green;
}
There are several gotchas here.
First, as of this posting, you should not use capital letters in the id for the button because they get completely removed - only lowercase letters and hyphens are allowed.
The id of the element is not the same as the id you gave it in the button declaration. See below for how to come up with this identifier.
To specify content in the url for the stylesheet file (in the loadSheet function call) you will also need to create a chrome.manifest in the root of your addon folder, and put this in it: content spadmintoolbar data/ where "data" is the name of a real directory in the root folder. I needed a data/ folder so I could load icons for the button declarations, but you need to declare your virtual directories in chrome.manifest which jpm init does not do for you.
How to get the element id for your css file:
The easy way to get the id for your button element for use in an external style sheet is by testing your addon and then using the browser-toolbox's inspector to locate the element, whence you can fetch the id from the outputted code.
However, if you want to figure it yourself, try this formula.
[button-class] = the sdk class for the button. An Action Button becomes action-button
[mybuttonid] = the id you gave the button in the sdk button declaration
[myaddonname] = the name you gave the addon in it's package.json file.
[strippedaddonid] = take the id you assigned the addon in the package.json file, and remove any # symbol or dots and change it to all lowercase.
Now put it all together (don't include the square brackets):
`#[button-class]--[strippedaddonid]-[mybuttonid]]`
An example: action-button--myaddonsomewherecom-mybutton
Really simple isn't it?!
credit for the stylesheet attach code goes to mconley

Froala add custom pre code button

I'm trying to create a code button with the Froala editor which can basicly do the same thing as here on SO by pressing CNTRL+K. Now I think I have two choices.
The first one is to edit the froala-editor.js file, because Froala already has a 'code' button which only adds the <pre> tags. If I could somehow get it to also add the <code> tag, problem solved. Unfortunately I didn't get this to work.
The second option is to create a custom button, so far I have this piece of code:
$('textarea[name="description"]').editable({
//Settings here
customButtons: {
insertCode: {
title: 'Insert code',
icon: {
type: 'font',
value: 'fa fa-code'
},
callback: function() {
this.saveSelection();
if (!this.selectionInEditor()) {
this.$element.focus(); // Focus on editor if it's not.
}
var html = '<pre><code>' + this.text() + ' </code></pre>';
this.restoreSelection();
this.insertHTML(html);
this.saveUndoStep();
}
}
}
});
It works somehow, but it's buggy and produces strange html like so:
<p><code></code>
<pre><code>asdasdasdasd
</code></pre>
</p>
Any help with getting this done for either option one or two would be greatly appreciated.
If you upgrade to version 1.2.3 that is available on Github your code should work https://github.com/froala/wysiwyg-editor. It's not necessary to save/restore selection.
LATER EDIT:
Here is a jsFiddle for it http://jsfiddle.net/9pmmg1jk/.
customButtons: {
insertCode: {
title: 'Insert code',
icon: {
type: 'font',
value: 'fa fa-code'
},
callback: function() {
if (!this.selectionInEditor()) {
this.$element.focus(); // Focus on editor if it's not.
}
var html = '<code>' + (this.text() || '​') + '<span class="f-marker" data-type="false" data-id="0" data-fr-verified="true"></span><span class="f-marker" data-type="true" data-id="0" data-fr-verified="true"></span></code>';
this.insertHTML(html);
this.restoreSelectionByMarkers();
this.saveUndoStep();
}
}
}

hiding controls in FCKEditor

i am using FCKEditor but i dont want all the buttons that are in the toolbar area i want only some of them is there any way to hide them using css or javascript or in any other way.
Have you looked into the ability to customize the fckeditor toolbar?
http://docs.cksource.com/FCKeditor_2.x/Developers_Guide/Configuration/Toolbar
http://developer.mindtouch.com/en/kb/Configure_the_FCKeditor_toolbar
There's FCKConfig.js which uses JSON configuration.
FCKConfig.ToolbarSets["Default"] = [
['Source','DocProps','-','Save','NewPage','Preview','-','Templates'],
['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],
['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField'],
'/',
['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
['Link','Unlink','Anchor'],
['Image','Flash','Table','Rule','Smiley','SpecialChar','PageBreak'],
'/',
['Style','FontFormat','FontName','FontSize'],
['TextColor','BGColor'],
['FitWindow','ShowBlocks','-','About'] // No comma for the last row.
] ;
FCKConfig.ToolbarSets["Basic"] = [
['Bold','Italic','-','OrderedList','UnorderedList','-','Link','Unlink','-','About']
] ;
For the version 3
There is a file called config.js
There You can change the default config value... for example
CKEDITOR.editorConfig = function( config )
{
config.entities = false;
config.entities_greek = false;
config.enterMode = 2;// 'br' ;
config.shiftEnterMode = 1 ; // 'p';
config.toolbar =
[
['Source','Preview'],
['Bold', 'Italic',,'Underline','Strike','-','Subscript','Superscript'],
['NumberedList', 'BulletedList', '-', 'Link', 'Unlink'],
['Cut','Copy','Paste','PasteText','PasteFromWord'],
['Outdent','Indent','Blockquote'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
['Link','Unlink','Anchor'],
['Image','Flash','Table','HorizontalRule','SpecialChar', 'Templates'],
['Format','Font','FontSize'],
['TextColor','BGColor'],
['Maximize', 'ShowBlocks']
];
};
Notes
for the moment you load the ckeditor.js, the CKEDITOR is global, so you can change the editorConfig anywhere on your javascript this way and not only on this config.

Resources