CHUVASH.eu
  • About
  • Search

Posts

January 4, 2013

javascript: show only a part of a long string (ellipsis)

Ellipsis (…) is a character which indicates that the content is to wide. There are many solutions to truncate the text and show an ellipsis: in javascript and css. I want to share my humble function which extends the String.prototype: [sourcecode language=“javascript”]String.prototype.ellipsize = function(maxLength) { maxLength = maxLength || 100; if (this.length <= maxLength) { return this; } var text = this.toString().replace(/[\r\n]/g, “”), max = maxLength, min = maxLength - 20, elipsized, tryExtract = function () { var regex = new RegExp("^.{" + min + “,” + max + “}\\s”), match = text.match(regex); if (match) { elipsized = match[0].replace(/\.?\s$/, ‘…’); } else { //well, there were no \s between min and max min = min - 20; tryExtract(); } }; if (min <= 0) { return text; } tryExtract(); return elipsized || text; };[/sourcecode] To use it, just call the function from a string property in your favorite templating engine: Angular, jsRender, Knockout….: [sourcecode language=“javascript”]order.description.ellipsize();[/sourcecode] This function takes an argument maxLength (default 100 chars). It doesn’t cut your text in the middle of a word, that’s why it looks after a whitespace in range of maxLength-20 and maxLength.

read more
December 31, 2012

2012 in review

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

4,329 films were submitted to the 2012 Cannes Film Festival. This blog had 54,000 views in 2012. If each view were a film, this blog would power 12 Film Festivals

Click here to see the complete report.

Comments from Wordpress.com

Justin Cooney - Jan 3, 2013

read more
December 28, 2012

Cool presentation about web performance optimization

by Chris Love [slideshare id=15218139&doc=webperformanceoptimizationformodernwebapplications-121116224847-phpapp01]

read more
December 11, 2012

PowerShell: Copy an entire document library from SharePoint 2007 to disk

For a while ago I needed to copy all files from a document library within a SharePoint 2007 site to the hard drive. So I didn’t need to copy files from SharePoint to SharePoint so I couldn’t use the stsadm -o export command or Chris O’Brien’s nice SharePoint Content Deployment Wizard. I came across the SPIEFolder application which should work with SharePoint 2007 and 2010. It has a site on codeplex: spiefolder.codeplex.com, but neither the binary nor the source code can be downloaded from there. After some searching I found the binary in the author’s skydrive. The fact that the source code was not available seemed as an disanvantage because I could not know what code was run. Nevertheless I tried it out and it didn’t work:

read more
December 6, 2012

Run web.config-dependant code in PowerShell

PowerShell is a great tool. It helps in SharePoint administration and tasks automation. Today I needed to provision a webpart on many similar pages. This third-party webpart’s constructor instantiates a dataaccess service and uses a connectionstring which is stored in the web.config file. So the webpart creation failed until I found a way to load the configuration into powershell. First you can create a simple file powershell.exe.config, put it into $pshome (C:\Windows\System32\WindowsPowerShell\v1.0). In that file you can specify the connectionstring in the same way like in the web.config (or app.config). But it is not secure: the connectionstring can be changed in the future, and you really don’t want to copy your connectionstrings around. So there is a better way: Check out Ohad Israeli’s blog post about how a configuration file can be bound dynamically in a .net assembly: Binding to a custom App.Config file. In PowerShell you can do the same, all we need is to modify the syntax: StackOverflow: Powershell Calling .NET Assembly that uses App.config:

read more
November 22, 2012

Create SPGroup in PowerShell

Thanks to Ryan for sharing powershell functions. I used New-SPGroup which I altered. Now You can define which permissions will be given to the new group. You can even create groups without default users. Here it comes:

 
function New-SPGroup {
<#
.Synopsis
	Use New-SPGroup to create a SharePoint Group.
.Description
	This function uses the Add() method of a SharePoint RoleAssignments property in an SPWeb to create a SharePoint Group.
.Example
New-SPGroup -Web http://intranet -GroupName "Test Group" -OwnerName DOMAIN\\User -MemberName DOMAIN\\User2 -Description "My Group" -Role "Read"
	This example creates a group called "Test Group" in the http://intranet site, with a description of "My Group".  The owner is DOMAIN\\User and the first member of the group is DOMAIN\\User2 and adds "Limited Access".
	C:\\PS>New-SPGroup -Web http://intranet -GroupName "Test Group" -OwnerName DOMAIN\\User -MemberName DOMAIN\\User2 -Description "My Group" -Role "Read"
	This example creates a group called "Test Group" in the http://intranet site, with a description of "My Group".  The owner is DOMAIN\\User and the first member of the group is DOMAIN\\User2 and adds "Read" access.
	Pay attention to the role definition names. They must be provided in the language of your site.
.Notes
	Name: New-SPGroup
	Author: Ryan Dennis, Anatoly Mironov
	Last Edit: 2012-11-05
	Keywords: New-SPGroup, spgroup, permissions
.Link
	http://www.sharepointryan.com
 	http://twitter.com/SharePointRyan
	https://sharepointkunskap.wordpress.com
.Inputs
	None
.Outputs
	None
#Requires -Version 2.0
#>
	\[CmdletBinding()\]
	Param(
	\[Microsoft.SharePoint.PowerShell.SPWebPipeBind\]$Web,
	\[string\]$GroupName,
	\[string\]$OwnerName,
	\[string\]$MemberName,
	\[string\]$Role,
	\[string\]$Description
	)
	$SPWeb = $Web.Read()
	if ($SPWeb.SiteGroups\[$GroupName\] -ne $null){
		throw "Group $GroupName already exists!"	
	}

	if ($Role) {
		$roleDefinition = $SPWeb.RoleDefinitions\[$Role\]
		if (!$roleDefinition) {
			throw "Role Definition $Role doesn't exist!"
		}
	}

	if ($SPWeb.Site.WebApplication.UseClaimsAuthentication){
		$op = New-SPClaimsPrincipal $OwnerName -IdentityType WindowsSamAccountName
		$owner = $SPWeb | Get-SPUser $op
		if ($MemberName) {
			$mp = New-SPClaimsPrincipal $MemberName -IdentityType WindowsSamAccountName
			$member = $SPWeb | Get-SPUser $mp
		}
	}
	else {
	$owner = $SPWeb | Get-SPUser $OwnerName
		if ($MemberName) {
			$member = $SPWeb | Get-SPUser $MemberName
		}
	}

	$SPWeb.SiteGroups.Add($GroupName, $owner, $member, $Description)
	$SPGroup = $SPWeb.SiteGroups\[$GroupName\]	
	$roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($SPGroup)
	if ($Role) {
		$roleAssignment.RoleDefinitionBindings.Add($roleDefinition)
	}
	$SPWeb.RoleAssignments.Add($roleAssignment)
	$SPWeb.Dispose()
	return $SPGroup
}
read more
November 22, 2012

AngularJS: sync $location.search with an input value

I have used AngularJS for a while and to me this seems to be the best MVC javascript framework. Today I wanted to implement a search which uses an input and a hash query string like in google. The input value and url have to be synced like:

index.html#?term=something

To do this we have to inject $location into our angular control. See the Angular Guide about $location. Then we have to observe both the $scope.term (which is bound to the input value) and $location.search().

read more
November 8, 2012

Determine if Silverlight is installed (javascript)

For a while ago I needed to provide an alternative solution when Silverlight isn’t installed. I searched  for javascript code for this and found this:

  • A blog post about that: Piotr Puszkiewicz’s Silverlight Blog. Determining if Silverlight is installed using Javascript.
  • A more advanced javascript function which can even determine the version of the Silerlight can be pulled from Silverlight.js library.

I didn’t need to determine the version of Silverlight, so I wrote a simplified js function (but it works in all browsers): [sourcecode language=“javascript”] var isSilverlightInstalled = function() { var installed = false; try { installed = !!navigator.plugins[“Silverlight Plug-In”] || !!(window.ActiveXObject && new ActiveXObject(‘AgControl.AgControl’)); } catch (e) {} return installed; };[/sourcecode] This function first checks if a Silverlight plugin is installed in almost all web browsers except IE, then if it is not it tries to create an ActiveXObject (IE) for Silverlight. If an error occurs, the function returns false and indicates that Silverlight is not available.

read more
October 30, 2012

JSOM: Alter a column's DisplayName

Here is another article in my JSOM series. For one month ago I showed how to alter a column’s ShowInDisplayForm property with JSOM. This time I’ll show a code sample for changing a column’s (field’s) display name. If you want to alter the displayname with Server Object Model, grab the code in the sharepoint.stackexchange.com: Change Field’s DisplayName in a List. [sourcecode language=“javascript”]var ctx = SP.ClientContext.get_current(), //SP.ClientContext field = ctx.get_web() //SP.Web .get_lists() //SP.ListCollection .getByTitle(‘MyList’) //SP.List .get_fields() //SP.FieldCollection .getByInternalNameOrTitle(“Body”); //SP.Field ctx.load(field, “Title”); //load only Title ctx.executeQueryAsync(function() { field.set_title(“Beskrivning”); field.update(); ctx.executeQueryAsync(); });[/sourcecode]

read more
October 23, 2012

Delete all list items with jsom

Today I needed to “clean” a list, meaning to remove all list items. For some time ago I wrote a post about different ways of removing list items in bulk: Server Object Model, SPLinq and RPC.  This time I had only the web browser. So I tried the jsom way. By the way, the javascript documentation for jsom on msdn is getting really good. Don’t miss that: How to: Complete basic operations using JavaScript library code in SharePoint 2013. Now here comes theworking code I used to remove all items in my list:

read more
  • ««
  • «
  • 18
  • 19
  • 20
  • 21
  • 22
  • »
  • »»
© CHUVASH.eu 2026