Skip to content

Instantly share code, notes, and snippets.

@ps-team
ps-team / form-validate-scroll-to-error.js
Created October 27, 2017 08:04
Scroll to first failed validation input in a Contensis Form. ***required JQuery.scrollIntoView***
!(function($, d) {
'use strict';
var debug = false;
$(function() {
$('[id*=btnSubmitForm]').click(onSubmitClick);
});
function onSubmitClick(e) {
var formID = returnFormId($(this).attr('id'));
@ps-team
ps-team / scroll-into-parent-view.js
Created October 27, 2017 08:04
JQuery plugin to vertically scroll view into first first parent that has scrolling available (css overflow set to either "auto", "scroll" and content > height). Interface: jQuery.scrollTo(elem, speed); //scroll this to elem in view jQuery.scrollIntoView(speed); //scroll this to first scroll-able parent
!(function($, window, d) {
'use strict';
var debug = false;
var defaultSpeed = 500;
$.fn.scrollTo = function(elem, speed) {
var elemTop = $(elem).offset().top - $(this).offset().top;
var thisScrollTop = $(this).scrollTop();
var targetScrollTop = thisScrollTop + elemTop;
@ps-team
ps-team / OpenGraphData.cshtml
Created October 27, 2017 08:05
OpenGraph data output - Razor and metadata needed for displaying better Facebook and Twitter share images for each webpage. Just add to a base razor file.
var OpenGraphImage = "https://www.cumbria.police.uk/SiteElements/Images/Facebook-logo.png";
if(CurrentNode.ThumbnailUrl!="") {
OpenGraphImage = "https://www.cumbria.police.uk" + CurrentNode.ThumbnailUrl;
}
CurrentContext.Page.Head.Add("meta", new { property = "og:title", content = CurrentNode.Title });
CurrentContext.Page.Head.Add("meta", new { property = "og:description", content = CurrentNode.Data.Description });
CurrentContext.Page.Head.Add("meta", new { property = "og:image", content = OpenGraphImage });
CurrentContext.Page.Head.Add("meta", new { property = "og:url", content = CurrentNode.FullPath });
CurrentContext.Page.Head.Add("meta", new { property = "og:site_name", content = "Cumbria Constabulary" });
@ps-team
ps-team / viewobjectcontents.cshtml
Created October 27, 2017 08:05
Convert an object into json to view its contents
@{
var obj = something;
@AsJson(obj);
}
@functions{
string AsJson(object obj) {
return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
}
@ps-team
ps-team / DateTime.cshtml
Created October 27, 2017 08:06
DateTime formatting. For different formatting options please refer to the MDN docs: https://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
@using Contensis.Framework.Web
@{
// Variables
var dateTime = Properties.time;
var day = dateTime.ToString("d ").Replace(" ", "");
var dateTimeOne = dateTime.ToString("yyyy-MM-ddTHH:mm");
var dateTimeTwo = dateTime.ToString("dd") + DateSuffix(day) + dateTime.ToString(" MMMM yyyy");
// Format one
<div>@dateTimeOne</div>
@ps-team
ps-team / youTubePosterImage.cshtml
Created October 27, 2017 08:06
YouTube poster image RegEx. The following code strips the YouTube video ID from the url which is then used as a parameter to retrieve the video poster image. There are different sizes available e.g: http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg http://img.youtube.com…
@using System.Text.RegularExpressions;
@{
string image = String.Empty;
string youtubeid = string.Empty;
// Strip youtube id from the url so we can use it as a poster image
Regex regex = new Regex(@"^(?:https?\:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v\=))([\w-]{10,12})(?:$|\&|\?\#).*");
Match youtubeMatch = regex.Match("youtubeurl");
if (youtubeMatch.Success) {
@ps-team
ps-team / CheckIfHyperlink.cshtml
Created October 27, 2017 08:07
Check if the content type is a hyperlink or not. Use FullPath if it is else use Path instead. Pass the content node to the function. Content types value set to 0, 16.
@ps-team
ps-team / hidePlaceholder.vb
Created October 27, 2017 08:08
Hide placeholders if they are empty or have default content. Within the custom code tab add the relevant code. If you want to add a class when the placeholder is hidden, use the code below but also add the [idSelector] to your html along with the property runat="server"
'hide placeholder
If Control.IsEmptyOrDefaultContent("[right column]") then
Control.visible = false
End If
'add class if placeholder is hidden
If Control.IsEmptyOrDefaultContent("[right column]") then
Control.visible = false
[idSelector].attributes("class")= [idSelector].attributes("class") & " testing"
@ps-team
ps-team / splitcolumns.cshtml
Created October 27, 2017 08:08
Splits columns into rows within a foreach loop. In this example it will put 2 columns in each row. Change the number to suit your needs e.g ++columnCounter % 4
@{
// Counter
int columnCounter = 0;
<div class="row">
@foreach (ContentNode feature in features) {
<div class="columns">
content in here
</div>
@ps-team
ps-team / ConditionalClassNames.cshtml
Created October 27, 2017 08:08
Conditionally change the class on items in a foreach loop
@{
int counter=0;
}
@foreach (var item in Model)
{
counter++;
<div class="@(counter<=3 ? "classRed":"classBlue")">
<img src="@item.Blog.Image.img_path" alt="Not Found" />
//other markup also here