Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Tuesday, August 7, 2018

Discussion List Reply Link in SharePoint 2013 and Online

Initially it was possible to achieve this using calculated column and concatenate anchor tag and generate a link. However after latest CU release, this is not possible anymore.
Following steps will help you to create a hyperlink column for discussion reply link in SharePoint 2013 or Online. Also it will help you to create a normal calculated hyperlink column in SharePoint 2013 and Online.


1. Below snap in about Discussion list default view and you are targeting to create highlighted link.

2. Create new Single link text Calculated column and add it in Discussion content type.
PN: Select Do not add it in All Content Types while creating a column.


3. Create a simple list view and make sure it consists your new calculated column.


4. Now on the list view page, add new Script Editor or Content Editor webpart.


5. Insert following script to the webpart.


<script>
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
  Templates: {
        Fields: {

          //Replace "ReplyLink" with Calculated column name
           'ReplyLink': {'View':function(ctx) {
                  var url = String.format('{0}/Flat.aspx?RootFolder={1}/{2}', ctx.listUrlDir, ctx.listUrlDir,ctx.CurrentItem.Title);
                  return String.format('<a href="{0}" onclick="EditItem2(event, \'{0}\');return false;">{1}</a>', url, "Bid for the Job");
           }}
       }
  }
});
</script>




6. Save the page and you can access the link in Calculated column.


PN: Whenever you want such functionality, you need to add new webpart on list view page and insert the same script.

Tuesday, June 18, 2013

JavaScript to Create Media player In SharePoint 2010

Steps to Create Media player In SharePoint 2010 using JavaScript:

1. Create new page in SharePoint site

2. Get <div> on newly created page

Example: <div id=”videoHolder”></div>

3. If page is inherited from master page, find “PlaceHolderAdditionalPageHead” and insert script tag with source as “_layouts/mediaplayer.js”

Example: <script type="text/javascript" src="_layouts/mediaplayer.js"></script>

4. Have one more script tag with following content:

<script type="text/javascript" >

_spBodyOnLoadFunctionNames.push("CreateMediaPlayer");

function CreateMediaPlayer()
{
    var videoUrl = “/Videos/MyVideo.wmv”; // video URL
    insertVideo(document.getElementById("videoHolder"),videoUrl);
}
function insertVideo(videoHolder,videoURL)
{
    mediaPlayer.createMediaPlayer(videoHolder,videoHolder.id, '400px','266px',
    {
         displayMode:'Inline',

         mediaTitle:’Help Video',
         mediaSource:videoURL,
         previewImageSource:'',
         autoPlay:true,
         loop:true,
         mediaFileExtensions:'wmv;wma;avi;mpg;mp3;',
         silverlightMediaExtensions:'wmv;wma;mp3;'
    });
}
</script>


5. Make sure the 
value of variable "videoUrl" is set correctly.

5. Save the page. That’s it!!!

6. Open the page and see the magic.

Thursday, June 13, 2013

SharePoint Modal Window Using JavaScript

Two ways to open SharePoint Modal Window using JavaScript:

1. Using the DialogOptions class.
var options = SP.UI.$create_DialogOptions();

options.title = "My Dialog Title";
options.width = 400;
options.height = 600;
options.url = "/_layouts/DialogPage.aspx";

SP.UI.ModalDialog.showModalDialog(options);

2. Using a generic object.
var options = {
    title: "My Dialog Title",
    width: 400,
    height: 600,
    url: "/_layouts/DialogPage.aspx" };

SP.UI.ModalDialog.showModalDialog(options);

Ref.: http://msdn.microsoft.com/en-us/library/ff410058(v=office.14).aspx

Friday, May 31, 2013

SharePoint "Download A Copy" from a SP Document Library

Generate a link using below format:
http://spsite/subsite/_layouts/download.aspx?SourceUrl=http://spsite/subsite/shared documents/file.docx

And use this URL in Anchor tag / window.open etc. as per the requirement.

Hope that helps.

Tuesday, May 7, 2013

Using JavaScript In OnLoad Event Of Body SharePoint 2010

When developing web parts or other SharePoint controls many times we might require to call some functions on body onload event. As web part does not contain body tag we cannot use onload attribute of body tag.

To overcome this drawback, a developer can use an array i.e. _spBodyOnLoadFunctionNames
The only thing we need to do is to pass the function's name using .push method.

Example:
<script language="javascript">
_spBodyOnLoadFunctionNames.push("TestFunction");

function TestFunction() 
{ 
   alert("hello"); 
} 
</script> 

We can use above script in master page, aspx page, content editor web part, visual web part as per the need.

Contact Me or post a comment for any technical help related with SharePoint 2010.