frame.scss 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. @function pad($radius) {
  2. $radius: boxmax($radius);
  3. $radius: parseint($radius);
  4. @if $radius >= 10 {
  5. @return $radius;
  6. }
  7. @else {
  8. @return "0" + $radius;
  9. }
  10. }
  11. @function frame-size($border-width, $inner-border-width, $border-radius) {
  12. // We use the border-radius of the two corners on each edge to determine the "edge's
  13. // border-radius". For IE, the framing elements need to be as large as the larger of
  14. // the border-radius and the border-width on each edge. These values are passed on to
  15. // JavaScript using an encoded background-image url and the equivalent operations are
  16. // handled by Renderable.js.
  17. $frame-top: max(top($border-width) + top($inner-border-width), max(top($border-radius), right($border-radius)));
  18. $frame-right: max(right($border-width) + right($inner-border-width), max(right($border-radius), bottom($border-radius)));
  19. $frame-bottom: max(bottom($border-width) + bottom($inner-border-width), max(bottom($border-radius), left($border-radius)));
  20. $frame-left: max(left($border-width) + left($inner-border-width), max(left($border-radius), top($border-radius)));
  21. $frame-max: max($frame-top $frame-right $frame-bottom $frame-left);
  22. // Slices produced by the slicer are always equally sized so that
  23. // they can be sprited. This means that all sides that have frames
  24. // must be the same size
  25. @if $frame-top != 0 {
  26. $frame-top: $frame-max;
  27. }
  28. @if $frame-right != 0 {
  29. $frame-right: $frame-max;
  30. }
  31. @if $frame-bottom != 0 {
  32. $frame-bottom: $frame-max;
  33. }
  34. @if $frame-left != 0 {
  35. $frame-left: $frame-max;
  36. }
  37. @return $frame-top $frame-right $frame-bottom $frame-left
  38. }
  39. @mixin x-frame(
  40. $cls,
  41. $ui: null,
  42. $border-radius: 0px,
  43. $border-width: 0px,
  44. $padding: null,
  45. $background-color: null,
  46. $background-gradient: null,
  47. $table: false,
  48. $background-direction: top,
  49. $include-frame-rtl: false,
  50. $background-stretch: null,
  51. $ignore-frame-padding: false,
  52. $inner-border-width: 0
  53. ) {
  54. $cls-ui: $cls;
  55. $cls-ui: null;
  56. @if $ui != null {
  57. $cls-ui: $cls + '-' + $ui;
  58. }
  59. @if is-null($inner-border-width) {
  60. // default inner border width to 0 if the caller passed null or 'none' (e.g. buttons do this)
  61. $inner-border-width: 0;
  62. }
  63. $vertical: false;
  64. @if not is-null($background-gradient) and ($background-direction == left or $background-direction == right) {
  65. $vertical: true;
  66. }
  67. $background-stretch-position: null;
  68. @if is-null($background-stretch) {
  69. @if $background-direction == top {
  70. $background-stretch: bottom;
  71. } @else if $background-direction == right {
  72. $background-stretch: left;
  73. } @else if $background-direction == bottom {
  74. $background-stretch: top;
  75. } @else if $background-direction == left {
  76. $background-stretch: right;
  77. }
  78. }
  79. @if $background-stretch == top {
  80. $background-stretch-position: bottom;
  81. } @else if $background-stretch == bottom {
  82. $background-stretch-position: top;
  83. } @else if $background-stretch == left {
  84. $background-stretch-position: right;
  85. } @else if $background-stretch == right {
  86. $background-stretch-position: left;
  87. }
  88. @if not is-null($background-gradient) {
  89. $stretch: slicer-background-stretch($cls-ui, $background-stretch);
  90. }
  91. $frame-size: frame-size($border-width, $inner-border-width, $border-radius);
  92. $frame-top: nth($frame-size, 1);
  93. $frame-right: nth($frame-size, 2);
  94. $frame-bottom: nth($frame-size, 3);
  95. $frame-left: nth($frame-size, 4);
  96. $frame-max: max($frame-size);
  97. $frame: slicer-frame($cls-ui, $frame-size);
  98. $padding-top: 0;
  99. $padding-right: 0;
  100. $padding-bottom: 0;
  101. $padding-left: 0;
  102. $frame-info-padding-top: 0;
  103. $frame-info-padding-right: 0;
  104. $frame-info-padding-bottom: 0;
  105. $frame-info-padding-left: 0;
  106. // For CSS3 browsers, if the border-radius is larger than the border-width, we need to
  107. // apply padding to inset the content. These values can never be 0 because frame-xxx
  108. // includes border-xxx in its max.
  109. //
  110. @if not $ignore-frame-padding {
  111. $padding-top: $frame-top - top($border-width);
  112. $padding-right: $frame-right - right($border-width);
  113. $padding-bottom: $frame-bottom - bottom($border-width);
  114. $padding-left: $frame-left - left($border-width);
  115. } @else {
  116. // In nocss3 browsers we can never ignore frame padding, because the framing elements
  117. // cannot be overlapped by the content.
  118. $frame-info-padding-top: $frame-top - top($border-width);
  119. $frame-info-padding-right: $frame-right - right($border-width);
  120. $frame-info-padding-bottom: $frame-bottom - bottom($border-width);
  121. $frame-info-padding-left: $frame-left - left($border-width);
  122. }
  123. // If there is additional padding, this is understood to be a request to ensure that
  124. // the content is **at least** this far from the inside of the border. If the framing
  125. // requires more padding, that wins. This is the amount of padding you need in CSS3
  126. // browsers.
  127. //
  128. @if not is-null($padding) {
  129. $padding-top: max($padding-top, top($padding));
  130. $padding-right: max($padding-right, right($padding));
  131. $padding-bottom: max($padding-bottom, bottom($padding));
  132. $padding-left: max($padding-left, left($padding));
  133. }
  134. // For IE, the framing elements are sized by frame-xxx and the "-mc" will carry the
  135. // extra-padding-xxx.
  136. //
  137. $extra-padding-top: max(top($border-width) + $padding-top - $frame-top, 0);
  138. $extra-padding-right: max(right($border-width) + $padding-right - $frame-right, 0);
  139. $extra-padding-bottom: max(bottom($border-width) + $padding-bottom - $frame-bottom, 0);
  140. $extra-padding-left: max(left($border-width) + $padding-left - $frame-left, 0);
  141. $framing-info: '';
  142. @if $table == true {
  143. $framing-info: $framing-info + 't';
  144. } @else {
  145. $framing-info: $framing-info + 'd';
  146. }
  147. @if $vertical == true {
  148. $framing-info: $framing-info + 'v';
  149. } @else {
  150. $framing-info: $framing-info + 'h';
  151. }
  152. $framing-info: $framing-info + '-' +
  153. nopx($frame-top) + '-' +
  154. nopx($frame-right) + '-' +
  155. nopx($frame-bottom) + '-' +
  156. nopx($frame-left) + '-' +
  157. nopx(top($border-width)) + '-' +
  158. nopx(right($border-width)) + '-' +
  159. nopx(bottom($border-width)) + '-' +
  160. nopx(left($border-width)) + '-' +
  161. if($ignore-frame-padding, $frame-info-padding-top, nopx($padding-top)) + '-' +
  162. if($ignore-frame-padding, $frame-info-padding-right, nopx($padding-right)) + '-' +
  163. if($ignore-frame-padding, $frame-info-padding-bottom, nopx($padding-bottom)) + '-' +
  164. if($ignore-frame-padding, $frame-info-padding-left, nopx($padding-left));
  165. .#{$prefix}#{$cls-ui} {
  166. @if length($border-radius) == 2 {
  167. @include border-top-left-radius(nth($border-radius, 1));
  168. @include border-top-right-radius(nth($border-radius, 2));
  169. } @else if length($border-radius) == 3 {
  170. @include border-top-left-radius(nth($border-radius, 1));
  171. @include border-top-right-radius(nth($border-radius, 2));
  172. @include border-bottom-right-radius(nth($border-radius, 3));
  173. } @else if length($border-radius) == 4 {
  174. @include border-top-left-radius(nth($border-radius, 1));
  175. @include border-top-right-radius(nth($border-radius, 2));
  176. @include border-bottom-right-radius(nth($border-radius, 3));
  177. @include border-bottom-left-radius(nth($border-radius, 4));
  178. } @else {
  179. @include border-radius($border-radius);
  180. }
  181. padding: $padding-top $padding-right $padding-bottom $padding-left;
  182. border-width: $border-width;
  183. border-style: solid;
  184. @if not is-null($background-color) {
  185. @if not is-null($background-gradient) {
  186. @include background-gradient($background-color, $background-gradient, $background-direction);
  187. }
  188. @else {
  189. background-color: $background-color;
  190. }
  191. }
  192. }
  193. @if $include-frame-rtl {
  194. @if $background-direction == left {
  195. $background-direction: right;
  196. } @else if $background-direction == right {
  197. $background-direction: left;
  198. }
  199. @if $background-direction == left or $background-direction == right {
  200. .#{$prefix}rtl.#{$prefix}#{$cls-ui} {
  201. @include background-gradient(
  202. $background-color,
  203. $background-gradient,
  204. $background-direction
  205. );
  206. }
  207. }
  208. }
  209. @if $include-slicer-border-radius {
  210. .#{$prefix}#{$cls-ui}-mc {
  211. @if not is-null($background-gradient) {
  212. background-image: slicer-frame-background-image($cls-ui, '#{$cls}/#{$cls-ui}-fbg');
  213. @if $vertical {
  214. background-position: $background-stretch-position 0;
  215. background-repeat: repeat-y;
  216. } @else {
  217. background-position: 0 $background-stretch-position;
  218. }
  219. }
  220. @if not is-null($background-color) {
  221. background-color: $background-color;
  222. }
  223. }
  224. @if $include-frame-rtl and not is-null($background-gradient) {
  225. .#{$prefix}rtl.#{$prefix}#{$cls-ui}-mc {
  226. background-image: slicer-frame-background-image-rtl($cls-ui, '#{$cls}/#{$cls-ui}-fbg-rtl');
  227. background-position: rtl-background-position($background-stretch-position 0);
  228. }
  229. }
  230. }
  231. @if $include-slicer-border-radius {
  232. .#{$prefix}nbr {
  233. // This rule must be in x-nbr to avoid matching on CSS3 browsers.
  234. .#{$prefix}#{$cls-ui} {
  235. padding: 0 !important;
  236. border-width: 0 !important;
  237. @include border-radius(0px);
  238. @if not is-null($background-color) {
  239. background-color: transparent !important;
  240. } @else {
  241. background: #fff;
  242. }
  243. @if not is-null($background-gradient) {
  244. background-image: none;
  245. }
  246. // it is helpful to suppress box-shadow when debugging nocss3 mode in modern browsers
  247. box-shadow: none !important;
  248. }
  249. }
  250. .#{$prefix}#{$cls-ui}-frameInfo {
  251. // Pass along Div/Table, Horz/Vert, border-radius and border-width
  252. // Here we're encoding the framing information in an arbitrary fashion so
  253. // it can be parsed by the component and get information about the framing.
  254. // Originally, this tried to embed the information using a background image
  255. // pointing to about:blank#info however in IE with SSL, this would trigger
  256. // the insecure content warning. We also tried encoding the info using a
  257. // filter as follows (where framing-info is a string containing the encoded data):
  258. // filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=false, src="ext-frame#{$framing-info}");
  259. // However the filter property can only be read by IE, making it impossible
  260. // to debug nocss3 mode in modern browsers. Font-family meets all the
  261. // requirements for tunneling data to JavaScript. It can contain an
  262. // arbitrary string value, which can be read in JS in any browser, and it
  263. // does not trigger any network interactions.
  264. font-family: #{$framing-info};
  265. }
  266. // These rules apply to elements that are not rendered on CSS3 browsers so we do
  267. // not need to force the browser to walk to the root of the document searching
  268. // for x-nbr!
  269. @if $vertical {
  270. // vertical framing element background positions
  271. .#{$prefix}#{$cls-ui}-tl {
  272. background-position: 0 0;
  273. }
  274. .#{$prefix}#{$cls-ui}-tr {
  275. background-position: 0 (-$frame-max);
  276. }
  277. .#{$prefix}#{$cls-ui}-bl {
  278. background-position: 0 (-$frame-max * 2);
  279. }
  280. .#{$prefix}#{$cls-ui}-br {
  281. background-position: 0 (-$frame-max * 3);
  282. }
  283. .#{$prefix}#{$cls-ui}-ml {
  284. background-position: (-$frame-max) 0;
  285. }
  286. .#{$prefix}#{$cls-ui}-mr {
  287. background-position: right 0;
  288. }
  289. .#{$prefix}#{$cls-ui}-tc {
  290. background-position: $background-stretch-position 0;
  291. }
  292. .#{$prefix}#{$cls-ui}-bc {
  293. background-position: $background-stretch-position (-$frame-max);
  294. }
  295. @if $include-frame-rtl {
  296. .#{$prefix}rtl.#{$prefix}#{$cls-ui}-tc {
  297. background-position: rtl-background-position($background-stretch-position 0);
  298. }
  299. .#{$prefix}rtl.#{$prefix}#{$cls-ui}-bc {
  300. background-position: rtl-background-position($background-stretch-position (-$frame-max));
  301. }
  302. }
  303. } @else {
  304. // horizontal framing element background positions
  305. .#{$prefix}#{$cls-ui}-tl {
  306. background-position: 0 (-$frame-max * 2);
  307. }
  308. .#{$prefix}#{$cls-ui}-tr {
  309. background-position: right (-$frame-max * 3);
  310. }
  311. .#{$prefix}#{$cls-ui}-bl {
  312. background-position: 0 (-$frame-max * 4);
  313. }
  314. .#{$prefix}#{$cls-ui}-br {
  315. background-position: right (-$frame-max * 5);
  316. }
  317. .#{$prefix}#{$cls-ui}-ml {
  318. @if $background-stretch-position == 'right' or $background-stretch-position == 'left' {
  319. background-position: $background-stretch-position 0;
  320. } @else {
  321. background-position: 0 $background-stretch-position;
  322. }
  323. }
  324. .#{$prefix}#{$cls-ui}-mr {
  325. @if $background-stretch-position == 'right' or $background-stretch-position == 'left' {
  326. background-position: $background-stretch-position 0;
  327. } @else {
  328. background-position: right $background-stretch-position;
  329. }
  330. }
  331. .#{$prefix}#{$cls-ui}-tc {
  332. background-position: 0 0;
  333. }
  334. .#{$prefix}#{$cls-ui}-bc {
  335. background-position: 0 (-$frame-max);
  336. }
  337. }
  338. .#{$prefix}#{$cls-ui}-tr,
  339. .#{$prefix}#{$cls-ui}-br,
  340. .#{$prefix}#{$cls-ui}-mr {
  341. padding-right: $frame-right;
  342. }
  343. .#{$prefix}#{$cls-ui}-tl,
  344. .#{$prefix}#{$cls-ui}-bl,
  345. .#{$prefix}#{$cls-ui}-ml {
  346. padding-left: $frame-left;
  347. }
  348. .#{$prefix}#{$cls-ui}-tc {
  349. height: $frame-top;
  350. }
  351. .#{$prefix}#{$cls-ui}-bc {
  352. height: $frame-bottom;
  353. }
  354. .#{$prefix}#{$cls-ui}-tl,
  355. .#{$prefix}#{$cls-ui}-bl,
  356. .#{$prefix}#{$cls-ui}-tr,
  357. .#{$prefix}#{$cls-ui}-br,
  358. .#{$prefix}#{$cls-ui}-tc,
  359. .#{$prefix}#{$cls-ui}-bc,
  360. .#{$prefix}#{$cls-ui}-ml,
  361. .#{$prefix}#{$cls-ui}-mr {
  362. @if $background-color != transparent {
  363. background-image: slicer-corner-sprite($cls-ui, '#{$cls}/#{$cls-ui}-corners');
  364. }
  365. }
  366. @if $background-color != transparent {
  367. @if $include-frame-rtl {
  368. .#{$prefix}rtl {
  369. &.#{$prefix}#{$cls-ui}-tl,
  370. &.#{$prefix}#{$cls-ui}-ml,
  371. &.#{$prefix}#{$cls-ui}-bl,
  372. &.#{$prefix}#{$cls-ui}-tr,
  373. &.#{$prefix}#{$cls-ui}-mr,
  374. &.#{$prefix}#{$cls-ui}-br {
  375. background-image: slicer-corner-sprite-rtl($cls-ui, '#{$cls}/#{$cls-ui}-corners-rtl');
  376. }
  377. }
  378. }
  379. }
  380. @if $vertical == true {
  381. .#{$prefix}#{$cls-ui}-tc,
  382. .#{$prefix}#{$cls-ui}-bc {
  383. @if $background-color != transparent {
  384. background-image: slicer-sides-sprite($cls-ui, '#{$cls}/#{$cls-ui}-sides');
  385. background-repeat: repeat-x;
  386. }
  387. }
  388. @if $include-frame-rtl and $background-color != transparent {
  389. .#{$prefix}rtl {
  390. &.#{$prefix}#{$cls-ui}-tc,
  391. &.#{$prefix}#{$cls-ui}-bc {
  392. background-image: slicer-sides-sprite-rtl($cls-ui, '#{$cls}/#{$cls-ui}-sides-rtl');
  393. }
  394. }
  395. }
  396. } @else {
  397. .#{$prefix}#{$cls-ui}-ml,
  398. .#{$prefix}#{$cls-ui}-mr {
  399. @if $background-color != transparent {
  400. background-image: slicer-sides-sprite($cls-ui, '#{$cls}/#{$cls-ui}-sides');
  401. @if is-null($background-gradient) {
  402. background-repeat: repeat-y;
  403. }
  404. }
  405. }
  406. }
  407. .#{$prefix}#{$cls-ui}-mc {
  408. padding: $extra-padding-top $extra-padding-right $extra-padding-bottom $extra-padding-left;
  409. }
  410. }
  411. @include x-slicer($cls-ui);
  412. }