How can I exit the each function when the conditions was true once?
This does not work:
$$('.box div').each(function(e) {
if(e.get('html') == '') {
e.set('html', 'test');
exit;
}
});
Hey,
Im really interested in the way of using lamda functions. Does it make sense to use them in a high-level programming language? If yes, why?
Is this really just a function embedded in a function, (Like this) or is there more behind?
Does code in the constructor add to code in subclass constructors? Or does the subclass's constructor override the superclass? Given this example superclass constructor:
class Car{
function Car(){
trace("CAR")
}
}
...and this subclass constructor:
class FordCar extends Car{
function FordCar(){
trace("FORD")
}
}
When an instance of FordCar is created, will this trace "Car" and "Ford" ??
I want to have site wide default settings for all jQuery validation uses on my site, I want every form to use the below settings, but then on a per form basis change the rules and messages. Is this possible?
$('#myForm').validate({
errorClass: 'field-validation-error',
errorElement: 'span',
errorPlacement: function(error, element) {
element.next('span').remove();
error.insertAfter( element )
.removeClass('field-validation-error')
.addClass('ui-state-error');
},
success: function(label) {
label.remove();
}
});
Hi, how can i make this code to don't pause the browser but still return value.
You can rewrite this with new method of course.
function get_char_val(merk)
{
var returnValue = null;
$.ajax({
type: "POST",
async: false,
url: "char_info2.php",
data: { name: merk },
dataType: "html",
success: function(data)
{
returnValue = data;
}
});
return returnValue;
}
var px= get_char_val('x');
var py= get_char_val('y');
Hi!
I have a js function that is named getID which is basically return document.getElementById(id)
I want to make another function, getTag that would return getElementsByTagName.
The part that I can't seem to manage is that I want to be able to call them like this:
getID('myid').getTag('input') = so this would return all the input elements inside the element with the id myid
Thanks!
ps: getTag would also have to work if it's called by it's own, but then it would just return document.getElementsByTagName
0I am using jQuery to calculate a running total on multiple textboxes. Just found an awesome response on how to get that working a few days ago, but now I am running into another problem. When using one selector, the total for GetTotal is calculated perfectly. However, when I include the second selector, the totals begin to conflict with one another, and no longer calculate properly. I have been searching for a solution to this for some time now, does anyone have any ideas?
Here is the selector i am currently using:
function GetTotal(txtBox) {
var total = 0;
$('input:text').each(function(index, value) {
total += parseInt($(value).val() || 0);
});
$("#chkTotal").html(total);
}
My view uses these txt boxes
<div class="editor-field">
@Html.TextBox("Field1", String.Empty, new {InputType = "text", id = "field1", onchange = "GetTotal(this)" })
</div>
<div class="editor-field">
@Html.TextBox("Field2", String.Empty, new {InputType = "text", id = "field2", onchange = "GetTotal(this)" })
</div>
<div>
<h3>Total Checked</h3>
</div>
<div id="chkTotal"></div>
Now I am trying to implement another selector which will total two additional editor fields...
function GetTotal1(txtBox) {
var total1 = 0;
$('input:text').each(function (index, value) {
total1 += parseInt($(value).val() || 0);
});
$("#disTotal").html(total1);
}
View:
<div class="editor-field">
@Html.TextBox("Field3", String.Empty, new {InputType = "text", id = "field3", onchange = "GetTotal1(this)" })
</div>
<div class="editor-field">
@Html.TextBox("Field4", String.Empty, new {InputType = "text", id = "field4", onchange = "GetTotal1(this)" })
</div>
<div>
<h3>Total Distributed</h3>
</div>
<div id="disTotal"></div>
When I use this code with an element whose id is "foobar":
$("#foobar").click(function () { alert("first"); });
$("#foobar").click(function () { alert("second"); });
I get two alerts: "first" and "second" second.
How do I specify a click event that also clears out any previous click events attached to the element? I want the last $("#foobar").click(...) to erase any previously bound events.
I downloaded jquery effects example and all effects are appearing only onclick but i want it to be executed on document.ready() and continue...
<script type="text/javascript">
var ImgIdx = 2;//To mark which image will be select next
function PreloadImg(){
$.ImagePreload("images/im2.jpg");
$.ImagePreload("images/im3.jpg");
$.ImagePreload("images/im4.jpg");
$.ImagePreload("images/im5.jpg");
}
$(document).ready(function(){
PreloadImg();
$(".SlashEff ul li").click(function(){
$(".Slash").ImageSwitch({Type:$(this).attr("rel"), NewImage:"images/im"+ImgIdx+".jpg", speed: 4000
});
ImgIdx++;
if(ImgIdx>5) ImgIdx = 1;
});
});
</script>
and my
<div class="SlashEff">
<ul>
<li class="TryFadeIn" rel="FadeIn">Fade in</li>
<li class="TryFlyIn" rel="FlyIn">Fly in</li>
<li class="TryFlyOut" rel="FlyOut">Fly out</li>
<li class="TryFlipIn" rel="FlipIn">Flip in</li>
<li class="TryFlipOut" rel="FlipOut">Flip out</li>
<li class="TryScroll" rel="ScrollIn">Scroll in</li>
<li class="TryScroll" rel="ScrollOut">Scroll out</li>
<li class="TrySingleDoor" rel="SingleDoor">Single Door</li>
<li class="TryDoubleDoor" rel="DoubleDoor">Double Door</li>
</ul>
</div>
Here is the link http://www.hieu.co.uk/blog/index.php/imageswitch/
I tried this,
$(document).ready(function(){
PreloadImg();
$(".Slash").ImageSwitch({Type:$(this).attr("rel"),
NewImage:"images/im"+ImgIdx+".jpg", speed: 4000
});
ImgIdx++;
if(ImgIdx>5) ImgIdx = 1;
});
I tried this but it gets executed only once.... I want to execute this every 5000ms... Is this possible...
Is it anyway possible to observe if a UIAlertView is being displayed and call a function when it is.
The UIAlertView is not being created and displayed in the same class which I want a function to be called in.
Its hard to explain but to put it simply I need to somehow monitor or observe if the view becomes like out of first responder or something because I dont think it is possible to monitor if a UIAlertView is being displayed :/
Hi all,
jQuery newbie here. I need to be able to set multiple cookies within the code without have to change out this variable each and every time. Is there any way to make this code generate unique cookies for different pages? As it is now, I'm having to rename that variable for each page that the jQuery animations exist on. (sbbcookiename)
Background on the issue: We are having issues with the sliders not autoplaying once one has already been triggered, due to it the cookie having been cached.
Thanks for your help.
(function(){
jQuery.noConflict();
var
_TIMEOUT= 1000,
initTimer= 0,
sbLoaded= false,
_re= null
;
initTimer= setTimeout(initSlider, _TIMEOUT);
jQuery(document).ready(initSlider);
function initSlider(){
if(sbLoaded) return;
if (jQuery('#campaign_name').length > 0) {
var sbbcookiename = jQuery('#campaign_name').attr('class');
} else {
var sbbcookiename = "slider728x90";
}
var
slideTimeout //timer
,sbTrigger = jQuery('#slidebartrigger') //convenience
,sbFirstSlide = (document.cookie.indexOf(sbbcookiename) == -1) //check cookie for 'already seen today'
;
clearTimeout(initTimer);
sbLoaded= true;
function toggleSlideboxes(){
if(slideTimeout) clearTimeout(slideTimeout);
var isDown = sbTrigger.is('.closeSlide');
jQuery('#slidebar')['slide' + (isDown ? 'Up' : 'Down')]((isDown ? 1000 : 1000), function(){
if(sbFirstSlide){ //if 'first time today' then clear for click-to-replay
sbTrigger.removeClass('firstSlide');
sbFirstSlide = false;
}
sbTrigger[(isDown ? 'remove' : 'add') + 'Class']('closeSlide').one('click', toggleSlideboxes);
if(!isDown) slideTimeout = setTimeout(toggleSlideboxes, 4000);
});
}
if(sbFirstSlide){
//not seen yet today so set a cookie for expire tomorrow, then toggle the slide boxes...
var oneDay = new Date();
oneDay.setUTCDate(oneDay.getUTCDate()+1);
oneDay.setUTCHours(0, 0, 0, 0); //set to literally day-by-day, rather than 24 hours
document.cookie=sbbcookiename+"=true;path=/;expires="+oneDay.toUTCString();
toggleSlideboxes();
}else{
//already seen today so show the trigger and set a click event on it...
sbTrigger.removeClass('firstSlide').one('click', toggleSlideboxes);
}
}
})();
The tabexpansion function only works partially when I override it like so:
function tabexpansion {
param($line, $lastWord)
if ($line -eq "hey ") {
"you", "Joe"
}
}
The custom completions work as expected, but now I only get the default autocomplete behavior for cmdlet names, not parameters. So New-TAB works fine, but New-Alias -TAB doesn't. How do I get the regular completions too after overriding tabexpansion?
I am calling some data which has pre-formatted HTML code in it, but when it renders from the jquery it appears to ignore my markup. This is my jQuery:
function GetFeed(){
document.getElementById("marq").innerHTML = '';
$.ajax({
type: "POST",
url: "xmlproxy.ashx",
dataType: "html",
success: function(obj) {
$('<span class="tickerItem"></span>').html(obj).appendTo('#marq');
}
});
}
hi i have a script
<script type="text/javascript">
window.addEvent('domready', function(){
var totIncrement = 0;
var increment = 560;
var maxRightIncrement = increment*(-6);
var fx = new Fx.Style('slider-list', 'margin-left', {
duration: 1000,
transition: Fx.Transitions.Back.easeInOut,
wait: true
});
//-------------------------------------
// EVENTS for the button "previous"
$('previous').addEvents({
'click' : function(event){
if(totIncrement<0){
totIncrement = totIncrement+increment;
fx.stop()
fx.start(totIncrement);
}
}
});
//-------------------------------------
// EVENTS for the button "next"
$('next').addEvents({
'click' : function(event){
if(totIncrement>maxRightIncrement){
totIncrement = totIncrement-increment;
fx.stop()
fx.start(totIncrement);
}
}
})
});
</script>
in mootools v1.1
it makes a scroller function at the bottom of my html page.
but when i click the next button the page's focus moves to the top of the page. how do i keep it on the scroller?
this is the html fragment:
<h3>Our Pastas</h3>
<div id="slider-buttons">
<a href="#" id="previous">Previous</a> | <a href="#" id="next">Next</a>
</div>
<div id="slider-stage">
<ul id="slider-list">
<li class="list_item">
<div id="thumbnail"><a href="xxx/product-catalog/pasta/long-pasta-in-brown-bags/bucatini"><img src="xxx/images/stories/products/_thumb1/bucatini.gif"></a></div><h4><a href="xxx/product-catalog/pasta/long-pasta-in-brown-bags/bucatini">Rustichella d'Abruzzo Bucatini</a></h4>
</li>
<li class="list_item">
<div id="thumbnail"><a href="xxx/product-catalog/pasta/pasta-in-trays/calamarata"><img src="xxx/images/stories/products/_thumb1/calamarata.jpg"></a></div><h4><a href="xxx/product-catalog/pasta/pasta-in-trays/calamarata">Rustichella d'Abruzzo Calamarata</a></h4>
</li>
<li class="list_item">
<div id="thumbnail"><a href="xxx/product-catalog/pasta/pasta-in-trays/cannolicchi"><img src="xxx/images/stories/products/_thumb1/cannolicchi.jpg"></a></div><h4><a href="xxx/product-catalog/pasta/pasta-in-trays/cannolicchi">Rustichella d'Abruzzo Cannolicchi</a></h4>
</li>
</ul></div>
I HAVE PROBLEM IN LOADING IMAGES USING JQUERY.
MY PROGRAM IS SUCH THAT IT INSERTS ASWELL AS DELETES FROM THE SAME FORM.
WHEN I DELETE AN IMAGE AND INSERTS THE IMAGE AND AFTER LOADING THE JQUERY FUNCTION THE DELETED IMAGE IS SHOWN.
I HAVE FOUND INCOSTIENCY IN DOM AND ACTUAL LOACTION.
THE BROWSER LOADS THE IMAGES FROM DOM NOT FORM ACTULA LOCATION.
IS THERE ANY FUNCTION THAT WILL FORCE TO READ FROM DOM./
DELETE THE IMAGES IN DOM
Hey there,
i've been working on a problem for a while now, which involves targeting the closest movieClip in relation to the x y coords of the mouse, I've attached a nice little acompanying graphic.
Each mc added to the stage has it's own sub-class (HotSpots) which uses Pythag to measure distance from mouse. At this stage i can determine the closest value from my Main class but can't figure out how to reference it back to the movieclip... hope this makes sense. Below are the two Classes.
My Main Class which attachs the mcs, and monitors mouse movement and traces closest value
package {
import flash.display.*;
import flash.text.*;
import flash.events.*;
public class Main extends MovieClip
{
var pos:Number = 50;
var nodeArray:Array;
public function Main(){
nodeArray = [];
for(var i:int = 0; i < 4; i++)
{
var hotSpot_mc:HotSpots = new HotSpots;
hotSpot_mc.x += pos;
hotSpot_mc.y += pos;
addChild(hotSpot_mc);
nodeArray.push(hotSpot_mc);
// set some pos
pos += 70;
}
stage.addEventListener(MouseEvent.MOUSE_MOVE,updateProxmity)
}
public function updateProxmity(e:MouseEvent):void
{
var tempArray:Array = new Array();
for(var i:int = 0; i < 4; i++)
{
this['tf'+[i]].text = String(nodeArray[i].dist);
tempArray.push(nodeArray[i].dist);
}
tempArray.sort(Array.NUMERIC);
var minValue:int = tempArray[0];
trace(minValue)
}
}
}
My HotSpots Class
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.text.TextField;
public class HotSpots extends MovieClip
{
public var XSide:Number;
public var YSide:Number;
public var dist:Number = 0;
public function HotSpots()
{
addEventListener(Event.ENTER_FRAME, textUp);
}
public function textUp(event:Event):void
{
XSide = this.x - MovieClip(root).mouseX;
YSide = this.y - MovieClip(root).mouseY;
dist = Math.round((Math.sqrt(XSide*XSide + YSide*YSide)));
}
}
}
thanks in advance
hey Guys,
I wanted to know if there's a way I can bind an Asp.net Ajax event to two different JS functions ?
eg.
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (!prm.get_isInAsyncPostBack())
{
prm.add_initializeRequest(InitializeRequest);
prm.add_initializeRequest(InitializeRequest2);
}
function InitalizeRequest() { ... }
function InitalizeRequest2() { ... }
Hello everyone.
Is there a way I can query from within Vim information about user-defined vimscript functions and script files that Vim knows about?
The things I'd like to know are:
Is a particular function defined?
Which source file is a given function defined in?
What are the vimscript files that have been sourced?
Etc.
I am currently developing a plugin-based system in C++ which provides a Lua scripting interface, for which I chose to use luabind. I'm using Lua 5 and luabind 0.9, both statically linked and compiled with MSVC++ 8. I am now having trouble binding functions with luabind when they are defined in a derived class, but not its parent class.
More specifically, I have an abstract base class called 'IPlugin' from which all plugin classes inherit. When the plugin manager initialises, it registers that class and its functions like this:
luabind::open(L);
luabind::module(L) [
luabind::class_("IPlugin")
.def("start", (void(IPlugin::*)())&IPlugin::start)
];
As it is only known at runtime what effective plugin classes are available, I had to solve loading plugins in a kind of roundabout way. The plugin manager exposes a factory function to Lua, which takes the name of a plugin class and a desired object name. The factory then creates the object, registers the plugin's class as inheriting from the 'IPlugin' base class, and immediately calls a function on the created object that registers itself as a global with the Lua state, like this:
void PluginExample::registerLuaObject(lua_State *L, string a_name)
{
luabind::globals(L)[a_name] = (PluginExample*)this;
}
I initially did this because I had problems with Lua determining the most derived class of the object, as if I register it from the StreamManager it is only known as a subtype of 'IPlugin' and not the specific subtype. I'm not sure anymore if this is even necessary though, but it works and the created object is subsequently accessible from Lua under 'a_name'.
The problem I have, though, is that functions defined in the derived class, which were not declared at all in the parent class, cannot be used. Virtual functions defined in the base class, such as 'start' above, work fine, and calling them from Lua on the new object runs the respective redefined code from the 'PluginExample' class. But if I add a new function to 'PluginExample', here for example a function taking no arguments and returning void, and register it like this:
luabind::module(L) [
luabind::class_("PluginExample")
.def(luabind::constructor())
.def("func", &PluginExample::func)
];
calling 'func' on the new object yields the following Lua runtime error:
No matching overload found, candidates:
void func(PluginExample&)
I am correctly using the ':' syntax so the 'self' argument is not needed and it seems suddenly Lua cannot determine the derived type of the object anymore. I am sure I am doing something wrong, probably having to do with the two-step binding required by my system architecture, but I can't figure out where. I'd much appreciate some help =)
Hi,
I'm sending email with PHP's mail function.
It works just as it should except all email clients show blank From-field.
Here's how i'm using the function:
mail( '[email protected]', "Example subject", $msg,
implode( "\r\n", array( Content-Type: text/html; charset=UTF-8', 'From: [email protected]') ) );
As i said everything works fine except From field is all blank when the message arrives.
Any ideas why this is happening?
I'm writing an application (A juggling pattern animator) in PLT Scheme that accepts Scheme expressions as values for some fields. I'm attempting to write a small text editor that will let me "explode" expressions into expressions that can still be eval'd but contain the data as literals for manual tweaking.
For example,
(4hss->sexp "747")
is a functioncall that generates a legitimate pattern. If I eval and print that, it becomes
(((7 3) - - -) (- - (4 2) -) (- (7 2) - -) (- - - (7 1)) ((4 0) - - -) (- - (7 0) -) (- (7 2) - -) (- - - (4 3)) ((7 3) - - -) (- - (7 0) -) (- (4 1) - -) (- - - (7 1)))
which can be "read" as a string, but will not "eval" the same as the function. For this statement, of course, what I need would be as simple as
(quote (((7 3...
but other examples are non-trivial. This one, for example, contains structs which print as vectors:
pair-of-jugglers
; -->
(#(struct:hand #(struct:position -0.35 2.0 1.0) #(struct:position -0.6 2.05 1.1) 1.832595714594046) #(struct:hand #(struct:position 0.35 2.0 1.0) #(struct:position 0.6 2.0500000000000003 1.1) 1.308996938995747) #(struct:hand #(struct:position 0.35 -2.0 1.0) #(struct:position 0.6 -2.05 1.1) -1.3089969389957472) #(struct:hand #(struct:position -0.35 -2.0 1.0) #(struct:position -0.6 -2.05 1.1) -1.8325957145940461))
I've thought of at least three possible solutions, none of which I like very much.
Solution A is to write a recursive eval-able output function myself for a reasonably large subset of the values that I might be using. There (probably...) won't be any circular references by the nature of the data structures used, so that wouldn't be such a long job. The output would end up looking like
`(((3 0) (... ; ex 1
`(,(make-hand (make-position ... ; ex 2
Or even worse if I could't figure out how to do it properly with quasiquoting.
Solution B would be to write out everything as
(read (open-input-string "(big-long-s-expression)"))
which, technically, solves the problem I'm bringing up but is... ugly.
Solution C might be a different approach of giving up eval and using only read for parsing input, or an uglier approach where the s-expression is used as directly data if eval fails, but those both seem unpleasant compared to using scheme values directly.
Undiscovered Solution D would be a PLT Scheme option, function or library I haven't located that would match Solution A.
Help me out before I start having bad recursion dreams again.
Tried doing http://davidwparker.com/2008/09/17/site-wide-announcements-in-rails-using-jquery-jgrowl/
Am really bad with JS. Think I am messing up on the last part where it says "This code goes in your application.js file (somewhere in $(function){ //here })"
Am I not suppose to do a link_to_function and create a function with this code that references that link?
Really lost on this one.
Hello,
Is it possible to add a live function on a plugin?
The jPikcer plugin wont work I create it from a .live('click', function(e)
Example:
$('.Multiple').jPicker();
Thanks,
Gino
I am making my first Facebook App and nothing is working as stated in the documentation. As an example, I have facebook.php on my server and am calling this line:
$friends = $facebook->api_client->friends_get();
but I get a "call to undefined function friends_get()"
I see that there is no "friends_get()" function in the facebook.php. I do see there is a friends.get in that long array... but I'm not sure how to access it?