Last active
June 30, 2017 09:17
-
-
Save 4noha/79730f49cc27b2b2e026386a247c5e7d to your computer and use it in GitHub Desktop.
ConfluenceでHTMLコードブロックと変数用の記事を使って投票ページを作るやつ
This file contains hidden or 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
| <table id="vote_system"> | |
| <thead> | |
| <tr> | |
| <th>名前</th> | |
| <th>得票数</th> | |
| <th></th> | |
| <th></th> | |
| </tr> | |
| </thead> | |
| <tbody></tbody> | |
| </table> | |
| <script type="text/javascript"> | |
| $(function(){ | |
| var pageidPagename = { '68487898': 'てすと1', '68487886': 'てすと2' } | |
| var appDomain = ''; | |
| updateLikes = function( pageId, method ){ | |
| let postSettings = { | |
| type: method, | |
| url: `https://${appDomain}/rest/likes/1.0/content/${pageId}/likes`, | |
| contentType: 'application/json', | |
| success: function(){ | |
| let url = `https://${appDomain}/rest/likes/1.0/content/${ pageId }/likes?commentLikes=false`; | |
| let request = new XMLHttpRequest(); | |
| request.open( 'GET', url, true ); | |
| request.send( null ); | |
| request.onreadystatechange = function() { | |
| if (request.readyState == 4 && request.status == 200) { | |
| let likes = JSON.parse( request.responseText )['likes']; | |
| $(`#like${pageId}`).text( likes.length ); | |
| } | |
| } | |
| } | |
| }; | |
| $.ajax( postSettings ); | |
| }; | |
| for ( pageId in pageidPagename ){ | |
| let url = `https://${appDomain}/rest/likes/1.0/content/${ pageId }/likes?commentLikes=false`; | |
| let request = new XMLHttpRequest(); | |
| request.open( 'GET', url, true ); | |
| request.send( null ); | |
| request.onreadystatechange = function() { | |
| if (request.readyState == 4 && request.status == 200) { | |
| let likes = JSON.parse( request.responseText )['likes']; | |
| let pageId = request.responseURL.match( /\d{8}/ )[0]; | |
| let tr = $('<tr></tr>'); | |
| tr.append(`<td>${ pageidPagename[pageId] }</td><td id="like${pageId}">${ likes.length }</td>`); | |
| tr.append(`<td><input type="button" onclick="updateLikes( ${pageId}, 'POST' )" value="投票" /></td>`); | |
| tr.append(`<td><input type="button" onclick="updateLikes( ${pageId}, 'DELETE' )" value="取り消し" /></td>`); | |
| $('#vote_system tbody').append( tr ); | |
| } | |
| } | |
| } | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment