Tag Archives: bootstrap

TinyMCE Plugin: columns

tinymce.PluginManager.add("columns", function (editor) {
    function insert(count) {
        editor.undoManager.transact(function () {
            var row = editor.dom.create("div", { "class": "row" });
            var width = Math.ceil(12 / count);
            for (var index = 0; index < count; index++) {
                var column = editor.dom.add(row, "div", { "class": "col-sm-" + width });
                editor.dom.add(column, "p", {}, "Column " + (index + 1));
            }
            var node = editor.selection.getNode();
            if (node === editor.getBody()) {
                node = node.firstChild;
            }
            node.parentNode.insertBefore(row, node);
        });
    }

    function getMenuItem(text, count) {
        return {
            text: text,
            onclick: function () {
                insert(count);
            }
        };
    }

    var menu = [
        getMenuItem("Two", 2),
        getMenuItem("Three", 3),
        getMenuItem("Four", 4)
    ];
    editor.addMenuItem("columns", {
        text: "Insert columns",
        context: "insert",
        menu: menu
    });
});

TinyMCE Plugin: glyphicons

tinymce.PluginManager.add("glyphicons", function (editor) {
    function insert(name) {
        editor.insertContent("<span class='glyphicon glyphicon-" + name + "'></span>");
    }

    function getMenuItem(name) {
        return {
            text: name,
            onclick: function () {
                insert(name);
            }
        };
    }

    editor.addMenuItem("glyphicons", {
        text: "Icon",
        context: "insert",
        menu: [
            getMenuItem("adjust"),
            getMenuItem("alert"),
            getMenuItem("align-center"),
            getMenuItem("align-justify"),
            getMenuItem("align-left"),
            getMenuItem("align-right"),
            getMenuItem("apple"),
            getMenuItem("arrow-down"),
            getMenuItem("arrow-left"),
            getMenuItem("arrow-right"),
            getMenuItem("arrow-up"),
            getMenuItem("asterisk"),
            getMenuItem("baby-formula"),
            getMenuItem("backward"),
            getMenuItem("ban-circle"),
            getMenuItem("barcode"),
            getMenuItem("bed"),
            getMenuItem("bell"),
            getMenuItem("bishop"),
            getMenuItem("bitcoin"),
            getMenuItem("blackboard"),
            getMenuItem("bold"),
            getMenuItem("book"),
            getMenuItem("bookmark"),
            getMenuItem("briefcase"),
            getMenuItem("btc"),
            getMenuItem("bullhorn"),
            getMenuItem("calendar"),
            getMenuItem("camera"),
            getMenuItem("cd"),
            getMenuItem("certificate"),
            getMenuItem("check"),
            getMenuItem("chevron-down"),
            getMenuItem("chevron-left"),
            getMenuItem("chevron-right"),
            getMenuItem("chevron-up"),
            getMenuItem("circle-arrow-down"),
            getMenuItem("circle-arrow-left"),
            getMenuItem("circle-arrow-right"),
            getMenuItem("circle-arrow-up"),
            getMenuItem("cloud"),
            getMenuItem("cloud-download"),
            getMenuItem("cloud-upload"),
            getMenuItem("cog"),
            getMenuItem("collapse-down"),
            getMenuItem("collapse-up"),
            getMenuItem("comment"),
            getMenuItem("compressed"),
            getMenuItem("console"),
            getMenuItem("copy"),
            getMenuItem("copyright-mark"),
            getMenuItem("credit-card"),
            getMenuItem("cutlery"),
            getMenuItem("dashboard"),
            getMenuItem("download"),
            getMenuItem("download-alt"),
            getMenuItem("duplicate"),
            getMenuItem("earphone"),
            getMenuItem("edit"),
            getMenuItem("education"),
            getMenuItem("eject"),
            getMenuItem("envelope"),
            getMenuItem("equalizer"),
            getMenuItem("erase"),
            getMenuItem("euro"),
            getMenuItem("exclamation-sign"),
            getMenuItem("expand"),
            getMenuItem("export"),
            getMenuItem("eye-close"),
            getMenuItem("eye-open"),
            getMenuItem("facetime-video"),
            getMenuItem("fast-backward"),
            getMenuItem("fast-forward"),
            getMenuItem("file"),
            getMenuItem("film"),
            getMenuItem("filter"),
            getMenuItem("fire"),
            getMenuItem("flag"),
            getMenuItem("flash"),
            getMenuItem("floppy-disk"),
            getMenuItem("floppy-open"),
            getMenuItem("floppy-remove"),
            getMenuItem("floppy-save"),
            getMenuItem("floppy-saved"),
            getMenuItem("folder-close"),
            getMenuItem("folder-open"),
            getMenuItem("font"),
            getMenuItem("forward"),
            getMenuItem("fullscreen"),
            getMenuItem("gbp"),
            getMenuItem("gift"),
            getMenuItem("glass"),
            getMenuItem("globe"),
            getMenuItem("grain"),
            getMenuItem("hand-down"),
            getMenuItem("hand-left"),
            getMenuItem("hand-right"),
            getMenuItem("hand-up"),
            getMenuItem("hd-video"),
            getMenuItem("hdd"),
            getMenuItem("header"),
            getMenuItem("headphones"),
            getMenuItem("heart"),
            getMenuItem("heart-empty"),
            getMenuItem("home"),
            getMenuItem("hourglass"),
            getMenuItem("ice-lolly"),
            getMenuItem("ice-lolly-tasted"),
            getMenuItem("import"),
            getMenuItem("inbox"),
            getMenuItem("indent-left"),
            getMenuItem("indent-right"),
            getMenuItem("info-sign"),
            getMenuItem("italic"),
            getMenuItem("jpy"),
            getMenuItem("king"),
            getMenuItem("knight"),
            getMenuItem("lamp"),
            getMenuItem("leaf"),
            getMenuItem("level-up"),
            getMenuItem("link"),
            getMenuItem("list"),
            getMenuItem("list-alt"),
            getMenuItem("lock"),
            getMenuItem("log-in"),
            getMenuItem("log-out"),
            getMenuItem("magnet"),
            getMenuItem("map-marker"),
            getMenuItem("menu-down"),
            getMenuItem("menu-hamburger"),
            getMenuItem("menu-left"),
            getMenuItem("menu-right"),
            getMenuItem("menu-up"),
            getMenuItem("minus"),
            getMenuItem("minus-sign"),
            getMenuItem("modal-window"),
            getMenuItem("move"),
            getMenuItem("music"),
            getMenuItem("new-window"),
            getMenuItem("object-align-bottom"),
            getMenuItem("object-align-horizontal"),
            getMenuItem("object-align-left"),
            getMenuItem("object-align-right"),
            getMenuItem("object-align-top"),
            getMenuItem("object-align-vertical"),
            getMenuItem("off"),
            getMenuItem("oil"),
            getMenuItem("ok"),
            getMenuItem("ok-circle"),
            getMenuItem("ok-sign"),
            getMenuItem("open"),
            getMenuItem("open-file"),
            getMenuItem("option-horizontal"),
            getMenuItem("option-vertical"),
            getMenuItem("paperclip"),
            getMenuItem("paste"),
            getMenuItem("pause"),
            getMenuItem("pawn"),
            getMenuItem("pencil"),
            getMenuItem("phone"),
            getMenuItem("phone-alt"),
            getMenuItem("picture"),
            getMenuItem("piggy-bank"),
            getMenuItem("plane"),
            getMenuItem("play"),
            getMenuItem("play-circle"),
            getMenuItem("plus"),
            getMenuItem("plus-sign"),
            getMenuItem("print"),
            getMenuItem("pushpin"),
            getMenuItem("qrcode"),
            getMenuItem("queen"),
            getMenuItem("question-sign"),
            getMenuItem("random"),
            getMenuItem("record"),
            getMenuItem("refresh"),
            getMenuItem("registration-mark"),
            getMenuItem("remove"),
            getMenuItem("remove-circle"),
            getMenuItem("remove-sign"),
            getMenuItem("repeat"),
            getMenuItem("resize-full"),
            getMenuItem("resize-horizontal"),
            getMenuItem("resize-small"),
            getMenuItem("resize-vertical"),
            getMenuItem("retweet"),
            getMenuItem("road"),
            getMenuItem("rub"),
            getMenuItem("ruble"),
            getMenuItem("save"),
            getMenuItem("save-file"),
            getMenuItem("saved"),
            getMenuItem("scale"),
            getMenuItem("scissors"),
            getMenuItem("screenshot"),
            getMenuItem("sd-video"),
            getMenuItem("search"),
            getMenuItem("send"),
            getMenuItem("share"),
            getMenuItem("share-alt"),
            getMenuItem("shopping-cart"),
            getMenuItem("signal"),
            getMenuItem("sort"),
            getMenuItem("sort-by-alphabet"),
            getMenuItem("sort-by-alphabet-alt"),
            getMenuItem("sort-by-attributes"),
            getMenuItem("sort-by-attributes-alt"),
            getMenuItem("sort-by-order"),
            getMenuItem("sort-by-order-alt"),
            getMenuItem("sound-5-1"),
            getMenuItem("sound-6-1"),
            getMenuItem("sound-7-1"),
            getMenuItem("sound-dolby"),
            getMenuItem("sound-stereo"),
            getMenuItem("star"),
            getMenuItem("star-empty"),
            getMenuItem("stats"),
            getMenuItem("step-backward"),
            getMenuItem("step-forward"),
            getMenuItem("stop"),
            getMenuItem("subscript"),
            getMenuItem("subtitles"),
            getMenuItem("sunglasses"),
            getMenuItem("superscript"),
            getMenuItem("tag"),
            getMenuItem("tags"),
            getMenuItem("tasks"),
            getMenuItem("tent"),
            getMenuItem("text-background"),
            getMenuItem("text-color"),
            getMenuItem("text-height"),
            getMenuItem("text-size"),
            getMenuItem("text-width"),
            getMenuItem("th"),
            getMenuItem("th-large"),
            getMenuItem("th-list"),
            getMenuItem("thumbs-down"),
            getMenuItem("thumbs-up"),
            getMenuItem("time"),
            getMenuItem("tint"),
            getMenuItem("tower"),
            getMenuItem("transfer"),
            getMenuItem("trash"),
            getMenuItem("tree-conifer"),
            getMenuItem("tree-deciduous"),
            getMenuItem("triangle-bottom"),
            getMenuItem("triangle-left"),
            getMenuItem("triangle-right"),
            getMenuItem("triangle-top"),
            getMenuItem("unchecked"),
            getMenuItem("upload"),
            getMenuItem("usd"),
            getMenuItem("user"),
            getMenuItem("volume-down"),
            getMenuItem("volume-off"),
            getMenuItem("volume-up"),
            getMenuItem("warning-sign"),
            getMenuItem("wrench"),
            getMenuItem("xbt"),
            getMenuItem("yen"),
            getMenuItem("zoom-in"),
            getMenuItem("zoom-out")
        ]
    });
});

jQuery/Bootstrap Widget: fileinput

<script type="text/html" id="file-input-template">
    <div class="input-group">
        <input type="text" readonly="readonly" class="form-control" />
        <label class="input-group-btn">
            <span class="btn btn-primary">
                Browse
                <input type="file" class="sr-only" />
            </span>
        </label>
    </div>
</script>

<script type="text/javascript">
    $.widget("scw.fileinput", {
        options: {
            id: "file",
            name: "file",
            disabled: false
        },

        _create: function () {
            var self = this;
            self.$group = $($("#file-input-template").html()).appendTo(self.element);
            self.$file = self.$group.find("input[type='file']");
            self.$file.attr("id", self.options.id);
            self.$file.attr("name", self.options.name);
            self.$text = self.$group.find("input[type='text']");
            self.$button = self.$group.find(".btn");
            self._setDisabled(self.options.disabled);
            self.$file.change(function () {
                self.$text.val(self.$file.val());
            });
        },

        _setDisabled: function (disabled) {
            var self = this;
            self.$text.prop("disabled", disabled);
            self.$file.prop("disabled", disabled);
            self.$button.toggleClass("disabled", disabled);
        },

        _setOption: function (key, value) {
            var self = this;
            self._super(key, value);
            if (key === "disabled") {
                self._setDisabled(value);
            }
        }
    });
</script>

jQuery/Bootstrap Widget: dialog

<script type="text/html" id="modal-template">
    <div class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <span class="modal-title"></span>
                </div>
                <div class="modal-body"></div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
</script>

<script type="text/javascript">
    $.widget("scw.dialog", {
        options: {
            size: "sm",
            title: "",
            body: "",
            buttons: [
                {
                    style: "primary",
                    text: "OK"
                }
            ]
        },

        _create: function () {
            var self = this;
            self.$modal = $($("#modal-template").html()).appendTo(self.element);
            self.$modal.find(".modal-dialog").addClass("modal-" + self.options.size);
            self.$modal.find(".modal-title").text(self.options.title);
            self.$modal.find(".modal-body").html(self.options.body);
            var $footer = self.$modal.find(".modal-footer");
            $.each(self.options.buttons, function () {
                var defaults = {
                    command: $.noop,
                    argument: null
                };
                var options = $.extend(defaults, this);
                var $button = $("<button type='button' class='btn'></button>");
                $button.addClass("btn-" + options.style);
                $button.text(options.text);
                $button.click(function () {
                    self.$modal.one("hidden.bs.modal", function () {
                        options.command(options.argument);
                        self.destroy();
                    });
                    self.$modal.modal("hide");
                });
                $footer.append($button);
            });
            self.$modal.modal({
                backdrop: "static",
                keyboard: false
            });
        },

        _destroy: function () {
            var self = this;
            self.$modal.remove();
        }
    });
</script>

Knockout Binding Handler: validationPopover

<script type="text/javascript">
    ko.bindingHandlers.validationPopover = {
        init: function (element, valueAccessor, allBindings) {
            if (!allBindings.has("value")) {
                return;
            }
            var $element = $(element);
            var value = allBindings.get("value");
            $element.popover($.extend({}, ko.unwrap(valueAccessor()), {
                content: function () {
                    return value.error();
                },
                trigger: "manual"
            }));
            value.subscribe(function () {
                $element.popover(value.isValid() ? "hide" : "show");
            });
        }
    };
</script>

<input type="text" data-bind="value: name, validationPopover: {}" />

<script type="text/javascript">
    ko.validation.init({
        insertMessages: false
    });
    
    function ViewModel() {
        var self = this;
        self.name = ko.observable().extend({ required: true });
    }
    
    ko.applyBindings(new ViewModel());
</script>