Skip to content

Instantly share code, notes, and snippets.

@PsichiX
Last active September 9, 2015 02:14
Show Gist options
  • Save PsichiX/87d3fa0f94b57b062fe1 to your computer and use it in GitHub Desktop.
Save PsichiX/87d3fa0f94b57b062fe1 to your computer and use it in GitHub Desktop.
PlayGate - custom editors
{
"properties": {
"value": { "editorId" : "number" },
"text": { "editorId" : "string" },
"on": { "editorId" : "boolean" }
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script>
var data = null;
function onValueChange(){
var day = document.getElementById('date-day'),
month = document.getElementById('date-month'),
year = document.getElementById('date-year');
data = data || {};
data.day = parseInt(day.value, 10);
data.month = month.selectedIndex;
data.year = parseInt(year.value, 10);
window.pgEditorApplyValue(data);
}
window.onEditorInitialize = function(value){
window.pgEditorApplyWindowSize(400, 150);
window.onEditorUpdateValue(value);
return true;
};
window.onEditorClose = function(){
onValueChange();
};
window.onEditorUpdateValue = function(value){
data = value;
var now = new Date(),
day = document.getElementById('date-day'),
month = document.getElementById('date-month'),
year = document.getElementById('date-year');
day.value = data && data.hasOwnProperty('day') ? data.day : now.getDate().toString();
month.selectedIndex = data && data.hasOwnProperty('month') ? data.month : now.getMonth();
year.value = data && data.hasOwnProperty('year') ? data.year : now.getFullYear().toString();
};
</script>
</head>
<body>
<form>
<select id="date-day" onchange="onValueChange();">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select id="date-month" onchange="onValueChange();">
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<input id="date-year" type="number" onchange="onValueChange();"/>
</form>
<script>
var now = new Date(),
day = document.getElementById('date-day'),
month = document.getElementById('date-month'),
year = document.getElementById('date-year');
day.value = now.getDate().toString();
month.selectedIndex = now.getMonth();
year.value = now.getFullYear().toString();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment