If you are eagle-eyed enough, you would have noticed that facebook actually doesn't poll unnecessarily from the server. Somehow it knows that you are away for sometime and when you are active and start to move your mouse, newer feeds starts loading.
<script type="text/javascript">
document.onmousemove = (function() {
var onmousestop = function() {
$('h1').css("color", "white");
}, thread;
return function() {
$('h1').css("color", "red") clearTimeout(thread);
thread = setTimeout(onmousestop, 200);
};
})();
Read more on this: Closures
I've embedded this scrip into the blog -> Blue H1, so don't panic if you see the h1 starts turning blue :)
Thursday, October 13, 2011
Thursday, September 29, 2011
Mimic wikipedia for SharePoint 2010 search
Recently, there was a user requirement for customizing SharePoint 2010 Enterprise wiki search control.
Objective: Mimicking Wikipedia search box functionality, whereby when a user enters a wiki page title, if there is an exact hit, we should redirect the user to the page, instead of displaying SharePoint's default result page. (Less the autocomplete)
Using jQuery & a bit of digging into SP.js, i found that internally, SharePoint actually uses a javascript function called "SubmitSearchRedirect", which actually redirects the user to "/_layouts/searchresults.aspx" and appending the search keyword as the querystring.
So a seemingly difficult request was actually completed in less than 10 mins.
function applyCustomSearch() {
$("#onetIDGoSearch").attr("onclick", ""); //user click on search img
$("#idSearchString").attr("onkeydown", ""); //user keystroke
$("#onetIDGoSearch").click(function() {
<Your AJAX function to check if the page exists>($("#idSearchString").val(), function(exactHit){
if(exactHit== true) { //simulate got exact hit
window.location = "http://"+ document.domain +"/<Your Enterprise Wiki Homepage>/" + $("#idSearchString").val() + ".aspx?ContextId=" + $.queryString("ContextId");
} else {
SubmitSearchRedirect("http://"+ document.domain +"/_layouts/searchresults.aspx");
}
});
});
$("#idSearchString").keydown(function (event) {
if (event.keyCode == '13') {
event.preventDefault();
<Your AJAX function to check if the page exists>($("#idSearchString").val(), function(exactHit){ if(exactHit== true) { //simulate got exact hit
window.location = "http://"+ document.domain +"/<Your Enterprise Wiki Homepage>/" + $("#idSearchString").val() + ".aspx?ContextId=" + $.queryString("ContextId");
} else {
SubmitSearchRedirect("http://"+ document.domain +"/_layouts/searchresults.aspx");
}
});
});
}
The logic is dead simple.
For my project, i used an event receiver to track all the articles by saving them into a database and creating a tag cloud. So i had the benefit of knowing exactly how many article pages and how they are being named. So all i did was a simple $.getJSON() to my custom RESTful WCF service, which returns a boolean, and the rest is straightforward.
For simpler projects, you can either use http://spservices.codeplex.com/ to query the wiki pages library for the article existence.
I shall do a blogpost on how to embed jQuery library into SharePoint 2010 in the subsequent posts.
Wednesday, September 21, 2011
GSPMigrator source code release
After leaving the source codes for this tool, i've decided to put it on CodePlex with the GNU v2 licence, hoping that it will support and help any one that needs to migrate files into SharePoint 2007 (and in the future 2010).
GSPMigrator is basically a migration tool that allows anyone within the network to connect to a network drive and view it with a tree view.
GSPMigrator is basically a migration tool that allows anyone within the network to connect to a network drive and view it with a tree view.
![]() |
There are several problems (although there are still some minor ones) that i went through before coming out with this version:
- Lazy-loading vs eager-loading on generating tree views
Lazy-loading will give better user experience.
Tuesday, September 20, 2011
Customising SharePoint 2010 enterprise wiki
Requirements:
There are 3 different business context:
There are 3 different business context:
- Work
- Personal
- Entertainment
When a user comes into the wiki site, there will be a visual webpart embedded in the form to scope this document to 1 of the above 3 context. So if the user would like to post a Work-related wiki article, he can select an option (dropdown list or radio button etc, but on my POC it's only a textbox :P) and when he click on the sharepoint save & close button
the permission of the article will be restricted based on predefined rules.
Solution (after some thoughts):
- Event receiver to set permissions
- Using HttpContext in EventReceiver synchronous events (itemAdding & itemUpdating) to get the value to b
- Customising the master page to include a VWP (visual webpart) to allow user select "context"
Thursday, July 21, 2011
.Net technical test drawing mountains
Recently, my friend was given a technical test during an interview, i realized that it's a rather common "test" given to interviewees. I took up the challenge and squeeze out some time to do it.
The interviewer asked my friend to write a console application that reads from user's keyboard input, when the user enters a number, draw a mountain with the user input as the number of back and forward slashes. (of course, with bigger numbers, the subsequent layers need more padding between the slashes).
I wasn't exactly sure how the question was structured, but based on my understanding, iscribbled typed the expected end results on a text editor.
/\ gap=0, space=0, input=1
/\ gap=1, space=0, input=2 (print new line)
/ \ gap=0, space=2
/\ gap=2, space=0, input=3 (print new line)
/ \ gap=1, space=2 (print new line)
/ \ gap=0, space=4 (print new line)
/\ gap=3, space=0, input=4
/ \ gap=2, space=2 (print new line)
/ \ gap=1, space=4 (print new line)
/ \ gap=0, space=6 (print new line)
So, with my iPad showing me the expected results and my primary monitor with visual studio 2010... i started writing some loops:
using System;
namespace DrawMountains
{
class Program
{
static void Main(string[] args)
{
int inputNum;
if (int.TryParse(Console.ReadLine(), out inputNum))
{
for (int i = 0; i < inputNum; i++)//print tip of mountain & padding (if any)
{
int temp = inputNum-i; //amount of padding to print
while (temp > 1) //amount of space before left slope
{
PrintSpace();
temp--;
}
PrintLeftSlope();
//----------------prints all left slope correctly (up to n num)
int temp2 = i*2;
for (int j = 0; j<temp2; j++) //padding between the slashes
{
PrintSpace();
}
PrintRightSlope(); //self-explanatory
}
Console.ReadKey();
}
else
{
Console.WriteLine("Invalid input");
Console.ReadKey();
}
}
static void PrintLeftSlope()
{
Console.Write("/");
}
static void PrintRightSlope()
{
Console.WriteLine(@"\");
}
static void PrintSpace()
{
Console.Write(" ");
}
}
}
The interviewer asked my friend to write a console application that reads from user's keyboard input, when the user enters a number, draw a mountain with the user input as the number of back and forward slashes. (of course, with bigger numbers, the subsequent layers need more padding between the slashes).
I wasn't exactly sure how the question was structured, but based on my understanding, i
/\ gap=0, space=0, input=1
/\ gap=1, space=0, input=2 (print new line)
/ \ gap=0, space=2
/\ gap=2, space=0, input=3 (print new line)
/ \ gap=1, space=2 (print new line)
/ \ gap=0, space=4 (print new line)
/\ gap=3, space=0, input=4
/ \ gap=2, space=2 (print new line)
/ \ gap=1, space=4 (print new line)
/ \ gap=0, space=6 (print new line)
So, with my iPad showing me the expected results and my primary monitor with visual studio 2010... i started writing some loops:
using System;
namespace DrawMountains
{
class Program
{
static void Main(string[] args)
{
int inputNum;
if (int.TryParse(Console.ReadLine(), out inputNum))
{
for (int i = 0; i < inputNum; i++)//print tip of mountain & padding (if any)
{
int temp = inputNum-i; //amount of padding to print
while (temp > 1) //amount of space before left slope
{
PrintSpace();
temp--;
}
PrintLeftSlope();
//----------------prints all left slope correctly (up to n num)
int temp2 = i*2;
for (int j = 0; j<temp2; j++) //padding between the slashes
{
PrintSpace();
}
PrintRightSlope(); //self-explanatory
}
Console.ReadKey();
}
else
{
Console.WriteLine("Invalid input");
Console.ReadKey();
}
}
static void PrintLeftSlope()
{
Console.Write("/");
}
static void PrintRightSlope()
{
Console.WriteLine(@"\");
}
static void PrintSpace()
{
Console.Write(" ");
}
}
}
This post is purely for educational purposes, no point for memorizing this sample and contrived effort. I believe the interviewer's purpose is to see how strong are you in the way you design your algorithms, handling exception (which i didn't do) and perhaps your naming convention and formatting.
Subscribe to:
Posts (Atom)

