Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

Monday, January 6, 2014

News Slider with multiple data sources for SharePoint (Content Query Webpart).

Project Description

News Slider is built for SharePoint 2007, 2010, 2013 which covers the below technical specifications
Technical Specifications:
  • Built for SharePoint 2007, 2010, 2013
  • Fetch data from multiple libraries (ex: Document Libraries, Pages Libraries)
  • jQuery based rendering
  • Enhanced/ Customized Content Query webpart
  • Responsive
    • Adapt to any screen
  • Touch
    • Swipe support that tracks touch movements on supported devices
  • CSS3 transitions
    • Animations that run smoothly on modern devices
  • Display only specified items
  • Display only published items
  • Display as per your sort order
  • Play/Pause
  • Next/Previous
  • Pause on Hover
Dependancies:
  • jQuery 1.7.1+ 
Download:
https://sharepointnewsslider.codeplex.com/

instructions document is available under downloads tab
 
Screenshots:


Thanks to SlidesJS team for developing a responsive and flexible Slider plugin based on jQuery. Please donate for their hardwork

Thursday, November 11, 2010

PushPin to show or hide DIV and maintain state across pages and Users using JQuery

JQuery has very cool features, providing the wide range of plugins to play around with your webpage. Here in this post I m going to discuss regarding a requirement I had to make use of JQuery to maintain the state of a DIV across pages, as well as across Users logged into the application.

Requirement:

This requirement is to provide interface for searching certain content in the SharePoint List based upon the keywords. This search window/pane should have the capability of toggle, as well as the capability of fixing/pin down (stopping toggle i.e showing the DIV) which should be maintained across the pages in the application untill the user either closes the pane or unfix. Also, this provision should be available as per the User choice, logged in to the application.

Example:
For better understanding we shall consider two user's named User1 & User2. When User1 loggs in to the application and prefers to pin down the DIV after showing DIV by toggle, that DIV should be in open state, in all the pages being traversed, untill preferred to pin up. But this preference should not reflect to User2, as this user might not prefer to search or looking into the DIV.

Challenges:
  1. Maintaining the Open/Close state across all pages based upon the preference to show/hide respectively.
  2. Maintain the Open/Close state based upon the logged in User preference to show/hide respectively.

Solution:
  1. Add Script References for
    JQuery Plugin:
    
    
    Download: http://jquery.com/

    Sessions Plugin:
    Download: http://plugins.jquery.com/node/8213/release

    JSON Plugin:
    
    
    Download: http://www.json.org/json2.js
  2. Create a DIV tag holding all your content as below:
    Note:Styles & images are from JQuery UI Smoothness theme.
  3. Add the below script in the head tag
    $(document).ready(function() {
    
     $.namesession.set("LoggedInUser",$().SPServices.SPGetCurrentUser({fieldName: "UserName", debug: false}));
    
     var SearchWindowStatus= ($.namesession.get('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''), '')!= '')?$.namesession.get('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''), '') :$.namesession.set('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''),false);
    
     if(SearchWindowStatus){
      $('#SearchFund-dialog').show();
      $("a[id$=anchorPinPoint]").children().removeClass('ui-icon-pin-w').addClass('ui-icon-pin-s').attr('title','Keep Search Closed');  
    
     }else{
      $('#SearchFund-dialog').hide();
     }
    
    
    
     $(this).click(function() {
    
       $('#SearchFund-dialog').toggle(); 
     }):
    
    
     $("a[id$=anchorPinPoint]").bind({
    
           mouseover:function() {
          $(this).addClass('ui-state-hover');
         },
         mouseout:function() {
          $(this).removeClass('ui-state-hover');
         },
        
        focus:function() {
         $(this).addClass('ui-state-focus');
         },
        blur:function() {
         $(this).removeClass('ui-state-focus');
         },
        click:function() { 
        
          TogglePinPoint(this)
    
         
         return false;
    
         }
      });
        
     function TogglePinPoint(ctrl)
     {
      if($(ctrl).children().hasClass('ui-icon-pin-w'))
       {
        $(ctrl).children().removeClass('ui-icon-pin-w').addClass('ui-icon-pin-s').attr('title','Keep Search Closed');  
        $.namesession.set('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''),true);
       }else if($(ctrl).children().hasClass('ui-icon-pin-s'))
       {
        $(ctrl).children().removeClass('ui-icon-pin-s').addClass('ui-icon-pin-w').attr('title','Keep Search Open');  
        $.namesession.set('SearchWindowStatus_'+$.namesession.get('LoggedInUser',''),false);
    
      } 
     }
    });
    

Note: Ensure your web.config file is configured for AJAX & JSON
Enable SessionState is set to true in the config file

Wednesday, April 7, 2010

Handling ClientID issues in SharePoint Webparts & jQuery

In ASP.NET/SharePoint a Control has a fully qualified ID that can be deduced from the control hierarchy and can be accessed with the properties ClientID or UniqueID. It then becomes the unique id or name of rendered html controls. It makes sense that these properties should be used right after the control hierarchy is completely defined, that means before the rendering, therefore in the PreRender.

What is not so well known is that accessing those two properties sets the _cachedUniqueID member, which sets irrevocably the ID to a control. That's why using these properties in ItemCreated events, for example, makes the html id of controls to remain the default defined one.

Example: In a DataList, you have an item template that contains a control, let's call it Control1. The rendered id in html will look like this: ctl00_m_g_aaf13d41_fc78_40be_81d5_2f40e534844f_txtName, but if you use ClientID inside the DataList_ItemCreated event, the rendered html id will be just Control1, thus making any javascript manipulation futile.

Of course, one could create a method to return the UniqueID without setting the cached value, since there are moments when the partial hierarchy is enough to define a proper id. Unfortunately, for controls without a specific and declared id, ASP.NET creates and automatic ID like ctl[number] or _ctl[number] and, of course, those methods and fields are all private or internal. One could use Reflection to get to them, but what would be the point?

UniqueID and ClientID are overridable, though, so one can change their behaviour in user defined controls.

Solution for handling in jQuery, Javascript & SharePoint Webparts (C#).

jQuery is fantastic! It makes client-side development faster and countless plug-ins are available for just about every need. Using jQuery with Asp.NET Web-Forms gets aggravating when dealing with nested server controls. ClientID’s get appended when using ASP.NET Master Pages. Objects in JavaScript tend to look like this:
ctl00_m_g_aaf13d41_fc78_40be_81d5_2f40e534844f_txtName
The difficulty of the issue above is that, in order to get the element txtName, It’s necessary to know the full “path”. It’s quite aggravating to refer to get the object using the method below:
document.getElementByID('ctl00_m_g_aaf13d41_fc78_40be_81d5_2f40e534844f_txtName');
This becomes a big problem when developing server controls or web parts that may be used in a typical ASP.NET application or SharePoint. You cannot hard-code the path above if you don’t know the full path of the control.

Fortunately, there are a few ways to get around this. There are three, in particular, I will mention. The first is the jQuery equivalent to the standard JavaScript method:
document.getElementById("<%=txtName.ClinetID%>");");
This can be done in jQuery by using:
$("#'<%=txtName.ClinetID%>");");
The second jQuery method does not require server tags. This method searches through all tags and looks for an element ending with the specified text. The jQuery code for this method is shown below:
$("[id$='_txtName']");
There are, of course, drawbacks to both methods above. The first is fast, but requires server tags. It’s fast, but it just looks messy. Also, it will not work with external script files. The second alternative is clean, but it can be slow. As I said earlier, there are several other alternatives, but these two are the ones I find myself using the most.

The third registering Javascript in C# code behind.
Page.ClientScript.RegisterStartupScript(GetType(), "saveScript",

String.Format("function EnableSave( isDisabled )"+

"{{ var saveButton = document.getElementById(\"{0}\");"+

"saveButton.disabled=isDisabled;}}", btnSave.ClientID), true);

Do not forget to call this script after controls have been loaded, I mean after Controls.Add(); in CreateChildControls method while developing webparts.