How do I run function inside a class. Javascript - javascript

I am having hard time calling a function inside a class. When I started working on this, I had it running, but after making revisions, I cant get it working :((
You can ignore my alerts because I just put them in there to check to see if the function gets called or not.
I have function "Unit" which is a class for me. then I call it by below.
From below code, that new Unit(args) does not get completed. It stops at this.direction=this.setDirection();
and this.setDirection() is not called for some reason. Can anyone take a look and tell me what went wrong?
Thanks!
var teamBlack = [];
var bking = new Unit("black", "king", new Coords(3,1, false));
teamBlack.push(bking);
function Unit(team, type, coords) {
alert("Unit started " + count);
this.team = team;
this.type = type;
this.position = coords;
this.highlight = false;
alert("before setdirection");
this.direction = this.setDirection();
alert("this " + this.type);
this.setDirection = function () {
alert("setDirection Started ");
alert(this.type);
var tempDir = [];
switch (this.type) {
case "king" :
alert("this is king");
tempDir = [this.N(), this.NW(), this.W(), this.SW(), this.S(), this.SE(), this.E(), this.NE()];
break;
case "bishop" :
tempDir = [this.NW(), this.SW(), this.SE(), this.NE()];
break;
case "rook" :
tempDir = [this.N(), this.S(), this.W(), this.E()];
break;
case "pawn" :
{
if (this.team == "white") {
tempDir = [this.S()];
} else {
tempDir = [this.N()];
}
break;
}
case "queen" :
{
if (this.team == "white") {
tempDir = [this.N(), this.W(), this.SW(), this.S(), this.SE(), this.E()];
} else {
tempDir = [this.N(), this.NW(), this.W(), this.S(), this.E(), this.NE()];
}
break;
}
}
tempDir = tempDir.filter(function (dir) {
return dir.x > -1 && dir.x < 3 && dir.y > -1 && dir.y < 4 && dir.c == false;
});
return tempDir;
}
}

This code is wrong because you try call function that is not exist yet in your class. I recommend you to move this function in prototype. For example:
function Unit() {
//this is your constructor
}
Unit.prototype.setDirection = function() {
//your code of setDirection function
}

Make sure variables are defined, then put this.setDirecton = function()... before calling this.setDirection().
See JSFiddle.

You need to use the setDirection function as a prototype of your Unit class.
Unit.prototype.setDirection = function() {
//setDirection functionality
}
Within the prototype you have access to your class properties via this.
Check this jsFiddle: https://jsfiddle.net/urtr3quc/

I would improve your code by separating the responsibilities:
//create the class Unit
function Unit(team, type, coords) {
alert("Unit started " + count);
this.team = team;
this.type = type;
this.position = coords;
this.highlight = false;
}
Then you specify new method for your class:
Unit.prototype.setDirection = function () {
alert("setDirection Started ");
alert(this.type);
var tempDir = [];
switch (this.type) {
case "king" :
alert("this is king");
tempDir = [this.N(), this.NW(), this.W(), this.SW(), this.S(), this.SE(), this.E(), this.NE()];
break;
case "bishop" :
tempDir = [this.NW(), this.SW(), this.SE(), this.NE()];
break;
case "rook" :
tempDir = [this.N(), this.S(), this.W(), this.E()];
break;
case "pawn" :
{
if (this.team == "white") {
tempDir = [this.S()];
} else {
tempDir = [this.N()];
}
break;
}
case "queen" :
{
if (this.team == "white") {
tempDir = [this.N(), this.W(), this.SW(), this.S(), this.SE(), this.E()];
} else {
tempDir = [this.N(), this.NW(), this.W(), this.S(), this.E(), this.NE()];
}
break;
}
}
tempDir = tempDir.filter(function (dir) {
return dir.x > -1 && dir.x < 3 && dir.y > -1 && dir.y < 4 && dir.c == false;
});
alert("before setdirection");
this.direction = tempDir;//setMethod doesn't return thing but set something somewhere
alert("this " + this.type);
};
and now you invoke your class instance:
var teamBlack = [];
var bking = new Unit("black", "king", new Coords(3,1, false));
bking.setDirection();
teamBlack.push(bking);
I suggest you to take a look on this link

Related

Photoshop ScriptUI Slider Indicator

The script writes the slider indicator position value to the xml file. But it fails to read and set the xml value.
The alert box in the save/read xml functions lists the xml variables. I am expecting the slider indicator to match the numerical vlaue in the xml variable.
I have a feeling the issue is with the switch statements in the read/write xml functions. Are these lines correct?
Read function:
case 'slider': myXML[a] = o[a].value; break;
Write function:
case 'slider': o[a].value = myXML[a] != '' ? (myXML[a] == 'true' ? 1 : 0) : o[a].value; break;
Reference screenshots. The slider indicator is at 0 instead of 63.
var w = new Window("dialog","test",undefined,{closeButton: true});
var group1 = w.add("group");
mySlider = group1.add("slider");
mySlider.minvalue = 0;
mySlider.maxvalue = 100;
//mySlider.value = 0;
mySlider.preferredSize.length = 195;
mySlider.preferredSize.height = 15;
mySliderEtxt = group1.add("edittext",undefined,"0");
mySliderEtxt.preferredSize=[50,20];
mySlider.onChanging = function(){
mySliderEtxt.text = mySlider.value;
}
mySliderEtxt.onChanging = function(){
mySlider.value = mySliderEtxt.text;
}
ok = group1.add("button", undefined, "Set", { name: "set" })
cancel = group1.add("button", undefined, "Close", { name: "close" })
settingsSlider1 = { sliderOne: mySlider, textItemOne: mySliderEtxt}
ok.onClick = function () {
w.close()
saveToXML(settingsSlider1, 'Simple Sider')
}
cancel.onClick = function () {
w.close()
}
w.onShow = function () {
readFromXML(settingsSlider1, 'Simple Sider')
}
w.show();
function saveToXML(o, xmlName) {
var f = new File(Folder.desktop + '/' + xmlName + '.xml'),
myXML = new XML('<variables></variables>');
for (var a in o) {
switch (o[a].type) {
case 'edittext': myXML[a] = o[a].text; break;
case 'checkbox': myXML[a] = o[a].value; break;
case 'radiobutton': myXML[a] = o[a].value; break;
case 'dropdownlist': myXML[a] = o[a].selection ? o[a].selection.text : ''; break;
case 'slider': myXML[a] = o[a].value; break;
}
}
alert('Save XML \n'+myXML);
f.encoding = "UTF8"
f.open('w');
f.write(myXML.toXMLString())
f.close();
}
function readFromXML(o, xmlName) {
var f = new File(Folder.desktop + '/' + xmlName + '.xml');
f.encoding = "UTF8";
f.open('r');
var myXML = new XML(f.read());
f.close();
for (var a in o) {
switch (o[a].type) {
case 'edittext': o[a].text = myXML[a] != '' ? myXML[a] : o[a].text; break;
case 'checkbox': o[a].value = myXML[a] != '' ? (myXML[a] == 'true' ? 1 : 0) : o[a].value; break;
case 'radiobutton': o[a].value = myXML[a] != '' ? (myXML[a] == 'true' ? 1 : 0) : o[a].value; break;
case 'dropdownlist': o[a].selection = myXML[a] != '' ? o[a].find(myXML[a]) : 0; break;
case 'slider': o[a].value = myXML[a] != '' ? (myXML[a] == 'true' ? 1 : 0) : o[a].value; break;
}
}
alert('Read XML \n'+myXML);
f.encoding = "UTF8"
f.open('w');
f.write(myXML.toXMLString())
f.close();
}
You have to add one line:
w.onShow = function () {
readFromXML(settingsSlider1, 'Simple Sider');
mySlider.value = mySliderEtxt.text; // <-------------- HERE
}

calculator in angular js using directives

I'm new to Angular js and trying to build a calculator. My requirement is that I need two separate directives each for textbox (to display) and for buttons.
The problem is that I'm getting the result, but the text box is not getting updated.
Below is the code that I have written.
Script File :
var app = angular.module("app",[]);
app.service('sharedProperties', function () {
var showInput = '0';
return {
getProperty: function () {
return showInput;
},
setProperty: function(value) {
showInput = value;
}
};
});
app.controller('myCtrl', function($scope,sharedProperties) {
$scope.count = ['0','1','2','3','4','5','6','7','8','9','+','-','*','/','=','C']; $scope.showInput2 = sharedProperties.getProperty();
}); app.directive("textdir",function() { return { restrict : 'E', template : "<input type ='text' value='{{showInput2}}' id='txt'><br/>" }; });
app.directive('counter',
function() {
return {
restrict: 'EAC',
template: '<div>'+
'<button ng-repeat="i in internalCount" ng-click="kick(i)">{{i}}</button>'+
'</div>',
scope: {
internalCount: '=model'
}, controller : function($scope,sharedProperties) {
$scope.op1="";
$scope.op2="";
$scope.tempStr="";
$scope.isContinue = true;
$scope.showInput1 = sharedProperties.getProperty();
$scope.kick = function(clickvalue)
{
switch(clickvalue)
{
case "=":
if ($scope.tempStr != "" && $scope.op1!= "")
{
if($scope.op2=="")
{
$scope.showInput1 = $scope.clac($scope.tempStr, $scope.showInput1, $scope.op1);
}
if(($scope.op1=="*"||$scope.op1=="/") && $scope.op2=="-")
{
$scope.showInput1 = -$scope.showInput1;
$scope.showInput1 = $scope.clac($scope.tempStr, $scope.showInput1, $scope.op1);
}
if($scope.op1=="-" && ($scope.op2=="*"||$scope.op2=="/"))
{
$scope.tempStr = -$scope.tempStr;
$scope.showInput1 = $scope.clac($scope.tempStr, $scope.showInput1, $scope.op2);
}
alert($scope.showInput1);
$scope.op1="";
$scope.op2="";
}
break;
case "+":
case "-":
case "*":
case "/":
if($scope.op1=="")
{
$scope.tempStr = $scope.showInput1;
$scope.isClear=true;
$scope.op1=clickvalue;
}
else
{
$scope.tempStr = $scope.showInput1;
$scope.isClear=true;
$scope.op2=clickvalue;
}
break;
case "C":
$scope.showInput1 = "0";
$scope.isClear = false;
$scope.tempStr = "";
$scope.clacType = "";
break;
default :
$scope.showInput1 = $scope.showInput1 == "0" ? "" : $scope.showInput1;
$scope.isContinue = false;
if ($scope.isClear)
{
$scope.showInput1 = "";
$scope.showInput1 += clickvalue;
$scope.isClear = false;
}
else
{
$scope.showInput1 += clickvalue;
}
//alert($scope.showInput);
break;
}
}
$scope.clac = function(num1,num2,type) {
switch (type)
{
case "+":
return parseFloat(num1) + parseFloat(num2);
case "-":
return parseFloat(num1) - parseFloat(num2);
case "*":
return parseFloat(num1) * parseFloat(num2);
case "/":
return parseFloat(num1) / parseFloat(num2);
default:
return "lkl";
break;
} } }
};
});
HTML File :
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.js"></script>
<script src = "AngularCalci.js"></script>
</head>
<body>
<div ng-app="app">
<div ng-controller="myCtrl">
<div>
<textdir/>
</div>
<counter model="count"></counter>
</div>
</div>
</body>
</html>
Every time you see 0 and it is not changing at all. The reason is it has been initialized to 0 and its value was never set to other value after that.
You need to call the set function. You have missed to add this code.
sharedProperties.setProperty(value);
UPDATE:
I have observed one more problem with the way you are setting the value back to the textbox.
If you see this line in the controller, it executes only at the beginning. But your data may change anytime during the execution. So also need take care of this scenario.
$scope.showInput2 = sharedProperties.getProperty();
You may need to dig more about events($broadcast, $emit, $on) and watchers($watch) to solve this issue.

javascript scope, perm cant get correct variable

i cant get perm from function !!
there is scope problem here
var perm = "none";
var participantsPromise = getChannelParticipants(peerID * -1).then(
function (participants) {
angular.forEach(participants, function (participant){
if (participant.user_id == UserID) {
switch (participant._) {
case "channelParticipant":
perm = "normal";
console.log('->>>>>>> Perm = normal');
break;
case "channelParticipantEditor":
perm = "Admin";
console.log('->>>>>>> Perm = Admin');
break;
case "channelParticipantModerator":
perm = "Admin";
console.log('->>>>>>> Perm = Admin');
break;
case "channelParticipantCreator":
perm = "Creator";
console.log('->>>>>>> Perm = Creator');
break;
default:
console.log('#########> No handler for', participant._);
perm = "unknown";
}
}
})
});
return perm;
function return none , but perm already set on other values .
what can i do ?
Try this one
var perm = "none";
var participantsPromise = getChannelParticipants(peerID * -1).then(
function (participants) {
if (participants.user_id == UserID) {
switch (participants._) {
case "channelParticipant":
perm = "normal";
break;
case "channelParticipantEditor":
perm = "Admin";
break;
case "channelParticipantModerator":
perm = "Admin";
break;
case "channelParticipantCreator":
perm = "Creator";
break;
default:
console.log('No handler for', participants._);
perm = "unknown";
}
// perm variable is normal :)
} else {
console.log('userid does not match');
perm = "userId Error";
}
});
I believe the problem is that you're trying to read value of perm synchronously, while it's changed in the asynchronous callback.
var perm = "none"; // here value of `perm` is "none"
var participantsPromise = getChannelParticipants(peerID * -1).then(
function(participants) {
if (participants.user_id == UserID) {
switch (participants._) {
...
case "channelParticipantCreator":
perm = "Creator";
break;
}
// perm variable is normal :)
}
});
console.log(perm) // perm is back to none - yes,
// because the code `function(participants) ` hasn't yet
// been executed, since it's asynchronous
// let's add a delayed callback that will wait until async code finishes executing
var timeToFinishGetChannelParticipants = 10000; // 10 seconds
setTimeout(function() {
console.log(perm); // here it should have value set inside `function(participants)`
}, timeToFinishGetChannelParticipants);
UPDATE:
function getPerm() {
return getChannelParticipants(peerID * -1).then(
function (participants) {
if (participants.user_id == UserID) {
switch (participants._) {
case "channelParticipant":
return "normal";
break;
case "channelParticipantEditor":
return "Admin";
break;
case "channelParticipantModerator":
return "Admin";
break;
case "channelParticipantCreator":
return "Creator";
break;
default:
console.log('No handler for', participants._);
return "unknown";
}
// perm variable is normal :)
} else {
console.log('userid does not match');
return "userId Error";
}
});
}
// outer code
getPerm().then(function(perm) {
console.log(perm);
});

Cannot read property length of undefined - Javascript

I'm new in javascript the main goal of this code is to type a question in the textbox the browser will check the question if it was in the switches statements and get the answer than write it on the paragraph's id="lable".
The function randomArray(z)-line[8]- return a random array value .
What's hapenning : Typed :"undefined" on the paragraph which has "lable" as an id .
.........................
The HTML code :
<body>
<img src="Alexs_face.png">
<p style="border:2px black solid; margin:100px 400px 50px 400px">Ask me !</p>
<p id="lable"></p>
<input id="input" type="text" autocomplete="off">
<input id="send" type="button" onclick="dosome()" value="Send">
<input id="delete" type="button" onclick="deleteVal()" value="Delete"></body>
The Javascript:
var greating , userName;
var firstHello = [[greating+userName+", How can I help you ?" ], ["Hi "+userName+" how can i help ?"] ,[ greating+", how can i help ?"]];
dosome () ;
function randomArray (z) {
var index = Math.floor(Math.random() * z.length);
return z[index];
};
function getVal() {
write(randomArray (firstHello)); /* <------ trying to write a radom value from the firstHello array
*/
var ask = document.getElementById("input").value;
return ask ;}
var ask = getVal();
function write (x){
var lable = document.getElementById("lable").innerHTML = x;
return lable ;
};
//Capitalize the first letters func :
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
//..............
//............................... you can ignore this function
function dosome () {
var ask = getVal();
var question = ask.split(" ");
var date = new Date().toTimeString().split(" ")[0]; ;
var userName ="Med" ;
//5// give you different "greatings" according to ur time
if (date >= "06:00:00" && date <="11:00:00"){
greating = "Good morning ";
var alertTime=""
}
else if (date >= "11:00:00" && date <= "15:00:00"){
greating = "Good afternoon ";
var alertTime=""
}
else if (date >= "15:00:00" && date <="22:00:00"){
greating = "Good evening ";
var alertTime=""
}
else {
greating = " You should have some sleep !";
var alertTime = greating ;
};
//5//end
//
if (question[0] === "what"){
switch ( question[1]){
case "time":
switch (question[2]){
case "is":
switch (question[3]){
case "it":
write("The time is :"+date+alertTime);
break;
default:
};
break;
default:
} ;
break;
case "is":
switch (question[2]){
case "your" :
switch (question[3]){
case "name":
write("Alex !");
break;
case "father":
write("Medardo Erabti , he made me !");
break;
default:
};
break;
case "my":
switch (question[3]){
case "name":
write("Alex !");
break;
default:
};
break;
default:
};
break;
default: write("unknown");
};}
else if (question[0] === "my"){
switch (question[1]){
case "name":
switch(question[2]){
case "is":
userName = capitalize(question[3]);;
alert("Your name is saved, "+userName);
break;
default:
};
break;
default:
};
}
else if (question[0] === "should" || "could" || "may" || "can" ) {
switch (question[1]) {
case "i" :
switch(question[2]){
case "sleep":
write("Sure ! you can sleep if you want to !!");
break;
default:
}
break;
default:
};
}
if (question[0] === "who"){
switch (question[1]){
case "are":
write ("I'm Alex !");
break;
case "am":
write ("My leader !");
default:
}
};
return userName,greating ;
};
function deleteVal () {
var x = document.getElementById("lable").innerHTML = "" ;
return x ;
};
What I have tried:
Tried to disable the 'z' parametr in the function 'randomArray(z)' and replace it with the name of the array "firstHello" , Its type "undefined in the paragraf that has "lable" as an id .
In the dosome function you create a local variable named userName, the same as the global variable. The local variable will shadow the global variable for the code inside the function, so the global variable will still be undefined after calling the function.
Notes about the code in the randomArray function:
You are using Math.floor instead of Math.random.
Don't use Math.round when creating an integer random number, that will make the first and last number occur half as often as the other numbers. Use Math.floor instead.
Your loop goes two items beyond the last item in the array.
You don't need to loop at all to get an item with a specific index.
Here is code that just shows the modified randomArray function and code to call it:
var greating = 'Hello', userName = 'sir';
var firstHello = [
[ greating + " " + userName + ", How can I help you ?" ],
[ "Hi " + userName + " how can i help ?" ],
[ greating + ", how can i help ?" ]
];
function randomArray(z) {
var index = Math.floor(Math.random() * z.length);
return z[index];
}
console.log(randomArray(firstHello));

Need help converting from prototype to jQuery

I need help converting the below code. I have a software that uses prototype but it really really conflicts with jquery. I have used online auto scripts to translate code, did nothing, i tried to manually do it but i don't have enough knowledge, and i tried using $.noconflict but it had no effect, and no help. - Please if anyone can help with the code below:
var menuList = new Array();
var buttonList = new Array();
var scriptList = new Array();
/* Ajax post request */
function scriptDoLoadPost(scriptUrl, scriptForm, scriptPos, scriptArgs, noLoading) {
if(!scriptArgs){ var scriptArgs = ''; }
scriptArgs = $(scriptForm).serialize() + scriptArgs;
myAjax = new Ajax.Updater(scriptPos, scriptUrl, {
method : 'post',
parameters : scriptArgs,
evalScripts : true,
onLoading: function(request){ showLoadingIcon(scriptPos, noLoading); },
insertion : Insertion.Append
});
}
/* Ajax get request */
function scriptDoLoad(scriptUrl, scriptPos, scriptArgs, noLoading) {
myAjax = new Ajax.Updater(scriptPos, scriptUrl, {
method : 'get',
parameters : scriptArgs,
evalScripts : true,
onLoading : function(request){ showLoadingIcon(scriptPos, noLoading); },
insertion : Insertion.Append
});
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
/* site map request */
function sitemapDoLoadPost(scriptUrl, scriptForm, scriptPos, scriptArgs, noLoading) {
hideDiv('proceed');
showDiv('message');
if(!scriptArgs){ var scriptArgs = ''; }
scriptArgs = $(scriptForm).serialize() + scriptArgs;
myAjax = new Ajax.Updater(scriptPos, scriptUrl, {
method : 'post',
parameters : scriptArgs,
evalScripts : true,
onLoading: function(request){ showLoadingIcon(scriptPos, noLoading); }
});
}
/* Onloading image icon function */
function showLoadingIcon(scriptPos,noLoading){
loading = 0;
contentDiv = "";
switch (scriptPos){
case "content":
contentDiv = '<div id="loading_content"></div>';
loading = 1;
break;
case "subcontent":
contentDiv = '<div id="loading_subcontent"></div>';
loading = 1;
break;
case "ContentFrame":
contentDiv = '<div id="loading_content_frame"></div>';
loading = 1;
break;
case "subcontmed":
contentDiv = '<div id="loading_subcontmed"></div>';
loading = 1;
break;
case "newsalert":
contentDiv = '<div id="loading_longthin"></div>';
loading = 1;
break;
default :
contentDiv = '<div id="loading_rankarea"></div>';
loading = 1;
break;
}
if((loading == 1) && (noLoading != 1)){
document.getElementById(scriptPos).innerHTML = contentDiv;
}
}
function confirmLoad(scriptUrl, scriptPos, scriptArgs) {
if (chkObject('wantproceed')) {
wantproceed = "Do you really want to proceed?";
}
var agree = confirm(wantproceed);
if (agree)
return scriptDoLoad(scriptUrl, scriptPos, scriptArgs);
else
return false;
}
function confirmSubmit(scriptUrl, scriptForm, scriptPos, scriptArgs) {
if(!scriptArgs){ var scriptArgs = ''; }
if (chkObject('wantproceed')) {
wantproceed = "Do you really want to proceed?";
}
var agree = confirm(wantproceed);
if (agree)
return scriptDoLoadPost(scriptUrl, scriptForm, scriptPos, scriptArgs);
else
return false;
}
function doAction(scriptUrl, scriptPos, scriptArgs, actionDiv) {
actVal = document.getElementById(actionDiv).value;
scriptArgs += "&sec=" + actVal;
switch (actVal) {
case "select":
break;
case "checkstatus":
case "edit":
case "reports":
case "viewreports":
case "pagedetails":
scriptDoLoad(scriptUrl, scriptPos, scriptArgs);
break;
default:
/* check whether the system is demo or not */
if(spdemo){
if((actVal == 'delete') || (actVal == 'Activate') || (actVal == 'Inactivate') || (actVal == 'recheckreport')
|| (actVal == 'showrunproject') || (actVal == 'checkscore') || (actVal == 'deletepage') || (actVal == 'upgrade') || (actVal == 'reinstall') ){
alertDemoMsg();
}
}
confirmLoad(scriptUrl, scriptPos, scriptArgs);
break;
}
}
function doLoad(argVal, scriptUrl, scriptPos, scriptArgs) {
actVal = document.getElementById(argVal).value;
scriptArgs += "&"+ argVal +"=" + actVal;
scriptDoLoad(scriptUrl, scriptPos, scriptArgs);
}
function doLoadUrl(argVal, scriptUrl) {
actVal = document.getElementById(argVal).value;
window.location = scriptUrl += "&"+ argVal +"=" + actVal;
}
/* func to show hide menu */
function showMenu(button, scriptPos){
for (var i=0; i<menuList.length; i++) {
if(menuList[i] == scriptPos){
var but = document.getElementById(button).src;
if(but.match("more") == "more"){
but = but.replace(/more/,"hide");
document.getElementById(scriptPos).style.display = '';
document.getElementById(button).src = but;
// load default script
if(typeof(scriptList[i]) != "undefined") {
scriptDoLoad(scriptList[i], 'content')
}
}else{
but = but.replace(/hide/,"more");
document.getElementById(scriptPos).style.display = 'none';
document.getElementById(button).src = but;
}
}else{
var butClose = document.getElementById(buttonList[i]).src;
if(butClose.match("hide") == "hide"){
butClose = butClose.replace(/hide/,"more");
document.getElementById(menuList[i]).style.display = 'none';
document.getElementById(buttonList[i]).src = butClose;
}
}
}
}
function updateArea(scriptPos, content) {
document.getElementById(scriptPos).innerHTML += content;
}
function chkObject(theVal) {
if (document.getElementById(theVal) != null) {
return true;
} else {
return false;
}
}
function checkSubmitInfo(scriptUrl, scriptForm, scriptPos, catCol) {
if(chkObject('captcha')){
value = document.getElementById('captcha').value;
if (value==null||value==""){
alert('Please enter the code shown');
return false;
}
}
var obj = document.getElementsByName(catCol).item(0);
value = obj.value;
if (value==null||value==""||value==0){
alert('Please select a category');
return false;
}
scriptDoLoadPost(scriptUrl, scriptForm, scriptPos);
}
function loadJsCssFile(filename, filetype){
if (filetype=="js"){ //if filename is a external JavaScript file
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
}else if (filetype=="css"){ //if filename is an external CSS file
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref)
}
function hideDiv(scriptPos){
document.getElementById(scriptPos).style.display = 'none';
}
function showDiv(scriptPos){
document.getElementById(scriptPos).style.display = '';
}
function crawlMetaData(url,scriptPos) {
weburl = document.getElementById('weburl').value;
if(weburl==null||weburl==""||weburl==0){
alert('Website url is empty!');
}else{
url = url + "&url=" + escape(weburl);
scriptDoLoad(url, scriptPos);
}
}
function hideNewsBox(scriptPos, cookieVar, cookieVal) {
hideDiv(scriptPos);
createCookie(cookieVar, cookieVal, 1);
}
function alertDemoMsg(){
if(spdemo){
alert('Some features are disabled in the demo system due to security threats. Please download and install seo panel to enjoy full features.');
exit;
}
}
function checkDirectoryFilter(checkId, scriptUrl, scriptPos){
var noFilter = 0;
if(document.getElementById(checkId).checked){
noFilter = 1;
}
scriptUrl = scriptUrl + "&" + checkId + "=" + noFilter;
scriptDoLoad(scriptUrl, scriptPos);
}
function checkList(checkId) {
checkall = document.getElementById(checkId).checked;
for (i = 0; i < document.listform.elements.length; i++){
if(document.listform.elements[i].type=="checkbox") {
document.listform.elements[i].checked = checkall ? true : false;
}
}
}
function selectAllOptions(selectBoxId, selectAll) {
selectBox = document.getElementById(selectBoxId);
for (var i = 0; i < selectBox.options.length; i++) {
selectBox.options[i].selected = selectAll;
}
}
Here is a site comparing the commands from Prototype to the jQuery equivalents, you should find what you need for translation:
http://andykdocs.de/andykdocs/document/Migrating-from-the-Prototype-JavaScript-Framework-to-jQuery/Prototype-JS-to-jQuery-Migration-Cheat-Sheet-V1-April-2010.html

Categories

Resources