UI kit notify pos issue - javascript

<script>
$(function(){
var ws_scheme = window.location.protocol == "https:" ? "wss": "ws";
var ws_path = ws_scheme + "://" + window.location.host + "/dashboard";
console.log("Connecting to " + ws_path);
var socket = new ReconnectingWebSocket(ws_path);
socket.onmessage = function (message) {
// Decode the JSON
console.log("Got websocket message " + message.data);
var display = '<div class="uk-alert uk-alert-success">'+ message.data + "</div>";
console.log("Got websocket message " + display);
UIkit.notify({
message : display,
status : 'info',
timeout : 0,
pos : 'top-center'
});
}
});
</script>
For the following snippet of code, UI kit notify is displaying the notification in the bottom left corner of the screen.
It doesn't change if I can the position to other possible values.
I must be doing something very silly. Any help is appreciated.

Message inside uikit notify is string only, maybe using div inside spoils the rest, try to make fiddle out of that.
Also notify component has its own css, be sure to include it.

Related

Session is not open when connecting to autobahn js

I'm having trouble while developing chat-like feature to my socket server.
First let me give you a little bit of my code:
document.conn = new ab.Session('ws://127.0.0.1:8090',
function () {
console.log('AB:Connected!');
conn.subscribe('room_1', function (topic, data) {
console.log('New message published to room "' + topic + '" : ' + data.content + ' by:' );
console.log(data);
});
},
function () {
console.warn('WebSocket connection closed');
},
{'skipSubprotocolCheck': true}
);
Currently it's attached to document just to try it out, the error I'm getting is as follows:
"Session not open"
I'm a bit confused about this error and it's origin, should I somehow define the connection?
do you start your socket server through cmd.exe ?
you need to use this command to start the server:
php c://wamp64/www/yourproject/bin/push-server.php

Audio shows 'Invalid source' when linking to a file on local machine using FileOpenPicker

I'm trying to write a JS Windows app. I have a button on the first page, and the click event handler code is as follows:
function pickSingleAudioFile(args) {
document.getElementById("output").innerText += "\n" + this.id + ": ";
// Create the picker object and set options
var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail;
openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary;
openPicker.fileTypeFilter.replaceAll([".mp3"]);
// Open the picker for the user to pick a file
openPicker.pickSingleFileAsync().then(function (file) {
if (file) {
// Application now has read/write access to the picked file
WinJS.log && WinJS.log("Picked file: " + file.name, "sample", "status");
document.getElementById("output").innerText += "You picked " + file.name + " from " + file.path;
// Save the file as an audio tag and load it
var audtag = document.createElement('audio');
audtag.setAttribute("id", "audtag");
audtag.setAttribute("controls", "true");
audtag.setAttribute("msAudioCategory", "backgroundcapablemedia");
audtag.setAttribute("src", "\"" + file.path + "\"");
document.getElementById("output").appendChild(audtag);
audtag.load();
} else {
// The picker was dismissed with no selected file
WinJS.log && WinJS.log("Operation cancelled.", "sample", "status");
}
});
}
The path is something like "D:\Songs\song1.mp3" or "\network-share\My Music\song name.mp3" I get the "Invalid Source" error when trying to load the file.
At first glance, this:
audtag.setAttribute("src", "\"" + file.path + "\"");
should instead be this:
audtag.setAttribute("src", file.path);
It's not clear why you are adding the backslashes. However, depending on what you are doing and based on samples I've seen, you'd be better off doing something like this:
var fileLocation = window.URL.createObjectURL(file, { oneTimeOnly: true });
audtag.setAttribute("src", fileLocation);
You might check out the "Playback Manager msAudioCategory Sample" from the Windows Dev Center for more ideas.

FB api call in for loop

I'm trying to get all facebook comments with profile pictures of commentators through fb.api() call. Currently all comments gets outputed i just can't get profile pictures to append to appropriate comment.
In for loop which loops through all comments is another FB.api call which gets the profile pic of user who commented on video and than append them into single comment block. With this code i get profile pictures of all users who commented in every single comment.
What am i doing wrong?? Thank you in advance!
var komentarji_length = response.comments.data.length;
for (var i = 0; i < komentarji_length; i++) {
var user_id = response.comments.data[i].from.id;
FB.api("/" + user_id + "/picture", {
access_token: access_token
}, function (response) {
var profile_pic_link = response.data.url;
$(".comments_profile_pic" + i).append("<img src=" + comments_profile_pic_link + ">");
});
var ime = response.comments.data[i].from.name;
var message = response.comments.data[i].message;
$(".fb_comments").append('<div class="single_comment"><div class="comments_profile_pic' + i + '"></div><div class="name">' + name + '&nbsp says:</div><div class="single_message">' + message + '</div></div>');
}
Issue 1: comments_profile_pic_link is not defined, the variable is: profile_pic_link.
But then also the problem will not be solved. When you call "/" + user_id + "/picture" it is redirected to the image url automatically. So you can directly use the image url as: https://graph.facebook.com/{user-id}/picture. No need to make the API call unnecessarily.
Example
Still if you wish to get the proper image url (not required though), use redirect=0 with your call-
FB.api("/" + user_id + "/picture?redirect=0", {
access_token: access_token
}, function (response) {
var profile_pic_link = response.data.url;
$(".comments_profile_pic" + i).append("<img src=" + comments_profile_pic_link + ">");
});

Form fill and capture fail sometimes using CasperJS

I want to fill the form and take capture of the generated page. So I wrote a CasperJS (This is my first time to use CasperJS) to archive to goal. I read the CasperJS API document but still not sure how to fix the problem.
Below is my code:
var casper = require('casper').create();
var filename = casper.cli.get(0);
var myear = casper.cli.get(1);
var mmon = casper.cli.get(2);
var stk_no = casper.cli.get(3);
casper.start('http://www.twse.com.tw/en/trading/exchange/STOCK_DAY/STOCK_DAYMAIN.php', function() {
this.fill("form[name='date_form']", {
'myear' : myear,
'mmon' : mmon,
'STK_NO': stk_no
},true);
});
casper.then(function() {
this.capture(filename);
this.echo("Saved screenshot of " + (this.getCurrentUrl()) + " to " + filename);
});
casper.run();
My command is like
casperjs test.js picture.png 2013 12 8271
Sometimes no picture file will be generated and it turns out to be failed:
Saved screenshot of http://www.twse.com.tw/en/trading/exchange/STOCK_DAY/STOCK_DAY.php to picture.png
Sometimes a picture file will be generated and it turns out to be successful:
Saved screenshot of http://www.twse.com.tw/en/trading/exchange/STOCK_DAY/genpage/Report201312/201312_F3_1_8_8271.php?STK_NO=8271&myear=2013&mmon=12 to picture.png
Why does sometime it work and give the capture but sometimes fail? Why the return value of this.getCurrentUrl() could differ?
When the current URL is http://www.twse.com.tw/en/trading/exchange/STOCK_DAY/STOCK_DAY.php, means you are blocked in the start page and waiting for the redirect, Change your
casper.then(function() {
this.capture(filename);
this.echo("Saved screenshot of " + (this.getCurrentUrl()) + " to " + filename);
});
to:
casper.waitForUrl(/Report/, function() {
this.capture(filename);
this.echo("Saved screenshot of " + (this.getCurrentUrl()) + " to " + filename);
});
/Report/ means "Report" in your current URL, so your are at the page data queried.

Is there any size limitation for ajax post?

I'm posting ckeditor content via Ajax to php. But getting 4-5 sentence of posted material in my db table. I wonder, Is there any size limitation for ajax post? is there any way to post big text contents via ajax?
My js looks like that
function postViaAjax(autosaveMode) {
var name = $("#name").val();
var title = $("#title").val();
var menu = $("#menu").val();
var parentcheck = $(".parentcheck:checked").val();
var id = $("#id").val();
if (parentcheck == 0) {
var parent = parentcheck;
} else {
var parent = $("#parent").val();
}
var content = CKEDITOR.instances['content'].getData();
var dataString = 'name=' + name + '&title=' + title + '&menu=' + menu + '&parentcheck=' + parentcheck + '&id=' + id + '&parent=' + parent + '&content=' + content;
$.ajax({
type: "POST",
url: "processor/dbadd.php",
data: dataString,
dataType: "json",
success: function (result, status, xResponse) {
var message = result.msg;
var err = result.err;
var now = new Date();
if (message != null) {
if (autosaveMode) {
$('#submit_btn').attr({
'value': 'Yadda saxlanıldı ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds()
});
} else {
$.notifyBar({
cls: "success",
html: message + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds()
});
}
}
if (err != null) {
$.notifyBar({
cls: "error",
html: err
});
}
}
});
};
The HTTP specification doesn't impose a specific size limit for posts. They will usually be limited by either the web server or the programming technology used to process the form submission.
What kind of server do you use?
There isn't any size limitation for POSTs in HTTP.
Maybe you have an & in your content variable. Then everything after that would be stripped after that.
Other than that what type do you use for your data column in the database? Is it, by any chance, something like varchar(1000)? Then anything bigger would also get stripped.
Check what you actually receive on the server end, so you know if you've got a problem with the code or the database.
You have a limitation on the Apache server. Look for LimitRequestBody directive.
This may be helpful:
http://gallery.menalto.com/node/14870
In theory the limits on AJAX requests are the same on all the other requests, so it depends on your web server/app setup. See also Max length of send() data param on XMLHttpRequest Post

Categories