I always admired the stackoverflow.com website.
I also, was always curious about what the Javascript:OpenID.Signin('example') here, in the login page of the Stackoverflow.com, does.
You see, i would like to implement something similar to my website, and this one is the question that first came in my mind. (I mean provide, separate button for every different connect provider).
Please keep in mind that i am a newbie and i would prefer, if possible, simple answers.
Thank you in advance.
PS. If you are not willing to tell me what the Javascript:OpenID.Signin('example') does, could you please tell me how can i achieve the same functionality?
I am totally lost with the OpenId stuff and in any case would not like to mention the OpenID as is, in my website. I am sure it will complicate things for the users of my website too. I would prefer a solution, connect with Google, Facebook etc separate buttons.
If you view source on the page your talking about you can see a script tag for an outside file
<script type="text/javascript" src="http://sstatic.net/Js/third-party/openid-jquery.js?v=8"></script>
If you look there, you'll see it contains a global var called openid which contains a function called signin among other things.
Here's the function body if you're curious
signin: function (box_id, onload) {
var provider = providers[box_id];
if (!provider) { return; }
this.highlight(box_id);
if (box_id == 'openid') {
$('#openid_input_area').empty();
this.setOpenIdUrl("");
$("#openid_identifier").focus();
return;
}
// prompt user for input?
if (provider['label']) {
this.useInputBox(provider);
this.provider_url = provider['url'];
} else {
$('.' + box_id).css('cursor', 'wait');
if (provider['oauth_version']) {
this.setOAuthInfo(provider['oauth_version'], provider['oauth_server']);
} else {
this.setOpenIdUrl(provider['url']);
}
this.provider_url = null;
if (!onload) {
$('#openid_form').submit();
}
}
}
Related
Looking for some direction and help. I am new to JavaScript and NodeJS and have not been able to find anything online on how to do this. I've written a minesweeper game in JavaScript and would like to be able to inject user written code into the game loop instead of taking inputs.
The main problem I am running into is getting access to the methods I've built into the game class. Here's the code.
class Game {
constructor() {
this.GameBoard = new MineSweeperBoard(true);
autoBind(this);
}
pop(x ,y){
this.GameBoard.pop(x, y);
}
flag(x, y){
this.GameBoard.flag(x,y);
}
removeFlag(x,y){
this.GameBoard.RemoveFlag(x,y);
}
checkWin(){
this.GameBoard.CheckForWin();
}
getGameBoard(){
return this.GameBoard.GetRevealedGameBoard()
}
}
function StartGame() {
let CurrentGame = new Game();
let win = false;
while(CurrentGame.GameBoard.RunGame) {
//User Code here
*User written code should run right about here.*
// Check win condition
if(CurrentGame.checkWin()){
win = true;
}
}
Any help or direction would be appreciated.
*** Edit ***
To answer some question that have been asked.
1: This isn't secure: Yes I understand there are potential security implications to running user generated code. As of right now that is not a concern as this is mostly a proof of concept.
2: Why do I want to do this: Because I want to see if it's possible and I know others have found ways to securely run user code (i.e. Screeps). Right now I would like to see what is possible.
I've been working on a website of mine for about a week now. I'm very good with HTML and CSS, but I'm still trying to wrap my head around Javascript, JQuery and PHP.
Basically, what I'm trying to do is create a way if remembering the users language and locale based on their selection on a language selection page. What I'd like (if possible), is for a user to select their flag on a /locale page and make that change the url of the homepage (ie. mysite.com/en-us). I'm going to be translating my website content via static pages, not active translation.
This only has to work for the homepage, not subsequent pages, however it would be awesome if it did work for pages under different directories too. You can view a live example of my newly constructed website here.
I'd prefer Javascript or JQuery, but honestly - when someone else is doing the hard part, I don't really have the right to be picky.
Thank everyone very much in advance for any assistance.
There's two ways to achieve this: Cookies or localStorage. The easiest one is localStorage:
Here's two plain Javascript functions. The first runs onbodyload and check if the previous language choice (stored in the localStorage) was Spanish. If not (or blank), the welcome appears in English.
When you click a button, it runs the second function which changes the welcome language plus stores the choice in the localStorage.
HTML
<button onclick="language('en')">english</button>
<button onclick="language('spa')">spanish</button>
<h1><span id=welcome>text</span></h1>
JAVASCRIPT
document.getElementsByTagName("body")[0].onload=function(){session()};
function session() {
var result = localStorage.getItem("session");
if (result === 'spa') {
document.getElementById("welcome").innerHTML = "Hola!";
} else {
document.getElementById("welcome").innerHTML = "Hello!";
}
}
function language(key) {
if (key === 'en') {
document.getElementById("welcome").innerHTML = "Hello!";
localStorage.setItem("session", "en");
} else if (key === 'spa') {
document.getElementById("welcome").innerHTML = "Hola!";
localStorage.setItem("session", "spa");
}
}
Codepen DEMO
I have application.
Client side is - knockout.
so I have page with form, and i want to ask user confirametion before he will try go to another page (in case if he changed something (this pard is ready))
So routing on all website - its Sammy.js.
I tried :
Sammy JS - before
function ViewModel()
{
Sammy.before(/.*/, function () {
if (window.confirm('Really go to another page?')){
}
else{
//DO NOTHING AND STAY IN THE SAME PAGE
//OR SOMETHING ELSE THAT YOU WANT
return false;
}
});
}
its work , but its still working for all website - and its bad.
I'm not found way to disable it, so maybe I can do it without sammy???
Thank you guys!
Update: This website is SPA
You can use before, but you must specify options to show the confirmation dialog only when necessary. See the docs. You're specifying to run it for all the routes, you must specify in which routes you want it executed. Before option only gives you information on the next route. If it depends on the current route, you can get it examining the current url:
function extractSammyUrlFrom (context)
{
// get the hash fragment (curernt route)
"#" + context.path.split("#")[1] ;
}
If it depends on any other thing in your page, just check it before showing the dialog.
I really didn't know how to explain my question in the title, so I tried.
Anyways, this is my problem. I have a webpage which is basically a puzzle. The basic premise of it is that when you visit a certain link, it will trigger a function and show the next piece.
Here's one of the functions that will show the piece -
function showone() {
var elem = document.getElementById("one");
if (elem.className = "hide") {
elem.className = "show"
}
}
The reason that it's built like this, is because the pieces are constructed and placed using an HTML table, using classes to hide and show them.
What I need to do, is somehow create a URL that will trigger a new piece. For example, "www.website.com/index.html?showone" is what I'd like. This would trigger the "showone" function.
I don't know how to do this though, and after a fair bit of searching, I'm more confused than I was to begin with.
The reason I'm using JavaScript to begin with, is that the page can't refresh. I understand that this might not be possible, in which case, I'm open to any suggestions on how I could get this to work.
Thanks in advance, any suggestions would be greatly appreciated.
-Mitchyl
Javascript web application frameworks can to this for you, they allow to build web application without refresh page.
For example you can use backbonejs it has Router class inside and it very easy to use.
code is easy as :
var Workspace = Backbone.Router.extend({
routes: {
"help": "help", // #help
"search/:query": "search", // #search/kiwis
"search/:query/p:page": "search" // #search/kiwis/p7
},
help: function() {
...
},
search: function(query, page) {
...
}
});
is also you can use angularjs it is big one that supports by Google.
Maybe this solution can help you?
$("a.icon-loading-link").click(function(e){
var link = $(e.target).prop("href"); //save link of current <a> into variable
/* Creating new icon-tag, for example $("<img/>", {src: "link/to/file"}).appendTo("next/dt"); */
e.preventDefault(); //Cancel opening link
return false; //For WebKit browsers
});
I'm writing a simple Windows Gadget, but I can't seem to get the settings to save when using this functions. Here's some of the code that should get the task done, but still won't work:
var mySettings = new botanicallileo();
function botanicallileo()
{
this.kitID = "";
this.load = loadSettings;
this.save = saveSettings;
}
function saveSettings()
{
System.Gadget.Settings.writeString("test", "true");
System.Gadget.Settings.writeString("kitID", this.kitID);
}
function settingsClosing(event)
{
if (event.closeAction == event.Action.commit)
{
mySettings.save();
}
}
I must be missing something very important but I can't seem to find what it is. I know the settings aren't saving because I can check the .ini file, and nothing seems to pop up, while with other gadgets the new variables do appear and get saved in the file. Help will be appreciated.
Note: the settings "test" is just that, a test to see if anything was getting written at all. Needless to say it's not getting written.