What We Are Trying to Achieve

As a side project I am in the middle of porting a website from Angular.js to Vue.js. Why you may ask, well it is not a complicated site and even though I am proficient with AngularJS, I saw the jump to Angular too heavy and I don’t need all the functionality or complexity that introduces. I have worked with Vue.js before and find it a superb framework that allows you to get a site running quickly with just the basics and only include the parts of the framework you need. It is easy enough to come back and put more functionality in such as routing, state management later on.

So as part of this work I have large chunks of TypeScript that interact with jQuery UI that I need to bring over. I know I could write or find on GitHub some of this functionality, but this is supposed to be a quick project and I haven’t got the time. I just need to get Vue to interact with jQuery UI written in TypeScript. Should be easy…and it is.

Create the Component

Firstly a new TypeScript file is needed to place the jQuery UI functionality into. I am going to use the DatePicker in this example, but the process is pretty much the same with other widgets as well.

For TypeScript to understand what Vue is, you need to import Vue, then you extend the Vue instance adding the template and mounted functions. The mounted function is a lifecycle hook you can use for when the Vue instance is being instantiated.It allows you to start to interact with the DOM or Virtual DOM in the case of Vue.

In the above example you simply use this.$el to get jQuery to find the element as you would any other jQuery UI code. Looking at the DatePicker API, there is a onSelect function that gets called when the date is changed. To get Vue to use this date object, we need to emit it using self.$emit and a kebab case property that matches a property in the HTML.

In the HTML (actually Razor syntax in this case) we add the element like this:-

Where the same kebab cased property is used to call a function called calculateJulianDate. I have to use two @ symbols here other wise Razor will think it is a segment of Razor code.

Import Into Your Vue Page

So now we come to our page code. Generally I set out my Vue code so all I need to call is run the WebPack CLI command and it will pick up my app.js file (generated from app.ts).

This app.js file simply lists out all the JavaScript files I want to compile into the one script. So I have for example:-

Which includes both page and datepicker scripts.

So at the top of page.ts I again need to do an import, this time for DatePicker which works because we export it from the datePicker.ts file earlier.

We also need to extend the Vue instance similar to what we did earlier and register the component like this:-

Now we also need to add the actual function we specified earlier as a kebab case property, in this case I am calculating the Julian Date from the date object passed in so we use the Vue methods properties like this:-

I have left out the actual function code as it doesn’t add anything to this example, but the take home is it sets a data property which is then bound to the HTML like this:-

Happy coding

Reading View

Have you ever browsed websites using Microsoft Edge and seen the little reading book in the address bar? That is the reading view option and is an absolute brilliant tool as when it is enabled, it gets rid of all the junk on the page, changes the text size and colours and makes a reading experience so much better. Some sites seem to have it and some don’t, but why? What is the magic juice that is needed to get this enabled for your web sites?

A tale of two Edges

Yes there are two edges we need to worry about here. Firstly there is the out of the box Microsoft Edge that comes with Windows 10 and renders using EdgeHTML. Secondly there is the re-invented Edge that uses Chromium under the hood. Edge powered by Chromium is still in development, but you can get your hands on it by signing up to the Insiders Channels.

Layout of your page

Have a basic layout similar to the following.

Reading View will extract various bits of information out from meta tags and specific classes such as the byline-name, dateline and displaydate and display them prominently on the page:-


reading-view-1

But this does not always work for the default Edge as even Microsoft’s page on Reading View does not work on the default Edge, but does on Chromium Edge.

Here is my test page address bar in both default Edge and Chromium Edge. I should point out that reading view does not work on local html files, they have to be hosted on a server.

Default Edge

default-edge-1

Chromium Edge

chromium-edge-1


But why?

Well I cannot be entirely sure, but my experiments show that if you call your file index.html, and browse to it then in the default Edge it will not have a reading view, but in Chromium Edge it will. However even in Chromium Edge, not all the meta data is extracted as this image shows. But this is all experimental at the moment, so this will maybe change in the future.I should also point out that you need enough content for the parser to deem it necessary to have a reading view. In the above page I have three paragraphs, if it was just the one then reading view is not available.

reading-view-2

Enabling it in Chromium Edge

It is already enabled in default Edge, but currently in Chromium Edge you need to set a flag by going to edge://flags/ in the address bar and searching for ‘Microsoft Edge Reading View’ which as of version 78.0.276.2 is still experimental.

reading-view


Happy coding.

HTTP Endpoint Monitoring for both Windows and Android
WebUp App