How to get "scrollTop"-value of FB.Canvas.getPageInfo - facebook

So far I can alert the "scrollTop"-value of "FB.Canvas.getPageInfo":
FB.Canvas.getPageInfo(
function(info) {
alert('scrollTop: ' + info.scrollTop);
}
);
Now I would like to use this value in one of my functions, but I don't know how.
The following is not working:
function test() {
var fbScrollTop = FB.Canvas.getPageInfo();
alert(fbScrollTop);
}
How can I access the the value?

I don't know if it's useful yet.
But now I can center my divs in my facebook app.
Here is the function:
jQuery.fn.center = function () {
var temp = this;
FB.Canvas.getPageInfo(
function(info) {
$(temp).css("position","absolute");
$(temp).css("top", Math.max(0, ((info.clientHeight - $(temp).outerHeight()) / 2) + info.scrollTop) + "px");
$(temp).css("left", Math.max(0, ((info.clientWidth - $(temp).outerWidth()) / 2) + info.scrollLeft) + "px");
}
);
return this;
}
And I use like that:
var loading = $("#loading");
loading.center();

Just combine both
function test() {
var fbScrollTop;
FB.Canvas.getPageInfo(function(info) {
fbScrollTop = info.scrollTop;
alert(fbScrollTop);
});
}

Most of the methods available in the SDK are asynchronous - this means that the response will not be available until the provided callback is invoked (with the response).

Related

Get current Work item data in VSTS Extension

I am want to create a VSTS Extension for TFS 2015 Update 3 and I want to start slow. I want to create a custom action that shows the Id and the Title of the current Work Item in one pop up window.
I have been reading the tutorials but I still don't get it.
I used this example from GitHub:
var showPropertiesMenuProvider = (function () {
"use strict";
return {
showPropertiesInDialog: function(properties, title) {
VSS.getService("ms.vss-web.dialog-service").then(function (dialogSvc) {
var extInfo = VSS.getExtensionContext();
var contibution = VSS.getContribution();
var dialogOptions = {
title: title || "Properties",
width: 800,
height: 600,
buttons: null
};
var contributionConfig = {
properties: properties
};
dialogSvc.openDialog(extInfo.publisherId + "." + extInfo.extensionId + "." + "contextForm", dialogOptions, contributionConfig);
});
},
execute: function(actionContext) {
this.showPropertiesInDialog(actionContext);
}
};
}());
VSS.register("showProperties", function (context) {
return showPropertiesMenuProvider;
});
which gives me a lot of information but I still can't extract the data I need.
Any ideas?
Thanks in advance!

How to use the numericRefinementList to set allowed distances?

I would like to be able to use the numericRefinementList to allow users to pick the distance from themselves an item can be? This would be using the IP geo-location feature or inputting the geo-location from browser if available.
Less than 50km
50 - 100km
100 - 150km
More than 150km
https://community.algolia.com/instantsearch.js/documentation/#numericrefinementlist
This is unfortunately not something you can do with the numericRefinementList but you can probably build a custom widget setting the aroundRadius depending on the link you've clicked on:
function radiusList(options) {
if (!options.container) {
throw new Error('radiusList: usage: radiusList({container, ...})');
}
var $container = $(options.container);
if ($container.length === 0) {
throw new Error('radiusList: cannot select \'' + options.container + '\'');
}
return {
init: function(args) {
// event delegation: set the aroundRadius of the underlying link
$(document).on('click', '.radius-link', function(e) {
e.preventDefault();
args.helper.setQueryParameter('aroundRadius', +$(this).data('radius'));
args.helper.search();
});
},
render: function(args) {
// FIXME: display the list of radius links
var html = '<ul>';
html += '<li>< 100km</li>';
html += '</ul>';
$container.html(html);
}
};
}
And then you use it with:
search.addWidget(radiusList({container: '#my-radius-list'}));

Ionic Framework display dynamic value inside $ionicLoading

How can I display a dynamic value inside of ionicLoading?
Here is my code to show $ionicLoading, the idea here is to display download progress:
$rootScope.updateProgress = 0;
$ionicLoading.show({
template: 'Updating...' + $rootScope.updateProgress
});
And later in my code I update $rootScope.updateProgress's value:
var iPecent = Math.round(downloadProgress.receivedBytes / downloadProgress.totalBytes * 100);
$rootScope.$apply(function () {
$rootScope.updateProgress = iPecent;
});
However, $rootScope.updateProgress's value is not reflected when $ionicLoading is displayed on the screen - just shows initial value of 0. If I log out $rootScope.updateProgress's value it is reflecting current download progress.
Let me use cordova-plugin-file-transfer as an example:
$ionicLoading.show({
template: 'downloading...'
});
$cordovaFileTransfer.download(source, filePath, options, trustAllHosts).then(function (result) {
console.log('download successfully!');
$ionicLoading.hide();
}, function (err) {
alert('download failed!' + err);
}, function (progress) {
var downloadProgress = (progress.loaded / progress.total) * 100;
$ionicLoading.show({
template: "Downloaded:" + Math.floor(downloadProgress) + "%"
});
if (downloadProgress >= 100) {
$ionicLoading.hide();
}
});
I believe this was requested and added here https://github.com/driftyco/ionic/issues/699.
I haven't tested it, but based on the statement:
Use $ionicLoading.show() while the loader is open with new content,
and it will update the content.
If you call .show() subsequent to a $ionicLoading already showing, it should update the content.. If this feature is in fact now part of Ionic, and you put in some sort of loop and delay routine, you should be able to achieve what you're after.
Hi i am using show percentage of image uploading like 19%...
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
$ionicLoading.show({
template: 'Uploading Start....' + parseInt(100.0 * evt.loaded /evt.total) + '%',
});
where evt is callback of progress method.

Display Facebook Album Cover Image

I'm trying to show the cover photos of a Facebook user's albums, but I am not having any luck.
What I have so far is this:
FB.api('/me/albums', function(response) {
for(var i = 0; i < response.data.length; i++)
{
if(response.data[i].cover_photo != undefined)
{
var alb = $('<div class="album" id="album-' + response.data[i].cover_photo + '"></div>').appendTo(view_scroll);
alb.css('background', 'url(https://graph.facebook.com/' + response.data[i].cover_photo + '/picture)');
}
}
});
All I am getting is a question mark image. Any suggestions on how get the actual cover image into the background of the div?
Found it... Needed to add the access token to the end of the url:
background-image: url(https://graph.facebook.com/' + response.data[i].cover_photo + '/picture?access_token=' + [ACCESSTOKEN]
Hi i had the same problem, and i already got the cover_photo from every album of the user. Im using javascript sdk. After checking the login status, just call the function albumes():
function albumes() {
FB.api('/me/albums?fields=name,link,cover_photo,id',
function(response) {
for(var c = 0 ; c < response.data.length ; c++) {
coverPhoto(response.data[c].cover_photo, response.data[c].name);
}
}
);
}
function coverPhoto(id, nombre){
FB.api('/'+id+'?fields=picture',
function(responseIn) {
$('#javascriptData').append(
"<br>"+ nombre +"<img src='"+ responseIn['picture'] +"'>");
}
);
}

PhoneGap: mediaRec.startRecord(); not working in cordova-1.7.0

I'm trying to record a sample audio with phoneGap(cordova 1.7.0), but it is not working.
here is the code
function startRecord() {
var src = "testrecord.wav";
alert("startRecord: "+src);
navigator.mediaRec = new Media(src, onSuccessRecord, onErrorRecord);
// Record audio
navigator.mediaRec.startRecord();
// Stop recording after 10 sec
var recTime = 0;
var recInterval = setInterval(function() {
recTime = recTime + 1;
//setAudioPosition(recTime + " sec");
if (recTime >= 10) {
clearInterval(recInterval);
navigator.mediaRec.stopRecord();
}
}, 1000);
}
function onSuccessRecord() {
//alert("recordAudio():Audio Success");
var src = "testrecord.wav";
playRecordedAudio(src);
}
function playRecordedAudio(src) {
// Create Media object from src
//alert("play: "+src);
navigator.my_media = new Media(src, onSuccessPlay, onErrorRecord);
// Play audio
navigator.my_media.play();
}
// onError Callback
//
function onSuccessPlay() {
console.log("playAudio():Audio Success");
}
function onErrorRecord(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
I have tried this in xcode simulator and its worked fine, but not in iphone
Can anyone please help me out?
For the iphone the recording file (in your case testrecord.wav) has to exists before you start recording. Make sure that it exists by using the Phonegap File API.