Code Monkey home page Code Monkey logo

angular-responsive's People

Contributors

konqi avatar lavinjj avatar thomasburleson avatar xavadu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-responsive's Issues

Document out of dated

The names of the directives in responsive-directives.js are arXs, arSm, arMd, arLg rather than arMobile, arTablet, arDesktop, etc.

Or maybe the code should be updated accordingly? And what is responsive.js used for?

ng-click not work with directives

If you add to div for example data-ar-mobile and ng-click attributes - click listener not trigger. Workaround: wrap your ng-click div with another div where you have data-ar-mobile attribute.

Not working

Wasn't able to get this working.

What are the correct directive names and which JS files need to be included? It seems like the documentation is out of sync?

Refactor directives to be more DRY

Really nice code library. I just wanted to suggest a refactor that could improve your code maintenance and reader understanding.

.directive('arMobile', ['responsiveHelper', function (responsiveHelper) 
{
    return {
        restrict    : "EAC",
        transclude  : 'element',
        template    : '<div></div>',
        compile     : buildCompileFn( 'arMobile', responsiveHelper.isMobile )
    };
}])
.directive('arMobile', ['responsiveHelper', function (responsiveHelper) 
{
    return {
        restrict    : "EAC",
        transclude  : 'element',
        template    : '<div></div>',
        compile     : buildCompileFn( 'arTablet', responsiveHelper.isTablet )
    };
}])
.directive('arMobile', ['responsiveHelper', function (responsiveHelper) 
{
    return {
        restrict    : "EAC",
        transclude  : 'element',
        template    : '<div></div>',
        compile     : buildCompileFn( 'arDesktop', responsiveHelper.isDesktop )
    };
}])
.directive('arResponsive', ['responsiveHelper', function (responsiveHelper) 
{
    return {
        restrict    : "EAC",
        transclude  : 'element',
        template    : '<div></div>',
        compile     : buildCompileFn( 'arResponsive', checkAllTypes(responsiveHelper) )
    };
}])

/**
 * Partial application for DRY construction of a directive compile function
 */
function buildCompileFn(responsiveType, verifyFn )
{
  return function (element, attr, transclude) 
  {
      return function postLink(scope, element, attr) 
      {
          var childElement, childScope,
          var deviceTypes = scope.$eval( attr[responsiveType] );

          scope.$watch( deviceTypes, function () 
          {
              // attribute changed, delete existing element & $scope

              if (childElement) {
                  childElement.remove();
                  childScope.$destroy();
                  childElement = undefined;
                  childScope = undefined;
              }

              if ( verifyFn(deviceTypes) ) 
              {
                  // Create a new element and $scope...

                  childScope = scope.$new();
                  childElement = transclude(childScope, function (clone) {
                      element.after(clone);
                  });
              }
          });
      };
  };
}

/**
 * Partial application for DRY construction of function to scan of any valid responsive types 
 */
function checkAllTypes(responsiveHelper)
{
    return function( deviceTypes )
    {
        return  ( deviceTypes['Mobile'] && responsiveHelper.isMobile() ) || 
                ( deviceTypes['Tablet'] && responsiveHelper.isTablet() ) || 
                ( deviceTypes['Desktop'] && responsiveHelper.isDesktop() );
    };
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.