Last active
December 20, 2015 06:39
-
-
Save ziyahan/6087265 to your computer and use it in GitHub Desktop.
Javascript Structure
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
| $(document).ready(function () { | |
| var selectedText = ""; | |
| var isSelected = false; | |
| $(this).bind('touchend', function () { | |
| if (obj.text != "") { | |
| selectedText = getSelected(); | |
| if (selectedText != null && selectedText.length > 0) { | |
| ajax("function=savetext&text=" + selectedText); | |
| isSelected = true; | |
| } | |
| } | |
| }); | |
| }); | |
| function getSelected() { | |
| if (window.getSelection) { | |
| return window.getSelection(); | |
| } else if (document.getSelection) { | |
| return document.getSelection(); | |
| } else { | |
| var selection = document.selection && document.selection.createRange(); | |
| if (selection.text) { | |
| return selection.text; | |
| } | |
| return false; | |
| } | |
| return false; | |
| } | |
| function ajax(parameters, type) { | |
| var urlprefix = ""; | |
| if (type == "admin") | |
| urlprefix = "../"; | |
| $.post(urlprefix + "core/ajax.php", parameters) | |
| .success(function (rData) { | |
| var obj = $.parseJSON(rData); | |
| if (obj.code == 0) { | |
| if (obj.msg != "") | |
| alert(obj.msg); | |
| if (obj.url != "") | |
| document.location.href = obj.url; | |
| if (obj.func != "") | |
| jQuery.globalEval(obj.func); | |
| } | |
| if (obj.code == 1) { | |
| if (obj.msg != "") | |
| alert(obj.msg); | |
| if (obj.url != "") | |
| document.location.href = obj.url; | |
| if (obj.func != "") | |
| eval(obj.func); | |
| } | |
| }) | |
| .error(function (xhr, ajaxOptions, thrownError) { | |
| alert(xhr.status); | |
| alert(thrownError); | |
| }) | |
| .complete(function () { | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment