oojs-ui-mediawiki.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*!
  2. * OOjs UI v0.17.1
  3. * https://www.mediawiki.org/wiki/OOjs_UI
  4. *
  5. * Copyright 2011–2016 OOjs UI Team and other contributors.
  6. * Released under the MIT license
  7. * http://oojs.mit-license.org
  8. *
  9. * Date: 2016-05-03T22:58:02Z
  10. */
  11. ( function ( OO ) {
  12. 'use strict';
  13. /**
  14. * @class
  15. * @extends OO.ui.Theme
  16. *
  17. * @constructor
  18. */
  19. OO.ui.MediaWikiTheme = function OoUiMediaWikiTheme() {
  20. // Parent constructor
  21. OO.ui.MediaWikiTheme.parent.call( this );
  22. };
  23. /* Setup */
  24. OO.inheritClass( OO.ui.MediaWikiTheme, OO.ui.Theme );
  25. /* Methods */
  26. /**
  27. * @inheritdoc
  28. */
  29. OO.ui.MediaWikiTheme.prototype.getElementClasses = function ( element ) {
  30. // Parent method
  31. var variant, isFramed, isActive,
  32. variants = {
  33. warning: false,
  34. invert: false,
  35. progressive: false,
  36. constructive: false,
  37. destructive: false
  38. },
  39. // Parent method
  40. classes = OO.ui.MediaWikiTheme.parent.prototype.getElementClasses.call( this, element );
  41. if ( element.supports( [ 'hasFlag' ] ) ) {
  42. isFramed = element.supports( [ 'isFramed' ] ) && element.isFramed();
  43. isActive = element.supports( [ 'isActive' ] ) && element.isActive();
  44. if (
  45. ( isFramed && ( isActive || element.isDisabled() || element.hasFlag( 'primary' ) ) )
  46. ) {
  47. // Button with a dark background, use white icon
  48. variants.invert = true;
  49. } else if ( !isFramed && element.isDisabled() ) {
  50. // Frameless disabled button, always use black icon regardless of flags
  51. variants.invert = false;
  52. } else {
  53. // Any other kind of button, use the right colored icon if available
  54. variants.progressive = element.hasFlag( 'progressive' );
  55. variants.constructive = element.hasFlag( 'constructive' );
  56. variants.destructive = element.hasFlag( 'destructive' );
  57. variants.warning = element.hasFlag( 'warning' );
  58. }
  59. }
  60. for ( variant in variants ) {
  61. classes[ variants[ variant ] ? 'on' : 'off' ].push( 'oo-ui-image-' + variant );
  62. }
  63. return classes;
  64. };
  65. /* Instantiation */
  66. OO.ui.theme = new OO.ui.MediaWikiTheme();
  67. }( OO ) );