Adding skype button with variable user - javascript

I have a site that creates a profile page on the fly. I want to add a skype button to the page for each of the profiles - each profile having a different ID.
I have found this code:
<script type="text/javascript" src="http://www.skypeassets.com/i/scom/js/skype-uri.js"></script>
<div id="SkypeButton_Call_skypeid_1">
<script type="text/javascript">
Skype.ui({
"name": "call",
"element": "SkypeButton_Call_skypeid_1",
"participants": ["skypeid"],
"imageSize": 32
});
</script>
This is just pasted into a php file at the moment.
I need to change the skypeid on the fly - I can do it for the html bits easy enough since I have a php variable for skypeid.
How do I pass this variable into the javascript?

<script type="text/javascript" src="http://www.skypeassets.com/i/scom/js/skype-uri.js"></script>
<div id="SkypeButton_Call_skypeid_1">
<script type="text/javascript">
Skype.ui({
"name": "call",
"element": "SkypeButton_Call_skypeid_1",
"participants": ["<?php echo $skypeid ?>"],
"imageSize": 32
});
</script>
should be what you need. If you cant access that script directly define a global javascript variable and pass that to the script

Related

TaffyDB, error says TAFFY is not a function

I'm working on a web-based game with HTML, CSS & JavaScript, using Visual Studio. I'm using TaffyDB as a database. However, whenever I try to create a database using the function TAFFY, an error shows up on the console, saying that TAFFY isn't a function. I'm not sure where the mistake is, I believe I've linked the JS files to the HTML correctly, here are all the ways I've tried:
<script type="text/javascript" src="/taffy-min.js"></script>
<script type="text/javascript" src="./taffy-min.js"></script>
<script type="text/javascript" src="taffy-min.js"></script>
<script type="text/javascript" src="https://github.com/typicaljoe/taffydb/blob/master/taffy.js"
I have also tried including the full path, and for all of the above I tried it using 'taffy.js' instead of 'taffy-min.js'. I have also tried it with and without jQuery:
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>
I am not sure if the mistake is the JS files not linking to the HTML properly, or if it's something entirely different. Code I used to set up a user:
var users = TAFFY([
{
"id": 1,
"user": "John123",
"level": 5,
"gameType: "easy"
}]);
First of all you have missing double quotes here: "gameType: "easy", should be "gameType": "easy". The error is saying that TAFFY is not a function: this means that there's another variable in the scope named TAFFY.
In order to check if the taffy script is linked correctly open the console and type typeof this.TAFFY which should print "function". Hope this helps.

Cannot get access to Marionette module from app.js

I am currently working my way through David Sulc's excellent "Backbone.Marionette.js: A Gentle Introduction" and have come unstuck at modules. With the app as it currently stands I am trying to access an API in a module called 'contacts.js' from the index.html script but I get the following error when I try to run the app:
"Handler not found for 'contact: entities' "
I am able to hit the API directly from the console in Chrome and manually get the 'contact' information so I was thinking this was a loading sequence problem where the API might not be available by the time app.js loads, however the loading sequence is as follows:
<script type="text/javascript" src="assets/js/vendor/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="assets/js/vendor/json2.js"></script>
<script type="text/javascript" src="assets/js/vendor/underscore-min.js"></script>
<script type="text/javascript" src="assets/js/vendor/backbone-min.js"></script>
<script type="text/javascript" src="assets/js/vendor/backbone.marionette.min.js"></script>
then the local scripts as follows:
<script type="text/javascript" src="assets/js/app.js"></script>
<script type="text/javascript" src="assets/js/entities/contact.js"></script>
and a script tag below the last two script tags directly runs the following code:
<script type="text/javascript">
... some view code
ContactManager.on("initialize:after", function(){
var contacts = ContactManager.request("contact: entities");
... some more code
</script>
the line beginning var contacts = ..... is the one giving me the error. Any help appreciated
I am as certain as I can be that I have scripted this exactly as per the book.
You have a space in your event name:
<script type="text/javascript">
... some view code
ContactManager.on("initialize:after", function(){
// Remove the space in contact: entities -->
var contacts = ContactManager.request("contact: entities");
... some more code
</script>

i18n Javascript Setup

I am trying to set up a simple dynamic page using i18n's javascript library. I am using their sample code of of their home page found here:
http://i18next.com/index.html
I can't get it to load the outlined json data, based on the sample html, javascript, and json code outlined below. Please let me know if there is a step, or a file naming convention I am missing.
home.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="../jquery.js" ></script>
<script type="text/javascript" src="../i18next.js" ></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<ul class="nav">
<li></li>
<li></li>
<li></li>
</ul>
<p>Test Paragraph</p>
</body>
</html>
script.js
i18n.init(function(t) {
// translate nav
$(".nav").i18n();
// programatical access
var appName = t("app.name");
});
data.json
{
"app": {
"name": "i18next"
},
"nav": {
"home": "Home",
"page1": "Page One",
"page2": "Page Two"
}
}
Any suggestions would be helpful.
Thanks!
if not configured i18next will load resources with this schema:
locales/__lng__/__ns__.json
if no namespace is set it will use translation as namespace. so if you rename your data.json to translation.json and put it into the folder location/en (or whatever language you got) it should work.
more about initialization could be found here
http://i18next.com/pages/doc_init.html

Help with Javascript in wordpress

I'm trying to add a java script slide show to my wordpress home page. In my theme folder I have a js folder and then in that I have jquery.cross-slide.min.js and jquery.min.js
This is what I have and what I'm pasting into my post area
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.cross-slide.min.js"></script>
<script type="text/javascript">
function() {
crossSlide({
sleep: 3,
fade: 1
}, [
{ src: 'images/slideshows/block1.jpg' },
{ src: 'images/slideshows/block2.jpg' },
{ src: 'images/slideshows/block3.jpg' }
])
});
</script>
If I paste this into a wordpress page throught the html editor it doesn't work. Please could you check for errors and advice.
See the Wordpress Codex: JavaScript in Posts.
For the occasional or one time use of
Javascript, you need to put the script
into a Javascript file and then call
it out from within the post. Make sure
that each script is defined by its
function name such as:
function updatepage(){var m="Page updated "+document.lastMo.......}
To include a Javascript inside a post,
you need to combine both the call to
the script file with the call to the
Javascript itself.
<script type="text/javascript" src="/scripts/updatepage.js"></script>
<script type="text/javascript">
<!--
updatepage();
//--></script>

MVC partial views and Unobtrusive jQuery/Javascript

I'm struggling to work out how I should be authoring my partial views which use jQuery.
For example, in the partial view below, I am displaying a text box which is hooked up to the jquery autocomplete plugin.
Eventually I want the results to be shown with an "X" next to them which the user can then remove, but for the purpose of this example the selected text is simply appended to the sibling div.
Is my jQuery code OK sitting here in the partial view, or should I be putting it in an external file? If an external file is used, then another developer using the partial view will need to be aware that the external js file should be included - is that OK?
I suppose my question really is that, although I'm kind of OK with jQuery (finding elements in the DOM, calling actions asynchronously etc..), I need some sort of guidance on where to put all this code that will stop me getting in a mess.
Does any of what I have just typed make sense????
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$(".acEmployee").autocomplete({
source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"],
select: function(event, ui) {
$(this).siblings().append(ui.item.value);
}
});
});
</script>
<div><div></div><input class="acEmployee" /></div>
If the JavaScript is "hookup" code then I don't mind it being in with the partial - as after all, everything it relates to is there.
If the JavaScript is "framework" code and can be reused all over the place, and isn't dependant on anything in the partial then I put it in its own file.
That's just what I do, but I'd be interested in hearing other peoples methods too.
If possible, keep all your js code in an external js files. That way you can put your jquery includes at the bottom of the page.
for .net mvc try something like:
<!--try fetching jquery from CDN, if CDN is down, fallback to local-->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='<%:Url.Content("~/Scripts/jquery-1.5.1.min.js")%>' type='text/javascript'%3E%3C/script%3E"));
}
</script>
<script type="text/javascript" language="javascript">
var MVC_baseurl = "<%:Url.Content("~/") %>";
</script>
<script type="text/javascript" language="javascript" src="<%:Url.Content("~/Scripts/jquery-ui-1.8.10.custom.min.js")%>"></script>
<script type="text/javascript" language="javascript" src="<%:Url.Content("~/Scripts/plugins.js")%>"></script>
<asp:ContentPlaceHolder ID="BottomJavascript" runat="server">
</asp:ContentPlaceHolder>
You can then put your page-specific stuff in the content placeholders. , your master page specific plugins in plugins.js, and you can use
var path = MVC_baseurl + "Controller/Action"
and use that in your ajax calls etc...

Categories