datetimeRangePicker icon indicating copy to clipboard operation
datetimeRangePicker copied to clipboard

Do not work on Angular 1.4.6

Open glivolsi opened this issue 9 years ago • 1 comments

As in subject your directive do not work on angular 1.4.6

glivolsi avatar Sep 23 '15 12:09 glivolsi

Issue is more than likely that ui.bootstrap has changed the datepicker directive name to uib-datepicker.

Try adding the following datepickerAlias module to your project and require it anywhere you require rgkevin.datetimeRangePicker

(function() {
  'use strict';

  /*****
   * This hack module is because our time picker uses and older version of
   * ui.bootstrap wherein the datepicker directive did not have the
   * uib- directive prefix. This will add an alias to the original
   * datepicker directive and also move some config from attributes into an
   * object.
   */

  angular.module('datepickerAlias', [
      'ui.bootstrap'
    ])
    .directive('datepicker', datepickerAliasDirective);

  datepickerAliasDirective.$inject = [
    '$injector',
    '$parse'
  ];
  function datepickerAliasDirective($injector, $parse){
    // This is the name of the directive we're going to override
    var directive = angular.copy($injector.get('uibDatepickerDirective')[0]);

    var originalCompile = directive.compile;

    directive.compile = function newCompile(el, attrs){

      // Some properties must be set before the controller runs
      attrs.$set('datepickerOptions', angular.toJson({showWeeks: false}));

      var originalPreLink  = angular.noop,
          originalPostLink = angular.noop;

      // There should be a compile function and it should return the linkers
      if(angular.isFunction(originalCompile)){
        var originalLinks = originalCompile.apply(directive, arguments);

        // Handle the mapping of pre and post links returned from original compiler
        if(angular.isFunction(originalLinks)){
          originalPostLink = originalLinks;
        } else {
          originalPreLink = originalLinks.pre || angular.noop;
          originalPostLink = originalLinks.post || angular.noop;
        }
      }

      return {
        pre: function newPreLink(scope, el, attrs){

          // these have watchers in the directive so it's ok to late bind
          [
            'maxDate',
            'minDate',
            'maxMode',
            'minMode'
          ].forEach(function(key){
            if(angular.isDefined(attrs[key])){
              scope.$watch(function(){
                return $parse(attrs[key])(scope.$parent);
              }, function(newVal){
                scope.datepickerOptions[key] = newVal;
              });
            }
          });

          originalPreLink.apply(directive, arguments);
        },

        post: originalPostLink
      }

    };

    return directive;
  }
})();

Sorry for updating this 100 times. This last update is working for sure.

Skinner927 avatar May 09 '16 20:05 Skinner927