Wednesday, 7 November 2012

Disable right click using javascript

<script type="text/javascript">

    var message = "";

    function clickIE() {
        if (document.all)
        { (message); return false; }
    }

    function clickNS(e) {
        if
(document.layers || (document.getElementById && !document.all)) {
            if (e.which == 2 || e.which == 3) { (message); return false; }
        }
    }

    if (document.layers)
    { document.captureEvents(Event.MOUSEDOWN); document.onmousedown = clickNS; }
    else
    { document.onmouseup = clickNS; document.oncontextmenu = clickIE; }
    document.oncontextmenu = new Function("return false")

</script>

Yahoo feed using to show the weather


1.Yahoo feed using to show the weather details
2.store the city in cookie
3.zipcode using to get the cityname

 Script
---------

<script type="text/javascript" src="/_layouts/Styles/VCSB/Js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" language="javascript">
function weather() {
        var t;
        var city = document.getElementById("<%= TxtCity.ClientID %>").value;
        if (city != null && city != "") {           
            var locationQuery = 'SELECT id FROM xml WHERE url="http://xoap.weather.com/search/search?where=' + city + ' " AND itemPath="search.loc"'
            var locationUrl = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(locationQuery) + '&format=json';
            $.getJSON(locationUrl + '&callback=?', function (data) {              
                if (data.query != null && data.query != "" && data.query.results != null && data.query.results != "") {                
                    var locationId = data.query.results.loc.id;                  
                    $('#weatherData .weather-location').append('Weather for ' + city + ' (' + locationId + ')');
                    var weatherUnit = 'f'; //c for Celcius, f for Fahrenheit     
                    var weatherQuery = 'SELECT * FROM rss WHERE url="http://xml.weather.yahoo.com/forecastrss/' + locationId + '_' + weatherUnit + '.xml"';
                    var weatherUrl = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(weatherQuery) + '&format=json';
                    $.getJSON(weatherUrl + '&callback=?', function (data) {
                      
                        var weatherForecasts = data.query.results.item.forecast;
                        if (weatherForecasts != null) {
                            var code = weatherForecasts[0].code;
                            $('input:textbox[id$=txtlocation]').val(city);
                            $('input:textbox[id$=txthigh]').val(weatherForecasts[0].high + '°F');
                            $('input:textbox[id$=txtlow]').val(weatherForecasts[0].low + '°F');
                            $('input:textbox[id$=txtfeelslike]').val(weatherForecasts[0].text);
                            //$('input:image[id$=imgicon]').attr('src','<TD><DIV title="' + weatherForecasts[0].text + '" /></TD>').find('DIV:last').css('background-position', '-' + (61 * code) + 'px 0px');
                            //                           $('divIcon').css({backgroundImage:'url(http://l.yimg.com/a/lib/ywc/img/wicons.png)',backgroundRepeat:'no-repeat',backgroundPosition:'+(61 * code)+'px 0px'});;
                            $('#divIcon').css({ backgroundImage: 'url(http://l.yimg.com/a/lib/ywc/img/wicons.png)', backgroundRepeat: 'no-repeat', backgroundPosition: '-1830px 0px', width: '61px', height: '45px' }); ;
                            var testloc = $('input:hiddenfield[id$=htnlocation]').val();
                            $('input:textbox[id$=txtlocation]').val(testloc);
                            document.cookie = "";
                            var name = "test";
                            var date = new Date();
                            date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
                            var expires = "; expires=" + date.toGMTString();
                            document.cookie = name + "=" + $('input:textbox[id$=txtlocation]').val() + expires + "; path=/";
                            //document.cookie = $('input:textbox[id$=txtlocation]').val();
                        }
                        else {
                            $('input:textbox[id$=txtlocation]').val('City not available');
                            $('input:textbox[id$=txthigh]').val('N/A');
                            $('input:textbox[id$=txtlow]').val('N/A');
                            $('input:textbox[id$=txtfeelslike]').val('N/A');
                        }
                    });
                }
                else {
                    $('input:textbox[id$=txtlocation]').val('City not available');
                    $('input:textbox[id$=txthigh]').val('N/A');
                    $('input:textbox[id$=txtlow]').val('N/A');
                    $('input:textbox[id$=txtfeelslike]').val('N/A');
                }
            });
        }
        else {
            var tt,city1,city3 = "";
            if (document.cookie.length != 104 && document.cookie.length != 67 && document.cookie.length != 111) {
                var nameEQ = "test" + "=";
                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)
                        tt = c.substring(nameEQ.length, c.length);
                }
                var city2 = tt.split(' ');
               
                if (city2.length > 1) {
                    for (var i = 1; i < city2.length; i++) {
                        city3 += city2[0] + city2[i];
                    }
                    city1 = city3;
                }
                else {
                    city1 = tt;
                }
            }
            else {
                city1 = "Deland,FL";
            }
          
            var locationQuery = 'SELECT id FROM xml WHERE url="http://xoap.weather.com/search/search?where=' + city1 + ' " AND itemPath="search.loc"'
            var locationUrl = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(locationQuery) + '&format=json';
           
            $.getJSON(locationUrl + '&callback=?', function (data) {
               
                if (data.query != null && data.query != "" && data.query.results != null && data.query.results != "") {
                 
                    var locationId = data.query.results.loc.id;
                    $('#weatherData .weather-location').append('Weather for ' + city1 + ' (' + locationId + ')');
                    var weatherUnit = 'f'; //c for Celcius, f for Fahrenheit     
                    var weatherQuery = 'SELECT * FROM rss WHERE url="http://xml.weather.yahoo.com/forecastrss/' + locationId + '_' + weatherUnit + '.xml"';
                    var weatherUrl = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(weatherQuery) + '&format=json';
                    $.getJSON(weatherUrl + '&callback=?', function (data) {
                        var weatherForecasts = data.query.results.item.forecast;
                        if (weatherForecasts != null) {
                            var code = weatherForecasts[0].code;
                            $('input:textbox[id$=txtlocation]').val(tt);
                            $('input:textbox[id$=txthigh]').val(weatherForecasts[0].high + '°F');
                            $('input:textbox[id$=txtlow]').val(weatherForecasts[0].low + '°F');
                            $('input:textbox[id$=txtfeelslike]').val(weatherForecasts[0].text);
                            //$('input:image[id$=imgicon]').attr('src','<TD><DIV title="' + weatherForecasts[0].text + '" /></TD>').find('DIV:last').css('background-position', '-' + (61 * code) + 'px 0px');
                            //                           $('divIcon').css({backgroundImage:'url(http://l.yimg.com/a/lib/ywc/img/wicons.png)',backgroundRepeat:'no-repeat',backgroundPosition:'+(61 * code)+'px 0px'});;
                            $('#divIcon').css({ backgroundImage: 'url(http://l.yimg.com/a/lib/ywc/img/wicons.png)', backgroundRepeat: 'no-repeat', backgroundPosition: '-1830px 0px', width: '61px', height: '45px' }); ;
                        }
                        else {
                          
                            $('input:textbox[id$=txtlocation]').val('City not available');
                            $('input:textbox[id$=txthigh]').val('N/A');
                            $('input:textbox[id$=txtlow]').val('N/A');
                            $('input:textbox[id$=txtfeelslike]').val('N/A');
                        }
                    });
                }
                else {
                  
                    $('input:textbox[id$=txtlocation]').val('City not available');
                    $('input:textbox[id$=txthigh]').val('N/A');
                    $('input:textbox[id$=txtlow]').val('N/A');
                    $('input:textbox[id$=txtfeelslike]').val('N/A');
                }
            });
        }
    }
    window.onload = weather;
</script>

  ascx
------------
<style type="text/css">
    #weatherData TD
    {
        text-align: center;
        padding-left: 15px;
        padding-right: 15px;
    }
    #weatherData CAPTION
    {
        font-style: italic;
        font-weight: bold;
    }
    .weather-icon DIV
    {
        background-image: url(http://l.yimg.com/a/lib/ywc/img/wicons.png);
      
        width: 61px;
        height: 34px;
    }  
    .td1
{
font-size:9px;
font-family:verdana,arial,helvetica,sans-serif;
}
</style>
<div id="weatherData">
    <asp:Panel ID="pnlWeather1" DefaultButton="ImgBtnGo" runat="server">
        <div class="menu_bg_sd">
            <div class="menu_left_sd">
            </div>
            <div class="menu_right_sd">
            </div>
            <h4>
                Weather & Local Info</h4>
        </div>
        <div class="menu_bg_sd_ind">
            <div class="menu_left_sd_ind">
            </div>
            <div class="menu_right_sd_ind">
            </div>
            <div class="box_inner_m2">
                <table width="100%" border="0" cellspacing="2" cellpadding="1" >
                    <tr>
                        <td align="left" valign="middle" style="color: Red; font-size: 14px; height: 25px;
                            font-weight: bold;" colspan="2">
                            <asp:TextBox ID="txtlocation" BackColor="#EEEEEE" Font-Bold="true" Height="25px" Font-Size="14px" ForeColor="#FF6600" BorderStyle="None" ReadOnly="true" runat="server"></asp:TextBox><br />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="height:50px;">
                            <div id="divIcon" >
                            </div>
                        </td>
                       
                    </tr>
                    <tr>        
                         
                    <td align="right" valign="middle" style="font-size:9px;font-family:verdana,arial,helvetica,sans-serif;">Maximum:
                        </td>
                   <td  align="left" valign="middle">
                                <asp:TextBox ID="txthigh" BackColor="#EEEEEE" BorderStyle="None" Font-Size="9px" ReadOnly="true" Width="50px" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                     <tr>
                     <td align="right" valign="middle" style="font-size:9px;font-family:verdana,arial,helvetica,sans-serif;">Minimum:
                        </td>
                   <td  align="left" valign="middle">
                            <asp:TextBox ID="txtlow"  BackColor="#EEEEEE" BorderStyle="None" Font-Size="9px" ReadOnly="true" Width="50px"  runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td valign="middle" style="font-size:9px;font-family:verdana,arial,helvetica,sans-serif;" >
                            Feels Like:
                        </td>
                        <td align="left">
                            <asp:TextBox ID="txtfeelslike" Width="112px" Font-Size="9px" BorderStyle="None" BackColor="#EEEEEE"  ReadOnly="true"  runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                   
                    </tr>
                    <tr>
                        <td colspan="2" align="center" valign="middle" style="padding-top:10px;">
                            <asp:TextBox ID="TxtCity" ValidationGroup="weather1" MaxLength="50" Width="110px"
                                Height="15px" runat="server"></asp:TextBox>
                            <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" TargetControlID="TxtCity"
                                WatermarkText="City or Zipcode" WatermarkCssClass="watercolor" runat="server">
                            </cc1:TextBoxWatermarkExtender>
                            <asp:ImageButton ID="ImgBtnGo" ToolTip="Go" runat="server" CausesValidation="false"
                                ValidationGroup="weather1" OnClientClick="weather();" ImageAlign="Top"
                                ImageUrl="/_layouts/Images/VCSB/weather_go.png" Width="31" Height="21" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" id="imgicons">
                            &nbsp;
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="menu_bg_sd_bot">
            <div class="menu_left_sd_bot">
            </div>
            <div class="menu_right_sd_bot">
            </div>
        </div>
    </asp:Panel>
   
  
</div>
<asp:HiddenField ID="htnlocation" runat="server" />

  ascx.cs
------------

protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var tt = htnlocation.Value;
                if (TxtCity.Text != "" && TxtCity.Text != null && TxtCity.Text != "City not available")
                {
                    string rssUri = "http://xoap.weather.com/search/search?where=" + Convert.ToString(TxtCity.Text);
                    //lnkbtnReadMore.PostBackUrl = rssUri;
                    var doc = System.Xml.Linq.XDocument.Load(rssUri);
                    if (doc != null)
                    {
                        string d = doc.LastNode.ToString();
                        if (d.Contains("</loc>"))
                        {
                            string str = d.Split('>').GetValue(2).ToString().Split('(').GetValue(0).ToString();
                            if (str.Contains("<"))
                            {
                                var ttt = str.Split('<').GetValue(0).ToString();
                                var ss = ttt.Split(',');
                                var cc = ss[1].Trim(' ');
                                htnlocation.Value = ss[0] + "," + cc;
                            }
                            else
                            {
                                var ss1 = str.Split(',');
                                var cc1 = ss1[1].Trim(' ');
                                htnlocation.Value = ss1[0] + "," + cc1;
                            }
                        }
                    }
                }
                if (txtlocation.Text == "")
                {
                    txtlocation.Text = "City not available";
                    txthigh.Text = "N/A";
                    txtlow.Text = "N/A";
                    txtfeelslike.Text = "N/A";
                }
            }
            catch (Exception ex)
            {
                txtlocation.Text = "City not available";
                txthigh.Text = "N/A";
                txtlow.Text = "N/A";
                txtfeelslike.Text = "N/A";
            }
        }
 

SharePoint online - Get List-item attachments and Display to div

Step 1 : Create a List ex: TestList and attach few images Step 2 : Copy and Pastet the below coding in App.js var  Items =  null ; ...