Search Results

Search found 17577 results on 704 pages for 'jquery tooltip'.

Page 70/704 | < Previous Page | 66 67 68 69 70 71 72 73 74 75 76 77  | Next Page >

  • jQuery - discrepency between classname and selectors

    - by Ciel
    I have the following code that I wrote, which I personally found to be pretty nice. It takes a <ul> and it drops down the contents when clicked. But I am having a disconnect here in comprehension, and one I had to do what I feel is a 'dirty hack' to solve. The problem is that I do not want the class `'sidebar-dropdown-open' to be so 'hardwired' in the plugin. However I discovered that there is a very stark difference between... $('.sidebar-dropdown-open') and 'sidebar-dropdown-open and even '.sidebar-dropdown-open. I 'solved' this problem by including two different 'parameters' in my plugin, but I was wondering if someone might give me some insight as to how I could perform this better, and why this was behaving this way. wiring (document load) $(document).ready(function () { $('[data-role="sidebar-dropdown"]').drawer({ open: 'sidebar-dropdown-open', css: '.sidebar-dropdown-open' }); }); html <ul> <li class=" dropdown" data-role="sidebar-dropdown"> <a href="pages/.." class="remote">Link Text</a> <ul class="sub-menu light sidebar-dropdown-menu"> <li><a class="remote" href="pages/...">Link Text</a></li> <li><a class="remote" href="pages/...">Link Text</a></li> <li><a class="remote" href="pages/...">Link Text</a></li> </ul> </li> </ul> javascript (function ($) { $.fn.drawer = function (options) { // Create some defaults, extending them with any options that were provided var settings = $.extend({ open: 'open', css: '.open' }, options); return this.each(function () { $(this).on('click', function (e) { // slide up all open dropdown menus $(settings.css).not($(this)).each(function () { $(this).removeClass(settings.open); // retrieve the appropriate menu item var $menu = $(this).children(".dropdown-menu, .sidebar-dropdown-menu"); // slide down the one clicked on. $menu.slideUp('fast'); $menu.removeClass('active'); }); // mark this menu as open $(this).addClass(settings.open); // retrieve the appropriate menu item var $menu = $(this).children(".dropdown-menu, .sidebar-dropdown-menu"); // slide down the one clicked on. $menu.slideDown(100); $menu.addClass('active'); e.preventDefault(); e.stopPropagation(); }).on("mouseleave", function () { $(this).children(".dropdown-menu").hide().delay(300); }); }) }; })(jQuery); I have tried using settings.open and demanding that it just be a className (.open), etc. - but that does not seem to work. It seems to get ignored by the removeClass function.

    Read the article

  • Jquery mobile and Google maps [on hold]

    - by Jack
    I have been trying to get my google maps to display within a page of a mobile app. The map will display for a second, and then disappear. I have read about a jquery bug, but i can't seem to find a way to get this code to work. any help would be greatly appreciated. <script> var geocoder; var currentLocation; var searchResults; var map; var directionsDisplay; var directionsService; function init(){ geocoder = new google.maps.Geocoder(); if (navigator.geolocation){ navigator.geolocation.watchPosition(showLocation, locationError); } else { alert("Geolocation not supported on this device"); return; } }//init function function showLocation(location){//start showlocation currentLocation = new google.maps.LatLng(location.coords.latitude, location.coords.longitude); $('#lat').attr("value", currentLocation.lat()); $('#lng').attr("value", currentLocation.lng()); geocoder = new google.maps.Geocoder(); geocoder.geocode({'latLng': currentLocation}, function(results, status){ if (status == google.maps.GeocoderStatus.OK){ if (results[0]){ var address = results[0].formatted_address; $('#loc').html(results[0].formatted_address); var info = "Latitude: " + location.coords.latitude + " Longitude: " + location.coords.longitude + "<br />"; info += "Location accurate within " + location.coords.accuracy + " meters <br /> Last Update: " + new Date(location.timestamp).toLocaleString(); $('#acc').html(info); $('#address').attr("value", results[0].formatted_address); }else{ alert('No results found'); }//end else //if(!map) initMap(); }else { $('#loc').html('Geocoder failed due to: ' + status); }//end else });//end of function if (!map) initMap(); }//end showlocation function function locationError(error){ switch(error.code) { case error.PERMISSION_DENIED: alert("Geolocation access denied or disabled. To enable geolocation on your iPhone, go to Settings > General> Location Services"); break; case error.POSITION_UNAVAILABLE: alert("Current location not available"); break; case error.TIMEOUT: alert("Timeout"); break; default: alert("unkown error"); break; }//endswitch }//endlocationerror function initMap(){ var mapOptions = { zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP, center: currentLocation };//var mapOptions map = new google.maps.Map(document.getElementById('mapDiv'), mapOptions); google.maps.event.trigger(map, 'resize'); var bounds = new google.maps.LatLngBounds(); bounds.extend(currentLocation); map.fitBounds(bounds); //new code //var center; //function calculateCenter(){ //center = map.getCenter(); //} //google.maps.even.addDomListener(map, 'idle', function(){ //calculateCenter(); //}); //google.maps.even.addListenerOnce(map, 'idle', function(){ //google.maps.even.trigger(map,'resize'); //}); //google.maps.event.addDomListener(window, 'resize', function() { //map.setCenter(center); //});//end new code }//end initMap() //------------------------------------------------------------------------------- $(document).on("pageinit", init);

    Read the article

  • Anobody succeeded in using ICEFaces with jQuery?

    - by hubertg
    Basically jquery is usable with IceFaces. Then only problem arises when partial updates of the page are used. For example you have a panelgroup where a jquery datepicker element (jquery UI datepicker plugin) is used. If the panelGroup is visible from the beginning it's no problem. The jquery call to jQuery(".datepicker").datepicker finds the input and jquery can do it's magic. But if the panelGroup is shown because of a partial update of the page (because the visible propery is changed) jquery is not called again. Does anybody has a solution to this problem? Basically the idea would be that jquery is run each time the dom has changed.

    Read the article

  • How to implement JQuery easing into this window scroll movement function?

    - by Mohammad
    With this code I've been able to capture the mousewheel movement and apply it to the horizontal scroll bars instead of the vertical default. $('html').bind('mousewheel', function(event, delta) { window.parent.scrollBy(-120 * delta, 0); return false; }); Is there any way that I could add this jQuery easing animation to the scroll movement? jQuery.extend( jQuery.easing, { easeInOutBack: function (x, t, b, c, d, s) { if (s == undefined) s = 1.70158; if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; } }); Thank you so much in advance!

    Read the article

  • jQuery CDN host with vsdoc?

    - by Guy
    Following on from this question (that I asked) and this question (that Simon asked), is there a CDN that provides the jQuery script AND the -vsdoc version side-by-side? e.g. Google provide: http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js but don't provide http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min-vsdoc.js Does Microsoft have a CDN for jQuery?

    Read the article

  • jQuery addClass() not running before jQuery.ajax()

    - by Josh
    I'm trying to have a button that onclick will apply a class loading (sets cursor to "wait") to the body, before making a series of ajax requests. Code is: $('#addSelected').click(function(){ $('body').addClass('loading'); var products = $(':checkbox[id^=add_]:checked'); products.each(function(){ var prodID = $(this).attr('id').replace('add_', ''); var qty = $('#qty_' + prodID).val(); if($('#prep_' + prodID).val()) { prodID += ':' + $('#prep_' + prodID).val(); } // Have to use .ajax rather than .get so we can use async:false, otherwise // product adds happen in parallel, causing data to be lost. $.ajax({ url: '<?=base_url()?>basket/update/' + prodID + '/' + qty, async: false, beforeSend: function(){ $('body').addClass('loading'); } }); }); }); I've tried doing $('body').addClass('loading'); both before the requests, and as a beforeSend callback, but there is no difference. In firebug I can see that body doesn't get the loading class until after the requests are complete. Any ideas?

    Read the article

  • Creating a jQuery plugin: best practices regarding functions' visibility?

    - by marcgg
    I'm creating a jQuery plugin. So far it's working fine, but I'm having doubt about the way I'm doing things: jQuery.fn.myMethod = function() { return this.each(function(){ MyScope.doSomething(jQuery(this).attr("id")); }); }; var MyScope = { doSomething: function(id){ // something doSomethingElse(23); // some more code doSomethingElse(55); }, doSomethingElse: function(someInt){ // some code } }; I use MyScope to store all my "private" functions. I don't want the user to be able to go $("p").doSomething(), but I do need to use them. I could move everything in the myMethod function, but it would create a 100 lines long function and people would hate me for it. What's the best practices in this situation? Are there any great tutorials out there regarding this?

    Read the article

  • Is it possible to do live events in YUI, similar to jQuery's live events?

    - by eculver
    It doesn't currently seem as though there is a way to do live events in YUI similar to jQuery: http://api.jquery.com/live/ It sure would be nice if something like: function handleClick(e) { // click! } YUI().use('node-base', function(Y) { Y.on("click", handleClick, ".foo"); }); caused handleClick to be fired when a node with the "foo" class was clicked on after being dynamically added to the DOM and sometime after the Y.on was evaluated. I feel like live events are one of jQuery's killer features that YUI lacks.

    Read the article

  • JQuery help, How to Hide all button in JQuery

    - by user303518
    Hi guys, I'm trying to make a request/reply section in my project. I want to achieve these functionality in that code (that I'm not able to implement; so guys please help me out): 1 When user click on reply button; other reply area(text-area +button) should be hide (means at a time only one reply area should be visible to the user). 2 when user click on reply button text-area will focus and page will slide down (suppose user reply 10 comment focus will automatically set to the 10 number text area and page will slide down to that position accordingly). Here is my so far code guys: //method call on the click of reply link. function linkReply_Clicked(issueId) { Id = issueId; textId = "text_" + issueId + count; btnReply = "btnReply_" + issueId + count; btnCancel = "btnCancel_" + issueId + count; var textareasArray = document.getElementsByTagName("textarea"); var btnArray = document.getElementsByTagName("input"); for (i = 0; i < textareasArray.length; i++) { textareasArray[i].style.display = "none"; btnArray[i].style.display = "none"; } var str = "<table cellpadding='3' cellspacing='0' width='58%'>"; str += "<tr><td valign='top' align='left'>"; str += "<textarea id=" + textId + " rows='5' cols='60'></textarea>"; str += "</td></tr>"; str += "<tr><td valign='top' align='right'>"; str += "<input id=" + btnReply + " type='button' onclick='btnReply_Clicked(Id ,textId)' value='Reply' />&nbsp;"; str += "<input id=" + btnCancel + " type='button' onclick='btnCancel_Clicked(Id ,textId)' value='Cancel' />&nbsp;"; str += "</td></tr>"; str += "</table>"; document.getElementById("divOuter_" + issueId).innerHTML = str; $("#" + textId + "").focus(); } // submit user reply and try to hide that reply area. function btnReply_Clicked(issueId, textID) { var comment = document.getElementById(textID).value; if (comment != '') { $.getJSON("/Issue/SaveComment", { IssueId: issueId, Comment: comment }, null); $("#text_" + issueId + count).hide(); $("#btnReply_" + issueId + count).hide(); $("#btnCancel_" + issueId + count).hide(); document.getElementById(textID).value = ''; count = count + 1; } } // cancel user reply and try to hide that reply area. function btnCancel_Clicked(issueId, textId) { $("#text_" + issueId + count).hide(); $("#btnReply_" + issueId + count).hide(); $("#btnCancel_" + issueId + count).hide(); document.getElementById(textId).value = ''; count = count + 1; }

    Read the article

  • jQuery - Need help stopping animation on click command.

    - by iamtheratio
    With a few of your help I was able to get the jquery I wanted to work flawlessly, except for one thing.. the animation doesn't stop when i click on the buttons. Scenario: I have an Image, and 3 buttons underneath labeled "1","2", and "3". The jquery will automate the click function every 4500ms and switch from 1 to 2, then 2 to 3 and continuously loop. However the problem is, if I manually click on a 1,2,3 button the animation does not stop. Any ideas how I could accomplish this? jQuery: var tabs; var len; var index = 1; var robot; function automate() { tabs.eq((index%len)).trigger('click'); index++; } robot = setInterval(automate, 5500); jQuery(document).ready(function(){ jQuery(".imgs").hide(); jQuery(".img_selection a").click(function(){ stringref = this.href.split('#')[1]; $(".img_selection a[id$=_on]").removeAttr('id'); this.id = this.className + "_on"; jQuery('.imgs').hide(); if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0") { jQuery('.imgs#' + stringref).show(); } else jQuery('.imgs#' + stringref).fadeIn(); return false; }); $('.img_selection a').removeAttr('id').eq(0).trigger('click'); tabs = jQuery(".img_selection a"); len = tabs.size(); }); I tried adding the below code, with a lot of help from this website, but to no avail.. CODE: jQuery(document).ready(function(){ jQuery(".imgs").hide().click(function(){ clearInterval(robot); }); HTML: <!-- TOP IMAGE ROTATION --> <div id="upper_image"> <div id="img1" class="imgs"> <p><img src="images/top_image.jpg" width="900" height="250" alt="The Ratio - Print Projects!" border="0" /></p> </div> <div id="img2" class="imgs"> <p><img src="images/top_image2.jpg" width="900" height="250" alt="The Ratio - In The Works!" border="0" /></p> </div> <div id="img3" class="imgs"> <p><img src="images/top_image3.jpg" width="900" height="250" alt="The Ratio!" border="0" /></p> </div> </div> <!-- / TOP IMAGE ROTATION --> <!-- TOP IMAGE SELECTION --> <ul class="img_selection"> <li><a id="img1_on" class="img1" href="#img1">1</a></li> <li><a class="img2" href="#img2">2</a></li> <li><a class="img3" href="#img3">3</a></li> </ul> <!-- / TOP IMAGE SELECTION -->

    Read the article

  • jQuery offset combined with jQuery UI doesn't update on drag

    - by Constructor
    I need to get the offset of the element that is being dragged and I use: $(function(){ $(".draggable").draggable({ stop: function(){ var offset = $("#boxone").offset(); alert(offset.left); } }); }); the element is positioned absolute and has a CSS of: left:100px; that is the value I get on the alert when I drag the element (even multiple times). What I want is to get it to alert the current offset (if I drag in 200px to the right it should say 300)

    Read the article

  • Why doesn't jquery validation plugin's remote attribute work for me?

    - by Pandiya Chendur
    I use jquery validation plugin and the remote attribute works with emailId but not with mobileNo? var validator = $("#addform").validate({ rules: { Name: "required", MobileNo: { required: true, minlength: 10, remote: '<%=Url.Action("getClientMobNo", "Clients") %>' }, Address: "required" }, messages: { Name: "please provide a client name", MobileNo: { required: "Please provide a mobile phone no", rangelength: jQuery.format("Enter at least {0} characters"), remote: jQuery.format("This MobileNo is already in use") }, Address: "please provide client address" }, A null value is passed to my controller action.. Any suggestion... public JsonResult getClientMobNo(string mobno) { JsonResult result = new JsonResult(); string status = clirep.getClientMobNo(Convert.ToInt64(mobno)); if (status == "Mobile No already exists") { result.Data = false; } else { result.Data = true; } return result; }

    Read the article

  • jQuery mobile 1.1.0 slider: JS-object properties access?

    - by Koniak
    EDIT: This could be seen as a pure javascript objects question. The code can be found here: jquery.mobile-1.1.0.js I need to access properties of a jQuery mobile JS-object but is not sure how that is possible. In the jquery.mobile-1.1.0.js and mobile.slider is the following (see extend on line 5967): $.widget( "mobile.slider", $.mobile.widget, { ... _create: function() { ... $.extend( this, { slider: slider, handle: handle, valuebg: valuebg, dragging: false, beforeStart: null, userModified: false, mouseMoved: false }); Primarily the property I would like to read is the "dragging". I know i can execute the methods using: $("#slider").slider("refresh") Is there a similair way to access the properties? Thanks

    Read the article

  • jQuery Toggle Help

    - by Cameron
    I have the following code: $(document).ready(function() { // Manage sidebar category display jQuery("#categories > ul > li.cat-item").each(function(){ var item; if ( jQuery(this).has("ul").length ) { item = jQuery("<span class='plus'>+</span>").click(function(e){ jQuery(this) .text( jQuery(this).text() === "+" ? "-" : "+" ) .parent().next().toggle(); return false; }); jQuery(this).find(".children").hide(); } else { item = jQuery("<span class='plus'>&nbsp;</span>"); } jQuery(this).children("a").prepend( item ); }); }); This creates a sort of toggle system for my categories. But it will only work with 2 levels deep, what I need it to do is work with unlimited levels.

    Read the article

  • jQuery: Writing jquery in an object oriented way

    - by anoopkattodi
    Hi all, I am trying to write all my query code in an object oriented way. But I don't know how to implement this for each click function and hover function etc. I also wanted to know: What are the advantages of writing query in object oriented way? For query what is better the object oriented way or in the ordinary way?

    Read the article

  • jQuery accordion: is there a way to make the scrollbar fit the displayed panel?

    - by Cheeso
    I have a jQuery accordion (jQuery 1.3.2, jQuery UI 1.7.2), with between 3-12 content panels. Some of the content panels are large, and have lots of content. some are small, and have only a little. When I expand any of them, the scrollbar on the div containing the accordion (it's got css overflow: auto;) is set as if the largest of the panels is expanded. Let's say I have 3 panels. One has 3 lines of content, one has 20 lines, and one has 1000 lines. If I expand either of the first two, the scrollbar indicator gets very very tiny, and moves all the way to the top, even though there is nothing worth scrolling. Is there a way to fix this? It seems like autoHeight:false ought to do it, but that doesn't work for me.

    Read the article

  • XAML ToolTip + IsHitTestVisible="False"

    - by Sean
    We need to have mouse clicks and drags "ignored" by our View1 but the ToolTip must still function in that view. The reason is View1 is above View2 in Z-Order, so View1 can tint View2 a red color and show a warning via ToolTip; however the ToolTip accompanying View1 will not work if IsHitTestVisible="False". Anyone know a work around so the ToolTip will display on mouse move/over and the rest of mouse events are ignored by View1 and go to View2? Thanks, Sean

    Read the article

  • open source custom tooltip (callout) control/code for asp.net

    - by dotnetcoder
    Looking for a custom tooltip (typical yellow baloon callout) on click of an anchor tag. The tooltip should appear and remain in view until the cross button on the tooltip is clicked. Just looking for a tried and tested open source solution. Tried googling this but most of the tooltip [...missing info?...] Ajax control toolkit has the calloutvalidator which seems like a good choice but is tied up to be used for validation tooltips.

    Read the article

  • Tooltip in Datagrid.

    - by senthil-nathanr
    Is there any way to show the tooltip in Datagrid for more than 30 seconds? example, here is my code e.Item.Cells(7).Tooltip = e.Item.Cells(6).Text on mousehover the tooltip will be displayed only 6 or 7 seconds, is there any way to increase the time for the tooltip?

    Read the article

  • Using the jQuery UI Library in a MVC 3 Application to Build a Dialog Form

    - by ChrisD
    Using a simulated dialog window is a nice way to handle inline data editing. The jQuery UI has a UI widget for a dialog window that makes it easy to get up and running with it in your application. With the release of ASP.NET MVC 3, Microsoft included the jQuery UI scripts and files in the MVC 3 project templates for Visual Studio. With the release of the MVC 3 Tools Update, Microsoft implemented the inclusion of those with NuGet as packages. That means we can get up and running using the latest version of the jQuery UI with minimal effort. To the code! Another that might interested you about JQuery Mobile and ASP.NET MVC 3 with C#. If you are starting with a new MVC 3 application and have the Tools Update then you are a NuGet update and a <link> and <script> tag away from adding the jQuery UI to your project. If you are using an existing MVC project you can still get the jQuery UI library added to your project via NuGet and then add the link and script tags. Assuming that you have pulled down the latest version (at the time of this publish it was 1.8.13) you can add the following link and script tags to your <head> tag: < link href = "@Url.Content(" ~ / Content / themes / base / jquery . ui . all . css ")" rel = "Stylesheet" type = "text/css" /> < script src = "@Url.Content(" ~ / Scripts / jquery-ui-1 . 8 . 13 . min . js ")" type = "text/javascript" ></ script > The jQuery UI library relies upon the CSS scripts and some image files to handle rendering of its widgets (you can choose a different theme or role your own if you like). Adding these to the stock _Layout.cshtml file results in the following markup: <!DOCTYPE html> < html > < head >     < meta charset = "utf-8" />     < title > @ViewBag.Title </ title >     < link href = "@Url.Content(" ~ / Content / Site . css ")" rel = "stylesheet" type = "text/css" />     <link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="Stylesheet" type="text/css" />     <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>     <script src="@Url.Content("~/Scripts/modernizr-1.7.min . js ")" type = "text/javascript" ></ script >     < script src = "@Url.Content(" ~ / Scripts / jquery-ui-1 . 8 . 13 . min . js ")" type = "text/javascript" ></ script > </ head > < body >     @RenderBody() </ body > </ html > Our example will involve building a list of notes with an id, title and description. Each note can be edited and new notes can be added. The user will never have to leave the single page of notes to manage the note data. The add and edit forms will be delivered in a jQuery UI dialog widget and the note list content will get reloaded via an AJAX call after each change to the list. To begin, we need to craft a model and a data management class. We will do this so we can simulate data storage and get a feel for the workflow of the user experience. The first class named Note will have properties to represent our data model. namespace Website . Models {     public class Note     {         public int Id { get ; set ; }         public string Title { get ; set ; }         public string Body { get ; set ; }     } } The second class named NoteManager will be used to set up our simulated data storage and provide methods for querying and updating the data. We will take a look at the class content as a whole and then walk through each method after. using System . Collections . ObjectModel ; using System . Linq ; using System . Web ; namespace Website . Models {     public class NoteManager     {         public Collection < Note > Notes         {             get             {                 if ( HttpRuntime . Cache [ "Notes" ] == null )                     this . loadInitialData ();                 return ( Collection < Note >) HttpRuntime . Cache [ "Notes" ];             }         }         private void loadInitialData ()         {             var notes = new Collection < Note >();             notes . Add ( new Note                           {                               Id = 1 ,                               Title = "Set DVR for Sunday" ,                               Body = "Don't forget to record Game of Thrones!"                           });             notes . Add ( new Note                           {                               Id = 2 ,                               Title = "Read MVC article" ,                               Body = "Check out the new iwantmymvc.com post"                           });             notes . Add ( new Note                           {                               Id = 3 ,                               Title = "Pick up kid" ,                               Body = "Daughter out of school at 1:30pm on Thursday. Don't forget!"                           });             notes . Add ( new Note                           {                               Id = 4 ,                               Title = "Paint" ,                               Body = "Finish the 2nd coat in the bathroom"                           });             HttpRuntime . Cache [ "Notes" ] = notes ;         }         public Collection < Note > GetAll ()         {             return Notes ;         }         public Note GetById ( int id )         {             return Notes . Where ( i => i . Id == id ). FirstOrDefault ();         }         public int Save ( Note item )         {             if ( item . Id <= 0 )                 return saveAsNew ( item );             var existingNote = Notes . Where ( i => i . Id == item . Id ). FirstOrDefault ();             existingNote . Title = item . Title ;             existingNote . Body = item . Body ;             return existingNote . Id ;         }         private int saveAsNew ( Note item )         {             item . Id = Notes . Count + 1 ;             Notes . Add ( item );             return item . Id ;         }     } } The class has a property named Notes that is read only and handles instantiating a collection of Note objects in the runtime cache if it doesn't exist, and then returns the collection from the cache. This property is there to give us a simulated storage so that we didn't have to add a full blown database (beyond the scope of this post). The private method loadInitialData handles pre-filling the collection of Note objects with some initial data and stuffs them into the cache. Both of these chunks of code would be refactored out with a move to a real means of data storage. The GetAll and GetById methods access our simulated data storage to return all of our notes or a specific note by id. The Save method takes in a Note object, checks to see if it has an Id less than or equal to zero (we assume that an Id that is not greater than zero represents a note that is new) and if so, calls the private method saveAsNew . If the Note item sent in has an Id , the code finds that Note in the simulated storage, updates the Title and Description , and returns the Id value. The saveAsNew method sets the Id , adds it to the simulated storage, and returns the Id value. The increment of the Id is simulated here by getting the current count of the note collection and adding 1 to it. The setting of the Id is the only other chunk of code that would be refactored out when moving to a different data storage approach. With our model and data manager code in place we can turn our attention to the controller and views. We can do all of our work in a single controller. If we use a HomeController , we can add an action method named Index that will return our main view. An action method named List will get all of our Note objects from our manager and return a partial view. We will use some jQuery to make an AJAX call to that action method and update our main view with the partial view content returned. Since the jQuery AJAX call will cache the call to the content in Internet Explorer by default (a setting in jQuery), we will decorate the List, Create and Edit action methods with the OutputCache attribute and a duration of 0. This will send the no-cache flag back in the header of the content to the browser and jQuery will pick that up and not cache the AJAX call. The Create action method instantiates a new Note model object and returns a partial view, specifying the NoteForm.cshtml view file and passing in the model. The NoteForm view is used for the add and edit functionality. The Edit action method takes in the Id of the note to be edited, loads the Note model object based on that Id , and does the same return of the partial view as the Create method. The Save method takes in the posted Note object and sends it to the manager to save. It is decorated with the HttpPost attribute to ensure that it will only be available via a POST. It returns a Json object with a property named Success that can be used by the UX to verify everything went well (we won't use that in our example). Both the add and edit actions in the UX will post to the Save action method, allowing us to reduce the amount of unique jQuery we need to write in our view. The contents of the HomeController.cs file: using System . Web . Mvc ; using Website . Models ; namespace Website . Controllers {     public class HomeController : Controller     {         public ActionResult Index ()         {             return View ();         }         [ OutputCache ( Duration = 0 )]         public ActionResult List ()         {             var manager = new NoteManager ();             var model = manager . GetAll ();             return PartialView ( model );         }         [ OutputCache ( Duration = 0 )]         public ActionResult Create ()         {             var model = new Note ();             return PartialView ( "NoteForm" , model );         }         [ OutputCache ( Duration = 0 )]         public ActionResult Edit ( int id )         {             var manager = new NoteManager ();             var model = manager . GetById ( id );             return PartialView ( "NoteForm" , model );         }         [ HttpPost ]         public JsonResult Save ( Note note )         {             var manager = new NoteManager ();             var noteId = manager . Save ( note );             return Json ( new { Success = noteId > 0 });         }     } } The view for the note form, NoteForm.cshtml , looks like so: @model Website . Models . Note @using ( Html . BeginForm ( "Save" , "Home" , FormMethod . Post , new { id = "NoteForm" })) { @Html . Hidden ( "Id" ) < label class = "Title" >     < span > Title < /span><br / >     @Html . TextBox ( "Title" ) < /label> <label class="Body">     <span>Body</ span >< br />     @Html . TextArea ( "Body" ) < /label> } It is a strongly typed view for our Note model class. We give the <form> element an id attribute so that we can reference it via jQuery. The <label> and <span> tags give our UX some structure that we can style with some CSS. The List.cshtml view is used to render out a <ul> element with all of our notes. @model IEnumerable < Website . Models . Note > < ul class = "NotesList" >     @foreach ( var note in Model )     {     < li >         @note . Title < br />         @note . Body < br />         < span class = "EditLink ButtonLink" noteid = "@note.Id" > Edit < /span>     </ li >     } < /ul> This view is strongly typed as well. It includes a <span> tag that we will use as an edit button. We add a custom attribute named noteid to the <span> tag that we can use in our jQuery to identify the Id of the note object we want to edit. The view, Index.cshtml , contains a bit of html block structure and all of our jQuery logic code. @ {     ViewBag . Title = "Index" ; } < h2 > Notes < /h2> <div id="NoteListBlock"></ div > < span class = "AddLink ButtonLink" > Add New Note < /span> <div id="NoteDialog" title="" class="Hidden"></ div > < script type = "text/javascript" >     $ ( function () {         $ ( "#NoteDialog" ). dialog ({             autoOpen : false , width : 400 , height : 330 , modal : true ,             buttons : {                 "Save" : function () {                     $ . post ( "/Home/Save" ,                         $ ( "#NoteForm" ). serialize (),                         function () {                             $ ( "#NoteDialog" ). dialog ( "close" );                             LoadList ();                         });                 },                 Cancel : function () { $ ( this ). dialog ( "close" ); }             }         });         $ ( ".EditLink" ). live ( "click" , function () {             var id = $ ( this ). attr ( "noteid" );             $ ( "#NoteDialog" ). html ( "" )                 . dialog ( "option" , "title" , "Edit Note" )                 . load ( "/Home/Edit/" + id , function () { $ ( "#NoteDialog" ). dialog ( "open" ); });         });         $ ( ".AddLink" ). click ( function () {             $ ( "#NoteDialog" ). html ( "" )                 . dialog ( "option" , "title" , "Add Note" )                 . load ( "/Home/Create" , function () { $ ( "#NoteDialog" ). dialog ( "open" ); });         });         LoadList ();     });     function LoadList () {         $ ( "#NoteListBlock" ). load ( "/Home/List" );     } < /script> The <div> tag with the id attribute of "NoteListBlock" is used as a container target for the load of the partial view content of our List action method. It starts out empty and will get loaded with content via jQuery once the DOM is loaded. The <div> tag with the id attribute of "NoteDialog" is the element for our dialog widget. The jQuery UI library will use the title attribute for the text in the dialog widget top header bar. We start out with it empty here and will dynamically change the text via jQuery based on the request to either add or edit a note. This <div> tag is given a CSS class named "Hidden" that will set the display:none style on the element. Since our call to the jQuery UI method to make the element a dialog widget will occur in the jQuery document ready code block, the end user will see the <div> element rendered in their browser as the page renders and then it will hide after that jQuery call. Adding the display:hidden to the <div> element via CSS will ensure that it is never rendered until the user triggers the request to open the dialog. The jQuery document load block contains the setup for the dialog node, click event bindings for the edit and add links, and a call to a JavaScript function called LoadList that handles the AJAX call to the List action method. The .dialog() method is called on the "NoteDialog" <div> element and the options are set for the dialog widget. The buttons option defines 2 buttons and their click actions. The first is the "Save" button (the text in quotations is used as the text for the button) that will do an AJAX post to our Save action method and send the serialized form data from the note form (targeted with the id attribute "NoteForm"). Upon completion it will close the dialog widget and call the LoadList to update the UX without a redirect. The "Cancel" button simply closes the dialog widget. The .live() method handles binding a function to the "click" event on all elements with the CSS class named EditLink . We use the .live() method because it will catch and bind our function to elements even as the DOM changes. Since we will be constantly changing the note list as we add and edit we want to ensure that the edit links get wired up with click events. The function for the click event on the edit links gets the noteid attribute and stores it in a local variable. Then it clears out the HTML in the dialog element (to ensure a fresh start), calls the .dialog() method and sets the "title" option (this sets the title attribute value), and then calls the .load() AJAX method to hit our Edit action method and inject the returned content into the "NoteDialog" <div> element. Once the .load() method is complete it opens the dialog widget. The click event binding for the add link is similar to the edit, only we don't need to get the id value and we load the Create action method. This binding is done via the .click() method because it will only be bound on the initial load of the page. The add button will always exist. Finally, we toss in some CSS in the Content/Site.css file to style our form and the add/edit links. . ButtonLink { color : Blue ; cursor : pointer ; } . ButtonLink : hover { text - decoration : underline ; } . Hidden { display : none ; } #NoteForm label { display:block; margin-bottom:6px; } #NoteForm label > span { font-weight:bold; } #NoteForm input[type=text] { width:350px; } #NoteForm textarea { width:350px; height:80px; } With all of our code in place we can do an F5 and see our list of notes: If we click on an edit link we will get the dialog widget with the correct note data loaded: And if we click on the add new note link we will get the dialog widget with the empty form: The end result of our solution tree for our sample:

    Read the article

  • jQuery Tutorial: Validation with the jQuery UI Tabs Widget

    This is so long overdue, but I told Dave Ward last Summer I would post this Blog and well I have not been so good on that commitment. If you want to validate a form that is organized using the jQuery UI Tabs widget you probably need to perform validation...(read more)...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • To create an inbox like Gmail in jQuery, would something like the Accordion effect work for opening

    - by snoopy
    I've been looking for a pre-built jQuery component that I could use to build an inbox for a messaging application: http://jqueryui.com/demos/accordion/ I was thinking that if I could close all of the elements in the Accordion, that would be equivalent to showing a list of unopened messages when the user first logs into their Inbox. And then, by clicking on the leaves of the Accordion, they can see each message one by one. Is this a good idea or is there some other jQuery plugin that would work better for this type of functionality?

    Read the article

  • Should we be using JQuery for Mobile AJAX Page Navigation?

    - by Brad
    I am developing a mobile site that will load page content using AJAX if JavaScript is enabled. I have been using the JQuery load() functionality to load page contents from other static pages but I feel I am wasting precious bandwidth loading the entire JQuery library when I'm only using a small piece of it. With this said should we be avoiding libraries when only using small pieces of them?

    Read the article

< Previous Page | 66 67 68 69 70 71 72 73 74 75 76 77  | Next Page >