jQuery Plugins » object https://jqueryplugins.info jQuery plugins, tutorials and resources Mon, 17 Oct 2011 21:15:36 +0000 en hourly 1 http://wordpress.org/?v=3.2.1 Handling Page.Response object in a custom class https://jqueryplugins.info/2011/10/handling-page-response-object-in-a-custom-class/ https://jqueryplugins.info/2011/10/handling-page-response-object-in-a-custom-class/#comments Wed, 12 Oct 2011 04:21:19 +0000 Admin https://jqueryplugins.info/2011/10/handling-page-response-object-in-a-custom-class/ Post link: Handling Page.Response object in a custom class

I have a custom class, Customer. I want to show a JQuery message on exception. I am attempting following class but the problem is that Page.Response object is unavailable in...

]]>
Post link: Handling Page.Response object in a custom class

I have a custom class, Customer. I want to show a JQuery message on exception. I am attempting following class but the problem is that Page.Response object is unavailable in a custom class.

How to modify the exception line in below given code? I have a separate class named as: MyErrorHandler, that stores all the methods for error handling. Code of both the classes is given below:

public sealed class Customer
{

     public void FillList()
     {
        try
        {
                .....
        }
        catch (Exception ex)
        {
             MyErrorHandler.GetScript(Page.Response,ex.Message.ToString());
        }
}

public static class MyErrorHandler
{
    public static void GetScript(System.Web.HttpResponse r, string customErrorMessage)
    {
        r.Write("<script type='javascript'>$  .msg({ content : '" + customErrorMessage + "' });</script>");
    }
}

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/handling-page-response-object-in-a-custom-class/feed/ 0
Using jQuery.live() on each element of the caller object of a plugin https://jqueryplugins.info/2011/10/using-jquery-live-on-each-element-of-the-caller-object-of-a-plugin/ https://jqueryplugins.info/2011/10/using-jquery-live-on-each-element-of-the-caller-object-of-a-plugin/#comments Thu, 06 Oct 2011 09:22:37 +0000 Admin https://jqueryplugins.info/2011/10/using-jquery-live-on-each-element-of-the-caller-object-of-a-plugin/ Post link: Using jQuery.live() on each element of the caller object of a plugin

I’ve built a filter plugin in jQuery that pops up an unordered list of query results from a database after I click an input textfield and filters the list depending...

]]>
Post link: Using jQuery.live() on each element of the caller object of a plugin

I’ve built a filter plugin in jQuery that pops up an unordered list of query results from a database after I click an input textfield and filters the list depending on the changing content of the input field. I guess it’s clear so far, we see many such things.

After spending some time with building it into a plugin I quickly realised that the .live() function I use on the list items instead of .click() (I have to use it as the list items are generated dynamically) doesn’t work the way I want it to work. After some googling, I found some relating articles, but my real problem is that the .live() function binds my click event to all the input fields with which I use the plugin, and after I click a list item it pushes the text in all of the callers.

Here’s a snapshot of the problem.

Here’s the relevant code:

I call the plugin like this on two input fields:

$  ('#inputf').lookupFilter({ dataSource: '/GetTownsForCounty/1', loadOnce: true });
$  ('#inputfield').lookupFilter({ dataSource: '/GetTownsForCounty/1', loadOnce: true });

And defined the plugin like this:

(function( $   ){
    var settings = {
         datarows: '#datarows',
         //  other settings here
    };
    $  .fn.lookupFilter = function( options ) {
      return this.each(function() {
        var $  this = $  (this);
        if( options ) {
            $  .extend( settings, options );
        }

     //  Generating & filtering the list items here

        $  this.keyup( function(){
            if($  (this).val() != '') {
                $  ("#datarows > li:not([name^='" + $  (this).val().toLowerCase() + "']):visible").hide();
                $  ("#datarows > li[name^='" + $  (this).val().toLowerCase() + "']:hidden").show();
            }
        })
        .keyup();  

        ajaxRequest(settings.dataSource);

        $  (settings.datarows + ' > li').live('click', function() {
            pushText($  this, $  (this).text());
            alert('right after pushText for id: ' + $  this.attr('id'));
        });
     });
})(jQuery);

I tried the above mentioned source’s solution like this (changing the $ (settings.datarows… line to this):

$  (settings.datarows + ' > li').liveBindTest();

And introducing the function itself:

$  .fn.liveBindTest = function () {
      $  (this.selector).live('click', function() {
          console.log('live clicked ' + $  (this).attr('id'));
          return false;
      });

But it returns both input fields’ ID again.

So, question is whether there is a workaround to bind only the relevant input field to the click event, or is it me who do things wrong? (Or is it an actual problem that no one has spotted yet?)

Thanks for the help.

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/using-jquery-live-on-each-element-of-the-caller-object-of-a-plugin/feed/ 0
Differed object confusion https://jqueryplugins.info/2011/10/differed-object-confusion/ https://jqueryplugins.info/2011/10/differed-object-confusion/#comments Sat, 01 Oct 2011 14:13:52 +0000 Admin https://jqueryplugins.info/2011/10/differed-object-confusion/ Post link: Differed object confusion

The following snippet works as expected: function boxAnimation() { var dfd = $ .Deferred(); $ ('div').fadeIn('slow', dfd.resolve); return dfd.promise(); } $ (function () { boxAnimation().done( function () { $ (this).animate({...

]]>
Post link: Differed object confusion

The following snippet works as expected:

function boxAnimation() {
        var dfd = $  .Deferred();
        $  ('div').fadeIn('slow', dfd.resolve);
        return dfd.promise();
    }

    $  (function () {
        boxAnimation().done(
            function () { $  (this).animate({ 'margin-top': 50 }); },
            function () { $  (this).animate({ 'margin-left': 150 }); },
            function () { $  (this).animate({ 'margin-top': 250 }); },
            function () { $  (this).animate({ 'margin-left': 350 }); }
        ).fail(function () { alert('failed'); });
    });

However in this one the differed object is neither rejected or resolved. Tell me where am I going wrong. Thanks

function boxAnimation() {
        var dfd = $  .Deferred();
        var randomNum = Math.floor(Math.random() * 5);
        $  ('div').fadeIn('slow', function () {
            if (randomNum == 1) {
                dfd.reject;
            }
            else {
                dfd.resolve;
            }
        });
        return dfd.promise();
    }

    $  (function () {
        boxAnimation().done(
            function () { $  (this).animate({ 'margin-top': 50 }); },
            function () { $  (this).animate({ 'margin-left': 150 }); },
            function () { $  (this).animate({ 'margin-top': 250 }); },
            function () { $  (this).animate({ 'margin-left': 350 }); }
        ).fail(function () { alert('failed'); });
    });

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/differed-object-confusion/feed/ 0
Making the List object compatible with post data from frontend in ASP.NET MVC3 https://jqueryplugins.info/2011/09/making-the-list-object-compatible-with-post-data-from-frontend-in-asp-net-mvc3/ https://jqueryplugins.info/2011/09/making-the-list-object-compatible-with-post-data-from-frontend-in-asp-net-mvc3/#comments Fri, 30 Sep 2011 23:14:02 +0000 Admin https://jqueryplugins.info/2011/09/making-the-list-object-compatible-with-post-data-from-frontend-in-asp-net-mvc3/ Post link: Making the List object compatible with post data from frontend in ASP.NET MVC3

I have the following controller that I am posting to in a form via AJAX: [HttpPost] public ActionResult Create(List<int> listOfSTuff) { try { service.Create(listOfSTuff); } catch { return null; }...

]]>
Post link: Making the List object compatible with post data from frontend in ASP.NET MVC3

I have the following controller that I am posting to in a form via AJAX:

[HttpPost]
public ActionResult Create(List<int> listOfSTuff)
{
    try
    {
        service.Create(listOfSTuff);
    }
    catch
    {
        return null;
    }
    return Json(new { gid = g.ID });
}

I am having a hard time with my jQuery AJAX post making the datatypes compatible. Here is my jQuery/JavaScript code:

var listOfStuff = [1, 2, 3];

$  .ajax({
    type: 'POST',
    url: '/MyController/Create',
    data: listOfStuff,
    success: function(data) {
        alert(data.gid);
    },
    error: alert(':('),
    dataType: 'json'
});

I know that the AJAX post to the controller is working because I get a gid but I do not see the array elements 1 or 2 or 3 saved in the database. It does not appear that the controller likes my JavaScript array that is being passed over. Can anyone suggest how the data structure should look like from the frontend?

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/09/making-the-list-object-compatible-with-post-data-from-frontend-in-asp-net-mvc3/feed/ 0
trying to use jquery tooltip plugin, object has no method “tooltip” https://jqueryplugins.info/2011/09/trying-to-use-jquery-tooltip-plugin-object-has-no-method-tooltip/ https://jqueryplugins.info/2011/09/trying-to-use-jquery-tooltip-plugin-object-has-no-method-tooltip/#comments Fri, 30 Sep 2011 01:15:46 +0000 Admin https://jqueryplugins.info/2011/09/trying-to-use-jquery-tooltip-plugin-object-has-no-method-tooltip/ Post link: trying to use jquery tooltip plugin, object has no method “tooltip”

I’m using this tooltip: http://flowplayer.org/tools/demos/tooltip/index.html I have the following lines in my html file: <script src="/javascripts/home.js" type="text/javascript"></script> <script src="http://cdn.jquerytools.org/1.2.6/jquery.tools.min.js" type="text/javascript"></script> <script type="text/javascript" src="/scripts/jquery.min.js"></script> <div id="boo"> <img src="image1.jpg" title="this thing is...

]]>
Post link: trying to use jquery tooltip plugin, object has no method “tooltip”

I’m using this tooltip: http://flowplayer.org/tools/demos/tooltip/index.html

I have the following lines in my html file:

<script src="/javascripts/home.js" type="text/javascript"></script>
<script src="http://cdn.jquerytools.org/1.2.6/jquery.tools.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/scripts/jquery.min.js"></script>

<div id="boo">
<img src="image1.jpg" title="this thing is a tool"/>
<img src="image2.jpg" title="this thing is also tool"/>
</div>

I have the following line in my home.js file:

$  ("#boo img[title]").tooltip();

I have the following line in my css file:

.tooltip {
    display:none;
    background:transparent url(/tools/img/tooltip/black_arrow.png);
    font-size:12px;
    height:70px;
    width:160px;
    padding:25px;
    color:#fff;
}

I get this error:

Uncaught TypeError: Object [object Object] has no method 'tooltip'

I’m at my wits end. I feel like I’ve followed the example on the site exactly, but no idea what’s going on.

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/09/trying-to-use-jquery-tooltip-plugin-object-has-no-method-tooltip/feed/ 0
how to populate an object using webservice(c#) and display the objects using jquery(json, data) https://jqueryplugins.info/2011/09/how-to-populate-an-object-using-webservicec-and-display-the-objects-using-jqueryjson-data/ https://jqueryplugins.info/2011/09/how-to-populate-an-object-using-webservicec-and-display-the-objects-using-jqueryjson-data/#comments Thu, 29 Sep 2011 18:14:24 +0000 Admin https://jqueryplugins.info/2011/09/how-to-populate-an-object-using-webservicec-and-display-the-objects-using-jqueryjson-data/ Post link: how to populate an object using webservice(c#) and display the objects using jquery(json, data)

I am creating a web application using visual studio 2010 using sql server at the backend. I need to randomly select 10 questions from a database using web service in...

]]>
Post link: how to populate an object using webservice(c#) and display the objects using jquery(json, data)

I am creating a web application using visual studio 2010 using sql server at the backend. I need to randomly select 10 questions from a database using web service in c# and display the results in a web browser using jquery.
On the browser I need to diplay question in random order and answer choices randomized as well.

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/09/how-to-populate-an-object-using-webservicec-and-display-the-objects-using-jqueryjson-data/feed/ 0
backbone.js nested model’s object not unique to instance https://jqueryplugins.info/2011/09/backbone-js-nested-models-object-not-unique-to-instance/ https://jqueryplugins.info/2011/09/backbone-js-nested-models-object-not-unique-to-instance/#comments Thu, 29 Sep 2011 06:15:23 +0000 Admin https://jqueryplugins.info/2011/09/backbone-js-nested-models-object-not-unique-to-instance/ Post link: backbone.js nested model’s object not unique to instance

I have a parent Model that has by default and nested Model. The nested Model itself has propertyA, which is an object with defaultValue and userValue. The idea is that...

]]>
Post link: backbone.js nested model’s object not unique to instance

I have a parent Model that has by default and nested Model. The nested Model itself has propertyA, which is an object with defaultValue and userValue. The idea is that every instance of parent Model comes with a nested Model that has a userValue of null, and a static default value.

The problem is, when I update the userValue for one instance, it ends up changing for all instances going forward. Instead of updating the userValue for a particular instance, I’m doing something wrong and updating the nested Model “prototype”.

Below code available at http://jsfiddle.net/GVkQp/4/. Thanks for help.

var ParentModel = Backbone.Model.extend({
    initialize: function(){
        var defaultObjs = {
            nestedModel : new NestedModel()
        };
        $  ().extend(this.attributes, defaultObjs);
    }
});

var NestedModel = Backbone.Model.extend({
    defaults: {
        "propertyA" : {
                        "defaultValue" : "ABC",
                        "userValue": null
                      }
    }
});

var ParentView = Backbone.View.extend({
    initialize: function(){
        var self = this;
        var defaultValue = self.model.get("nestedModel").get("propertyA")["defaultValue"];
        var userValue = self.model.get("nestedModel").get("propertyA")["userValue"];

        var div = $  ("<div class='box'>defaultValue = <span id='defaultValue'>" +
                    defaultValue+ "</span>, userValue = <span id='userValue'>" +
                    userValue + "</span></div>");
        var divButton = $  ('<input type="button" value="Change my userValue to DEF">')
            .click(function(){
            temp = self.model.get("nestedModel").get("propertyA");
            temp.userValue = "DEF";
            //wherewas my intention is just to set the userValue for a particular instance,
            //generating another instance of ParentView (by clicking button) reveals that
            //the userValue is set even for new instances.
            //How can I change it such that I only change the userValue of the particular
            //instance?

            //set value
            self.model.get("nestedModel").set({"propertyA": temp});

            //update userValue in View
            userValue = self.model.get("nestedModel").get("propertyA")["userValue"];
            $  (this).parent().find("span#userValue").text(userValue);
        });    

        //append divButtont to div
        div.append(divButton)

        //append div to body
        $  ('body').append(div)
    },
});

$  ("#add").click(function(){
    var newBoxView = new ParentView({
        model: new ParentModel()
    });
});

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/09/backbone-js-nested-models-object-not-unique-to-instance/feed/ 0
jQuery $(this) Problem, wrong object https://jqueryplugins.info/2011/09/jquery-this-problem-wrong-object/ https://jqueryplugins.info/2011/09/jquery-this-problem-wrong-object/#comments Tue, 27 Sep 2011 21:13:20 +0000 Admin https://jqueryplugins.info/2011/09/jquery-this-problem-wrong-object/ Post link: jQuery $(this) Problem, wrong object

i using this code to show a title $ (".line").mopTip({ 'w':150, 'style':"overOut", 'get': $ (this).attr("title") }); but as title I get the title of page… what do I wrong? newest...

]]>
Post link: jQuery $(this) Problem, wrong object

i using this code to show a title

$  (".line").mopTip({
'w':150,
'style':"overOut",
'get': $  (this).attr("title")
});

but as title I get the title of page… what do I wrong?

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/09/jquery-this-problem-wrong-object/feed/ 0
Javascript – emulating document.ready() on HTML object https://jqueryplugins.info/2011/09/javascript-emulating-document-ready-on-html-object/ https://jqueryplugins.info/2011/09/javascript-emulating-document-ready-on-html-object/#comments Tue, 27 Sep 2011 10:14:34 +0000 Admin https://jqueryplugins.info/2011/09/javascript-emulating-document-ready-on-html-object/ Post link: Javascript – emulating document.ready() on HTML object

I have a main site A onto which I load content with AJAX from sub-site B. There is a jQuery file that alters elements on the site A (adds events...

]]>
Post link: Javascript – emulating document.ready() on HTML object

I have a main site A onto which I load content with AJAX from sub-site B. There is a jQuery file that alters elements on the site A (adds events to them, classes, re-renders them if needed etc) that is being launched on document.ready()

Now I need to load content from site B into site A. I do it with a function:

$  .get("/some/url/",{},function(e){
    $  (".some_div").html(e);
});

The problem is if I include jQuery in site B, the following happens: jQuery loads the content, puts it into site A and then triggers all the scripts that were fetched within it. Which causes re-render of the site and whole lot of mess.

What I need to do is to emulate the document.ready() on the HTML object e right after it was pulled out of the site B but before it is appended to the site A (so I will have re-rendered HTML code with all events, classes and listeners ready).

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/09/javascript-emulating-document-ready-on-html-object/feed/ 0
return more then one JSON object in the same response and parsing it https://jqueryplugins.info/2011/09/return-more-then-one-json-object-in-the-same-response-and-parsing-it/ https://jqueryplugins.info/2011/09/return-more-then-one-json-object-in-the-same-response-and-parsing-it/#comments Sat, 24 Sep 2011 10:14:17 +0000 Admin https://jqueryplugins.info/2011/09/return-more-then-one-json-object-in-the-same-response-and-parsing-it/ Post link: return more then one JSON object in the same response and parsing it

i have the following code: (simplified for readability) CSHARP: foreach(DataRow dRow in myDS.Tables[0].Rows){ Company myCompany = new Company(); myCompany.id = int.Parse(dRow["id"].ToString()); Companies.Add(myCompany); } JavaScriptSerializer serializer = new JavaScriptSerializer(); Response.Write(serializer.Serialize(Companies)); Response.End();...

]]>
Post link: return more then one JSON object in the same response and parsing it

i have the following code: (simplified for readability)

CSHARP:

        foreach(DataRow dRow in myDS.Tables[0].Rows){
            Company myCompany = new Company();
            myCompany.id = int.Parse(dRow["id"].ToString());
            Companies.Add(myCompany);
        }

        JavaScriptSerializer serializer = new JavaScriptSerializer();
        Response.Write(serializer.Serialize(Companies));
        Response.End();

JQUERY:

$  .getJSON('ajax.aspx?what=' + $  ('input[name="what"]').val() + '&where=' + $  ('input[name="what"]').val(), function (data) {
    $  .each(data, function (key, val) {
        var myCompany = new function () {
            this.id = val.id;
        }
        Companies.push(myCompany);
    });
});

now, i have another object in the CSHARP code, which is named Cities
and i would like to return it in the same request.

something like

Response.Write(serializer.Serialize(Companies));
Response.Write(serializer.Serialize(Cities));
Response.End()

and offcourse parse it on the Client side.

how can i do something like that?

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/09/return-more-then-one-json-object-in-the-same-response-and-parsing-it/feed/ 0