Exemplo n.º 1
0
    protected function renderClientRules(HTML_QuickForm2_JavascriptBuilder $builder)
    {
        $id = Am_Controller::escape($this->editor->getId());
        $vars = "";
        foreach ($this->tagsOptions as $k => $v) {
            $vars .= "['{$k}'],\n";
        }
        $vars = trim($vars, "\n\r,");
        $builder->addElementJavascript(<<<CUT
\$(function(){
    // modified version of http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript
    \$.fn.insertAtCaret = function (myValue) {
            return this.each(function(){
                    //IE support
                    if (document.selection) {
                            this.focus();
                            sel = document.selection.createRange();
                            sel.text = myValue;
                            this.focus();
                    }
                    //MOZILLA/NETSCAPE support
                    else if (this.selectionStart || this.selectionStart == '0') {
                            var startPos = this.selectionStart;
                            var endPos = this.selectionEnd;
                            var scrollTop = this.scrollTop;
                            this.value = this.value.substring(0, startPos)
                                          + myValue
                                  + this.value.substring(endPos,
    this.value.length);
                            this.focus();
                            this.selectionStart = startPos + myValue.length;
                            this.selectionEnd = startPos + myValue.length;
                            this.scrollTop = scrollTop;
                    } else {
                            this.value += myValue;
                            this.focus();
                    }
            });

    };
            
    \$('select#insert-tags').change(function(){
        var val = \$(this).val();
        if (!val) return;
        \$("#txt-0").insertAtCaret(val);
        \$(this).prop("selectedIndex", -1);
    });
            
    if (CKEDITOR.instances["{$id}"]) {
        delete CKEDITOR.instances["{$id}"];
    }
    var editor = null;
    \$("input[name='format']").change(function()
    {
        if (!this.checked) return;
        if (this.value == 'html')
        {
            if (!editor) {
                editor = initCkeditor("{$id}", { placeholder_items: [
                    {$vars}
                ]});
            }
            \$('select#insert-tags').hide();
        } else {
            if (editor) {
                editor.destroy();
                editor = null;
            }
            \$('select#insert-tags').show();
        }
    }).change();
});            
CUT
);
    }
Exemplo n.º 2
0
    protected function renderClientRules(HTML_QuickForm2_JavascriptBuilder $builder)
    {
        $generate = ___("generate");
        $builder->addElementJavascript(<<<CUT
\$(document).ready(function(){
    var pass0 = \$("input#_pass-0").after(" <a href='javascript:;' class='local' id='generate-pass'>{$generate}</a>");
    \$("a#generate-pass").click(function(){
        if (pass0.attr("type")!="text")
        {
            pass0.replaceWith("<input type='text' name='"+pass0.attr("name")
                    +"' id='"+pass0.attr("id")
                    +"' size='"+pass0.attr("size")
                    +"' />");
            pass0 = \$("input#_pass-0");
        }
        var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz";
        var pass = "";
        var len = 9;
        for(i=0;i<len;i++)
        {
            x = Math.floor(Math.random() * 62);
            pass += chars.charAt(x);
        }
        pass0.val(pass);
    });
});
CUT
);
    }
 public function testFormJavascript()
 {
     $builder = new HTML_QuickForm2_JavascriptBuilder();
     $element = new HTML_QuickForm2_Element_InputText();
     $mockRuleOne = $this->getMock('HTML_QuickForm2_Rule', array('validateOwner', 'getJavascriptCallback'), array($element));
     $mockRuleOne->expects($this->once())->method('getJavascriptCallback')->will($this->returnValue('jsRuleOne'));
     $mockRuleTwo = $this->getMock('HTML_QuickForm2_Rule', array('validateOwner', 'getJavascriptCallback'), array($element));
     $mockRuleTwo->expects($this->once())->method('getJavascriptCallback')->will($this->returnValue('jsRuleTwo'));
     $this->assertEquals('', $builder->getFormJavascript());
     $builder->setFormId('formOne');
     $builder->addRule($mockRuleOne);
     $builder->addElementJavascript('setupCodeOne');
     $builder->setFormId('formTwo');
     $builder->addRule($mockRuleTwo);
     $builder->addElementJavascript('setupCodeTwo');
     $scriptOne = $builder->getFormJavascript('formOne', false);
     $this->assertContains('jsRuleOne', $scriptOne);
     $this->assertContains('setupCodeOne', $scriptOne);
     $this->assertNotContains('jsRuleTwo', $scriptOne);
     $this->assertNotContains('setupCodeTwo', $scriptOne);
     $this->assertNotContains('<script', $scriptOne);
     $scriptTwo = $builder->getFormJavascript('formTwo', true);
     $this->assertNotContains('jsRuleOne', $scriptTwo);
     $this->assertNotContains('setupCodeOne', $scriptTwo);
     $this->assertContains('jsRuleTwo', $scriptTwo);
     $this->assertContains('setupCodeTwo', $scriptTwo);
     $this->assertContains('<script', $scriptTwo);
     $scriptBoth = $builder->getFormJavascript();
     $this->assertContains('jsRuleOne', $scriptBoth);
     $this->assertContains('setupCodeTwo', $scriptBoth);
 }
Exemplo n.º 4
0
    protected function renderClientRules(HTML_QuickForm2_JavascriptBuilder $builder)
    {
        $id = Am_Controller::escape($this->editor->getId());
        $vars = "";
        foreach ($this->tagsOptions as $k => $v) {
            $vars .= sprintf("[%s, %s],\n", Am_Controller::getJson($v), Am_Controller::getJson($k));
        }
        $vars = trim($vars, "\n\r,");
        $builder->addElementJavascript(<<<CUT
\$(function(){
    \$('select#insert-tags').change(function(){
        var val = \$(this).val();
        if (!val) return;
        \$("#txt-0").insertAtCaret(val);
        \$(this).prop("selectedIndex", -1);
    });
            
    if (CKEDITOR.instances["{$id}"]) {
        delete CKEDITOR.instances["{$id}"];
    }
    var editor = null;
    \$("input[name='format']").change(function()
    {
        if (window.configDisable_rte) return;
        if (!this.checked) return;
        if (this.value == 'html')
        {
            if (!editor) {
                editor = initCkeditor("{$id}", { placeholder_items: [
                    {$vars}
                ], entities_greek: false});
            }
            \$('#insert-tags-wrapper').hide();
        } else {
            if (editor) {
                editor.destroy();
                editor = null;
            }
            \$('#insert-tags-wrapper').show();
        }
    }).change();
});            
CUT
);
    }