diff --git a/README.md b/README.md index f897cf6..f46e0ab 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,12 @@ A simple AngularJS directive to use jQuery backstretch plugin (http://srobbin.co ## Installation -Get the last `angular-backstretch.js` from here OR install it via Twitter bower: `bower install angular-backstretch` +Get the last `angular-backstretch.js` from here OR install it via bower: `bower install angular-backstretch` ## Setup 1. Include `angular-backstretch.js` in your project -2. Add it as a dependency of your main module: `angular.module('app', ['backstretch'])` -3. Declare an HTML element using the directive: `` \ No newline at end of file +2. Add it as a dependency of your main module: `angular.module('app', ['ngBackstretch'])` +3. Declare an HTML element using the directive: `
` + +Version 1.0.1 diff --git a/angular-backstretch.js b/angular-backstretch.js index 34f9570..bb05f5c 100644 --- a/angular-backstretch.js +++ b/angular-backstretch.js @@ -1,9 +1,42 @@ -angular.module('backstretch') - .directive('backstretch', function () { - return { - restrict: 'A' - link: function (scope, element, attr) { - $(element).backstretch(attr.backgroundUrl); - } - } - }); \ No newline at end of file +/* + * Title: ngBackstretch + * Description: An angular directive to assist the use of jQuery Backstretch. + * A plugin by Robbin & Co http://srobbin.com/jquery-plugins/backstretch/ + * Version: 1.0.0 + * Authors: Steven Collier, Erik Zettersten + */ +(function() { + + /* Start ngBackstretch */ + + 'use strict'; + + angular.module('ngBackstretch', []) + + .directive('ngBackstretch', [ + + function() { + + if (typeof $.fn.backstretch !== 'function') + throw new Error('ngBackstretch | Please make sure the jquery backstretch plugin is included before this directive is added.') + + return { + restrict: 'A', + link: function(scope, element, attr) { + + if (attr.ngBackstretch === '' || typeof attr.ngBackstretch === 'undefined') + throw new Error('ngBackstretch | You have not declared an image to be stretched.') + + if (element.context.toString().match(/HTMLBodyElement/gi)) + return $.backstretch(attr.ngBackstretch); + + $(element).backstretch(attr.ngBackstretch); + + } + } + + } + + ]); + +}).call(this); diff --git a/component.json b/component.json index cf504e1..e1fac85 100644 --- a/component.json +++ b/component.json @@ -1,6 +1,6 @@ { "name": "angular-backstrech", - "version": "0.0.1", + "version": "1.0.1", "main": "angular-backstretch.js", "ignore": [ "**/.*", @@ -11,4 +11,4 @@ "jquery": ">1.9.1", "jquery-backstretch": "https://raw.github.com/srobbin/jquery-backstretch/master/jquery.backstretch.min.js" } -} \ No newline at end of file +}