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

Sunday, September 23, 2012

Select custom ribbon tab - jQuery

    I created custom ribbon tab and a button on a page. When  a user press the button on the page, I needed to focus him to the custom ribbon tab. Of course, I used 
_ribbonStartInit("Ribbon.CustomTab", false, null);

but the problem is, after a user changes it to another tab, i.e. "Read" or "Browse" the second pressing doesn't work. Therefore, the solution was - adding SelectRibbonTab() function:

$('img.CustomTabButtonClass').bind('click', function() { 
    
  if (typeof(_ribbonStartInit) == "function")
   {
     try 
     {
       _ribbonStartInit("Ribbon.CustomTab", false, null);
     }
     catch(e)
       {
                  
        }
     SelectRibbonTab("Ribbon.CustomTab", true);
    }
    });

Tuesday, September 11, 2012

The vertical scrolling bar doesn't work in Chrome browser

Like most of us, I faced this problem when scroll bar doesn't work in Chrome.
After googling, the solution was a jQuery script which I inserted to the master page:



Wednesday, August 8, 2012

Add Title to Social Comments - jQuery

To insert some title or another text to social comments on a page:
You can resolve it by jQuery code:


  $(document).ready(function () {

            var socomHolders = $('div [id*="_socomHolder_"]');
            if (socomHolders.length) {

                socomHolders.each(function () {

                    var phName = $(this).attr('id');
                    var index = phName.substring(phName.lastIndexOf('socomHolder') + 
                        12, phName.length);

                    var socomContent = $('div [id*="_socomContents_' + index +'"]');
                    var newRow = $("Example : "+ index +"");
                    $(".ms-socialCommentItem", socomContent).prepend(newRow);
                });
            }
        });


Monday, May 28, 2012

jQuery - Extension to SPServices.SPCascadeDropdowns

We use SPServices.SPCascadeDropdowns , after 20 items it looks like this:




Instead of:









but the problem is that it doesn't work with Wiki Pages.
Therefore I wrote little extension which helps me to solve this problem.

I changed two things:
1.
After : "var defaultViewUrl = $(this).attr("DefaultViewUrl");"
insert code :

if (listPath.indexOf('/PAGES/') > 0)
{ listPath = listPath + 'FORMS/'; }



2.
Instead of "$(columnSelect.Obj).closest("td").prepend(simpleSelect);"
replace with :

if ($(columnSelect.Obj).closest("td").length)
{ $(columnSelect.Obj).closest("td").prepend(simpleSelect); }
else
{ $(columnSelect.Obj).closest("span").prepend(simpleSelect); }


Tuesday, April 24, 2012

JQuery - TaxonomyFieldControl changed

In some case I needed to catch a event if TaxonomyFieldControl was changed.
The solution was here.
So, I added a plugin to my .js file


jQuery.fn.contentChange = function(callback){
 var elms = jQuery(this);
 elms.each(
   function(i){
var elm = jQuery(this);
elm.data("lastContents", elm.html());
        window.watchContentChange =                                                                            window.watchContentChange 
               ? window.watchContentChange : [];
window.watchContentChange.push({"element": elm, "callback": callback});
                })
return elms;
}
setInterval(function(){
   if(window.watchContentChange){
       for( i in window.watchContentChange){
     if(window.watchContentChange[i].element.data("lastContents")!=
         window.watchContentChange[i].element.html())
        {
          window.watchContentChange[i].callback.apply(window.watchContentChange[i].element);
 window.watchContentChange[i].element.data("lastContents",
 window.watchContentChange[i].element.html())
};
  }
  }
},500);

...and in the end I put this code to watch it.


$('div#taxonomyName').contentChange(function(){

//TO DO
});