remove ungit plugin
This commit is contained in:
parent
f6e3d3fe07
commit
15fa3818e7
@ -1,138 +0,0 @@
|
||||
<?xml version='1.0' standalone='yes'?>
|
||||
|
||||
<!DOCTYPE PLUGIN [
|
||||
<!ENTITY name "ungit">
|
||||
<!ENTITY author "dmacias72">
|
||||
<!ENTITY version "2016.11.06">
|
||||
<!ENTITY launch "Settings/UnGit">
|
||||
<!ENTITY gitURL "https://raw.githubusercontent.com/&author;/unRAID-plugins/master">
|
||||
<!ENTITY pluginURL "&gitURL;/plugins/&name;.plg">
|
||||
<!ENTITY pkgURL "&gitURL;/source/packages">
|
||||
<!ENTITY plgPATH "/boot/config/plugins/&name;">
|
||||
<!ENTITY pkgNAME "&name;-&version;-x86_64-1">
|
||||
<!ENTITY emhttp "/usr/local/emhttp/plugins/&name;">
|
||||
]>
|
||||
|
||||
<PLUGIN name="&name;" author="&author;" launch="&launch;" version="&version;" pluginURL="&pluginURL;">
|
||||
|
||||
<!--
|
||||
This Plugin installs libvirt wake on lan for unRaid 6.1 All dependencies are installed as needed and is controlable from the webgui.
|
||||
-->
|
||||
|
||||
<CHANGES>
|
||||
##&name;
|
||||
###&version;
|
||||
- initial commit
|
||||
</CHANGES>
|
||||
|
||||
<FILE Name="&plgPATH;/nodejs-4.6.0-x86_64-1_slonly.txz" Min="6.2" Run="upgradepkg --install-new">
|
||||
<URL>&gitURL;/packages/6.2/nodejs-4.6.0-x86_64-1_slonly.txz</URL>
|
||||
<MD5>8a7dae6947e415f2dd01bf4d2a57b6f4</MD5>
|
||||
</FILE>
|
||||
|
||||
<FILE Name="&plgPATH;/nodejs-4.2.4-x86_64-1_slack.txz" Min="6.1" Max="6.1.99" Run="upgradepkg --install-new">
|
||||
<URL>&gitURL;/packages/6.1/nodejs-4.2.4-x86_64-1_slack.txz</URL>
|
||||
<MD5>7c17ad5a7aab095c9dbfe54051772ded</MD5>
|
||||
</FILE>
|
||||
|
||||
<FILE Name="&plgPATH;/&name;.cfg">
|
||||
<INLINE>
|
||||
<![CDATA[
|
||||
DAEMON="disable"
|
||||
PORT="8448"
|
||||
]]>
|
||||
</INLINE>
|
||||
</FILE>
|
||||
|
||||
<!--
|
||||
The 'plugin' package file.
|
||||
-->
|
||||
<FILE Name="&plgPATH;/&pkgNAME;.txz">
|
||||
<URL>&gitURL;/archive/&pkgNAME;.txz</URL>
|
||||
</FILE>
|
||||
|
||||
<!--
|
||||
The 'plugin' package MD5 hash.
|
||||
-->
|
||||
<FILE Name="&plgPATH;/&pkgNAME;.md5">
|
||||
<URL>&gitURL;/archive/&pkgNAME;.md5</URL>
|
||||
</FILE>
|
||||
|
||||
<!--
|
||||
The 'install' script.
|
||||
-->
|
||||
<FILE Run="/bin/bash">
|
||||
<INLINE>
|
||||
#Verify unRAID Version
|
||||
source /etc/unraid-version
|
||||
VER=${version:0:3}
|
||||
|
||||
if [[ $VER == 6.0 ]]; then
|
||||
echo "unRAID version 6.1 or higher is required"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify and install plugin package
|
||||
sum1=$(/usr/bin/md5sum &plgPATH;/&pkgNAME;.txz)
|
||||
sum2=$(/usr/bin/cat &plgPATH;/&pkgNAME;.md5)
|
||||
if [ "${sum1:0:32}" != "${sum2:0:32}" ]; then
|
||||
echo "Wrong 'plugin' package md5 hash."
|
||||
rm &plgPATH;/&pkgNAME;.txz
|
||||
rm &plgPATH;/&pkgNAME;.md5
|
||||
exit 1
|
||||
else
|
||||
|
||||
upgradepkg --install-new &plgPATH;/&pkgNAME;.txz
|
||||
|
||||
echo "installing ungit (takes a minute)..."
|
||||
npm -g install ungit
|
||||
|
||||
#restart event daemon
|
||||
echo "starting ungit..."
|
||||
at -M -f &emhttp;/scripts/restart now 2>/dev/null
|
||||
|
||||
# Cleaning old source files
|
||||
find &plgPATH;/ -type f -iname "&name;*.txz" ! -iname "*&version;*" -delete
|
||||
find &plgPATH;/ -type f -iname "&name;*.md5" ! -iname "*&version;*" -delete
|
||||
|
||||
echo ""
|
||||
echo "-----------------------------------------------------------"
|
||||
echo " &name; has been installed."
|
||||
echo " This plugin requires Dynamix webGui to operate"
|
||||
echo " Copyright 2016, &author;"
|
||||
echo " Version: &version;"
|
||||
echo "-----------------------------------------------------------"
|
||||
echo ""
|
||||
|
||||
fi
|
||||
</INLINE>
|
||||
</FILE>
|
||||
|
||||
<!--
|
||||
The 'remove' script.
|
||||
-->
|
||||
<FILE Run="/bin/bash" Method="remove">
|
||||
<INLINE>
|
||||
# stop service
|
||||
echo "stopping ungit..."
|
||||
at -M -f &emhttp;/scripts/stop now 2>/dev/null
|
||||
|
||||
removepkg &plgPATH;/&pkgNAME;.txz
|
||||
rm -rf &emhttp;
|
||||
rm -f &plgPATH;/*.txz \
|
||||
&plgPATH;/*.md5
|
||||
|
||||
echo "removing ungit..."
|
||||
npm -g uninstall ungit
|
||||
|
||||
echo ""
|
||||
echo "-----------------------------------------------------------"
|
||||
echo " &name; has been removed."
|
||||
echo " Copyright 2016, &author;"
|
||||
echo " Version: &version;"
|
||||
echo "-----------------------------------------------------------"
|
||||
echo ""
|
||||
</INLINE>
|
||||
</FILE>
|
||||
|
||||
</PLUGIN>
|
@ -1,82 +0,0 @@
|
||||
#!/bin/sh
|
||||
# start/stop/restart ungit daemon:
|
||||
PLG="ungit"
|
||||
PROG="/usr/lib64/node_modules/$PLG/src/server.js"
|
||||
LOCKFILE="/var/lock/$PLG"
|
||||
PIDFILE="/var/run/$PLG.pid"
|
||||
CONFIG="/boot/config/plugins/$PLG/$PLG.cfg"
|
||||
|
||||
# read our configuration
|
||||
[ -e "$CONFIG" ] && source "$CONFIG"
|
||||
|
||||
# Start ungit:
|
||||
ungit_start() {
|
||||
# no-op if already running
|
||||
if [ ! -r "$PIDFILE" ]; then
|
||||
if [ "$DAEMON" == "enable" ]; then
|
||||
echo "starting $PLG..."
|
||||
sleep 1
|
||||
nohup /usr/bin/node $PROG --port="$PORT" --logDirectory="/var/log/" --logGitCommands --logGitOutput >/var/log/$PLG 2>&1 | echo $! > $PIDFILE &
|
||||
touch $LOCKFILE
|
||||
TIMER=0
|
||||
while [ ! -e $PIDFILE ]; do
|
||||
sleep 1
|
||||
let TIMER=$TIMER+1
|
||||
if [ $TIMER -gt 5 ]; then
|
||||
echo -n "$PIDFILE not created"
|
||||
break
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "$PLG is not enabled "
|
||||
fi
|
||||
else
|
||||
echo "$PLG is running "
|
||||
fi
|
||||
}
|
||||
|
||||
# Stop ungit:
|
||||
ungit_stop() {
|
||||
# no-op if not running
|
||||
if [ -r $PIDFILE ]; then
|
||||
#stop ungit
|
||||
echo "stopping $PLG..."
|
||||
sleep 1
|
||||
kill $(cat $PIDFILE)
|
||||
rm -f $LOCKFILE && rm -f $PIDFILE
|
||||
else
|
||||
echo "$PLG is stopped "
|
||||
fi
|
||||
}
|
||||
|
||||
# Restart ungit:
|
||||
ungit_restart() {
|
||||
ungit_stop
|
||||
sleep 1
|
||||
ungit_start
|
||||
}
|
||||
|
||||
# Restart ungit:
|
||||
ungit_update() {
|
||||
ungit_stop
|
||||
sleep 1
|
||||
npm -g update
|
||||
ungit_start
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
'start')
|
||||
ungit_start
|
||||
;;
|
||||
'stop')
|
||||
ungit_stop
|
||||
;;
|
||||
'restart')
|
||||
ungit_restart
|
||||
;;
|
||||
'update')
|
||||
ungit_update
|
||||
;;
|
||||
*)
|
||||
echo "usage rc.ungit: start|stop|restart"
|
||||
esac
|
@ -1,12 +0,0 @@
|
||||
#!/bin/sh
|
||||
RC_SCRIPT="/etc/rc.d/rc.ungit"
|
||||
SD_RCFILE="/etc/rc.d/rc.local_shutdown"
|
||||
|
||||
# Update file permissions of scripts
|
||||
chmod +0755 $RC_SCRIPT
|
||||
|
||||
# add stop to shutdown script
|
||||
if ! grep "$RC_SCRIPT" $SD_RCFILE >/dev/null 2>&1
|
||||
then echo -e "\n[ -x $RC_SCRIPT ] && $RC_SCRIPT stop" >> $SD_RCFILE
|
||||
fi
|
||||
[ ! -x $SD_RCFILE ] && chmod u+x $SD_RCFILE
|
@ -1,19 +0,0 @@
|
||||
# HOW TO EDIT THIS FILE:
|
||||
# The "handy ruler" below makes it easier to edit a package description.
|
||||
# Line up the first '|' above the ':' following the base package name, and
|
||||
# the '|' on the right side marks the last column you can put a character in.
|
||||
# You must make exactly 11 lines for the formatting to be correct. It's also
|
||||
# customary to leave one space after the ':' except on otherwise blank lines.
|
||||
|
||||
|-----handy-ruler------------------------------------------------------|
|
||||
ungit: unGit unRAID 6.1+ Plugin
|
||||
ungit:
|
||||
ungit: Ungit brings user friendliness to git without sacrificing
|
||||
ungit: versatility of git. Clean and intuitive UI that makes it easy to
|
||||
ungit: understand git.
|
||||
ungit:
|
||||
ungit: https://github.com/FredrikNoren/ungit
|
||||
ungit:
|
||||
ungit: dmacias72/unRAID
|
||||
ungit: https://github.com/dmacias72/unRAID-plugins
|
||||
ungit:
|
@ -1,37 +0,0 @@
|
||||
#!/bin/bash
|
||||
DIR="$(dirname "$(readlink -f ${BASH_SOURCE[0]})")"
|
||||
tmpdir=/tmp/tmp.$(( $RANDOM * 19318203981230 + 40 ))
|
||||
plugin=$(basename ${DIR})
|
||||
archive="$(dirname $(dirname ${DIR}))/archive"
|
||||
version=$(date +"%Y.%m.%d")
|
||||
package="${archive}/${plugin}-${version}-x86_64-1.txz"
|
||||
md5="${archive}/${plugin}-${version}-x86_64-1.md5"
|
||||
|
||||
if [[ -f $package ]]; then
|
||||
for x in a b c d e d f g h ; do
|
||||
package="${archive}/${plugin}-${version}${x}-x86_64-1.txz"
|
||||
md5="${archive}/${plugin}-${version}${x}-x86_64-1.md5"
|
||||
if [[ ! -f $package ]]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
mkdir -p $tmpdir
|
||||
cd "$DIR"
|
||||
cp --parents -f $(find . -type f ! \( -iname "pkg_build.sh" -o -iname "sftp-config.json" -o -iname ".DS_Store" \) ) $tmpdir/
|
||||
cd "$tmpdir/"
|
||||
makepkg -l y -c y "${package}"
|
||||
cd "$archive/"
|
||||
md5sum $(basename "$package") > "$md5"
|
||||
rm -rf "$tmpdir"
|
||||
|
||||
# Verify and install plugin package
|
||||
sum1=$(md5sum "${package}")
|
||||
sum2=$(cat "$md5")
|
||||
if [ "${sum1:0:32}" != "${sum2:0:32}" ]; then
|
||||
echo "Checksum mismatched.";
|
||||
rm "$md5" "${package}"
|
||||
else
|
||||
echo "Checksum matched."
|
||||
fi
|
@ -1,3 +0,0 @@
|
||||
**unGit**
|
||||
|
||||
unGit brings user friendliness to git without sacrificing versatility of git. Clean and intuitive UI that makes it easy to understand git.
|
@ -1,107 +0,0 @@
|
||||
Icon="ungit.png"
|
||||
Menu="NetworkServices"
|
||||
Title="unGit"
|
||||
---
|
||||
<? require_once '/usr/local/emhttp/plugins/ungit/include/settings.php';?>
|
||||
|
||||
<form markdown="1" id="gform" name="g_settings" action="/update.php" method="POST" target="progressFrame">
|
||||
<input type="hidden" name="#file" value="ungit/ungit.cfg" />
|
||||
<input type="hidden" id="command" name="#command" value="" />
|
||||
|
||||
Enable unGit Server (<?=$gversion;?>):
|
||||
: <select id="DAEMON" name="DAEMON" size="1" onChange="checkRUNNING(this.form);">
|
||||
<?=mk_option($gdaemon, "disable", "No");?>
|
||||
<?=mk_option($gdaemon, "enable", "Yes");?>
|
||||
</select>
|
||||
|
||||
> Choose to enable unGit Server.
|
||||
>
|
||||
> Select Yes to enable, No to disable.
|
||||
|
||||
Port:
|
||||
: <input id="PORT" name="PORT" type="text" class="g-run" style="width:25px" maxlength="4" value="<?=$gport;?>" title="port must be 0-65535, default is 8448" placeholder="Port" >
|
||||
|
||||
> Enter Port number of your unGit Server
|
||||
|
||||
<input id="DEFAULT" class="g-run" type="submit" value="Default" onClick="resetDATA(this.form)"><input id="BtnConnect" type="button" value="Connect">
|
||||
: <input id="btnApply" type="submit" value="Apply" style="margin-bottom:8px" onClick="verifyDATA(this.form);"><input type="button" value="Done" onClick="done()">
|
||||
</form>
|
||||
|
||||
<div id="title" ><span class="left"><img class="icon" src="/webGui/icons/log.png"> unGit Log </span></div>
|
||||
<table class="tablesorter" style="margin-top: -22px;">
|
||||
<thead>
|
||||
<th>Logfile</th>
|
||||
<th>Size</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?
|
||||
$log = '/var/log/ungit';
|
||||
if(file_exists($log)){
|
||||
echo "<tr><td style='cursor:pointer;'><a title='$log' onclick=\"openWindow('/webGui/scripts/tail_log&arg1=ungit','unGit Log',600,900);\">$log</a></td><td>"
|
||||
.filesize($log).'</td></tr>';
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script type="text/javascript" src="/plugins/ungit/js/jquery.mask.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$('.tabs')
|
||||
.append("<span class='status'>Status: <?=$gstatus;?> </span>");
|
||||
|
||||
// dynamix plugin update api
|
||||
<?if (function_exists('plugin_update_available') && $version = plugin_update_available('ungit')):?>
|
||||
showNotice('ungit Notify <?=$version?> available. <a>Update</a>','ungit');
|
||||
$('#user-notice a').on('click', function () {
|
||||
$('#user-notice').empty();
|
||||
});
|
||||
<?endif;?>
|
||||
|
||||
$('#PORT').mask('0000#');
|
||||
|
||||
$('#BtnConnect').click(function () {
|
||||
window.open("<?php echo 'http://',$var['NAME'],':',$gport;?>", '_blank');
|
||||
});
|
||||
|
||||
checkRUNNING(document.g_settings);
|
||||
});
|
||||
|
||||
|
||||
function resetDATA(form) {
|
||||
form.PORT.value = 8448;
|
||||
}
|
||||
|
||||
function checkRUNNING(form) {
|
||||
if ("<?=$grunning;?>" == true){
|
||||
$('.g-run').prop('disabled', true);
|
||||
$('#BtnConnect').prop('disabled', false);
|
||||
form.btnApply.disabled = true;
|
||||
}else{
|
||||
$('.g-run').prop('disabled', false);
|
||||
$('#BtnConnect').prop('disabled', true);
|
||||
}
|
||||
if (form.DAEMON.value == 'enable'){
|
||||
form.command.value = '/usr/local/emhttp/plugins/ungit/scripts/start';
|
||||
} else {
|
||||
form.command.value = '/usr/local/emhttp/plugins/ungit/scripts/stop';
|
||||
form.btnApply.disabled = (form.DAEMON.value == 'enable');
|
||||
}
|
||||
}
|
||||
|
||||
function verifyDATA(form) {
|
||||
if (form.PORT.value < 0 || form.PORT.value > 65535 || form.PORT.value == ''){
|
||||
form.PORT.value = 8448;
|
||||
}
|
||||
form.DAEMON.value = form.DAEMON.value.replace(/ /g,"_");
|
||||
}
|
||||
|
||||
/* empty fan log */
|
||||
function clearFanLOG(){
|
||||
$.get('/plugins/ungit/include/fanlog_clear.php', {},function() {
|
||||
$('#fanlog-size').html('0');
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
Binary file not shown.
Before Width: | Height: | Size: 636 B |
Binary file not shown.
Before Width: | Height: | Size: 4.7 KiB |
@ -1,18 +0,0 @@
|
||||
<?
|
||||
$gcfg_file = '/boot/config/plugins/ungit/ungit.cfg';
|
||||
if(file_exists($gcfg_file))
|
||||
$gcfg = parse_ini_file($gcfg_file);
|
||||
|
||||
$gdaemon = isset($gcfg['DAEMON']) ? $gcfg['DAEMON'] : "disable";
|
||||
//$qipaddr = preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ipmi_cfg['host']) ?
|
||||
// $qcfg['host'] : $var['IPADDR'];
|
||||
$gipaddr = 'localhost';
|
||||
$gport = (isset($gcfg['PORT']) && is_numeric($gcfg['PORT']) && $gcfg['PORT'] > 0 && $gcfg['PORT'] < 65535 ) ? $gcfg['PORT'] : 8448;
|
||||
$gversion = trim(shell_exec( 'ungit -v' ));
|
||||
|
||||
//check running status
|
||||
$grunning = (trim(shell_exec( "[ -f /proc/`cat /var/run/ungit.pid 2> /dev/null`/exe ] && echo 1 || echo 0 2> /dev/null" )) == 1);
|
||||
$daemon_running = "<span class='green'>Running</span>";
|
||||
$daemon_stopped = "<span class='orange'>Stopped</span>";
|
||||
$gstatus = ($grunning) ? $daemon_running : $daemon_stopped;
|
||||
?>
|
@ -1,482 +0,0 @@
|
||||
/**
|
||||
* jquery.mask.js
|
||||
* @version: v1.11.3
|
||||
* @author: Igor Escobar
|
||||
*
|
||||
* Created by Igor Escobar on 2012-03-10. Please report any bug at http://blog.igorescobar.com
|
||||
*
|
||||
* Copyright (c) 2012 Igor Escobar http://blog.igorescobar.com
|
||||
*
|
||||
* The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/*jshint laxbreak: true */
|
||||
/* global define */
|
||||
|
||||
// UMD (Universal Module Definition) patterns for JavaScript modules that work everywhere.
|
||||
// https://github.com/umdjs/umd/blob/master/jqueryPluginCommonjs.js
|
||||
(function (factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(["jquery"], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
// Node/CommonJS
|
||||
factory(require('jquery'));
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(window.jQuery || window.Zepto);
|
||||
}
|
||||
}(function ($) {
|
||||
"use strict";
|
||||
var Mask = function (el, mask, options) {
|
||||
el = $(el);
|
||||
|
||||
var jMask = this, old_value = el.val(), regexMask;
|
||||
|
||||
mask = typeof mask === "function" ? mask(el.val(), undefined, el, options) : mask;
|
||||
|
||||
var p = {
|
||||
invalid: [],
|
||||
getCaret: function () {
|
||||
try {
|
||||
var sel,
|
||||
pos = 0,
|
||||
ctrl = el.get(0),
|
||||
dSel = document.selection,
|
||||
cSelStart = ctrl.selectionStart;
|
||||
|
||||
// IE Support
|
||||
if (dSel && navigator.appVersion.indexOf("MSIE 10") === -1) {
|
||||
sel = dSel.createRange();
|
||||
sel.moveStart('character', el.is("input") ? -el.val().length : -el.text().length);
|
||||
pos = sel.text.length;
|
||||
}
|
||||
// Firefox support
|
||||
else if (cSelStart || cSelStart === '0') {
|
||||
pos = cSelStart;
|
||||
}
|
||||
|
||||
return pos;
|
||||
} catch (e) {}
|
||||
},
|
||||
setCaret: function(pos) {
|
||||
try {
|
||||
if (el.is(":focus")) {
|
||||
var range, ctrl = el.get(0);
|
||||
|
||||
if (ctrl.setSelectionRange) {
|
||||
ctrl.setSelectionRange(pos,pos);
|
||||
} else if (ctrl.createTextRange) {
|
||||
range = ctrl.createTextRange();
|
||||
range.collapse(true);
|
||||
range.moveEnd('character', pos);
|
||||
range.moveStart('character', pos);
|
||||
range.select();
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
},
|
||||
events: function() {
|
||||
el
|
||||
.on('keyup.mask', p.behaviour)
|
||||
.on("paste.mask drop.mask", function() {
|
||||
setTimeout(function() {
|
||||
el.keydown().keyup();
|
||||
}, 100);
|
||||
})
|
||||
.on('change.mask', function(){
|
||||
el.data('changed', true);
|
||||
})
|
||||
.on("blur.mask", function(){
|
||||
if (old_value !== el.val() && !el.data('changed')) {
|
||||
el.trigger("change");
|
||||
}
|
||||
el.data('changed', false);
|
||||
})
|
||||
// it's very important that this callback remains in this position
|
||||
// otherwhise old_value it's going to work buggy
|
||||
.on('keydown.mask, blur.mask', function() {
|
||||
old_value = el.val();
|
||||
})
|
||||
// select all text on focus
|
||||
.on('focus.mask', function (e) {
|
||||
if (options.selectOnFocus === true) {
|
||||
$(e.target).select();
|
||||
}
|
||||
})
|
||||
// clear the value if it not complete the mask
|
||||
.on("focusout.mask", function() {
|
||||
if (options.clearIfNotMatch && !regexMask.test(p.val())) {
|
||||
p.val('');
|
||||
}
|
||||
});
|
||||
},
|
||||
getRegexMask: function() {
|
||||
var maskChunks = [], translation, pattern, optional, recursive, oRecursive, r;
|
||||
|
||||
for (var i = 0; i < mask.length; i++) {
|
||||
translation = jMask.translation[mask.charAt(i)];
|
||||
|
||||
if (translation) {
|
||||
|
||||
pattern = translation.pattern.toString().replace(/.{1}$|^.{1}/g, "");
|
||||
optional = translation.optional;
|
||||
recursive = translation.recursive;
|
||||
|
||||
if (recursive) {
|
||||
maskChunks.push(mask.charAt(i));
|
||||
oRecursive = {digit: mask.charAt(i), pattern: pattern};
|
||||
} else {
|
||||
maskChunks.push(!optional && !recursive ? pattern : (pattern + "?"));
|
||||
}
|
||||
|
||||
} else {
|
||||
maskChunks.push(mask.charAt(i).replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
|
||||
}
|
||||
}
|
||||
|
||||
r = maskChunks.join("");
|
||||
|
||||
if (oRecursive) {
|
||||
r = r.replace(new RegExp("(" + oRecursive.digit + "(.*" + oRecursive.digit + ")?)"), "($1)?")
|
||||
.replace(new RegExp(oRecursive.digit, "g"), oRecursive.pattern);
|
||||
}
|
||||
|
||||
return new RegExp(r);
|
||||
},
|
||||
destroyEvents: function() {
|
||||
el.off(['keydown', 'keyup', 'paste', 'drop', 'blur', 'focusout', ''].join('.mask '));
|
||||
},
|
||||
val: function(v) {
|
||||
var isInput = el.is('input'),
|
||||
method = isInput ? 'val' : 'text',
|
||||
r;
|
||||
|
||||
if (arguments.length > 0) {
|
||||
if (el[method]() !== v) {
|
||||
el[method](v);
|
||||
}
|
||||
r = el;
|
||||
} else {
|
||||
r = el[method]();
|
||||
}
|
||||
|
||||
return r;
|
||||
},
|
||||
getMCharsBeforeCount: function(index, onCleanVal) {
|
||||
for (var count = 0, i = 0, maskL = mask.length; i < maskL && i < index; i++) {
|
||||
if (!jMask.translation[mask.charAt(i)]) {
|
||||
index = onCleanVal ? index + 1 : index;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
},
|
||||
caretPos: function (originalCaretPos, oldLength, newLength, maskDif) {
|
||||
var translation = jMask.translation[mask.charAt(Math.min(originalCaretPos - 1, mask.length - 1))];
|
||||
|
||||
return !translation ? p.caretPos(originalCaretPos + 1, oldLength, newLength, maskDif)
|
||||
: Math.min(originalCaretPos + newLength - oldLength - maskDif, newLength);
|
||||
},
|
||||
behaviour: function(e) {
|
||||
e = e || window.event;
|
||||
p.invalid = [];
|
||||
var keyCode = e.keyCode || e.which;
|
||||
if ($.inArray(keyCode, jMask.byPassKeys) === -1) {
|
||||
|
||||
var caretPos = p.getCaret(),
|
||||
currVal = p.val(),
|
||||
currValL = currVal.length,
|
||||
changeCaret = caretPos < currValL,
|
||||
newVal = p.getMasked(),
|
||||
newValL = newVal.length,
|
||||
maskDif = p.getMCharsBeforeCount(newValL - 1) - p.getMCharsBeforeCount(currValL - 1);
|
||||
|
||||
p.val(newVal);
|
||||
|
||||
// change caret but avoid CTRL+A
|
||||
if (changeCaret && !(keyCode === 65 && e.ctrlKey)) {
|
||||
// Avoid adjusting caret on backspace or delete
|
||||
if (!(keyCode === 8 || keyCode === 46)) {
|
||||
caretPos = p.caretPos(caretPos, currValL, newValL, maskDif);
|
||||
}
|
||||
p.setCaret(caretPos);
|
||||
}
|
||||
|
||||
return p.callbacks(e);
|
||||
}
|
||||
},
|
||||
getMasked: function (skipMaskChars) {
|
||||
var buf = [],
|
||||
value = p.val(),
|
||||
m = 0, maskLen = mask.length,
|
||||
v = 0, valLen = value.length,
|
||||
offset = 1, addMethod = "push",
|
||||
resetPos = -1,
|
||||
lastMaskChar,
|
||||
check;
|
||||
|
||||
if (options.reverse) {
|
||||
addMethod = "unshift";
|
||||
offset = -1;
|
||||
lastMaskChar = 0;
|
||||
m = maskLen - 1;
|
||||
v = valLen - 1;
|
||||
check = function () {
|
||||
return m > -1 && v > -1;
|
||||
};
|
||||
} else {
|
||||
lastMaskChar = maskLen - 1;
|
||||
check = function () {
|
||||
return m < maskLen && v < valLen;
|
||||
};
|
||||
}
|
||||
|
||||
while (check()) {
|
||||
var maskDigit = mask.charAt(m),
|
||||
valDigit = value.charAt(v),
|
||||
translation = jMask.translation[maskDigit];
|
||||
|
||||
if (translation) {
|
||||
if (valDigit.match(translation.pattern)) {
|
||||
buf[addMethod](valDigit);
|
||||
if (translation.recursive) {
|
||||
if (resetPos === -1) {
|
||||
resetPos = m;
|
||||
} else if (m === lastMaskChar) {
|
||||
m = resetPos - offset;
|
||||
}
|
||||
|
||||
if (lastMaskChar === resetPos) {
|
||||
m -= offset;
|
||||
}
|
||||
}
|
||||
m += offset;
|
||||
} else if (translation.optional) {
|
||||
m += offset;
|
||||
v -= offset;
|
||||
} else if (translation.fallback) {
|
||||
buf[addMethod](translation.fallback);
|
||||
m += offset;
|
||||
v -= offset;
|
||||
} else {
|
||||
p.invalid.push({p: v, v: valDigit, e: translation.pattern});
|
||||
}
|
||||
v += offset;
|
||||
} else {
|
||||
if (!skipMaskChars) {
|
||||
buf[addMethod](maskDigit);
|
||||
}
|
||||
|
||||
if (valDigit === maskDigit) {
|
||||
v += offset;
|
||||
}
|
||||
|
||||
m += offset;
|
||||
}
|
||||
}
|
||||
|
||||
var lastMaskCharDigit = mask.charAt(lastMaskChar);
|
||||
if (maskLen === valLen + 1 && !jMask.translation[lastMaskCharDigit]) {
|
||||
buf.push(lastMaskCharDigit);
|
||||
}
|
||||
|
||||
return buf.join("");
|
||||
},
|
||||
callbacks: function (e) {
|
||||
var val = p.val(),
|
||||
changed = val !== old_value,
|
||||
defaultArgs = [val, e, el, options],
|
||||
callback = function(name, criteria, args) {
|
||||
if (typeof options[name] === "function" && criteria) {
|
||||
options[name].apply(this, args);
|
||||
}
|
||||
};
|
||||
|
||||
callback('onChange', changed === true, defaultArgs);
|
||||
callback('onKeyPress', changed === true, defaultArgs);
|
||||
callback('onComplete', val.length === mask.length, defaultArgs);
|
||||
callback('onInvalid', p.invalid.length > 0, [val, e, el, p.invalid, options]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// public methods
|
||||
jMask.mask = mask;
|
||||
jMask.options = options;
|
||||
jMask.remove = function() {
|
||||
var caret = p.getCaret();
|
||||
p.destroyEvents();
|
||||
p.val(jMask.getCleanVal());
|
||||
p.setCaret(caret - p.getMCharsBeforeCount(caret));
|
||||
return el;
|
||||
};
|
||||
|
||||
// get value without mask
|
||||
jMask.getCleanVal = function() {
|
||||
return p.getMasked(true);
|
||||
};
|
||||
|
||||
jMask.init = function(only_mask) {
|
||||
only_mask = only_mask || false;
|
||||
options = options || {};
|
||||
|
||||
jMask.byPassKeys = $.jMaskGlobals.byPassKeys;
|
||||
jMask.translation = $.jMaskGlobals.translation;
|
||||
|
||||
jMask.translation = $.extend({}, jMask.translation, options.translation);
|
||||
jMask = $.extend(true, {}, jMask, options);
|
||||
|
||||
regexMask = p.getRegexMask();
|
||||
|
||||
if (only_mask === false) {
|
||||
|
||||
if (options.placeholder) {
|
||||
el.attr('placeholder' , options.placeholder);
|
||||
}
|
||||
|
||||
// autocomplete needs to be off. we can't intercept events
|
||||
// the browser doesn't fire any kind of event when something is
|
||||
// selected in a autocomplete list so we can't sanitize it.
|
||||
el.attr('autocomplete', 'off');
|
||||
p.destroyEvents();
|
||||
p.events();
|
||||
|
||||
var caret = p.getCaret();
|
||||
p.val(p.getMasked());
|
||||
p.setCaret(caret + p.getMCharsBeforeCount(caret, true));
|
||||
|
||||
} else {
|
||||
p.events();
|
||||
p.val(p.getMasked());
|
||||
}
|
||||
};
|
||||
|
||||
jMask.init(!el.is("input"));
|
||||
};
|
||||
|
||||
$.maskWatchers = {};
|
||||
var HTMLAttributes = function () {
|
||||
var input = $(this),
|
||||
options = {},
|
||||
prefix = "data-mask-",
|
||||
mask = input.attr('data-mask');
|
||||
|
||||
if (input.attr(prefix + 'reverse')) {
|
||||
options.reverse = true;
|
||||
}
|
||||
|
||||
if (input.attr(prefix + 'clearifnotmatch')) {
|
||||
options.clearIfNotMatch = true;
|
||||
}
|
||||
|
||||
if (input.attr(prefix + 'selectonfocus') === 'true') {
|
||||
options.selectOnFocus = true;
|
||||
}
|
||||
|
||||
if (notSameMaskObject(input, mask, options)) {
|
||||
return input.data('mask', new Mask(this, mask, options));
|
||||
}
|
||||
},
|
||||
notSameMaskObject = function(field, mask, options) {
|
||||
options = options || {};
|
||||
var maskObject = $(field).data('mask'),
|
||||
stringify = JSON.stringify,
|
||||
value = $(field).val() || $(field).text();
|
||||
try {
|
||||
if (typeof mask === "function") {
|
||||
mask = mask(value);
|
||||
}
|
||||
return typeof maskObject !== "object" || stringify(maskObject.options) !== stringify(options) || maskObject.mask !== mask;
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
|
||||
$.fn.mask = function(mask, options) {
|
||||
options = options || {};
|
||||
var selector = this.selector,
|
||||
globals = $.jMaskGlobals,
|
||||
interval = $.jMaskGlobals.watchInterval,
|
||||
maskFunction = function() {
|
||||
if (notSameMaskObject(this, mask, options)) {
|
||||
return $(this).data('mask', new Mask(this, mask, options));
|
||||
}
|
||||
};
|
||||
|
||||
$(this).each(maskFunction);
|
||||
|
||||
if (selector && selector !== "" && globals.watchInputs) {
|
||||
clearInterval($.maskWatchers[selector]);
|
||||
$.maskWatchers[selector] = setInterval(function(){
|
||||
$(document).find(selector).each(maskFunction);
|
||||
}, interval);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
$.fn.unmask = function() {
|
||||
clearInterval($.maskWatchers[this.selector]);
|
||||
delete $.maskWatchers[this.selector];
|
||||
return this.each(function() {
|
||||
var dataMask = $(this).data('mask');
|
||||
if (dataMask) {
|
||||
dataMask.remove().removeData('mask');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$.fn.cleanVal = function() {
|
||||
return this.data('mask').getCleanVal();
|
||||
};
|
||||
|
||||
$.applyDataMask = function() {
|
||||
$(document).find($.jMaskGlobals.maskElements).filter(globals.dataMaskAttr).each(HTMLAttributes);
|
||||
}
|
||||
|
||||
var globals = {
|
||||
maskElements: 'input,td,span,div',
|
||||
dataMaskAttr: '*[data-mask]',
|
||||
dataMask: true,
|
||||
watchInterval: 300,
|
||||
watchInputs: true,
|
||||
watchDataMask: false,
|
||||
byPassKeys: [9, 16, 17, 18, 36, 37, 38, 39, 40, 91],
|
||||
translation: {
|
||||
'0': {pattern: /\d/},
|
||||
'9': {pattern: /\d/, optional: true},
|
||||
'#': {pattern: /\d/, recursive: true},
|
||||
'A': {pattern: /[a-zA-Z0-9]/},
|
||||
'S': {pattern: /[a-zA-Z]/}
|
||||
}
|
||||
};
|
||||
|
||||
$.jMaskGlobals = $.jMaskGlobals || {};
|
||||
globals = $.jMaskGlobals = $.extend(true, {}, globals, $.jMaskGlobals);
|
||||
|
||||
// looking for inputs with data-mask attribute
|
||||
if (globals.dataMask) { $.applyDataMask(); }
|
||||
|
||||
setInterval(function(){
|
||||
if ($.jMaskGlobals.watchDataMask) { $.applyDataMask(); }
|
||||
}, globals.watchInterval);
|
||||
}));
|
@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
/etc/rc.d/rc.ungit restart
|
@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
/etc/rc.d/rc.ungit start
|
@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
/etc/rc.d/rc.ungit stop
|
Loading…
Reference in New Issue
Block a user