Index: trunk/extensions/SemanticFormsInputs/SemanticFormsInputs.php |
— | — | @@ -45,7 +45,7 @@ |
46 | 46 | class SFISettings { |
47 | 47 | // general settings |
48 | 48 | public $scriptPath; |
49 | | - public $yuiBase; |
| 49 | + //public $yuiBase; |
50 | 50 | |
51 | 51 | // settings for input type datepicker |
52 | 52 | public $datePickerFirstDate; |
— | — | @@ -73,6 +73,7 @@ |
74 | 74 | $sfgFormPrinter->setInputTypeHook( 'datepicker', array( 'SFIInputs', 'jqDatePickerHTML' ), array() ); |
75 | 75 | $sfgFormPrinter->setInputTypeHook( 'simpledatepicker', array( 'SFIInputs', 'jqDatePickerHTML' ), array() ); |
76 | 76 | $sfgFormPrinter->setInputTypeHook( 'timepicker', array( 'SFIInputs', 'timepickerHTML' ), array() ); |
| 77 | + $sfgFormPrinter->setInputTypeHook( 'datetimepicker', array( 'SFIInputs', 'datetimepickerHTML' ), array() ); |
77 | 78 | // $sfgFormPrinter->setInputTypeHook( 'wysiwyg', array( 'SFIInputs', 'wysiwygHTML' ), array() ); |
78 | 79 | $sfgFormPrinter->setInputTypeHook( 'menuselect', array( 'SFIInputs', 'menuselectHTML' ), array() ); |
79 | 80 | |
Index: trunk/extensions/SemanticFormsInputs/images/DateTimePickerResetButtonDisabled.gif |
Cannot display: file marked as a binary type. |
svn:mime-type = image/gif |
Property changes on: trunk/extensions/SemanticFormsInputs/images/DateTimePickerResetButtonDisabled.gif |
___________________________________________________________________ |
Added: svn:mime-type |
80 | 81 | + image/gif |
Index: trunk/extensions/SemanticFormsInputs/images/DateTimePickerResetButton.gif |
Cannot display: file marked as a binary type. |
svn:mime-type = image/gif |
Property changes on: trunk/extensions/SemanticFormsInputs/images/DateTimePickerResetButton.gif |
___________________________________________________________________ |
Added: svn:mime-type |
81 | 82 | + image/gif |
Index: trunk/extensions/SemanticFormsInputs/SFI_Settings.php |
— | — | @@ -159,3 +159,10 @@ |
160 | 160 | # |
161 | 161 | $sfigSettings->timePickerShowResetButton = false; |
162 | 162 | |
| 163 | + |
| 164 | +## |
| 165 | +# This determines if a reset button shall be shown. This is the only |
| 166 | +# way to erase the input field if it is disabled for direct input. |
| 167 | +# |
| 168 | +$sfigSettings->datetimePickerShowResetButton = false; |
| 169 | + |
Index: trunk/extensions/SemanticFormsInputs/skins/SFI_Timepicker.css |
— | — | @@ -6,9 +6,9 @@ |
7 | 7 | */ |
8 | 8 | |
9 | 9 | .SFI_timepicker { |
10 | | - display: block; |
11 | 10 | position: absolute; |
12 | 11 | cursor: default; |
| 12 | + margin-top: 22px; |
13 | 13 | } |
14 | 14 | |
15 | 15 | .SFI_timepicker ul { /* hours and minutes lists */ |
Index: trunk/extensions/SemanticFormsInputs/SFI_Inputs.php |
— | — | @@ -9,8 +9,8 @@ |
10 | 10 | * |
11 | 11 | */ |
12 | 12 | |
13 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
14 | | - die( 'This file is a MediaWiki extension, it is not a valid entry point.' ); |
| 13 | +if ( !defined( 'SFI_VERSION' ) ) { |
| 14 | + die( 'This file is part of a MediaWiki extension, it is not a valid entry point.' ); |
15 | 15 | } |
16 | 16 | |
17 | 17 | class SFIInputs { |
— | — | @@ -111,19 +111,15 @@ |
112 | 112 | /** |
113 | 113 | * Definition of input type "regexp" |
114 | 114 | * |
115 | | - * Returns an array containing three elements: the html code and the JS code |
116 | | - * to be included in the page and the name of a JS function to be called to |
117 | | - * initialize the input. |
| 115 | + * Returns the html code to be included in the page and registers the |
| 116 | + * input's JS initialisation method |
118 | 117 | * |
119 | | - * These values are all taken from the base input type, the JS for the |
120 | | - * regexp is written to the code directly. |
121 | | - * |
122 | 118 | * @param string $cur_value current value of this field (which is sometimes null) |
123 | 119 | * @param string $input_name HTML name that this input should have |
124 | 120 | * @param boolean $is_mandatory indicates whether this field is mandatory for the user |
125 | 121 | * @param boolean $is_disabled indicates whether this field is disabled (meaning, the user can't edit) |
126 | 122 | * @param array $other_args hash representing all the other properties defined for this input in the form definition |
127 | | - * @return array of two strings |
| 123 | + * @return string html code of input |
128 | 124 | */ |
129 | 125 | static function regexpHTML ( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
130 | 126 | |
— | — | @@ -458,17 +454,15 @@ |
459 | 455 | /** |
460 | 456 | * Definition of input type "datepicker". |
461 | 457 | * |
462 | | - * Returns an array containing three elements: the html code to be included |
463 | | - * in the page, an empty string (instead of JS initialization code, which is |
464 | | - * inserted into the page directly) and the name of a JS function to be |
465 | | - * called to initialize the input. |
| 458 | + * Returns the html code to be included in the page and registers the |
| 459 | + * input's JS initialisation method |
466 | 460 | * |
467 | 461 | * @param string $cur_value current value of this field (which is sometimes null) |
468 | 462 | * @param string $input_name HTML name that this input should have |
469 | 463 | * @param boolean $is_mandatory indicates whether this field is mandatory for the user |
470 | 464 | * @param boolean $is_disabled indicates whether this field is disabled (meaning, the user can't edit) |
471 | 465 | * @param array $other_args hash representing all the other properties defined for this input in the form definition |
472 | | - * @return array of three strings |
| 466 | + * @return string html code of input |
473 | 467 | */ |
474 | 468 | static function jqDatePickerHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
475 | 469 | |
— | — | @@ -499,9 +493,96 @@ |
500 | 494 | || ( !array_key_exists( 'enable input field', $other_args ) && $sfigSettings->datePickerDisableInputField ) |
501 | 495 | || $is_disabled ; |
502 | 496 | |
503 | | - // second: set up JS attributes, but only if we need them |
504 | | - if ( !$is_disabled ) { |
| 497 | + // second: set up JS attributes |
505 | 498 | |
| 499 | + // set up attributes required for both enabled and disabled datepickers |
| 500 | + $jsattribs = array( |
| 501 | + 'currValue' => $cur_value, |
| 502 | + 'disabled' => $is_disabled, |
| 503 | + 'userClasses' => $userClasses |
| 504 | + ); |
| 505 | + |
| 506 | + if ( array_key_exists( 'part of dtp', $other_args ) ) { |
| 507 | + $jsattribs['partOfDTP'] = $other_args['part of dtp']; |
| 508 | + } |
| 509 | + |
| 510 | + // set date format |
| 511 | + // SHORT and LONG are SFI specific acronyms and are translated here |
| 512 | + // into format strings, anything else is passed to the jQuery date picker |
| 513 | + // Americans need special treatment |
| 514 | + if ( $wgAmericanDates && $wgLang->getCode() == "en" ) { |
| 515 | + |
| 516 | + if ( array_key_exists( 'date format', $other_args ) ) { |
| 517 | + |
| 518 | + if ( $other_args['date format'] == 'SHORT' ) { |
| 519 | + $jsattribs['dateFormat'] = 'mm/dd/yy'; |
| 520 | + } elseif ( $other_args['date format'] == 'LONG' ) { |
| 521 | + $jsattribs['dateFormat'] = 'MM d, yy'; |
| 522 | + } else { |
| 523 | + $jsattribs['dateFormat'] = $other_args['date format']; |
| 524 | + } |
| 525 | + |
| 526 | + } elseif ( $sfigSettings->datePickerDateFormat ) { |
| 527 | + |
| 528 | + if ( $sfigSettings->datePickerDateFormat == 'SHORT' ) { |
| 529 | + $jsattribs['dateFormat'] = 'mm/dd/yy'; |
| 530 | + } elseif ( $sfigSettings->datePickerDateFormat == 'LONG' ) { |
| 531 | + $jsattribs['dateFormat'] = 'MM d, yy'; |
| 532 | + } else { |
| 533 | + $jsattribs['dateFormat'] = $sfigSettings->datePickerDateFormat; |
| 534 | + } |
| 535 | + |
| 536 | + } else $jsattribs['dateFormat'] = 'yy/mm/dd'; |
| 537 | + |
| 538 | + } else { |
| 539 | + |
| 540 | + if ( array_key_exists( 'date format', $other_args ) ) { |
| 541 | + |
| 542 | + if ( $other_args['date format'] == 'SHORT' ) { |
| 543 | + $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatshort' ); |
| 544 | + } elseif ( $other_args['date format'] == 'LONG' ) { |
| 545 | + $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatlong' ); |
| 546 | + } else { |
| 547 | + $jsattribs['dateFormat'] = $other_args['date format']; |
| 548 | + } |
| 549 | + |
| 550 | + } elseif ( $sfigSettings->datePickerDateFormat ) { |
| 551 | + |
| 552 | + if ( $sfigSettings->datePickerDateFormat == 'SHORT' ) { |
| 553 | + $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatshort' ); |
| 554 | + } elseif ( $sfigSettings->datePickerDateFormat == 'LONG' ) { |
| 555 | + $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatlong' ); |
| 556 | + } else { |
| 557 | + $jsattribs['dateFormat'] = $sfigSettings->datePickerDateFormat; |
| 558 | + } |
| 559 | + |
| 560 | + } else $jsattribs['dateFormat'] = 'yy/mm/dd'; |
| 561 | + |
| 562 | + } |
| 563 | + |
| 564 | + // setup attributes required only for either disabled or enabled datepickers |
| 565 | + if ( $is_disabled ) { |
| 566 | + |
| 567 | + $jsattribs['buttonImage'] = $sfigSettings->scriptPath . '/images/DatePickerButtonDisabled.gif'; |
| 568 | + |
| 569 | + if ( array_key_exists( 'show reset button', $other_args ) || |
| 570 | + ( !array_key_exists( 'hide reset button', $other_args ) && $sfigSettings->datePickerShowResetButton ) ) { |
| 571 | + |
| 572 | + $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DatePickerResetButtonDisabled.gif'; |
| 573 | + |
| 574 | + } |
| 575 | + |
| 576 | + } else { |
| 577 | + |
| 578 | + $jsattribs['buttonImage'] = $sfigSettings->scriptPath . '/images/DatePickerButton.gif'; |
| 579 | + |
| 580 | + if ( array_key_exists( 'show reset button', $other_args ) || |
| 581 | + ( !array_key_exists( 'hide reset button', $other_args ) && $sfigSettings->datePickerShowResetButton ) ) { |
| 582 | + |
| 583 | + $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DatePickerResetButton.gif'; |
| 584 | + |
| 585 | + } |
| 586 | + |
506 | 587 | // find min date, max date and disabled dates |
507 | 588 | |
508 | 589 | // set first date |
— | — | @@ -640,12 +721,6 @@ |
641 | 722 | $highlightedDays = null; |
642 | 723 | } |
643 | 724 | |
644 | | - // set datepicker widget attributes |
645 | | - $jsattribs = array( |
646 | | - 'currValue' => $cur_value, |
647 | | - 'buttonImage' => $sfigSettings->scriptPath . '/images/DatePickerButton.gif', |
648 | | - ); |
649 | | - |
650 | 725 | // set first day of the week |
651 | 726 | if ( array_key_exists( 'week start', $other_args ) ) { |
652 | 727 | $jsattribs['firstDay'] = $other_args['week start']; |
— | — | @@ -664,243 +739,190 @@ |
665 | 740 | $jsattribs['showWeek'] = false; |
666 | 741 | } |
667 | 742 | |
668 | | - // set date format |
669 | | - // SHORT and LONG are SFI specific acronyms and are translated here |
670 | | - // into format strings, anything else is passed to the jQuery date picker |
671 | | - // Americans need special treatment |
672 | | - if ( $wgAmericanDates && $wgLang->getCode() == "en" ) { |
| 743 | + // store min date as JS attrib |
| 744 | + if ( $minDate ) { |
| 745 | + $jsattribs['minDate'] = $minDate->format( 'Y/m/d' ); |
| 746 | + } |
673 | 747 | |
674 | | - if ( array_key_exists( 'date format', $other_args ) ) { |
| 748 | + // store max date as JS attrib |
| 749 | + if ( $maxDate ) { |
| 750 | + $jsattribs['maxDate'] = $maxDate->format( 'Y/m/d' ); |
| 751 | + } |
675 | 752 | |
676 | | - if ( $other_args['date format'] == 'SHORT' ) { |
677 | | - $jsattribs['dateFormat'] = 'mm/dd/yy'; |
678 | | - } elseif ( $other_args['date format'] == 'LONG' ) { |
679 | | - $jsattribs['dateFormat'] = 'MM d, yy'; |
680 | | - } else { |
681 | | - $jsattribs['dateFormat'] = $other_args['date format']; |
682 | | - } |
| 753 | + // register disabled dates with datepicker |
| 754 | + if ( count( $disabledDates ) > 0 ) { |
683 | 755 | |
684 | | - } elseif ( $sfigSettings->datePickerDateFormat ) { |
| 756 | + // convert the PHP array of date ranges into an array of numbers |
| 757 | + $jsattribs["disabledDates"] = array_map( create_function ( '$range', ' |
685 | 758 | |
686 | | - if ( $sfigSettings->datePickerDateFormat == 'SHORT' ) { |
687 | | - $jsattribs['dateFormat'] = 'mm/dd/yy'; |
688 | | - } elseif ( $sfigSettings->datePickerDateFormat == 'LONG' ) { |
689 | | - $jsattribs['dateFormat'] = 'MM d, yy'; |
690 | | - } else { |
691 | | - $jsattribs['dateFormat'] = $sfigSettings->datePickerDateFormat; |
692 | | - } |
| 759 | + $y0 = $range[0]->format( "Y" ); |
| 760 | + $m0 = $range[0]->format( "m" ) - 1; |
| 761 | + $d0 = $range[0]->format( "d" ); |
693 | 762 | |
694 | | - } else $jsattribs['dateFormat'] = 'yy/mm/dd'; |
| 763 | + $y1 = $range[1]->format( "Y" ); |
| 764 | + $m1 = $range[1]->format( "m" ) - 1; |
| 765 | + $d1 = $range[1]->format( "d" ); |
695 | 766 | |
696 | | - } else { |
| 767 | + return array($y0, $m0, $d0, $y1, $m1, $d1); |
| 768 | + ' ) , $disabledDates ); |
| 769 | + } |
697 | 770 | |
698 | | - if ( array_key_exists( 'date format', $other_args ) ) { |
| 771 | + // register highlighted dates with datepicker |
| 772 | + if ( count( $highlightedDates ) > 0 ) { |
699 | 773 | |
700 | | - if ( $other_args['date format'] == 'SHORT' ) { |
701 | | - $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatshort' ); |
702 | | - } elseif ( $other_args['date format'] == 'LONG' ) { |
703 | | - $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatlong' ); |
704 | | - } else { |
705 | | - $jsattribs['dateFormat'] = $other_args['date format']; |
706 | | - } |
| 774 | + // convert the PHP array of date ranges into an array of numbers |
| 775 | + $jsattribs["highlightedDates"] = array_map( create_function ( '$range', ' |
707 | 776 | |
708 | | - } elseif ( $sfigSettings->datePickerDateFormat ) { |
| 777 | + $y0 = $range[0]->format( "Y" ); |
| 778 | + $m0 = $range[0]->format( "m" ) - 1; |
| 779 | + $d0 = $range[0]->format( "d" ); |
709 | 780 | |
710 | | - if ( $sfigSettings->datePickerDateFormat == 'SHORT' ) { |
711 | | - $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatshort' ); |
712 | | - } elseif ( $sfigSettings->datePickerDateFormat == 'LONG' ) { |
713 | | - $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatlong' ); |
714 | | - } else { |
715 | | - $jsattribs['dateFormat'] = $sfigSettings->datePickerDateFormat; |
716 | | - } |
| 781 | + $y1 = $range[1]->format( "Y" ); |
| 782 | + $m1 = $range[1]->format( "m" ) - 1; |
| 783 | + $d1 = $range[1]->format( "d" ); |
717 | 784 | |
718 | | - } else $jsattribs['dateFormat'] = 'yy/mm/dd'; |
| 785 | + return array($y0, $m0, $d0, $y1, $m1, $d1); |
| 786 | + ' ) , $highlightedDates ); |
| 787 | + } |
719 | 788 | |
| 789 | + // register disabled days of week with datepicker |
| 790 | + if ( count( $disabledDays ) > 0 ) { |
| 791 | + $jsattribs["disabledDays"] = $disabledDays; |
720 | 792 | } |
721 | 793 | |
| 794 | + // register highlighted days of week with datepicker |
| 795 | + if ( count( $highlightedDays ) > 0 ) { |
| 796 | + $jsattribs["highlightedDays"] = $highlightedDays; |
| 797 | + } |
722 | 798 | } |
723 | 799 | |
724 | 800 | |
725 | 801 | // third: assemble HTML and JS code |
726 | 802 | |
727 | | - if ( $is_disabled ) { |
| 803 | + // start with the displayed input and append the real, but hidden |
| 804 | + // input that gets sent to SF; it will be filled by the datepicker |
| 805 | + $html = self::textHTML( $cur_value, "", $is_mandatory, $inputFieldDisabled, |
| 806 | + $other_args, "input_{$sfgFieldNum}_dp_show", null, "createboxInput" ); |
728 | 807 | |
729 | | - // if the input field is disabled, create a mockup without functionality |
| 808 | + if ( ! array_key_exists( 'part of dtp', $other_args ) ) { |
730 | 809 | |
731 | | - // first create a simple text input and an inert button |
732 | | - $html = self::textHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args, null, null, "createboxInput" ) |
733 | | - |
734 | | - . Xml::element( "button", |
| 810 | + $html .= Xml::element( "input", |
735 | 811 | array( |
736 | | - 'type' => 'button', |
737 | | - 'class' => $userClasses, |
738 | | - 'disabled' => '1', |
739 | | - 'id' => "input_{$sfgFieldNum}_button" |
740 | | - ) ) |
| 812 | + "id" => "input_{$sfgFieldNum}", |
| 813 | + "name" => $input_name, |
| 814 | + "type" => "hidden", |
| 815 | + "value" => $cur_value |
| 816 | + ) ); |
741 | 817 | |
742 | | - . Xml::element( "image", |
743 | | - array( |
744 | | - 'src' => $sfigSettings->scriptPath . '/images/DatePickerButtonDisabled.gif' |
745 | | - ) ) |
| 818 | + // wrap in span (e.g. used for mandatory inputs) |
| 819 | + $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>'; |
| 820 | + } |
746 | 821 | |
747 | | - . Xml::closeElement( "button" ); |
| 822 | + // build JS code from attributes array |
| 823 | + $jsattribsString = Xml::encodeJsVar( $jsattribs ); |
748 | 824 | |
749 | | - // append reset button if required |
750 | | - if ( array_key_exists( 'show reset button', $other_args ) || |
751 | | - $sfigSettings->datePickerShowResetButton && !array_key_exists( 'hide reset button', $other_args ) ) { |
| 825 | + // wrap the JS code fragment in a function for deferred init |
| 826 | + $jstext = <<<JAVASCRIPT |
| 827 | +jQuery(function(){ jQuery('#input_{$sfgFieldNum}_dp_show').registerInitialisation(SFI_DP_init, $jsattribsString ); }); |
| 828 | +JAVASCRIPT; |
752 | 829 | |
753 | | - $html .= Xml::openElement( "button", |
754 | | - array( |
755 | | - 'type' => 'button', |
756 | | - 'class' => $userClasses, |
757 | | - 'disabled' => '1', |
758 | | - 'id' => "input_{$sfgFieldNum}_resetbutton" |
759 | | - ) ) |
| 830 | + // insert the code of the JS init function into the pages code |
| 831 | + $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' ); |
760 | 832 | |
761 | | - . Xml::element( "image", |
762 | | - array( |
763 | | - 'src' => $sfigSettings->scriptPath . '/images/DatePickerResetButtonDisabled.gif' |
764 | | - ) ) |
| 833 | + //return array( $html, "", "initInput$sfgFieldNum" ); |
| 834 | + return $html; |
765 | 835 | |
766 | | - . Xml::closeElement( "button" ); |
| 836 | + } |
767 | 837 | |
768 | | - } |
| 838 | + /** |
| 839 | + * Setup for input type jqdatepicker. |
| 840 | + * |
| 841 | + * Adds the Javascript code used by all datetimepickers. |
| 842 | + */ |
| 843 | + static private function datetimePickerSetup () { |
769 | 844 | |
770 | | - // no JS needed on a disabled datepicker |
771 | | - $jstext = ''; |
| 845 | + global $wgOut, $sfigSettings; |
772 | 846 | |
773 | | - } else { |
| 847 | + static $hasRun = false; |
774 | 848 | |
775 | | - // start with the displayed input and append the real, but hidden |
776 | | - // input that gets sent to SF; it will be filled by the datepicker |
777 | | - $html = self::textHTML( $cur_value, "", $is_mandatory, $inputFieldDisabled, |
778 | | - $other_args, "input_{$sfgFieldNum}_show", null, "createboxInput" ) |
| 849 | + if ( !$hasRun ) { |
| 850 | + $hasRun = true; |
779 | 851 | |
780 | | - . Xml::element( "input", |
781 | | - array( |
782 | | - "id" => "input_{$sfgFieldNum}", |
783 | | - "name" => $input_name, |
784 | | - "type" => "hidden" |
785 | | - ) ); |
| 852 | + $wgOut->addScript( '<script type="text/javascript" src="' . $sfigSettings->scriptPath . '/libs/datetimepicker.js"></script> ' ); |
786 | 853 | |
787 | | - // append reset button if required |
788 | | - if ( array_key_exists( 'show reset button', $other_args ) || |
789 | | - ( !array_key_exists( 'hide reset button', $other_args ) && $sfigSettings->datePickerShowResetButton ) ) { |
| 854 | + } |
| 855 | + } |
790 | 856 | |
791 | | - // can not use Xml::element, it would sanitize the onclick attribute |
792 | | - $html .= "<button " |
793 | | - . Xml::expandAttributes ( array( |
794 | | - 'type' => 'button', |
795 | | - 'class' => $userClasses, |
796 | | - 'id' => "input_{$sfgFieldNum}_resetbutton", |
797 | | - ) ) |
798 | | - . "onclick= \"\n" |
799 | | - . "document.getElementById(this.id.replace('_resetbutton','')).value='';" |
800 | | - . "document.getElementById(this.id.replace('_resetbutton','_show')).value='';" |
801 | | - . "\"" |
802 | | - . ">" |
| 857 | + /** |
| 858 | + * Definition of input type "datetimepicker". |
| 859 | + * |
| 860 | + * Returns the html code to be included in the page and registers the |
| 861 | + * input's JS initialisation method |
| 862 | + * |
| 863 | + * @param string $cur_value current value of this field (which is sometimes null) |
| 864 | + * @param string $input_name HTML name that this input should have |
| 865 | + * @param boolean $is_mandatory indicates whether this field is mandatory for the user |
| 866 | + * @param boolean $is_disabled indicates whether this field is disabled (meaning, the user can't edit) |
| 867 | + * @param array $other_args hash representing all the other properties defined for this input in the form definition |
| 868 | + * @return string html code of input |
| 869 | + */ |
| 870 | + static function datetimepickerHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { |
803 | 871 | |
804 | | - . Xml::element( "image", |
805 | | - array( |
806 | | - 'src' => $sfigSettings->scriptPath . '/images/DatePickerResetButton.gif' |
807 | | - ) ) |
| 872 | + global $wgOut, $sfgFieldNum, $sfigSettings; |
808 | 873 | |
809 | | - . Xml::closeElement( "button" ); |
| 874 | + self::datetimePickerSetup(); |
810 | 875 | |
811 | | - } |
| 876 | + $other_args["part of dtp"] = true; |
812 | 877 | |
813 | | - // sanitize current value before putting it into the JS code |
814 | | - $cur_value = Xml::escapeJsString( $cur_value ); |
| 878 | + $jsAttribs = array(); |
815 | 879 | |
816 | | - // build JS code from attributes array |
817 | | - $jsattribsString = Xml::encodeJsVar( $jsattribs ); |
| 880 | + // if we have to show a reset button |
| 881 | + if ( array_key_exists( 'show reset button', $other_args ) || |
| 882 | + ( !array_key_exists( 'hide reset button', $other_args ) && $sfigSettings->datetimePickerShowResetButton ) ) { |
818 | 883 | |
819 | | - // store min date as JS attrib |
820 | | - if ( $minDate ) { |
821 | | - $jsattribs['minDate'] = $minDate->format( 'Y/m/d' ); |
822 | | - } |
| 884 | + // some values must be available to the init function |
823 | 885 | |
824 | | - // store max date as JS attrib |
825 | | - if ( $maxDate ) { |
826 | | - $jsattribs['maxDate'] = $maxDate->format( 'Y/m/d' ); |
827 | | - } |
| 886 | + // is the button disabled? |
| 887 | + $jsattribs['disabled'] = $is_disabled; |
828 | 888 | |
829 | | - |
830 | | - // add user-defined class(es) to all datepicker components |
831 | | - if ( array_key_exists( 'class', $other_args ) ) { |
832 | | - $jsattribs['userClass'] = $userClasses; |
| 889 | + // set the button image |
| 890 | + if ( $is_disabled ) { |
| 891 | + $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DateTimePickerResetButtonDisabled.gif'; |
| 892 | + } else { |
| 893 | + $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DateTimePickerResetButton.gif'; |
833 | 894 | } |
834 | 895 | |
835 | | - // attach event handler to handle disabled and highlighted dates |
836 | | - if ( count( $disabledDates ) || count( $highlightedDates ) || count( $disabledDays ) || count( $highlightedDays ) ) { |
| 896 | + // set user classes |
| 897 | + if ( array_key_exists( 'class', $other_args ) ) $jsattribs[ "userClasses" ] = $other_args['class']; |
| 898 | + else $jsattribs[ "userClasses" ] = ""; |
837 | 899 | |
838 | | - // first register disabled dates with datepicker |
839 | | - if ( count( $disabledDates ) ) { |
| 900 | + } |
840 | 901 | |
841 | | - // convert the PHP array of date ranges into a JS array definition |
842 | | - $jsattribs["disabledDates"] = array_map( create_function ( '$range', ' |
| 902 | + // build JS code from attributes array |
| 903 | + $jsattribsString = Xml::encodeJsVar( $jsattribs ); |
843 | 904 | |
844 | | - $y0 = $range[0]->format( "Y" ); |
845 | | - $m0 = $range[0]->format( "m" ) - 1; |
846 | | - $d0 = $range[0]->format( "d" ); |
847 | | - |
848 | | - $y1 = $range[1]->format( "Y" ); |
849 | | - $m1 = $range[1]->format( "m" ) - 1; |
850 | | - $d1 = $range[1]->format( "d" ); |
851 | | - |
852 | | - return array($y0, $m0, $d0, $y1, $m1, $d1); |
853 | | - ' ) , $disabledDates ); |
854 | | - } |
855 | | - |
856 | | - // then register highlighted dates with datepicker |
857 | | - if ( count( $highlightedDates ) > 0 ) { |
858 | | - |
859 | | - // convert the PHP array of date ranges into a JS array definition |
860 | | - $jsattribs["highlightedDates"] = array_map( create_function ( '$range', ' |
861 | | - |
862 | | - $y0 = $range[0]->format( "Y" ); |
863 | | - $m0 = $range[0]->format( "m" ) - 1; |
864 | | - $d0 = $range[0]->format( "d" ); |
865 | | - |
866 | | - $y1 = $range[1]->format( "Y" ); |
867 | | - $m1 = $range[1]->format( "m" ) - 1; |
868 | | - $d1 = $range[1]->format( "d" ); |
869 | | - |
870 | | - return array($y0, $m0, $d0, $y1, $m1, $d1); |
871 | | - ' ) , $highlightedDates ); |
872 | | - } |
873 | | - |
874 | | - // register disabled days of week with datepicker |
875 | | - if ( count( $disabledDays ) ) { |
876 | | - $jsattribs["disabledDays"] = $disabledDays; |
877 | | - } |
878 | | - |
879 | | - // register highlighted days of week with datepicker |
880 | | - if ( count( $highlightedDays ) ) { |
881 | | - $jsattribs["highlightedDays"] = $highlightedDays; |
882 | | - } |
883 | | - } |
884 | | - |
885 | | - // build JS code from attributes array |
886 | | - $jsattribsString = Xml::encodeJsVar( $jsattribs ); |
887 | | - |
888 | | - // wrap the JS code fragment in a function for deferred init |
889 | | - $jstext = <<<JAVASCRIPT |
890 | | -jQuery(function(){ jQuery('#input_$sfgFieldNum').registerInitialisation(SFI_DP_init, $jsattribsString ); }); |
| 905 | + $jstext = <<<JAVASCRIPT |
| 906 | +jQuery(function(){ jQuery('#input_$sfgFieldNum').registerInitialisation(SFI_DTP_init, $jsattribsString ); }); |
891 | 907 | JAVASCRIPT; |
892 | 908 | |
893 | | - |
894 | | - } |
895 | | - |
896 | | - // wrap in span (e.g. used for mandatory inputs) |
897 | | - $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>'; |
898 | | - |
899 | 909 | // insert the code of the JS init function into the pages code |
900 | | - $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' ); |
| 910 | + $wgOut->addScript('<script type="text/javascript">' . $jstext . '</script>'); |
901 | 911 | |
902 | | - return array( $html, "", "initInput$sfgFieldNum" ); |
| 912 | + $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' . |
| 913 | + self::jqDatePickerHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) . " " . |
| 914 | + self::timepickerHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) . |
| 915 | + Xml::element("input", |
| 916 | + array( |
| 917 | + "id" => "input_{$sfgFieldNum}", |
| 918 | + "name" => $input_name, |
| 919 | + "type" => "hidden", |
| 920 | + "value" => $cur_value |
| 921 | + )) |
| 922 | + . '</span>'; |
903 | 923 | |
| 924 | + return $html; |
904 | 925 | } |
| 926 | + |
905 | 927 | // |
906 | 928 | // static function wysiwygSetup() { |
907 | 929 | // |
— | — | @@ -963,17 +985,15 @@ |
964 | 986 | /** |
965 | 987 | * Definition of input type "timepicker" |
966 | 988 | * |
967 | | - * Returns an array containing three elements: the html code to be included |
968 | | - * in the page, an empty string (instead of JS initialization code, which is |
969 | | - * inserted into the page directly) and the name of a JS function to be |
970 | | - * called to initialize the input. |
| 989 | + * Returns the html code to be included in the page and registers the |
| 990 | + * input's JS initialisation method |
971 | 991 | * |
972 | 992 | * @param string $cur_value current value of this field (which is sometimes null) |
973 | 993 | * @param string $input_name HTML name that this input should have |
974 | 994 | * @param boolean $is_mandatory indicates whether this field is mandatory for the user |
975 | 995 | * @param boolean $is_disabled indicates whether this field is disabled (meaning, the user can't edit) |
976 | 996 | * @param array $other_args hash representing all the other properties defined for this input in the form definition |
977 | | - * @return array of three strings |
| 997 | + * @return string html code of input |
978 | 998 | */ |
979 | 999 | static function timepickerHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
980 | 1000 | |
— | — | @@ -999,13 +1019,16 @@ |
1000 | 1020 | |
1001 | 1021 | // second: assemble HTML |
1002 | 1022 | // create visible input field (for display) and invisible field (for data) |
1003 | | - $html = self::textHTML( $cur_value, '', $is_mandatory, $inputFieldDisabled, $other_args, "input_{$sfgFieldNum}_show", null, "createboxInput" ) |
1004 | | - . Xml::element( "input", array( |
| 1023 | + $html = self::textHTML( $cur_value, '', $is_mandatory, $inputFieldDisabled, $other_args, "input_{$sfgFieldNum}_tp_show", null, "createboxInput" ); |
| 1024 | + |
| 1025 | + if ( ! array_key_exists( 'part of dtp', $other_args ) ) { |
| 1026 | + $html .= Xml::element( "input", array( |
1005 | 1027 | 'id' => "input_{$sfgFieldNum}", |
1006 | 1028 | 'type' => 'hidden', |
1007 | 1029 | 'name' => $input_name, |
1008 | 1030 | 'value' => $cur_value |
1009 | 1031 | ) ); |
| 1032 | + } |
1010 | 1033 | |
1011 | 1034 | // append time picker button |
1012 | 1035 | if ( $is_disabled ) { |
— | — | @@ -1034,7 +1057,7 @@ |
1035 | 1058 | 'class' => 'createboxInput ' . $userClasses, |
1036 | 1059 | 'name' => "button", |
1037 | 1060 | ) ) |
1038 | | - . "onclick=\"document.getElementById(this.id.replace('_button','_show')).focus();\"" |
| 1061 | + . "onclick=\"document.getElementById(this.id.replace('_button','_tp_show')).focus();\"" |
1039 | 1062 | . ">" |
1040 | 1063 | |
1041 | 1064 | . Xml::element( |
— | — | @@ -1047,8 +1070,11 @@ |
1048 | 1071 | } |
1049 | 1072 | |
1050 | 1073 | // append reset button (if selected) |
1051 | | - if ( array_key_exists( 'show reset button', $other_args ) || |
1052 | | - $sfigSettings->timePickerShowResetButton && !array_key_exists( 'hide reset button', $other_args ) ) { |
| 1074 | + if ( ! array_key_exists( 'part of dtp', $other_args ) && |
| 1075 | + ( array_key_exists( 'show reset button', $other_args ) || |
| 1076 | + $sfigSettings->timePickerShowResetButton && !array_key_exists( 'hide reset button', $other_args ) |
| 1077 | + ) |
| 1078 | + ) { |
1053 | 1079 | |
1054 | 1080 | if ( $is_disabled ) { |
1055 | 1081 | |
— | — | @@ -1077,7 +1103,7 @@ |
1078 | 1104 | 'name' => "resetbutton", |
1079 | 1105 | ) ) |
1080 | 1106 | . "onclick=\"document.getElementById(this.id.replace('_resetbutton','')).value='';" |
1081 | | - . "document.getElementById(this.id.replace('_resetbutton','_show')).value='';\"" |
| 1107 | + . "document.getElementById(this.id.replace('_resetbutton','_tp_show')).value='';\"" |
1082 | 1108 | . ">" |
1083 | 1109 | |
1084 | 1110 | . Xml::element( |
— | — | @@ -1091,7 +1117,9 @@ |
1092 | 1118 | } |
1093 | 1119 | |
1094 | 1120 | // wrap in span (e.g. used for mandatory inputs) |
1095 | | - $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>'; |
| 1121 | + if ( ! array_key_exists( 'part of dtp', $other_args ) ) { |
| 1122 | + $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>'; |
| 1123 | + } |
1096 | 1124 | |
1097 | 1125 | // third: if the timepicker is not disabled set up JS attributes ans assemble JS call |
1098 | 1126 | if ( !$is_disabled ) { |
— | — | @@ -1123,29 +1151,32 @@ |
1124 | 1152 | } |
1125 | 1153 | |
1126 | 1154 | // build JS code from attributes array |
1127 | | - $jstext = Xml::encodeJsVar( array( |
| 1155 | + $jsattribs = array( |
1128 | 1156 | "minTime" => $minTime, |
1129 | 1157 | "maxTime" => $maxTime, |
1130 | 1158 | "interval" => $interval, |
1131 | 1159 | "format" => "hh:mm" |
1132 | | - ) ); |
| 1160 | + ); |
1133 | 1161 | |
| 1162 | + if ( array_key_exists( 'part of dtp', $other_args ) ) { |
| 1163 | + $jsattribs['partOfDTP'] = $other_args['part of dtp']; |
| 1164 | + } |
| 1165 | + |
| 1166 | + $jstext = Xml::encodeJsVar( $jsattribs ); |
| 1167 | + |
1134 | 1168 | $jstext = <<<JAVASCRIPT |
1135 | | -jQuery(function(){ jQuery('#input_$sfgFieldNum').registerInitialisation(SFI_TP_init, $jstext ); }); |
| 1169 | +jQuery(function(){ jQuery('#input_{$sfgFieldNum}_tp_show').registerInitialisation(SFI_TP_init, $jstext ); }); |
1136 | 1170 | JAVASCRIPT; |
1137 | 1171 | |
1138 | 1172 | // write JS code directly to the page's code |
1139 | 1173 | $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' ); |
1140 | 1174 | |
1141 | 1175 | // return HTML and name of JS init function |
1142 | | - return $html; |
1143 | 1176 | |
1144 | | - } else { |
| 1177 | + } |
1145 | 1178 | |
1146 | | - return $html; |
| 1179 | + return $html; |
1147 | 1180 | |
1148 | | - } |
1149 | | - |
1150 | 1181 | } |
1151 | 1182 | |
1152 | 1183 | /** |
— | — | @@ -1172,10 +1203,15 @@ |
1173 | 1204 | /** |
1174 | 1205 | * Definition of input type "menuselect" |
1175 | 1206 | * |
1176 | | - * Returns an array containing two elements: the html text to be included |
1177 | | - * and an empty string (no JS code necessary) |
| 1207 | + * Returns the html code to be included in the page and registers the |
| 1208 | + * input's JS initialisation method |
1178 | 1209 | * |
1179 | | - * @return array of two strings |
| 1210 | + * @param string $cur_value current value of this field (which is sometimes null) |
| 1211 | + * @param string $input_name HTML name that this input should have |
| 1212 | + * @param boolean $is_mandatory indicates whether this field is mandatory for the user |
| 1213 | + * @param boolean $is_disabled indicates whether this field is disabled (meaning, the user can't edit) |
| 1214 | + * @param array $other_args hash representing all the other properties defined for this input in the form definition |
| 1215 | + * @return string html code of input |
1180 | 1216 | */ |
1181 | 1217 | static function menuselectHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
1182 | 1218 | global $wgParser, $wgUser, $wgTitle, $wgOut; |
Index: trunk/extensions/SemanticFormsInputs/libs/datetimepicker.js |
— | — | @@ -0,0 +1,37 @@ |
| 2 | +/** |
| 3 | + * Javascript code to be used with input type datepicker. |
| 4 | + * |
| 5 | + * @author Stephan Gambke |
| 6 | + * @version 0.4 alpha |
| 7 | + * |
| 8 | + */ |
| 9 | + |
| 10 | + |
| 11 | +function SFI_DTP_init ( input_id, params ) { |
| 12 | + |
| 13 | + var dp = jQuery( "#" + input_id + "_dp_show"); // datepicker element |
| 14 | + var tp = jQuery( "#" + input_id + "_tp_show"); // timepicker element |
| 15 | + |
| 16 | + jQuery( "#" + input_id + "_dp_show, #" + input_id + "_tp_show" ).change (function(){ |
| 17 | + jQuery( "#" + input_id ).attr("value", |
| 18 | + jQuery.datepicker.formatDate( dp.datepicker("option", "altFormat"), dp.datepicker("getDate"), null ) + |
| 19 | + " " + tp.attr( "value" ) |
| 20 | + ); |
| 21 | + }) |
| 22 | + |
| 23 | + if ( params.resetButtonImage ) { |
| 24 | + |
| 25 | + if ( params.disabled ) { |
| 26 | + // append inert reset button if image is set |
| 27 | + tp.parent().append('<button type="button" class="ui-datetimepicker-trigger' + params.userClasses + '" disabled><img src="' + params.resetButtonImage + '" alt="..." title="..."></button>'); |
| 28 | + } else { |
| 29 | + var resetbutton = jQuery('<button type="button" class="ui-datetimepicker-trigger ' + params.userClasses + '" ><img src="' + params.resetButtonImage + '" alt="..." title="..."></button>'); |
| 30 | + tp.parent().append(resetbutton); |
| 31 | + resetbutton.click(function(){ |
| 32 | + dp.datepicker( "setDate", null); |
| 33 | + tp.attr( "value", "" ); |
| 34 | + jQuery( "#" + input_id ).attr( "value", "" ); |
| 35 | + }) |
| 36 | + } |
| 37 | + } |
| 38 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticFormsInputs/libs/datetimepicker.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 39 | + native |
Index: trunk/extensions/SemanticFormsInputs/libs/datepicker.js |
— | — | @@ -8,82 +8,113 @@ |
9 | 9 | |
10 | 10 | function SFI_DP_init ( input_id, params ) { |
11 | 11 | |
12 | | - var input = jQuery("#" + input_id + "_show"); |
| 12 | + var input = jQuery("#" + input_id); |
| 13 | + var re = /\d{4}\/\d{2}\/\d{2}/ |
13 | 14 | |
14 | | - input.datepicker( { |
15 | | - "showOn": "both", |
16 | | - "buttonImage": params.buttonImage, |
17 | | - "buttonImageOnly": false, |
18 | | - "changeMonth": true, |
19 | | - "changeYear": true, |
20 | | - "altFormat": "yy/mm/dd", |
21 | | - // Today button does not work (http://dev.jqueryui.com/ticket/4045) |
22 | | - // do not show button panel for now |
23 | | - // TODO: show date picker button panel when bug is fixed |
24 | | - "showButtonPanel": false, |
25 | | - "firstDay": params.firstDay, |
26 | | - "showWeek": params.showWeek, |
27 | | - "dateFormat": params.dateFormat, |
28 | | - "altField": "#" + input_id, |
29 | | - "beforeShowDay": function (date) {return SFI_DP_checkDate("#" + input_id + "_show", date);} |
30 | | - } ); |
| 15 | + if ( params.disabled ) { |
31 | 16 | |
32 | | - if ( params.minDate ) { |
33 | | - input.datepicker( "option", "minDate", |
34 | | - jQuery.datepicker.parseDate("yy/mm/dd", params.minDate, null) ); |
35 | | - } |
| 17 | + // append inert reset button if image is set |
| 18 | + if ( params.resetButtonImage && ! params.partOfDTP ) { |
| 19 | + input.after('<button type="button" class="ui-datepicker-trigger' + params.userClasses + '" disabled><img src="' + params.resetButtonImage + '" alt="..." title="..."></button>'); |
| 20 | + } |
36 | 21 | |
37 | | - if ( params.maxDate ) { |
38 | | - input.datepicker( "option", "maxDate", |
39 | | - jQuery.datepicker.parseDate("yy/mm/dd", params.maxDate, null) ); |
40 | | - } |
| 22 | + // append inert datepicker button |
| 23 | + input.after('<button type="button" class="ui-datepicker-trigger' + params.userClasses + '" disabled><img src="' + params.buttonImage + '" alt="..." title="..."></button>'); |
41 | 24 | |
42 | | - if ( params.userClass ) { |
43 | | - input.datepicker("widget").addClass( params.userClass ); |
44 | | - jQuery("#" + input_id + "_show + button").addClass( params.userClass ); |
45 | | - } |
| 25 | + // set value for input fields |
| 26 | + try { |
| 27 | + if ( ! re.test( params.currValue ) ) { |
| 28 | + throw "Wrong date format!"; |
| 29 | + } |
| 30 | + input.attr( "value", jQuery.datepicker.formatDate(params.dateFormat, jQuery.datepicker.parseDate( "yy/mm/dd", params.currValue, null ), null ) ); |
46 | 31 | |
47 | | - if ( params.disabledDates ) { |
| 32 | + } catch (e) { |
| 33 | + input.attr( "value", params.currValue ); |
| 34 | + } |
| 35 | + } else { |
48 | 36 | |
49 | | - var disabledDates = params.disabledDates.map(function(range) { |
50 | | - return [new Date(range[0], range[1], range[2]), new Date(range[3], range[4], range[5])] |
51 | | - }); |
| 37 | + // append reset button if image is set |
| 38 | + if ( params.resetButtonImage && ! params.partOfDTP ) { |
| 39 | + var resetbutton = jQuery('<button type="button" class="ui-datepicker-trigger ' + params.userClasses + '" ><img src="' + params.resetButtonImage + '" alt="..." title="..."></button>'); |
| 40 | + input.after(resetbutton); |
| 41 | + resetbutton.click(function(){ |
| 42 | + input.datepicker( "setDate", null); |
| 43 | + }) |
| 44 | + } |
52 | 45 | |
53 | | - input.datepicker("option", "disabledDates", disabledDates); |
54 | | - } |
| 46 | + input.datepicker( { |
| 47 | + "showOn": "both", |
| 48 | + "buttonImage": params.buttonImage, |
| 49 | + "buttonImageOnly": false, |
| 50 | + "changeMonth": true, |
| 51 | + "changeYear": true, |
| 52 | + "altFormat": "yy/mm/dd", |
| 53 | + // Today button does not work (http://dev.jqueryui.com/ticket/4045) |
| 54 | + // do not show button panel for now |
| 55 | + // TODO: show date picker button panel when bug is fixed |
| 56 | + "showButtonPanel": false, |
| 57 | + "firstDay": params.firstDay, |
| 58 | + "showWeek": params.showWeek, |
| 59 | + "dateFormat": params.dateFormat, |
| 60 | + "beforeShowDay": function (date) {return SFI_DP_checkDate("#" + input_id, date);} |
| 61 | + } ); |
55 | 62 | |
56 | | - if ( params.highlightedDates ) { |
| 63 | + if ( ! params.partOfDTP ) { |
| 64 | + input.datepicker( "option", "altField", "#" + input_id.replace( "_dp_show", "" ) ); |
| 65 | + } |
57 | 66 | |
58 | | - var highlightedDates = params.highlightedDates.map(function(range) { |
59 | | - return [new Date(range[0], range[1], range[2]), new Date(range[3], range[4], range[5])] |
60 | | - }); |
| 67 | + if ( params.minDate ) { |
| 68 | + input.datepicker( "option", "minDate", |
| 69 | + jQuery.datepicker.parseDate("yy/mm/dd", params.minDate, null) ); |
| 70 | + } |
61 | 71 | |
62 | | - input.datepicker("option", "highlightedDates", highlightedDates); |
63 | | - } |
| 72 | + if ( params.maxDate ) { |
| 73 | + input.datepicker( "option", "maxDate", |
| 74 | + jQuery.datepicker.parseDate("yy/mm/dd", params.maxDate, null) ); |
| 75 | + } |
64 | 76 | |
65 | | - if (params.disabledDays) { |
66 | | - input.datepicker("option", "disabledDays", params.disabledDays); |
67 | | - } |
| 77 | + if ( params.userClasses ) { |
| 78 | + input.datepicker("widget").addClass( params.userClasses ); |
| 79 | + jQuery("#" + input_id + " + button").addClass( params.userClasses ); |
| 80 | + } |
68 | 81 | |
69 | | - if (params.highlightedDays) { |
70 | | - input.datepicker("option", "highlightedDays", params.highlightedDays); |
71 | | - } |
| 82 | + if ( params.disabledDates ) { |
72 | 83 | |
73 | | - //input.datepicker("option", "beforeShowDay", function (date) {return SFI_DP_checkDate("#" + input_id + "_show", date);}); |
| 84 | + var disabledDates = params.disabledDates.map(function(range) { |
| 85 | + return [new Date(range[0], range[1], range[2]), new Date(range[3], range[4], range[5])] |
| 86 | + }); |
74 | 87 | |
75 | | - try { |
| 88 | + input.datepicker("option", "disabledDates", disabledDates); |
| 89 | + } |
76 | 90 | |
77 | | - var re = /\d{4}\/\d{2}\/\d{2}/ |
78 | | - if ( ! re.test( params.currValue ) ) { |
79 | | - throw "Wrong date format!"; |
| 91 | + if ( params.highlightedDates ) { |
| 92 | + |
| 93 | + var highlightedDates = params.highlightedDates.map(function(range) { |
| 94 | + return [new Date(range[0], range[1], range[2]), new Date(range[3], range[4], range[5])] |
| 95 | + }); |
| 96 | + |
| 97 | + input.datepicker("option", "highlightedDates", highlightedDates); |
80 | 98 | } |
81 | | - input.datepicker( "setDate", jQuery.datepicker.parseDate( "yy/mm/dd", params.currValue, null ) ); |
82 | | - |
83 | | - } catch (e) { |
84 | | - input.attr( "value", params.currValue ); |
85 | | - jQuery( "#" + input_id).attr( "value", params.currValue ); |
| 99 | + |
| 100 | + if (params.disabledDays) { |
| 101 | + input.datepicker("option", "disabledDays", params.disabledDays); |
| 102 | + } |
| 103 | + |
| 104 | + if (params.highlightedDays) { |
| 105 | + input.datepicker("option", "highlightedDays", params.highlightedDays); |
| 106 | + } |
| 107 | + |
| 108 | + try { |
| 109 | + if ( ! re.test( params.currValue ) ) { |
| 110 | + throw "Wrong date format!"; |
| 111 | + } |
| 112 | + input.datepicker( "setDate", jQuery.datepicker.parseDate( "yy/mm/dd", params.currValue, null ) ); |
| 113 | + |
| 114 | + } catch (e) { |
| 115 | + input.attr( "value", params.currValue ); |
| 116 | + jQuery( "#" + input_id.replace( "_dp_show", "" )).attr( "value", params.currValue ); |
| 117 | + } |
86 | 118 | } |
87 | | - |
88 | 119 | } |
89 | 120 | |
90 | 121 | /** |
— | — | @@ -139,4 +170,3 @@ |
140 | 171 | |
141 | 172 | return [ enable, highlight, "" ]; |
142 | 173 | } |
143 | | - |
Index: trunk/extensions/SemanticFormsInputs/libs/timepicker.js |
— | — | @@ -17,8 +17,10 @@ |
18 | 18 | * format: (String) a format string (unused) (do we even need it?) |
19 | 19 | * |
20 | 20 | */ |
21 | | -function SFI_TP_init( inputID, params ) { // minTime, maxTime, interval, format |
| 21 | +function SFI_TP_init( inputIDshow, params ) { // minTime, maxTime, interval, format |
22 | 22 | |
| 23 | + var inputID = inputIDshow.replace( "_tp_show", "" ); |
| 24 | + |
23 | 25 | // sanitize inputs |
24 | 26 | var re = /^\d+:\d\d$/; |
25 | 27 | var minh = 0; |
— | — | @@ -27,7 +29,7 @@ |
28 | 30 | var maxh = 23; |
29 | 31 | var maxm = 59; |
30 | 32 | |
31 | | -if ( re.test( params.minTime ) ) { |
| 33 | + if ( re.test( params.minTime ) ) { |
32 | 34 | |
33 | 35 | var min = params.minTime.split( ':', 2 ); |
34 | 36 | minh = Number( min[0] ); |
— | — | @@ -46,12 +48,12 @@ |
47 | 49 | } |
48 | 50 | |
49 | 51 | var interv = Number( params.interval ); |
50 | | - |
| 52 | + |
51 | 53 | if ( interv < 1 ) interv = 1; |
52 | 54 | else if ( interv > 60 ) interv = 60; |
53 | 55 | |
54 | 56 | // build html structure |
55 | | - var sp = jQuery( "<span class='SFI_timepicker' id='" + inputID + "_tree' ></span>" ).insertAfter( "#" + inputID ); |
| 57 | + var sp = jQuery( "<span class='SFI_timepicker' id='" + inputID + "_tree' ></span>" ).insertBefore( "#" + inputIDshow ); |
56 | 58 | |
57 | 59 | var ulh = jQuery( "<ul>" ).appendTo( sp ); |
58 | 60 | |
— | — | @@ -128,36 +130,50 @@ |
129 | 131 | }); |
130 | 132 | |
131 | 133 | jQuery("#" + inputID + "_tree li") // hours, minutes |
132 | | - .mousedown(function(){ |
| 134 | + .mousedown(function(evt){ |
133 | 135 | // set values and leave input |
134 | | - jQuery("#" + inputID + "_show").attr("value", jQuery(this).data("show")).blur(); |
135 | | - jQuery("#" + inputID ).attr("value", jQuery(this).data("value")); |
| 136 | + jQuery("#" + inputIDshow ).attr("value", jQuery(this).data("show")).blur().change(); |
| 137 | + //jQuery("#" + inputID ).attr("value", jQuery(this).data("value")); |
| 138 | + |
| 139 | + // clear any timeout that may still run on this jQuery list item |
| 140 | + clearTimeout(jQuery(evt.currentTarget).data("timeout")); |
| 141 | + |
| 142 | + jQuery(evt.currentTarget) |
| 143 | + |
| 144 | + // switch classes to change display style |
| 145 | + .removeClass("ui-state-hover") |
| 146 | + .addClass("ui-state-default") |
| 147 | + |
| 148 | + // avoid propagation to parent list item (e.g. hours), |
| 149 | + // they would overwrite the input value |
136 | 150 | return false; |
137 | 151 | }); |
138 | 152 | |
139 | 153 | // show timepicker when input gets focus |
140 | | - jQuery("#" + inputID + "_show").focus(function() { |
| 154 | + jQuery("#" + inputIDshow ).focus(function() { |
141 | 155 | jQuery("#" + inputID + "_tree>ul").fadeIn(); |
142 | | - }); |
| 156 | + }); |
143 | 157 | |
144 | 158 | // hide timepicker when input loses focus |
145 | | - jQuery("#" + inputID + "_show").blur(function() { |
146 | | - jQuery("#" + inputID + "_tree ul").fadeOut(); |
| 159 | + jQuery("#" + inputIDshow ).blur(function() { |
| 160 | + jQuery("#" + inputID + "_tree ul").fadeOut("normal", function() {jQuery(this).hide()}); |
147 | 161 | }); |
148 | 162 | |
149 | | - jQuery("#" + inputID + "_show").change(function() { |
150 | | - jQuery("#" + inputID ).attr("value", jQuery(this).attr("value")); |
151 | | - }); |
| 163 | + if ( ! params.partOfDTP ) { |
| 164 | + jQuery("#" + inputIDshow).change(function() { |
| 165 | + jQuery("#" + inputID ).attr("value", jQuery(this).attr("value")); |
| 166 | + }); |
| 167 | + } |
152 | 168 | |
153 | | - jQuery("#" + inputID + '~ button[name="button"]' ) |
| 169 | + jQuery("#" + inputID + '_tp_show ~ button[name="button"]' ) |
154 | 170 | .attr("id", inputID + "_button") |
155 | 171 | .click(function() { |
156 | | - jQuery("#" + inputID + "_show" ).focus(); |
| 172 | + jQuery("#" + inputIDshow ).focus(); |
157 | 173 | }); |
158 | 174 | |
159 | | - jQuery("#" + inputID + '~ button[name="resetbutton"]' ) |
| 175 | + jQuery("#" + inputID + '_tp_show ~ button[name="resetbutton"]' ) |
160 | 176 | .attr("id", inputID + "_resetbutton") |
161 | 177 | .click(function() { |
162 | | - jQuery("#" + inputID + "_show" ).attr("value", ""); |
| 178 | + jQuery("#" + inputIDshow ).attr("value", ""); |
163 | 179 | }); |
164 | 180 | } |
\ No newline at end of file |