diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..fe3a5642
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+##ignore this file##
+/.idea/*
+/Runtime/*
+/application/database.php
diff --git a/.idea/fastadmin.iml b/.idea/fastadmin.iml
deleted file mode 100644
index c956989b..00000000
--- a/.idea/fastadmin.iml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
deleted file mode 100644
index e62fe692..00000000
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index b61da765..00000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7f..00000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/application/api/controller/Sms.php b/application/api/controller/Sms.php
index 5e558c42..4c31111c 100644
--- a/application/api/controller/Sms.php
+++ b/application/api/controller/Sms.php
@@ -1,114 +1,114 @@
-request->request("mobile");
- $event = $this->request->request("event");
- $event = $event ? $event : 'register';
-
- $last = Smslib::get($mobile, $event);
- if ($last && time() - $last['createtime'] < 60)
- {
- $this->error(__('发送频繁'));
- }
- if ($event)
- {
- $userinfo = User::getByMobile($mobile);
- if ($event == 'register' && $userinfo)
- {
- //已被注册
- $this->error(__('已被注册'));
- }
- else if (in_array($event, ['changemobile']) && $userinfo)
- {
- //被占用
- $this->error(__('已被占用'));
- }
- else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo)
- {
- //未注册
- $this->error(__('未注册'));
- }
- }
- $ret = Smslib::send($mobile, NULL, $event);
- if ($ret)
- {
- $this->success(__('发送成功'));
- }
- else
- {
- $this->error(__('发送失败'));
- }
- }
-
- /**
- * 检测验证码
- *
- * @param string $mobile 手机号
- * @param string $event 事件名称
- * @param string $captcha 验证码
- */
- public function check()
- {
- $mobile = $this->request->request("mobile");
- $event = $this->request->request("event");
- $event = $event ? $event : 'register';
- $captcha = $this->request->request("captcha");
-
- if ($event)
- {
- $userinfo = User::getByMobile($mobile);
- if ($event == 'register' && $userinfo)
- {
- //已被注册
- $this->error(__('已被注册'));
- }
- else if (in_array($event, ['changemobile']) && $userinfo)
- {
- //被占用
- $this->error(__('已被占用'));
- }
- else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo)
- {
- //未注册
- $this->error(__('未注册'));
- }
- }
- $ret = Smslib::check($mobile, $captcha, $event);
- if ($ret)
- {
- $this->success(__('成功'));
- }
- else
- {
- $this->error(__('验证码不正确'));
- }
- }
-
-}
+request->request("mobile");
+ $event = $this->request->request("event");
+ $event = $event ? $event : 'register';
+
+ $last = Smslib::get($mobile, $event);
+ if ($last && time() - $last['createtime'] < 60)
+ {
+ $this->error(__('发送频繁'));
+ }
+ if ($event)
+ {
+ $userinfo = User::getByMobile($mobile);
+ if ($event == 'register' && $userinfo)
+ {
+ //已被注册
+ $this->error(__('已被注册'));
+ }
+ else if (in_array($event, ['changemobile']) && $userinfo)
+ {
+ //被占用
+ $this->error(__('已被占用'));
+ }
+ else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo)
+ {
+ //未注册
+ $this->error(__('未注册'));
+ }
+ }
+ $ret = Smslib::send($mobile, NULL, $event);
+ if ($ret)
+ {
+ $this->success(__('发送成功'));
+ }
+ else
+ {
+ $this->error(__('发送失败'));
+ }
+ }
+
+ /**
+ * 检测验证码
+ *
+ * @param string $mobile 手机号
+ * @param string $event 事件名称
+ * @param string $captcha 验证码
+ */
+ public function check()
+ {
+ $mobile = $this->request->request("mobile");
+ $event = $this->request->request("event");
+ $event = $event ? $event : 'register';
+ $captcha = $this->request->request("captcha");
+
+ if ($event)
+ {
+ $userinfo = User::getByMobile($mobile);
+ if ($event == 'register' && $userinfo)
+ {
+ //已被注册
+ $this->error(__('已被注册'));
+ }
+ else if (in_array($event, ['changemobile']) && $userinfo)
+ {
+ //被占用
+ $this->error(__('已被占用'));
+ }
+ else if (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo)
+ {
+ //未注册
+ $this->error(__('未注册'));
+ }
+ }
+ $ret = Smslib::check($mobile, $captcha, $event);
+ if ($ret)
+ {
+ $this->success(__('成功'));
+ }
+ else
+ {
+ $this->error(__('验证码不正确'));
+ }
+ }
+
+}
diff --git a/application/api/controller/Validate.php b/application/api/controller/Validate.php
index c8a7a017..37364131 100644
--- a/application/api/controller/Validate.php
+++ b/application/api/controller/Validate.php
@@ -1,112 +1,112 @@
-request->request('email');
- $id = (int) $this->request->request('id');
- $count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
- if ($count > 0)
- {
- $this->error(__('邮箱已经被占用'));
- }
- $this->success();
- }
-
- /**
- * 检测用户名
- *
- * @param string $username 用户名
- * @param string $id 会员ID
- */
- public function check_username_available()
- {
- $email = $this->request->request('username');
- $id = (int) $this->request->request('id');
- $count = User::where('username', '=', $email)->where('id', '<>', $id)->count();
- if ($count > 0)
- {
- $this->error(__('用户名已经被占用'));
- }
- $this->success();
- }
-
- /**
- * 检测手机
- *
- * @param string $mobile 手机号
- * @param string $id 会员ID
- */
- public function check_mobile_available()
- {
- $email = $this->request->request('mobile');
- $id = (int) $this->request->request('id');
- $count = User::where('mobile', '=', $email)->where('id', '<>', $id)->count();
- if ($count > 0)
- {
- $this->error(__('已经使用该手机号注册'));
- }
- $this->success();
- }
-
- /**
- * 检测手机
- *
- * @param string $mobile 手机号
- */
- public function check_mobile_exist()
- {
- $email = $this->request->request('mobile');
- $count = User::where('mobile', '=', $email)->count();
- if (!$count)
- {
- $this->error(__('手机号不存在'));
- }
- $this->success();
- }
-
- /**
- * 检测验证码
- *
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- * @param string $event 事件
- */
- public function check_sms_correct()
- {
- $mobile = $this->request->request('mobile');
- $captcha = $this->request->request('captcha');
- $event = $this->request->request('event');
- if (!\app\common\library\Sms::check($mobile, $captcha, $event))
- {
- $this->error(__('验证码不正确'));
- }
- $this->success();
- }
-
-}
+request->request('email');
+ $id = (int) $this->request->request('id');
+ $count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
+ if ($count > 0)
+ {
+ $this->error(__('邮箱已经被占用'));
+ }
+ $this->success();
+ }
+
+ /**
+ * 检测用户名
+ *
+ * @param string $username 用户名
+ * @param string $id 会员ID
+ */
+ public function check_username_available()
+ {
+ $email = $this->request->request('username');
+ $id = (int) $this->request->request('id');
+ $count = User::where('username', '=', $email)->where('id', '<>', $id)->count();
+ if ($count > 0)
+ {
+ $this->error(__('用户名已经被占用'));
+ }
+ $this->success();
+ }
+
+ /**
+ * 检测手机
+ *
+ * @param string $mobile 手机号
+ * @param string $id 会员ID
+ */
+ public function check_mobile_available()
+ {
+ $email = $this->request->request('mobile');
+ $id = (int) $this->request->request('id');
+ $count = User::where('mobile', '=', $email)->where('id', '<>', $id)->count();
+ if ($count > 0)
+ {
+ $this->error(__('已经使用该手机号注册'));
+ }
+ $this->success();
+ }
+
+ /**
+ * 检测手机
+ *
+ * @param string $mobile 手机号
+ */
+ public function check_mobile_exist()
+ {
+ $email = $this->request->request('mobile');
+ $count = User::where('mobile', '=', $email)->count();
+ if (!$count)
+ {
+ $this->error(__('手机号不存在'));
+ }
+ $this->success();
+ }
+
+ /**
+ * 检测验证码
+ *
+ * @param string $mobile 手机号
+ * @param string $captcha 验证码
+ * @param string $event 事件
+ */
+ public function check_sms_correct()
+ {
+ $mobile = $this->request->request('mobile');
+ $captcha = $this->request->request('captcha');
+ $event = $this->request->request('event');
+ if (!\app\common\library\Sms::check($mobile, $captcha, $event))
+ {
+ $this->error(__('验证码不正确'));
+ }
+ $this->success();
+ }
+
+}
diff --git a/application/api/model/Area.php b/application/api/model/Area.php
index 90500f94..859dae46 100644
--- a/application/api/model/Area.php
+++ b/application/api/model/Area.php
@@ -1,93 +1,93 @@
- 'geo:province', 2 => 'geo:city', 3 => 'geo:district'];
- $rangearr = [1 => 15000, 2 => 1000, 3 => 200];
- $geoname = isset($namearr[$level]) ? $namearr[$level] : $namearr[3];
- $georange = isset($rangearr[$level]) ? $rangearr[$level] : $rangearr[3];
- $neararea = [];
- // 读取范围内的ID
- $redis = Cache::store('redis')->handler();
- $georadiuslist = [];
- if (method_exists($redis, 'georadius'))
- {
- $georadiuslist = $redis->georadius($geoname, $lng, $lat, $georange, 'km', ['WITHDIST', 'COUNT' => 5, 'ASC']);
- }
-
- if ($georadiuslist)
- {
- list($id, $distance) = $georadiuslist[0];
- }
- $id = isset($id) && $id ? $id : 3;
- return self::get($id);
- }
-
- /**
- * 根据经纬度获取省份
- *
- * @param string $lng 经度
- * @param string $lat 纬度
- * @return array
- */
- public static function getProvinceFromLngLat($lng, $lat)
- {
- $provincedata = [];
- $citydata = self::getCityFromLngLat($lng, $lat);
- if ($citydata)
- {
- $provincedata = self::get($citydata['pid']);
- }
- return $provincedata;
- }
-
- /**
- * 根据经纬度获取城市
- *
- * @param string $lng 经度
- * @param string $lat 纬度
- * @return array
- */
- public static function getCityFromLngLat($lng, $lat)
- {
- $citydata = [];
- $districtdata = self::getDistrictFromLngLat($lng, $lat);
- if ($districtdata)
- {
- $citydata = self::get($districtdata['pid']);
- }
- return $citydata;
- }
-
- /**
- * 根据经纬度获取地区
- *
- * @param string $lng 经度
- * @param string $lat 纬度
- * @return array
- */
- public static function getDistrictFromLngLat($lng, $lat)
- {
- $districtdata = self::getAreaFromLngLat($lng, $lat, 3);
- return $districtdata;
- }
-
-}
+ 'geo:province', 2 => 'geo:city', 3 => 'geo:district'];
+ $rangearr = [1 => 15000, 2 => 1000, 3 => 200];
+ $geoname = isset($namearr[$level]) ? $namearr[$level] : $namearr[3];
+ $georange = isset($rangearr[$level]) ? $rangearr[$level] : $rangearr[3];
+ $neararea = [];
+ // 读取范围内的ID
+ $redis = Cache::store('redis')->handler();
+ $georadiuslist = [];
+ if (method_exists($redis, 'georadius'))
+ {
+ $georadiuslist = $redis->georadius($geoname, $lng, $lat, $georange, 'km', ['WITHDIST', 'COUNT' => 5, 'ASC']);
+ }
+
+ if ($georadiuslist)
+ {
+ list($id, $distance) = $georadiuslist[0];
+ }
+ $id = isset($id) && $id ? $id : 3;
+ return self::get($id);
+ }
+
+ /**
+ * 根据经纬度获取省份
+ *
+ * @param string $lng 经度
+ * @param string $lat 纬度
+ * @return array
+ */
+ public static function getProvinceFromLngLat($lng, $lat)
+ {
+ $provincedata = [];
+ $citydata = self::getCityFromLngLat($lng, $lat);
+ if ($citydata)
+ {
+ $provincedata = self::get($citydata['pid']);
+ }
+ return $provincedata;
+ }
+
+ /**
+ * 根据经纬度获取城市
+ *
+ * @param string $lng 经度
+ * @param string $lat 纬度
+ * @return array
+ */
+ public static function getCityFromLngLat($lng, $lat)
+ {
+ $citydata = [];
+ $districtdata = self::getDistrictFromLngLat($lng, $lat);
+ if ($districtdata)
+ {
+ $citydata = self::get($districtdata['pid']);
+ }
+ return $citydata;
+ }
+
+ /**
+ * 根据经纬度获取地区
+ *
+ * @param string $lng 经度
+ * @param string $lat 纬度
+ * @return array
+ */
+ public static function getDistrictFromLngLat($lng, $lat)
+ {
+ $districtdata = self::getAreaFromLngLat($lng, $lat, 3);
+ return $districtdata;
+ }
+
+}
diff --git a/application/common/library/Sms.php b/application/common/library/Sms.php
index 39d3a4b5..88576526 100644
--- a/application/common/library/Sms.php
+++ b/application/common/library/Sms.php
@@ -1,143 +1,143 @@
- $mobile, 'event' => $event])
- ->order('id', 'DESC')
- ->find();
- Hook::listen('sms_get', $sms, null, true);
- return $sms ? $sms : NULL;
- }
-
- /**
- * 发送验证码
- *
- * @param int $mobile 手机号
- * @param int $code 验证码,为空时将自动生成4位数字
- * @param string $event 事件
- * @return boolean
- */
- public static function send($mobile, $code = NULL, $event = 'default')
- {
- $code = is_null($code) ? mt_rand(1000, 9999) : $code;
- $time = time();
- $sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'createtime' => $time]);
- $result = Hook::listen('sms_send', $sms, null, true);
- if (!$result)
- {
- $sms->delete();
- return FALSE;
- }
- return TRUE;
- }
-
- /**
- * 发送通知
- *
- * @param mixed $mobile 手机号,多个以,分隔
- * @param string $msg 消息内容
- * @param string $template 消息模板
- * @return boolean
- */
- public static function notice($mobile, $msg = '', $template = NULL)
- {
- $params = [
- 'mobile' => $mobile,
- 'msg' => $msg,
- 'template' => $template
- ];
- $result = Hook::listen('sms_notice', $params, null, true);
- return $result ? TRUE : FALSE;
- }
-
- /**
- * 校验验证码
- *
- * @param int $mobile 手机号
- * @param int $code 验证码
- * @param string $event 事件
- * @return boolean
- */
- public static function check($mobile, $code, $event = 'default')
- {
- $time = time() - self::$expire;
- $sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event])
- ->order('id', 'DESC')
- ->find();
- if ($sms)
- {
- if ($sms['createtime'] > $time && $sms['times'] <= self::$maxCheckNums)
- {
- $correct = $code == $sms['code'];
- if (!$correct)
- {
- $sms->times = $sms->times + 1;
- $sms->save();
- return FALSE;
- }
- else
- {
- $result = Hook::listen('sms_check', $sms, null, true);
- return $result;
- }
- }
- else
- {
- // 过期则清空该手机验证码
- self::flush($mobile, $event);
- return FALSE;
- }
- }
- else
- {
- return FALSE;
- }
- }
-
- /**
- * 清空指定手机号验证码
- *
- * @param int $mobile 手机号
- * @param string $event 事件
- * @return boolean
- */
- public static function flush($mobile, $event = 'default')
- {
- \app\common\model\Sms::
- where(['mobile' => $mobile, 'event' => $event])
- ->delete();
- Hook::listen('sms_flush');
- return TRUE;
- }
-
-}
+ $mobile, 'event' => $event])
+ ->order('id', 'DESC')
+ ->find();
+ Hook::listen('sms_get', $sms, null, true);
+ return $sms ? $sms : NULL;
+ }
+
+ /**
+ * 发送验证码
+ *
+ * @param int $mobile 手机号
+ * @param int $code 验证码,为空时将自动生成4位数字
+ * @param string $event 事件
+ * @return boolean
+ */
+ public static function send($mobile, $code = NULL, $event = 'default')
+ {
+ $code = is_null($code) ? mt_rand(1000, 9999) : $code;
+ $time = time();
+ $sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'createtime' => $time]);
+ $result = Hook::listen('sms_send', $sms, null, true);
+ if (!$result)
+ {
+ $sms->delete();
+ return FALSE;
+ }
+ return TRUE;
+ }
+
+ /**
+ * 发送通知
+ *
+ * @param mixed $mobile 手机号,多个以,分隔
+ * @param string $msg 消息内容
+ * @param string $template 消息模板
+ * @return boolean
+ */
+ public static function notice($mobile, $msg = '', $template = NULL)
+ {
+ $params = [
+ 'mobile' => $mobile,
+ 'msg' => $msg,
+ 'template' => $template
+ ];
+ $result = Hook::listen('sms_notice', $params, null, true);
+ return $result ? TRUE : FALSE;
+ }
+
+ /**
+ * 校验验证码
+ *
+ * @param int $mobile 手机号
+ * @param int $code 验证码
+ * @param string $event 事件
+ * @return boolean
+ */
+ public static function check($mobile, $code, $event = 'default')
+ {
+ $time = time() - self::$expire;
+ $sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event])
+ ->order('id', 'DESC')
+ ->find();
+ if ($sms)
+ {
+ if ($sms['createtime'] > $time && $sms['times'] <= self::$maxCheckNums)
+ {
+ $correct = $code == $sms['code'];
+ if (!$correct)
+ {
+ $sms->times = $sms->times + 1;
+ $sms->save();
+ return FALSE;
+ }
+ else
+ {
+ $result = Hook::listen('sms_check', $sms, null, true);
+ return $result;
+ }
+ }
+ else
+ {
+ // 过期则清空该手机验证码
+ self::flush($mobile, $event);
+ return FALSE;
+ }
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+
+ /**
+ * 清空指定手机号验证码
+ *
+ * @param int $mobile 手机号
+ * @param string $event 事件
+ * @return boolean
+ */
+ public static function flush($mobile, $event = 'default')
+ {
+ \app\common\model\Sms::
+ where(['mobile' => $mobile, 'event' => $event])
+ ->delete();
+ Hook::listen('sms_flush');
+ return TRUE;
+ }
+
+}
diff --git a/application/database.php b/application/database.php
deleted file mode 100644
index 77138511..00000000
--- a/application/database.php
+++ /dev/null
@@ -1,56 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-use think\Env;
-
-return [
- // 数据库类型
- 'type' => Env::get('database.type', 'mysql'),
- // 服务器地址
- 'hostname' => Env::get('database.hostname', '39.106.45.64'),
- // 数据库名
- 'database' => Env::get('database.database', 'qulvxing'),
- // 用户名
- 'username' => Env::get('database.username', 'jtl'),
- // 密码
- 'password' => Env::get('database.password', '!jtl123361@GLOD.com'),
- // 端口
- 'hostport' => Env::get('database.hostport', ''),
- // 连接dsn
- 'dsn' => '',
- // 数据库连接参数
- 'params' => [],
- // 数据库编码默认采用utf8
- 'charset' => Env::get('database.charset', 'utf8'),
- // 数据库表前缀
- 'prefix' => Env::get('database.prefix', 'fa_'),
- // 数据库调试模式
- 'debug' => Env::get('database.debug', true),
- // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
- 'deploy' => 0,
- // 数据库读写是否分离 主从式有效
- 'rw_separate' => false,
- // 读写分离后 主服务器数量
- 'master_num' => 1,
- // 指定从服务器序号
- 'slave_no' => '',
- // 是否严格检查字段是否存在
- 'fields_strict' => true,
- // 数据集返回类型
- 'resultset_type' => 'array',
- // 自动写入时间戳字段
- 'auto_timestamp' => false,
- // 时间字段取出后的默认时间格式,默认为Y-m-d H:i:s
- 'datetime_format' => false,
- // 是否需要进行SQL性能分析
- 'sql_explain' => false,
-];
diff --git a/application/index/controller/User.php b/application/index/controller/User.php
index 265c87f5..8daea85c 100644
--- a/application/index/controller/User.php
+++ b/application/index/controller/User.php
@@ -1,358 +1,358 @@
-auth;
-
- $ucenter = get_addon_info('ucenter');
- if ($ucenter && $ucenter['state'])
- {
- include ADDON_PATH . 'ucenter' . DS . 'uc.php';
- }
-
- //监听注册登录注销的事件
- Hook::add('user_login_successed', function($user) use($auth) {
- Cookie::set('uid', $user->id);
- Cookie::set('token', $auth->getToken());
- });
- Hook::add('user_register_successed', function($user) use($auth) {
- Cookie::set('uid', $user->id);
- Cookie::set('token', $auth->getToken());
- });
- Hook::add('user_delete_successed', function($user) use($auth) {
- Cookie::delete('uid');
- Cookie::delete('token');
- });
- Hook::add('user_logout_successed', function($user) use($auth) {
- Cookie::delete('uid');
- Cookie::delete('token');
- });
- }
-
- /**
- * 会员中心
- */
- public function index()
- {
- $this->view->assign('title', __('User center'));
- return $this->view->fetch();
- }
-
- /**
- * 注册会员
- */
- public function register()
- {
- $url = $this->request->request('url', url('user/index'));
- if ($this->auth->id)
- $this->success(__('You\'ve logged in, do not login again'), $url);
- if ($this->request->isPost())
- {
- $username = $this->request->post('username');
- $password = $this->request->post('password');
- $email = $this->request->post('email');
- $mobile = $this->request->post('mobile', '');
- $captcha = $this->request->post('captcha');
- $token = $this->request->post('__token__');
- $rule = [
- 'username' => 'require|length:3,30',
- 'password' => 'require|length:6,30',
- 'email' => 'require|email',
- 'mobile' => 'regex:/^1\d{10}$/',
- 'captcha' => 'require|captcha',
- '__token__' => 'token',
- ];
-
- $msg = [
- 'username.require' => 'Username can not be empty',
- 'username.length' => 'Username must be 3 to 30 characters',
- 'password.require' => 'Password can not be empty',
- 'password.length' => 'Password must be 6 to 30 characters',
- 'captcha.require' => 'Captcha can not be empty',
- 'captcha.captcha' => 'Captcha is incorrect',
- 'email' => 'Email is incorrect',
- 'mobile' => 'Mobile is incorrect',
- ];
- $data = [
- 'username' => $username,
- 'password' => $password,
- 'email' => $email,
- 'mobile' => $mobile,
- 'captcha' => $captcha,
- '__token__' => $token,
- ];
- $validate = new Validate($rule, $msg);
- $result = $validate->check($data);
- if (!$result)
- {
- $this->error(__($validate->getError()));
- }
- if ($this->auth->register($username, $password, $email, $mobile))
- {
- $synchtml = '';
- ////////////////同步到Ucenter////////////////
- if (defined('UC_STATUS') && UC_STATUS)
- {
- $uc = new \addons\ucenter\library\client\Client();
- $synchtml = $uc->uc_user_synregister($this->auth->id, $password);
- }
- $this->success(__('Sign up successful') . $synchtml, $url);
- }
- else
- {
- $this->error($this->auth->getError());
- }
- }
- Session::set('redirect_url', $url);
- $this->view->assign('title', __('Register'));
- return $this->view->fetch();
- }
-
- /**
- * 会员登录
- */
- public function login()
- {
- $url = $this->request->request('url', url('user/index'));
- if ($this->auth->id)
- $this->success(__('You\'ve logged in, do not login again'), $url);
- if ($this->request->isPost())
- {
- $account = $this->request->post('account');
- $password = $this->request->post('password');
- $keeptime = (int) $this->request->post('keeptime');
- $token = $this->request->post('__token__');
- $rule = [
- 'account' => 'require|length:3,50',
- 'password' => 'require|length:6,30',
- '__token__' => 'token',
- ];
-
- $msg = [
- 'account.require' => 'Account can not be empty',
- 'account.length' => 'Account must be 3 to 50 characters',
- 'password.require' => 'Password can not be empty',
- 'password.length' => 'Password must be 6 to 30 characters',
- ];
- $data = [
- 'account' => $account,
- 'password' => $password,
- '__token__' => $token,
- ];
- $validate = new Validate($rule, $msg);
- $result = $validate->check($data);
- if (!$result)
- {
- $this->error(__($validate->getError()));
- return FALSE;
- }
- if ($this->auth->login($account, $password, $keeptime))
- {
- $synchtml = '';
- ////////////////同步到Ucenter////////////////
- if (defined('UC_STATUS') && UC_STATUS)
- {
- $uc = new \addons\ucenter\library\client\Client();
- $synchtml = $uc->uc_user_synlogin($this->auth->id);
- }
- $this->success(__('Logged in successful') . $synchtml, $url);
- }
- else
- {
- $this->error($this->auth->getError());
- }
- }
- $this->view->assign('title', __('Login'));
- return $this->view->fetch();
- }
-
- /**
- * 注销登录
- */
- function logout()
- {
- //注销本站
- $this->auth->logout();
- $synchtml = '';
- ////////////////同步到Ucenter////////////////
- if (defined('UC_STATUS') && UC_STATUS)
- {
- $uc = new \addons\ucenter\library\client\Client();
- $synchtml = $uc->uc_user_synlogout();
- }
- $this->success(__('Logout successful') . $synchtml, url('user/index'));
- }
-
- /**
- * 第三方登录跳转和回调处理
- */
- public function third()
- {
- $url = url('user/index');
- $action = $this->request->param('action');
- $platform = $this->request->param('platform');
- $config = get_addon_config('third');
- if (!$config || !isset($config[$platform]))
- {
- $this->error(__('Invalid parameters'));
- }
- foreach ($config as $k => &$v)
- {
- $v['callback'] = url('user/third', ['action' => 'callback', 'platform' => $k], false, true);
- }
- unset($v);
- $app = new \addons\third\library\Application($config);
- if ($action == 'redirect')
- {
- // 跳转到登录授权页面
- $this->redirect($app->{$platform}->getAuthorizeUrl());
- }
- else if ($action == 'callback')
- {
- // 授权成功后的回调
- $result = $app->{$platform}->getUserInfo();
- if ($result)
- {
- $loginret = \addons\third\library\Service::connect($platform, $result);
- if ($loginret)
- {
- $synchtml = '';
- ////////////////同步到Ucenter////////////////
- if (defined('UC_STATUS') && UC_STATUS)
- {
- $uc = new \addons\ucenter\library\client\Client();
- $synchtml = $uc->uc_user_synlogin($this->auth->id);
- }
- $this->success(__('Logged in successful') . $synchtml, $url);
- }
- }
- $this->error(__('Operation failed'), $url);
- }
- else
- {
- $this->error(__('Invalid parameters'));
- }
- }
-
- /**
- * 个人信息
- */
- public function profile()
- {
- $this->view->assign('title', __('Profile'));
- return $this->view->fetch();
- }
-
- /**
- * 激活邮箱
- */
- public function activeemail()
- {
- $code = $this->request->request('code');
- $code = base64_decode($code);
- parse_str($code, $params);
- if (!isset($params['id']) || !isset($params['time']) || !isset($params['key']))
- {
- $this->error(__('Invalid parameters'));
- }
- $user = \app\common\model\User::get($params['id']);
- if (!$user)
- {
- $this->error(__('User not found'));
- }
- if ($user->verification->email)
- {
- $this->error(__('Email already activation'));
- }
- if ($key !== md5(md5($user->id . $user->email . $time) . $user->salt) || time() - $params['time'] > 1800)
- {
- $this->error(__('Secrity code already invalid'));
- }
- $verification = $user->verification;
- $verification->email = 1;
- $user->verification = $verification;
- $user->save();
- $this->success(__('Active email successful'), url('user/index'));
- return;
- }
-
- /**
- * 修改密码
- */
- public function changepwd()
- {
- if ($this->request->isPost())
- {
- $oldpassword = $this->request->post("oldpassword");
- $newpassword = $this->request->post("newpassword");
- $renewpassword = $this->request->post("renewpassword");
- $token = $this->request->post('__token__');
- $rule = [
- 'oldpassword' => 'require|length:6,30',
- 'newpassword' => 'require|length:6,30',
- 'renewpassword' => 'require|length:6,30|confirm:newpassword',
- '__token__' => 'token',
- ];
-
- $msg = [
- ];
- $data = [
- 'oldpassword' => $oldpassword,
- 'newpassword' => $newpassword,
- 'renewpassword' => $renewpassword,
- '__token__' => $token,
- ];
- $field = [
- 'oldpassword' => __('Old password'),
- 'newpassword' => __('New password'),
- 'renewpassword' => __('Renew password')
- ];
- $validate = new Validate($rule, $msg, $field);
- $result = $validate->check($data);
- if (!$result)
- {
- $this->error(__($validate->getError()));
- return FALSE;
- }
-
- $ret = $this->auth->changepwd($newpassword, $oldpassword);
- if ($ret)
- {
- $synchtml = '';
- ////////////////同步到Ucenter////////////////
- if (defined('UC_STATUS') && UC_STATUS)
- {
- $uc = new \addons\ucenter\library\client\Client();
- $synchtml = $uc->uc_user_synlogout();
- }
- $this->success(__('Reset password successful') . $synchtml, url('user/login'));
- }
- else
- {
- $this->error($this->auth->getError());
- }
- }
- $this->view->assign('title', __('Change password'));
- return $this->view->fetch();
- }
-
-}
+auth;
+
+ $ucenter = get_addon_info('ucenter');
+ if ($ucenter && $ucenter['state'])
+ {
+ include ADDON_PATH . 'ucenter' . DS . 'uc.php';
+ }
+
+ //监听注册登录注销的事件
+ Hook::add('user_login_successed', function($user) use($auth) {
+ Cookie::set('uid', $user->id);
+ Cookie::set('token', $auth->getToken());
+ });
+ Hook::add('user_register_successed', function($user) use($auth) {
+ Cookie::set('uid', $user->id);
+ Cookie::set('token', $auth->getToken());
+ });
+ Hook::add('user_delete_successed', function($user) use($auth) {
+ Cookie::delete('uid');
+ Cookie::delete('token');
+ });
+ Hook::add('user_logout_successed', function($user) use($auth) {
+ Cookie::delete('uid');
+ Cookie::delete('token');
+ });
+ }
+
+ /**
+ * 会员中心
+ */
+ public function index()
+ {
+ $this->view->assign('title', __('User center'));
+ return $this->view->fetch();
+ }
+
+ /**
+ * 注册会员
+ */
+ public function register()
+ {
+ $url = $this->request->request('url', url('user/index'));
+ if ($this->auth->id)
+ $this->success(__('You\'ve logged in, do not login again'), $url);
+ if ($this->request->isPost())
+ {
+ $username = $this->request->post('username');
+ $password = $this->request->post('password');
+ $email = $this->request->post('email');
+ $mobile = $this->request->post('mobile', '');
+ $captcha = $this->request->post('captcha');
+ $token = $this->request->post('__token__');
+ $rule = [
+ 'username' => 'require|length:3,30',
+ 'password' => 'require|length:6,30',
+ 'email' => 'require|email',
+ 'mobile' => 'regex:/^1\d{10}$/',
+ 'captcha' => 'require|captcha',
+ '__token__' => 'token',
+ ];
+
+ $msg = [
+ 'username.require' => 'Username can not be empty',
+ 'username.length' => 'Username must be 3 to 30 characters',
+ 'password.require' => 'Password can not be empty',
+ 'password.length' => 'Password must be 6 to 30 characters',
+ 'captcha.require' => 'Captcha can not be empty',
+ 'captcha.captcha' => 'Captcha is incorrect',
+ 'email' => 'Email is incorrect',
+ 'mobile' => 'Mobile is incorrect',
+ ];
+ $data = [
+ 'username' => $username,
+ 'password' => $password,
+ 'email' => $email,
+ 'mobile' => $mobile,
+ 'captcha' => $captcha,
+ '__token__' => $token,
+ ];
+ $validate = new Validate($rule, $msg);
+ $result = $validate->check($data);
+ if (!$result)
+ {
+ $this->error(__($validate->getError()));
+ }
+ if ($this->auth->register($username, $password, $email, $mobile))
+ {
+ $synchtml = '';
+ ////////////////同步到Ucenter////////////////
+ if (defined('UC_STATUS') && UC_STATUS)
+ {
+ $uc = new \addons\ucenter\library\client\Client();
+ $synchtml = $uc->uc_user_synregister($this->auth->id, $password);
+ }
+ $this->success(__('Sign up successful') . $synchtml, $url);
+ }
+ else
+ {
+ $this->error($this->auth->getError());
+ }
+ }
+ Session::set('redirect_url', $url);
+ $this->view->assign('title', __('Register'));
+ return $this->view->fetch();
+ }
+
+ /**
+ * 会员登录
+ */
+ public function login()
+ {
+ $url = $this->request->request('url', url('user/index'));
+ if ($this->auth->id)
+ $this->success(__('You\'ve logged in, do not login again'), $url);
+ if ($this->request->isPost())
+ {
+ $account = $this->request->post('account');
+ $password = $this->request->post('password');
+ $keeptime = (int) $this->request->post('keeptime');
+ $token = $this->request->post('__token__');
+ $rule = [
+ 'account' => 'require|length:3,50',
+ 'password' => 'require|length:6,30',
+ '__token__' => 'token',
+ ];
+
+ $msg = [
+ 'account.require' => 'Account can not be empty',
+ 'account.length' => 'Account must be 3 to 50 characters',
+ 'password.require' => 'Password can not be empty',
+ 'password.length' => 'Password must be 6 to 30 characters',
+ ];
+ $data = [
+ 'account' => $account,
+ 'password' => $password,
+ '__token__' => $token,
+ ];
+ $validate = new Validate($rule, $msg);
+ $result = $validate->check($data);
+ if (!$result)
+ {
+ $this->error(__($validate->getError()));
+ return FALSE;
+ }
+ if ($this->auth->login($account, $password, $keeptime))
+ {
+ $synchtml = '';
+ ////////////////同步到Ucenter////////////////
+ if (defined('UC_STATUS') && UC_STATUS)
+ {
+ $uc = new \addons\ucenter\library\client\Client();
+ $synchtml = $uc->uc_user_synlogin($this->auth->id);
+ }
+ $this->success(__('Logged in successful') . $synchtml, $url);
+ }
+ else
+ {
+ $this->error($this->auth->getError());
+ }
+ }
+ $this->view->assign('title', __('Login'));
+ return $this->view->fetch();
+ }
+
+ /**
+ * 注销登录
+ */
+ function logout()
+ {
+ //注销本站
+ $this->auth->logout();
+ $synchtml = '';
+ ////////////////同步到Ucenter////////////////
+ if (defined('UC_STATUS') && UC_STATUS)
+ {
+ $uc = new \addons\ucenter\library\client\Client();
+ $synchtml = $uc->uc_user_synlogout();
+ }
+ $this->success(__('Logout successful') . $synchtml, url('user/index'));
+ }
+
+ /**
+ * 第三方登录跳转和回调处理
+ */
+ public function third()
+ {
+ $url = url('user/index');
+ $action = $this->request->param('action');
+ $platform = $this->request->param('platform');
+ $config = get_addon_config('third');
+ if (!$config || !isset($config[$platform]))
+ {
+ $this->error(__('Invalid parameters'));
+ }
+ foreach ($config as $k => &$v)
+ {
+ $v['callback'] = url('user/third', ['action' => 'callback', 'platform' => $k], false, true);
+ }
+ unset($v);
+ $app = new \addons\third\library\Application($config);
+ if ($action == 'redirect')
+ {
+ // 跳转到登录授权页面
+ $this->redirect($app->{$platform}->getAuthorizeUrl());
+ }
+ else if ($action == 'callback')
+ {
+ // 授权成功后的回调
+ $result = $app->{$platform}->getUserInfo();
+ if ($result)
+ {
+ $loginret = \addons\third\library\Service::connect($platform, $result);
+ if ($loginret)
+ {
+ $synchtml = '';
+ ////////////////同步到Ucenter////////////////
+ if (defined('UC_STATUS') && UC_STATUS)
+ {
+ $uc = new \addons\ucenter\library\client\Client();
+ $synchtml = $uc->uc_user_synlogin($this->auth->id);
+ }
+ $this->success(__('Logged in successful') . $synchtml, $url);
+ }
+ }
+ $this->error(__('Operation failed'), $url);
+ }
+ else
+ {
+ $this->error(__('Invalid parameters'));
+ }
+ }
+
+ /**
+ * 个人信息
+ */
+ public function profile()
+ {
+ $this->view->assign('title', __('Profile'));
+ return $this->view->fetch();
+ }
+
+ /**
+ * 激活邮箱
+ */
+ public function activeemail()
+ {
+ $code = $this->request->request('code');
+ $code = base64_decode($code);
+ parse_str($code, $params);
+ if (!isset($params['id']) || !isset($params['time']) || !isset($params['key']))
+ {
+ $this->error(__('Invalid parameters'));
+ }
+ $user = \app\common\model\User::get($params['id']);
+ if (!$user)
+ {
+ $this->error(__('User not found'));
+ }
+ if ($user->verification->email)
+ {
+ $this->error(__('Email already activation'));
+ }
+ if ($key !== md5(md5($user->id . $user->email . $time) . $user->salt) || time() - $params['time'] > 1800)
+ {
+ $this->error(__('Secrity code already invalid'));
+ }
+ $verification = $user->verification;
+ $verification->email = 1;
+ $user->verification = $verification;
+ $user->save();
+ $this->success(__('Active email successful'), url('user/index'));
+ return;
+ }
+
+ /**
+ * 修改密码
+ */
+ public function changepwd()
+ {
+ if ($this->request->isPost())
+ {
+ $oldpassword = $this->request->post("oldpassword");
+ $newpassword = $this->request->post("newpassword");
+ $renewpassword = $this->request->post("renewpassword");
+ $token = $this->request->post('__token__');
+ $rule = [
+ 'oldpassword' => 'require|length:6,30',
+ 'newpassword' => 'require|length:6,30',
+ 'renewpassword' => 'require|length:6,30|confirm:newpassword',
+ '__token__' => 'token',
+ ];
+
+ $msg = [
+ ];
+ $data = [
+ 'oldpassword' => $oldpassword,
+ 'newpassword' => $newpassword,
+ 'renewpassword' => $renewpassword,
+ '__token__' => $token,
+ ];
+ $field = [
+ 'oldpassword' => __('Old password'),
+ 'newpassword' => __('New password'),
+ 'renewpassword' => __('Renew password')
+ ];
+ $validate = new Validate($rule, $msg, $field);
+ $result = $validate->check($data);
+ if (!$result)
+ {
+ $this->error(__($validate->getError()));
+ return FALSE;
+ }
+
+ $ret = $this->auth->changepwd($newpassword, $oldpassword);
+ if ($ret)
+ {
+ $synchtml = '';
+ ////////////////同步到Ucenter////////////////
+ if (defined('UC_STATUS') && UC_STATUS)
+ {
+ $uc = new \addons\ucenter\library\client\Client();
+ $synchtml = $uc->uc_user_synlogout();
+ }
+ $this->success(__('Reset password successful') . $synchtml, url('user/login'));
+ }
+ else
+ {
+ $this->error($this->auth->getError());
+ }
+ }
+ $this->view->assign('title', __('Change password'));
+ return $this->view->fetch();
+ }
+
+}
diff --git a/public/assets/js/require-backend.min.js b/public/assets/js/require-backend.min.js
index 36b0dae9..91ce44ed 100644
--- a/public/assets/js/require-backend.min.js
+++ b/public/assets/js/require-backend.min.js
@@ -13042,387 +13042,387 @@ define('form',['jquery', 'bootstrap', 'upload', 'validator'], function ($, undef
};
return Form;
});
-// jQuery List DragSort v0.5.2
-// Website: http://dragsort.codeplex.com/
-// License: http://dragsort.codeplex.com/license
-
-(function($) {
-
- $.fn.dragsort = function(options) {
- if (options == "destroy") {
- $(this.selector).trigger("dragsort-uninit");
- return;
- }
-
- var opts = $.extend({}, $.fn.dragsort.defaults, options);
- var lists = [];
- var list = null, lastPos = null;
-
- this.each(function(i, cont) {
-
- //if list container is table, the browser automatically wraps rows in tbody if not specified so change list container to tbody so that children returns rows as user expected
- if ($(cont).is("table") && $(cont).children().size() == 1 && $(cont).children().is("tbody"))
- cont = $(cont).children().get(0);
-
- var newList = {
- draggedItem: null,
- placeHolderItem: null,
- pos: null,
- offset: null,
- offsetLimit: null,
- scroll: null,
- container: cont,
-
- init: function() {
- //set options to default values if not set
- opts.tagName = opts.tagName == "" ? ($(this.container).children().size() == 0 ? "li" : $(this.container).children().get(0).tagName.toLowerCase()) : opts.tagName;
- if (opts.itemSelector == "")
- opts.itemSelector = opts.tagName;
- if (opts.dragSelector == "")
- opts.dragSelector = opts.tagName;
- if (opts.placeHolderTemplate == "")
- opts.placeHolderTemplate = "<" + opts.tagName + "> " + opts.tagName + ">";
-
- //listidx allows reference back to correct list variable instance
- $(this.container).attr("data-listidx", i).mousedown(this.grabItem).bind("dragsort-uninit", this.uninit);
- this.styleDragHandlers(true);
- },
-
- uninit: function() {
- var list = lists[$(this).attr("data-listidx")];
- $(list.container).unbind("mousedown", list.grabItem).unbind("dragsort-uninit");
- list.styleDragHandlers(false);
- },
-
- getItems: function() {
- return $(this.container).children(opts.itemSelector);
- },
-
- styleDragHandlers: function(cursor) {
- this.getItems().map(function() { return $(this).is(opts.dragSelector) ? this : $(this).find(opts.dragSelector).get(); }).css("cursor", cursor ? "pointer" : "");
- },
-
- grabItem: function(e) {
- var list = lists[$(this).attr("data-listidx")];
- var item = $(e.target).closest("[data-listidx] > " + opts.tagName).get(0);
- var insideMoveableItem = list.getItems().filter(function() { return this == item; }).size() > 0;
-
- //if not left click or if clicked on excluded element (e.g. text box) or not a moveable list item return
- if (e.which != 1 || $(e.target).is(opts.dragSelectorExclude) || $(e.target).closest(opts.dragSelectorExclude).size() > 0 || !insideMoveableItem)
- return;
-
- //prevents selection, stops issue on Fx where dragging hyperlink doesn't work and on IE where it triggers mousemove even though mouse hasn't moved,
- //does also stop being able to click text boxes hence dragging on text boxes by default is disabled in dragSelectorExclude
- //e.preventDefault();
-
- //change cursor to move while dragging
- var dragHandle = e.target;
- while (!$(dragHandle).is(opts.dragSelector)) {
- if (dragHandle == this) return;
- dragHandle = dragHandle.parentNode;
- }
- $(dragHandle).attr("data-cursor", $(dragHandle).css("cursor"));
- $(dragHandle).css("cursor", "move");
-
- //on mousedown wait for movement of mouse before triggering dragsort script (dragStart) to allow clicking of hyperlinks to work
- var listElem = this;
- var trigger = function() {
- list.dragStart.call(listElem, e);
- $(list.container).unbind("mousemove", trigger);
- };
- $(list.container).mousemove(trigger).mouseup(function() { $(list.container).unbind("mousemove", trigger); $(dragHandle).css("cursor", $(dragHandle).attr("data-cursor")); });
- },
-
- dragStart: function(e) {
- if (list != null && list.draggedItem != null)
- list.dropItem();
-
- list = lists[$(this).attr("data-listidx")];
- list.draggedItem = $(e.target).closest("[data-listidx] > " + opts.tagName)
-
- //record current position so on dragend we know if the dragged item changed position or not, not using getItems to allow dragsort to restore dragged item to original location in relation to fixed items
- list.draggedItem.attr("data-origpos", $(this).attr("data-listidx") + "-" + $(list.container).children().index(list.draggedItem));
-
- //calculate mouse offset relative to draggedItem
- var mt = parseInt(list.draggedItem.css("marginTop"));
- var ml = parseInt(list.draggedItem.css("marginLeft"));
- list.offset = list.draggedItem.offset();
- list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1;
- list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1;
-
- //calculate box the dragged item can't be dragged outside of
- if (!opts.dragBetween) {
- var containerHeight = $(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + list.getItems().size() * list.draggedItem.outerWidth() / $(list.container).outerWidth())) * list.draggedItem.outerHeight() : $(list.container).outerHeight();
- list.offsetLimit = $(list.container).offset();
- list.offsetLimit.right = list.offsetLimit.left + $(list.container).outerWidth() - list.draggedItem.outerWidth();
- list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight();
- }
-
- //create placeholder item
- var h = list.draggedItem.height();
- var w = list.draggedItem.width();
- if (opts.tagName == "tr") {
- list.draggedItem.children().each(function() { $(this).width($(this).width()); });
- list.placeHolderItem = list.draggedItem.clone().attr("data-placeholder", true);
- list.draggedItem.after(list.placeHolderItem);
- //list.placeHolderItem.children().each(function() { $(this).css({ borderWidth:0, width: $(this).width() + 1, height: $(this).height() + 1 }).html(" "); });
- list.placeHolderItem.children().each(function() { $(this).html(" "); });
- } else {
- list.draggedItem.after(opts.placeHolderTemplate);
- list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeholder", true);
- }
-
- if (opts.tagName == "td") {
- var listTable = list.draggedItem.closest("table").get(0);
- $("
").appendTo("body").children().append(list.draggedItem);
- }
-
- //style draggedItem while dragging
- var orig = list.draggedItem.attr("style");
- list.draggedItem.attr("data-origstyle", orig ? orig : "");
- list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w });
-
- //auto-scroll setup
- list.scroll = { moveX: 0, moveY: 0, maxX: $(document).width() - $(window).width(), maxY: $(document).height() - $(window).height() };
- list.scroll.scrollY = window.setInterval(function() {
- if (opts.scrollContainer != window) {
- $(opts.scrollContainer).scrollTop($(opts.scrollContainer).scrollTop() + list.scroll.moveY);
- return;
- }
- var t = $(opts.scrollContainer).scrollTop();
- if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) {
- $(opts.scrollContainer).scrollTop(t + list.scroll.moveY);
- list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1);
- }
- }, 10);
- list.scroll.scrollX = window.setInterval(function() {
- if (opts.scrollContainer != window) {
- $(opts.scrollContainer).scrollLeft($(opts.scrollContainer).scrollLeft() + list.scroll.moveX);
- return;
- }
- var l = $(opts.scrollContainer).scrollLeft();
- if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) {
- $(opts.scrollContainer).scrollLeft(l + list.scroll.moveX);
- list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1);
- }
- }, 10);
-
- //misc
- $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
- list.setPos(e.pageX, e.pageY);
- $(document).bind("mousemove", list.swapItems);
- $(document).bind("mouseup", list.dropItem);
- if (opts.scrollContainer != window)
- $(window).bind("wheel", list.wheel);
- },
-
- //set position of draggedItem
- setPos: function(x, y) {
- //remove mouse offset so mouse cursor remains in same place on draggedItem instead of top left corner
- var top = y - this.offset.top;
- var left = x - this.offset.left;
-
- //limit top, left to within box draggedItem can't be dragged outside of
- if (!opts.dragBetween) {
- top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top));
- left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left));
- }
-
- //adjust top & left calculations to parent offset
- var parent = this.draggedItem.offsetParent().not("body").offset(); //offsetParent returns body even when it's static, if not static offset is only factoring margin
- if (parent != null) {
- top -= parent.top;
- left -= parent.left;
- }
-
- //set x or y auto-scroll amount
- if (opts.scrollContainer == window) {
- y -= $(window).scrollTop();
- x -= $(window).scrollLeft();
- y = Math.max(0, y - $(window).height() + 5) + Math.min(0, y - 5);
- x = Math.max(0, x - $(window).width() + 5) + Math.min(0, x - 5);
- } else {
- var cont = $(opts.scrollContainer);
- var offset = cont.offset();
- y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top);
- x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left);
- }
-
- list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x);
- list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y);
-
- //move draggedItem to new mouse cursor location
- this.draggedItem.css({ top: top, left: left });
- },
-
- //if scroll container is a div allow mouse wheel to scroll div instead of window when mouse is hovering over
- wheel: function(e) {
- if (list && opts.scrollContainer != window) {
- var cont = $(opts.scrollContainer);
- var offset = cont.offset();
- e = e.originalEvent;
- if (e.clientX > offset.left && e.clientX < offset.left + cont.width() && e.clientY > offset.top && e.clientY < offset.top + cont.height()) {
- var deltaY = (e.deltaMode == 0 ? 1 : 10) * e.deltaY;
- cont.scrollTop(cont.scrollTop() + deltaY);
- e.preventDefault();
- }
- }
- },
-
- //build a table recording all the positions of the moveable list items
- buildPositionTable: function() {
- var pos = [];
- this.getItems().not([list.draggedItem[0], list.placeHolderItem[0]]).each(function(i) {
- var loc = $(this).offset();
- loc.right = loc.left + $(this).outerWidth();
- loc.bottom = loc.top + $(this).outerHeight();
- loc.elm = this;
- pos[i] = loc;
- });
- this.pos = pos;
- },
-
- dropItem: function() {
- if (list.draggedItem == null)
- return;
-
- //list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower
- //list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower)
- var orig = list.draggedItem.attr("data-origstyle");
- list.draggedItem.attr("style", orig);
- if (orig == "")
- list.draggedItem.removeAttr("style");
- list.draggedItem.removeAttr("data-origstyle");
-
- list.styleDragHandlers(true);
-
- list.placeHolderItem.before(list.draggedItem);
- list.placeHolderItem.remove();
-
- $("[data-droptarget], .dragSortItem").remove();
-
- window.clearInterval(list.scroll.scrollY);
- window.clearInterval(list.scroll.scrollX);
-
- //if position changed call dragEnd
- if (list.draggedItem.attr("data-origpos") != $(lists).index(list) + "-" + $(list.container).children().index(list.draggedItem))
- if (opts.dragEnd.apply(list.draggedItem) == false) { //if dragEnd returns false revert order
- var pos = list.draggedItem.attr("data-origpos").split('-');
- var nextItem = $(lists[pos[0]].container).children().not(list.draggedItem).eq(pos[1]);
- if (nextItem.size() > 0)
- nextItem.before(list.draggedItem);
- else if (pos[1] == 0) //was the only item in list
- $(lists[pos[0]].container).prepend(list.draggedItem);
- else //was the last item in list
- $(lists[pos[0]].container).append(list.draggedItem);
- }
- list.draggedItem.removeAttr("data-origpos");
-
- list.draggedItem = null;
- $(document).unbind("mousemove", list.swapItems);
- $(document).unbind("mouseup", list.dropItem);
- if (opts.scrollContainer != window)
- $(window).unbind("wheel", list.wheel);
- return false;
- },
-
- //swap the draggedItem (represented visually by placeholder) with the list item the it has been dragged on top of
- swapItems: function(e) {
- if (list.draggedItem == null)
- return false;
-
- //move draggedItem to mouse location
- list.setPos(e.pageX, e.pageY);
-
- //retrieve list and item position mouse cursor is over
- var ei = list.findPos(e.pageX, e.pageY);
- var nlist = list;
- for (var i = 0; ei == -1 && opts.dragBetween && i < lists.length; i++) {
- ei = lists[i].findPos(e.pageX, e.pageY);
- nlist = lists[i];
- }
-
- //if not over another moveable list item return
- if (ei == -1)
- return false;
-
- //save fixed items locations
- var children = function() { return $(nlist.container).children().not(nlist.draggedItem); };
- var fixed = children().not(opts.itemSelector).each(function(i) { this.idx = children().index(this); });
-
- //if moving draggedItem up or left place placeHolder before list item the dragged item is hovering over otherwise place it after
- if (lastPos == null || lastPos.top > list.draggedItem.offset().top || lastPos.left > list.draggedItem.offset().left)
- $(nlist.pos[ei].elm).before(list.placeHolderItem);
- else
- $(nlist.pos[ei].elm).after(list.placeHolderItem);
-
- //restore fixed items location
- fixed.each(function() {
- var elm = children().eq(this.idx).get(0);
- if (this != elm && children().index(this) < this.idx)
- $(this).insertAfter(elm);
- else if (this != elm)
- $(this).insertBefore(elm);
- });
-
- //misc
- $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
- lastPos = list.draggedItem.offset();
- return false;
- },
-
- //returns the index of the list item the mouse is over
- findPos: function(x, y) {
- for (var i = 0; i < this.pos.length; i++) {
- if (this.pos[i].left < x && this.pos[i].right > x && this.pos[i].top < y && this.pos[i].bottom > y)
- return i;
- }
- return -1;
- },
-
- //create drop targets which are placeholders at the end of other lists to allow dragging straight to the last position
- createDropTargets: function() {
- if (!opts.dragBetween)
- return;
-
- $(lists).each(function() {
- var ph = $(this.container).find("[data-placeholder]");
- var dt = $(this.container).find("[data-droptarget]");
- if (ph.size() > 0 && dt.size() > 0)
- dt.remove();
- else if (ph.size() == 0 && dt.size() == 0) {
- if (opts.tagName == "td")
- $(opts.placeHolderTemplate).attr("data-droptarget", true).appendTo(this.container);
- else
- //list.placeHolderItem.clone().removeAttr("data-placeholder") crashes in IE7 and jquery 1.5.1 (doesn't in jquery 1.4.2 or IE8)
- $(this.container).append(list.placeHolderItem.removeAttr("data-placeholder").clone().attr("data-droptarget", true));
-
- list.placeHolderItem.attr("data-placeholder", true);
- }
- });
- }
- };
-
- newList.init();
- lists.push(newList);
- });
-
- return this;
- };
-
- $.fn.dragsort.defaults = {
- tagName:"",
- itemSelector: "",
- dragSelector: "",
- dragSelectorExclude: "input, textarea",
- dragEnd: function() { },
- dragBetween: false,
- placeHolderTemplate: "",
- scrollContainer: window,
- scrollSpeed: 5
- };
-
-})(jQuery);
+// jQuery List DragSort v0.5.2
+// Website: http://dragsort.codeplex.com/
+// License: http://dragsort.codeplex.com/license
+
+(function($) {
+
+ $.fn.dragsort = function(options) {
+ if (options == "destroy") {
+ $(this.selector).trigger("dragsort-uninit");
+ return;
+ }
+
+ var opts = $.extend({}, $.fn.dragsort.defaults, options);
+ var lists = [];
+ var list = null, lastPos = null;
+
+ this.each(function(i, cont) {
+
+ //if list container is table, the browser automatically wraps rows in tbody if not specified so change list container to tbody so that children returns rows as user expected
+ if ($(cont).is("table") && $(cont).children().size() == 1 && $(cont).children().is("tbody"))
+ cont = $(cont).children().get(0);
+
+ var newList = {
+ draggedItem: null,
+ placeHolderItem: null,
+ pos: null,
+ offset: null,
+ offsetLimit: null,
+ scroll: null,
+ container: cont,
+
+ init: function() {
+ //set options to default values if not set
+ opts.tagName = opts.tagName == "" ? ($(this.container).children().size() == 0 ? "li" : $(this.container).children().get(0).tagName.toLowerCase()) : opts.tagName;
+ if (opts.itemSelector == "")
+ opts.itemSelector = opts.tagName;
+ if (opts.dragSelector == "")
+ opts.dragSelector = opts.tagName;
+ if (opts.placeHolderTemplate == "")
+ opts.placeHolderTemplate = "<" + opts.tagName + "> " + opts.tagName + ">";
+
+ //listidx allows reference back to correct list variable instance
+ $(this.container).attr("data-listidx", i).mousedown(this.grabItem).bind("dragsort-uninit", this.uninit);
+ this.styleDragHandlers(true);
+ },
+
+ uninit: function() {
+ var list = lists[$(this).attr("data-listidx")];
+ $(list.container).unbind("mousedown", list.grabItem).unbind("dragsort-uninit");
+ list.styleDragHandlers(false);
+ },
+
+ getItems: function() {
+ return $(this.container).children(opts.itemSelector);
+ },
+
+ styleDragHandlers: function(cursor) {
+ this.getItems().map(function() { return $(this).is(opts.dragSelector) ? this : $(this).find(opts.dragSelector).get(); }).css("cursor", cursor ? "pointer" : "");
+ },
+
+ grabItem: function(e) {
+ var list = lists[$(this).attr("data-listidx")];
+ var item = $(e.target).closest("[data-listidx] > " + opts.tagName).get(0);
+ var insideMoveableItem = list.getItems().filter(function() { return this == item; }).size() > 0;
+
+ //if not left click or if clicked on excluded element (e.g. text box) or not a moveable list item return
+ if (e.which != 1 || $(e.target).is(opts.dragSelectorExclude) || $(e.target).closest(opts.dragSelectorExclude).size() > 0 || !insideMoveableItem)
+ return;
+
+ //prevents selection, stops issue on Fx where dragging hyperlink doesn't work and on IE where it triggers mousemove even though mouse hasn't moved,
+ //does also stop being able to click text boxes hence dragging on text boxes by default is disabled in dragSelectorExclude
+ //e.preventDefault();
+
+ //change cursor to move while dragging
+ var dragHandle = e.target;
+ while (!$(dragHandle).is(opts.dragSelector)) {
+ if (dragHandle == this) return;
+ dragHandle = dragHandle.parentNode;
+ }
+ $(dragHandle).attr("data-cursor", $(dragHandle).css("cursor"));
+ $(dragHandle).css("cursor", "move");
+
+ //on mousedown wait for movement of mouse before triggering dragsort script (dragStart) to allow clicking of hyperlinks to work
+ var listElem = this;
+ var trigger = function() {
+ list.dragStart.call(listElem, e);
+ $(list.container).unbind("mousemove", trigger);
+ };
+ $(list.container).mousemove(trigger).mouseup(function() { $(list.container).unbind("mousemove", trigger); $(dragHandle).css("cursor", $(dragHandle).attr("data-cursor")); });
+ },
+
+ dragStart: function(e) {
+ if (list != null && list.draggedItem != null)
+ list.dropItem();
+
+ list = lists[$(this).attr("data-listidx")];
+ list.draggedItem = $(e.target).closest("[data-listidx] > " + opts.tagName)
+
+ //record current position so on dragend we know if the dragged item changed position or not, not using getItems to allow dragsort to restore dragged item to original location in relation to fixed items
+ list.draggedItem.attr("data-origpos", $(this).attr("data-listidx") + "-" + $(list.container).children().index(list.draggedItem));
+
+ //calculate mouse offset relative to draggedItem
+ var mt = parseInt(list.draggedItem.css("marginTop"));
+ var ml = parseInt(list.draggedItem.css("marginLeft"));
+ list.offset = list.draggedItem.offset();
+ list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1;
+ list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1;
+
+ //calculate box the dragged item can't be dragged outside of
+ if (!opts.dragBetween) {
+ var containerHeight = $(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + list.getItems().size() * list.draggedItem.outerWidth() / $(list.container).outerWidth())) * list.draggedItem.outerHeight() : $(list.container).outerHeight();
+ list.offsetLimit = $(list.container).offset();
+ list.offsetLimit.right = list.offsetLimit.left + $(list.container).outerWidth() - list.draggedItem.outerWidth();
+ list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight();
+ }
+
+ //create placeholder item
+ var h = list.draggedItem.height();
+ var w = list.draggedItem.width();
+ if (opts.tagName == "tr") {
+ list.draggedItem.children().each(function() { $(this).width($(this).width()); });
+ list.placeHolderItem = list.draggedItem.clone().attr("data-placeholder", true);
+ list.draggedItem.after(list.placeHolderItem);
+ //list.placeHolderItem.children().each(function() { $(this).css({ borderWidth:0, width: $(this).width() + 1, height: $(this).height() + 1 }).html(" "); });
+ list.placeHolderItem.children().each(function() { $(this).html(" "); });
+ } else {
+ list.draggedItem.after(opts.placeHolderTemplate);
+ list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeholder", true);
+ }
+
+ if (opts.tagName == "td") {
+ var listTable = list.draggedItem.closest("table").get(0);
+ $("").appendTo("body").children().append(list.draggedItem);
+ }
+
+ //style draggedItem while dragging
+ var orig = list.draggedItem.attr("style");
+ list.draggedItem.attr("data-origstyle", orig ? orig : "");
+ list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w });
+
+ //auto-scroll setup
+ list.scroll = { moveX: 0, moveY: 0, maxX: $(document).width() - $(window).width(), maxY: $(document).height() - $(window).height() };
+ list.scroll.scrollY = window.setInterval(function() {
+ if (opts.scrollContainer != window) {
+ $(opts.scrollContainer).scrollTop($(opts.scrollContainer).scrollTop() + list.scroll.moveY);
+ return;
+ }
+ var t = $(opts.scrollContainer).scrollTop();
+ if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) {
+ $(opts.scrollContainer).scrollTop(t + list.scroll.moveY);
+ list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1);
+ }
+ }, 10);
+ list.scroll.scrollX = window.setInterval(function() {
+ if (opts.scrollContainer != window) {
+ $(opts.scrollContainer).scrollLeft($(opts.scrollContainer).scrollLeft() + list.scroll.moveX);
+ return;
+ }
+ var l = $(opts.scrollContainer).scrollLeft();
+ if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) {
+ $(opts.scrollContainer).scrollLeft(l + list.scroll.moveX);
+ list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1);
+ }
+ }, 10);
+
+ //misc
+ $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
+ list.setPos(e.pageX, e.pageY);
+ $(document).bind("mousemove", list.swapItems);
+ $(document).bind("mouseup", list.dropItem);
+ if (opts.scrollContainer != window)
+ $(window).bind("wheel", list.wheel);
+ },
+
+ //set position of draggedItem
+ setPos: function(x, y) {
+ //remove mouse offset so mouse cursor remains in same place on draggedItem instead of top left corner
+ var top = y - this.offset.top;
+ var left = x - this.offset.left;
+
+ //limit top, left to within box draggedItem can't be dragged outside of
+ if (!opts.dragBetween) {
+ top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top));
+ left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left));
+ }
+
+ //adjust top & left calculations to parent offset
+ var parent = this.draggedItem.offsetParent().not("body").offset(); //offsetParent returns body even when it's static, if not static offset is only factoring margin
+ if (parent != null) {
+ top -= parent.top;
+ left -= parent.left;
+ }
+
+ //set x or y auto-scroll amount
+ if (opts.scrollContainer == window) {
+ y -= $(window).scrollTop();
+ x -= $(window).scrollLeft();
+ y = Math.max(0, y - $(window).height() + 5) + Math.min(0, y - 5);
+ x = Math.max(0, x - $(window).width() + 5) + Math.min(0, x - 5);
+ } else {
+ var cont = $(opts.scrollContainer);
+ var offset = cont.offset();
+ y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top);
+ x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left);
+ }
+
+ list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x);
+ list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y);
+
+ //move draggedItem to new mouse cursor location
+ this.draggedItem.css({ top: top, left: left });
+ },
+
+ //if scroll container is a div allow mouse wheel to scroll div instead of window when mouse is hovering over
+ wheel: function(e) {
+ if (list && opts.scrollContainer != window) {
+ var cont = $(opts.scrollContainer);
+ var offset = cont.offset();
+ e = e.originalEvent;
+ if (e.clientX > offset.left && e.clientX < offset.left + cont.width() && e.clientY > offset.top && e.clientY < offset.top + cont.height()) {
+ var deltaY = (e.deltaMode == 0 ? 1 : 10) * e.deltaY;
+ cont.scrollTop(cont.scrollTop() + deltaY);
+ e.preventDefault();
+ }
+ }
+ },
+
+ //build a table recording all the positions of the moveable list items
+ buildPositionTable: function() {
+ var pos = [];
+ this.getItems().not([list.draggedItem[0], list.placeHolderItem[0]]).each(function(i) {
+ var loc = $(this).offset();
+ loc.right = loc.left + $(this).outerWidth();
+ loc.bottom = loc.top + $(this).outerHeight();
+ loc.elm = this;
+ pos[i] = loc;
+ });
+ this.pos = pos;
+ },
+
+ dropItem: function() {
+ if (list.draggedItem == null)
+ return;
+
+ //list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower
+ //list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower)
+ var orig = list.draggedItem.attr("data-origstyle");
+ list.draggedItem.attr("style", orig);
+ if (orig == "")
+ list.draggedItem.removeAttr("style");
+ list.draggedItem.removeAttr("data-origstyle");
+
+ list.styleDragHandlers(true);
+
+ list.placeHolderItem.before(list.draggedItem);
+ list.placeHolderItem.remove();
+
+ $("[data-droptarget], .dragSortItem").remove();
+
+ window.clearInterval(list.scroll.scrollY);
+ window.clearInterval(list.scroll.scrollX);
+
+ //if position changed call dragEnd
+ if (list.draggedItem.attr("data-origpos") != $(lists).index(list) + "-" + $(list.container).children().index(list.draggedItem))
+ if (opts.dragEnd.apply(list.draggedItem) == false) { //if dragEnd returns false revert order
+ var pos = list.draggedItem.attr("data-origpos").split('-');
+ var nextItem = $(lists[pos[0]].container).children().not(list.draggedItem).eq(pos[1]);
+ if (nextItem.size() > 0)
+ nextItem.before(list.draggedItem);
+ else if (pos[1] == 0) //was the only item in list
+ $(lists[pos[0]].container).prepend(list.draggedItem);
+ else //was the last item in list
+ $(lists[pos[0]].container).append(list.draggedItem);
+ }
+ list.draggedItem.removeAttr("data-origpos");
+
+ list.draggedItem = null;
+ $(document).unbind("mousemove", list.swapItems);
+ $(document).unbind("mouseup", list.dropItem);
+ if (opts.scrollContainer != window)
+ $(window).unbind("wheel", list.wheel);
+ return false;
+ },
+
+ //swap the draggedItem (represented visually by placeholder) with the list item the it has been dragged on top of
+ swapItems: function(e) {
+ if (list.draggedItem == null)
+ return false;
+
+ //move draggedItem to mouse location
+ list.setPos(e.pageX, e.pageY);
+
+ //retrieve list and item position mouse cursor is over
+ var ei = list.findPos(e.pageX, e.pageY);
+ var nlist = list;
+ for (var i = 0; ei == -1 && opts.dragBetween && i < lists.length; i++) {
+ ei = lists[i].findPos(e.pageX, e.pageY);
+ nlist = lists[i];
+ }
+
+ //if not over another moveable list item return
+ if (ei == -1)
+ return false;
+
+ //save fixed items locations
+ var children = function() { return $(nlist.container).children().not(nlist.draggedItem); };
+ var fixed = children().not(opts.itemSelector).each(function(i) { this.idx = children().index(this); });
+
+ //if moving draggedItem up or left place placeHolder before list item the dragged item is hovering over otherwise place it after
+ if (lastPos == null || lastPos.top > list.draggedItem.offset().top || lastPos.left > list.draggedItem.offset().left)
+ $(nlist.pos[ei].elm).before(list.placeHolderItem);
+ else
+ $(nlist.pos[ei].elm).after(list.placeHolderItem);
+
+ //restore fixed items location
+ fixed.each(function() {
+ var elm = children().eq(this.idx).get(0);
+ if (this != elm && children().index(this) < this.idx)
+ $(this).insertAfter(elm);
+ else if (this != elm)
+ $(this).insertBefore(elm);
+ });
+
+ //misc
+ $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
+ lastPos = list.draggedItem.offset();
+ return false;
+ },
+
+ //returns the index of the list item the mouse is over
+ findPos: function(x, y) {
+ for (var i = 0; i < this.pos.length; i++) {
+ if (this.pos[i].left < x && this.pos[i].right > x && this.pos[i].top < y && this.pos[i].bottom > y)
+ return i;
+ }
+ return -1;
+ },
+
+ //create drop targets which are placeholders at the end of other lists to allow dragging straight to the last position
+ createDropTargets: function() {
+ if (!opts.dragBetween)
+ return;
+
+ $(lists).each(function() {
+ var ph = $(this.container).find("[data-placeholder]");
+ var dt = $(this.container).find("[data-droptarget]");
+ if (ph.size() > 0 && dt.size() > 0)
+ dt.remove();
+ else if (ph.size() == 0 && dt.size() == 0) {
+ if (opts.tagName == "td")
+ $(opts.placeHolderTemplate).attr("data-droptarget", true).appendTo(this.container);
+ else
+ //list.placeHolderItem.clone().removeAttr("data-placeholder") crashes in IE7 and jquery 1.5.1 (doesn't in jquery 1.4.2 or IE8)
+ $(this.container).append(list.placeHolderItem.removeAttr("data-placeholder").clone().attr("data-droptarget", true));
+
+ list.placeHolderItem.attr("data-placeholder", true);
+ }
+ });
+ }
+ };
+
+ newList.init();
+ lists.push(newList);
+ });
+
+ return this;
+ };
+
+ $.fn.dragsort.defaults = {
+ tagName:"",
+ itemSelector: "",
+ dragSelector: "",
+ dragSelectorExclude: "input, textarea",
+ dragEnd: function() { },
+ dragBetween: false,
+ placeHolderTemplate: "",
+ scrollContainer: window,
+ scrollSpeed: 5
+ };
+
+})(jQuery);
define("dragsort", function(){});
@@ -13442,201 +13442,201 @@ define("drag", function(){});
;(function(d){d.fn.drop=function(i,e,h){var g=typeof i=="string"?i:"",f=d.isFunction(i)?i:d.isFunction(e)?e:null;if(g.indexOf("drop")!==0){g="drop"+g}h=(i==f?e:h)||{};return f?this.bind(g,h,f):this.trigger(g)};d.drop=function(e){e=e||{};b.multi=e.multi===true?Infinity:e.multi===false?1:!isNaN(e.multi)?e.multi:b.multi;b.delay=e.delay||b.delay;b.tolerance=d.isFunction(e.tolerance)?e.tolerance:e.tolerance===null?null:b.tolerance;b.mode=e.mode||b.mode||"intersect"};var c=d.event,a=c.special,b=d.event.special.drop={multi:1,delay:20,mode:"overlap",targets:[],datakey:"dropdata",noBubble:true,add:function(f){var e=d.data(this,b.datakey);e.related+=1},remove:function(){d.data(this,b.datakey).related-=1},setup:function(){if(d.data(this,b.datakey)){return}var e={related:0,active:[],anyactive:0,winner:0,location:{}};d.data(this,b.datakey,e);b.targets.push(this);return false},teardown:function(){var f=d.data(this,b.datakey)||{};if(f.related){return}d.removeData(this,b.datakey);var e=this;b.targets=d.grep(b.targets,function(g){return(g!==e)})},handler:function(g,e){var f,h;if(!e){return}switch(g.type){case"mousedown":case"touchstart":h=d(b.targets);if(typeof e.drop=="string"){h=h.filter(e.drop)}h.each(function(){var i=d.data(this,b.datakey);i.active=[];i.anyactive=0;i.winner=0});e.droppable=h;a.drag.hijack(g,"dropinit",e);break;case"mousemove":case"touchmove":b.event=g;if(!b.timer){b.tolerate(e)}break;case"mouseup":case"touchend":b.timer=clearTimeout(b.timer);if(e.propagates){a.drag.hijack(g,"drop",e);a.drag.hijack(g,"dropend",e)}break}},locate:function(k,h){var l=d.data(k,b.datakey),g=d(k),i=g.offset()||{},e=g.outerHeight(),j=g.outerWidth(),f={elem:k,width:j,height:e,top:i.top,left:i.left,right:i.left+j,bottom:i.top+e};if(l){l.location=f;l.index=h;l.elem=k}return f},contains:function(e,f){return((f[0]||f.left)>=e.left&&(f[0]||f.right)<=e.right&&(f[1]||f.top)>=e.top&&(f[1]||f.bottom)<=e.bottom)},modes:{intersect:function(f,e,g){return this.contains(g,[f.pageX,f.pageY])?1000000000:this.modes.overlap.apply(this,arguments)},overlap:function(f,e,g){return Math.max(0,Math.min(g.bottom,e.bottom)-Math.max(g.top,e.top))*Math.max(0,Math.min(g.right,e.right)-Math.max(g.left,e.left))},fit:function(f,e,g){return this.contains(g,e)?1:0},middle:function(f,e,g){return this.contains(g,[e.left+e.width*0.5,e.top+e.height*0.5])?1:0}},sort:function(f,e){return(e.winner-f.winner)||(f.index-e.index)},tolerate:function(q){var k,e,n,j,l,m,g,p=0,f,h=q.interactions.length,r=[b.event.pageX,b.event.pageY],o=b.tolerance||b.modes[b.mode];do{if(f=q.interactions[p]){if(!f){return}f.drop=[];l=[];m=f.droppable.length;if(o){n=b.locate(f.proxy)}k=0;do{if(g=f.droppable[k]){j=d.data(g,b.datakey);e=j.location;if(!e){continue}j.winner=o?o.call(b,b.event,n,e):b.contains(e,r)?1:0;l.push(j)}}while(++k -1 ? "&" : "?") + "ref=addtabs") : url;
- window.history.pushState(state, title, pushurl);
- }
- $(this).data("pushstate", null);
- _add.call(this, {
- id: id,
- title: $(this).attr('title') ? $(this).attr('title') : $(this).html(),
- content: content,
- url: url,
- ajax: ajax
- });
- }
- });
-
- navobj.on('click', '.close-tab', function (e) {
- id = $(this).prev("a").attr("aria-controls");
- _close(id);
- return false;
- });
- navobj.on('dblclick', 'li[role=presentation]', function (e) {
- $(this).find(".close-tab").trigger("click");
- });
- navobj.on('click', 'li[role=presentation]', function (e) {
- $("a[addtabs=" + $("a", this).attr("node-id") + "]").trigger("click");
- });
-
- $(window).resize(function () {
- $("#nav").width($("#header > .navbar").width() - $(".sidebar-toggle").outerWidth() - $(".navbar-custom-menu").outerWidth() - 20);
- _drop();
- });
-
- _add = function (opts) {
- var id, tabid, conid, url;
- id = opts.id;
- tabid = 'tab_' + opts.id;
- conid = 'con_' + opts.id;
- url = opts.url;
- url += (opts.url.indexOf("?") > -1 ? "&addtabs=1" : "?addtabs=1");
- navobj.find("[role='presentation']").removeClass('active');
- tabobj.find("[role='tabpanel']").removeClass('active');
- //如果TAB不存在,创建一个新的TAB
- if ($("#" + tabid).size() == 0) {
- //创建新TAB的title
- title = $('' + opts.title + '');
- //是否允许关闭
- if (options.close && $("li", navobj).size() > 0) {
- title.append(' ');
- }
- //创建新TAB的内容
- content = $('');
- //是否指定TAB内容
- if (opts.content) {
- content.append(opts.content);
- } else if (options.iframeUse && !opts.ajax) {//没有内容,使用IFRAME打开链接
- var height = options.iframeHeight;
- content.append('');
- } else {
- $.get(url, function (data) {
- content.append(data);
- });
- }
- //加入TABS
- if ($('.tabdrop li').size() > 0) {
- $('.tabdrop ul').append(title);
- } else {
- navobj.append(title);
- }
- tabobj.append(content);
- } else {
- //强制刷新iframe
- if (options.iframeForceRefresh) {
- $("#" + conid + " iframe").attr('src', function (i, val) {
- return val;
- });
- }
- }
- localStorage.setItem("addtabs", $(this).prop('outerHTML'));
- //激活TAB
- $("#" + tabid).addClass('active');
- $("#" + conid).addClass("active");
- _drop();
- };
-
- _close = function (id) {
- var tabid = 'tab_' + id;
- var conid = 'con_' + id;
- //如果关闭的是当前激活的TAB,激活他的前一个TAB
- if (obj.find("li.active").not('.tabdrop').attr('id') == tabid) {
- if ($("#" + tabid).prev().not(".tabdrop").size() > 0) {
- $("#" + tabid).prev().not(".tabdrop").find("a").trigger("click");
- } else if ($("#" + tabid).next().size() > 0) {
- $("#" + tabid).next().trigger("click");
- } else {
- $(">li:last > a", navobj).trigger('click');
- }
- }
- //关闭TAB
- $("#" + tabid).remove();
- $("#" + conid).remove();
- _drop();
- options.callback();
- };
-
- _drop = function () {
- //创建下拉标签
- var dropdown = $('' +
- '' +
- ' ');
- //检测是否已增加
- if (!$('.tabdrop').html()) {
- dropdown.prependTo(navobj);
- } else {
- dropdown = navobj.find('.tabdrop');
- }
- //检测是否有下拉样式
- if (navobj.parent().is('.tabs-below')) {
- dropdown.addClass('dropup');
- }
- var collection = 0;
-
- var maxwidth = navobj.width() - 60;
-
- var liwidth = 0;
- //检查超过一行的标签页
- var litabs = navobj.append(dropdown.find('li')).find('>li').not('.tabdrop');
- var lisize = litabs.size();
- litabs.each(function (i, j) {
- liwidth += $(this).width();
- if (collection == 0 && i == lisize - 1 && liwidth <= navobj.width()) {
- return true;
- }
- if (liwidth > maxwidth) {
- dropdown.find('ul').append($(this));
- collection++;
- }
- });
- //如果有超出的,显示下拉标签
- if (collection > 0) {
- dropdown.removeClass('hide');
- if (dropdown.find('.active').length == 1) {
- dropdown.addClass('active');
- } else {
- dropdown.removeClass('active');
- }
- } else {
- dropdown.addClass('hide');
- }
- };
-};
+/**
+ * http://git.oschina.net/hbbcs/bootStrap-addTabs
+ * Created by joe on 2015-12-19.
+ */
+$.fn.addtabs = function (options) {
+ var obj = $(this);
+ options = $.extend({
+ content: '', //直接指定所有页面TABS内容
+ close: true, //是否可以关闭
+ monitor: 'body', //监视的区域
+ nav: '.nav-addtabs',
+ tab: '.tab-addtabs',
+ iframeUse: true, //使用iframe还是ajax
+ iframeHeight: $(window).height() - 50, //固定TAB中IFRAME高度,根据需要自己修改
+ iframeForceRefresh: false, //点击后强制刷新对应的iframe
+ callback: function () {
+ //关闭后回调函数
+ }
+ }, options || {});
+ var navobj = $(options.nav);
+ var tabobj = $(options.tab);
+ if (history.pushState) {
+ //浏览器前进后退事件
+ $(window).on("popstate", function (e) {
+ var state = e.originalEvent.state;
+ if (state) {
+ $("a[addtabs=" + state.id + "]", options.monitor).data("pushstate", true).trigger("click");
+ }
+ });
+ }
+ $(options.monitor).on('click', '[addtabs]', function (e) {
+ if ($(this).attr('url').indexOf("javascript:") !== 0) {
+ if ($(this).is("a")) {
+ e.preventDefault();
+ }
+ var id = $(this).attr('addtabs');
+ var title = $(this).attr('title') ? $(this).attr('title') : $.trim($(this).text());
+ var url = $(this).attr('url');
+ var content = options.content ? options.content : $(this).attr('content');
+ var ajax = $(this).attr('ajax') ? true : false;
+ var state = ({
+ url: url, title: title, id: id, content: content, ajax: ajax
+ });
+
+ document.title = title;
+ if (history.pushState && !$(this).data("pushstate")) {
+ var pushurl = url.indexOf("ref=addtabs") == -1 ? (url + (url.indexOf("?") > -1 ? "&" : "?") + "ref=addtabs") : url;
+ window.history.pushState(state, title, pushurl);
+ }
+ $(this).data("pushstate", null);
+ _add.call(this, {
+ id: id,
+ title: $(this).attr('title') ? $(this).attr('title') : $(this).html(),
+ content: content,
+ url: url,
+ ajax: ajax
+ });
+ }
+ });
+
+ navobj.on('click', '.close-tab', function (e) {
+ id = $(this).prev("a").attr("aria-controls");
+ _close(id);
+ return false;
+ });
+ navobj.on('dblclick', 'li[role=presentation]', function (e) {
+ $(this).find(".close-tab").trigger("click");
+ });
+ navobj.on('click', 'li[role=presentation]', function (e) {
+ $("a[addtabs=" + $("a", this).attr("node-id") + "]").trigger("click");
+ });
+
+ $(window).resize(function () {
+ $("#nav").width($("#header > .navbar").width() - $(".sidebar-toggle").outerWidth() - $(".navbar-custom-menu").outerWidth() - 20);
+ _drop();
+ });
+
+ _add = function (opts) {
+ var id, tabid, conid, url;
+ id = opts.id;
+ tabid = 'tab_' + opts.id;
+ conid = 'con_' + opts.id;
+ url = opts.url;
+ url += (opts.url.indexOf("?") > -1 ? "&addtabs=1" : "?addtabs=1");
+ navobj.find("[role='presentation']").removeClass('active');
+ tabobj.find("[role='tabpanel']").removeClass('active');
+ //如果TAB不存在,创建一个新的TAB
+ if ($("#" + tabid).size() == 0) {
+ //创建新TAB的title
+ title = $('' + opts.title + '');
+ //是否允许关闭
+ if (options.close && $("li", navobj).size() > 0) {
+ title.append(' ');
+ }
+ //创建新TAB的内容
+ content = $('');
+ //是否指定TAB内容
+ if (opts.content) {
+ content.append(opts.content);
+ } else if (options.iframeUse && !opts.ajax) {//没有内容,使用IFRAME打开链接
+ var height = options.iframeHeight;
+ content.append('');
+ } else {
+ $.get(url, function (data) {
+ content.append(data);
+ });
+ }
+ //加入TABS
+ if ($('.tabdrop li').size() > 0) {
+ $('.tabdrop ul').append(title);
+ } else {
+ navobj.append(title);
+ }
+ tabobj.append(content);
+ } else {
+ //强制刷新iframe
+ if (options.iframeForceRefresh) {
+ $("#" + conid + " iframe").attr('src', function (i, val) {
+ return val;
+ });
+ }
+ }
+ localStorage.setItem("addtabs", $(this).prop('outerHTML'));
+ //激活TAB
+ $("#" + tabid).addClass('active');
+ $("#" + conid).addClass("active");
+ _drop();
+ };
+
+ _close = function (id) {
+ var tabid = 'tab_' + id;
+ var conid = 'con_' + id;
+ //如果关闭的是当前激活的TAB,激活他的前一个TAB
+ if (obj.find("li.active").not('.tabdrop').attr('id') == tabid) {
+ if ($("#" + tabid).prev().not(".tabdrop").size() > 0) {
+ $("#" + tabid).prev().not(".tabdrop").find("a").trigger("click");
+ } else if ($("#" + tabid).next().size() > 0) {
+ $("#" + tabid).next().trigger("click");
+ } else {
+ $(">li:last > a", navobj).trigger('click');
+ }
+ }
+ //关闭TAB
+ $("#" + tabid).remove();
+ $("#" + conid).remove();
+ _drop();
+ options.callback();
+ };
+
+ _drop = function () {
+ //创建下拉标签
+ var dropdown = $('' +
+ '' +
+ ' ');
+ //检测是否已增加
+ if (!$('.tabdrop').html()) {
+ dropdown.prependTo(navobj);
+ } else {
+ dropdown = navobj.find('.tabdrop');
+ }
+ //检测是否有下拉样式
+ if (navobj.parent().is('.tabs-below')) {
+ dropdown.addClass('dropup');
+ }
+ var collection = 0;
+
+ var maxwidth = navobj.width() - 60;
+
+ var liwidth = 0;
+ //检查超过一行的标签页
+ var litabs = navobj.append(dropdown.find('li')).find('>li').not('.tabdrop');
+ var lisize = litabs.size();
+ litabs.each(function (i, j) {
+ liwidth += $(this).width();
+ if (collection == 0 && i == lisize - 1 && liwidth <= navobj.width()) {
+ return true;
+ }
+ if (liwidth > maxwidth) {
+ dropdown.find('ul').append($(this));
+ collection++;
+ }
+ });
+ //如果有超出的,显示下拉标签
+ if (collection > 0) {
+ dropdown.removeClass('hide');
+ if (dropdown.find('.active').length == 1) {
+ dropdown.addClass('active');
+ } else {
+ dropdown.removeClass('active');
+ }
+ } else {
+ dropdown.addClass('hide');
+ }
+ };
+};
define("addtabs", function(){});