Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
refactor(main): Converted to Javascript
Browse files Browse the repository at this point in the history
Removed ngAnimate dependencies for Mac
Updated karma config
  • Loading branch information
adrianlee44 committed May 31, 2015
1 parent f6d04ce commit 8693388
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 201 deletions.
2 changes: 1 addition & 1 deletion docs/doc.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###
Documentation script
###
angular.module("Mac").
angular.module("MacDemo", ['Mac', 'ngAnimate']).
directive("code", ->
restrict: "E"
terminal: true
Expand Down
2 changes: 1 addition & 1 deletion docs/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ html
link(href='css/macgyver.css', rel='stylesheet')
link(href='css/vendor.css', rel='stylesheet')

body(ng-app="Mac", mac-scroll-spy, mac-scroll-spy-offset="10")
body(ng-app="MacDemo", mac-scroll-spy, mac-scroll-spy-offset="10")
nav.navbar.navbar-fixed-top.navbar-inverse
.container-fluid
.navbar-header
Expand Down
179 changes: 0 additions & 179 deletions src/main.coffee

This file was deleted.

201 changes: 201 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
angular.module("Mac", ["Mac.Util"]);

/**
* @chalk overview
* @name angular.element
*
* @description
* Angular comes with jqLite, a tiny, API-compatible subset of jQuery. However, its
* functionality is very limited and MacGyver extends jqLite to make sure MacGyver
* components work properly.
*
* Real jQuery will continue to take precedence over jqLite and all functions MacGyver extends.
*
* MacGyver adds the following methods:
* - [height()](http://api.jquery.com/height/) - Does not support set
* - [width()](http://api.jquery.com/width/) - Does not support set
* - [outerHeight()](http://api.jquery.com/outerHeight/) - Does not support set
* - [outerWidth()](http://api.jquery.com/outerWidth/) - Does not support set
* - [offset()](http://api.jquery.com/offset/)
* - [scrollTop()](http://api.jquery.com/scrollTop/)
*/

var cssExpand = ["Top", "Right", "Bottom", "Left"],
core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,
rnumnonpx = new RegExp("^(" + core_pnum + ")(?!px)[a-z%]+$", "i");

function getStyles(element) {
return window.getComputedStyle(element, null);
};

function isWindow(obj) {
return obj && obj.document && obj.location && obj.alert && obj.setInterval;
};

function isScope(obj) {
return obj && (obj.$evalAsync != null) && (obj.$watch != null);
};

// HACK: Add isScope to AngularJS global scope
angular.isScope = isScope;

function getWindow(element) {
if (isWindow(element)) {
return element;
} else {
return element.nodeType === 9 && element.defaultView;
}
};

function augmentWidthOrHeight(element, name, extra, isBorderBox, styles) {
var i, j, ref, start, val;
if (extra === (isBorderBox ? "border" : "content")) {
return 0;
}
val = 0;
start = name === "Width" ? 1 : 0;
for (i = j = ref = start; j <= 3; i = j += 2) {
if (extra === "margin") {
val += parseFloat(styles["" + extra + cssExpand[i]]);
}
if (isBorderBox) {
if (extra === "content") {
val -= parseFloat(styles["padding" + cssExpand[i]]);
}
if (extra !== "margin") {
val -= parseFloat(styles["border" + cssExpand[i]]);
}
} else {
val += parseFloat(styles["padding" + cssExpand[i]]);
if (extra !== "padding") {
val += parseFloat(styles["border" + cssExpand + "Width"]);
}
}
}
return val;
};

function getWidthOrHeight(type, prefix, element) {
return function(margin) {
var defaultExtra, doc, extra, isBorderBox, name, styles, value, valueIsBorderBox;

switch (prefix) {
case 'inner':
defaultExtra = 'padding';
break;
case 'outer':
defaultExtra = '';
break;
default:
defaultExtra = 'content';
}
extra = defaultExtra || (margin === true ? "margin" : "border");

if (isWindow(element)) {
return element.document.documentElement["client" + type];
}

if (element.nodeType === 9) {
doc = element.documentElement;
return Math.max(element.body["scroll" + type], doc["scroll" + type], element.body["offset" + type], doc["offset" + type], doc["client" + type]);
}

valueIsBorderBox = true;
styles = getStyles(element);
name = type.toLowerCase();
value = type === "Height" ? element.offsetHeight : element.offsetWidth;
isBorderBox = element.style.boxSizing === "border-box";

if (value <= 0 || value === null) {
value = styles[name];
if (value < 0 || value === null) {
value = element.style[name];
}
if (rnumnonpx.test(value)) {
return value;
}
valueIsBorderBox = isBorderBox;
value = parseFloat(value) || 0;
}
return value + augmentWidthOrHeight(element, type, extra || (isBorderBox ? "border" : "content"), valueIsBorderBox, styles);
};
};

var jqLiteExtend = {
height: function(element) {
return getWidthOrHeight("Height", "", element)();
},
width: function(element) {
return getWidthOrHeight("Width", "", element)();
},
outerHeight: function(element, margin) {
return getWidthOrHeight("Height", "outer", element)(margin);
},
outerWidth: function(element, margin) {
return getWidthOrHeight("Width", "outer", element)(margin);
},
offset: function(element) {
var box, doc, docElem, win;
box = {
top: 0,
left: 0
};
doc = element && element.ownerDocument;
if (!doc) {
return;
}
docElem = doc.documentElement;
if (element.getBoundingClientRect != null) {
box = element.getBoundingClientRect();
}
win = getWindow(doc);
return {
top: box.top + win.pageYOffset - docElem.clientTop,
left: box.left + win.pageXOffset - docElem.clientLeft
};
},
scrollTop: function(element, value) {
var win = getWindow(element);
if (value == null) {
if (win) {
return win["pageYOffset"];
} else {
return element["scrollTop"];
}
}
if (win) {
return win.scrollTo(window.pageYOffset, value);
} else {
return element["scrollTop"] = value;
}
},
scrollLeft: function(element, value) {
var win = getWindow(element);
if (value == null) {
if (win) {
return win["pageXOffset"];
} else {
return element["scrollLeft"];
}
}
if (win) {
return win.scrollTo(window.pageXOffset, value);
} else {
return element["scrollLeft"] = value;
}
}
};

(function () {
var jqLite = angular.element;
if ((window.jQuery != null) && (angular.element.prototype.offset != null)) {
return;
}
return angular.forEach(jqLiteExtend, function(fn, name) {
return jqLite.prototype[name] = function(arg1, arg2) {
if (this.length) {
return fn(this[0], arg1, arg2);
}
};
});
})();
Loading

0 comments on commit 8693388

Please sign in to comment.