SyntaxError: missing { before function body - javascript

I want to get our website up and running.
I installed a plugin for a slideshow, which then stopped the page's form automatically refreshing when closing the slideshow. After a lot of research, I put in this code to the jquery.easing.1.3.js
Now, I am able to get an automatic refresh, but my menu doesn't work.
The new error using Firefox says:
SyntaxError: missing { before function body
However, in Chrome, it says:
Unexpected token .
The website is: www.harmandisplay.com
The code in jquery.easing.1.3.js:
// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
$(document).ready{(function(): {
def: 'easeOutQuad',
swing: function (x, t, b, c, d) {
//alert(jQuery.easing.default);
return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
},
easeInQuad: function (x, t, b, c, d) {
return c*(t/=d)*t + b;
},
easeOutQuad: function (x, t, b, c, d) {
return -c *(t/=d)*(t-2) + b;
},
.... and it goes on and on.

This
$(document).ready{(function(): {
is a syntax error
remove the ':'

You have an invalid : syntax that is breaking the JavaScript code. Change
$(document).ready{(function(): {
To
$(document).ready{(function() {

Related

Add a script before </body> only on a single component - vuejs

I'm vuejs newbie, and I'm start to use the clearsale api for validations and want make a fingerprint catch for an validation, and need's call a script funcion on page's bottom only in one vuejs component. This is the script in question:
<script>
(function(a, b, c, d, e, f, g) {
a["CsdpObject"] = e;
(a[e] =
a[e] ||
function() {
(a[e].q = a[e].q || []).push(arguments);
}),
(a[e].l = 1 * new Date());
(f = b.createElement(c)), (g = b.getElementsByTagName(c)[0]);
f.async = 1;
f.src = d;
g.parentNode.insertBefore(f, g);
})(window, document, "script", "//device.clearsale.com.br/p/fp.js", "csdp");
csdp("app", "appKey");
csdp("sessionid", "sessionID");
</script>
I called out of export default scope, but thei not recognize the csdp functions.
(p.s. sorry about my english)
You should put this inline script in your public/index.html file - but without the last 2 statements (where you call the csdp function). In your component then you will write
window.csdp("app", "appKey");
window.csdp("sessionid", "sessionID");

Javascript - Uncaught TypeError: tri.Area is not a function

So i'm starting to learn ab it of JS. This is probably kinda basic since I started with it yesterday. So I have come so far that I actually got a error that I have been trying to figure out this past 2-3 hours without any results.
I'm trying to take the value from height and width where I create a own function (area) that should make a math value from height * width / 2 and then return it back to area(). and then get the value in console.log. Pretty simple but im getting a error on the last console.log for some strange reason which I cant figure out why.
function x(a, b) {
return {
a: a, b: b
}
}
function Area(a, b) {
this.a = a;
this.b = b;
this.y = this.a* this.b / 2;
return y;
}
var Snorlax = x(12, 14);
console.log(Snorlax.a);
console.log(Snorlax.b);
console.log(Snorlax.Area()); <---- Issue here
What could the issue be?
EDIT: So the issue is that im getting a issue on console.log(Snorlax.Area()); <---- Issue here where it says Snorlax.Area is not a function so basically I just wanna fix it to make this program to work. By having the console.log(Snorlax.Area()); it supposed to make the function Area to work and give me a results of a*b/2. Thats pretty much it.
EDIT2:
function x(a, b) {
return {
a: a, b: b
}
}
function Area(a, b) {
return a * b / 2;
}
var Snorlax = x(12, 14);
console.log(Snorlax.a);
console.log(Snorlax.b);
console.log(Area(Snorlax.a, Snorlax b));
In that case that would be right?
Your not passing in a,b to the Area() function
Try: console.log(Area(Snorlax.a,Snorlax.b));
Return this.y from the Area function
The reason you function is not defined is because you were calling an Area function on your x object(which does not exist). You need to call the Area function straight like above.

jquery prevent animation queue build up

I have problem, if user clicks too fast on button, animation queue is keep piling up so it stops works properly. I would need behaviors, that when he clicks on button animation will always start current animation from beginning and forget about past animations in queue.
I tried stop(true, true) and clearQueue() adding to code below, but I'm doing this based on luck because don't understand jQuery well and didn't succeed with hours of trying.
var o, s, l;
e.animate = function(n, a, r, l, u) {
o = u, s = [], i(n), t(".unddd").each(function(e, n) {
Z.enqueue(function() {
t(n).removeClass("unddd", 1, null, Z.dequeue)
})
}), Z.enqueue(function() {
t(".unindicated").addClass("used_for_hand", o, null, Z.dequeue)
}, t(".unindicated").size()), Z.enqueue(function() {
t("#paybe").addClass("highlight"), Z.dequeue()
}), Z.enqueue(function() {
}), Z.startDequeue()
}, e.animateOut = function(e) {
e ? Z.enqueue(function() {
t(".status").hide(), t(".ble").addClass("discard", o, null, Z.dequeue)
}, t(".ble").size()) : Z.enqueue(function() {
t(".ble").not(".held").addClass("discard", o, null, Z.dequeue)
}, t(".ble").not(".held").size()), Z.startDequeue()
}
You could add a boolean check "isRunning" and set it to true during your animate function, then set it to false when the animation is complete.
After that, just check isRunning == false before calling any animation methods. The animation will only run if it isnt already running.
i managed to work-around this, by disabling onclick after click and, enabling it after animation end

Replace functions in javascript (to shorten phonegap plugins commands)

I need to shorten my functions (I use them a lot, if i shorten them probably my app needs less storage)
For Example I have navigator.notification.confirm
it is a function. I call it like this : navigator.notification.confirm(a, b, c, [d, e, f, ...])
I want to shorten it as : confirm(a, b, c, [d, e, f, ...])
I used var confirm = navigator.notification.confirm but it doesn't work :(
I can use function confirm(a, b, c, d) { navigator.notification.confirm(a, b, c, d) }
but isn't there any shorter way ?
Here is an example of how I do this for navigator.notification.alert:
I put this in my function that is called from the deviceReady event.
//Shortcut for navigator.notification.alert
if (navigator.notification) {
window.alert = function (message,func,title,buttonTxt) {
if(!func){
func = null;
}
navigator.notification.alert(message, func, title, buttonTxt);
};
}
Now with this code in place, anytime I want to alert something I can do this:
alert('hi');
instead of:
navigator.notification.alert('hi');

Userscript - Replace a variable's property with a function

A website has the following code:
var Items = {
drop: function (a, b, d) {
if (!(typeof a == "undefined" || typeof sockets[a.id] == "undefined")) {
SSocket.send(sockets[a.id], {
action: "item_drop",
data: {
id: d
}
});
Inventory.add(a, d)
}
},
give_to_player: function (a, b) {
Items.drop(a, void 0, b)
},
take_from_player: function (a, b) {
var d = clients[a];
Inventory.remove(d, b);
Player.send_inventory(d.id)
},
};
I am trying to replace the give_to_player property with my own function using a userscript. However, I am having zero luck doing so. I am familiar with javascript injection and the variable scope.
I have tried the following:
Object.defineProperty(window.Item, 'give_to_player', {
value:
function(a,b){
console.log('Change occured');
}
});
This does not generate any errors, however the change does not take hold and the console remains empty. I have tried Object.defineProperties as well with no luck.
Finally the following code failed to produce results either:
window.Item.give_to_player = function(a,b){ console.log('Change occured');};
Does anyone have any suggestions?
I am using Chrome to run my userscripts.
The second method would work if you change the name to Items with a s and drop the window in the method to just Items.give_to_player = function(a,b){ console.log('Change occured');};.
EDIT: the var in var Items makes the method not accessible thru the window scope. if the var was dropped this window.Items.give_to_player won't throw error but since its there you'll not need to use the window in front of Items.(if that makes sense)
JSFIDDLE
side note: your error
window.Items.give_to_player = function(a,b){ console.log('Change occured');};
// Uncaught TypeError: Cannot set property 'give_to_player' of undefined
I really don't know how the rest of code looks like (if that object is in some particular scope, deeply nested or what) but if Items object is in global scope you can define AFTER that object (and its properties definition) again that property and that should override the previous one:
Items.give_to_player: function () {
//write your own function
}
But I'm not sure if this will work as long as I have so little information.

Categories

Resources