-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix copy to clipboard is available only for rust snippets #447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ $( document ).ready(function() { | |
window.onunload = function(){}; | ||
|
||
// Set theme | ||
var theme = store.get('theme'); | ||
var theme = store.get('mdbook-theme'); | ||
if (theme === null || theme === undefined) { theme = 'light'; } | ||
|
||
set_theme(theme); | ||
|
@@ -145,7 +145,7 @@ $( document ).ready(function() { | |
}); | ||
} | ||
|
||
store.set('theme', theme); | ||
store.set('mdbook-theme', theme); | ||
|
||
$('body').removeClass().addClass(theme); | ||
} | ||
|
@@ -186,19 +186,36 @@ $( document ).ready(function() { | |
if(!lines_hidden) { return; } | ||
|
||
// add expand button | ||
pre_block.prepend("<div class=\"buttons\"><i class=\"fa fa-expand\"></i></div>"); | ||
pre_block.prepend("<div class=\"buttons\"><i class=\"fa fa-expand\" title=\"Show hidden lines\"></i></div>"); | ||
|
||
pre_block.find("i").click(function(e){ | ||
if( $(this).hasClass("fa-expand") ) { | ||
$(this).removeClass("fa-expand").addClass("fa-compress"); | ||
$(this).attr("title", "Hide lines"); | ||
pre_block.find("span.hidden").removeClass("hidden").addClass("unhidden"); | ||
} | ||
else { | ||
$(this).removeClass("fa-compress").addClass("fa-expand"); | ||
$(this).attr("title", "Show hidden lines"); | ||
pre_block.find("span.unhidden").removeClass("unhidden").addClass("hidden"); | ||
} | ||
}); | ||
}); | ||
|
||
$("pre code").each(function(i, block){ | ||
var pre_block = $(this).parent(); | ||
if( !pre_block.hasClass('playpen') ) { | ||
var buttons = pre_block.find(".buttons"); | ||
if(buttons.length == 0) { | ||
pre_block.prepend("<div class=\"buttons\"></div>"); | ||
buttons = pre_block.find(".buttons"); | ||
} | ||
buttons.prepend("<i class=\"fa fa-copy clip-button\"><i class=\"tooltiptext\"></i></i>"); | ||
buttons.find(".clip-button").mouseout(function(e){ | ||
hideTooltip(e.currentTarget); | ||
}); | ||
} | ||
}); | ||
|
||
// Process playpen code blocks | ||
$(".playpen").each(function(block){ | ||
|
@@ -209,12 +226,12 @@ $( document ).ready(function() { | |
pre_block.prepend("<div class=\"buttons\"></div>"); | ||
buttons = pre_block.find(".buttons"); | ||
} | ||
buttons.prepend("<i class=\"fa fa-play play-button hidden\"></i>"); | ||
buttons.prepend("<i class=\"fa fa-copy clip-button\"><i class=\"tooltiptext\"></i></i>"); | ||
buttons.prepend("<i class=\"fa fa-play play-button hidden\" title=\"Run this code\"></i>"); | ||
buttons.prepend("<i class=\"fa fa-copy clip-button\" title=\"Copy to clipboard\"><i class=\"tooltiptext\"></i></i>"); | ||
|
||
let code_block = pre_block.find("code").first(); | ||
if (window.ace && code_block.hasClass("editable")) { | ||
buttons.prepend("<i class=\"fa fa-history reset-button\"></i>"); | ||
buttons.prepend("<i class=\"fa fa-history reset-button\" title=\"Undo changes\"></i>"); | ||
} | ||
|
||
buttons.find(".play-button").click(function(e){ | ||
|
@@ -234,7 +251,7 @@ $( document ).ready(function() { | |
var clipboardSnippets = new Clipboard('.clip-button', { | ||
text: function(trigger) { | ||
hideTooltip(trigger); | ||
let playpen = $(trigger).parents(".playpen"); | ||
let playpen = $(trigger).parents("pre"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. most likely we would no longer name this variable |
||
return playpen_text(playpen); | ||
} | ||
}); | ||
|
@@ -336,17 +353,17 @@ function sidebarToggle() { | |
var html = $("html"); | ||
if ( html.hasClass("sidebar-hidden") ) { | ||
html.removeClass("sidebar-hidden").addClass("sidebar-visible"); | ||
store.set('sidebar', 'visible'); | ||
store.set('mdbook-sidebar', 'visible'); | ||
} else if ( html.hasClass("sidebar-visible") ) { | ||
html.removeClass("sidebar-visible").addClass("sidebar-hidden"); | ||
store.set('sidebar', 'hidden'); | ||
store.set('mdbook-sidebar', 'hidden'); | ||
} else { | ||
if($("#sidebar").position().left === 0){ | ||
html.addClass("sidebar-hidden"); | ||
store.set('sidebar', 'hidden'); | ||
store.set('mdbook-sidebar', 'hidden'); | ||
} else { | ||
html.addClass("sidebar-visible"); | ||
store.set('sidebar', 'visible'); | ||
store.set('mdbook-sidebar', 'visible'); | ||
} | ||
} | ||
} | ||
|
@@ -358,30 +375,32 @@ function run_rust_code(code_block) { | |
result_block = code_block.find(".result"); | ||
} | ||
|
||
let text = playpen_text(code_block);; | ||
|
||
let text = playpen_text(code_block); | ||
var params = { | ||
version: "stable", | ||
optimize: "0", | ||
code: text, | ||
}; | ||
channel: "stable", | ||
mode: "debug", | ||
crateType: "bin", | ||
tests: false, | ||
code: text, | ||
} | ||
|
||
if(text.indexOf("#![feature") !== -1) { | ||
params.version = "nightly"; | ||
params.channel = "nightly"; | ||
} | ||
|
||
result_block.text("Running..."); | ||
|
||
$.ajax({ | ||
url: "https://play.rust-lang.org/evaluate.json", | ||
url: "https://play.rust-lang.org/execute", | ||
method: "POST", | ||
crossDomain: true, | ||
dataType: "json", | ||
contentType: "application/json", | ||
data: JSON.stringify(params), | ||
timeout: 15000, | ||
success: function(response){ | ||
result_block.text(response.result); | ||
result_block.text(response.success ? response.stdout : response.stderr); | ||
}, | ||
error: function(qXHR, textStatus, errorThrown){ | ||
result_block.text("Playground communication " + textStatus); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that we would prefer to have the button dock for each code/pre instead of specifically in the playgrounds. And only add additional buttons to (other than clipboard) to already existing button bar for rust specific snippets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll wait for your comments then.