Wednesday, May 3, 2017

Using CSS to cause an image to "expand" when hovered over

I just stumbled across some interesting code written by one of my co-workers that utilizes CSS to cause an image to expand slightly when the user of the web page hovers over it.  As you might guess, this would be perfect for highlighting clickable components such as buttons and the like.  This idea was so clever that I thought I'd share:


<style>
        .imgButton {
          display: inline-block;
          vertical-align: middle;
          -webkit-transform: perspective(1px) translateZ(0);
          transform: perspective(1px) translateZ(0);
          box-shadow: 0 0 1px transparent;
          -webkit-transition-duration: 0.3s;
          transition-duration: 0.3s;
          -webkit-transition-property: transform;
          transition-property: transform;
        }
        .imgButton:hover, .imgButton:active, .imgButton:focus {
          -webkit-transform: scale(1.1);
          transform: scale(1.1);
        }

</style>

...

<img src="pathToImageFile" class="imgButton" />

Tuesday, January 17, 2017

Making sure the Time Component is accounted for in a DateTime CAML Query

The key to making certain that the time component is leveraged when you're performing a datetime comparison in a CAML Query is to include the IncludeTimeValue attribute in your query with a value set to "TRUE".

In the following example, I leveraged a javascript CSOM CAML query to only return items in my image library called "Banners" in which the current datetime falls within the boundaries specified in my custom StartDate and EndDate datetime fields of the image library:

<View>
 <Query>
  <Where>
   <And>
    <Leq>
     <FieldRef Name=\'StartDate\'/><Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'><Today /></Value>
    </Leq>
    <Geq>
     <FieldRef Name=\'EndDate\'/><Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'><Today /></Value>
    </Geq>
   </And>
  </Where>
 </Query>
</View>

Here is a more complete version of the code that I used:

function execRequest_Banner() {
     var ctx_Banner = SP.ClientContext.get_current();
     var camlQuery_Banner = new SP.CamlQuery();
     // Filter the image to display based on the following criteria:
     // 1) Only display images in which today's date falls within the Start and End Date range
     // specified

     camlQuery_Banner.set_viewXml('<View><Query><Where><And><Leq><FieldRef Name=\'StartDate\'/>
<Value Type=\'DateTime\'><Today /></Value></Leq><Geq><FieldRef Name=\'EndDate\'/>
<Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'><Today /></Value></Geq></And>
</Where></Query></View>');
     this.items_Banner = 
     ctx_Banner.get_web().get_lists().getByTitle('Banners').getItems(camlQuery_Banner);
     ctx_Banner.load(items_Banner);
     ctx_Banner.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded_Banner),
     Function.createDelegate(this, this.onQueryFailed_Banner));
}

Friday, December 30, 2016

Hide components located on the SharePoint Online master page, oslo.master

In order to hide various components located on the oslo.master master page of SharePoint Online site, a brutally simple solution is to insert a Script Editor web part on the web page and add one or more of the following CSS elements to it:

<style>

     .ms-srch-sb {display:none;}

     .ms-core-pageTitle {display:none;}

     #pageContentTitle { display:none;}

     #titlerow { display:none;}

</style>

Just a quick warning, placing all of these CSS elements on the web page is going to turn the web page into a blank page (that is, if you don't have any content on it) so feel free to remove any of those CSS elements listed above if you want that component to be displayed.

Here is a key that explain which element removes which control:

.ms-srch-sb {display:none;} - removes just the Search control
.ms-core-pageTitle {display:none;} - removes just the Page Title
#pageContentTitle { display:none;} - removes just the Site Title
#titlerow { display:none;} - removes the Site Logo, Site Title, and Search Control

Friday, November 4, 2016

RequiredExpressionValidator expression to limit the number of characters entered in a textbox

For the ASP.NET project that I'm currently working on, I wanted to limit the number of characters that could be entered into a specific textbox control to a maximum of 25 characters (NOTE: since this was a required field so I also wanted them to at least enter 1 character); however, in this particular instance, I wanted to allow the user to be able to enter any kind of special character.  To provide this capability, I used the following value for my ValidationExpression:

^.{1,25}$

Now, if I did want to limit the type of characters entered to be only alpha-numeric and empty spaces, I used the following:

^[a-zA-Z0-9 ]{1,25}$


Tuesday, June 28, 2016

Obtain a list of SharePoint subsites using Javascript CSOM

Here is some code that you can utilize for obtaining a list of SharePoint subsites that the given user has access to:

<div id="selectsubwebs"></div>

<script type="text/javascript">
   var subsites = null;
   var web = null;
   var context = null;
   var subweb = null;
   var renderedHTML = "";
   var scriptbase = "https://rootSiteUrl/_layouts/15/";

   $.getScript(scriptbase + "SP.Runtime.js", function() {
      $.getScript(scriptbase + "SP.js", function() {
         $.getScript(scriptbase + "SP.RequestExecutor.js", getSubWebs);
      });
   });

   function getSubWebs(){
      context = SP.ClientContext.get_current();
      web = context.get_web();
      context.load(web);
      context.executeQueryAsync(onGetWebSuccess, onGetWebFail);
   }

   function onGetWebSuccess(sender, args) {
      //subsites = web.get_webs();  //Complete list of subsites
      subsites = web.getSubwebsForCurrentUser(null);
      context.load(webCollection);
      context.executeQueryAsync(onGetSubwebsSuccess, onGetSubwebsFail);
   }

   function onGetSubwebsSuccess(sender, args) {
      renderedHTML = renderedHTML + "<table id='table_id' class='display'><thead><tr><th>Team Site Title</th></tr></thead><tbody>";
      var webEnumerator = subsites.getEnumerator();
      while (webEnumerator.moveNext()){
         subweb = webEnumerator.get_current();
         renderedHTML = renderedHTML + "<tr><td><a href='" + subweb.get_url() + "' target='_blank'>" + subweb.get_title() + "</a></td></tr>";
      }
      renderedHTML = renderedHTML + "</tbody></table>";

      document.getElementById("selectsubwebs").innerHTML = renderedHTML;

   }
   function onGetSubwebsFail(sender, args){
      alert("Request to retrieve subwebs failed. Error: " + args.get_message())
   }

   function onGetWebFail(sender, args){
      alert("Request to retrieve subwebs failed. Error: " + args.get_message())
   }
</script>

Friday, August 14, 2015

Remove dashed line that appears around elements of an HTML image map

If you discover that you're being plagued by a dashed line that appears around the <area>  elements of your HTML image map whenever a user clicks on a given element of the image map, here is some jQuery code that you can use to remove those dashed lines...

$(document).ready(function() {

     $("area").focus(function() { $(this).blur(); });

}

To help explain matters, the dashed line is simply an indicator that the user placed the focus on the given element when he/she clicked on it.  The above code works by using the blur method to remove the focus from the selected item after it's been has been clicked.

Monday, June 15, 2015

Reading a value from the Web.config file of an ASP .NET Web Application using Javascript

To read a value from the web.config file of an ASP .NET Web Application using javascript, you can do the following:

  1. In your web.config file, add a new <appSettings> with the key and value that you wish for the javascript code to obtain.  In this example, here is the new <appSettings> node, I'm going to reference:

    <appSettings>
         <add key="Environment" value="TEST" />
    </appSettings>


  2. In the HTML code of my default.aspx page, I'm going to add the following javascript function that's going to reference the new <appSettings> node that I just added:

    function getEnvironment() { 
         var environment = '<%= ConfigurationManager.AppSettings["Environment"].ToString() %>';
         alert(environment);
    }
All you have to do is call this function at an appropriate location in your code and it will obtain the value of the respective <appSettings> node.  Naturally, you'll want to swap out the alert call with some valid code, but the idea of this example is to get you rolling.