Skip to content

Instantly share code, notes, and snippets.

View danielcrisp's full-sized avatar

Daniel Crisp danielcrisp

View GitHub Profile
@danielcrisp
danielcrisp / touch-tooltip-fix.js
Created August 22, 2014 12:50 — forked from marco-martins/touch-tooltip-fix.js
Updated to work with Highcharts v4
Highcharts.Chart.prototype.callbacks.push(function(chart) {
var hasTouch = hasTouch = document.documentElement.ontouchstart !== undefined,
mouseTracker = chart.pointer,
container = chart.container,
mouseMove;
mouseMove = function (e) {
// let the system handle multitouch operations like two finger scroll
// and pinching
if (e && e.touches && e.touches.length > 0) {
@danielcrisp
danielcrisp / build.js
Created September 4, 2015 10:15
iScroll.js - ZOOM and PROBE custom build
#!/usr/bin/env node
var pkg = require('./package.json');
var fs = require('fs');
var hint = require("jshint").JSHINT;
var uglify = require('uglify-js');
var banner = '/*! iScroll v' + pkg.version + ' ~ (c) 2008-' + (new Date().getFullYear()) + ' Matteo Spinelli ~ http://cubiq.org/license */\n';
var releases = {
@danielcrisp
danielcrisp / auth.service.ts
Created July 25, 2017 13:23
AuthService - Async HTTP Interceptors with Angular 4
import { Injectable } from '@angular/core';
import { UserManager, User } from 'oidc-client';
@Injectable()
export class AuthService {
private userManager: UserManager;
constructor () {
this.userManager = new UserManager({
@danielcrisp
danielcrisp / token.interceptor.ts
Last active July 25, 2017 13:28
TokenInterceptor - Async HTTP Interceptors with Angular 4
import { Injectable } from '@angular/core';
import { HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { AuthService } from './auth.service';
@Injectable()
export class TokenInterceptor implements HttpInterceptor {
constructor (private auth: AuthService) {}
@danielcrisp
danielcrisp / app.module.ts
Created July 25, 2017 13:28
AppModule - Async HTTP Interceptors with Angular 4
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { AppComponent } from '/app.component';
import { AuthService } from './auth.service';
import { TokenInterceptor } from './token.interceptor';
@NgModule({
declarations: [
@danielcrisp
danielcrisp / app.component.ts
Created July 25, 2017 13:29
AppComponent - Async HTTP Interceptors with Angular 4
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'my-app',
template: '<div></div>'
})
export class AppComponent implements OnInit {
constructor (private http: HttpClient) {}
@danielcrisp
danielcrisp / token.interceptor.ts
Created July 25, 2017 13:30
TokenInterceptor.intercept - Async HTTP Interceptors with Angular 4
intercept (request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request);
}
@danielcrisp
danielcrisp / token.interceptor.ts
Created July 25, 2017 13:31
TokenInterceptor.intercept - Async HTTP Interceptors with Angular 4
// THIS DOESN'T WORK!
intercept (request, next) {
this.auth.getUser().then(user => {
// ... modify the request here ...
next.handle(request);
});
}
@danielcrisp
danielcrisp / auth.service.ts
Created July 25, 2017 13:35
AuthService imports - Async HTTP Interceptors with Angular 4
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/fromPromise';
@danielcrisp
danielcrisp / auth.service.ts
Created July 25, 2017 13:36
AuthService.getUser - Async HTTP Interceptors with Angular 4
getUser (): Observable<User> {
return Observable.fromPromise(this.userManager.getUser());
}