小编jcu*_*bic的帖子

如何在Ace编辑器中获取所选文本?

我查看文档,并选择源代码,我找不到任何东西,我看到的只是选择和范围对象,以及操纵范围的方法.

javascript ace-editor

7
推荐指数
2
解决办法
4264
查看次数

将文本拆分为相等长度的字符串,保持字不变

我有这个代码,将较长的行分成等长字符串的数组保持单词,它也考虑到格式化[[u;#fff;]some text],它分割文本,因此每个字符串可以独立转换为HTML:

var format_re = /\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?/gi;
var format_begin_re = /(\[\[[!gbiuso]*;[^;]*;[^\]]*\])/i;
var format_last_re = /\[\[[!gbiuso]*;[^;]*;[^\]]*\]?$/i;
$.terminal.split_equal = function(str, length, words) {
  var formatting = false;
  var in_text = false;
  var prev_format = '';
  var result = [];
  // add format text as 5th paramter to formatting it's used for
  // data attribute in format function
  var array = str.replace(format_re, function(_, format, text) {
    var semicolons = format.match(/;/g).length;
    // missing semicolons
    if (semicolons == 2) {
      semicolons = ';;';
    } …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

7
推荐指数
1
解决办法
951
查看次数

如何在javascript中单击文本时获取字符位置

我有这个函数来点击文本时获取光标的位置,它只适用于等宽字符,这很好,但它显然不适用于像中文或日文更宽的字符.

    function get_char_pos(point) {
        var prompt_len = self.find('.prompt').text().length;
        var size = get_char_size();
        var width = size.width;
        var height = size.height;
        var offset = self.offset();
        var col = Math.floor((point.x - offset.left) / width);
        var row = Math.floor((point.y - offset.top) / height);
        var lines = get_splited_command_line(command);
        var try_pos;
        if (row > 0 && lines.length > 1) {
            try_pos = col + lines.slice(0, row).reduce(function(sum, line) {
                return sum + line.length;
            }, 0);
        } else {
            try_pos = col - prompt_len;
        }
        // tabs …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

7
推荐指数
2
解决办法
3260
查看次数

如何列出元素中的所有css变量名称/值对

我有JS库,我有这个问题:我正在使用等宽字体创建用于计算字符大小的临时元素.现在我正在复制风格,但我需要原始的所有样式,包括css变量.我不想克隆元素,因为里面有我不需要的元素.此外,元素可能具有用户设置的id,不确定当存在两个具有相同id的元素时这将如何表现,因此将每个样式复制到新的临时元素会更好(我认为).

我有基于这些的代码:

我的代码看起来像这样:

function is_valid_style_property(key, value) {
    //checking that the property is not int index ( happens on some browser
    return typeof value === 'string' && value.length && value !== parseInt(value);
}

function copy_computed_style(from, to) {
    var computed_style_object = false;
    computed_style_object = from.currentStyle || document.defaultView.getComputedStyle(from, null);

    if (!computed_style_object) {
        return;
    }
    Object.keys(computed_style_object).forEach(function(key) {
        var value = computed_style_object.getPropertyValue(key);
        if (key.match(/^--/)) {
            console.log({key, value}); // this is never executed
        }
        if (is_valid_style_property(key, value)) {
            to.style.setProperty(key, value);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

问题是 …

javascript css css-variables

7
推荐指数
1
解决办法
574
查看次数

实现“少”时,例如在移动设备上滚动时,仅触摸一次移动火

我正在尝试在 jQuery 终端的较少扩展中实现触摸滚动。它的工作方式类似于 less unix 命令。

我有这个代码:

self.touch_scroll(function(event) {
    // how much difference changed since last touch move
    var delta = event.current.clientY - event.previous.clientY;
    var ret;
    var interpreter = interpreters.top();
    if (is_function(interpreter.touchscroll)) {
        ret = interpreter.touchscroll(event, delta, self);
    } else if (is_function(settings.touchscroll)) {
        ret = settings.touchscroll(event, delta, self);
    }
    if (ret === true) {
        return;
    }
    return false;
});
// make_callback_plugin is helper that use $.Callbacks and make sure that there is only
// one handler on the element
$.fn.touch_scroll …
Run Code Online (Sandbox Code Playgroud)

javascript jquery android touch-event jquery-terminal

7
推荐指数
1
解决办法
625
查看次数

如何在Ubuntu上使用openjdk构建android项目?

我发现在Ubuntu 10.10上使用Android SDK确实需要Sun Java吗?我更喜欢OpenJDK,但我无法在Ubuntu上构建android项目.当我尝试:

$ ant debug
Run Code Online (Sandbox Code Playgroud)

我有:

Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar

...

BUILD FAILED
/home/kuba/projects/Android/android-sdk-linux/tools/ant/build.xml:651: The following error occurred while executing this line:
/home/kuba/projects/Android/android-sdk-linux/tools/ant/build.xml:672: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-openjdk/jre"
Run Code Online (Sandbox Code Playgroud)

我有java版本:

$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.13) (6b20-1.9.13-0ubuntu1~10.10.1)
OpenJDK Client VM (build 19.0-b09, mixed mode, sharing)
Run Code Online (Sandbox Code Playgroud)

ubuntu openjdk android

6
推荐指数
1
解决办法
2万
查看次数

在php异常中使用其他数据

我有执行python cgi的PHP代码,我想传递python跟踪(从cgi返回)作为额外的数据到php异常我该怎么做呢?我怎样才能从中获取该值catch(Exception e) {(它应该检查是否有额外的值exesit ).

我有这样的代码:

$response = json_decode(curl_exec($ch));
if (isset($response->error)) {
    // how to send $response->trace with exception.
    throw new Exception($response->error);
}
return $response->result;
Run Code Online (Sandbox Code Playgroud)

我使用json-rpc库,应该将该数据返回给用户:

} catch (Exception $e) {
    //catch all exeption from user code
    $msg = $e->getMessage();
    echo response(null, $id, array("code"=>200, "message"=>$msg));
}
Run Code Online (Sandbox Code Playgroud)

我是否需要编写新类型的异常,或者我可以正常Exception吗?我想发送所有扔进去的东西"data" =>

php exception-handling exception

6
推荐指数
1
解决办法
3930
查看次数

如何使用jasmine和node从命令行测试jQuery插件?

我有jQuery插件,我正在测试.我发现了这个问题:如何从命令行对Node.js运行Jasmine测试?但是当我跑步时:

node_modules/jasmine-node/bin/jasmine-node --verbose --junitreport --noColor spec
Run Code Online (Sandbox Code Playgroud)

我得到了$ $未定义的错误.我怎么能包含jQuery?(现在我只测试不与dom交互的实用程序).

javascript jquery node.js jasmine

6
推荐指数
1
解决办法
928
查看次数

AngularJS在get请求中包含API密钥

我正在尝试使用AngularJS从幻想数据API获取信息.我使用$ resource在我的控制器中执行我的get请求,但是我无法弄清楚如何正确地包含API密钥.我是否需要将其作为标题包含在内?谢谢.

nflApp.controller('mainController', ['$scope','$resource','$routeParams', function($scope, $resource, $routeParams) {

$scope.fantasyAPI = $resource("https://api.fantasydata.net/nfl/v2/JSON/DailyFantasyPlayers/2015-DEC-28", { callback: "JSON_CALLBACK" }, { get: { method: "JSONP"}});

console.log($scope.fantasyAPI);

}]);
Run Code Online (Sandbox Code Playgroud)

以下是该站点的http请求信息. http请求信息

javascript angularjs

6
推荐指数
1
解决办法
4118
查看次数

使用javascript函数递归制作星形三角形

我对编程很陌生,我开始了解 JavaScript,而且我刚刚学习了递归的概念。现在我遇到了一个问题,要创建一个函数(如const f = function(n) { }),如果我们使用 调用该函数f(5),我们应该看到:

     *
    ***
   *****
  *******
 *********
Run Code Online (Sandbox Code Playgroud)

垂直星的数量必须由输入确定。我必须使用 no for/while/do-while;递归只能循环。

我想出了这个代码来连接 5 颗星

const f = function(n) {
  if (n === 0) {
    return "";
  }
  return  "*" +  f(n - 1);
};

 console.log(f(5));
Run Code Online (Sandbox Code Playgroud)

虽然,我不知道如何制作三角形,我该怎么办?

javascript recursion

6
推荐指数
1
解决办法
2678
查看次数