-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,373 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace jDate; | ||
|
||
use yii\helpers\Json; | ||
use yii\base\Model; | ||
use yii\base\InvalidConfigException; | ||
use yii\helpers\Html; | ||
/** | ||
* Jalali date & time. | ||
* @author Mohammad Mahdi Gholomian. | ||
* @copyright 2014 [email protected] | ||
*/ | ||
class DatePicker extends \yii\base\Widget | ||
{ | ||
/** | ||
* @var Model the data model that this widget is associated with. | ||
*/ | ||
public $model; | ||
/** | ||
* @var string the model attribute that this widget is associated with. | ||
*/ | ||
public $attribute; | ||
/** | ||
* @var string the input name. This must be set if [[model]] and [[attribute]] are not set. | ||
*/ | ||
public $name; | ||
/** | ||
* @var string the input value. | ||
*/ | ||
public $value; | ||
/** | ||
* @var array Input options. | ||
*/ | ||
public $options = []; | ||
/** | ||
* @var array Date picker options. | ||
*/ | ||
public $clientOptions = ['formatDate' => "YYYY/0M/0D"]; | ||
|
||
public function init() | ||
{ | ||
parent::init(); | ||
if (!isset($this->options['id'])) { | ||
$this->options['id'] = $this->getId(); | ||
} | ||
if (!$this->hasModel() && $this->name === null) { | ||
throw new InvalidConfigException("Either 'name', or 'model' and 'attribute' properties must be specified."); | ||
} | ||
if ($this->hasModel() && !isset($this->options['id'])) { | ||
$this->options['id'] = Html::getInputId($this->model, $this->attribute); | ||
} | ||
} | ||
|
||
function run() | ||
{ | ||
$this->registerAsset(); | ||
|
||
echo $this->renderInput(); | ||
|
||
$this->renderJsCode(); | ||
} | ||
/** | ||
* Register datepicker asset into view. | ||
*/ | ||
function registerAsset() | ||
{ | ||
DatePickerAsset::register($this->getView()); | ||
} | ||
/** | ||
* Render input. | ||
*/ | ||
function renderInput() | ||
{ | ||
if ($this->hasModel()) { | ||
return Html::activeTextInput($this->model, $this->attribute, $this->options); | ||
} else { | ||
return Html::textInput($this->name, $this->value, $this->options); | ||
} | ||
} | ||
/** | ||
* Render Js code. | ||
*/ | ||
function renderJsCode() | ||
{ | ||
$name = 'persianDatepicker'; | ||
$id = $this->options['id']; | ||
$options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions); | ||
$js = "jQuery('#$id').$name($options);"; | ||
$this->getView()->registerJs($js); | ||
} | ||
/** | ||
* @return boolean whether this widget is associated with a data model. | ||
*/ | ||
protected function hasModel() | ||
{ | ||
return $this->model instanceof Model && $this->attribute !== null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace jDate; | ||
|
||
use yii\web\AssetBundle; | ||
|
||
/** | ||
* @author Mohammad Mahdi Gholomian. | ||
* @copyright 2014 [email protected] | ||
*/ | ||
class DatePickerAsset extends AssetBundle | ||
{ | ||
public $sourcePath = '@vendor/mohammad-mahdy/yii2-jdate/assets'; | ||
public $js = [ | ||
'js/persianDatepicker.min.js', | ||
]; | ||
public $css = [ | ||
'css/persianDatepicker-default.css', | ||
]; | ||
public $depends = [ | ||
'yii\web\JqueryAsset', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2013 Mohammad hasan Behzadi | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
##[Demos and information](http://mbehzadi.com/persianDatepicker "mbehzadi.com") | ||
|
||
##About | ||
|
||
persianDatepicker is A lightweight jQuery plugin that select persian(jalali) date. | ||
|
||
- **Browsers:** >IE8, Chrome, Firefox, safari, opera | ||
- **Light weight:** ~14k minified | ||
- **Beautiful themes:** default, dark | ||
- **Size and font:** set the size (width & height) and fontsize for datepicker cells | ||
- **Show persian numbers:** (۰ - ۹) | ||
- **Select gregorian date:** (good way to convert jalali date to gregorian date) | ||
- **Multi formatting date:** like ("YYYY/0M/DD hh:ss") becomes like **1392/07/22 16:45** | ||
- **Selectable months and years:** [1, 3, 4, 12] | ||
|
||
|
||
##Usage | ||
1- include jQuery & persianDatepicker.js & persianDatepicker.css | ||
```html | ||
<link type="text/css" rel="stylesheet" href="css/persianDatepicker.css" /> | ||
<script type="text/javascript" src="js/jquery-1.10.1.min.js"></script> | ||
<script type="text/javascript" src="js/persianDatepicker.min.js"></script> | ||
``` | ||
2- add your html element (input or span or etc) | ||
```html | ||
<input type="text" id="input1" /> | ||
<span id="span1"></span> | ||
``` | ||
3- call the persianDatepicker plugin | ||
```html | ||
<script type="text/javascript"> | ||
$(function() { | ||
$("#input1, #span1").persianDatepicker(); | ||
}); | ||
</script> | ||
``` | ||
|
||
|
||
##Options | ||
To customize persian datepicker, simply pass in an options object: (defaults shown) | ||
```javascript | ||
$("#input1")persianDatePicker({ | ||
months: ["فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند"], | ||
dowTitle: ["شنبه", "یکشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنج شنبه", "جمعه"], | ||
shortDowTitle: ["ش", "ی", "د", "س", "چ", "پ", "ج"], | ||
showGregorianDate: false, | ||
persianNumbers: true, | ||
formatDate: "YYYY/MM/DD", | ||
prevArrow: '\u25c4', | ||
nextArrow: '\u25ba', | ||
theme: 'default', | ||
alwaysShow: false, | ||
selectableYears: null, | ||
selectableMonths: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], | ||
cellWidth: 25, | ||
cellHeight: 20, | ||
fontSize: 13, | ||
isRTL: false, | ||
calendarPosition: { | ||
x: 0, | ||
y: 0, | ||
}, | ||
onShow: function(calendar) { | ||
calendar.show(); | ||
}, | ||
onHide: function(calendar) { | ||
calendar.hide(); | ||
}, | ||
}); | ||
``` | ||
|
||
##Credit | ||
Created by [@kharabati](http://twitter.com/kharabati "@kharabati"), [blog](http://mbehzadi.com/ "mbehzadi.com") | ||
|
||
use, share , fork , enjoy! , ... |
Oops, something went wrong.