Skip to content

Commit

Permalink
Rename live -> watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Krister Kari committed Jun 9, 2015
1 parent 97f9411 commit e8d2b31
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ __data-placeholder-mode="input"__

Does not hide placeholder on focus, but hides it after user types text to the input field.

### data-placeholder-live
### data-placeholder-watch

Default: `true`

__data-placeholder-live="false"__
__data-placeholder-watch="false"__

Disables Placekeeper's feature that watches for placeholder attribute changes on input fields that are currently on the page.

Expand Down
6 changes: 3 additions & 3 deletions src/data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {

function hasLiveUpdatesAttrSetToFalse(element) {
return element.getAttribute("data-placeholder-live") === "false";
function hasWatchAttrSetToFalse(element) {
return element.getAttribute("data-placeholder-watch") === "false";
}

function hasModeAttrSetToInput(element) {
Expand Down Expand Up @@ -89,7 +89,7 @@
}

placekeeper.data = {
hasLiveUpdatesAttrSetToFalse: hasLiveUpdatesAttrSetToFalse,
hasWatchAttrSetToFalse: hasWatchAttrSetToFalse,
hasModeAttrSetToInput: hasModeAttrSetToInput,
hasEventsAttrSetToTrue: hasEventsAttrSetToTrue,
hasActiveAttrSetToTrue: hasActiveAttrSetToTrue,
Expand Down
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@
}
clearInterval(loopInterval);
placekeeperLoop();
if (!mode.hasDisabledLiveUpdates()) {
mode.enableLive();
if (!mode.hasWatchingDisabled()) {
mode.enableWatching();
// main loop
loopInterval = setInterval(placekeeperLoop, settings.defaultLoopDuration);
} else {
mode.disableLive();
mode.disableWatching();
}
}

Expand All @@ -149,7 +149,7 @@
placekeeper.enable = init;
placekeeper.disable = disablePlacekeeper;
placekeeper.isFocusEnabled = mode.isPlacekeeperFocusEnabled;
placekeeper.isLiveUpdateEnabled = mode.isPlacekeeperLiveUpdateEnabled;
placekeeper.isWatchingEnabled = mode.isPlacekeeperWatchingEnabled;

// Exposed private methods
placekeeper.priv = {
Expand Down
28 changes: 14 additions & 14 deletions src/mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

var isEnabled = false;
var isFocusEnabled = true;
var isLiveUpdateEnabled = false;
var isWatchingEnabled = false;

function isPlacekeeperEnabled() {
return isEnabled;
Expand All @@ -14,13 +14,13 @@
return isFocusEnabled;
}

function isPlacekeeperLiveUpdateEnabled() {
return isLiveUpdateEnabled;
function isPlacekeeperWatchingEnabled() {
return isWatchingEnabled;
}

function hasDisabledLiveUpdates() {
return data.hasLiveUpdatesAttrSetToFalse(document.documentElement) ||
data.hasLiveUpdatesAttrSetToFalse(document.body);
function hasWatchingDisabled() {
return data.hasWatchAttrSetToFalse(document.documentElement) ||
data.hasWatchAttrSetToFalse(document.body);
}

function hasFocusDisabled() {
Expand All @@ -36,12 +36,12 @@
isFocusEnabled = false;
}

function enableLive() {
isLiveUpdateEnabled = true;
function enableWatching() {
isWatchingEnabled = true;
}

function disableLive() {
isLiveUpdateEnabled = false;
function disableWatching() {
isWatchingEnabled = false;
}

function disable() {
Expand All @@ -55,13 +55,13 @@
placekeeper.mode = {
isPlacekeeperEnabled: isPlacekeeperEnabled,
isPlacekeeperFocusEnabled: isPlacekeeperFocusEnabled,
isPlacekeeperLiveUpdateEnabled: isPlacekeeperLiveUpdateEnabled,
hasDisabledLiveUpdates: hasDisabledLiveUpdates,
isPlacekeeperWatchingEnabled: isPlacekeeperWatchingEnabled,
hasWatchingDisabled: hasWatchingDisabled,
hasFocusDisabled: hasFocusDisabled,
enableFocus: enableFocus,
disableFocus: disableFocus,
enableLive: enableLive,
disableLive: disableLive,
enableWatching: enableWatching,
disableWatching: disableWatching,
disable: disable,
enable: enable
};
Expand Down
6 changes: 3 additions & 3 deletions test/unit/hide-on-input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ describe("hide on input mode", function() {
helpers.spyOnFocusEnabledAndReturn(false);
element = helpers.createInputElement(true);
placekeeper.priv.__setupPlaceholders();
placekeeper.mode.enableLive();
placekeeper.mode.enableWatching();
});

afterEach(function() {
element.parentNode.removeChild(element);
});

it("should have live updates enabled", function() {
expect(placekeeper.isLiveUpdateEnabled()).toEqual(true);
it("should have watching enabled", function() {
expect(placekeeper.isWatchingEnabled()).toEqual(true);
});

it("should have called utils.addEventListener for keydown handler", function() {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/live.spec.js → test/unit/watch.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
describe("live updates", function() {
describe("watching for placeholder changes", function() {
"use strict";

beforeEach(helpers.initialSetup);

describe("when live updates are enabled and there is an element with placeholder on the page", function() {
describe("when watching enabled and there is an element with placeholder on the page", function() {
var element;

beforeEach(function(done) {
Expand All @@ -22,8 +22,8 @@ describe("live updates", function() {
expect(element.getAttribute("data-placeholder-value")).toEqual("Test");
});

it("should have live updates enabled", function() {
expect(placekeeper.isLiveUpdateEnabled()).toEqual(true);
it("should have watching enabled", function() {
expect(placekeeper.isWatchingEnabled()).toEqual(true);
});

describe("and when placeholder value is changed", function() {
Expand Down

0 comments on commit e8d2b31

Please sign in to comment.