Wednesday, July 22, 2015

JavaScript and Cookie


JavaScript and Cookie
First we will see “how we can read cookie with JavaScript code?”
For that I have created one JavaScript function that will take one argument (name of cookie’s variable)

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ')
{
 c = c.substring(1,c.length);
}
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
    return null;
}
Now in below code I will try to show how we can create cookies using JavaScript

function cookieCheck(){
        var interval;
            if(readCookie("userlogTime") == null)
                {
                    var cDateTime = new Date();
                     var timeSet = cDateTime.getHours();
                     document.cookie ="userlogTime="+timeSet;
                 }
         }

The above code show how we can create cookie using javascript

Thursday, July 2, 2015

Carousel Jquery

 <html>
<head>
    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
    <script type="text/javascript">

    //Script for tabs
        $(document).ready(function () {
            $("#tabClick2-1 div").click(function () {
                $("#cont-2-2").css("display", "block");
                $("#cont-2-1").css("display", "none");
                $("#tabClick2-2").css("display", "block");
                $("#tabClick2-1").css("display", "none");
            });
            $("#tabClick2-2 div").click(function () {
                $("#cont-2-1").css("display", "block");
                $("#cont-2-2").css("display", "none");
                $("#tabClick2-2").css("display", "none");
                $("#tabClick2-1").css("display", "block");
            });
        });

        // script for Carousel
        var x;
        var slidby = 892;
        var x1;
        $(document).ready(function () {
            x = $("#carousel ul li").length;
            x1 = $("#carousel1 ul li").length;
            var y = x * slidby;
            var y1 = x1 * slidby;
            $("#carousel ul").css("width", y + "px");
            $("#carousel1 ul").css("width", y1 + "px");
            x = x - 1;
            x1 = x1 - 1;
            var leftEnd = x * slidby;
            var leftEnd1 = x1 * slidby;
            leftEnd = "-" + leftEnd + "px";
            leftEnd1 = "-" + leftEnd1 + "px";
            $("#carousel1 ul").css("margin-left", leftEnd1);
            $("#carousel ul").css("margin-left", leftEnd);
            $("#prv").click(function () {
                var carouselul = "#carousel ul";
                var leftPAdding1 = $(carouselul).css("margin-left");
                if (leftPAdding1 != "0px") {
                    privious(carouselul);
                }
            });
            $("#prv1").click(function () {
                var carouselul = "#carousel1 ul";
                var leftPAdding1 = $(carouselul).css("margin-left");
                if (leftPAdding1 != "0px") {
                    privious(carouselul);
                }
            });
            function privious(c) {
                var leftPAdding1 = $(c).css("margin-left");
                var leftPAdding = Number(leftPAdding1.replace(/px$/, ''));
                var margin = leftPAdding + slidby;
                if (leftPAdding >= 0) {
                    return;
                }
                if (leftPAdding == ("-" + slidby + "px")) {
                    leftPAdding = "0px";
                } else if (leftPAdding == "0px") {

                } else {
                    leftPAdding = margin + "px";
                }
                var t = setInterval(function () {
                    $(c).animate({ "margin-left": leftPAdding }, 1000, function () {
                    });
                });
            }
            $("#nxt").click(function () {
                var carouselul = "#carousel ul";
                var leftPAdding1 = $(carouselul).css("margin-left");

                if (leftPAdding1 != leftEnd) {
                    nextSlid(carouselul);
                }
            });
            $("#nxt1").click(function () {
                var carouselul = "#carousel1 ul";
                var leftPAdding1 = $(carouselul).css("margin-left");
                if (leftPAdding1 != leftEnd) {
                    nextSlid(carouselul);
                }
            });
            function nextSlid(c) {
                var leftPAdding1 = $(c).css("margin-left");
                var leftPAdding = Number(leftPAdding1.replace(/px$/, ''));
                var widthUL = $(c).css("width");
                widthUL = Number(widthUL.replace(/px$/, ''));
                widthUL = widthUL - slidby;
                if (widthUL + leftPAdding == 0) {
                    return;
                }
                var margin = leftPAdding - slidby;
                if (leftPAdding == "0px") {
                    leftPAdding = margin + "px";
                } else {
                    leftPAdding = margin + "px";
                }
                var t = setInterval(function () {
                    $(c).animate({ "margin-left": leftPAdding }, 1000, function () {
                    });
                });
            }
        });
    </script>
    <style type="text/css">
        #tabClick2-1
        {
            background-image: url(references-tab.png);
            width: 100%;
            background-repeat: no-repeat;
            height: 53px;
        }
        #tabClick2-1 div
        {
            margin-left: 185px;
            width: 144px;
            height: 36px;
            cursor: pointer;
            border: 1px solid red;
        }
        #tabClick2-2
        {
            background-image: url(bckimg.png);
            width: 100%;
            background-repeat: no-repeat;
            height: 53px;
        }
        #tabClick2-2 div
        {
            width: 144px;
            height: 36px;
            margin-left: 29px;
            cursor: pointer;
        }
        /* css for carousel Start */
        .mainUl
        {
            padding: 0px;
            padding-left: 20px;
            margin: 0px;
        }
        .mainUl LI
        {
            float: left;
        }
        .tabcontent
        {
            border: 0px solid white;
        }
        .carousel
        {
            width: 892px;
            height: 200px;
            overflow: hidden;
        }
        .carousel Ul
        {
            padding: 0px;
            margin: 0px;
        }
        .carousel Ul li
        {
            height: 100px;
            text-align: center;
            float:left;
            list-style-type: none;
            list-style-image: none;
        }
        .carousel Ul li div
        {
            width: 223px;
            text-align: center;
        }
       
        .carousel Ul li div img
        {
            width: 208px;
            height: 139px;
        }
        /* css for carousel End */
    </style>
</head>
<body>
    <div id="tabClick2-1">
        <div>
            &nbsp;
        </div>
    </div>
    <div id="tabClick2-2" style="display: none">
        <div>
            &nbsp;
        </div>
    </div>
    <!-- Content for first tab data--->
    <div class="tabcontent paddingAll" id="cont-2-1">
        <ul class="mainUL">
            <li>
                <div class="prv" id="prv">
                    <img src="/Images1/Back.png" alt="" />
                    &#160;</div>
            </li>
            <li>
                <div style="width: 870px; overflow: hidden">
                    <div class="carousel" id="carousel">
                        <ul>
                            <li>
                                <div style="float: left">
                                    <img width="208" height="139" src="/Images1/ref222.png" alt="" />
                                </div>
                                <div style="float: left">
                                    <img width="208" height="139" src="/Images1/ref222.png" alt="" />
                                </div>
                            </li>
                        </ul>
                        &#160;</div>
                    &#160;</div>
            </li>
            <li>
                <div class="nxt" id="nxt">
                    <img src="/Images1/Next.png" alt="" /></div>
            </li>
        </ul>
        <!-- CAROSAL CONTENTS END---->
    </div>
    <!-- Content for 2nd tab data--->
    <div class="tabcontent paddingAll" id="cont-2-2" style="display: none">
        <ul class="mainUL">
            <li>
                <div class="prv" id="prv1">
                    <img src="/Images1/Back.png" alt="" />
                    &#160;</div>
            </li>
            <li>
                <div style="width: 870px; overflow: hidden">
                    <div class="carousel" id="carousel1">
                        <ul>
                            <li>
                                <div style="float: left">
                                    1 IMAGE
                                </div>
                                <div style="float: left">
                                    2 IMAGE
                                </div>
                                <div style="float: left">
                                    3 IMAGE
                                </div>
                                <div style="float: left">
                                    4 IMAGE
                                </div>
                            </li>
                            <li>
                                <div style="float: left">
                                    5 IMAGE
                                </div>
                            </li>
                        </ul>
                        &#160;</div>
                    &#160;</div>
            </li>
            <li>
                <div class="nxt" id="nxt1">
                    <img src="/Images1/Next.png" alt="" />&#160;&#160;</div>
            </li>
        </ul>
    </div>
</body>
</html>

Thursday, February 5, 2015

JSON in sharepoint 2010


<script type="text/javascript" src="/sites/Training/SiteAssets/js/jquery-1.3.2.min.js"></script>

<script type="text/javascript">
function getLs(){
var currentdate = new Date();
var dateT=currentdate.getMinutes() +"::"+currentdate.getSeconds();
$("#IDInContentEditorWP").append(dateT);
var myurl="http://server/sites/training/_vti_bin/listdata.svc/Curriculum";
$.ajax({
    url : myurl,
    headers: { "Accept": "application/json; odata=verbose"},
    type: 'GET',
    dataType: 'json',
        success : function(data){
             for (i=0; i<data.d.results.length; i++ ){
                 dateT=currentdate.getMinutes() +"::"+currentdate.getSeconds();
                 $("#IDInContentEditorWP").append("<table><tr><td>"+data.d.results[i].Title+"</td></tr></table>");
$("#IDInContentEditorWP").append(dateT);
           }
    },
    error : function(xhr, status){
        console.log(status);
    }
});
}


//  additme is addining item to a sharepoint list
function additme(){
var myurl="http://server/sites/training/_vti_bin/listdata.svc/Curriculum";
var contact = {
CurriculumName: "Dell"
};
var body = JSON.stringify(contact);
$.ajax({
          url : myurl,
          contentType: 'application/json',
          type: 'POST',
         dataType: 'json',
         data: body,
         processData: false,
        success : function(data){
             alert("save");
    },
    error : function(xhr, status){
        console.log(status);
    }
});
}

You can also put filter
var myurl="http://server/sites/training/_vti_bin/listdata.svc/Curriculum?$filter=fieldName eq 'Operations' 

Thursday, December 26, 2013

Rest Solution in Share Point 2010

Fetch the record from sharepoint list using jQuery with ajax call..............


Lets take an example :-
List name :http://site/web/_vti_bin/ListData.svc/UserInformationList

from this list i want to fetch data of all users.
$.ajax({
        url: "http://mypc/BD/_vti_bin/ListData.svc/UserInformationList",
        dataType: "json",
        success: function(data) {

$.each( data.d.results, function( key, value ) {
  alert( key + ": " + value.Account );
});          
         
        },
        error: function(data) {
            alert("error");
           
        }          
    });

Tuesday, October 15, 2013

ItemDataBound event for repeater control

Here i am giving one simple example for ItemDataBound event. In this block of code i am finding one label and assigning a value.

/* Code block started */
  Dim listOfparticipant As New Generic.List(Of registerParticipant)
  Dim participant As New registerParticipant 
  listOfparticipant.Add(participant)

  rptVerifyParticipant.DataSource = listOfparticipant
  rptVerifyParticipant.DataBind()

  Protected Sub rptVerifyParticipant_ItemDataBound(ByVal sender As Object, ByVal e As    System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptVerifyParticipant.ItemDataBound

 If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

 Dim _tbl As registerParticipant = CType(e.Item.DataItem, registerParticipant)
            Dim VerifyNric As Label = CType(e.Item.FindControl("VerifyNric"), Label)
            VerifyNric.Text = Microsoft.SharePoint.Utilities.SPHttpUtility.HtmlEncode(Convert.ToString(_tbl.NRIC))

End If
 End Sub

/* Code block End */

In this block i have created on list of "registerParticipan" class, and after that adding one item to this list , after that i am assigning to repeater data source.

Now after that will write itemDatabound event .
In itemdatabound event we are typcasting item.dataitem to registerParticipant class .

Thanks,





Tuesday, September 3, 2013

Find checked radio button throug jQuery

$("#_chkbox").change(function () {
            var items = $(".childCheckBox").find("input");
            if ($('#_chkbox').is(':checked') == false) {
                for (i = 0; i < items.length; i++) {
                    if (items[i].type == "checkbox") {
                        items[i].checked = false;
                    }
                }
            }
            if ($('#_chkbox').is(':checked') == true) {
                for (i = 0; i < items.length; i++) {
                    if (items[i].type == "checkbox") {
                        items[i].checked = true;
                    }
                }
            }
        });

How to get search content sources in a sharepoint site

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim farmServices As SPServiceCollection = SPFarm.Local.Services
        For Each s As SPService In farmServices
            Dim x As SPServiceApplicationCollection = s.Applications
            For Each f As SPServiceApplication In x
                If f.TypeName = "Search Service Application" Then
                    If f.DisplayName = "FAST Content SSA 14012013" Then
                        Dim ssa As SearchServiceApplication = CType(f, SearchServiceApplication)
                        Dim consources As List(Of String) = ssa.GetContentSourceNames()
                        For i As Integer = 0 To consources.Count - 1
                            Label1.Text &= consources(i) + "</br>"
                        Next
                    End If
                End If

            Next

        Next
    End Sub