npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-svg-timer

v0.1.1

Published

An SVG-based timer button

Downloads

8

Readme

angular-svg-timer

Build Status

An Angular directive to provide a self-contained, SVG-based timer button with visual feedback of elapsed time:

Timer screenshots

The SVG is based on this fiddle. Extending this into an Angular directive allows additional features, including the start/stop button (works with touch) and communication between the directive and the view so that timer events can be handled.

Demo

See the demo page for a working example.

Usage

  1. Install with bower:

    bower install angular-svg-timer

  2. Include the scripts in your main index.html file:

    <script src="bower_components/moment/moment.js"></script>
    <script src="bower_components/angular-moment/angular-moment.js"></script>
    <script src="bower_components/angular-svg-timer/timer.js"></script>
  3. Register the module dependency in your main app.js file, e.g.:

    var App = angular.module('App', ['markau.timer']);

Quick start

The minimal declaration is:

<markau-timer time="20" />

Options

The directive uses an isolate scope with 2-way binding on provided attributes, so the view can remain aware of changes in timer state.

The directive exposes the following attributes:

  • Time: countdown time (in milliseconds). Required.
  • Status:
    • notstarted
    • running
    • complete
    • <something else> (based on events below)
  • Events: an array of objects in the form { 'time': '<event>' }. This is intended to allow the timer to check for <event> milestones and update the status accordingly. The one event supported so far is { 'time': 'half' }; when the countdown is half way through, the status attribute changes from 'running' to 'halftime'. Other useful events may include 1/4 and 3/4 time, '10 seconds remaining' etc.

Example

Instantiate scope variables:

$scope.time = 20;
$scope.status = 'notstarted';
$scope.events: [{ 'time': 'half' }];

Bind the scope variables to attributes on the element:

<markau-timer time="time" status="status" events="events" />

Add a placeholder to show the current value of the scope variable:

<h2>Timer status: {{status}}</h2>

More advanced use cases involve a $watch on the $scope.status variable, or use of ng-class to show different content depending on the status. The demo page shows this in action.

Style

The directive uses an html template which exposes the svg-container and svg-timer-text classes. You can change the style on the countdown text by overriding the class:

.svg-timer-text {
    fill: #262626; /* 'fill' is the svg version of 'color' */
    font-size: 42px;
}

Size

Being an SVG, the timer scales to fill the containing DOM element (effectively, width: 100%). Place it inside a width-constrained block element to control the size of the timer.

A note on precision

Counting setTimeout() intervals is an unreliable method of measuring time in JavaScript; a 1000ms interval is not necessarily 1000ms, up to 200-300ms, depending on the load on the client device (intervals can be blocked).

This directive follows an approach of comparing the elapsed time of each setTimeout() interval against Date.now(), in order to calculate and adjust for any drift. This use of system time ensures reliable results across devices.

Compatability

This has been tested on Android 4.2 and iOS 6 / 7 in a Phonegap project, in addition to a variety of modern desktop browsers.

License

MIT