]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/assets/syntax.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / assets / syntax.js
1 if (YUI && yuiConfig) {
2     YUI(yuiConfig).use('node', 'event-mouseenter', 'yui-later', function(Y) {
3         var items = Y.all('.yui-syntax-highlight'),
4             openWindow = function(node, print) {
5                 var n = Y.one('#' + node.get('id') + '-plain'),
6                     code = n.get('value'), win = null,
7                     h = n.get('offsetHeight');
8
9                 code = code.replace(/</g, '&lt;').replace(/>/g, '&gt;');
10                 win = window.open('', "codeview", "status=0,scrollbars=1,width=600,height=400,menubar=0,toolbar=0,directories=0"); 
11                 win.document.body.innerHTML = '<pre>' + code + '</pre>';
12
13                 if (print) {
14                     Y.later(1000, win, function() {
15                         win.focus();
16                         win.print();
17                         win.focus();
18                     });
19                 }
20             },
21             handleClick = function(e) {
22                 if (e.target.get('tagName').toLowerCase() == 'a') {
23                     var type = e.target.get('innerHTML').replace(/ /g, '');
24                     switch (type) {
25                         case 'print':
26                             openWindow(e.target.get('parentNode.parentNode'), true);
27                             break;
28                         case 'viewplain':
29                             openWindow(e.target.get('parentNode.parentNode'));
30                             break;
31                         case 'togglelinenumbers':
32                             e.target.get('parentNode.parentNode').toggleClass('yui-syntax-highlight-linenumbers');
33                             break;
34                         case 'copy':
35                             break;
36                     }
37                 }
38                 e.halt();
39             };
40
41
42
43         items.each(function(i) {
44             //var header = Y.Node.create('<div class="syn-header hidden"><a href="#">view plain</a> | <a href="#">print</a> | <a href="#">copy</a></div>');
45             var header = Y.Node.create('<div class="syn-header hidden"><a href="#">view plain</a> | <a href="#">print</a> | <a href="#">toggle line numbers</a></div>');
46             header.on('click', handleClick);
47             i.insertBefore(header, i.get('firstChild'));
48             i.on('mouseenter', function() {
49                 header.removeClass('hidden');
50             });
51             i.on('mouseleave', function() {
52                 header.addClass('hidden');
53             });
54         });
55     });
56 }