Created
October 1, 2015 16:15
-
-
Save dennisseah/817623be89866dac1e7b to your computer and use it in GitHub Desktop.
Flip Toggle SAPUI5 Desktop button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>SAPUI5 Flip Toggle Button</title> | |
<style> | |
.toggleFlipButton { | |
padding: 0px; | |
padding-left: 0px; | |
padding-right: 0px; | |
background-color: transparent !important; | |
outline-color: transparent !important; | |
border: none !important; | |
border-style: none !important; | |
} | |
.toggleFlipButton>DIV { | |
color: #333; | |
background-color: #f7f7f7; | |
padding-left: 2px; | |
padding-right: 2px; | |
padding-top: 2px; | |
text-align:center; | |
border: 1px solid #bfbfbf !important; | |
} | |
.sapUiToggleBtnPressed { | |
color: #333333 !important; | |
outline-color: transparent !important; | |
background-color: transparent !important; | |
} | |
.sapUiToggleBtnPressed>DIV { | |
color: #ffffff; | |
background-color: #007cc0; | |
} | |
</style> | |
<script | |
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" | |
id="sap-ui-bootstrap" | |
data-sap-ui-theme="sap_bluecrystal" | |
data-sap-ui-xx-bindingSyntax="complex" | |
data-sap-ui-libs="sap.ui.commons,sap.m"></script> | |
<script src="https://cdn.rawgit.com/nnattawat/flip/v1.0.16/dist/jquery.flip.min.js"></script> | |
<script> | |
sap.ui.commons.ToggleButton.extend('FlipToggleButton', { | |
metadata: { | |
properties: { | |
pressedText: 'string' | |
} | |
}, | |
renderer: {}, | |
onAfterRendering: function() { | |
if (sap.ui.commons.ToggleButton.prototype.onAfterRendering) { | |
sap.ui.commons.ToggleButton.prototype.onAfterRendering.apply(this, arguments); | |
} | |
function replaceTagName(tag) { | |
new_element = $("<div/>"); | |
$.each(tag.get(0).attributes, function(i, attr) { | |
$(new_element).attr(attr.name, attr.value); | |
}); | |
new_element.html(tag.html()); | |
tag.replaceWith(new_element); | |
} | |
var $this = this.$(); | |
var width = $this.width(); | |
var height = $this.height(); | |
var innerHtml = $this.html(); | |
var front = $('<div/>'); | |
front.addClass('front'); | |
front.html(innerHtml); | |
front.css('width', width + 'px'); | |
front.css('height', height + 'px'); | |
var back = $('<div/>'); | |
back.addClass('back'); | |
back.html(innerHtml); | |
back.css('width', width + 'px'); | |
back.css('height', height + 'px'); | |
var pressedText = this.getPressedText() || this.getText(); | |
back.find('.sapUiBtnTxt').html(pressedText); | |
$this.html(''); | |
$this.append(front).append(back); | |
replaceTagName($this); | |
$this = this.$(); | |
$this.flip(); | |
$this.addClass('toggleFlipButton'); | |
$this.css('width', (width +16) + 'px'); | |
$this.css('height', height); | |
} | |
}); | |
var btn = new FlipToggleButton({ | |
text: 'Press Me', | |
pressedText: 'Me Pressed', | |
icon: 'sap-icon://synchronize', | |
press: function(e) { | |
sap.m.MessageToast.show(this.getPressed()); | |
} | |
}); | |
btn.placeAt('content'); | |
</script> | |
</head> | |
<body class="sapUiBody"> | |
<div id='content'></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment