Initial commit

This commit is contained in:
zhongjin 2018-09-28 09:27:11 +08:00
commit 8b7425a99e
34 changed files with 1709 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules

6
.npmignore Normal file
View File

@ -0,0 +1,6 @@
Gruntfile.js
tasks
node_modules
test
.travis.yml
appveyor.yml

7
.travis.yml Normal file
View File

@ -0,0 +1,7 @@
os:
- linux
language: node_js
node_js:
- '4'
- '8'
- '10'

156
Gruntfile.js Normal file
View File

@ -0,0 +1,156 @@
// To use this file in WebStorm, right click on the file name in the Project Panel (normally left) and select "Open Grunt Console"
/** @namespace __dirname */
/* jshint -W097 */// jshint strict:false
/*jslint node: true */
"use strict";
module.exports = function (grunt) {
var srcDir = __dirname + '/';
var dstDir = srcDir + '.build/';
var pkg = grunt.file.readJSON('package.json');
var iopackage = grunt.file.readJSON('io-package.json');
var version = (pkg && pkg.version) ? pkg.version : iopackage.common.version;
// Project configuration.
grunt.initConfig({
pkg: pkg,
replace: {
core: {
options: {
patterns: [
{
match: /version: *"[\.0-9]*"/,
replacement: 'version: "' + version + '"'
},
{
match: /"version": *"[\.0-9]*",/g,
replacement: '"version": "' + version + '",'
},
{
match: /version: *"[\.0-9]*",/g,
replacement: 'version: "' + version + '",'
}
]
},
files: [
{
expand: true,
flatten: true,
src: [
srcDir + 'package.json',
srcDir + 'io-package.json'
],
dest: srcDir
},
{
expand: true,
flatten: true,
src: [
srcDir + 'widgets/' + pkg.name.substring('yunkong2.vis-'.length) + '.html'
],
dest: srcDir + 'widgets'
},
{
expand: true,
flatten: true,
src: [
srcDir + 'widgets/' + pkg.name.substring('yunkong2.vis-'.length) + '/js/' + pkg.name.substring('yunkong2.vis-'.length) + '.js'
],
dest: srcDir + 'widgets/' + pkg.name.substring('yunkong2.vis-'.length) + '/js'
}
]
}
},
// Javascript code styler
jscs: require(__dirname + '/tasks/jscs.js'),
// Lint
jshint: require(__dirname + '/tasks/jshint.js'),
http: {
get_hjscs: {
options: {
url: 'https://raw.githubusercontent.com/yunkong2/yunkong2.js-controller/master/tasks/jscs.js'
},
dest: 'tasks/jscs.js'
},
get_jshint: {
options: {
url: 'https://raw.githubusercontent.com/yunkong2/yunkong2.js-controller/master/tasks/jshint.js'
},
dest: 'tasks/jshint.js'
},/*
get_gruntfile: {
options: {
url: 'https://raw.githubusercontent.com/yunkong2/yunkong2.build/master/adapters/Gruntfile.js'
},
dest: 'Gruntfile.js'
},
get_utilsfile: {
options: {
url: 'https://raw.githubusercontent.com/yunkong2/yunkong2.build/master/adapters/utils.js'
},
dest: 'lib/utils.js'
},*/
get_jscsRules: {
options: {
url: 'https://raw.githubusercontent.com/yunkong2/yunkong2.js-controller/master/tasks/jscsRules.js'
},
dest: 'tasks/jscsRules.js'
}
}
});
grunt.registerTask('updateReadme', function () {
var readme = grunt.file.read('README.md');
var pos = readme.indexOf('## Changelog');
if (pos != -1) {
var readmeStart = readme.substring(0, pos + '## Changelog\n'.length);
var readmeEnd = readme.substring(pos + '## Changelog\n'.length);
if (readme.indexOf(version) == -1) {
var timestamp = new Date();
var date = timestamp.getFullYear() + '-' +
("0" + (timestamp.getMonth() + 1).toString(10)).slice(-2) + '-' +
("0" + (timestamp.getDate()).toString(10)).slice(-2);
var news = "";
if (iopackage.common.whatsNew) {
for (var i = 0; i < iopackage.common.whatsNew.length; i++) {
if (typeof iopackage.common.whatsNew[i] == 'string') {
news += '* ' + iopackage.common.whatsNew[i] + '\n';
} else {
news += '* ' + iopackage.common.whatsNew[i].en + '\n';
}
}
}
grunt.file.write('README.md', readmeStart + '### ' + version + ' (' + date + ')\n' + (news ? news + '\n\n' : '\n') + readmeEnd);
}
}
});
grunt.loadNpmTasks('grunt-replace');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-http');
grunt.registerTask('default', [
'exec',
'http',
'clean',
'replace',
'updateReadme',
'compress',
'copy',
'jshint',
'jscs'
]);
grunt.registerTask('prepublish', [
'replace',
'updateReadme'
]);
grunt.registerTask('p', [
'prepublish'
]);
};

42
LICENSE Normal file
View File

@ -0,0 +1,42 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
You must give any other recipients of the Work or Derivative Works a copy of this License; and
You must cause any modified files to carry prominent notices stating that You changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

32
README.md Normal file
View File

@ -0,0 +1,32 @@
![Logo](admin/fancyswitch.png)
yunkong2.vis-fancyswitch
============
[![NPM version](http://img.shields.io/npm/v/yunkong2.vis-fancyswitch.svg)](https://www.npmjs.com/package/yunkong2.vis-fancyswitch)
[![Downloads](https://img.shields.io/npm/dm/yunkong2.vis-fancyswitch.svg)](https://www.npmjs.com/package/yunkong2.vis-fancyswitch)
[![NPM](https://nodei.co/npm/yunkong2.vis-fancyswitch.png?downloads=true)](https://nodei.co/npm/yunkong2.vis-fancyswitch/)
fancyswitch - Switch widgets for yunkong2.vis ported from http://papermashup.com/jquery-fancy-switch/ from @ashleyford
![Example](img/widgets.png)
## Changelog
### 1.1.0 (2016-07-17)
- (Apollon77) Enhance handling of boolean and textual values for on/off
### 1.0.0 (2016-04-07)
- (bluefox) fix button Giva Labs iButton (other widgets did not work)
### 0.0.3 (2015-10-04)
- (bluefox) add version output
### 0.0.2 (2015-10-04)
- (bluefox) fix dependencies
### 0.0.1 (2015-10-04)
- (bluefox) initial checkin
## License
Copyright (c) 2013-2016 hobbyquaker https://git.spacen.net/hobbyquaker, bluefox https://git.spacen.net/GermanBluefox
Apache 2.0

BIN
admin/fancyswitch.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

61
admin/index.html Normal file
View File

@ -0,0 +1,61 @@
<html>
<!-- these 4 files always have to be included -->
<link rel="stylesheet" type="text/css" href="../../lib/css/themes/jquery-ui/redmond/jquery-ui.min.css"/>
<link rel="stylesheet" type="text/css" href="../../lib/css/jquery.multiselect-1.13.css"/>
<script type="text/javascript" src="../../lib/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../socket.io/socket.io.js"></script>
<script type="text/javascript" src="../../lib/js/jquery-ui-1.10.3.full.min.js"></script>
<!-- these two file always have to be included -->
<link rel="stylesheet" type="text/css" href="../../css/adapter.css"/>
<script type="text/javascript" src="../../js/translate.js"></script>
<script type="text/javascript" src="../../js/adapter-settings.js"></script>
<style>
.table_header {
background-color: blue;
color: white;
}
.ip {
width: 150px;
text-align: right;
}
</style>
<!-- you have to define 2 functions in the global scope: -->
<script type="text/javascript">
systemDictionary = {
"Fancyswitch Widgets settings": {
"en": "Fancyswitch Widgets settings",
"de": "Fancyswitch Widgets Einstellungen",
"ru": "Настройки Fancyswitch Widgets"
},
"There is nothing to setup": {
"en": "There is nothing to setup",
"de": "Es gibt nichts einzustellen",
"ru": "Нечего настраивать"
},
};
function load(settings, onChange) {
if (!settings) return;
onChange(false);
}
function save(callback) {
callback(null);
}
</script>
<div id="adapter-container">
<table><tr>
<td><img src="hqwidgets.png"></td>
<td style="padding-top: 20px;padding-left: 10px"><h3 class="translate">Fancyswitch Widgets settings</h3></td>
</tr></table>
<div class="translate">There is nothing to setup</h4>
</div>
</html>

BIN
img/widgets.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

59
io-package.json Normal file
View File

@ -0,0 +1,59 @@
{
"common": {
"name": "vis-fancyswitch",
"version": "1.1.0",
"title": "yunkong2 Visualisation - fancyswitch style Widgets",
"news": {
"1.1.0": {
"en": "Enhance handling of boolean and textual values for on/off",
"de": "Behandlung von Boolean und Zeichenketten als Werte für Ein/Aus verbessert",
"ru": "Enhance handling of boolean and textual values for on/off"
},
"1.0.0": {
"en": "fix button Giva Labs iButton (other widgets did not work)",
"de": "fix button Giva Labs iButton (other widgets did not work)",
"ru": "fix button Giva Labs iButton (other widgets did not work)"
}
},
"desc": {
"en": "Switch widgets for yunkong2.vis",
"de": "Schalter und Wippe-Widgets für yunkong2.vis",
"ru": "Переключатели для yunkong2.vis"
},
"platform": "Javascript/Node.js",
"loglevel": "info",
"icon": "fancyswitch.png",
"enabled": true,
"mode": "once",
"extIcon": "https://raw.githubusercontent.com/yunkong2/yunkong2.vis-fancyswitch/master/admin/fancyswitch.png",
"keywords": [
"fancyswitch",
"vis",
"GUI",
"graphical",
"scada"
],
"readme": "https://git.spacen.net/yunkong2/yunkong2.vis-fancyswitch/blob/master/README.md",
"authors": [
"bluefox <dogafox@gmail.com>"
],
"localLink": "%web_protocol%://%ip%:%web_port%/vis/edit.html",
"license": "Apache 2.0",
"dependencies": [
"vis"
],
"onlyWWW": true,
"singleton": true,
"type": "visualization-widgets",
"restartAdapters": [
"vis"
],
"noConfig": true
},
"native": {
"dependencies": [
"basic"
]
},
"instanceObjects": []
}

50
package.json Normal file
View File

@ -0,0 +1,50 @@
{
"name": "yunkong2.vis-fancyswitch",
"description": "fancyswitch Widgets for yunkong2.vis",
"version": "1.1.0",
"author": {
"name": "bluefox",
"email": "dogafox@gmail.com"
},
"contributors": [
"bluefox <dogafox@gmail.com>",
"Apollon77 <ingo@fischer-ka.de>"
],
"homepage": "https://git.spacen.net/yunkong2/yunkong2.vis-fancyswitch",
"repository": {
"type": "git",
"url": "https://git.spacen.net/yunkong2/yunkong2.vis-fancyswitch"
},
"licenses": [
{
"type": "Apache 2.0",
"url": "https://git.spacen.net/yunkong2/yunkong2.vis-fancyswitch/blob/master/LICENSE"
}
],
"keywords": [
"yunkong2",
"GUI",
"DashUI",
"web interface",
"home automation",
"SCADA",
"fancyswitch GUI"
],
"devDependencies": {
"grunt": "^1.0.1",
"grunt-replace": "^1.0.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-jscs": "^3.0.1",
"grunt-http": "^2.2.0",
"mocha": "^4.1.0",
"chai": "^4.1.2"
},
"bugs": {
"url": "https://git.spacen.net/yunkong2/yunkong2.vis-fancyswitch/issues"
},
"main": "widgets/fancyswitch.html",
"scripts": {
"test": "node node_modules/mocha/bin/mocha --exit"
},
"license": "Apache 2.0"
}

17
tasks/jscs.js Normal file
View File

@ -0,0 +1,17 @@
var srcDir = __dirname + "/../";
module.exports = {
all: {
src: [
srcDir + "*.js",
srcDir + "lib/*.js",
srcDir + "adapter/example/*.js",
srcDir + "tasks/**/*.js",
srcDir + "www/**/*.js",
'!' + srcDir + "www/lib/**/*.js",
'!' + srcDir + 'node_modules/**/*.js',
'!' + srcDir + 'adapter/*/node_modules/**/*.js'
],
options: require('./jscsRules.js')
}
};

36
tasks/jscsRules.js Normal file
View File

@ -0,0 +1,36 @@
module.exports = {
force: true,
"requireCurlyBraces": ["else", "for", "while", "do", "try", "catch"], /*"if",*/
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"disallowSpacesInFunctionDeclaration": {"beforeOpeningRoundBrace": true},
"disallowSpacesInNamedFunctionExpression": {"beforeOpeningRoundBrace": true},
"requireSpacesInFunctionExpression": {"beforeOpeningCurlyBrace": true},
"requireSpacesInAnonymousFunctionExpression": {"beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true},
"requireSpacesInNamedFunctionExpression": {"beforeOpeningCurlyBrace": true},
"requireSpacesInFunctionDeclaration": {"beforeOpeningCurlyBrace": true},
"disallowMultipleVarDecl": true,
"requireBlocksOnNewline": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpacesInsideParentheses": true,
"requireCommaBeforeLineBreak": true,
//"requireAlignedObjectValues": "all",
"requireOperatorBeforeLineBreak": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
// "disallowLeftStickedOperators": ["?", "+", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
// "requireRightStickedOperators": ["!"],
// "requireSpaceAfterBinaryOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
//"disallowSpaceAfterBinaryOperators": [","],
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
"requireSpaceAfterBinaryOperators": ["?", ">", ",", ">=", "<=", "<", "+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
//"validateIndentation": 4,
//"validateQuoteMarks": { "mark": "\"", "escape": true },
"disallowMixedSpacesAndTabs": true,
"disallowKeywordsOnNewLine": ["else", "catch"]
};

17
tasks/jshint.js Normal file
View File

@ -0,0 +1,17 @@
var srcDir = __dirname + "/../";
module.exports = {
options: {
force: true
},
all: [
srcDir + "*.js",
srcDir + "lib/*.js",
srcDir + "adapter/example/*.js",
srcDir + "tasks/**/*.js",
srcDir + "www/**/*.js",
'!' + srcDir + "www/lib/**/*.js",
'!' + srcDir + 'node_modules/**/*.js',
'!' + srcDir + 'adapter/*/node_modules/**/*.js'
]
};

91
test/testPackageFiles.js Normal file
View File

@ -0,0 +1,91 @@
/* jshint -W097 */
/* jshint strict:false */
/* jslint node: true */
/* jshint expr: true */
var expect = require('chai').expect;
var fs = require('fs');
describe('Test package.json and io-package.json', function() {
it('Test package files', function (done) {
console.log();
var fileContentIOPackage = fs.readFileSync(__dirname + '/../io-package.json', 'utf8');
var ioPackage = JSON.parse(fileContentIOPackage);
var fileContentNPMPackage = fs.readFileSync(__dirname + '/../package.json', 'utf8');
var npmPackage = JSON.parse(fileContentNPMPackage);
expect(ioPackage).to.be.an('object');
expect(npmPackage).to.be.an('object');
expect(ioPackage.common.version, 'ERROR: Version number in io-package.json needs to exist').to.exist;
expect(npmPackage.version, 'ERROR: Version number in package.json needs to exist').to.exist;
expect(ioPackage.common.version, 'ERROR: Version numbers in package.json and io-package.json needs to match').to.be.equal(npmPackage.version);
if (!ioPackage.common.news || !ioPackage.common.news[ioPackage.common.version]) {
console.log('WARNING: No news entry for current version exists in io-package.json, no rollback in Admin possible!');
console.log();
}
expect(npmPackage.author, 'ERROR: Author in package.json needs to exist').to.exist;
expect(ioPackage.common.authors, 'ERROR: Authors in io-package.json needs to exist').to.exist;
if (ioPackage.common.name.indexOf('template') !== 0) {
if (Array.isArray(ioPackage.common.authors)) {
expect(ioPackage.common.authors.length, 'ERROR: Author in io-package.json needs to be set').to.not.be.equal(0);
if (ioPackage.common.authors.length === 1) {
expect(ioPackage.common.authors[0], 'ERROR: Author in io-package.json needs to be a real name').to.not.be.equal('my Name <my@email.com>');
}
}
else {
expect(ioPackage.common.authors, 'ERROR: Author in io-package.json needs to be a real name').to.not.be.equal('my Name <my@email.com>');
}
}
else {
console.log('WARNING: Testing for set authors field in io-package skipped because template adapter');
console.log();
}
expect(fs.existsSync(__dirname + '/../README.md'), 'ERROR: README.md needs to exist! Please create one with description, detail information and changelog. English is mandatory.').to.be.true;
if (!ioPackage.common.titleLang || typeof ioPackage.common.titleLang !== 'object') {
console.log('WARNING: titleLang is not existing in io-package.json. Please add');
console.log();
}
if (
ioPackage.common.title.indexOf('yunkong2') !== -1 ||
ioPackage.common.title.indexOf('yunkong2') !== -1 ||
ioPackage.common.title.indexOf('adapter') !== -1 ||
ioPackage.common.title.indexOf('Adapter') !== -1
) {
console.log('WARNING: title contains Adapter or yunkong2. It is clear anyway, that it is adapter for yunkong2.');
console.log();
}
if (ioPackage.common.name.indexOf('vis-') !== 0) {
if (!ioPackage.common.materialize || !fs.existsSync(__dirname + '/../admin/index_m.html') || !fs.existsSync(__dirname + '/../gulpfile.js')) {
console.log('WARNING: Admin3 support is missing! Please add it');
console.log();
}
if (ioPackage.common.materialize) {
expect(fs.existsSync(__dirname + '/../admin/index_m.html'), 'Admin3 support is enabled in io-package.json, but index_m.html is missing!').to.be.true;
}
}
var licenseFileExists = fs.existsSync(__dirname + '/../LICENSE');
var fileContentReadme = fs.readFileSync(__dirname + '/../README.md', 'utf8');
if (fileContentReadme.indexOf('## Changelog') === -1) {
console.log('Warning: The README.md should have a section ## Changelog');
console.log();
}
expect((licenseFileExists || fileContentReadme.indexOf('## License') !== -1), 'A LICENSE must exist as LICENSE file or as part of the README.md').to.be.true;
if (!licenseFileExists) {
console.log('Warning: The License should also exist as LICENSE file');
console.log();
}
if (fileContentReadme.indexOf('## License') === -1) {
console.log('Warning: The README.md should also have a section ## License to be shown in Admin3');
console.log();
}
done();
});
});

381
widgets/fancyswitch.html Normal file
View File

@ -0,0 +1,381 @@
<!--
yunkong2.vis fancyswitch Widget-Set
version: "1.0.0"
Copyright 2013-2015 hobbyquaker, bluefox<dogafox@gmail.com>
-->
<style type="text/css">
.fancy-switch{
border:none;
background:left no-repeat;
width:105px;
height:46px;
padding:0;
margin:0;
white-space: nowrap;
}
.fancy-on, .fancy-off{
width:50px;
height:40px;
display:inline-block;
cursor:pointer;
}
</style>
<link rel="stylesheet" type="text/css" href="widgets/fancyswitch/css/jquery.ibutton.min.css"/>
<script type="text/javascript" src="widgets/fancyswitch/js/jquery-ui.toggleSwitch.js"></script>
<script type="text/javascript" src="widgets/fancyswitch/js/jquery.ibutton.min.js"></script>
<script type="text/javascript">
"use strict";
if (vis.editMode) {
// Add words for basic widgets
$.extend(true, systemDictionary, {
"text_true": {"en": "Label for true", "de": "Text für TRUE", "ru": "Текст для 1"},
"text_false": {"en": "Label for false", "de": "Text für FALSE", "ru": "Текст для 0"},
"width": {"en": "Width", "de": "Breite", "ru": "Ширина"},
"auto": {"en": "auto", "de": "auto", "ru": "автоматически"},
"true": {"en": "true", "de": "true", "ru": "да"},
"false": {"en": "false", "de": "false", "ru": "нет"},
"labelOn": {"en": "Label for 'ON'", "de": "Text für AN", "ru": "Подпись для 'истина/1'"},
"labelOff": {"en": "Label for 'OFF'", "de": "Text für AUS", "ru": "Подпись для 'ложь/0'"},
"resizeHandle": {"en": "resizeHandle", "de": "Hebelgröße", "ru": "Изменить размер клавиши"},
"resizeContainer": {"en": "resizeContainer", "de": "Konteinergröße", "ru": "Изменить размер виджета"},
"enableDrag": {"en": "Enable drag", "de": "Ziehen erlaubt", "ru": "Можно тащить мышкой"},
"enableFx": {"en": "Animation", "de": "Animation", "ru": "Анимация"},
"duration": {"en": "Effect duration(ms)", "de": "Umschaltdauer(ms)", "ru": "Длительность анимации"},
"highlight_switch": {"en": "Highlight switch", "de": "Highlight Schalter", "ru": "Подсветить выключатель"},
"invert": {"en": "Invert state", "de": "Zustand invertieren", "ru": "Инвертировать состояние"},
"test": {"en": "Test", "de": "Testen", "ru": "Тест"},
"valFalse": {"en": "False value", "de": "Falsch-Wert", "ru": "False-значение"},
"valTrue": {"en": "True value", "de": "Wahr-Wert", "ru": "True-значение"},
"lightStyle": {"en": "Light style", "de": "Hellstil", "ru": "Светлый стиль"},
"autoOff": {"en": "Auto OFF in (ms)", "de": "Auto AUS(ms)", "ru": "Авто Выкл.(мс)"},
"autoOff_tooltip": {
"en": "Chnage to previous state after given interval automatically",
"de": "Ändert Zustand auf vorheriger nach eingegebenem Intervall",
"ru": "Меняет состояние на обратное по истечении указанного времени"
}
});
}
vis.binds.fancyswitch = {
version: "1.0.0",
showVersion: function () {
if (vis.binds.fancyswitch.version) {
console.log('Version vis-fancyswitch:' + vis.binds.fancyswitch.version);
vis.binds.fancyswitch.version = null;
}
},
fancyswitch: function (el, options) {
vis.binds.fancyswitch.showVersion();
var $this = $(el).parent().find('.fancy-switch');
var oid = $this.attr('data-oid');
options.valTrue = (options.valTrue === null || options.valTrue === '' || options.valTrue === undefined) ? null: options.valTrue;
options.valFalse = (options.valFalse === null || options.valFalse === '' || options.valFalse === undefined) ? null: options.valFalse;
if (options.valTrue === null) options.valTrue = 1;
if (options.valTrue === "true") options.valTrue = true;
if (options.valTrue === "false") options.valTrue = false;
if (options.valFalse === null) options.valFalse = 0;
if (options.valFalse === "true") options.valFalse = true;
if (options.valFalse === "false") options.valFalse = false;
if (oid && oid != 'nothing_selected') {
vis.states.bind(oid + '.val', function (e, newVal, oldVal) {
if (newVal === null || newVal === undefined) newVal = options.valFalse;
var num = newVal;
if (num === "true") num = true;
if (num === "false") num = false;
if (num !== true && num !== false) {
if (typeof num === 'string') {
var f = parseFloat(num);
if (f == num) {
num = f;
}
}
if ((typeof num === 'number' && num > 0) || (options.valTrue === 1 && newVal === true) || newVal.toString() === options.valTrue) {
num = true;
}
else {
num = false;
}
}
else {
if (num === options.valTrue) num = true;
else num = false;
}
if (options.invert) {
num = !num;
}
$this.css('background-position', num ? 'left' : 'right');
$this.find('input.fancy-on_off[value="' + options.valFalse + '"]').prop('checked', !num);
$this.find('input.fancy-on_off[value="' + options.valTrue + '"]').prop('checked', num);
});
}
$this.css('background', 'url("' + options.src + '")');
$this.find('.fancy-on_off').css('display', 'none');
$this.find('.fancy-on, .fancy-off').css('text-indent', '-10000px');
var newVal = vis.states.attr(oid + '.val');
if (newVal === null || newVal === undefined) newVal = options.valFalse;
var num = newVal;
if (num === "true") num = true;
if (num === "false") num = false;
if (num !== true && num !== false) {
if (typeof num === 'string') {
var f = parseFloat(num);
if (f == num) {
num = f;
}
}
if ((typeof num === 'number' && num > 0) || (options.valTrue === 1 && newVal === true) || newVal.toString() === options.valTrue) {
num = true;
}
else {
num = false;
}
}
else {
if (num === options.valTrue) num = true;
else num = false;
}
if (options.invert) {
num = !num;
}
$this.css('background-position', num ? 'left' : 'right');
if (!vis.editMode && oid && oid != 'nothing_selected') {
options.autoOff = parseInt(options.autoOff, 10) || 0;
$this.find("input.fancy-on_off").change(function() {
var newVal = $(this).val();
if (newVal === null || newVal === undefined) newVal = options.valFalse;
var num = newVal;
if (num === "true") num = true;
if (num === "false") num = false;
if (num !== true && num !== false) {
if (typeof num === 'string') {
var f = parseFloat(num);
if (f == num) {
num = f;
}
}
if ((typeof num === 'number' && num > 0) || (options.valTrue === 1 && newVal === true) || newVal.toString() === options.valTrue) {
num = true;
}
else {
num = false;
}
}
else {
if (num === options.valTrue) num = true;
else num = false;
}
if (options.invert) {
num = !num;
}
$this.css('background-position', num ? 'left' : 'right');
vis.setValue(oid, num ? options.valTrue : options.valFalse);
if (options.autoOff) {
setTimeout(function () {
vis.setValue(oid, num ? options.valFalse : options.valTrue);
}, options.autoOff);
}
});
}
},
toggleSwitch: function (el, options) {
vis.binds.fancyswitch.showVersion();
var $this = $(el).prev();
$this.toggleSwitch({
highlight: options.highlight,
width: parseInt(options.width, 10) || 40/*,
change: function (e) {
console.log(e);
}*/
});
if (vis.editMode) {
if (options.test) {
$this.val(!parseInt($this.val(), 10) ? '1' : '0').trigger('change');
}
setTimeout(function () {
var id = $this.attr('id');
id = id.substring(0, id.length - '_select'.length);
$('#' + id).find('.ui-toggle-switch').css({'pointer-events': 'none'});
}, 100);
}
},
iButton: function (el, options) {
vis.binds.fancyswitch.showVersion();
var $this = $(el);
setTimeout(function () {
$this.iButton(options);
}, 20);
if (!options.enableFx) options.enableFx = false;
if (!options.enableDrag) options.enableDrag = false;
if (options.resizeHandle === 'false') options.resizeHandle = false;
if (options.resizeContainer === 'false') options.resizeContainer = false;
var oid = $this.attr('data-oid');
if (oid != 'nothing_selected') {
vis.states.bind(oid + '.val', function (e, newVal, oldVal) {
var num = (parseFloat(newVal) > 0 || newVal === 'true' || newVal === true);
$this.prop('checked', num).trigger('change');
});
}
if (vis.editMode) {
if (options.test) $this.prop('checked', !$this.prop('checked')).trigger('change');
setTimeout(function () {
var id = $this.attr('id');
id = id.substring(0, id.length - '_checkbox'.length);
$('#' + id).find('.ibutton-container').css({'pointer-events': 'none'});
}, 100);
}
}
};
</script>
<script id="tplFancySwitch1"
type="text/ejs"
class="vis-tpl"
data-vis-prev='<div id="prev_tplFancySwitch1" style=" position: relative; text-align: initial;padding: 4px "><div class="vis-widget_prev" style="width: 104px; height: 40px; left: 179.5px; top: 46px; position: absolute;" > <div class="vis-widget-prev-body"> <fieldset class="fancy-switch" data-o style="background-image: url(widgets/fancyswitch/img/fancyswitch-1.png); background-position: 100% 50%; background-repeat: initial initial;"> <label class="fancy-off" style="text-indent: -10000px;">Off<input type="radio" class="fancy-on_off" name="w00004_on_off" value="0" style="display: none;"></label> <label class="fancy-on" style="text-indent: -10000px;">On<input type="radio" class="fancy-on_off" name="w00004_on_off" value="1" style="display: none;"></label> </fieldset> <div></div> </div> </div>'
data-vis-set="fancyswitch"
data-vis-type="ctrl - Bool"
data-vis-name="Switch light Off/On"
data-vis-attrs="oid;invert/checkbox;valFalse[0];valTrue[1];autoOff/slider,0,5000,100">
<div class="vis-widget <%== this.data.attr('class') %>" style="width:105px; height:46px;" id="<%= this.data.attr('wid') %>">
<div class="vis-widget-body">
<fieldset id="<%= this.data.attr('wid') %>_fancy" class="fancy-switch" data-oid="<%= this.data.attr('oid') %>">
<label class="fancy-off">Off<input type="radio" class="fancy-on_off" name="<%= this.data.attr('wid') %>_on_off" value="<%= (this.data.attr('valFalse') !== undefined) ? this.data.attr('valFalse') : 0 %>"/></label>
<label class="fancy-on">On<input type="radio" class="fancy-on_off" name="<%= this.data.attr('wid') %>_on_off" value="<%= (this.data.attr('valTrue') === '' || this.data.attr('valTrue') === null || this.data.attr('valTrue') === undefined) ? 1 : this.data.attr('valTrue') %>"/></label>
</fieldset>
<div <%= (el) -> vis.binds.fancyswitch.fancyswitch(el, {src: "widgets/fancyswitch/img/fancyswitch-1.png", invert: data.attr('invert'), valTrue: this.data.attr('valTrue'), valFalse: this.data.attr('valFalse'), autoOff: this.data.attr('autoOff')}) %>></div>
</div>
</div>
</script>
<script id="tplFancySwitch2"
type="text/ejs"
class="vis-tpl"
data-vis-prev='<div id="prev_tplFancySwitch2" style=" position: relative; text-align: initial;padding: 4px "><div class="vis-widget_prev ui-selectee" style="width: 105px; height: 46px; left: 408px; top: 404px;" > <div class="vis-widget-prev-body"> <fieldset class="fancy-switch" data-o style="background-image: url(widgets/fancyswitch/img/fancyswitch-2.png); background-position: 100% 50%; background-repeat: initial initial;"> <label class="fancy-off" style="text-indent: -10000px;">Off<input type="radio" class="fancy-on_off" name="w00005_on_off" value="0" style="display: none;"></label> <label class="fancy-on" style="text-indent: -10000px;">On<input type="radio" class="fancy-on_off" name="w00005_on_off" value="1" style="display: none;"></label> </fieldset> <div></div> </div> </div>'
data-vis-set="fancyswitch"
data-vis-type="ctrl - Bool"
data-vis-name="Slider dark Off/On"
data-vis-attrs="oid;invert/checkbox;valFalse[0];valTrue[1];autoOff/slider,0,5000,100">
<div class="vis-widget <%== this.data.attr('class') %>" style="width:105px; height:46px;" id="<%= this.data.attr('wid') %>">
<div class="vis-widget-body">
<fieldset id="<%= this.data.attr('wid') %>_fancy" class="fancy-switch" data-oid="<%= this.data.attr('oid') %>">
<label class="fancy-off">Off<input type="radio" class="fancy-on_off" name="<%= this.data.attr('wid') %>_on_off" value="<%= (this.data.attr('valFalse') !== undefined) ? this.data.attr('valFalse') : 0 %>"/></label>
<label class="fancy-on">On<input type="radio" class="fancy-on_off" name="<%= this.data.attr('wid') %>_on_off" value="<%= (this.data.attr('valTrue') === '' || this.data.attr('valTrue') === null || this.data.attr('valTrue') === undefined) ? 1 : this.data.attr('valTrue') %>"/></label>
</fieldset>
<div <%= (el) -> vis.binds.fancyswitch.fancyswitch(el, {src: "widgets/fancyswitch/img/fancyswitch-2.png", invert: data.attr('invert'), valTrue: this.data.attr('valTrue'), valFalse: this.data.attr('valFalse'), autoOff: this.data.attr('autoOff')}) %>></div>
</div>
</div>
</script>
<script id="tplFancyDarkAnAus"
type="text/ejs"
class="vis-tpl"
data-vis-prev='<div id="prev_tplFancyDarkAnAus" style=" position: relative; text-align: initial;padding: 4px "><div class="vis-widget_prev" style="width: 105px; height: 46px; left: 136px; top: 613px;" > <div class="vis-widget-prev-body"> <fieldset class="fancy-switch" data-o style="background-image: url(widgets/fancyswitch/img/fancyswitch-3.png); background-position: 100% 50%; background-repeat: initial initial;"> <label class="fancy-off" style="text-indent: -10000px;">Off<input type="radio" class="fancy-on_off" name="w00006_on_off" value="0" style="display: none;"></label> <label class="fancy-on" style="text-indent: -10000px;">On<input type="radio" class="fancy-on_off" name="w00006_on_off" value="1" style="display: none;"></label> </fieldset> <div></div> </div> </div>'
data-vis-set="fancyswitch"
data-vis-type="ctrl - Bool"
data-vis-name="Schieber dunkel Ein/Aus"
data-vis-attrs="oid;invert/checkbox;valFalse[0];valTrue[1];autoOff/slider,0,5000,100">
<div class="vis-widget <%== this.data.attr('class') %>" style="width:105px; height:46px;" id="<%= this.data.attr('wid') %>">
<div class="vis-widget-body">
<fieldset id="<%= this.data.attr('wid') %>_fancy" class="fancy-switch" data-oid="<%= this.data.attr('oid') %>">
<label class="fancy-off">Off<input type="radio" class="fancy-on_off" name="<%= this.data.attr('wid') %>_on_off" value="<%= (this.data.attr('valFalse') !== undefined) ? this.data.attr('valFalse') : 0 %>"/></label>
<label class="fancy-on">On<input type="radio" class="fancy-on_off" name="<%= this.data.attr('wid') %>_on_off" value="<%= (this.data.attr('valTrue') === '' || this.data.attr('valTrue') === null || this.data.attr('valTrue') === undefined) ? 1 : this.data.attr('valTrue') %>"/></label>
</fieldset>
<div <%= (el) -> vis.binds.fancyswitch.fancyswitch(el, {src: "widgets/fancyswitch/img/fancyswitch-3.png", invert: data.attr('invert'), valTrue: this.data.attr('valTrue'), valFalse: this.data.attr('valFalse'), autoOff: this.data.attr('autoOff')}) %>></div>
</div>
</div>
</script>
<script id="tplFancyDarkAnAusRev"
type="text/ejs"
class="vis-tpl"
data-vis-prev='<div id="prev_tplFancyDarkAnAusRev" style=" position: relative; text-align: initial;padding: 4px "><div class="vis-widget_prev" style="width: 105px; height: 46px; left: 278px; top: 527px;" > <div class="vis-widget-prev-body"> <fieldset class="fancy-switch" data-o style="background-image: url(widgets/fancyswitch/img/fancyswitch-4.png); background-position: 100% 50%; background-repeat: initial initial;"> <label class="fancy-off" style="text-indent: -10000px;">Off<input type="radio" class="fancy-on_off" name="w00007_on_off" value="0" style="display: none;"></label> <label class="fancy-on" style="text-indent: -10000px;">On<input type="radio" class="fancy-on_off" name="w00007_on_off" value="1" style="display: none;"></label> </fieldset> <div></div> </div> </div>'
data-vis-set="fancyswitch"
data-vis-type="ctrl - Bool"
data-vis-name="Schieber dunkel Aus/Ein"
data-vis-attrs="oid;invert/checkbox;valFalse[0];valTrue[1];autoOff/slider,0,5000,100">
<div class="vis-widget <%== this.data.attr('class') %>" style="width:105px; height:46px;" id="<%= this.data.attr('wid') %>">
<div class="vis-widget-body">
<fieldset id="<%= this.data.attr('wid') %>_fancy" class="fancy-switch" data-oid="<%= this.data.attr('oid') %>">
<label class="fancy-off">Off<input type="radio" class="fancy-on_off" name="<%= this.data.attr('wid') %>_on_off" value="<%= (this.data.attr('valFalse') !== undefined) ? this.data.attr('valFalse') : 0 %>"/></label>
<label class="fancy-on">On<input type="radio" class="fancy-on_off" name="<%= this.data.attr('wid') %>_on_off" value="<%= (this.data.attr('valTrue') === '' || this.data.attr('valTrue') === null || this.data.attr('valTrue') === undefined) ? 1 : this.data.attr('valTrue') %>"/></label>
</fieldset>
<div <%= (el) -> vis.binds.fancyswitch.fancyswitch(el, {src: "widgets/fancyswitch/img/fancyswitch-4.png", invert: data.attr('invert'), valTrue: this.data.attr('valTrue'), valFalse: this.data.attr('valFalse'), autoOff: this.data.attr('autoOff')}) %>></div>
</div>
</div>
</script>
<script id="tplFancyDarkAnAusWippe"
type="text/ejs"
class="vis-tpl"
data-vis-prev='<div id="prev_tplFancyDarkAnAusWippe" style=" position: relative; text-align: initial;padding: 4px "><div class="vis-widget_prev ui-selectee" style="width: 102px; height: 49px; left: 73px; top: 232px; position: absolute;" > <div class="vis-widget-prev-body"> <fieldset class="fancy-switch" data-o style="background-image: url(widgets/fancyswitch/img/fancyswitch-5.png); background-position: 100% 50%; background-repeat: initial initial;"> <label class="fancy-off" style="text-indent: -10000px;">Off<input type="radio" class="fancy-on_off" name="w00002_on_off" value="0" style="display: none;"></label> <label class="fancy-on" style="text-indent: -10000px;">On<input type="radio" class="fancy-on_off" name="w00002_on_off" value="1" style="display: none;"></label> </fieldset> <div></div> </div> </div>'
data-vis-set="fancyswitch"
data-vis-type="ctrl - Bool"
data-vis-name="Wippe dunkel Aus/Ein"
data-vis-attrs="oid;invert/checkbox;valFalse[0];valTrue[1];autoOff/slider,0,5000,100;lightStyle/checkbox">
<div class="vis-widget <%== this.data.attr('class') %>" style="width:105px; height:46px;" id="<%= this.data.attr('wid') %>">
<div class="vis-widget-body">
<fieldset id="<%= this.data.attr('wid') %>_fancy" class="fancy-switch" data-oid="<%= this.data.attr('oid') %>">
<label class="fancy-off">Off<input type="radio" class="fancy-on_off" name="<%= this.data.attr('wid') %>_on_off" value="<%= (this.data.attr('valFalse') !== undefined) ? this.data.attr('valFalse') : 0 %>"/></label>
<label class="fancy-on">On<input type="radio" class="fancy-on_off" name="<%= this.data.attr('wid') %>_on_off" value="<%= (this.data.attr('valTrue') === '' || this.data.attr('valTrue') === null || this.data.attr('valTrue') === undefined) ? 1 : this.data.attr('valTrue') %>"/></label>
</fieldset>
<div <%= (el) -> vis.binds.fancyswitch.fancyswitch(el, {src: data.attr('lightStyle') ? "widgets/fancyswitch/img/fancyswitch-6.png" : "widgets/fancyswitch/img/fancyswitch-5.png", invert: data.attr('invert'), valTrue: this.data.attr('valTrue'), valFalse: this.data.attr('valFalse'), autoOff: this.data.attr('autoOff')}) %>></div>
</div>
</div>
</script>
<script id="tplFancyGivaIButton"
type="text/ejs"
class="vis-tpl"
data-vis-prev='<div id="prev_tplFancyGivaIButton" style=" position: relative; text-align: initial;padding: 4px "><div class="vis-widget_prev ui-selectee" style="top: 514px; left: 186px;" > <div class="vis-widget-prev-body"> <div class="ibutton-container" style="pointer-events: none;"><input type="checkbox" name="w00004_checkbox" data-o value="1"><div class="ibutton-handle" style="left: 0px;"><div class="ibutton-handle-right"><div class="ibutton-handle-middle"></div></div></div><div class="ibutton-label-off"><span style="margin-right: 0px;"><label>OFF</label></span></div><div class="ibutton-label-on" style="width: 4px;"><span style="margin-left: -50px;"><label>ON</label></span></div><div class="ibutton-padding-left"></div><div class="ibutton-padding-right"></div></div> </div> </div>'
data-vis-set="fancyswitch"
data-vis-type="ctrl - Bool"
data-vis-name="Giva Labs iButton"
data-vis-attrs="oid;labelOn[ON];labelOff[OFF];resizeHandle[auto]/select,auto,true,false;resizeContainer[auto]/select,auto,true,false;enableDrag/checkbox;enableFx/checkbox;duration[200]/slider,0,5000,100;test/checkbox">
<div class="vis-widget <%== this.data.attr('class') %>" style="top:0px; left:0px;" id="<%= this.data.attr('wid') %>" >
<div class="vis-widget-body">
<input type="checkbox" name="<%= this.data.attr('wid') %>_checkbox"
id="<%= this.data.attr('wid') %>_checkbox"
data-oid="<%= this.data.attr('oid') %>"
value="1"
<%= (el) -> vis.binds.basic.checkbox(el); vis.binds.fancyswitch.iButton(el, {duration: data.attr('duration'), labelOn: data.attr('labelOn'), labelOff: data.attr('labelOff'), resizeHandle: data.attr('resizeHandle'), resizeContainer: data.attr('resizeContainer'), enableDrag: data.attr('enableDrag'), enableFx: data.attr('enableFx'), test: data.attr('test')}); %>/>
</div>
</div>
</script>
<script id="tplFancyToggleswitch"
type="text/ejs"
data-vis-prev='<div id="prev_tplFancyToggleswitch" style=" position: relative; text-align: initial;padding: 4px "><div class="vis-widget_prev ui-selectee" style="padding-left: 10px; left: 109px; top: 604px; position: absolute; height: 62px; width: 45px;" > <div class="vis-widget-prev-body" style="padding-top:5px; text-align: center"> <select data-oid="" class="ui-toggle-switch" style="display: none; pointer-events: none;"> <option value="0">OFF</option> <option value="1">ON</option> </select> <div></div> <div class="ui-toggle-switch" style="pointer-events: none;"><label style="border: 0px" class="ui-state-active">OFF</label><div class="ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all" aria-disabled="false" style="width: 40px;"><div class="ui-slider-range ui-widget-header ui-corner-all ui-slider-range-max" style="width: 100%;"></div><a class="ui-slider-handle ui-state-default ui-corner-all" href="#" style="left: 0%;"></a></div><label style="border: 0px">ON</label></div></div> </div>'
class="vis-tpl"
data-vis-set="fancyswitch"
data-vis-type="ctrl - Bool"
data-vis-name="Taitem jqui Toggleswitch"
data-vis-attrs="html_prepend;html_append;oid;text_true[ON];text_false[OFF];highlight_switch/checkbox;width[40]/slider,10,500,1;test/checkbox">
<div class="vis-widget <%== this.data.attr('class') %>" style="padding-left:10px;" id="<%= this.data.attr('wid') %>" >
<div class="vis-widget-body" style="padding-top:5px; text-align: center">
<%== this.data.attr("html_prepend") %>
<select id="<%= this.data.attr('wid') %>_select" data-oid="<%= (this.data.attr('oid') == 'nothing_selected' ? '' : this.data.attr('oid')) %>">
<option value="0"><%= this.data.attr('text_false') %></option>
<option value="1"><%= this.data.attr('text_true') %></option>
</select>
<div <%= (el) -> vis.binds.basic.select(el); vis.binds.fancyswitch.toggleSwitch(el, {highlight: data.attr('highlight_switch'), width: data.attr('width'), test: data.attr('test')}); %>></div>
<%== this.data.attr("html_append") %>
</div>
</div>
</script>

View File

@ -0,0 +1,197 @@
.ibutton-container {
position: relative;
height: 27px;
cursor: pointer;
overflow: hidden;
/* set max width to that of sprite */
max-width: 400px;
/* prevent text selection */
-khtml-user-select: none;
-o-user-select: none;
-moz-user-select: none;
-moz-user-focus: ignore;
-moz-user-input: disabled;
/* set default width based on ON/OFF labels */
width: 89px;
}
.ibutton-container input {
position: absolute;
top: 0;
left: 0;
/* hide the element */
filter:alpha(opacity=0);
-moz-opacity: 0.0;
opacity: 0.0;
/* allow checking of input if visible */
-moz-user-input: enabled !important;
}
.ibutton-handle {
display: block;
height: 27px;
cursor: inherit;
position: absolute;
top: 0;
left: 0;
width: 0;
background: transparent url(../img/ibutton-slider-default.png) no-repeat scroll 0 -54px;
z-index: 3;
padding-left: 3px;
/* set default width based on ON/OFF labels */
width: 33px;
}
.ibutton-handle-right {
height: 100%;
width: 100%;
padding-right: 3px;
background: transparent url(../img/ibutton-slider-default.png) no-repeat scroll 100% -54px;
z-index: 3;
}
.ibutton-handle-middle {
height: 100%;
width: 100%;
background: transparent url(../img/ibutton-slider-default.png) no-repeat scroll 50% -54px;
z-index: 3;
}
div.ibutton-label-on, div.ibutton-label-off {
white-space: nowrap;
font-size: 17px;
line-height: 17px;
font-weight: bold;
font-family: Helvetica Neue, Arial, Helvetica, sans-serif;
text-transform: uppercase;
cursor: inherit;
display: block;
height: 22px;
position: absolute;
width: auto;
top: 0;
padding-top: 5px;
overflow: hidden;
background: transparent url(../img/ibutton-slider-default.png) no-repeat scroll 0 0;
}
div.ibutton-label-on {
color: #fff;
text-shadow: 0 -1px 2px rgba(0, 0, 0, 0.4);
left: 0;
padding-top: 5px;
z-index: 1;
}
div.ibutton-label-on span {
padding-left: 5px;
}
div.ibutton-label-off {
color: #7c7c7c;
background-position: 100% 0;
text-shadow: 0 -1px 2px rgba(153, 153, 153, 0.4);
text-align: right;
right: 0;
/* the off label needs to near the left edge (ideally just 5px away)
* it just needs to be close enough that it won't show under the handle if dragged to the left
*/
width: 95%;
}
div.ibutton-label-off span {
padding-right: 5px;
}
/* create an outline when button gets focus via keyboard */
.ibutton-container label {
cursor: inherit;
padding: 1px 3px;
font-size: 1em !important;
}
.ibutton-focus label {
/* we must use border, since outline doesn't work in IE */
border: 1px dotted #666 !important;
padding: 0 2px;
}
.ibutton-focus div.ibutton-label-on span label {
/* use white for more contrast */
border-color: #fff !important;
}
/* add padding to right/left so that text gets clipped before absolute edge */
.ibutton-padding-left, .ibutton-padding-right {
position: absolute;
top: 4px;
z-index: 2;
background: transparent url(../img/ibutton-slider-default.png) no-repeat scroll 0 -4px;
width: 3px;
height: 20px;
}
.ibutton-padding-left {
left: 0;
}
.ibutton-padding-right {
right: 0;
background-position: 100% -4px;
}
/* change the styles of the handle when being dragged */
.ibutton-active-handle .ibutton-handle {
background-position: 0 -108px;
}
.ibutton-active-handle .ibutton-handle-right {
background-position: 100% -108px;
}
.ibutton-active-handle .ibutton-handle-middle {
background-position: 50% -108px;
}
/* styles to use when the button is disabled */
.ibutton-disabled {
cursor: not-allowed !important; /* cursor options: default or not-allowed */
}
.ibutton-disabled .ibutton-handle {
background-position: 0 -81px;
}
.ibutton-disabled .ibutton-handle-right {
background-position: 100% -81px;
}
.ibutton-disabled .ibutton-handle-middle {
background-position: 50% -81px;
}
.ibutton-disabled div.ibutton-label-on {
background-position: 0 -27px;
}
.ibutton-disabled div.ibutton-label-off {
background-position: 100% -27px;
}
.ibutton-disabled .ibutton-padding-left {
background-position: 0 -27px;
}
.ibutton-disabled .ibutton-padding-right {
background-position: 100% -27px;
}
.ibutton-disabled div.ibutton-label-on {
color: #fff;
}
.ibutton-disabled div.ibutton-label-off {
color: #cbcbcb;
}

View File

@ -0,0 +1 @@
.ibutton-container{position:relative;height:27px;cursor:pointer;overflow:hidden;max-width:400px;-khtml-user-select:none;-o-user-select:none;-moz-user-select:none;-moz-user-focus:ignore;-moz-user-input:disabled;width:89px;}.ibutton-container input{position:absolute;top:0;left:0;filter:alpha(opacity=0);-moz-opacity:.0;opacity:.0;-moz-user-input:enabled!important;}.ibutton-handle{display:block;height:27px;cursor:inherit;position:absolute;top:0;left:0;width:0;background:transparent url(../img/ibutton-slider-default.png) no-repeat scroll 0 -54px;z-index:3;padding-left:3px;width:33px;}.ibutton-handle-right{height:100%;width:100%;padding-right:3px;background:transparent url(../img/ibutton-slider-default.png) no-repeat scroll 100% -54px;z-index:3;}.ibutton-handle-middle{height:100%;width:100%;background:transparent url(../img/ibutton-slider-default.png) no-repeat scroll 50% -54px;z-index:3;}div.ibutton-label-on,div.ibutton-label-off{white-space:nowrap;font-size:17px;line-height:17px;font-weight:bold;font-family:Helvetica Neue,Arial,Helvetica,sans-serif;text-transform:uppercase;cursor:inherit;display:block;height:22px;position:absolute;width:auto;top:0;padding-top:5px;overflow:hidden;background:transparent url(../img/ibutton-slider-default.png) no-repeat scroll 0 0;}div.ibutton-label-on{color:#fff;text-shadow:0 -1px 2px rgba(0,0,0,0.4);left:0;padding-top:5px;z-index:1;}div.ibutton-label-on span{padding-left:5px;}div.ibutton-label-off{color:#7c7c7c;background-position:100% 0;text-shadow:0 -1px 2px rgba(153,153,153,0.4);text-align:right;right:0;width:95%;}div.ibutton-label-off span{padding-right:5px;}.ibutton-container label{cursor:inherit;padding:1px 3px;font-size:1em!important;}.ibutton-focus label{border:1px dotted #666!important;padding:0 2px;}.ibutton-focus div.ibutton-label-on span label{border-color:#fff!important;}.ibutton-padding-left,.ibutton-padding-right{position:absolute;top:4px;z-index:2;background:transparent url(../img/ibutton-slider-default.png) no-repeat scroll 0 -4px;width:3px;height:20px;}.ibutton-padding-left{left:0;}.ibutton-padding-right{right:0;background-position:100% -4px;}.ibutton-active-handle .ibutton-handle{background-position:0 -108px;}.ibutton-active-handle .ibutton-handle-right{background-position:100% -108px;}.ibutton-active-handle .ibutton-handle-middle{background-position:50% -108px;}.ibutton-disabled{cursor:not-allowed!important;}.ibutton-disabled .ibutton-handle{background-position:0 -81px;}.ibutton-disabled .ibutton-handle-right{background-position:100% -81px;}.ibutton-disabled .ibutton-handle-middle{background-position:50% -81px;}.ibutton-disabled div.ibutton-label-on{background-position:0 -27px;}.ibutton-disabled div.ibutton-label-off{background-position:100% -27px;}.ibutton-disabled .ibutton-padding-left{background-position:0 -27px;}.ibutton-disabled .ibutton-padding-right{background-position:100% -27px;}.ibutton-disabled div.ibutton-label-on{color:#fff;}.ibutton-disabled div.ibutton-label-off{color:#cbcbcb;}

View File

@ -0,0 +1,92 @@
<html>
<head>
<link rel="stylesheet" href="../../css/doc.css" />
<title>Dokumentation Widget-Set "fancyswitch"</title>
</head>
<body>
<h3><a name="tplFancySwitch1">hm_ctrl - Bool - Wippe hell Off/On</a></h3>
<img src="doc/tplFancyswitch1.png"/>
<hr/>
<h3><a name="tplFancySwitch2">hm_ctrl - Bool - Schieber dunkel Off/On</a></h3>
<img src="doc/tplFancyswitch2.png"/>
<hr/>
<h3><a name="tplFancyDarkAnAus">hm_ctrl - Bool - Schieber dunkel Ein/Aus</a></h3>
<hr/>
<h3><a name="tplFancyDarkAnAusRev">hm_ctrl - Bool - Schieber dunkel Aus/Ein</a></h3>
<hr/>
<h3><a name="tplFancyDarkAnAusWippe">hm_ctrl - Bool - Wippe dunkel Aus/Ein</a></h3>
<img src="doc/tplFancyDarkAnAusWippe.png"/>
<hr/>
<h3><a name="tplFancyGivaIButton">hm_ctrl - Bool - Giva Labs iButton</a></h3>
<img src="doc/tplFancyGivaIButton.png"/><br/><br/>
<a href="http://www.givainc.com/labs/ibutton_jquery_plugin.htm" target="_blank">siehe auch Giva Labs iButton Homepage</a>
<h4>Attribute</h4>
<dl>
<dt>duration</dt>
<dd></dd>
<dt>labelOn</dt>
<dd></dd>
<dt>labelOff</dt>
<dd></dd>
<dt>resizeHandle</dt>
<dd></dd>
<dt>resizeContainer</dt>
<dd></dd>
<dt>enableDrag</dt>
<dd></dd>
<dt>enableFx</dt>
<dd></dd>
</dl>
<hr/>
<h3><a name="tplFancyToggleswitch">hm_ctrl - Bool - Taitem jqui Toggleswitch</a></h3>
sieht nur im Theme Kiandra wirklich gut aus.
<h4>Attribute</h4>
<dl>
<dt></dt>
<dd></dd>
</dl>
<hr/>
<h3><a name=""></a></h3>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,77 @@
jQuery.fn.toggleSwitch = function (params) {
var defaults = {
highlight: true,
width: 25,
change: null
};
var options = $.extend({}, defaults, params);
$(this).each(function (i, item) {
generateToggle(item);
});
function generateToggle(selectObj) {
// create containing element
var $contain = $("<div />").addClass("ui-toggle-switch");
// generate labels
$(selectObj).find("option").each(function (i, item) {
$contain.append("<label style='border: 0px'>" + $(item).text() + "</label>");
}).end().addClass("ui-toggle-switch");
// generate slider with established options
var $slider = $("<div />").slider({
min: 0,
max: 100,
animate: "fast",
change: options.change,
stop: function (e, ui) {
var roundedVal = Math.round(ui.value / 100);
var self = this;
window.setTimeout(function () {
toggleValue(self.parentNode, roundedVal);
}, 11);
},
range: (options.highlight && !$(selectObj).data("hideHighlight")) ? "max" : null
}).width(options.width);
// put slider in the middle
$slider.insertAfter(
$contain.children().eq(0)
);
// bind interaction
$contain.delegate("label", "click", function () {
if ($(this).hasClass("ui-state-active")) {
return;
}
var labelIndex = ($(this).is(":first-child")) ? 0 : 1;
toggleValue(this.parentNode, labelIndex);
});
$(selectObj).change(function () {
var cur = $(selectObj).find("option:selected").val();
var val = $contain.find(".ui-slider").slider("value");
if ((cur * 100) != val) {
$contain.find("label").eq(cur).addClass("ui-state-active").siblings("label").removeClass("ui-state-active");
$contain.find(".ui-slider").slider("value", cur * 100);
}
});
function toggleValue(slideContain, index) {
$(slideContain).find("label").eq(index).addClass("ui-state-active").siblings("label").removeClass("ui-state-active");
$(selectObj).find("option[value='"+index+"']").prop("selected", true);
$(selectObj).trigger("change");
$(slideContain).find(".ui-slider").slider("value", index * 100);
}
// initialise selected option
$contain.find("label").eq(selectObj.selectedIndex).click();
// add to DOM
$(selectObj).hide().parent().append($contain);
}
};

View File

@ -0,0 +1,386 @@
/*!
* iButton jQuery Plug-in
*
* Copyright 2011 Giva, Inc. (http://www.givainc.com/labs/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Date: 2011-07-26
* Rev: 1.0.03
*/
;(function($){
// set default options
$.iButton = {
version: "1.0.03-hq1",
setDefaults: function(options){
$.extend(defaults, options);
}
};
$.fn.iButton = function(options) {
var method = typeof arguments[0] == "string" && arguments[0];
var args = method && Array.prototype.slice.call(arguments, 1) || arguments;
// get a reference to the first iButton found
var self = (this.length == 0) ? null : $.data(this[0], "iButton");
// if a method is supplied, execute it for non-empty results
if( self && method && this.length ){
// if request a copy of the object, return it
if( method.toLowerCase() == "object" ) return self;
// if method is defined, run it and return either it's results or the chain
else if( self[method] ){
// define a result variable to return to the jQuery chain
var result;
this.each(function (i){
// apply the method to the current element
var r = $.data(this, "iButton")[method].apply(self, args);
// if first iteration we need to check if we're done processing or need to add it to the jquery chain
if( i == 0 && r ){
// if this is a jQuery item, we need to store them in a collection
if( !!r.jquery ){
result = $([]).add(r);
// otherwise, just store the result and stop executing
} else {
result = r;
// since we're a non-jQuery item, just cancel processing further items
return false;
}
// keep adding jQuery objects to the results
} else if( !!r && !!r.jquery ){
result = result.add(r);
}
});
// return either the results (which could be a jQuery object) or the original chain
return result || this;
// everything else, return the chain
} else return this;
// initializing request (only do if iButton not already initialized)
} else {
// create a new iButton for each object found
return this.each(function (){
new iButton(this, options);
});
};
};
// count instances
var counter = 0;
var iButton = function (input, options){
var self = this
, $input = $(input)
, id = ++counter
, disabled = false
, width = {}
, mouse = {dragging: false, clicked: null}
, dragStart = {position: null, offset: null, time: null }
// make a copy of the options and use the metadata if provided
, options = $.extend({}, defaults, options, (!!$.metadata ? $input.metadata() : {}))
// check to see if we're using the default labels
, bDefaultLabelsUsed = (options.labelOn == ON && options.labelOff == OFF)
// set valid field types
, allow = ":checkbox, :radio";
//console.log("iButton options");
//console.log(options);
// only do for checkboxes buttons, if matches inside that node
if( !$input.is(allow) ) return $input.find(allow).iButton(options);
// if iButton already exists, stop processing
else if($.data($input[0], "iButton") ) return;
// store a reference to this marquee
$.data($input[0], "iButton", self);
// if using the "auto" setting, then don't resize handle or container if using the default label (since we'll trust the CSS)
if( options.resizeHandle == "auto" ) options.resizeHandle = !bDefaultLabelsUsed;
if( options.resizeContainer == "auto" ) options.resizeContainer = !bDefaultLabelsUsed;
// toggles the state of a button (or can turn on/off)
this.toggle = function (t){
//console.log("toggle input.checked="+$input[0].checked);
var toggle = (arguments.length > 0) ? t : !$input[0].checked;
if (toggle) {
$input.prop("checked", true).trigger("change");
} else {
$input.removeAttr("checked").trigger("change");
}
};
// disable/enable the control
this.disable = function (t){
var toggle = (arguments.length > 0) ? t : !disabled;
// mark the control disabled
disabled = toggle;
// mark the input disabled
$input.attr("disabled", toggle);
// set the diabled styles
$container[toggle ? "addClass" : "removeClass"](options.classDisabled);
// run callback
if( $.isFunction(options.disable) ) options.disable.apply(self, [disabled, $input, options]);
};
// repaint the button
this.repaint = function (){
positionHandle();
};
// this will destroy the iButton style
this.destroy = function (){
// remove behaviors
$([$input[0], $container[0]]).unbind(".iButton");
$(document).unbind(".iButton_" + id);
// move the checkbox to it's original location
$container.after($input).remove();
// kill the reference
$.data($input[0], "iButton", null);
// run callback
if( $.isFunction(options.destroy) ) options.destroy.apply(self, [$input, options]);
};
//console.log("LABEL ON "+options.labelOn);
$input
// create the wrapper code
.wrap('<div class="' + $.trim(options.classContainer + ' ' + options.className) + '" />')
.after(
'<div class="' + options.classHandle + '"><div class="' + options.classHandleRight + '"><div class="' + options.classHandleMiddle + '" /></div></div>'
+ '<div class="' + options.classLabelOff + '"><span><label>'+ options.labelOff + '</label></span></div>'
+ '<div class="' + options.classLabelOn + '"><span><label>' + options.labelOn + '</label></span></div>'
+ '<div class="' + options.classPaddingLeft + '"></div><div class="' + options.classPaddingRight + '"></div>'
);
var $container = $input.parent()
, $handle = $input.siblings("." + options.classHandle)
, $offlabel = $input.siblings("." + options.classLabelOff)
, $offspan = $offlabel.children("span")
, $onlabel = $input.siblings("." + options.classLabelOn)
, $onspan = $onlabel.children("span");
// if we need to do some resizing, get the widths only once
if( options.resizeHandle || options.resizeContainer ){
width.onspan = $onspan.outerWidth();
width.offspan = $offspan.outerWidth();
}
// automatically resize the handle
if( options.resizeHandle ){
width.handle = Math.min(width.onspan, width.offspan);
$handle.css("width", width.handle);
} else {
width.handle = $handle.width();
}
// automatically resize the control
if( options.resizeContainer ){
width.container = (Math.max(width.onspan, width.offspan) + width.handle + 20);
$container.css("width", width.container);
// adjust the off label to match the new container size
$offlabel.css("width", width.container - 5);
} else {
width.container = $container.width();
//console.log("width.container="+width.container);
}
var handleRight = width.container - width.handle - 6;
var positionHandle = function (animate){
//console.log("positionHandle()");
//console.log("handleRight="+handleRight);
var checked = $input[0].checked
, x = (checked) ? handleRight : 0
, animate = (arguments.length > 0) ? arguments[0] : true;
//console.log(options.enableFx);
if( animate && options.enableFx ){
$handle.stop().animate({left: x}, options.duration, options.easing);
$onlabel.stop().animate({width: x + 4}, options.duration, options.easing);
$onspan.stop().animate({marginLeft: x - handleRight}, options.duration, options.easing);
$offspan.stop().animate({marginRight: -x}, options.duration, options.easing);
} else {
$handle.css("left", x);
$onlabel.css("width", x + 4);
$onspan.css("marginLeft", x - handleRight);
$offspan.css("marginRight", -x);
}
};
// place the buttons in their default location
positionHandle(false);
var getDragPos = function(e){
return e.pageX || ((e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : 0);
};
// monitor mouse clicks in the container
$container.bind("mousedown.iButton touchstart.iButton", function(e) {
// abort if disabled or allow clicking the input to toggle the status (if input is visible)
if( $(e.target).is(allow) || disabled || (!options.allowRadioUncheck && $input.is(":radio:checked")) ) return;
e.preventDefault();
mouse.clicked = $handle;
dragStart.position = getDragPos(e);
dragStart.offset = dragStart.position - (parseInt($handle.css("left"), 10) || 0);
dragStart.time = (new Date()).getTime();
return false;
});
// make sure dragging support is enabled
if( options.enableDrag ){
// monitor mouse movement on the page
$(document).bind("mousemove.iButton_" + id + " touchmove.iButton_" + id, function(e) {
// if we haven't clicked on the container, cancel event
if( mouse.clicked != $handle ){ return }
e.preventDefault();
var x = getDragPos(e);
if( x != dragStart.offset ){
mouse.dragging = true;
$container.addClass(options.classHandleActive);
}
// make sure number is between 0 and 1
var pct = Math.min(1, Math.max(0, (x - dragStart.offset) / handleRight));
$handle.css("left", pct * handleRight);
$onlabel.css("width", pct * handleRight + 4);
$offspan.css("marginRight", -pct * handleRight);
$onspan.css("marginLeft", -(1 - pct) * handleRight);
return false;
});
}
// monitor when the mouse button is released
$(document).bind("mouseup.iButton_" + id + " touchend.iButton_" + id, function(e) {
if( mouse.clicked != $handle ){ return }
e.preventDefault();
// track if the value has changed
var changed = true;
// if not dragging or click time under a certain millisecond, then just toggle
if( !mouse.dragging || (((new Date()).getTime() - dragStart.time) < options.clickOffset ) ){
var checked = $input[0].checked;
$input.prop("checked", !checked);
// run callback
if( $.isFunction(options.click) ) options.click.apply(self, [!checked, $input, options]);
} else {
var x = getDragPos(e);
var pct = (x - dragStart.offset) / handleRight;
var checked = (pct >= 0.5);
// if the value is the same, don't run change event
if( $input[0].checked == checked ) changed = false;
$input.prop("checked", checked);
}
// remove the active handler class
$container.removeClass(options.classHandleActive);
mouse.clicked = null;
mouse.dragging = null;
// run any change event for the element
if( changed ) $input.trigger("change");
// if the value didn't change, just reset the handle
else positionHandle();
return false;
});
// animate when we get a change event
$input
.bind("change.iButton", function (){
// move handle
positionHandle();
// if a radio element, then we must repaint the other elements in it's group to show them as not selected
if( $input.is(":radio") ){
var el = $input[0];
// try to use the DOM to get the grouped elements, but if not in a form get by name attr
var $radio = $(el.form ? el.form[el.name] : ":radio[name=" + el.name + "]");
// repaint the radio elements that are not checked
$radio.filter(":not(:checked)").iButton("repaint");
}
// run callback
if( $.isFunction(options.change) ) options.change.apply(self, [$input, options]);
})
// if the element has focus, we need to highlight the container
.bind("focus.iButton", function (){
$container.addClass(options.classFocus);
})
// if the element has focus, we need to highlight the container
.bind("blur.iButton", function (){
$container.removeClass(options.classFocus);
});
// if a click event is registered, we must register on the checkbox so it's fired if triggered on the checkbox itself
if( $.isFunction(options.click) ){
$input.bind("click.iButton", function (){
options.click.apply(self, [$input[0].checked, $input, options]);
});
}
// if the field is disabled, mark it as such
if( $input.is(":disabled") ) this.disable(true);
// run the init callback
if( $.isFunction(options.init) ) options.init.apply(self, [$input, options]);
};
var defaults = {
duration: 200 // the speed of the animation
, easing: "swing" // the easing animation to use
, labelOn: "ON" // the text to show when toggled on
, labelOff: "OFF" // the text to show when toggled off
, resizeHandle: "auto" // determines if handle should be resized
, resizeContainer: "auto" // determines if container should be resized
, enableDrag: true // determines if we allow dragging
, enableFx: true // determines if we show animation
, allowRadioUncheck: true // determine if a radio button should be able to be unchecked
, clickOffset: 120 // if millseconds between a mousedown & mouseup event this value, then considered a mouse click
// define the class statements
, className: ""
, classContainer: "ibutton-container"
, classDisabled: "ibutton-disabled"
, classFocus: "ibutton-focus"
, classLabelOn: "ibutton-label-on"
, classLabelOff: "ibutton-label-off"
, classHandle: "ibutton-handle"
, classHandleMiddle: "ibutton-handle-middle"
, classHandleRight: "ibutton-handle-right"
, classHandleActive: "ibutton-active-handle"
, classPaddingLeft: "ibutton-padding-left"
, classPaddingRight: "ibutton-padding-right"
// event handlers
, init: null // callback that occurs when a iButton is initialized
, change: null // callback that occurs when the button state is changed
, click: null // callback that occurs when the button is clicked
, disable: null // callback that occurs when the button is disabled/enabled
, destroy: null // callback that occurs when the button is destroyed
}, ON = defaults.labelOn, OFF = defaults.labelOff;
})(jQuery);