lavinjj / angular-responsive Goto Github PK
View Code? Open in Web Editor NEWA set of AngularJS directives to help with responsive design.
License: Apache License 2.0
A set of AngularJS directives to help with responsive design.
License: Apache License 2.0
Hi,
Could you add a feature to handle the resize event? When you resize the browser the layout does not change.
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?
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.
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?
Hello,
I understand that this $watch should be listening the config,
https://github.com/lavinjj/angular-responsive/blob/master/src/responsive-directive.js#L91
and if it change destroy and create the element again, per example, when a tablet is turned.
I tried to change to:
unwatch = scope.$watch( function() {return scope.$eval( attr[responsiveType] ); }, function ()...
but it isn't a good idea, because it is called a lot of time in the digest,
any idea?
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() );
};
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.