* actually not all blocks because we don't want to add the setup bits to
the setup bits, so that's kinda shit
*/
- document.addEventListener('copy', function (e) {
- var target = $(e.target).closest('.switchable:not(.setup)').get(0);
- // not in a switchable
- if (!target) { return; }
- var lang = getHighlightLanguage(target);
- if (!lang) {
- // switchable without highlight (e.g. language-specific notes),
- // don't munge
- return;
- }
- e.preventDefault();
- // get generic setup code
- var prefix = document.querySelector('.setupcode.highlight-' + lang).textContent;
+ document.addEventListener('copy', copyCode);
- // prepend setup code to current snippet, get all of current snippet
- // in case only part of it was selected
- var data = prefix + target.textContent;
- // sane browsers
- e.clipboardData.setData('text/plain', data);
- // MSIE
- e.clipboardData.setData('Text', data);
+ ZeroClipboard.config({
+ swfPath: '../_static/zeroclipboard-2.1.6/ZeroClipboard.swf',
+ flashLoadTimeout: 3e3,
+ });
+ var zc = new ZeroClipboard();
+ zc.on('ready', function () {
+ var $highlighted = $('.switchable:not(.setup) .highlight').addClass('with-btn-clipboard');
+ var $clipboard_buttons =
+ $('<button type="button" class="btn-clipboard">Copy</button>')
+ .on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function () {
+ $(this).removeClass('active');
+ })
+ .prependTo($highlighted);
+ zc.clip($clipboard_buttons);
+ });
+ zc.on('copy', function (e) {
+ // yellow flash
+ $(e.target).addClass('active');
+ copyCode(e);
});
// stripe page stuff
});
})(); }
+
+ function copyCode(e) {
+ // works for both C-c and "Copy" button if copy button is injected
+ // inside highlighted code section
+ var target = $(e.target).closest('.switchable:not(.setup)').get(0);
+ // not in a switchable
+ if (!target) { return; }
+ var lang = getHighlightLanguage(target);
+ if (!lang) {
+ // switchable without highlight (e.g. language-specific notes),
+ // don't munge
+ return;
+ }
+
+ // get generic setup code
+ var setup_selector = '.setupcode.highlight-' + lang + ' pre';
+ var setup = document.querySelector(setup_selector).textContent;
+
+ // prepend setup code to current snippet, get all of current snippet
+ // in case only part of it was selected. Ensure we don't get e.g.
+ // button text around snippet itself
+ var data = setup + '\n' + target.querySelector('pre').textContent;
+ // sane browsers & ZeroClipboard
+ e.clipboardData.setData('text/plain', data);
+ // MSIE
+ e.clipboardData.setData('Text', data);
+
+ // no preventDefault on ZC event
+ e.preventDefault && e.preventDefault();
+ }
/**
* @param {Node} node highlight node to get the language of
* @returns {String|null} either the highlight language or null
url, db, username, password = \
info['host'], info['database'], info['user'], info['password']
common = XMLRPC::Client.new2("#{url}/xmlrpc/2/common")
- uid = common.authenticate(db, username, password, {})
- models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
+ uid = common.call('authenticate', db, username, password, {})
+ models = XMLRPC::Client.new2("#{url}/xmlrpc/2/object").proxy
.. code-block:: php