示例#1
0
    def prepare(self):
        super(DynLoaderWidget, self).prepare()

        if self.hash is None:
            # User does not want a custom hash, set it randomly
            self.attrs['hash'] = self.hash = str(uuid4())

        if not hasattr(self, 'id') or 'id' not in self.attrs:
            self.attrs['id'] = self.id = "dynload-%s" % self.hash

        self._js_resources = []
        self._css_resources = []
        self._widgets = {}

        # put code here to run just before the widget is displayed
        for c in self.children:
            for res in c.resources:
                if issubclass(res, twc.JSLink):
                    self._js_resources.append("/resources/%s/%s" % (res.modname, res.req().filename))
                elif issubclass(res, twc.CSSLink):
                    self._css_resources.append("/resources/%s/%s"%(res.modname, res.req().filename))
                else:
                    pass

            self._widgets[c.id.encode()] = urllib.quote(c.display().encode())

        self.selector = self.attrs['id'].replace(':', '\\:')

        self.add_call(base.js_loader.load_widget(
            self.selector,
            twc.js_symbol(self._js_resources),
            twc.js_symbol(self._css_resources),
            twc.js_symbol(self._widgets)))
示例#2
0
 def prepare(self):
     super(Wysihtml5, self).prepare()
     wysihtml5_args = self.wysihtml5_args.copy()
     wysihtml5_args.update(stylesheets=self.stylesheets)
     if self.parser and self.parser in parsers:
         self.safe_modify('resources')
         self.resources.append(parsers[self.parser])
         wysihtml5_args.update(parserRules=twc.js_symbol('wysihtml5ParserRules'))
     if self.parser is False:
         wysihtml5_args.update(parser=twc.js_symbol('function(elementOrHtml, rules, context, cleanUp) { return elementOrHtml; }'))
     self.add_call(twj.jQuery(self.selector).wysihtml5(wysihtml5_args))
示例#3
0
 def prepare(self):
     super(Wysihtml5, self).prepare()
     wysihtml5_args = self.wysihtml5_args.copy()
     wysihtml5_args.update(stylesheets=self.stylesheets)
     if self.parser and self.parser in parsers:
         self.safe_modify('resources')
         self.resources.append(parsers[self.parser])
         wysihtml5_args.update(
             parserRules=twc.js_symbol('wysihtml5ParserRules'))
     if self.parser is False:
         wysihtml5_args.update(parser=twc.js_symbol(
             'function(elementOrHtml, rules, context, cleanUp) { return elementOrHtml; }'
         ))
     self.add_call(twj.jQuery(self.selector).wysihtml5(wysihtml5_args))
示例#4
0
    def prepare(self):
        super(MokshaContextualMenu, self).prepare()

        if not self.id:
            raise Exception("MokshaMenu must have an id!")
        if not self.callback:
            raise Exception("Must provide a callback URL!")

        menus = []
        for menu in self.menus:
            menus.append((menu.lower().replace(' ', ''), menu))
        self.menus = menus

        self.add_call(tw2.jquery.jQuery(
            twc.js_symbol('document')).buildContextualMenu({
                'template': self.callback,
                'menuWidth': self.menuWidth,
                'rootMenuSelector': ".%s" % self.rootMenuSelector,
                'menuSelector': ".%s" % self.menuSelector,
                'iconPath': self.iconPath,
                'hasImages': self.hasImages,
                'fadeTime': self.fadeTime,
                'fadeInTime': self.fadeInTime,
                'fadeOutTime': self.fadeOutTime,
                'adjustLeft': self.adjustLeft,
                'adjustTop': self.adjustTop,
                'opacity': self.opacity,
                'shadow': self.shadow,
                'effect': self.effect,
                'minZindex': self.minZindex
                }))
示例#5
0
    def test_js_function_composition(self):
        f = js_function("f")
        g = js_function("g")
        h = js_function("h")

        y = js_symbol("y")

        obj = f(g(h("x", y)))

        eq_(str(obj), """f(g(h("x", y)))""")
示例#6
0
文件: test_js.py 项目: Cito/tw2.core
    def test_js_function_composition(self):
        f = js_function("f")
        g = js_function("g")
        h = js_function("h")

        y = js_symbol("y")

        obj = f(g(h("x", y)))

        eq_(str(obj), """f(g(h("x", y)))""")
示例#7
0
 def test_multiline_js(self):
     """ https://github.com/toscawidgets/tw2.core/issues/12 """
     raw = """
         $(document).ready(function() {
               console.log("This is multiline javascript");
         });
     """
     expected = '{"onLoad": %s}' % raw
     f = js_symbol(raw)
     json = self.encode({'onLoad': f})
     eq_(json, expected)
示例#8
0
文件: test_js.py 项目: Cito/tw2.core
 def test_multiline_js(self):
     """ https://github.com/toscawidgets/tw2.core/issues/12 """
     raw = """
         $(document).ready(function() {
               console.log("This is multiline javascript");
         });
     """
     expected = '{"onLoad": %s}' % raw
     f = js_symbol(raw)
     json = self.encode({'onLoad': f})
     eq_(json, expected)
示例#9
0
文件: test_js.py 项目: Cito/tw2.core
    def test_encoding_widget_id(self):
        from tw2.core import Widget
        w = Widget("foo")

        f = js_callback(js_function('jQuery')(w).click(js_symbol('onClick')))
        args = {'onLoad': f}

        json = self.encode(args)
        eq_(json, '{"onLoad": function(){jQuery("foo").click(onClick)}}')

        json = self.encode({'args':args})
        eq_(json, '{"args": {"onLoad": function(){jQuery("foo").click(onClick)}}}')
示例#10
0
    def test_encoding_widget_id(self):
        from tw2.core import Widget
        w = Widget("foo")

        f = js_callback(js_function('jQuery')(w).click(js_symbol('onClick')))
        args = {'onLoad': f}

        json = self.encode(args)
        eq_(json, '{"onLoad": function(){jQuery("foo").click(onClick)}}')

        json = self.encode({'args': args})
        eq_(json,
            '{"args": {"onLoad": function(){jQuery("foo").click(onClick)}}}')
示例#11
0
    def prepare(self):
        if 'str' not in str(type(self.data)):
            raise ValueError, "QRCodeWidget data parameter must be a string"

        super(QRCodeWidget, self).prepare()
        # put code here to run just before the widget is displayed
        if 'str' not in str(type(self.correction_level)) and str(self.correction_level).upper() not in ['H', 'Q', 'M', 'L']:
            raise ValueError, 'QRCodeWidget correction_level must be a string containing one of the following options: H, Q, M, L'

        if 'int' not in str(type(self.qr_type)) or int(self.qr_type) <= 0 and int(self.qr_type) > 40:
            raise ValueError, "QRCodeWidget qr_type must be between 1 and 40 inclusive"

        if not hasattr(self, 'id') or 'id' not in self.attrs:
            raise ValueError, 'QRCodeWidget must be supplied an id'

        self.selector = self.attrs['id'].replace(':', '\\:') # grabed from tw2.jqplugins.ui
        self._width = str(self.width)

        self.add_call(base.js_draw_qr(self.selector, 
            self.data,
            self.qr_type,
            twc.js_symbol("QRErrorCorrectLevel.%s"%self.correction_level), 
            self.width))
示例#12
0
    def prepare(self):
        super(CookieConsentWidget, self).prepare()

        if self.options:
            cfg = self.options
        else:
            cfg = self.default_options

        # always use full URLs for themes
        theme = cfg.get('theme', 'light-floating')
        rl = request_local()
        cfg['theme'] = (
            rl['middleware'].config.res_prefix + 'tw2.cookieconsent/static/'
            + theme + ".css")

        # evaluate any lazy strings
        for key, value in cfg.items():
            if is_lazy_string(value):
                cfg[key] = str(value)

        self.add_call(js_function(
            "(function(window,cfg){window.cookieconsent_options=cfg;})"
        )(js_symbol("window"), cfg), location='head')
        inject_resources()
示例#13
0
 def test_js_symbol(self):
     obj = self.encode({"onLoad": js_symbol("param")})
     eq_(obj, '{"onLoad": param}')
示例#14
0
 def test_js_symbol(self):
     obj = self.encode({"onLoad": js_symbol("param")})
     eq_(obj, '{"onLoad": param}')
 def prepare(self):
     super(TagifyWidget, self).prepare()
     self.add_call(twc.js_function("$('#"+self.selector+"').tagify")(twc.js_symbol(self.options)))
示例#16
0
 def post_define(cls):
     cls.default_options = cls.default_options.copy()
     cls.default_options.update({
         'readOnly': 'nocursor',
         'viewportMargin': twc.js_symbol('Infinity')
     })
示例#17
0
 def post_define(cls):
     cls.default_options = cls.default_options.copy()
     cls.default_options.update({"readOnly": "nocursor", "viewportMargin": twc.js_symbol("Infinity")})