JQuery: Get Rid off SharePoint Spell Check


Hi Guys,

After spending 3-4 hours of struggle, I finally found way to get rid off irritating SharePoint Spell checker. It caught people picker too under the umbrella of spell check, but why, usually it does not required. Well again it may be the requirement.

But for my case, I don’t want it to watch any of my control on whole site. I tried to navigate to Manage Farm Features > Spell Check feature. Even after deactivating this feature it still working like a stubborn functionality. Then I realized that nothing is impossible for a developer. I have JQuery with me I can hide that control.

Resolution:

1) Hiding spell check from the Ribbon: in order to hide the spell check feature to end user, trick that worked for me is to add following line in my custom js:

$(‘a:has(img[src*=”images/spellingHH.png”])’).parents(“li”).hide();

2) Exclude fields from the spell check feature: I have created follwoing method to exclude people picker and other inputs fields from spell check:

function DisableSpellCheck() {
var tagclass = $(“input”).attr(‘class’);
if (tagclass !== undefined) {
tagclass = tagclass.replace(‘ ms-spellcheck-true’, ”);
}
$(“.input”).attr(‘class’, tagclass);

var $fld_in = $(“div.authorEdit input”);
var $fld_tx = document.getElementsByTagName(‘textarea’);

for ($i = 0; $i < $fld_in.length; $i++) {
var $inputName = $fld_in[$i].getAttribute(‘name’);
if ($inputName.indexOf(‘UserField’) != -1) {
$fld_in[$i].className = ‘ms-spellcheck-false’;
}
}
for ($i = 0; $i < $fld_tx.length; $i++) {
var $inputName = $fld_tx[$i].getAttribute(‘name’);
if ($inputName.indexOf(‘UserField’) != -1) {
$fld_tx[$i].setAttribute(“excludeFromSpellCheck”, “true”);
}
}
}

Note: “authorEdit” is the custom class added to the people picker.

If you add this line of code to your master page or document.ready function of the page layout it will solve this issue.

Hope this little trick might helpful.

Happy SharePointing :)!!

Advertisements

Powershell: Change Like and comments settings of a library


Hi,

Recently I was working on the requirement to enable the like and comments settings of any library. So I prefer to use PowerShell script for same. I am sharing the code as below:

function Change-SettingsForLikeComment()
{
# Change page library settings for Likes and comments
$list=$web.Lists[“Pages”];
if($list -ne $null)
{
Write-Host $list.Title “not null”;
$assembly=[System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
$reputationHelper =$assembly.GetType(“Microsoft.SharePoint.Portal.ReputationHelper”);

$bindings = @(“EnableReputation”, “NonPublic”, “Static”);
[System.Reflection.BindingFlags]$flags = [System.Reflection.BindingFlags]::Static -bor [System.Reflection.BindingFlags]::NonPublic;

$methodInfo = $reputationHelper.GetMethod(“EnableReputation”, $flags);

#For enabling Ratings
#$values = @($list, “Ratings”, $false);

#OR for enabling Likes
$values = @($list, “Likes”, $false);

$methodInfo.Invoke($null, @($values));

#For disable Rating or Likes
<#$methodInfo = $reputationHelper.GetMethod(“DisableReputation”, $flags);
$disableValues = @($list);
$methodInfo.Invoke($null, @($disableValues));#>
}
}

 

This code will work for Pages library as in most of the cases we prefer to use pages library as a news library. One just have to create a $web object by using the command:

$url= “<url of your sute>“;
$web=Get-SPWeb $url;

and call the method:

Change-SettingsForLikeComment

Thatz it for now. Thanks for time.

Will be back with more scripts!!

Powershell: Update “Subsite Templates” under AreaTemplateSettings.aspx


Hi,

This time I am discussing about how one can update the “AvailableWebTemplates” once you have created a site. Just for the information, we can define this property in Onet.xml while creating any new site. But what if you have created sites, sub sites underneath and sub sub sites underneath, in that case you need a power shell script to update all those values.

Background: This property is defined in Onet as shown below:

<Feature ID=”22A9EF51-737B-4ff2-9346-694633FE4416″>

—————–

<Property Key=”AvailableWebTemplates” Value=”*-CMSPUBLISHING#0;*-BLANKINTERNET#2;*-ENTERWIKI#0;*-SRCHCEN#0″/>

———————

</Feature>

But once site is created using this site template, we have to dig down to update this. Using power shell its quite easy task provided you must know the Id and template name.

Work Arround:

We using the below mention code we can override the web template property. In order to update that we must know the name of template which we want to update its like CMSPUBLISHING#0 ,it follows the rule of <template name>#<configuration id>. How to get the web template

So after that run the following code in power shell:

$url = ‘http://sgtspweb01/&#8217;

$SPSite = Get-SPSite -Identity $url

foreach ($SPWeb in $SPSite.AllWebs)
{
$SPWeb.AllProperties[“__WebTemplates”] = ‘<webtemplates><lcid id=”all”><webtemplate name=”CMSPUBLISHING#1″ /><webtemplate name=”CMSPUBLISHING#0″ /></lcid></webtemplates>’
$SPWeb.Update();
$SPWeb.Dispose();

write-host “Template ‘” $templateName “‘succesfuly added to web on ” $SPWeb.Url
}

Notice that “__WebTemplates” property stores the value in the xml template, so sometimes you have to just add one template then you must get the existing value of the property first then update it with the desired one.

Some times you may need to know the site template of the existing site. The code to get the title and Id of web template for any site is as follows:

$web = Get-SPWeb http://portal
write-host “Web Template:” $web.WebTemplate ” | Web Template ID:” $web.WebTemplateId
$web.Dispose()

Hope that helped you.

Happy SharePointing :)…