PageSourceSearch

http://bayalagbuteegch.mn/js/wysiwyg.js

js bayalagbuteegch.mn collected 2026-10-04 13:28:48 UTC 10,104 bytes, 313 lines download raw bytes

1/*
2 * jQuery Hotkeys Plugin
3 * Copyright 2010, John Resig
4 * Dual licensed under the MIT or GPL Version 2 licenses.
5 *
6 * Based upon the plugin by Tzury Bar Yochay:
7 * http://github.com/tzuryby/hotkeys
8 *
9 * Original idea by:
10 * Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/
11*/
12
13/*
14 * One small change is: now keys are passed by object { keys: '...' }
15 * Might be useful, when you want to pass some other data to your handler
16 */
17
18
19(function(jQuery){
20
21	jQuery.hotkeys = {
22		version: "0.8",
23
24		specialKeys: {
25			8: "backspace", 9: "tab", 10: "return", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause",
26			20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home",
27			37: "left", 38: "up", 39: "right", 40: "down", 45: "insert", 46: "del", 
28			96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7",
29			104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/", 
30			112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8", 
31			120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 186: ";", 191: "/",
32			220: "\\", 222: "'", 224: "meta"
33		},
34
35		shiftNums: {
36			"`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", "6": "^", "7": "&", 
37			"8": "*", "9": "(", "0": ")", "-": "_", "=": "+", ";": ": ", "'": "\"", ",": "<", 
38			".": ">",  "/": "?",  "\\": "|"
39		}
40	};
41
42	function keyHandler( handleObj ) {
43		if ( typeof handleObj.data === "string" ) {
44			handleObj.data = { keys: handleObj.data };
45		}
46
47		// Only care when a possible input has been specified
48		if ( !handleObj.data || !handleObj.data.keys || typeof handleObj.data.keys !== "string" ) {
49			return;
50		}
51
52		var origHandler = handleObj.handler,
53			keys = handleObj.data.keys.toLowerCase().split(" "),
54			textAcceptingInputTypes = ["text", "password", "number", "email", "url", "range", "date", "month", "week", "time", "datetime", "datetime-local", "search", "color", "tel"];
55
56		handleObj.handler = function( event ) {
57			// Don't fire in text-accepting inputs that we didn't directly bind to
58			if ( this !== event.target && (/textarea|select/i.test( event.target.nodeName ) ||
59				jQuery.inArray(event.target.type, textAcceptingInputTypes) > -1 ) ) {
60				return;
61			}
62
63			var special = jQuery.hotkeys.specialKeys[ event.keyCode ],
64				// character codes are available only in keypress
65				character = event.type === "keypress" && String.fromCharCode( event.which ).toLowerCase(),
66				modif = "", possible = {};
67
68			// check combinations (alt|ctrl|shift+anything)
69			if ( event.altKey && special !== "alt" ) {
70				modif += "alt+";
71			}
72
73			if ( event.ctrlKey && special !== "ctrl" ) {
74				modif += "ctrl+";
75			}
76
77			// TODO: Need to make sure this works consistently across platforms
78			if ( event.metaKey && !event.ctrlKey && special !== "meta" ) {
79				modif += "meta+";
80			}
81
82			if ( event.shiftKey && special !== "shift" ) {
83				modif += "shift+";
84			}
85
86			if ( special ) {
87				possible[ modif + special ] = true;
88			}
89
90			if ( character ) {
91				possible[ modif + character ] = true;
92				possible[ modif + jQuery.hotkeys.shiftNums[ character ] ] = true;
93
94				// "$" can be triggered as "Shift+4" or "Shift+$" or just "$"
95				if ( modif === "shift+" ) {
96					possible[ jQuery.hotkeys.shiftNums[ character ] ] = true;
97				}
98			}
99
100			for ( var i = 0, l = keys.length; i < l; i++ ) {
101				if ( possible[ keys[i] ] ) {
102					return origHandler.apply( this, arguments );
103				}
104			}
105		};
106	}
107
108	jQuery.each([ "keydown", "keyup", "keypress" ], function() {
109		jQuery.event.special[ this ] = { add: keyHandler };
110	});
111
112})( this.jQuery );
113
114/* http://github.com/mindmup/bootstrap-wysiwyg */
115/*global jQuery, $, FileReader*/
116/*jslint browser:true*/
117(function ($) {
118	'use strict';
119	var readFileIntoDataUrl = function (fileInfo) {
120		var loader = $.Deferred(),
121			fReader = new FileReader();
122		fReader.onload = function (e) {
123			loader.resolve(e.target.result);
124		};
125		fReader.onerror = loader.reject;
126		fReader.onprogress = loader.notify;
127		fReader.readAsDataURL(fileInfo);
128		return loader.promise();
129	};
130	$.fn.cleanHtml = function () {
131		var html = $(this).html();
132		return html && html.replace(/(<br>|\s|<div><br><\/div>|&nbsp;)*$/, '');
133	};
134	$.fn.wysiwyg = function (userOptions) {
135		var editor = this,
136			selectedRange,
137			options,
138			toolbarBtnSelector,
139			updateToolbar = function () {
140				if (options.activeToolbarClass) {
141					$(options.toolbarSelector).find(toolbarBtnSelector).each(function () {
142						var command = $(this).data(options.commandRole);
143						if (document.queryCommandState(command)) {
144							$(this).addClass(options.activeToolbarClass);
145						} else {
146							$(this).removeClass(options.activeToolbarClass);
147						}
148					});
149				}
150			},
151			execCommand = function (commandWithArgs, valueArg) {
152				var commandArr = commandWithArgs.split(' '),
153					command = commandArr.shift(),
154					args = commandArr.join(' ') + (valueArg || '');
155				document.execCommand(command, 0, args);
156				updateToolbar();
157			},
158			bindHotkeys = function (hotKeys) {
159				$.each(hotKeys, function (hotkey, command) {
160					editor.keydown(hotkey, function (e) {
161						if (editor.attr('contenteditable') && editor.is(':visible')) {
162							e.preventDefault();
163							e.stopPropagation();
164							execCommand(command);
165						}
166					}).keyup(hotkey, function (e) {
167						if (editor.attr('contenteditable') && editor.is(':visible')) {
168							e.preventDefault();
169							e.stopPropagation();
170						}
171					});
172				});
173			},
174			getCurrentRange = function () {
175				var sel = window.getSelection();
176				if (sel.getRangeAt && sel.rangeCount) {
177					return sel.getRangeAt(0);
178				}
179			},
180			saveSelection = function () {
181				selectedRange = getCurrentRange();
182			},
183			restoreSelection = function () {
184				var selection = window.getSelection();
185				if (selectedRange) {
186					try {
187						selection.removeAllRanges();
188					} catch (ex) {
189						document.body.createTextRange().select();
190						document.selection.empty();
191					}
192
193					selection.addRange(selectedRange);
194				}
195			},
196			insertFiles = function (files) {
197				editor.focus();
198				$.each(files, function (idx, fileInfo) {
199					if (/^image\//.test(fileInfo.type)) {
200						$.when(readFileIntoDataUrl(fileInfo)).done(function (dataUrl) {
201							execCommand('insertimage', dataUrl);
202						}).fail(function (e) {
203							options.fileUploadError("file-reader", e);
204						});
205					} else {
206						options.fileUploadError("unsupported-file-type", fileInfo.type);
207					}
208				});
209			},
210			markSelection = function (input, color) {
211				restoreSelection();
212				if (document.queryCommandSupported('hiliteColor')) {
213					document.execCommand('hiliteColor', 0, color || 'transparent');
214				}
215				saveSelection();
216				input.data(options.selectionMarker, color);
217			},
218			bindToolbar = function (toolbar, options) {
219				toolbar.find(toolbarBtnSelector).click(function () {
220					restoreSelection();
221					editor.focus();
222					execCommand($(this).data(options.commandRole));
223					saveSelection();
224				});
225				toolbar.find('[data-toggle=dropdown]').click(restoreSelection);
226
227				toolbar.find('input[type=text][data-' + options.commandRole + ']').on('webkitspeechchange change', function () {
228					var newValue = this.value; /* ugly but prevents fake double-calls due to selection restoration */
229					this.value = '';
230					restoreSelection();
231					if (newValue) {
232						editor.focus();
233						execCommand($(this).data(options.commandRole), newValue);
234					}
235					saveSelection();
236				}).on('focus', function () {
237					var input = $(this);
238					if (!input.data(options.selectionMarker)) {
239						markSelection(input, options.selectionColor);
240						input.focus();
241					}
242				}).on('blur', function () {
243					var input = $(this);
244					if (input.data(options.selectionMarker)) {
245						markSelection(input, false);
246					}
247				});
248				toolbar.find('input[type=file][data-' + options.commandRole + ']').change(function () {
249					restoreSelection();
250					if (this.type === 'file' && this.files && this.files.length > 0) {
251						insertFiles(this.files);
252					}
253					saveSelection();
254					this.value = '';
255				});
256			},
257			initFileDrops = function () {
258				editor.on('dragenter dragover', false)
259					.on('drop', function (e) {
260						var dataTransfer = e.originalEvent.dataTransfer;
261						e.stopPropagation();
262						e.preventDefault();
263						if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
264							insertFiles(dataTransfer.files);
265						}
266					});
267			};
268		options = $.extend({}, $.fn.wysiwyg.defaults, userOptions);
269		toolbarBtnSelector = 'a[data-' + options.commandRole + '],button[data-' + options.commandRole + '],input[type=button][data-' + options.commandRole + ']';
270		bindHotkeys(options.hotKeys);
271		if (options.dragAndDropImages) {
272			initFileDrops();
273		}
274		bindToolbar($(options.toolbarSelector), options);
275		editor.attr('contenteditable', true)
276			.on('mouseup keyup mouseout', function () {
277				saveSelection();
278				updateToolbar();
279			});
280		$(window).bind('touchend', function (e) {
281			var isInside = (editor.is(e.target) || editor.has(e.target).length > 0),
282				currentRange = getCurrentRange(),
283				clear = currentRange && (currentRange.startContainer === currentRange.endContainer && currentRange.startOffset === currentRange.endOffset);
284			if (!clear || isInside) {
285				saveSelection();
286				updateToolbar();
287			}
288		});
289		return this;
290	};
291	$.fn.wysiwyg.defaults = {
292		hotKeys: {
293			'ctrl+b meta+b': 'bold',
294			'ctrl+i meta+i': 'italic',
295			'ctrl+u meta+u': 'underline',
296			'ctrl+z meta+z': 'undo',
297			'ctrl+y meta+y meta+shift+z': 'redo',
298			'ctrl+l meta+l': 'justifyleft',
299			'ctrl+r meta+r': 'justifyright',
300			'ctrl+e meta+e': 'justifycenter',
301			'ctrl+j meta+j': 'justifyfull',
302			'shift+tab': 'outdent',
303			'tab': 'indent'
304		},
305		toolbarSelector: '[data-role=editor-toolbar]',
306		commandRole: 'edit',
307		activeToolbarClass: 'btn-info',
308		selectionMarker: 'edit-focus-marker',
309		selectionColor: 'darkgrey',
310		dragAndDropImages: true,
311		fileUploadError: function (reason, detail) { console.log("File upload error", reason, detail); }
312	};
313}(window.jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.