Giter Club home page Giter Club logo

heyoffline's Introduction

๐Ÿ”Œ Heyoffline

Notify your users when their network goes down. Make sure they don't lose anything.

Features

  • Notify on general network outage
  • Notify only when users have unsaved form field states
  • Default, pretty generic, good looking styles

Setup

Module

NPM: heyoffline

import Heyoffline from "./dist/heyoffline.esm.js"
new Heyoffline()

Browser

UNPKG: https://unpkg.com/heyoffline@latest/dist/heyoffline.umd.js

<script src="dist/heyoffline.umd.js"></script>
new Heyoffline({
  monitorFields: true,
  fields: ".monitoredFields"
});

Options

Name Type Default Description
monitorFields boolean false If this option is enabled, message on network error will be shown only if a input/textarea/select/etc on the page was modified
prefix string heyoffline Class prefix for generated elements
noStyles boolean false Don't use the default CSS (generated by JS)
disableDimiss boolean false By default the user can dismiss the warning. With this option you can hide the dismiss button.
fields string "input, select, textarea, *[contenteditable]" Field elements that will be monitored for changes - see monitorFields option.
text.offline.title string You're currently offline Heading of the modal window
text.offline.content string Wait until your network comes back before continuing. Body message of the modal window
text.offline.button string Dismiss Dismissal button of the modal window
text.offline.icon string SVG icon Modal icon

Events

Name Provides Description
onOnline Fires then the network becomes available
onOffline Fires when the network disappears

Requirements

Heyoffline is framework-agnostic vanilla JS.

Source code

All efforts have been made to keep the source as clean and readable as possible.

Requirements

Heyoffline.js is released under an MIT License, so do with it what you will.

heyoffline's People

Contributors

akatz avatar imkingdavid avatar oskarkrawczyk avatar shashankmehta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heyoffline's Issues

element.addEventListener breaks IE8

  • Love the project
  • Unfortunately, it seems that heyoffline.js:24 (return element.addEventListener(event, fn, useCapture);) gives this error:

"Object doesn't support this property or method"

  • After a little research, it seems that if the addEventListener function is not available you can use attachEvent.
  • I'll give it a shot and see if I can contribute a fix for it, but no guarantees :)

onOnline and onOffline are reversed?

Please see the code below, the output of console.log shows that onOnline and onOffline events are the opposite of network availability. (meaning that onOnline triggered when disconnected from the wifi, and onOffline triggered when reconnected to wifi)
The modal window show and hide are correct.

$(function () {
new Heyoffline({
onOnline: function () {
console.log("online now");
},
onOffline: function () {
console.log("offline now");
}
});
});

please advise,
Thank you,

Does not work on Windows 7

I switched my Wi fi off for about 60 seconds. But then I did not see any DOM change to reflect the functioning of your online demo script. Is there anything more I need to do?

Thanks. Great project btw.

Not working when through proxy

I connect to the Internet via ssh proxy tunnel. If I disable the proxy tunnel message won't appear (it'll appear only when I disconnect from Wi-Fi).

Mac OS X 10.8.2

Useful!!!

I just want to say this is really useful for me. I am creating a web text editor and want to tell users if they can save. If it is alright I would like to build on this API.

Issues in Firefox 29.0.1

The script doesn't work on Mozilla Firefox 29.0.1 (Windows 7).

But works fine on the same machine with -
Google Chrome 35.0.1916.153 m
Opera 22.0.1471.70
Internet Explorer 11.0.9600

No checkup at startup ?

This project is just awesome !
But there's a thing that embarrass me, it's not possible to check the network when the website opens.
I would be usefull if the website is available offline (thanks to the HTML5 manifest).

Rewrite

  • Rewrite into ES6
  • Consider external CSS
  • Configurable message template
  • Remove CoffeeScript remains
  • Discard Bower stuff
  • Publish on NPM

Does not work on Firefox.

Tested on Firefox 17.0.

I undestand that firefox spec is not standard regarding the online/offline events. But it should trigger at least when the user clicks on "work offline" which is not the case currently.

Thanks.

Issues in Linux

Hey there. Great little script - works fine in Chromium under Ubuntu, but doesnt in Firefox. Also fails in a Windows 7 virtualbox under Safari and Firefox, havent tested Chrome yet. Just an FYI, hope to see improvements in the future!

Custom text

I can't figure out how to change the text. I've tried with the following code

new Heyoffline({
  text.title: "Heading",
  text.content: "Warning Text",
  text.button: "Close Warning" 
} ) ;

But I just get some error messages. Uncaught SyntaxError: Unexpected token .

What could be wrong?

What type of offline?

I tested this by disconnection my network connection while on the demo site and it didn't detect I had lost my connection.

So is this script only for mobile devices? Or for when the browser is set to Work Offline ?

Android 2.3.x

It doesn't work on Webkit browser but it works on Firefox Mobile

Missing supported browser/required features list in readme

Would be useful to update the readme to have a list of supported browsers or, alternately, a description of what features are required for this to work.

My first impression of this was that it did not work because I tried the demo in Firefox 19.0.2 (which does not support the features required by this utility).

Customize heyoffline texts

I am trying to change the texts of the heyoffline script. Unfortunately, i'm not being able to change it's options, like such:

new Heyoffline({
text: {
title: "Heading",
content: "WarningMessage",
button: "Close Alert"
}
});

It tells me that "object is not a function". My console is telling me that "Heyoffline" is an object, not a function.
Without any adjustments, if I disconnect my wifi, it displays your heyoffline popup just fine.

Any clue what I am missing here?

TIA, Jasper

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.