Skip to content

Commit

Permalink
add all plugin files
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMayerhofer committed Apr 22, 2018
1 parent a371a8f commit fac50bd
Show file tree
Hide file tree
Showing 21 changed files with 846 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"env": {
"es6": true,
"browser": true,
"jquery": true,
},
"extends": "airbnb",
"rules": {
"no-console": 1,
"no-unused-vars": 1,
"no-tabs": 0,
"indent": [2, "tab"],
"react/jsx-indent": [2, "tab"],
"react/jsx-indent-props": [2, "tab"],
"react/jsx-filename-extension": 0,
"react/forbid-prop-types": 0,
},
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": false,
"codeFrame": false
}
}
96 changes: 96 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Created with the help of https://www.gitignore.io/api/wordpress,sublimetext,grunt,sass,osx,git,tower

### SublimeText ###
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# workspace files are user-specific
*.sublime-workspace

# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
# *.sublime-project

# sftp configuration file
sftp-config.json

# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
bh_unicode_properties.cache

# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings

# Sublime-Grunt package cache file
.sublime-grunt.cache

# PHP Intel package
.phpintel/

### Grunt ###
# Grunt usually compiles files inside this directory
dist/
build/

# minified images
imgmin/
img/min/

# Grunt usually preprocesses files such as coffeescript, compass... inside the .tmp directory
.tmp/

node_modules

# SASS
.sass-cache

# Generated CSS files
style.css.map
style.css
admin.css.map
admin.css


### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Others ###

# generated of README.md
README.html

#Composer
/vendor
98 changes: 98 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* eslint import/no-dynamic-require:0 */
/* eslint global-require:0 */
/* eslint-disable-next-line func-names */
module.exports = function (grunt) {
// Utility to load the different option files
// based on their names
function loadConfig(path) {
const glob = require('glob');
const object = {};
let key;
glob.sync('*', { cwd: path }).forEach((option) => {
key = option.replace(/\.js$/, '');
object[key] = require(path + option);
});
return object;
}

// Initial config
const config = {
pkg: grunt.file.readJSON('package.json'),
env: process.env,
paths: {
// PHP assets
php: {
files_std: [ // Standard file match
'**/*.php',
'!node_modules/**',
'!vendor/**',
],
files: '<%= paths.php.files_std %>', // Dynamic file match
},

// JavaScript assets
js: {
grunt: {
tasks: 'tasks/**/*.js',
gruntfile: 'Gruntfile.js',
},
src: 'js', // Development code
dest: 'js/build', // Production code
dist_file_name: 'build.js',
files_std: [ // Standard file match
'<%= paths.js.src %>/**/*.js',
'!<%= paths.js.dest %>/**/*',
'<%= paths.js.grunt.tasks %>',
'<%= paths.js.grunt.gruntfile %>',
],
files: '<%= paths.js.files_std %>', // Dynamic file match
},
},
};

// Load tasks from the tasks folder
grunt.loadTasks('tasks');

// Load all task options in tasks/options
grunt.util._.extend(config, loadConfig('./tasks/options/'));

/**
* Adds input source map for babel task.
* Because grunt tries to read the map before it was generated, this has to be done
* in a task. configureBabelInputSourceMap task must always be called before babel task.
*/
function setBabelInputSourceMap() {
config.babel.options.inputSourceMap = grunt.file.readJSON(`${config.paths.js.dest}/${config.paths.js.dist_file_name}.js.map`);
}
grunt.task.registerTask('configureBabelInputSourceMap', 'configures babel input source map', setBabelInputSourceMap);

grunt.initConfig(config);

grunt.event.on('watch', (action, filepath) => {
// Determine task based on filepath
function getExt(path) {
let ret = '';
const i = path.lastIndexOf('.');
if (i !== -1 && i <= path.length) {
ret = path.substr(i + 1);
}
return ret;
}

switch (getExt(filepath)) {
// PHP
case 'php':
grunt.config('paths.php.files', [filepath]);
break;
// JavaScript
case 'js':
grunt.config('paths.js.files', [filepath]);
break;
default:
break;
}
});

// loads any tasks listed in devDependencies in package.json
require('load-grunt-tasks')(grunt);
};
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Scarcity Counter

[![Github Releases](https://img.shields.io/github/release/SimonMayerhofer/scarcity-counter.svg)](https://github.com/SimonMayerhofer/scarcity-counter/releases)

Scarcity Counter is a WordPress plugin for [artificial scarcity](https://en.wikipedia.org/wiki/Artificial_scarcity). It is great for marketing purposes. By providing timelimits and random reduction numbers it aims to make it not too obvious it's fake.
Be aware that it is just client side. So if the user visit your site on another device another number will be visible.

It works with multiple counters on a page. Use the same `id` attribute to show the same counter at different places on your page.

## Demo
You can see it in action [on Codepen](https://codepen.io/maysi/full/NMGyOV/).

## Shortcode
[scarcity-counter id="id" start="27" min="3" reduction="3" timelimit="5000"]

### Attributes
* **id** id to identify the counter. if used multiple times, the same number is shown. defaults to `id`.
* **start** number to start with. defaults to `27`.
* **min** lower limit. the counter won't ever get below that limit. defaults to `3`.
* **reduction** upper range limit. E.g. if 5 is set as the limit, the counter will be reduced by a number between 1 and 5. defaults to `3`.
* **timelimit** number in milliseconds how long to wait until another reduction (on page reload). defaults to `5000`.


## Requirements
To compile this plugin, it requires the following modules installed on your system:

1. [Composer][]
2. [Grunt][]

[Composer]: https://getcomposer.org/ "Composer"
[Grunt]: https://gruntjs.com/ "Grunt"

## Compilation

To compile the plugin follow the following steps:

1. Navigate to this plugins directory
2. Setup composer: `composer install`
3. Install npm modules: `npm install`

After you followed the steps above you're able to compile the project with
`grunt build`.

Use `grunt watch` to watch the files for changes.

FYI: You can just go to [Releases](https://github.com/SimonMayerhofer/scarcity-counter/releases) to download a already compiled release.
Loading

0 comments on commit fac50bd

Please sign in to comment.