Skip to content

Commit

Permalink
Allow javascript get some less variables value
Browse files Browse the repository at this point in the history
Push grid variables into body data for javascript use. Example, get
small screen size value by jQuery ('body').data('screen-sm');
  • Loading branch information
khanhlh committed Apr 23, 2014
1 parent badba6a commit 44998f9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
23 changes: 23 additions & 0 deletions source/plg_system_t3/base-bs3/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@

!function($){

// Detect grid-float-breakpoint value and put to $(body) data
$(document).ready(function(){
var fromClass = 'body-data-holder',
prop = 'content',
$inspector = $('<div>').css('display', 'none').addClass(fromClass).appendTo($('body'));

try {
var attrs = window.getComputedStyle(
$inspector[0], ':before'
).getPropertyValue(prop),
matches = attrs.match(/([\da-z\-]+)/gi),
data = {};
if (matches && matches.length) {
for (var i=0; i<matches.length; i++) {
data[matches[i++]] = i<matches.length ? matches[i] : null;
}
}
$('body').data (data);
} finally {
$inspector.remove(); // and remove from DOM
}
});

//detect transform (https://github.com/cubiq/)
(function(){
$.support.t3transform = (function () {
Expand Down
11 changes: 10 additions & 1 deletion source/plg_system_t3/base-bs3/less/t3.less
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,13 @@
overflow: hidden;
display: block;
}
}
}


// for interact with javascript
// ---------------------------------------------------------------------------
// place holder class to detect the grid variables value in javascript
.body-data-holder:before {
display: none;
content: "grid-float-breakpoint:@{grid-float-breakpoint} screen-xs:@{screen-xs} screen-sm:@{screen-sm} screen-md:@{screen-md} screen-lg:@{screen-lg}";
}
24 changes: 24 additions & 0 deletions source/plg_system_t3/base/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@

!function($){

// Detect grid-float-breakpoint value and put to $(body) data
$(document).ready(function(){
var fromClass = 'body-data-holder',
prop = 'content',
$inspector = $('<div>').css('display', 'none').addClass(fromClass).appendTo($('body'));

try {
var attrs = window.getComputedStyle(
$inspector[0], ':before'
).getPropertyValue(prop),
matches = attrs.match(/([\da-z\-]+)/gi),
data = {};
if (matches && matches.length) {
for (var i=0; i<matches.length; i++) {
data[matches[i++]] = i<matches.length ? matches[i] : null;
}
}
$('body').data (data);
} finally {
$inspector.remove(); // and remove from DOM
}
});


//detect transform (https://github.com/cubiq/)
$.support.t3transform = (function () {
var style = document.createElement('div').style,
Expand Down
9 changes: 9 additions & 0 deletions source/plg_system_t3/base/less/t3.less
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,13 @@
display: block;
}
}
}


// for interact with javascript
// ---------------------------------------------------------------------------
// place holder class to detect the grid variables value in javascript
.body-data-holder:before {
display: none;
content: "grid-float-breakpoint:@{navbarCollapseWidth} screen-xs:600px screen-sm:@{gridRowWidth768} screen-md:@{gridRowWidth} screen-lg:@{gridRowWidth1200}";
}

0 comments on commit 44998f9

Please sign in to comment.