Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
	<div class="row">
		<div class="col-lg-6">
			<h1>Open Graph Video Tag Tester</h1>
			<h5>simulate og:videos in Apple Messages</h5>
			<div class="input-group">	<span class="input-group-btn">
					<button class="btn btn-secondary" type="button">Go!</button>
				</span>
				<input type="text" class="form-control" id="url" placeholder="Enter your url here:">
			</div>
			<div class="alert alert-danger" role="alert" id="badurl">	<strong>Please type the whole url </strong> please use http:// or https://</div>
			<div class="alert alert-danger" role="alert" id="jsonurl">	<strong>Failed getting  </strong> There seems to be a problem with the URL</div>

			<ul class="list-group">
				<li class="list-group-item"><strong>OG:url</strong>: <span id="ogURL"></span></li>
				<li class="list-group-item"><strong>OG:title</strong>: <span id="ogTitle"></span></li>
				<li class="list-group-item"><strong>og:site_name</strong>: <span id="ogSiteName"></span></li>
				<li class="list-group-item"><strong>og:image</strong>: <span id="ogImage"></span></li>
				<li class="list-group-item"><strong>og:description</strong>: <span id="ogDescription"></span></li>
				<li class="list-group-item"><strong>og:video</strong>: <span id="ogVideo"></span></li>
				<li class="list-group-item"><strong>og:video:type</strong>: <span id="ogVideoType"></span></li>
				<li class="list-group-item"><strong>og:video:width</strong>: <span id="ogVideoWidth"></span></li>
				<li class="list-group-item"><strong>og:video:height</strong>: <span id="ogVideoHeight"></span></li>
			</ul>
						<br><p><small><em>What is this?</em>: og tags are metadata tags for websites for other services (facebook, messages, slack) to scrape to provide more engaging previews. iOS and macOS messages unlike facebook/slack can display videos instead of images. Previously, there's been no utility to preview iOS messages so I made this. See <a href="https://developers.facebook.com/docs/opengraph/getting-started">opengraph getting started</a> for more details.</small></p>
		</div>
		<div class="col-lg-6">
			<section>
				<div class="from-me ">
					<p>Check out this rich media preview...</p>
				</div>
				<div class="clear"></div>
				<div class="from-them">
					<p>Let's see it!</p>
				</div>
				<div class="clear"></div>
				<div id="target"></div>
				<div class="clear"></div>
				<div class="from-them" id="congrats">
					<p>Hey, that's pretty cool!</p>
				</div>
				<div class="from-them" id="condolence">
					<p>Looks like you don't have a og:video tag :(</p>
				</div>
				<div class="clear"></div>
			</section>
		</div>
		<div class="row">
			<div class="col-lg-12">	<small>Uses <a href="https://allorigins.me" target="_blank">allorigins</a> + and thanks to <a href="https://codepen.io/samuelkraft/pen/Farhl" target="_blank">samuelkraft</a> for creating styles. <br> Try http://www.greggant.com see this script work.</small>
			</div>
		</div>
	</div>
</div>
<div class="hide"></div>

<!-- Handlebars -->
<script id="template" type="text/x-handlebars-template">
	<div class="video">
				<video width="100%" autoplay loop muted="" playsinline="">
			  <source src="{{videoURL}}" type="video/mp4" >
		</video>
					<p>{{description}}</p>
			<p class="url">{{domain}}</p>
	</div>
</script>
              
            
!

CSS

              
                
.container, .row {
	padding-top: 10px;
}
.hide {
	visibility: hidden !important;
}
.alert {
	display: none;
}
strong {
	display: inline-block;
	min-width: 131px;
}
span {
	font-family: Consolas, "Andale Mono WT", "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier, monospace;
}
.input-group {
	margin-bottom: 10px;
}

section {
	max-width: 450px;
	margin: 50px auto;
	font-family: "Helvetica Neue";
	font-size: 16px;
	font-weight: normal;
		p {
		margin-bottom: 0px;
	}
	div {
		max-width: 255px;
		word-wrap: break-word;
		margin-bottom: 12px;
    line-height: 18px;
    &:after {
      content: "";
      display: table;
      clear: both;
    }
	}
}
#congrats, #condolence {
	display: none;
}
#target {
float: right;
	display: none;
	.video {
		transition: opacity 0.5s; 
	}
}

$radius: 10px ;

//messages styling
@mixin message($color, $position, $opposite, $fontcolor) {
		position:relative;
		padding:10px 20px;
		background: $color;
		border-radius: $radius;
		color: $fontcolor;
		float: $opposite;
		&:before {
			content:"";
			position:absolute;
			z-index:-1;
			bottom:-2px;
			#{$opposite}:-7px;
			height:20px;
			border-#{$opposite}:20px solid $color;
			border-bottom-#{$position}-radius: 16px 14px;
			-webkit-transform:translate(0, -2px);
		}
		&:after {
			content:"";
			position:absolute;
			z-index:1;
			bottom:-2px;
			right:-56px;
			width:26px;
			height:20px;
			background:white;
			border-bottom-#{$position}-radius: 10px;
			-webkit-transform:translate(-30px, -2px);
		}		
}
.from-me {
	@include message( #0B93F6, left, right, white);
}
.from-them {
	@include message( #E5E5EA, right, left, black);
	//overwrites
	&:after {
		left: 4px;
	}
}
.video {
	@include message( #E5E5EA, left, right, black);
	//overwrites
	font-size: 12.5px;
	padding:0px;
	video {
		border-radius: 10px 10px 0px 0px;
	}
	p {
		padding-left: 15px;
		padding-right: 15px;
		padding-botom: 0;
		margin-bottom: 0;
	}
	p.url {
		font-size: 11.5px;
		color:rgba(157, 157, 159, 1.000);
		margin-bottom: 10px;
		font-weight: 400;
	}
}
.clear {clear: both}


              
            
!

JS

              
                var thisURL;
//ui interactions
$( "button" ).click(function() {
	urlAction();
});
$('#url').keyup(function(e){
    if(e.keyCode == 13){
       urlAction();
    }
});

//err catch URL
function urlAction() {
		thisURL = $('#url').val();
	if ( thisURL.indexOf('http://') !== -1 || thisURL.indexOf('https://') !== -1 ) {
		thisURL = thisURL.replace("https", "http");
		$(".alert").hide();
		getURL();
	} else {
		$("#badurl").show();
	}
}
//mustache
function templater (theVideoURL, theDescription, theDomain) {
  var theData = { videoURL: theVideoURL, description: theDescription, domain: theDomain };
  var theTemplateScript = $("#template").html();
	var theTemplate = Handlebars.compile (theTemplateScript);
	$("#target").html(theTemplate (theData));
}
function writeData (property, target){
	if (property ) {
		$(target).text(property);
	} else {
		$(target).text("error / does not exist");
	}
}
//opengraph data + meta data
var ogMetaData = {
	"#ogURL": 'meta[property="og:url"]',
	'#ogTitle': 'meta[property="og:title"]',
	'#ogSiteName': 'meta[property="og:site_name"]',
	'#ogImage' : 'meta[property="og:image"]',
	'#ogDescription':'meta[property="og:description"]',
	'#ogVideo' : 'meta[property="og:video"]',
	'#ogVideoType' : 'meta[property="og:video:type"]',
	'#ogVideoWidth' : 'meta[property="og:video:width"]' ,
	'#ogVideoHeight' : 'meta[property="og:video:height"]'
}
function getURL() {
		$.getJSON('https://allorigins.me/get?url=' + encodeURIComponent( thisURL) + '&callback=?', function(data){
    	$('.hide').html(data.contents);			
			Object.keys(ogMetaData).forEach(function(key) {
				writeData( $( ogMetaData[key] ).attr("content"),  key); //
			});
			$('.hide [rel=stylesheet]').remove();
			var doesExist = $('meta[property="og:video"]').attr("content");
			if (doesExist ) {
				templater( 
					$('meta[property="og:video"]').attr("content"), 
					$('meta[property="og:description"]').attr("content"), 
					$('meta[property="og:url"]').attr("content")
				)
				$("#condolence").hide();
				$("#target").fadeIn();
				 setTimeout(function(){$("#congrats").fadeIn(); },	2000);
			} else {
				$("#congrats").hide();
				$("#target").hide();
				setTimeout(function(){$("#condolence").fadeIn(); },  1000);
			}
	}).fail(function(d) {
    $("#jsonurl").show(); 
  })
}
              
            
!
999px

Console