I have such code :
casper.thenOpen(url, function() {
this.echo('Opening at ' + width);
//give some time for the page to load
casper.waitFor(function check() {
return this.evaluate(function() {
return document.querySelectorAll('#browse-packshots').length > 0;
});
}, function then() {
//set the viewport to the desired height and width
this.viewport(width, height);
//Set up two vars, one for the fullpage save, one for the actual viewport save
var FPfilename = saveDir + '/fullpage-' + width + ".png",
ACfilename = saveDir + '/' + width + '-' + height + ".png";
//Capture selector captures the whole body
this.captureSelector(FPfilename, 'body');
//capture snaps a defined selection of the page
this.capture(ACfilename,{top: 0,left: 0,width: width, height: height});
this.echo('snapshot taken');
},function timeout() {
this.echo("Too long . No screenshot taken").exit();
},10000);
})
Casper version is 1.0.4 on Mac. When I want to use captureSelector I'm getting
[error] [phantom] Failed to save screenshot to fullpage-1440.png;
please check permissions...
With capture there is no problem. I event try with sudo but with no effect.
I think I found answer . I change one stuff in code:
this.captureSelector(FPfilename, 'html');
Have not idea why it wasn't working.
Related
I am posting sample code below please any help me
var bb_CoverPageImage = Ti.UI.createImageView({
width : '100%',
image : '',
categoryName : magazinePagesList[i].categoryName,
lengthId : magazinePagesList.length,
});
bb_CoverPageImage.image = L('Site_URL_Images') + magazinePagesList[i].imagePreviewUrl.replace(/\s/g, '%20');
coverScrollView.add(bb_CoverPageImage);
Though you have not mentioned why you need image width/height of remote image, but there can be basically 3 ways to get the width/height of any remote image.
Solution 1:
You can either ask your backend devs to provide you the image width & height as separate parameters.
Solution 2:
You can use Ti.UI.ImageView's load event to wait till your image is loaded & then you can use a code similar like this:
imageview.addEventListener('load', function(e) {
var image = imageview.toBlob();
var h = image.height;
var w = image.width;
});
This method forces that you can get width/height only after the image is loaded in ImageView.
Solution 3:
You can use web-service to download image & get further values:
var client = Ti.Network.createHTTPClient({
onload: function(e) {
var image = this.responseData;
var h = image.height;
var w = image.width;
bb_CoverPageImage.image = image;
},
onerror: function(e) {}
});
client.open("GET", magazinePagesList[i].imagePreviewUrl);
client.send();
I want to create an "image comparison slider" for contents. Example:
Codepen Link
// Call & init
$(document).ready(function(){
$('.ba-slider').each(function(){
var cur = $(this);
// Adjust the slider
var width = cur.width()+'px';
cur.find('.resize img').css('width', width);
// Bind dragging events
drags(cur.find('.handle'), cur.find('.resize'), cur);
});
});
// Update sliders on resize.
// Because we all do this: i.imgur.com/YkbaV.gif
$(window).resize(function(){
$('.ba-slider').each(function(){
var cur = $(this);
var width = cur.width()+'px';
cur.find('.resize img').css('width', width);
});
});
function drags(dragElement, resizeElement, container) {
// Initialize the dragging event on mousedown.
dragElement.on('mousedown touchstart', function(e) {
dragElement.addClass('draggable');
resizeElement.addClass('resizable');
// Check if it's a mouse or touch event and pass along the correct value
var startX = (e.pageX) ? e.pageX : e.originalEvent.touches[0].pageX;
// Get the initial position
var dragWidth = dragElement.outerWidth(),
posX = dragElement.offset().left + dragWidth - startX,
containerOffset = container.offset().left,
containerWidth = container.outerWidth();
// Set limits
minLeft = containerOffset + 10;
maxLeft = containerOffset + containerWidth - dragWidth - 10;
// Calculate the dragging distance on mousemove.
dragElement.parents().on("mousemove touchmove", function(e) {
// Check if it's a mouse or touch event and pass along the correct value
var moveX = (e.pageX) ? e.pageX : e.originalEvent.touches[0].pageX;
leftValue = moveX + posX - dragWidth;
// Prevent going off limits
if ( leftValue < minLeft) {
leftValue = minLeft;
} else if (leftValue > maxLeft) {
leftValue = maxLeft;
}
// Translate the handle's left value to masked divs width.
widthValue = (leftValue + dragWidth/2 - containerOffset)*100/containerWidth+'%';
// Set the new values for the slider and the handle.
// Bind mouseup events to stop dragging.
$('.draggable').css('left', widthValue).on('mouseup touchend touchcancel', function () {
$(this).removeClass('draggable');
resizeElement.removeClass('resizable');
});
$('.resizable').css('width', widthValue);
}).on('mouseup touchend touchcancel', function(){
dragElement.removeClass('draggable');
resizeElement.removeClass('resizable');
});
e.preventDefault();
}).on('mouseup touchend touchcancel', function(e){
dragElement.removeClass('draggable');
resizeElement.removeClass('resizable');
});
}
Same as above, but instead of images, I want to create content divs with text, images, html. Like 2 pages with a slider to compare both.
Your comparison script utilizes a resizing a div, so there's no way (that I know of) to achieve this without some considerable trickery (or how to achieve the same effect without resizing).
The only way to prevent the text from automatically wrapping is by using ...
white-space: nowrap;
... but that would just result in one continuous line of text.
Breaks <br> could be inserted from there, but that would just look awful and negate any resizing.
Personally, my approach would be to render the text within a canvas element first (https://www.w3schools.com/graphics/canvas_text.asp).
Since a canvas is treated nearly identical to that of an image, it wouldn't require any changes to the existing comparison script.
I'm trying to use this work
Bootstrap Application Wizard Hosted in Github
to create a wizard, but i need a full-width and responsive wizard.
In docs, contentHeight and contentWidth are the properties to resize the wizard, but they are in pixels, not in percentage.
I tried adding classes to the modal with some css, but i failed because the dimensions are calculated with js. Any help will be appreciated.
Github Demo
Github Js
My Jsfiddle
Snippet to modify:
autoDimensions: function() {
// DO NOT REMOVE DISPLAY ; Temporary display is required for calculation
this.modal.css('display', 'block');
this.dimensions.header = this.header.outerHeight(true);
// Navigation Pane is dyanmic build on card content
// Navigation Pane === BASE Inner Content Height
this.dimensions.navigation = this.wizardSteps.outerHeight(true);
if ( this.dimensions.navigation < this.dimensions.contentHeight ) {
this.dimensions.navigation = this.dimensions.contentHeight;
this.navContainer.height( (this.dimensions.contentHeight-30) - this.progressContainer.outerHeight(true));
}
// Dimension Alias ( Body Height === (Navigation Height) )
this.dimensions.body = this.dimensions.navigation;
// Apply OuterHeight of navigation to it's parent wizardSteps
this.wizardSteps.height(this.dimensions.body);
// Modal Height === (Header + Content)
this.dimensions.modal = (this.dimensions.header + this.dimensions.navigation);
this.content.height(this.dimensions.modal + 'px');
this.dialog.width(this.dimensions.contentWidth);
this.body.height(this.dimensions.body + 'px');
this.wizardCards.height(this.dimensions.body + 'px');
// Footer Height
this.dimensions.footer = this.footer.outerHeight(true);
// Card Container === (Body - Footer)
this.dimensions.cardContainer = (this.dimensions.body - this.dimensions.footer);
this.wizardCardContainer.height(this.dimensions.cardContainer);
// Reposition
this.dimensions.offset = ($(window).height() - this.dialog.height()) / 2;
this.dialog.css({
'margin-top': this.dimensions.offset + 'px',
'padding-top': 0
});
// DO NOT REMOVE NEXT LINE
this.modal.css('display', '');
},
In /src/bootstrap-wizard.js :
Comment // this.dialog.width(this.dimensions.contentWidth); because we want our modal to be responsive and not to set a width.
Remove 'margin-top': this.dimensions.offset + 'px', This can be replaced by a media query.
After container: el.parents('.form-group') add placement: 'top'. Without this, default popover behavior is to show on the right of the control they are attached on. On small screens, they appear out off screen.
It now reads like this (note the coma at the end of first line) :
var popover = el.popover({
content: msg,
trigger: "manual",
html: allowHtml,
container: el.parents('.form-group'),
placement: 'top'
}).addClass("error-popover").popover("show").next(".popover");
I have a Mapbox feature layer (with a geoJSON as source) with popups for each marker (with a divIcon). We are resizing the marker icon on different zoom levels (using css). How can I reset the offset of the popup on different zoom levels?
Here is the initial setup of the marker and popup (this all works):
var curOffset = [0,1];
Markers.on('layeradd', function(la) {
var Icon = la.layer,
feature = Icon.feature;
var popupContent = "<some html>"
var popupOptions = {
autoPan:true,
closeButton: false,
minWidth: 220,
maxWidth: 220,
zoomAnimation:true,
offset: curOffset
};
Icon.setIcon(L.divIcon(Iconfeature.properties.icon));
Markers.bindPopup(popupContent, popupOptions);
});
I tried to reset the offset on a zoom event like so, but it doesn't work:
map.on('zoomend', function(e) {
if (layerOn == true) {
size = map.getZoom();
switch (size){
case 14: console.log("14"); curOffset = [0,5]; break;
...
}
}
});
Do I need to close and then open the popup perhaps? I tried something along those lines but I got an error.
I received this suggestion from the a Leaflet Github contributor, but I haven't been able to get this to work either/
'Update the popup.options.offset, then call the private method popup._updatePosition.'
The GitHub Leaflet contributor also suggested looking into just changing the css for the popup on an event..once my co-worker and I found the right rule to modify, it worked:
map.on('zoomend', function(e) {
switch (size){ // zoom level
case 14: $('.leaflet-popup.leaflet-zoom-animated').css('bottom', '-5px'); $('.leaflet-popup .leaflet-zoom-animated').css('left', '-28px'); break;
...
I also had to add an additional check in case the layer was turned off during the zoom, with similar code.
I have an image slider that is controlled by text navigation. The text is highlighted orange when it's relative slide is current in the gallery. I would like the other text to have an inactive state with a black background but cannot get this to work!
(In case that didn't make much sense! Basically, I want background-color orange when current, background-color black when inactive.) THANKS
$(document).ready(function(){
$('.slider').each(function(e){
if(e == 0){
$(this).addClass('current');
}
$(this).attr('id', 'handle' + e);
})
$('.tabs li').each(function(e){
if(e == 0){
$(this).addClass('current'); //adds class current to 1st li
}
$(this).wrapInner('<a class="title"></a>'); //wraps list items in anchor tag
$(this).children('a').attr('href', '#handle' + e);//adds href to the anchors
t = $(this).children('a').text();
$('#handle' + e).append('<h2>' + t + '</h2>'); //adds h2 and text to big images
})
$('.tabs li a').click(function(){
c = $(this).attr('href');
if($(c).hasClass('current')){
return false;
}else{
showImage($(c), 20);
$('.tabs li').removeClass('current');
$(this).parent().addClass('current');
return false;
}
})
runRotateImages();
$("#featured").hover(
function(){
clearTimeout(xx);
},
function(){
runRotateImages();
}
)
})
function showImage(img, duration){
$('.slider').removeClass('current').css({
"opacity" : 0.0,
"zIndex" : 2
});
img.animate({opacity:1.0}, duration, function(){
$(this).addClass('current').css({zIndex:1});
});
}
function rotateImages(){
var curPhoto = $("div.current");
var nxtPhoto = curPhoto.next();
var curTab = $(".tabs li.current");
var nxtTab = curTab.next();
if (nxtPhoto.length == 0) {
nxtPhoto = $('#featured div:first');
nxtTab = $('.tabs li:first-child');
}
curTab.removeClass('current');
nxtTab.addClass('current');
showImage(nxtPhoto, 300);
}
function runRotateImages(){
xx = setInterval("rotateImages()", 5000);
}
I have added a jsfiddle - http://jsfiddle.net/n5EPM/3/
However, on jsfiddle it does not seem to automatically cycle through the images, not sure why, have no problems in browser.
Try using not() method: http://api.jquery.com/not/
Basically, you need to create a new class disabled
.disabled{
background-color:#000000;
}
Then, add the following line to your tabs.li's each loop:
$(".tabs li").not(".current").addClass('disabled'); //add disabled class for non-current tabs
At last you need to remove disabled class in the rotateimage() function before assigning current and then disable non-current again. like this:
curTab.removeClass('current');
nxtTab.removeClass('disabled'); //remove diabled class
nxtTab.addClass('current');
$(".tabs li").not(".current").addClass('disabled'); // disable non-current again
Working jsfiddle here: http://jsfiddle.net/n5EPM/9/
This might not be the perfect solution but you will need to tweak it a little bit.
Hope this helps.